Skip to content

Commit b1445e5

Browse files
isilenceaxboe
authored andcommitted
io_uring: synchronise ev_posted() with waitqueues
waitqueue_active() needs smp_mb() to be in sync with waitqueues modification, but we miss it in io_cqring_ev_posted*() apart from cq_wait() case. Take an smb_mb() out of wq_has_sleeper() making it waitqueue_active(), and place it a few lines before, so it can synchronise other waitqueue_active() as well. The patch doesn't add any additional overhead, so even if there are no problems currently, it's just safer to have it this way. Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 4aa84f2 commit b1445e5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

fs/io_uring.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,27 +1700,33 @@ static inline unsigned __io_cqring_events(struct io_ring_ctx *ctx)
17001700

17011701
static void io_cqring_ev_posted(struct io_ring_ctx *ctx)
17021702
{
1703+
/* see waitqueue_active() comment */
1704+
smp_mb();
1705+
17031706
if (waitqueue_active(&ctx->wait))
17041707
wake_up(&ctx->wait);
17051708
if (ctx->sq_data && waitqueue_active(&ctx->sq_data->wait))
17061709
wake_up(&ctx->sq_data->wait);
17071710
if (io_should_trigger_evfd(ctx))
17081711
eventfd_signal(ctx->cq_ev_fd, 1);
1709-
if (wq_has_sleeper(&ctx->cq_wait)) {
1712+
if (waitqueue_active(&ctx->cq_wait)) {
17101713
wake_up_interruptible(&ctx->cq_wait);
17111714
kill_fasync(&ctx->cq_fasync, SIGIO, POLL_IN);
17121715
}
17131716
}
17141717

17151718
static void io_cqring_ev_posted_iopoll(struct io_ring_ctx *ctx)
17161719
{
1720+
/* see waitqueue_active() comment */
1721+
smp_mb();
1722+
17171723
if (ctx->flags & IORING_SETUP_SQPOLL) {
17181724
if (waitqueue_active(&ctx->wait))
17191725
wake_up(&ctx->wait);
17201726
}
17211727
if (io_should_trigger_evfd(ctx))
17221728
eventfd_signal(ctx->cq_ev_fd, 1);
1723-
if (wq_has_sleeper(&ctx->cq_wait)) {
1729+
if (waitqueue_active(&ctx->cq_wait)) {
17241730
wake_up_interruptible(&ctx->cq_wait);
17251731
kill_fasync(&ctx->cq_fasync, SIGIO, POLL_IN);
17261732
}

0 commit comments

Comments
 (0)