Skip to contentSkip to conversation

io_uring: add lockdep checks for io_handle_tw_list

PATCH In review Pavel Begunkov 2 participants 4 messages Apr 1, 2025 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io_uring: add lockdep checks for io_handle_tw_list

Add a lockdep check to io_handle_tw_list() verifying that the context is locked and no task work drops it by accident.

---
 io_uring/io_uring.c | 4 ++++
 1 file changed, 4 insertions(+)
io_uring/io_uring.c +4 -0
index 6df996d01ccf..13e0b48d1aac 100644
@@ -1054,6 +1054,10 @@ struct llist_node *io_handle_tw_list(struct llist_node *node,
 			mutex_lock(&ctx->uring_lock);
 			percpu_ref_get(&ctx->refs);
 		}
+
+		lockdep_assert(req->ctx == ctx);
+		lockdep_assert_held(&ctx->uring_lock);
+
 		INDIRECT_CALL_2(req->io_task_work.func,
 				io_poll_task_func, io_req_rw_complete,
 				req, ts);
Signature · 1 line
2.48.1
maintainer
#1 lore raw
Quoted 2 lines · Pavel Begunkov

Add a lockdep check to io_handle_tw_list() verifying that the context is locked and no task work drops it by accident.

I think we'd want a bit more of a "why" explanation here, but I can add that while committing.

Quoted 5 lines
io_uring/io_uring.c +0 -0
index 6df996d01ccf..13e0b48d1aac 100644

io_uring/io_uring.c struct llist_node *io_handle_tw_list(struct llist_node *node, · line 1063

Quoted 10 lines
io_uring/io_uring.c +4 -0
@@ -1054,6 +1054,10 @@ struct llist_node *io_handle_tw_list(struct llist_node *node,
 			mutex_lock(&ctx->uring_lock);
 			percpu_ref_get(&ctx->refs);
 		}
+
+		lockdep_assert(req->ctx == ctx);
+		lockdep_assert_held(&ctx->uring_lock);
+
 		INDIRECT_CALL_2(req->io_task_work.func,
 				io_poll_task_func, io_req_rw_complete,
 				req, ts);

If the assumption is that some previous tw messed things up, might not be a bad idea to include dumping of that if one of the above lockdep asserts fail? Preferably in such a way that code generation is the same when lockdep isn't set...

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 19 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov

Add a lockdep check to io_handle_tw_list() verifying that the context is locked and no task work drops it by accident.

I think we'd want a bit more of a "why" explanation here, but I can add that while committing.

Quoted 12 lines
io_uring/io_uring.c +4 -0
index 6df996d01ccf..13e0b48d1aac 100644
@@ -1054,6 +1054,10 @@ struct llist_node *io_handle_tw_list(struct llist_node *node,
  			mutex_lock(&ctx->uring_lock);
  			percpu_ref_get(&ctx->refs);
  		}
+
+		lockdep_assert(req->ctx == ctx);
+		lockdep_assert_held(&ctx->uring_lock);
+
Quoted 8 lines

io_uring/io_uring.c struct llist_node *io_handle_tw_list(struct llist_node *node, · line 1063

Quoted 3 lines
io_uring/io_uring.c +0 -0
  		INDIRECT_CALL_2(req->io_task_work.func,
  				io_poll_task_func, io_req_rw_complete,
  				req, ts);

If the assumption is that some previous tw messed things up, might not be a bad idea to include dumping of that if one of the above lockdep asserts fail? Preferably in such a way that code generation is the same when lockdep isn't set...

We can move it after the tw run where it still has the request (but doesn't own it).

Signature · 1 line
Pavel Begunkov
maintainer
#3 lore raw
Quoted 29 lines · Pavel Begunkov
Quoted 19 lines · Jens Axboe
Quoted 2 lines · Pavel Begunkov

Add a lockdep check to io_handle_tw_list() verifying that the context is locked and no task work drops it by accident.

I think we'd want a bit more of a "why" explanation here, but I can add that while committing.

Quoted 12 lines
io_uring/io_uring.c +4 -0
index 6df996d01ccf..13e0b48d1aac 100644
@@ -1054,6 +1054,10 @@ struct llist_node *io_handle_tw_list(struct llist_node *node,
              mutex_lock(&ctx->uring_lock);
              percpu_ref_get(&ctx->refs);
          }
+
+        lockdep_assert(req->ctx == ctx);
+        lockdep_assert_held(&ctx->uring_lock);
+
Quoted 8 lines

io_uring/io_uring.c struct llist_node *io_handle_tw_list(struct llist_node *node, · line 1063

Quoted 3 lines
io_uring/io_uring.c +0 -0
          INDIRECT_CALL_2(req->io_task_work.func,
                  io_poll_task_func, io_req_rw_complete,
                  req, ts);

If the assumption is that some previous tw messed things up, might not be a bad idea to include dumping of that if one of the above lockdep asserts fail? Preferably in such a way that code generation is the same when lockdep isn't set...

Quoted 2 lines

We can move it after the tw run where it still has the request (but doesn't own it).

Yep let's do that, but it'd still be nice to dump what func is if it ends up triggering.

Signature · 1 line
Jens Axboe