From: Jens Axboe <axboe@kernel.dk>
To: "Pavel Begunkov" <asml.silence@gmail.com>, 姜智伟 <qq282012236@gmail.com>
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
akpm@linux-foundation.org, peterx@redhat.com,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, io-uring@vger.kernel.org
Subject: Re: [PATCH v2 1/2] io_uring: Add new functions to handle user fault scenarios
Date: Wed, 23 Apr 2025 10:23:12 -0600 [thread overview]
Message-ID: <4ec65451-d183-453e-a873-97b4abb4f884@kernel.dk> (raw)
In-Reply-To: <00c7d434-d923-4b91-8ad0-5f3c8e0c6465@gmail.com>
On 4/23/25 10:17 AM, Pavel Begunkov wrote:
> On 4/23/25 16:55, Jens Axboe wrote:
>> Something like this, perhaps - it'll ensure that io-wq workers get a
>> chance to flush out pending work, which should prevent the looping. I've
>> attached a basic test case. It'll issue a write that will fault, and
>> then try and cancel that as a way to trigger the TIF_NOTIFY_SIGNAL based
>> looping.
>>
>> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
>> index d80f94346199..e18926dbf20a 100644
>> --- a/fs/userfaultfd.c
>> +++ b/fs/userfaultfd.c
>> @@ -32,6 +32,7 @@
>> #include <linux/swapops.h>
>> #include <linux/miscdevice.h>
>> #include <linux/uio.h>
>> +#include <linux/io_uring.h>
>> static int sysctl_unprivileged_userfaultfd __read_mostly;
>> @@ -376,6 +377,8 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason)
>> */
>> if (current->flags & (PF_EXITING|PF_DUMPCORE))
>> goto out;
>> + else if (current->flags & PF_IO_WORKER)
>> + io_worker_fault();
>> assert_fault_locked(vmf);
>> diff --git a/include/linux/io_uring.h b/include/linux/io_uring.h
>> index 85fe4e6b275c..d93dd7402a28 100644
>> --- a/include/linux/io_uring.h
>> +++ b/include/linux/io_uring.h
>> @@ -28,6 +28,7 @@ static inline void io_uring_free(struct task_struct *tsk)
>> if (tsk->io_uring)
>> __io_uring_free(tsk);
>> }
>> +void io_worker_fault(void);
>> #else
>> static inline void io_uring_task_cancel(void)
>> {
>> @@ -46,6 +47,9 @@ static inline bool io_is_uring_fops(struct file *file)
>> {
>> return false;
>> }
>> +static inline void io_worker_fault(void)
>> +{
>> +}
>> #endif
>> #endif
>> diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
>> index d52069b1177b..f74bea028ec7 100644
>> --- a/io_uring/io-wq.c
>> +++ b/io_uring/io-wq.c
>> @@ -1438,3 +1438,13 @@ static __init int io_wq_init(void)
>> return 0;
>> }
>> subsys_initcall(io_wq_init);
>> +
>> +void io_worker_fault(void)
>> +{
>> + if (test_thread_flag(TIF_NOTIFY_SIGNAL))
>> + clear_notify_signal();
>> + if (test_thread_flag(TIF_NOTIFY_RESUME))
>> + resume_user_mode_work(NULL);
>> + if (task_work_pending(current))
>> + task_work_run();
>
> Looking at the stacktrace, that sounds dangerous
>
> iou-wrk-44588 [kernel.kallsyms] [k] io_wq_worker
> iou-wrk-44588 [kernel.kallsyms] [k] io_worker_handle_work
> iou-wrk-44588 [kernel.kallsyms] [k] io_wq_submit_work
> iou-wrk-44588 [kernel.kallsyms] [k] io_issue_sqe
> iou-wrk-44588 [kernel.kallsyms] [k] io_write
> iou-wrk-44588 [kernel.kallsyms] [k] blkdev_write_iter
> iou-wrk-44588 [kernel.kallsyms] [k] iomap_file_buffered_write
> iou-wrk-44588 [kernel.kallsyms] [k] iomap_write_iter
> iou-wrk-44588 [kernel.kallsyms] [k] fault_in_iov_iter_readable
> iou-wrk-44588 [kernel.kallsyms] [k] fault_in_readable
> iou-wrk-44588 [kernel.kallsyms] [k] asm_exc_page_fault
> iou-wrk-44588 [kernel.kallsyms] [k] exc_page_fault
> iou-wrk-44588 [kernel.kallsyms] [k] do_user_addr_fault
> iou-wrk-44588 [kernel.kallsyms] [k] handle_mm_fault
> iou-wrk-44588 [kernel.kallsyms] [k] hugetlb_fault
> iou-wrk-44588 [kernel.kallsyms] [k] hugetlb_no_page
> iou-wrk-44588 [kernel.kallsyms] [k] hugetlb_handle_userfault
> iou-wrk-44588 [kernel.kallsyms] [k] handle_userfault
>
> It might be holding a good bunch of locks, and then it's trapped
> in a page fault handler. Do normal / non-PF_IO_WORKER tasks run
> task_work from handle_userfault?
Yeah, it's really just a test patch. Ideally we want this to do the
usual thing, which is fall back and let it retry, where we can handle
all of this too.
--
Jens Axboe
next prev parent reply other threads:[~2025-04-23 16:23 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 16:29 [PATCH v2 0/2] Fix 100% CPU usage issue in IOU worker threads Zhiwei Jiang
2025-04-22 16:29 ` [PATCH v2 1/2] io_uring: Add new functions to handle user fault scenarios Zhiwei Jiang
2025-04-22 16:32 ` Jens Axboe
2025-04-22 17:04 ` 姜智伟
2025-04-22 17:33 ` Jens Axboe
2025-04-23 2:49 ` 姜智伟
2025-04-23 3:11 ` 姜智伟
2025-04-23 6:22 ` 姜智伟
2025-04-23 13:34 ` Jens Axboe
2025-04-23 14:29 ` 姜智伟
2025-04-23 15:10 ` Jens Axboe
2025-04-23 18:55 ` Jens Axboe
2025-04-23 15:55 ` Jens Axboe
2025-04-23 16:07 ` 姜智伟
2025-04-23 16:17 ` Pavel Begunkov
2025-04-23 16:23 ` Jens Axboe [this message]
2025-04-23 22:57 ` Jens Axboe
2025-04-24 14:08 ` 姜智伟
2025-04-24 14:13 ` Jens Axboe
2025-04-24 14:45 ` 姜智伟
2025-04-24 14:52 ` Jens Axboe
2025-04-24 15:12 ` 姜智伟
2025-04-24 15:21 ` Jens Axboe
2025-04-24 15:51 ` 姜智伟
2025-04-22 16:29 ` [PATCH v2 2/2] userfaultfd: Set the corresponding flag in IOU worker context Zhiwei Jiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ec65451-d183-453e-a873-97b4abb4f884@kernel.dk \
--to=axboe@kernel.dk \
--cc=akpm@linux-foundation.org \
--cc=asml.silence@gmail.com \
--cc=brauner@kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=qq282012236@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox