Re: [PATCH v3 01/11] KVM: arm64: guest_memfd: Check mmap support when preparing memslot

From: Sean Christopherson

Date: Tue Dec 01 2026 - 20:09:36 EST


On Mon, Nov 23, 2026, Suzuki K Poulose wrote:
> On 19/11/2026 14:54, Sean Christopherson wrote:
> > On Thu, Nov 19, 2026, Suzuki K Poulose wrote:
> > > I see, thanks Steven. For context:
> > >
> > > Arm64 currently (without inplace conversion support) only allows GMEM
> > > with MMAP flags only and relies on kvm_slot_gmem_only() to detect that
> > > the GMEM has MMAP flag. But, when we enable inplace conversion,
> > > we can't reliably reject the slots by kvm_slot_gmem_only(), because
> > > all GMEM slots are marked GMEM only with inplace conversion.
> > >
> > > Also, from the API Documentation,
> > >
> > > "When the KVM MMU performs a PFN lookup to service a guest fault, the fault
> > > will always be consumed from guest_memfd, regardless of whether it is a shared
> > > or a private fault (unless in-place conversion is disabled and the backing
> > > guest_memfd does not have the GUEST_MEMFD_FLAG_MMAP flag set)."
>
> > > So, in effect, with in-place conversion enabled a KVM_CREATE_GUEST_MEMFD
> > > without GUEST_MEMFD_FLAG_MMAP is an error
> >
> > It's only an error if (a) the userspace address in the memslot points at the
> > gmem fd and
>
> I don't understand this part. With inplace conversion, we mark the slot
> as GMEM_ONLY and always resolve shared faults from the gmem (on arm64
> as described by the API). So, isn't it a usage error from the VMM if it
> plans to use GUEST_MEMFD_FLAG_MMAP=false with inplace conversion ?

Sure, but KVM isn't the usage police. Critically, KVM can't know what the VMM
*intends*, KVM only knows what the VMM has actually done.

> In other words, do you mean to say, passing a non-gmem fd userspace address
> is fine with GUEST_MEMFD_FLAG_MMAP=false ?

Yes. arm64 is relatively unique in that it does VMA lookups when handling faults,
most other architectures don't care. E.g. x86 cares only what's mapped into the
userspace page tables, and doesn't try to enforce anything at a VMA level.

> But the API documentation

I don't see any contradiction. The blurb you quote above specifically talks about
guest faults, and KVM *does* go straight to gmem for those. KVM accesses to guest
memory aren't guest faults, so that above blurb doesn't apply.

> and the GMEM_ONLY flags contradict the usage.

GMEM_ONLY is a KVM-internal thing, and is slightly misnamed. It's really
KVM_MMU_CAN_GET_PFNS_FROM_GMEM or something like that.

> Now, should we reject that in KVM or not is the secondary question.

No, because we risk disallowing legitimate (if unusual) setups that KVM can handle
just fine.