2022-02-09 09:57:39

by Usama Arif

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

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 <[email protected]>
Signed-off-by: Usama Arif <[email protected]>
---
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



2022-02-09 11:46:22

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH] io_uring: unregister eventfd while holding lock when freeing ring ctx

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