public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 5.19] io_uring: fix req->apoll_events
@ 2022-06-21 12:25 Pavel Begunkov
  2022-06-21 12:28 ` Pavel Begunkov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pavel Begunkov @ 2022-06-21 12:25 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe, asml.silence

apoll_events should be set once in the beginning of poll arming just as
poll->events and not change after. However, currently io_uring resets it
on each __io_poll_execute() for no clear reason. There is also a place
in __io_arm_poll_handler() where we add EPOLLONESHOT to downgrade a
multishot, but forget to do the same thing with ->apoll_events, which is
buggy.

Fixes: 81459350d581e ("io_uring: cache req->apoll->events in req->cflags")
Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 87c65a358678..ebda9a565fc0 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6954,7 +6954,8 @@ static void io_apoll_task_func(struct io_kiocb *req, bool *locked)
 		io_req_complete_failed(req, ret);
 }
 
-static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
+static void __io_poll_execute(struct io_kiocb *req, int mask,
+			      __poll_t __maybe_unused events)
 {
 	req->cqe.res = mask;
 	/*
@@ -6963,7 +6964,6 @@ static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
 	 * CPU. We want to avoid pulling in req->apoll->events for that
 	 * case.
 	 */
-	req->apoll_events = events;
 	if (req->opcode == IORING_OP_POLL_ADD)
 		req->io_task_work.func = io_poll_task_func;
 	else
@@ -7114,6 +7114,8 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
 	io_init_poll_iocb(poll, mask, io_poll_wake);
 	poll->file = req->file;
 
+	req->apoll_events = poll->events;
+
 	ipt->pt._key = mask;
 	ipt->req = req;
 	ipt->error = 0;
@@ -7144,8 +7146,10 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
 
 	if (mask) {
 		/* can't multishot if failed, just queue the event we've got */
-		if (unlikely(ipt->error || !ipt->nr_entries))
+		if (unlikely(ipt->error || !ipt->nr_entries)) {
 			poll->events |= EPOLLONESHOT;
+			req->apoll_events |= EPOLLONESHOT;
+		}
 		__io_poll_execute(req, mask, poll->events);
 		return 0;
 	}
@@ -7392,7 +7396,7 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
 		return -EINVAL;
 
 	io_req_set_refcount(req);
-	req->apoll_events = poll->events = io_poll_parse_events(sqe, flags);
+	poll->events = io_poll_parse_events(sqe, flags);
 	return 0;
 }
 
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.19] io_uring: fix req->apoll_events
  2022-06-21 12:25 [PATCH 5.19] io_uring: fix req->apoll_events Pavel Begunkov
@ 2022-06-21 12:28 ` Pavel Begunkov
  2022-06-21 13:28 ` Hao Xu
  2022-06-21 13:49 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2022-06-21 12:28 UTC (permalink / raw)
  To: io-uring; +Cc: Jens Axboe

On 6/21/22 13:25, Pavel Begunkov wrote:
> apoll_events should be set once in the beginning of poll arming just as
> poll->events and not change after. However, currently io_uring resets it
> on each __io_poll_execute() for no clear reason. There is also a place
> in __io_arm_poll_handler() where we add EPOLLONESHOT to downgrade a
> multishot, but forget to do the same thing with ->apoll_events, which is
> buggy.
> 
> Fixes: 81459350d581e ("io_uring: cache req->apoll->events in req->cflags")
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>   fs/io_uring.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 87c65a358678..ebda9a565fc0 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -6954,7 +6954,8 @@ static void io_apoll_task_func(struct io_kiocb *req, bool *locked)
>   		io_req_complete_failed(req, ret);
>   }
>   
> -static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
> +static void __io_poll_execute(struct io_kiocb *req, int mask,
> +			      __poll_t __maybe_unused events)

Killing @events would add extra rebase conflicts, so left it here and will
send a clean up for 5.20.

>   {
>   	req->cqe.res = mask;
>   	/*
> @@ -6963,7 +6964,6 @@ static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
>   	 * CPU. We want to avoid pulling in req->apoll->events for that
>   	 * case.
>   	 */
> -	req->apoll_events = events;
>   	if (req->opcode == IORING_OP_POLL_ADD)
>   		req->io_task_work.func = io_poll_task_func;
>   	else
> @@ -7114,6 +7114,8 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
>   	io_init_poll_iocb(poll, mask, io_poll_wake);
>   	poll->file = req->file;
>   
> +	req->apoll_events = poll->events;
> +
>   	ipt->pt._key = mask;
>   	ipt->req = req;
>   	ipt->error = 0;
> @@ -7144,8 +7146,10 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
>   
>   	if (mask) {
>   		/* can't multishot if failed, just queue the event we've got */
> -		if (unlikely(ipt->error || !ipt->nr_entries))
> +		if (unlikely(ipt->error || !ipt->nr_entries)) {
>   			poll->events |= EPOLLONESHOT;
> +			req->apoll_events |= EPOLLONESHOT;
> +		}
>   		__io_poll_execute(req, mask, poll->events);
>   		return 0;
>   	}
> @@ -7392,7 +7396,7 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
>   		return -EINVAL;
>   
>   	io_req_set_refcount(req);
> -	req->apoll_events = poll->events = io_poll_parse_events(sqe, flags);
> +	poll->events = io_poll_parse_events(sqe, flags);
>   	return 0;
>   }
>   

-- 
Pavel Begunkov

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.19] io_uring: fix req->apoll_events
  2022-06-21 12:25 [PATCH 5.19] io_uring: fix req->apoll_events Pavel Begunkov
  2022-06-21 12:28 ` Pavel Begunkov
@ 2022-06-21 13:28 ` Hao Xu
  2022-06-21 13:49 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Hao Xu @ 2022-06-21 13:28 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring; +Cc: Jens Axboe

On 6/21/22 20:25, Pavel Begunkov wrote:
> apoll_events should be set once in the beginning of poll arming just as
> poll->events and not change after. However, currently io_uring resets it
> on each __io_poll_execute() for no clear reason. There is also a place
> in __io_arm_poll_handler() where we add EPOLLONESHOT to downgrade a
> multishot, but forget to do the same thing with ->apoll_events, which is
> buggy.
> 
> Fixes: 81459350d581e ("io_uring: cache req->apoll->events in req->cflags")
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>   fs/io_uring.c | 12 ++++++++----
>   1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 87c65a358678..ebda9a565fc0 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -6954,7 +6954,8 @@ static void io_apoll_task_func(struct io_kiocb *req, bool *locked)
>   		io_req_complete_failed(req, ret);
>   }
>   
> -static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
> +static void __io_poll_execute(struct io_kiocb *req, int mask,
> +			      __poll_t __maybe_unused events)
>   {
>   	req->cqe.res = mask;
>   	/*
> @@ -6963,7 +6964,6 @@ static void __io_poll_execute(struct io_kiocb *req, int mask, __poll_t events)
>   	 * CPU. We want to avoid pulling in req->apoll->events for that
>   	 * case.
>   	 */
> -	req->apoll_events = events;
>   	if (req->opcode == IORING_OP_POLL_ADD)
>   		req->io_task_work.func = io_poll_task_func;
>   	else
> @@ -7114,6 +7114,8 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
>   	io_init_poll_iocb(poll, mask, io_poll_wake);
>   	poll->file = req->file;
>   
> +	req->apoll_events = poll->events;
> +
>   	ipt->pt._key = mask;
>   	ipt->req = req;
>   	ipt->error = 0;
> @@ -7144,8 +7146,10 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
>   
>   	if (mask) {
>   		/* can't multishot if failed, just queue the event we've got */
> -		if (unlikely(ipt->error || !ipt->nr_entries))
> +		if (unlikely(ipt->error || !ipt->nr_entries)) {
>   			poll->events |= EPOLLONESHOT;
> +			req->apoll_events |= EPOLLONESHOT;
> +		}
>   		__io_poll_execute(req, mask, poll->events);
>   		return 0;
>   	}
> @@ -7392,7 +7396,7 @@ static int io_poll_add_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
>   		return -EINVAL;
>   
>   	io_req_set_refcount(req);
> -	req->apoll_events = poll->events = io_poll_parse_events(sqe, flags);
> +	poll->events = io_poll_parse_events(sqe, flags);
>   	return 0;
>   }
>   

Make sense,
Reviewed-by: Hao Xu <[email protected]>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.19] io_uring: fix req->apoll_events
  2022-06-21 12:25 [PATCH 5.19] io_uring: fix req->apoll_events Pavel Begunkov
  2022-06-21 12:28 ` Pavel Begunkov
  2022-06-21 13:28 ` Hao Xu
@ 2022-06-21 13:49 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2022-06-21 13:49 UTC (permalink / raw)
  To: io-uring, asml.silence

On Tue, 21 Jun 2022 13:25:06 +0100, Pavel Begunkov wrote:
> apoll_events should be set once in the beginning of poll arming just as
> poll->events and not change after. However, currently io_uring resets it
> on each __io_poll_execute() for no clear reason. There is also a place
> in __io_arm_poll_handler() where we add EPOLLONESHOT to downgrade a
> multishot, but forget to do the same thing with ->apoll_events, which is
> buggy.
> 
> [...]

Applied, thanks!

[1/1] io_uring: fix req->apoll_events
      commit: aacf2f9f382c91df73f33317e28a4c34c8038986

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-21 13:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-21 12:25 [PATCH 5.19] io_uring: fix req->apoll_events Pavel Begunkov
2022-06-21 12:28 ` Pavel Begunkov
2022-06-21 13:28 ` Hao Xu
2022-06-21 13:49 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox