* [PATCH 0/2] userfaultfdv4.1 update for -mm
@ 2015-05-20 19:13 Andrea Arcangeli
2015-05-20 19:13 ` [PATCH 1/2] userfaultfd: documentation update Andrea Arcangeli
2015-05-20 19:13 ` [PATCH 2/2] userfaultfd: fs/userfaultfd.c add more comments Andrea Arcangeli
0 siblings, 2 replies; 3+ messages in thread
From: Andrea Arcangeli @ 2015-05-20 19:13 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] userfaultfd: documentation update
2015-05-20 19:13 [PATCH 0/2] userfaultfdv4.1 update for -mm Andrea Arcangeli
@ 2015-05-20 19:13 ` Andrea Arcangeli
2015-05-20 19:13 ` [PATCH 2/2] userfaultfd: fs/userfaultfd.c add more comments Andrea Arcangeli
1 sibling, 0 replies; 3+ messages in thread
From: Andrea Arcangeli @ 2015-05-20 19:13 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
Documentation/vm/userfaultfd.txt | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/Documentation/vm/userfaultfd.txt b/Documentation/vm/userfaultfd.txt
index 3557edd..70a3c94 100644
--- a/Documentation/vm/userfaultfd.txt
+++ b/Documentation/vm/userfaultfd.txt
@@ -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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] userfaultfd: fs/userfaultfd.c add more comments
2015-05-20 19:13 [PATCH 0/2] userfaultfdv4.1 update for -mm Andrea Arcangeli
2015-05-20 19:13 ` [PATCH 1/2] userfaultfd: documentation update Andrea Arcangeli
@ 2015-05-20 19:13 ` Andrea Arcangeli
1 sibling, 0 replies; 3+ messages in thread
From: Andrea Arcangeli @ 2015-05-20 19:13 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-mm
Add more commentary.
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
fs/userfaultfd.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index f601f27..a519f74 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -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 majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-20 19:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-20 19:13 [PATCH 0/2] userfaultfdv4.1 update for -mm Andrea Arcangeli
2015-05-20 19:13 ` [PATCH 1/2] userfaultfd: documentation update Andrea Arcangeli
2015-05-20 19:13 ` [PATCH 2/2] userfaultfd: fs/userfaultfd.c add more comments Andrea Arcangeli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).