Skip to content

Commit e91f90b

Browse files
rolanddtorvalds
authored andcommitted
aio: wake all waiters when destroying ctx
The test program below will hang because io_getevents() uses add_wait_queue_exclusive(), which means the wake_up() in io_destroy() only wakes up one of the threads. Fix this by using wake_up_all() in the aio code paths where we want to make sure no one gets stuck. // t.c -- compile with gcc -lpthread -laio t.c #include <libaio.h> #include <pthread.h> #include <stdio.h> #include <unistd.h> static const int nthr = 2; void *getev(void *ctx) { struct io_event ev; io_getevents(ctx, 1, 1, &ev, NULL); printf("io_getevents returned\n"); return NULL; } int main(int argc, char *argv[]) { io_context_t ctx = 0; pthread_t thread[nthr]; int i; io_setup(1024, &ctx); for (i = 0; i < nthr; ++i) pthread_create(&thread[i], NULL, getev, ctx); sleep(1); io_destroy(ctx); for (i = 0; i < nthr; ++i) pthread_join(thread[i], NULL); return 0; } Signed-off-by: Roland Dreier <[email protected]> Reviewed-by: Jeff Moyer <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 77d1c8e commit e91f90b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/aio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static inline void really_put_req(struct kioctx *ctx, struct kiocb *req)
520520
ctx->reqs_active--;
521521

522522
if (unlikely(!ctx->reqs_active && ctx->dead))
523-
wake_up(&ctx->wait);
523+
wake_up_all(&ctx->wait);
524524
}
525525

526526
static void aio_fput_routine(struct work_struct *data)
@@ -1229,7 +1229,7 @@ static void io_destroy(struct kioctx *ioctx)
12291229
* by other CPUs at this point. Right now, we rely on the
12301230
* locking done by the above calls to ensure this consistency.
12311231
*/
1232-
wake_up(&ioctx->wait);
1232+
wake_up_all(&ioctx->wait);
12331233
put_ioctx(ioctx); /* once for the lookup */
12341234
}
12351235

0 commit comments

Comments
 (0)