public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] io_uring: fix mismatched finish_wait() calls in io_uring_cancel_files()
@ 2020-04-26  7:54 Xiaoguang Wang
  2020-05-04 13:56 ` Xiaoguang Wang
  2020-05-04 15:07 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Xiaoguang Wang @ 2020-04-26  7:54 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, joseph.qi, Xiaoguang Wang

The prepare_to_wait() and finish_wait() calls in io_uring_cancel_files()
are mismatched. Currently I don't see any issues related this bug, just
find it by learning codes.

Signed-off-by: Xiaoguang Wang <[email protected]>
---
 fs/io_uring.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index c687f57fb651..2d7a8d05ab10 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7356,11 +7356,9 @@ static int io_uring_release(struct inode *inode, struct file *file)
 static void io_uring_cancel_files(struct io_ring_ctx *ctx,
 				  struct files_struct *files)
 {
-	struct io_kiocb *req;
-	DEFINE_WAIT(wait);
-
 	while (!list_empty_careful(&ctx->inflight_list)) {
-		struct io_kiocb *cancel_req = NULL;
+		struct io_kiocb *cancel_req = NULL, *req;
+		DEFINE_WAIT(wait);
 
 		spin_lock_irq(&ctx->inflight_lock);
 		list_for_each_entry(req, &ctx->inflight_list, inflight_entry) {
@@ -7400,6 +7398,7 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
 			 */
 			if (refcount_sub_and_test(2, &cancel_req->refs)) {
 				io_put_req(cancel_req);
+				finish_wait(&ctx->inflight_wait, &wait);
 				continue;
 			}
 		}
@@ -7407,8 +7406,8 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
 		io_wq_cancel_work(ctx->io_wq, &cancel_req->work);
 		io_put_req(cancel_req);
 		schedule();
+		finish_wait(&ctx->inflight_wait, &wait);
 	}
-	finish_wait(&ctx->inflight_wait, &wait);
 }
 
 static int io_uring_flush(struct file *file, void *data)
-- 
2.17.2


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

* Re: [PATCH] io_uring: fix mismatched finish_wait() calls in io_uring_cancel_files()
  2020-04-26  7:54 [PATCH] io_uring: fix mismatched finish_wait() calls in io_uring_cancel_files() Xiaoguang Wang
@ 2020-05-04 13:56 ` Xiaoguang Wang
  2020-05-04 15:07 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Xiaoguang Wang @ 2020-05-04 13:56 UTC (permalink / raw)
  To: io-uring; +Cc: axboe, joseph.qi

hi,

Ping.

Regards,
Xiaoguang Wang
> The prepare_to_wait() and finish_wait() calls in io_uring_cancel_files()
> are mismatched. Currently I don't see any issues related this bug, just
> find it by learning codes.
> 
> Signed-off-by: Xiaoguang Wang <[email protected]>
> ---
>   fs/io_uring.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index c687f57fb651..2d7a8d05ab10 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -7356,11 +7356,9 @@ static int io_uring_release(struct inode *inode, struct file *file)
>   static void io_uring_cancel_files(struct io_ring_ctx *ctx,
>   				  struct files_struct *files)
>   {
> -	struct io_kiocb *req;
> -	DEFINE_WAIT(wait);
> -
>   	while (!list_empty_careful(&ctx->inflight_list)) {
> -		struct io_kiocb *cancel_req = NULL;
> +		struct io_kiocb *cancel_req = NULL, *req;
> +		DEFINE_WAIT(wait);
>   
>   		spin_lock_irq(&ctx->inflight_lock);
>   		list_for_each_entry(req, &ctx->inflight_list, inflight_entry) {
> @@ -7400,6 +7398,7 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
>   			 */
>   			if (refcount_sub_and_test(2, &cancel_req->refs)) {
>   				io_put_req(cancel_req);
> +				finish_wait(&ctx->inflight_wait, &wait);
>   				continue;
>   			}
>   		}
> @@ -7407,8 +7406,8 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
>   		io_wq_cancel_work(ctx->io_wq, &cancel_req->work);
>   		io_put_req(cancel_req);
>   		schedule();
> +		finish_wait(&ctx->inflight_wait, &wait);
>   	}
> -	finish_wait(&ctx->inflight_wait, &wait);
>   }
>   
>   static int io_uring_flush(struct file *file, void *data)
> 

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

* Re: [PATCH] io_uring: fix mismatched finish_wait() calls in io_uring_cancel_files()
  2020-04-26  7:54 [PATCH] io_uring: fix mismatched finish_wait() calls in io_uring_cancel_files() Xiaoguang Wang
  2020-05-04 13:56 ` Xiaoguang Wang
@ 2020-05-04 15:07 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-05-04 15:07 UTC (permalink / raw)
  To: Xiaoguang Wang, io-uring; +Cc: joseph.qi

On 4/26/20 1:54 AM, Xiaoguang Wang wrote:
> The prepare_to_wait() and finish_wait() calls in io_uring_cancel_files()
> are mismatched. Currently I don't see any issues related this bug, just
> find it by learning codes.

Applied, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-05-04 15:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-26  7:54 [PATCH] io_uring: fix mismatched finish_wait() calls in io_uring_cancel_files() Xiaoguang Wang
2020-05-04 13:56 ` Xiaoguang Wang
2020-05-04 15:07 ` Jens Axboe

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