mps icon indicating copy to clipboard operation
mps copied to clipboard

Possible enhancement: use userfaultfd() for write barriers on Linux

Open promovicz opened this issue 2 years ago • 2 comments

Linux has recently gained a feature intended for write barriers without signals or stopping the mutator:

https://www.kernel.org/doc/html/latest/admin-guide/mm/userfaultfd.html#write-protect-notifications

Unfortunately it seems like this is intended for page granularity notifications - even though it seems to provide the fault address, so use for garbage collector barriers might be possible. Additional extensions to the kernel API might be required for optimum efficiency.

Greetings from the Open Dylan project. I just noticed this feature and figured you might be interested.

promovicz avatar Dec 20 '21 12:12 promovicz

I just spent some time discussing this with a colleague from security. They have been doing some pretty advanced things using usefaultfd(), and they have answered some of my questions. It seems that userfaultfd() can handle even kernel-level page faults and also provide an efficient replacement for "/proc/self/maps" scanning.

Further exploration is definitely recommended.

promovicz avatar Jul 10 '22 01:07 promovicz

Reading the updated documentation reveals that userfaultfd() on Debian 10 can not yet notify for write barriers.

From the ioctl_userfaultfd manual page:

       The mode field defines the mode of operation desired for this memory region.  The following values may be bitwise ORed to set the userfaultfd mode for the specified range:

       UFFDIO_REGISTER_MODE_MISSING
              Track page faults on missing pages.

       UFFDIO_REGISTER_MODE_WP
              Track page faults on write-protected pages.

       Currently, the only supported mode is UFFDIO_REGISTER_MODE_MISSING.

So the required features are foreseen, but not necessarily widely available. This may have changed at kernel level though.

promovicz avatar Jul 10 '22 02:07 promovicz

It's essential to understand this properly.

thejayps avatar Feb 13 '23 16:02 thejayps