public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH for-5.15] io_uring: fix lacking of protection for compl_nr
@ 2021-08-20 18:40 Hao Xu
  2021-08-20 18:59 ` Pavel Begunkov
  0 siblings, 1 reply; 13+ messages in thread
From: Hao Xu @ 2021-08-20 18:40 UTC (permalink / raw)
  To: Jens Axboe; +Cc: io-uring, Pavel Begunkov, Joseph Qi

coml_nr in ctx_flush_and_put() is not protected by uring_lock, this
may cause problems when accessing it parallelly.

Fixes: d10299e14aae ("io_uring: inline struct io_comp_state")
Signed-off-by: Hao Xu <[email protected]>
---
 fs/io_uring.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index c755efdac71f..420f8dfa5327 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2003,11 +2003,10 @@ static void ctx_flush_and_put(struct io_ring_ctx *ctx)
 {
 	if (!ctx)
 		return;
-	if (ctx->submit_state.compl_nr) {
-		mutex_lock(&ctx->uring_lock);
+	mutex_lock(&ctx->uring_lock);
+	if (ctx->submit_state.compl_nr)
 		io_submit_flush_completions(ctx);
-		mutex_unlock(&ctx->uring_lock);
-	}
+	mutex_unlock(&ctx->uring_lock);
 	percpu_ref_put(&ctx->refs);
 }
 
-- 
2.24.4


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

end of thread, other threads:[~2021-08-21  3:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-20 18:40 [PATCH for-5.15] io_uring: fix lacking of protection for compl_nr Hao Xu
2021-08-20 18:59 ` Pavel Begunkov
2021-08-20 20:39   ` Hao Xu
2021-08-20 21:32     ` Pavel Begunkov
2021-08-20 22:07       ` Hao Xu
2021-08-20 22:09       ` Jens Axboe
2021-08-20 22:21         ` Hao Xu
2021-08-20 22:28         ` Pavel Begunkov
2021-08-20 22:30           ` Jens Axboe
2021-08-20 22:41             ` Pavel Begunkov
2021-08-20 22:46               ` Jens Axboe
2021-08-20 22:59                 ` Pavel Begunkov
2021-08-21  3:10                   ` Jens Axboe

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