Jens Axboe <axboe@xxxxxxxxx> 于2025年4月23日周三 23:55写道: > > 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(); > +} > > -- > Jens Axboe I understand some of what you said. I was indeed lost in appearances. It's very late here now, and I'll take a deeper look tomorrow. Thank you very much.