Skip to contentSkip to conversation

Misc minor tctx fixes

PATCH In review Jens Axboe 2 participants 5 messages Apr 16 – Apr 20 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

cover Misc minor tctx fixes

Hi,

Just two small fixes for issues introduced in this merge window.

Signature · 1 line
Jens Axboe
author maintainer
#1 lore raw

PATCH 1/2 io_uring/tctx: check for setup tctx->io_wq before teardown

As with the idling code before it, the error exit path should check for a NULL tctx->io_wq before calling io_wq_put_and_exit().

Fixes 7880174e1e5e ("io_uring/tctx: clean up __io_uring_add_tctx_node() error handling")
---
 io_uring/tctx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
io_uring/tctx.c +2 -1
index 61533f30494f..c011a593c0ad 100644
@@ -171,7 +171,8 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
 	}
 	if (!current->io_uring) {
 err_free:
-		io_wq_put_and_exit(tctx->io_wq);
+		if (tctx->io_wq)
+			io_wq_put_and_exit(tctx->io_wq);
 		percpu_counter_destroy(&tctx->inflight);
 		kfree(tctx);
 	}
Signature · 1 line
2.53.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] io_uring/tctx: check for setup tctx->io_wq before teardown

Quoted 16 lines · Jens Axboe
Quoted 1 line

As with the idling code before it, the error exit path should check for a NULL tctx->io_wq before calling io_wq_put_and_exit().

Fixes 7880174e1e5e ("io_uring/tctx: clean up __io_uring_add_tctx_node() error handling")
---
  io_uring/tctx.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
io_uring/tctx.c +0 -0
index 61533f30494f..c011a593c0ad 100644

io_uring/tctx.c int __io_uring_add_tctx_node(struct io_ring_ctx *ctx) · line 178

Quoted 9 lines
io_uring/tctx.c +2 -1
@@ -171,7 +171,8 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
  	}
  	if (!current->io_uring) {
  err_free:
-		io_wq_put_and_exit(tctx->io_wq);
+		if (tctx->io_wq)
+			io_wq_put_and_exit(tctx->io_wq);
  		percpu_counter_destroy(&tctx->inflight);
  		kfree(tctx);
  	}

Hi Jens,

LGTM,

Thanks,

Clément

author maintainer
#3 lore raw

PATCH 2/2 io_uring/tctx: mark io_wq as exiting before error path teardown

In reply to Jens Axboe

syzbot reports that it's hitting the below condition for exiting an io_wq context:

WARN_ON_ONCE(!test_bit(IO_WQ_BIT_EXIT, &wq->state))

in io_wq_put_and_exit(), which can be triggered with memory allocation fault injection. Ensure that the io_wq is marked as exiting to silence this warning trigger.

Reported-by [email protected]
Fixes 7880174e1e5e ("io_uring/tctx: clean up __io_uring_add_tctx_node() error handling")
---
 io_uring/tctx.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
io_uring/tctx.c +3 -1
index c011a593c0ad..80366320276d 100644
@@ -171,8 +171,10 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
 	}
 	if (!current->io_uring) {
 err_free:
-		if (tctx->io_wq)
+		if (tctx->io_wq) {
+			io_wq_exit_start(tctx->io_wq);
 			io_wq_put_and_exit(tctx->io_wq);
+		}
 		percpu_counter_destroy(&tctx->inflight);
 		kfree(tctx);
 	}
Signature · 1 line
2.53.0
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] io_uring/tctx: mark io_wq as exiting before error path teardown

Quoted 23 lines · Jens Axboe
Quoted 1 line

syzbot reports that it's hitting the below condition for exiting an io_wq context:

WARN_ON_ONCE(!test_bit(IO_WQ_BIT_EXIT, &wq->state))

in io_wq_put_and_exit(), which can be triggered with memory allocation fault injection. Ensure that the io_wq is marked as exiting to silence this warning trigger.

Reported-by [email protected]
Fixes 7880174e1e5e ("io_uring/tctx: clean up __io_uring_add_tctx_node() error handling")
---
  io_uring/tctx.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
io_uring/tctx.c +0 -0
index c011a593c0ad..80366320276d 100644
@@ -171,8 +171,10 @@ int __io_uring_add_tctx_node(struct io_ring_ctx *ctx)
  	}

io_uring/tctx.c int __io_uring_add_tctx_node(struct io_ring_ctx *ctx) · line 180

Quoted 10 lines
io_uring/tctx.c +3 -1
  	if (!current->io_uring) {
  err_free:
-		if (tctx->io_wq)
+		if (tctx->io_wq) {
+			io_wq_exit_start(tctx->io_wq);
  			io_wq_put_and_exit(tctx->io_wq);
+		}
  		percpu_counter_destroy(&tctx->inflight);
  		kfree(tctx);
  	}

Hi Jens,

LGTM as well,

Thanks,

Clément