Skip to contentSkip to conversation

Fix poll bug

PATCH Applied Dylan Yudaken 2 participants 4 messages May 12, 2022

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

cover Fix poll bug

Hi,

This fixes a bug in poll wakeups, where it would wake up unnecessarily. This is most obvious with sockets, where the socket will wake both readers and writers when new read data is available, even if the socket is still not writable.

Patch 1 is a simple bug I noticed while debugging the poll problem Patch 2 is the poll fix

Dylan Yudaken (2):
io_uring: fix ordering of args in io_uring_queue_async_work
io_uring: only wake when the correct events are set

 fs/io_uring.c                   | 5 +++--
 include/trace/events/io_uring.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

base-commit: f569add47119fa910ed7711b26b8d38e21f7ea77

Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 io_uring: fix ordering of args in io_uring_queue_async_work

Fix arg ordering in TP_ARGS macro, which fixes the output.

Fixes 502c87d65564c ("io-uring: Make tracepoints consistent.")
---
 include/trace/events/io_uring.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/io_uring.h +1 -1
index 630982b3c34c..ef186809ce97 100644
@@ -148,7 +148,7 @@ TRACE_EVENT(io_uring_queue_async_work,
 	TP_PROTO(void *ctx, void * req, unsigned long long user_data, u8 opcode,
 		unsigned int flags, struct io_wq_work *work, int rw),
 
-	TP_ARGS(ctx, req, user_data, flags, opcode, work, rw),
+	TP_ARGS(ctx, req, user_data, opcode, flags, work, rw),
 
 	TP_STRUCT__entry (
 		__field(  void *,			ctx		)
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/2 io_uring: only wake when the correct events are set

In reply to Dylan Yudaken

The check for waking up a request compares the poll_t bits, however this will always contain some common flags so this always wakes up.

For files with single wait queues such as sockets this can cause the request to be sent to the async worker unnecesarily. Further if it is non-blocking will complete the request with EAGAIN which is not desired.

Here exclude these common events, making sure to not exclude POLLERR which might be important.

Fixes d7718a9d25a6 ("io_uring: use poll driven retry for files that support it")
---
 fs/io_uring.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/io_uring.c +3 -2
index 44c57dca358d..44661a1f695a 100644
@@ -6782,6 +6782,7 @@ static void io_poll_cancel_req(struct io_kiocb *req)
 
 #define wqe_to_req(wait)	((void *)((unsigned long) (wait)->private & ~1))
 #define wqe_is_double(wait)	((unsigned long) (wait)->private & 1)
+#define IO_ASYNC_POLL_COMMON	(EPOLLONESHOT | POLLPRI)
 
 static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
 			void *key)
@@ -6816,7 +6817,7 @@ static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,
 	}
 
 	/* for instances that support it check for an event match first */
-	if (mask && !(mask & poll->events))
+	if (mask && !(mask & (poll->events & ~IO_ASYNC_POLL_COMMON)))
 		return 0;
 
 	if (io_poll_get_ownership(req)) {
@@ -6973,7 +6974,7 @@ static int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
 	struct io_ring_ctx *ctx = req->ctx;
 	struct async_poll *apoll;
 	struct io_poll_table ipt;
-	__poll_t mask = EPOLLONESHOT | POLLERR | POLLPRI;
+	__poll_t mask = IO_ASYNC_POLL_COMMON | POLLERR;
 	int ret;
 
 	if (!def->pollin && !def->pollout)
Signature · 1 line
2.30.2
maintainer Applied
#3 lore raw
In reply to Dylan Yudaken
Quoted 9 lines · Dylan Yudaken

This fixes a bug in poll wakeups, where it would wake up unnecessarily. This is most obvious with sockets, where the socket will wake both readers and writers when new read data is available, even if the socket is still not writable.

Patch 1 is a simple bug I noticed while debugging the poll problem Patch 2 is the poll fix

[...]

Applied, thanks!

[1/2] io_uring: fix ordering of args in io_uring_queue_async_work

      commit: 2d2d5cb6ca8424fa849ebb4edb8e8022c13860c7
[2/2] io_uring: only wake when the correct events are set
      commit: beed4eed5fc1fe18f2b78b214450e28d786c1e49

Best regards,

Signature · 1 line
Jens Axboe