Re: Using userfaultfd with KVM's async page fault handling causes processes to hung waiting for mmap_lock to be released

From: Peter Xu
Date: Thu Jul 20 2023 - 16:08:49 EST


On Thu, Jul 20, 2023 at 06:35:34PM +0800, Hillf Danton wrote:
> On Wed, Jul 19, 2023 at 2:16 PM Axel Rasmussen <axelrasmussen@xxxxxxxxxx> wrote:
> >
> > I think perhaps the right thing to do is to have handle_userfault() release
> > mmap_lock when it returns VM_FAULT_NOPAGE, and to have GUP deal with that
> > appropriately? But, some investigation is required to be sure that's okay to do
> > in the other non-GUP ways we can end up in handle_userfault().
>
> See if making kworker special works.
>
> --- x/fs/userfaultfd.c
> +++ y/fs/userfaultfd.c
> @@ -457,6 +457,8 @@ vm_fault_t handle_userfault(struct vm_fa
> * close the uffd.
> */
> ret = VM_FAULT_NOPAGE;
> + if (current->flags & PF_WQ_WORKER)
> + ret = VM_FAULT_OOM;
> goto out;
> }

Sorry this won't work - we need userfault to work with all forms of
kworkers, especially including kvm async pf. Thanks.

--
Peter Xu