aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAndrea Arcangeli <aarcange@redhat.com>2015-05-20 16:54:28 +0200
committerAndrea Arcangeli <aarcange@redhat.com>2015-06-09 21:23:43 +0200
commitd4c253b945017c62e5a45385ffe4ba0953033129 (patch)
treef9c934ae801be6f15f369a3fa7f5386729f54f6f
parent2866c6d67f1aeef6b70630789f196a8cfc31f9db (diff)
downloadaa-userfault20.tar.gz
userfaultfd: fs/userfaultfd.c add more commentsuserfault20
Add more commentary.
-rw-r--r--fs/userfaultfd.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index a68007b08a3ef..5f11678907d5d 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);