Patch "io_uring: fix race between poll completion and cancel_hash insertion" has been added to the 5.14-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    io_uring: fix race between poll completion and cancel_hash insertion

to the 5.14-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     io_uring-fix-race-between-poll-completion-and-cancel.patch
and it can be found in the queue-5.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 2463ccfa8ddbfb67c569038aae873daa937c4319
Author: Hao Xu <haoxu@xxxxxxxxxxxxxxxxx>
Date:   Wed Sep 22 18:12:36 2021 +0800

    io_uring: fix race between poll completion and cancel_hash insertion
    
    [ Upstream commit bd99c71bd14072ce2920f6d0c2fe43df072c653c ]
    
    If poll arming and poll completion runs in parallel, there maybe races.
    For instance, run io_poll_add in iowq and io_poll_task_func in original
    context, then:
    
      iowq                                      original context
      io_poll_add
        vfs_poll
         (interruption happens
          tw queued to original
          context)                              io_poll_task_func
                                                  generate cqe
                                                  del from cancel_hash[]
        if !poll.done
          insert to cancel_hash[]
    
    The entry left in cancel_hash[], similar case for fast poll.
    Fix it by set poll.done = true when del from cancel_hash[].
    
    Fixes: 5082620fb2ca ("io_uring: terminate multishot poll for CQ ring overflow")
    Signed-off-by: Hao Xu <haoxu@xxxxxxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20210922101238.7177-2-haoxu@xxxxxxxxxxxxxxxxx
    Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 754d59f734d8..27a1c813f1e1 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4968,10 +4968,8 @@ static bool io_poll_complete(struct io_kiocb *req, __poll_t mask)
 	}
 	if (req->poll.events & EPOLLONESHOT)
 		flags = 0;
-	if (!io_cqring_fill_event(ctx, req->user_data, error, flags)) {
-		req->poll.done = true;
+	if (!io_cqring_fill_event(ctx, req->user_data, error, flags))
 		flags = 0;
-	}
 	if (flags & IORING_CQE_F_MORE)
 		ctx->cq_extra++;
 
@@ -4993,6 +4991,7 @@ static void io_poll_task_func(struct io_kiocb *req)
 		if (done) {
 			io_poll_remove_double(req);
 			hash_del(&req->hash_node);
+			req->poll.done = true;
 		} else {
 			req->result = 0;
 			add_wait_queue(req->poll.head, &req->poll.wait);
@@ -5126,6 +5125,7 @@ static void io_async_task_func(struct io_kiocb *req)
 
 	hash_del(&req->hash_node);
 	io_poll_remove_double(req);
+	apoll->poll.done = true;
 	spin_unlock_irq(&ctx->completion_lock);
 
 	if (!READ_ONCE(apoll->poll.canceled))



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux