From: Steven Price <steven.price@arm.com>
To: Ackerley Tng <ackerleytng@google.com>,
sashiko-reviews@lists.linux.dev, kvm@vger.kernel.org,
kvmarm@lists.linux.dev
Cc: Oliver Upton <oupton@kernel.org>, Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH v4 01/11] KVM: arm64: guest_memfd: Check mmap support when preparing memslot
Date: Wed, 25 Nov 2026 11:31:00 +0000 [thread overview]
Message-ID: <10b37dd6-a32b-46bb-8629-347805edb9d3@arm.com> (raw)
In-Reply-To: <CAEvNRgGU+z609edF+Mw8xQ0NDUDKn9jjxJjJWTyUqJ0N2BGEHQ@mail.gmail.com>
On 24/11/2026 23:30, Ackerley Tng wrote:
> sashiko-bot@kernel.org writes:
>
>> Thank you for your contribution! Sashiko AI review found 1 potential
>> issue to consider:
>> - [Medium] KVM: arm64: kvm_arch_prepare_memory_region() rejects non-mmap
>> guest_memfd
>> --
>>
>> commit a0665f8dc612d05686ef019cc8462841573fe88c
>> Author: Steven Price <steven.price@arm.com>
>>
>> KVM: arm64: guest_memfd: Check mmap support when preparing memslot
>>
>> This commit introduces kvm_gmem_slot_supports_mmap() and uses it in
>> kvm_arch_prepare_memory_region() to require that all guest_memfd-backed
>> memslots on arm64 come from files created with GUEST_MEMFD_FLAG_MMAP.
>>
>>> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
>>> index 1db10d8d6db73..2825fccd2a197 100644
>>> --- a/arch/arm64/kvm/mmu.c
>>> +++ b/arch/arm64/kvm/mmu.c
>>> @@ -2839,10 +2839,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
>>> return -EFAULT;
>>>
>>> /*
>>> - * Only support guest_memfd backed memslots with mappable memory, since
>>> - * there aren't any CoCo VMs that support only private memory on arm64.
>>> + * All VMs need mappable guest_memfd memory, as the memslot's HVA may be
>>> + * used to access shared memory even if guest faults use guest_memfd.
>>> */
>>> - if (kvm_slot_has_gmem(new) && !kvm_memslot_is_gmem_only(new))
>>> + if (kvm_slot_has_gmem(new) && !kvm_gmem_slot_supports_mmap(new))
>>> return -EINVAL;
>>>
>>> /* guest_memfd is incompatible with MTE. */
>>
>> [Severity: Medium]
>> As reported by Suzuki K Poulose on v2 [1], should
>> kvm_arch_prepare_memory_region() drop this guest_memfd check altogether
>> rather than rejecting memslots backed by a guest_memfd created without
>> GUEST_MEMFD_FLAG_MMAP?
>>
>> Both gmem_abort() and realm_gmem_abort() fault in guest_memfd pages via
>> kvm_gmem_get_pfn() without using new->userspace_addr, and
>> kvm_arch_prepare_memory_region() does not verify that new->userspace_addr
>> maps the guest_memfd or any valid VMA. Requiring GUEST_MEMFD_FLAG_MMAP
>> here fails KVM_SET_USER_MEMORY_REGION2 with -EINVAL for VMs (such as
>> Realms) that bind private-only guest_memfd instances without allowing host
>> userspace mmap, and on v3 the guest_memfd maintainer noted that this check
>> is unnecessary and should be removed rather than exposing
>> kvm_gmem_slot_supports_mmap().
>>
>
> I agree with Sashiko here. I traced the history of this check:
>
> if (kvm_slot_has_gmem(new) && !kvm_memslot_is_gmem_only(new))
> return -EINVAL;
>
> In [1], Arm64 guest_memfd enablement, !kvm_memslot_is_gmem_only(new)
> meant "this guest_memfd does not support mmap()". Arm64 had no CoCo
> private-memory VMs yet, so guest_memfd was only usable for shared memory
> where the host VMM needed mmap() to access guest RAM. Rejecting
> non-mappable guest_memfd slots prevented unusable private-only memslots.
>
> In [2], pKVM support was added. The v1 of [2], [3], says pKVM uses
> anonymous memory. pKVM doesn't really specifically use gmem, so there's
> actually no change, this check doesn't really affect pKVM.
>
> Conversions [4] made stage 2 faults (mostly on x86), always get memory
> from gmem. On arm, as long as it is a gmem memslot, it already always
> got memory from gmem.
>
> Now that ARM CCA supports private memory, we should drop this check
> completely, I think David noted that right when it was added [5], and
> that's what Sean means too [6].
>
> If userspace sets up gmem with a memslot and doesn't set up mmap,
> userspace probably won't be able to set up a running ARM CCA VM, but
> that's userspace's bug imo.
>
> Imo even back in [1] perhaps the check didn't need to be added, it's
> just a userspace bug to try and set up a memslot with gmem that can't
> really be used.
Ok, thanks for digging through the history. I'm fine with just dropping
the check altogether. I had been trying to avoid changing the behaviour
of non-realm VMs but if we're agreed that the behaviour can be loosened
to allow buggy VMMs to shoot themselves in the foot then that's clearly
much easier to maintain.
Thanks,
Steve
> [1] https://lore.kernel.org/all/20250729225455.670324-21-seanjc@google.com/
> [2] https://lore.kernel.org/all/20260330144841.26181-1-will@kernel.org/
> [3] https://lore.kernel.org/all/20260105154939.11041-1-will@kernel.org/
> [4] https://lore.kernel.org/all/20260910-gmem-inplace-conversion-v13-12-dd6fbf94f4e1@google.com/
> [5] https://lore.kernel.org/all/2195c01b-3a17-46c5-a013-66922e8509bd@redhat.com/
> [6] https://lore.kernel.org/all/av8No1rvJLXwciId@seanjc-mac.roam.internal/
>
>> [1] https://lore.kernel.org/r/26a29420-8d27-4069-bbd5-28692c9e8542@arm.com
>>
>> --
>> Sashiko AI review · https://sashiko.dev/#/patchset/20261123104233.95710-1-steven.price@arm.com?part=1
next prev parent reply other threads:[~2026-11-25 11:31 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 10:42 [PATCH v4 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-11-23 10:42 ` [PATCH v4 01/11] KVM: arm64: guest_memfd: Check mmap support when preparing memslot Steven Price
2026-11-23 11:04 ` sashiko-bot
2026-11-24 23:30 ` Ackerley Tng
2026-11-25 11:31 ` Steven Price [this message]
2026-11-23 10:42 ` [PATCH v4 02/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-11-30 8:01 ` Fuad Tabba
2026-11-23 10:42 ` [PATCH v4 03/11] KVM: arm64: Pass range filter to stage2_unmap_range Steven Price
2026-11-23 10:42 ` [PATCH v4 04/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor Steven Price
2026-11-23 11:23 ` Suzuki K Poulose
2026-11-25 11:32 ` Steven Price
2026-11-30 8:30 ` Fuad Tabba
2026-11-23 10:42 ` [PATCH v4 05/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-11-23 11:35 ` Suzuki K Poulose
2026-11-25 11:51 ` Steven Price
2026-11-23 10:42 ` [PATCH v4 06/11] KVM: arm64: CCA: Destroy RTTs Steven Price
2026-11-23 11:00 ` sashiko-bot
2026-11-23 11:57 ` Suzuki K Poulose
2026-11-24 0:01 ` Suzuki K Poulose
2026-11-25 15:36 ` Steven Price
2026-11-23 10:42 ` [PATCH v4 07/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-11-23 11:12 ` sashiko-bot
2026-11-23 22:39 ` Suzuki K Poulose
2026-11-25 16:46 ` Steven Price
2026-11-23 13:32 ` Suzuki K Poulose
2026-11-25 16:42 ` Steven Price
2026-11-24 0:20 ` Suzuki K Poulose
2026-11-25 9:51 ` Suzuki K Poulose
2026-11-25 16:47 ` Steven Price
2026-11-23 10:42 ` [PATCH v4 08/11] KVM: Allow architectures to reject memslot changes before invalidation Steven Price
2026-11-30 9:05 ` Fuad Tabba
2026-11-30 10:15 ` Steven Price
2026-11-23 10:42 ` [PATCH v4 09/11] KVM: arm64: CCA: Prevent memslot modifications after Realm creation Steven Price
2026-11-25 0:09 ` Ackerley Tng
2026-11-25 14:58 ` Suzuki K Poulose
2026-11-26 16:47 ` Steven Price
2026-11-23 10:42 ` [PATCH v4 10/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-11-23 11:14 ` sashiko-bot
2026-11-26 9:44 ` Suzuki K Poulose
2026-11-26 17:02 ` Steven Price
2026-11-23 10:42 ` [PATCH v4 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Steven Price
2026-11-24 9:47 ` [PATCH v4 00/11] KVM: arm64: CCA: Prepare Realm memory management Kohei Enju
2026-11-25 11:54 ` Steven Price
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=10b37dd6-a32b-46bb-8629-347805edb9d3@arm.com \
--to=steven.price@arm.com \
--cc=ackerleytng@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.