Open promovicz opened 2 years ago
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.
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.
It's essential to understand this properly.
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.