aio: add missing smp_rmb() in read_events_ring
authorJeff Moyer <jmoyer@redhat.com>
Tue, 2 Sep 2014 17:17:00 +0000 (13:17 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Wed, 5 Nov 2014 20:27:40 +0000 (20:27 +0000)
commit 2ff396be602f10b5eab8e73b24f20348fa2de159 upstream.

We ran into a case on ppc64 running mariadb where io_getevents would
return zeroed out I/O events.  After adding instrumentation, it became
clear that there was some missing synchronization between reading the
tail pointer and the events themselves.  This small patch fixes the
problem in testing.

Thanks to Zach for helping to look into this, and suggesting the fix.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
[bwh: Backported to 3.2: adjust context, indentation]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/aio.c

index 8cdd8ea0f44a3792171d0158b67fdcc42ec8f36d..9acfd0708d922545b68ce5938b3f118422790793 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1102,6 +1102,13 @@ static int aio_read_evt(struct kioctx *ioctx, struct io_event *ent)
        head = ring->head % info->nr;
        if (head != ring->tail) {
                struct io_event *evp = aio_ring_event(info, head, KM_USER1);
+
+               /*
+                * Ensure that once we've read the current tail pointer, that
+                * we also see the events that were stored up to the tail.
+                */
+               smp_rmb();
+
                *ent = *evp;
                head = (head + 1) % info->nr;
                smp_mb(); /* finish reading the event before updatng the head */