Re: [PATCH v4 13/15] KVM: guest_memfd: implement userfaultfd operations

From: Sean Christopherson

Date: Mon May 18 2026 - 16:45:35 EST


On Fri, May 15, 2026, Ackerley Tng wrote:
> Sean Christopherson <seanjc@xxxxxxxxxx> writes:
>
> >
> > [...snip...]
> >
> >> +#ifdef CONFIG_USERFAULTFD
> >> +static bool kvm_gmem_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags)
> >> +{
> >> + struct inode *inode = file_inode(vma->vm_file);
> >> +
> >> + /*
> >> + * Only support userfaultfd for guest_memfd with INIT_SHARED flag.
> >> + * This ensures the memory can be mapped to userspace.
> >> + */
>
> Is the principle here that any memory that is allowed to be mapped to
> userspace can be userfault-ed?

Yes? It's more the opposite though: memory that can't be SHARED and thus can't
be mapped into userspace can't possibly support userfaultfd. Six of one, half
dozen of the other, but I think it's important to highlight that there's no
judgment call being made, i.e. we aren't deciding to support only SHARED just
because we're lazy, it's a hard requirement.