userfaultfdv4.1 update for -mm
Subsystems (3)
cover userfaultfdv4.1 update for -mm
Hello,
Here some change I already folded earlier, extracted in order to apply cleanly at the end of current -mm.
To fold the userfaultfd.txt update the part in "userfaultfd: change the read API to return a uffd_msg" should also be extracted and folded first or this one will reject.
Andrea Arcangeli (2):
userfaultfd: documentation update
userfaultfd: fs/userfaultfd.c add more comments
Documentation/vm/userfaultfd.txt | 16 +++++++++------- fs/userfaultfd.c | 28 +++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 8 deletions(-)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/2 userfaultfd: documentation update
--- Documentation/vm/userfaultfd.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
Documentation/vm/userfaultfd.txt +9 -7
@@ -3,8 +3,8 @@ == Objective == Userfaults allow the implementation of on-demand paging from userland -and more generally they allow userland to take control various memory -page faults, something otherwise only the kernel code could do. +and more generally they allow userland to take control of various +memory page faults, something otherwise only the kernel code could do. For example userfaults allows a proper and more optimal implementation of the PROT_NONE+SIGSEGV trick.
@@ -47,10 +47,10 @@ When first opened the userfaultfd must be enabled invoking the UFFDIO_API ioctl specifying a uffdio_api.api value set to UFFD_API (or a later API version) which will specify the read/POLLIN protocol userland intends to speak on the UFFD and the uffdio_api.features -userland needs to be enabled. The UFFDIO_API ioctl if successful -(i.e. if the requested uffdio_api.api is spoken also by the running -kernel and the requested features are going to be enabled) will return -into uffdio_api.features and uffdio_api.ioctls two 64bit bitmasks of +userland requires. The UFFDIO_API ioctl if successful (i.e. if the +requested uffdio_api.api is spoken also by the running kernel and the +requested features are going to be enabled) will return into +uffdio_api.features and uffdio_api.ioctls two 64bit bitmasks of respectively all the available features of the read(2) protocol and the generic ioctl available.
@@ -77,7 +77,9 @@ The primary ioctl to resolve userfaults is UFFDIO_COPY. That atomically copies a page into the userfault registered range and wakes up the blocked userfaults (unless uffdio_copy.mode & UFFDIO_COPY_MODE_DONTWAKE is set). Other ioctl works similarly to -UFFDIO_COPY. +UFFDIO_COPY. They're atomic as in guaranteeing that nothing can see an +half copied page since it'll keep userfaulting until the copy has +finished. == QEMU/KVM ==
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 userfaultfd: fs/userfaultfd.c add more comments
In reply to Andrea ArcangeliAdd more commentary.
--- fs/userfaultfd.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
fs/userfaultfd.c +27 -1
@@ -86,7 +86,20 @@ static int userfaultfd_wake_function(wait_queue_t *wq, unsigned mode, goto out; ret =wake_up_state (wq->private, mode);if (ret) -/* wake only once, autoremove behavior */ +/* +* Wake only once, autoremove behavior. +* +* After the effect of list_del_init is visible to the +* other CPUs, the waitqueue may disappear from under +* us, see the !list_empty_careful() in +* handle_userfault(). try_to_wake_up() has an +* implicit smp_mb__before_spinlock, and the +* wq->private is read before calling the extern +* function "wake_up_state" (which in turns calls +* try_to_wake_up). While the spin_lock;spin_unlock; +* wouldn't be enough, the smp_mb__before_spinlock is +* enough to avoid an explicit smp_mb() here. +*/ list_del_init (&wq->task_list); out:return ret;
@@ -511,6 +524,19 @@ static ssize_t userfaultfd_ctx_read(struct userfaultfd_ctx *ctx, int no_wait,* Refile this userfault from * fault_pending_wqh to fault_wqh, it's not * pending anymore after we read it. +* +* Use list_del() by hand (as +* userfaultfd_wake_function also uses +* list_del_init() by hand) to be sure nobody +* changes __remove_wait_queue() to use +* list_del_init() in turn breaking the +* !list_empty_careful() check in +* handle_userfault(). The uwq->wq.task_list +* must never be empty at any time during the +* refile, or the waitqueue could disappear +* from under us. The "wait_queue_head_t" +* parameter of __remove_wait_queue() is unused +* anyway. */ list_del (&uwq->wq.task_list);__add_wait_queue (&ctx->fault_wqh, &uwq->wq);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>