public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 5.8] io_uring: fix missing ->mm on exit
@ 2020-08-24 20:35 Pavel Begunkov
  2020-08-24 20:40 ` Pavel Begunkov
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2020-08-24 20:35 UTC (permalink / raw)
  To: Jens Axboe, io-uring

do_exit() first drops current->mm and then runs task_work, from where
io_sq_thread_acquire_mm() would try to set mm for a user dying process.

[  208.004249] WARNING: CPU: 2 PID: 1854 at
	kernel/kthread.c:1238 kthread_use_mm+0x244/0x270
[  208.004287]  kthread_use_mm+0x244/0x270
[  208.004288]  io_sq_thread_acquire_mm.part.0+0x54/0x80
[  208.004290]  io_async_task_func+0x258/0x2ac
[  208.004291]  task_work_run+0xc8/0x210
[  208.004294]  do_exit+0x1b8/0x430
[  208.004295]  do_group_exit+0x44/0xac
[  208.004296]  get_signal+0x164/0x69c
[  208.004298]  do_signal+0x94/0x1d0
[  208.004299]  do_notify_resume+0x18c/0x340
[  208.004300]  work_pending+0x8/0x3d4

Reported-by: Roman Gershman <>
Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 493e5047e67c..a8b3a608c553 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -4313,7 +4313,8 @@ static int io_sq_thread_acquire_mm(struct io_ring_ctx *ctx,
 				   struct io_kiocb *req)
 {
 	if (io_op_defs[req->opcode].needs_mm && !current->mm) {
-		if (unlikely(!mmget_not_zero(ctx->sqo_mm)))
+		if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
+			     !mmget_not_zero(ctx->sqo_mm)))
 			return -EFAULT;
 		kthread_use_mm(ctx->sqo_mm);
 	}
-- 
2.24.0


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

* Re: [PATCH 5.8] io_uring: fix missing ->mm on exit
  2020-08-24 20:35 [PATCH 5.8] io_uring: fix missing ->mm on exit Pavel Begunkov
@ 2020-08-24 20:40 ` Pavel Begunkov
  2020-08-24 20:44   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Begunkov @ 2020-08-24 20:40 UTC (permalink / raw)
  To: Jens Axboe, io-uring

On 24/08/2020 23:35, Pavel Begunkov wrote:
> do_exit() first drops current->mm and then runs task_work, from where
> io_sq_thread_acquire_mm() would try to set mm for a user dying process.

This is a backport of [1] + [2] for 5.8. Let's wait to see if
Roman Gershman can test it.

[1] 8eb06d7e8dd85 ("io_uring: fix missing ->mm on exit")
[2] cbcf72148da4a ("io_uring: return locked and pinned page accounting")


> 
> [  208.004249] WARNING: CPU: 2 PID: 1854 at
> 	kernel/kthread.c:1238 kthread_use_mm+0x244/0x270
> [  208.004287]  kthread_use_mm+0x244/0x270
> [  208.004288]  io_sq_thread_acquire_mm.part.0+0x54/0x80
> [  208.004290]  io_async_task_func+0x258/0x2ac
> [  208.004291]  task_work_run+0xc8/0x210
> [  208.004294]  do_exit+0x1b8/0x430
> [  208.004295]  do_group_exit+0x44/0xac
> [  208.004296]  get_signal+0x164/0x69c
> [  208.004298]  do_signal+0x94/0x1d0
> [  208.004299]  do_notify_resume+0x18c/0x340
> [  208.004300]  work_pending+0x8/0x3d4
> 
> Reported-by: Roman Gershman <>
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>  fs/io_uring.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 493e5047e67c..a8b3a608c553 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -4313,7 +4313,8 @@ static int io_sq_thread_acquire_mm(struct io_ring_ctx *ctx,
>  				   struct io_kiocb *req)
>  {
>  	if (io_op_defs[req->opcode].needs_mm && !current->mm) {
> -		if (unlikely(!mmget_not_zero(ctx->sqo_mm)))
> +		if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
> +			     !mmget_not_zero(ctx->sqo_mm)))
>  			return -EFAULT;
>  		kthread_use_mm(ctx->sqo_mm);
>  	}
> 

-- 
Pavel Begunkov

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

* Re: [PATCH 5.8] io_uring: fix missing ->mm on exit
  2020-08-24 20:40 ` Pavel Begunkov
@ 2020-08-24 20:44   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-08-24 20:44 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 8/24/20 2:40 PM, Pavel Begunkov wrote:
> On 24/08/2020 23:35, Pavel Begunkov wrote:
>> do_exit() first drops current->mm and then runs task_work, from where
>> io_sq_thread_acquire_mm() would try to set mm for a user dying process.
> 
> This is a backport of [1] + [2] for 5.8. Let's wait to see if
> Roman Gershman can test it.
> 
> [1] 8eb06d7e8dd85 ("io_uring: fix missing ->mm on exit")
> [2] cbcf72148da4a ("io_uring: return locked and pinned page accounting")

Yes, would be great if we could test. And provide an email, too :-)

Once that's settled, I'll shove this to 5.8-stable.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-08-24 20:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-24 20:35 [PATCH 5.8] io_uring: fix missing ->mm on exit Pavel Begunkov
2020-08-24 20:40 ` Pavel Begunkov
2020-08-24 20:44   ` Jens Axboe

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