From: sashiko-bot@kernel.org
To: "Steven Price" <steven.price@arm.com>,
kvm@vger.kernel.org, kvmarm@lists.linux.dev
Cc: "Oliver Upton" <oupton@kernel.org>, "Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH 09/11] KVM: arm64: CCA: Prevent memslot modifications after Realm creation
Date: Mon, 02 Nov 2026 15:50:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-193708@kernel.org> (raw)
In-Reply-To: <20261102141304.126883-10-steven.price@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] KVM: arm64: CCA: guest_memfd memslot delete rejected after Stage-2 unmap
--
commit 5106402397c36eec1e5fa59a5bb2c5adf4ee2aa8
Author: Suzuki K Poulose <suzuki.poulose@arm.com>
KVM: arm64: CCA: Prevent memslot modifications after Realm creation
This commit updates kvm_arch_prepare_memory_region() to disallow creating,
modifying, or deleting guest_memfd-backed memslots once a Realm has been
created.
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 51fda7b2ff7f3..eb8c5f9e9791d 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -2862,13 +2862,28 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
> (new->flags & (KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_READONLY)))
> return -EPERM;
>
> - if (kvm->arch.vm_flavor == VM_PROTECTED_PKVM) {
> + switch (kvm->arch.vm_flavor) {
> + case VM_PROTECTED_PKVM:
> /* Cannot modify memslots once a pVM has run. */
> if (pkvm_hyp_vm_is_created(kvm) &&
> - (change == KVM_MR_DELETE || change == KVM_MR_MOVE)) {
> + (change == KVM_MR_DELETE || change == KVM_MR_MOVE))
> return -EPERM;
> - }
> + break;
> + case VM_REALM:
> + /*
> + * Once the Realm is created, we cannot modify any slots that
> + * could be providing private memory. i.e., guest_memfd backed
> + * slots.
> + * TODO: Handle trusted device private memory slots
> + */
> + if (!kvm_realm_is_created(kvm))
> + break;
>
> + if (kvm_slot_has_gmem(old) || kvm_slot_has_gmem(new))
> + return -EPERM;
[Severity: High]
Does checking kvm_slot_has_gmem(old) in kvm_arch_prepare_memory_region() run
too late to prevent Stage-2 unmapping when deleting a guest_memfd-backed
memslot on a created Realm?
In virt/kvm/kvm_main.c:kvm_set_memory_region(), non-delete changes
(KVM_MR_MOVE and KVM_MR_FLAGS_ONLY) on KVM_MEM_GUEST_MEMFD memslots are
already rejected upfront with -EINVAL, so kvm_slot_has_gmem(old) is reached
here when change == KVM_MR_DELETE.
However, in virt/kvm/kvm_main.c:kvm_set_memslot(), KVM invalidates and
flushes the old memslot before calling kvm_prepare_memory_region():
virt/kvm/kvm_main.c:kvm_set_memslot() {
if (change == KVM_MR_DELETE || change == KVM_MR_MOVE) {
invalid_slot = kzalloc_obj(*invalid_slot, GFP_KERNEL_ACCOUNT);
if (!invalid_slot) {
mutex_unlock(&kvm->slots_arch_lock);
return -ENOMEM;
}
kvm_invalidate_memslot(kvm, old, invalid_slot);
}
r = kvm_prepare_memory_region(kvm, old, new, change);
if (r)
goto err;
}
kvm_invalidate_memslot() marks the active slot as KVM_MEMSLOT_INVALID and
calls arch/arm64/kvm/mmu.c:kvm_arch_flush_shadow_memslot():
arch/arm64/kvm/mmu.c:kvm_arch_flush_shadow_memslot() {
write_lock(&kvm->mmu_lock);
kvm_stage2_unmap_range(&kvm->arch.mmu, gpa, size, true);
kvm_nested_unmap_cipa_range(kvm, gpa, size, true);
write_unlock(&kvm->mmu_lock);
}
For a Realm VM, kvm_stage2_unmap_range() invokes
arch/arm64/kvm/rmi.c:kvm_realm_unmap_range_filter() with
KVM_FILTER_PRIVATE | KVM_FILTER_SHARED:
arch/arm64/kvm/rmi.c:kvm_realm_unmap_range_filter() {
if (attr_filter & KVM_FILTER_SHARED)
realm_unmap_shared_range(kvm, start, end, may_block);
if (attr_filter & KVM_FILTER_PRIVATE)
realm_unmap_private_range(kvm, start, end, may_block);
}
By the time kvm_arch_prepare_memory_region() returns -EPERM and
kvm_set_memslot() restores the old memslot in the error path, hasn't
realm_unmap_private_range() already unmapped and undelegated the Realm's
private Stage-2 DATA granules across the memslot's GPA range?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102141304.126883-1-steven.price@arm.com?part=9
next prev parent reply other threads:[~2026-11-02 15:50 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 14:12 [PATCH 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-11-02 14:12 ` [PATCH 01/11] KVM: arm64: CCA: Reserve the RMM mode Steven Price
2026-11-02 14:12 ` [PATCH 02/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-11-02 14:30 ` sashiko-bot
2026-11-02 15:45 ` Steven Price
2026-11-03 11:34 ` Suzuki K Poulose
2026-11-02 14:12 ` [PATCH 03/11] KVM: arm64: CCA: Check for RMI support at KVM init Steven Price
2026-11-02 14:12 ` [PATCH 04/11] KVM: arm64: CCA: Check for LPA2 support and SHA-256 Steven Price
2026-11-02 14:38 ` sashiko-bot
2026-11-02 15:56 ` Steven Price
2026-11-03 11:47 ` Suzuki K Poulose
2026-11-02 14:12 ` [PATCH 05/11] KVM: arm64: Handle attributes in stage2_unmap_range Steven Price
2026-11-02 14:12 ` [PATCH 06/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-11-02 15:05 ` sashiko-bot
2026-11-02 16:24 ` Steven Price
2026-11-02 23:49 ` Suzuki K Poulose
2026-11-02 14:12 ` [PATCH 07/11] KVM: arm64: CCA: Tear down RTTs Steven Price
2026-11-02 15:18 ` sashiko-bot
2026-11-02 17:01 ` Steven Price
2026-11-03 15:20 ` Suzuki K Poulose
2026-11-02 14:12 ` [PATCH 08/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-11-02 15:37 ` sashiko-bot
2026-11-02 14:13 ` [PATCH 09/11] KVM: arm64: CCA: Prevent memslot modifications after Realm creation Steven Price
2026-11-02 15:50 ` sashiko-bot [this message]
2026-11-02 14:13 ` [PATCH 10/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-11-02 16:26 ` sashiko-bot
2026-11-02 14:13 ` [PATCH 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Steven Price
2026-11-02 17:12 ` sashiko-bot
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=sashiko-outbox-193708@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=steven.price@arm.com \
/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.