History

userfaultfd: non-cooperative: Add fork() event

When the mm with uffd-ed vmas fork()-s the respective vmas notify their uffds with the event which contains a descriptor with new uffd. This new descriptor can then be used to get events from the child and populate its mm with data. Note, that there can be different uffd-s controlling different vmas within one mm, so first we should collect all those uffds (and ctx-s) in a list and then notify them all one by one but only once per fork(). The context is created at fork() time but the descriptor, file struct and anon inode object is created at event read time. So some trickery is added to the userfaultfd_ctx_read() to handle the ctx queues' locking vs file creation. Another thing worth noticing is that the task that fork()-s waits for the uffd event to get processed WITHOUT the mmap sem. [aarcange@redhat.com: build warning fix] Link: http://lkml.kernel.org/r/20161216144821.5183-10-aarcange@redhat.com Link: http://lkml.kernel.org/r/20161216144821.5183-9-aarcange@redhat.com Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> Cc: Hillf Danton <hillf.zj@alibaba-inc.com> Cc: Michael Rapoport <RAPOPORT@il.ibm.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Pavel Emelyanov committed 9 years ago

Commit 893e26e1 parent 65603144 files · +170 −16Browse files

Showing the changes to include/uapi/linux (1 of 4 files). Show all

Unified · Split

include/uapi/linux/userfaultfd.h+5−10
@@ -18,12 +18,7 @@ · 17 unmodified lines
18 * means the userland is reading).18 * means the userland is reading).
19 */19 */
20#define UFFD_API ((__u64)0xAA)20#define UFFD_API ((__u64)0xAA)
21/*21#define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK)
22 * After implementing the respective features it will become:
23 * #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \
24 * UFFD_FEATURE_EVENT_FORK)
25 */
26#define UFFD_API_FEATURES (0)
27#define UFFD_API_IOCTLS \22#define UFFD_API_IOCTLS \
28 ((__u64)1 << _UFFDIO_REGISTER | \23 ((__u64)1 << _UFFDIO_REGISTER | \
29 (__u64)1 << _UFFDIO_UNREGISTER | \24 (__u64)1 << _UFFDIO_UNREGISTER | \
@@ -77,6 +72,10 @@ struct uffd_msg { · 47 unmodified lines
77 __u64 address;72 __u64 address;
78 } pagefault;73 } pagefault;
79 74
75 struct {
76 __u32 ufd;
77 } fork;
78
80 struct {79 struct {
81 /* unused reserved fields */80 /* unused reserved fields */
82 __u64 reserved1;81 __u64 reserved1;
@@ -90,9 +89,7 @@ struct uffd_msg { · 7 unmodified lines
90 * Start at 0x12 and not at 0 to be more strict against bugs.89 * Start at 0x12 and not at 0 to be more strict against bugs.
91 */90 */
92#define UFFD_EVENT_PAGEFAULT 0x1291#define UFFD_EVENT_PAGEFAULT 0x12
93#if 0 /* not available yet */
94#define UFFD_EVENT_FORK 0x1392#define UFFD_EVENT_FORK 0x13
95#endif
96 93
97/* flags for UFFD_EVENT_PAGEFAULT */94/* flags for UFFD_EVENT_PAGEFAULT */
98#define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */95#define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */
@@ -111,10 +108,8 @@ struct uffdio_api { · 12 unmodified lines
111 * are to be considered implicitly always enabled in all kernels as108 * are to be considered implicitly always enabled in all kernels as
112 * long as the uffdio_api.api requested matches UFFD_API.109 * long as the uffdio_api.api requested matches UFFD_API.
113 */110 */
114#if 0 /* not available yet */
115#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)111#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
116#define UFFD_FEATURE_EVENT_FORK (1<<1)112#define UFFD_FEATURE_EVENT_FORK (1<<1)
117#endif
118 __u64 features;113 __u64 features;
119 114
120 __u64 ioctls;115 __u64 ioctls;