From: Greg Kroah-Hartman <gregkh@linuxfoundation•org>
To: linux-kernel@vger•kernel.org, stable@vger•kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation•org>,
alan@lxorguk•ukuu.org.uk, Eric Wong <normalperson@yhbt•net>,
Hans Verkuil <hans.verkuil@cisco•com>,
Jiri Olsa <jolsa@redhat•com>, Jonathan Corbet <corbet@lwn•net>,
Al Viro <viro@zeniv•linux.org.uk>,
Davide Libenzi <davidel@xmailserver•org>,
Hans de Goede <hdegoede@redhat•com>,
Mauro Carvalho Chehab <mchehab@infradead•org>,
David Miller <davem@davemloft•net>,
Eric Dumazet <eric.dumazet@gmail•com>,
Andrew Morton <akpm@linux-foundation•org>,
Andreas Voellmy <andreas.voellmy@yale•edu>,
"Junchang(Jason) Wang" <junchang.wang@yale•edu>,
Linus Torvalds <torvalds@linux-foundation•org>,
netdev@vger•kernel.org, linux-fsdevel@vger•kernel.org
Subject: [ 069/171] epoll: prevent missed events on EPOLL_CTL_MOD
Date: Tue, 15 Jan 2013 14:43:54 -0800 [thread overview]
Message-ID: <20130115224318.378490097@linuxfoundation.org> (raw)
In-Reply-To: <20130115224313.394976595@linuxfoundation.org>
3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Wong <normalperson@yhbt•net>
commit 128dd1759d96ad36c379240f8b9463e8acfd37a1 upstream.
EPOLL_CTL_MOD sets the interest mask before calling f_op->poll() to
ensure events are not missed. Since the modifications to the interest
mask are not protected by the same lock as ep_poll_callback, we need to
ensure the change is visible to other CPUs calling ep_poll_callback.
We also need to ensure f_op->poll() has an up-to-date view of past
events which occured before we modified the interest mask. So this
barrier also pairs with the barrier in wq_has_sleeper().
This should guarantee either ep_poll_callback or f_op->poll() (or both)
will notice the readiness of a recently-ready/modified item.
This issue was encountered by Andreas Voellmy and Junchang(Jason) Wang in:
http://thread.gmane.org/gmane.linux.kernel/1408782/
Signed-off-by: Eric Wong <normalperson@yhbt•net>
Cc: Hans Verkuil <hans.verkuil@cisco•com>
Cc: Jiri Olsa <jolsa@redhat•com>
Cc: Jonathan Corbet <corbet@lwn•net>
Cc: Al Viro <viro@zeniv•linux.org.uk>
Cc: Davide Libenzi <davidel@xmailserver•org>
Cc: Hans de Goede <hdegoede@redhat•com>
Cc: Mauro Carvalho Chehab <mchehab@infradead•org>
Cc: David Miller <davem@davemloft•net>
Cc: Eric Dumazet <eric.dumazet@gmail•com>
Cc: Andrew Morton <akpm@linux-foundation•org>
Cc: Andreas Voellmy <andreas.voellmy@yale•edu>
Tested-by: "Junchang(Jason) Wang" <junchang.wang@yale•edu>
Cc: netdev@vger•kernel.org
Cc: linux-fsdevel@vger•kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation•org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation•org>
---
fs/eventpoll.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1226,11 +1226,31 @@ static int ep_modify(struct eventpoll *e
* otherwise we might miss an event that happens between the
* f_op->poll() call and the new event set registering.
*/
- epi->event.events = event->events;
+ epi->event.events = event->events; /* need barrier below */
pt._key = event->events;
epi->event.data = event->data; /* protected by mtx */
/*
+ * The following barrier has two effects:
+ *
+ * 1) Flush epi changes above to other CPUs. This ensures
+ * we do not miss events from ep_poll_callback if an
+ * event occurs immediately after we call f_op->poll().
+ * We need this because we did not take ep->lock while
+ * changing epi above (but ep_poll_callback does take
+ * ep->lock).
+ *
+ * 2) We also need to ensure we do not miss _past_ events
+ * when calling f_op->poll(). This barrier also
+ * pairs with the barrier in wq_has_sleeper (see
+ * comments for wq_has_sleeper).
+ *
+ * This barrier will now guarantee ep_poll_callback or f_op->poll
+ * (or both) will notice the readiness of an item.
+ */
+ smp_mb();
+
+ /*
* Get current event bits. We can safely use the file* here because
* its usage count has been increased by the caller of this function.
*/
parent reply other threads:[~2013-01-15 22:43 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20130115224313.394976595@linuxfoundation.org>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130115224318.378490097@linuxfoundation.org \
--to=gregkh@linuxfoundation$(echo .)org \
--cc=akpm@linux-foundation$(echo .)org \
--cc=alan@lxorguk$(echo .)ukuu.org.uk \
--cc=andreas.voellmy@yale$(echo .)edu \
--cc=corbet@lwn$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=davidel@xmailserver$(echo .)org \
--cc=eric.dumazet@gmail$(echo .)com \
--cc=hans.verkuil@cisco$(echo .)com \
--cc=hdegoede@redhat$(echo .)com \
--cc=jolsa@redhat$(echo .)com \
--cc=junchang.wang@yale$(echo .)edu \
--cc=linux-fsdevel@vger$(echo .)kernel.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=mchehab@infradead$(echo .)org \
--cc=netdev@vger$(echo .)kernel.org \
--cc=normalperson@yhbt$(echo .)net \
--cc=stable@vger$(echo .)kernel.org \
--cc=torvalds@linux-foundation$(echo .)org \
--cc=viro@zeniv$(echo .)linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox