Skip to content

Commit

Permalink
eventfd/kaio integration fix
Browse files Browse the repository at this point in the history
Jeff Roberson discovered a race when using kaio eventfd based notifications.
When it occurs it can lead tomissed wakeups and hung userspace.

This patch fixes the race by moving the notification inside the spinlocked
section of kaio.  The operation is safe since eventfd spinlock and kaio one
are unrelated.

Signed-off-by: Davide Libenzi <[email protected]>
Cc: Zach Brown <[email protected]>
Cc: Jeff Roberson <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
davidel authored and torvalds committed Apr 11, 2008
1 parent d479540 commit 8d1c98b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,14 +936,6 @@ int aio_complete(struct kiocb *iocb, long res, long res2)
return 1;
}

/*
* Check if the user asked us to deliver the result through an
* eventfd. The eventfd_signal() function is safe to be called
* from IRQ context.
*/
if (!IS_ERR(iocb->ki_eventfd))
eventfd_signal(iocb->ki_eventfd, 1);

info = &ctx->ring_info;

/* add a completion event to the ring buffer.
Expand Down Expand Up @@ -992,6 +984,15 @@ int aio_complete(struct kiocb *iocb, long res, long res2)
kunmap_atomic(ring, KM_IRQ1);

pr_debug("added to ring %p at [%lu]\n", iocb, tail);

/*
* Check if the user asked us to deliver the result through an
* eventfd. The eventfd_signal() function is safe to be called
* from IRQ context.
*/
if (!IS_ERR(iocb->ki_eventfd))
eventfd_signal(iocb->ki_eventfd, 1);

put_rq:
/* everything turned out well, dispose of the aiocb. */
ret = __aio_put_req(ctx, iocb);
Expand Down

0 comments on commit 8d1c98b

Please sign in to comment.