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 v5 07/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers
Date: Mon, 30 Nov 2026 14:53:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-241438@kernel.org> (raw)
In-Reply-To: <20261130142534.219108-8-steven.price@arm.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: arm64: cca: stale err_level and KVM_BUG_ON() on OOM in
private unmap
--
commit ecf125967f6f8c4f0a2799914ef908db3d675dea
Author: Steven Price <steven.price@arm.com>
KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers
This commit adds RMI Realm Translation Table (RTT) creation and shared/private
range unmap helpers for CCA Realm stage-2 memory operations.
> diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c
> index 140c7f9ab2c20..4690df0a5d29a 100644
> --- a/arch/arm64/kvm/rmi.c
> +++ b/arch/arm64/kvm/rmi.c
[ ... ]
> @@ -166,6 +286,198 @@ void kvm_realm_unmap_stage2_all(struct kvm *kvm)
> realm->stage2_unmapped = true;
> }
>
> +static bool realm_unmap_cache_topup(struct kvm *kvm,
> + struct kvm_mmu_memory_cache *mc, int needed)
> +{
> + int ret;
> +
> + if (kvm_mmu_memory_cache_nr_free_objects(mc) >= needed)
> + return false;
> +
> + lockdep_assert_held_write(&kvm->mmu_lock);
> + write_unlock(&kvm->mmu_lock);
> + ret = __kvm_mmu_topup_memory_cache(mc, KVM_PGTABLE_LAST_LEVEL, needed);
> + write_lock(&kvm->mmu_lock);
> +
> + return !ret;
> +}
> +
> +static void realm_unmap_shared_range(struct kvm *kvm,
> + unsigned long start,
> + unsigned long end,
> + bool may_block,
> + struct kvm_mmu_memory_cache *mc)
> +{
[ ... ]
> + ret = realm_create_rtt_levels(realm, addr, err_level,
> + level, mc);
> + if (!ret) {
> + /* Retry with the RTT levels in place. */
> + next_addr = addr;
> + break;
> + }
> + WARN_ON(ret != -ENOMEM);
> +
> + /* Splitting failed; unmap the entire existing block. */
> + next_addr = ALIGN_DOWN(addr, kvm_granule_size(err_level));
> + end = max(end, next_addr + kvm_granule_size(err_level));
> + break;
> + }
> + default:
> + WARN_ON(1);
> + return;
> + }
> +
> + if (may_block)
> + cond_resched_rwlock_write(&kvm->mmu_lock);
> + }
> +}
> +
> +static void realm_unmap_private_range(struct kvm *kvm,
> + unsigned long start,
> + unsigned long end,
> + bool may_block,
> + struct kvm_mmu_memory_cache *mc)
> +{
[ ... ]
> + case RMI_ERROR_RTT: {
> + int err_level = RMI_RESULT_DATA_LEVEL(ret);
> + int level = find_map_level(realm, addr, end);
> +
> + if (WARN_ON(err_level < realm->start_level ||
> + err_level > KVM_PGTABLE_LAST_LEVEL))
> + return;
> +
> + if (err_level >= level) {
> + /* Nothing present, so skip this RTT entry. */
> + next_addr = ALIGN(addr + 1,
> + kvm_granule_size(err_level));
> + break;
> + }
> +
> + if (may_block && realm_unmap_cache_topup(kvm, mc,
> + level - err_level)) {
> + next_addr = addr;
> + break;
> + }
> +
> + ret = realm_create_rtt_levels(realm, addr, err_level,
> + level, mc);
> + if (!ret) {
> + next_addr = addr;
> + break;
> + }
> +
> + /* A failed split cannot leave the backing pages mapped. */
> + KVM_BUG_ON(1, kvm);
> + next_addr = ALIGN_DOWN(addr, kvm_granule_size(err_level));
> + end = max(end, next_addr + kvm_granule_size(err_level));
> + break;
[Severity: Medium]
Does an allocation failure during an RTT split in realm_unmap_private_range()
cause a stale err_level to be used and trigger a host kernel warning via
KVM_BUG_ON(1, kvm)?
When realm_unmap_cache_topup() needs to allocate objects, it drops and
re-acquires kvm->mmu_lock around __kvm_mmu_topup_memory_cache(), which uses
GFP_KERNEL_ACCOUNT. If that allocation fails (for example under a memory
cgroup limit), realm_unmap_cache_topup() returns false even though
kvm->mmu_lock was released, so realm_unmap_private_range() proceeds directly
to realm_create_rtt_levels() with the pre-unlock err_level instead of
retrying rmi_rtt_data_unmap().
If realm_create_rtt_levels() then fails with -ENOMEM, KVM_BUG_ON(1, kvm)
emits a host WARN_ON_ONCE() splat on a __GFP_ACCOUNT allocation failure
instead of warning only when ret != -ENOMEM and marking the VM dead with
kvm_vm_dead(kvm).
Also, if realm_create_rtt_levels() creates an intermediate RTT level before
failing at a deeper level during a multi-level split, the fallback in both
realm_unmap_private_range() and realm_unmap_shared_range() widens next_addr
and end using kvm_granule_size(err_level) rather than the granule size of
the last level reached.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130142534.219108-1-steven.price@arm.com?part=7
next prev parent reply other threads:[~2026-11-30 14:53 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 14:25 [PATCH v5 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-11-30 14:25 ` [PATCH v5 01/11] KVM: arm64: guest_memfd: Drop mmap requirement for memslots Steven Price
2026-11-30 14:58 ` sashiko-bot
2026-11-30 15:40 ` Suzuki K Poulose
2026-11-30 15:41 ` Steven Price
2026-11-30 14:25 ` [PATCH v5 02/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-11-30 14:25 ` [PATCH v5 03/11] KVM: arm64: Pass range filter to stage2_unmap_range Steven Price
2026-11-30 14:25 ` [PATCH v5 04/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor Steven Price
2026-11-30 14:25 ` [PATCH v5 05/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-12-01 16:56 ` Suzuki K Poulose
2026-11-30 14:25 ` [PATCH v5 06/11] KVM: arm64: CCA: Destroy RTTs Steven Price
2026-12-01 23:17 ` Suzuki K Poulose
2026-11-30 14:25 ` [PATCH v5 07/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-11-30 14:53 ` sashiko-bot [this message]
2026-12-01 23:15 ` Suzuki K Poulose
2026-11-30 14:25 ` [PATCH v5 08/11] KVM: arm64: CCA: Restrict Realm memslots to the lower IPA half Steven Price
2026-12-01 18:39 ` Fuad Tabba
2026-11-30 14:25 ` [PATCH v5 09/11] KVM: arm64: CCA: Advertise private memory support for Realms Steven Price
2026-12-01 23:23 ` Suzuki K Poulose
2026-11-30 14:25 ` [PATCH v5 10/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-11-30 14:58 ` sashiko-bot
2026-12-01 19:55 ` Fuad Tabba
2026-11-30 14:25 ` [PATCH v5 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations 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=sashiko-outbox-241438@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.