public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior
@ 2021-03-07 10:54 Stefan Metzmacher
  2021-03-07 10:54 ` [PATCH 1/2] io_uring: run __io_sq_thread() with the initial creds from io_uring_setup() Stefan Metzmacher
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stefan Metzmacher @ 2021-03-07 10:54 UTC (permalink / raw)
  To: io-uring

Hi Jens,

I guess on top of your "io-wq: always track creds for async issue"
we want to following to patches in order to restore the sq_thread
behavior of 5.11 (and older) with IORING_SETUP_ATTACH_WQ.

- io_uring: run __io_sq_thread() with the initial creds
- io_uring: kill io_sq_thread_fork() and return -EOWNERDEAD
- io_
I've not tested them, but they compile and as far as I read the
5.11 code, they should restore the old behavior.

metze


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] io_uring: run __io_sq_thread() with the initial creds from io_uring_setup()
  2021-03-07 10:54 [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior Stefan Metzmacher
@ 2021-03-07 10:54 ` Stefan Metzmacher
  2021-03-07 10:54 ` [PATCH 2/2] io_uring: kill io_sq_thread_fork() and return -EOWNERDEAD if the sq_thread is gone Stefan Metzmacher
  2021-03-07 20:07 ` [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Metzmacher @ 2021-03-07 10:54 UTC (permalink / raw)
  To: io-uring; +Cc: Stefan Metzmacher

With IORING_SETUP_ATTACH_WQ we should let __io_sq_thread() use the
initial creds from each ctx.

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 fs/io_uring.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 3b8838123cc5..133b52a9a768 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -380,6 +380,7 @@ struct io_ring_ctx {
 	/* Only used for accounting purposes */
 	struct mm_struct	*mm_account;
 
+	const struct cred	*sq_creds;	/* cred used for __io_sq_thread() */
 	struct io_sq_data	*sq_data;	/* if using sq thread polling */
 
 	struct wait_queue_head	sqo_sq_wait;
@@ -6719,7 +6720,13 @@ static int io_sq_thread(void *data)
 		sqt_spin = false;
 		cap_entries = !list_is_singular(&sqd->ctx_list);
 		list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
+			const struct cred *creds = NULL;
+
+			if (ctx->sq_creds != current_cred())
+				creds = override_creds(ctx->sq_creds);
 			ret = __io_sq_thread(ctx, cap_entries);
+			if (creds)
+				revert_creds(creds);
 			if (!sqt_spin && (ret > 0 || !list_empty(&ctx->iopoll_list)))
 				sqt_spin = true;
 		}
@@ -7150,6 +7157,8 @@ static void io_sq_thread_finish(struct io_ring_ctx *ctx)
 
 		io_put_sq_data(sqd);
 		ctx->sq_data = NULL;
+		if (ctx->sq_creds)
+			put_cred(ctx->sq_creds);
 	}
 }
 
@@ -7888,6 +7897,7 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
 			goto err;
 		}
 
+		ctx->sq_creds = get_current_cred();
 		ctx->sq_data = sqd;
 		io_sq_thread_park(sqd);
 		mutex_lock(&sqd->ctx_lock);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] io_uring: kill io_sq_thread_fork() and return -EOWNERDEAD if the sq_thread is gone
  2021-03-07 10:54 [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior Stefan Metzmacher
  2021-03-07 10:54 ` [PATCH 1/2] io_uring: run __io_sq_thread() with the initial creds from io_uring_setup() Stefan Metzmacher
@ 2021-03-07 10:54 ` Stefan Metzmacher
  2021-03-07 20:07 ` [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Metzmacher @ 2021-03-07 10:54 UTC (permalink / raw)
  To: io-uring; +Cc: Stefan Metzmacher

Signed-off-by: Stefan Metzmacher <[email protected]>
---
 fs/io_uring.c | 31 +++----------------------------
 1 file changed, 3 insertions(+), 28 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 133b52a9a768..6487f9b2c3a7 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -336,7 +336,6 @@ struct io_ring_ctx {
 		unsigned int		drain_next: 1;
 		unsigned int		eventfd_async: 1;
 		unsigned int		restricted: 1;
-		unsigned int		sqo_exec: 1;
 
 		/*
 		 * Ring buffer of indices into array of io_uring_sqe, which is
@@ -6786,7 +6785,6 @@ static int io_sq_thread(void *data)
 
 	sqd->thread = NULL;
 	list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
-		ctx->sqo_exec = 1;
 		io_ring_set_wakeup_flag(ctx);
 	}
 
@@ -7844,26 +7842,6 @@ void __io_uring_free(struct task_struct *tsk)
 	tsk->io_uring = NULL;
 }
 
-static int io_sq_thread_fork(struct io_sq_data *sqd, struct io_ring_ctx *ctx)
-{
-	struct task_struct *tsk;
-	int ret;
-
-	clear_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state);
-	reinit_completion(&sqd->parked);
-	ctx->sqo_exec = 0;
-	sqd->task_pid = current->pid;
-	tsk = create_io_thread(io_sq_thread, sqd, NUMA_NO_NODE);
-	if (IS_ERR(tsk))
-		return PTR_ERR(tsk);
-	ret = io_uring_alloc_task_context(tsk, ctx);
-	if (ret)
-		set_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state);
-	sqd->thread = tsk;
-	wake_up_new_task(tsk);
-	return ret;
-}
-
 static int io_sq_offload_create(struct io_ring_ctx *ctx,
 				struct io_uring_params *p)
 {
@@ -9197,13 +9175,10 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
 	if (ctx->flags & IORING_SETUP_SQPOLL) {
 		io_cqring_overflow_flush(ctx, false, NULL, NULL);
 
-		if (unlikely(ctx->sqo_exec)) {
-			ret = io_sq_thread_fork(ctx->sq_data, ctx);
-			if (ret)
-				goto out;
-			ctx->sqo_exec = 0;
-		}
 		ret = -EOWNERDEAD;
+		if (unlikely(ctx->sq_data->thread == NULL)) {
+			goto out;
+		}
 		if (flags & IORING_ENTER_SQ_WAKEUP)
 			wake_up(&ctx->sq_data->wait);
 		if (flags & IORING_ENTER_SQ_WAIT) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior
  2021-03-07 10:54 [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior Stefan Metzmacher
  2021-03-07 10:54 ` [PATCH 1/2] io_uring: run __io_sq_thread() with the initial creds from io_uring_setup() Stefan Metzmacher
  2021-03-07 10:54 ` [PATCH 2/2] io_uring: kill io_sq_thread_fork() and return -EOWNERDEAD if the sq_thread is gone Stefan Metzmacher
@ 2021-03-07 20:07 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2021-03-07 20:07 UTC (permalink / raw)
  To: Stefan Metzmacher, io-uring

On 3/7/21 3:54 AM, Stefan Metzmacher wrote:
> Hi Jens,
> 
> I guess on top of your "io-wq: always track creds for async issue"
> we want to following to patches in order to restore the sq_thread
> behavior of 5.11 (and older) with IORING_SETUP_ATTACH_WQ.
> 
> - io_uring: run __io_sq_thread() with the initial creds
> - io_uring: kill io_sq_thread_fork() and return -EOWNERDEAD
> - io_
> I've not tested them, but they compile and as far as I read the
> 5.11 code, they should restore the old behavior.

Thanks this looks good, I'll apply them. There's really no point
to the fork handling of SQPOLL anymore, since the unshare code
went away.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-07 20:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-07 10:54 [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior Stefan Metzmacher
2021-03-07 10:54 ` [PATCH 1/2] io_uring: run __io_sq_thread() with the initial creds from io_uring_setup() Stefan Metzmacher
2021-03-07 10:54 ` [PATCH 2/2] io_uring: kill io_sq_thread_fork() and return -EOWNERDEAD if the sq_thread is gone Stefan Metzmacher
2021-03-07 20:07 ` [PATCH 5.12 0/2] Restore sq_thread 5.11 behavior Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox