Skip to contentSkip to conversation

io_uring: flush overflowed CQ events in the io_uring_poll()

PATCH Applied Stefano Garzarella 2 participants 3 messages Feb 7, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring: flush overflowed CQ events in the io_uring_poll()

In io_uring_poll() we must flush overflowed CQ events before to check if there are CQ events available, to avoid missing events.

We call the io_cqring_events() that checks and flushes any overflow and returns the number of CQ events available.

We can avoid taking the 'uring_lock' since the flush is already protected by 'completion_lock'.

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index 77f22c3da30f..02e77e86abaf 100644
@@ -6301,7 +6301,7 @@ static __poll_t io_uring_poll(struct file *file, poll_table *wait)
 	if (READ_ONCE(ctx->rings->sq.tail) - ctx->cached_sq_head !=
 	    ctx->rings->sq_ring_entries)
 		mask |= EPOLLOUT | EPOLLWRNORM;
-	if (READ_ONCE(ctx->rings->cq.head) != ctx->cached_cq_tail)
+	if (io_cqring_events(ctx, false))
 		mask |= EPOLLIN | EPOLLRDNORM;
 
 	return mask;
Signature · 1 line
2.24.1
maintainer Applied
#1 lore raw
Quoted 8 lines · Stefano Garzarella

In io_uring_poll() we must flush overflowed CQ events before to check if there are CQ events available, to avoid missing events.

We call the io_cqring_events() that checks and flushes any overflow and returns the number of CQ events available.

We can avoid taking the 'uring_lock' since the flush is already protected by 'completion_lock'.

Thanks, applied. I dropped that last sentence, as a) it doesn't really matter, and b) we may very well already have it held here if someone is doing a poll on the io_uring fd itself.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 7 lines · Jens Axboe
Quoted 6 lines · Stefano Garzarella

In io_uring_poll() we must flush overflowed CQ events before to check if there are CQ events available, to avoid missing events.

We call the io_cqring_events() that checks and flushes any overflow and returns the number of CQ events available.

Quoted 6 lines
Quoted 2 lines

We can avoid taking the 'uring_lock' since the flush is already protected by 'completion_lock'.

Thanks, applied. I dropped that last sentence, as a) it doesn't really matter, and b) we may very well already have it held here if someone is doing a poll on the io_uring fd itself.

Sure, indeed I was undecided whether to put it after the three dashes as a response to your yesterday's request.

Thanks,
Stefano