1 From 8d1c98b0b5c0148b519c6416e689ef6a89ffcea3 Mon Sep 17 00:00:00 2001
2 From: Davide Libenzi <davidel@xmailserver.org>
3 Date: Thu, 10 Apr 2008 21:29:19 -0700
4 Subject: [PATCH] eventfd/kaio integration fix
6 Jeff Roberson discovered a race when using kaio eventfd based notifications.
7 When it occurs it can lead tomissed wakeups and hung userspace.
9 This patch fixes the race by moving the notification inside the spinlocked
10 section of kaio. The operation is safe since eventfd spinlock and kaio one
13 Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
14 Cc: Zach Brown <zach.brown@oracle.com>
15 Cc: Jeff Roberson <jroberson@chesapeake.net>
16 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
17 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
18 Signed-off-by: Oliver Pinter <oliver.pntr@gmail.com>
20 diff --git a/fs/aio.c b/fs/aio.c
21 index 60a4cd4..2283686 100644
24 @@ -936,14 +936,6 @@ int aio_complete(struct kiocb *iocb, long res, long res2)
29 - * Check if the user asked us to deliver the result through an
30 - * eventfd. The eventfd_signal() function is safe to be called
33 - if (!IS_ERR(iocb->ki_eventfd))
34 - eventfd_signal(iocb->ki_eventfd, 1);
36 info = &ctx->ring_info;
38 /* add a completion event to the ring buffer.
39 @@ -992,6 +984,15 @@ int aio_complete(struct kiocb *iocb, long res, long res2)
40 kunmap_atomic(ring, KM_IRQ1);
42 pr_debug("added to ring %p at [%lu]\n", iocb, tail);
45 + * Check if the user asked us to deliver the result through an
46 + * eventfd. The eventfd_signal() function is safe to be called
49 + if (!IS_ERR(iocb->ki_eventfd))
50 + eventfd_signal(iocb->ki_eventfd, 1);
53 /* everything turned out well, dispose of the aiocb. */
54 ret = __aio_put_req(ctx, iocb);