[PATCH] io_uring: unregister eventfd while holding lock when freeing ring ctx

Usama Arif posted 1 patch 4 years, 4 months ago
fs/io_uring.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] io_uring: unregister eventfd while holding lock when freeing ring ctx
Posted by Usama Arif 4 years, 4 months ago
This is because ctx->io_ev_fd is rcu_dereference_protected using
ctx->uring_lock in io_eventfd_unregister. Not locking the function
resulted in suspicious RCU usage reported by kernel test robot.

Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Usama Arif <usama.arif@bytedance.com>
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index ad8f84376955..dbc9d3f3f6c5 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -9471,8 +9471,8 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
 		__io_sqe_files_unregister(ctx);
 	if (ctx->rings)
 		__io_cqring_overflow_flush(ctx, true);
-	mutex_unlock(&ctx->uring_lock);
 	io_eventfd_unregister(ctx);
+	mutex_unlock(&ctx->uring_lock);
 	io_destroy_buffers(ctx);
 	if (ctx->sq_creds)
 		put_cred(ctx->sq_creds);
-- 
2.25.1

Re: [PATCH] io_uring: unregister eventfd while holding lock when freeing ring ctx
Posted by Jens Axboe 4 years, 4 months ago
On 2/7/22 3:50 AM, Usama Arif wrote:
> This is because ctx->io_ev_fd is rcu_dereference_protected using
> ctx->uring_lock in io_eventfd_unregister. Not locking the function
> resulted in suspicious RCU usage reported by kernel test robot.

I'll fold this in with the change, thanks.

-- 
Jens Axboe