v2.6.22.22-op2-rc1
[linux-2.6.22.y-op-patches.git] / release-2.6.22.y / 2.6.22.22-op1 / KAIO-eventfd_kaio-integration-fix.patch
blobd3590eba978fcc43742dcda78549764f7c67aa69
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
11 are unrelated.
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
22 --- a/fs/aio.c
23 +++ b/fs/aio.c
24 @@ -936,14 +936,6 @@ int aio_complete(struct kiocb *iocb, long res, long res2)
25 return 1;
28 - /*
29 - * Check if the user asked us to deliver the result through an
30 - * eventfd. The eventfd_signal() function is safe to be called
31 - * from IRQ context.
32 - */
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);
44 + /*
45 + * Check if the user asked us to deliver the result through an
46 + * eventfd. The eventfd_signal() function is safe to be called
47 + * from IRQ context.
48 + */
49 + if (!IS_ERR(iocb->ki_eventfd))
50 + eventfd_signal(iocb->ki_eventfd, 1);
52 put_rq:
53 /* everything turned out well, dispose of the aiocb. */
54 ret = __aio_put_req(ctx, iocb);