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 v6 05/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers
Date: Fri, 04 Dec 2026 12:28:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-249790@kernel.org> (raw)
In-Reply-To: <20261204115725.45272-6-steven.price@arm.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] KVM: arm64: early return on undelegate error abandons private
unmap range
- [Medium] KVM: arm64: KVM_BUG_ON() warns on -ENOMEM in
realm_unmap_private_range()
- [Medium] KVM: arm64: unhandled RMI_BLOCKED in Realm RTT unmap and
create helpers
- [Low] KVM: arm64: try_topup never resets on address advance in private
unmap
--
commit 6a6c7236f977c112e6be13a65e7a962486113d13
Author: Steven Price <steven.price@arm.com>
KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers
This commit adds the RMI Realm Translation Table (RTT) creation and
unmapping helpers for CCA Realm stage-2 memory operations, and moves
rmi_addr_block_size_to_bytes() into include/linux/arm-rmi-cmds.h.
> diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c
> index 6a8bff1d8d467..ee16f5364b9aa 100644
> --- a/arch/arm64/kvm/rmi.c
> +++ b/arch/arm64/kvm/rmi.c
> @@ -16,6 +16,337 @@ u32 kvm_rmm_ipa_limit(void)
[ ... ]
> +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 = rmi_rtt_unprot_unmap(rd, addr, end, RMI_ADDR_TYPE_NONE,
> + 0, &next_addr, NULL, NULL);
> + if (WARN_ON(ret < 0))
> + return;
> +
> + switch (RMI_RESULT_STATUS(ret)) {
[ ... ]
> + default:
> + WARN_ON(1);
> + return;
> + }
[Severity: Medium]
Can an RMI_BLOCKED return from rmi_rtt_unprot_unmap() abort shared
unmapping mid-range?
rmi_smccc_invoke() only retries RMI_BLOCKED twice before returning it
for the caller to handle. Hitting default here returns early from a
void invalidation callback, so callers such as MMU notifiers or
kvm_gmem_punch_hole() can reclaim or free host pages while the Realm
still has live unprotected stage-2 mappings to them (use-after-free).
realm_unmap_private_range() has the same early return on RMI_BLOCKED,
leaving still-mapped, still-delegated granules to be freed back to the
host allocator. realm_create_rtt_levels() also warns and turns
RMI_BLOCKED into -ENXIO instead of retrying or returning -EAGAIN,
which triggers KVM_BUG_ON() in realm_unmap_private_range().
[ ... ]
> +static void realm_unmap_private_range(struct kvm *kvm,
> + unsigned long start,
> + unsigned long end,
> + bool may_block,
> + struct kvm_mmu_memory_cache *mc)
> +{
> + struct realm *realm = &kvm->arch.realm;
> + unsigned long rd = realm->rd_phys;
> + unsigned long next_addr, addr;
> + bool try_topup = may_block;
> + long ret;
> +
> + for (addr = start; addr < end; addr = next_addr) {
> + unsigned long out_range;
> + unsigned long flags = RMI_ADDR_TYPE_SINGLE;
> + /* TODO: Optimise using RMI_ADDR_TYPE_LIST */
> +
> + ret = rmi_rtt_data_unmap(rd, addr, end, flags, 0,
> + &next_addr, &out_range, NULL);
> + if (WARN_ON(ret < 0))
> + return;
> +
> + switch (RMI_RESULT_STATUS(ret)) {
> + case RMI_SUCCESS:
> + ret = undelegate_range_desc(out_range);
> + if (WARN_ON(ret))
> + return;
> + break;
[Severity: Medium]
Does returning here on an undelegate_range_desc() failure abandon
unmapping and undelegating [next_addr, end)?
Because kvm_realm_unmap_range_filter() returns void, callers such as
kvm_gmem_punch_hole() still truncate and free the remaining backing
pages back to the host allocator. Leaving [next_addr, end) mapped in
a runnable Realm and still delegated risks guest use-after-free and
host Granule Protection Faults.
Continuing the loop after WARN_ON(ret) would leak only the failed
range (as rmi_sro_free() does) while still unmapping the rest. The
other early returns in realm_unmap_private_range() also exit without
marking the VM bugged via KVM_BUG_ON(1, kvm).
[ ... ]
> + if (try_topup) {
> + bool lock_dropped;
> +
> + if (realm_unmap_cache_topup(kvm, mc,
> + level - err_level,
> + &lock_dropped))
> + try_topup = false;
> + if (lock_dropped) {
> + /* Retry the RTT walk with mmu_lock held. */
> + next_addr = addr;
> + break;
> + }
> + }
[Severity: Low]
Should try_topup be reset to may_block whenever addr advances?
Once realm_unmap_cache_topup() fails for one address, try_topup stays
false for the rest of the range. If the loop moves on (for instance
after a concurrent split/unmap while mmu_lock was dropped, or via the
atomic fallback), later splits in the same call skip sleepable topups
and rely only on GFP_ATOMIC, making a failed split and KVM_BUG_ON()
more likely.
> +
> + 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);
[Severity: Medium]
Can this KVM_BUG_ON(1, kvm) trigger a host WARN_ON_ONCE() on -ENOMEM?
When realm_create_rtt_levels() fails with -ENOMEM (from a GFP_ATOMIC
allocation failure or rmi_delegate_page() failure in
alloc_delegated_granule()), KVM_BUG_ON() emits a WARN_ON_ONCE(),
tainting the kernel and panicking hosts with panic_on_warn=1 on an
out-of-memory condition rather than a kernel bug.
Unlike realm_unmap_shared_range(), which uses WARN_ON(ret != -ENOMEM),
this warns unconditionally. Using kvm_vm_dead(kvm) on -ENOMEM and
reserving KVM_BUG_ON() for ret != -ENOMEM would still kill the VM
without firing a warning on allocation failure.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204115725.45272-1-steven.price@arm.com?part=5
next prev parent reply other threads:[~2026-12-04 12:28 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:57 [PATCH v6 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-12-04 11:57 ` [PATCH v6 01/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-12-04 16:07 ` Kohei Enju
2026-12-04 17:05 ` Steven Price
2026-12-04 11:57 ` [PATCH v6 02/11] KVM: arm64: Pass range filter to stage2_unmap_range Steven Price
2026-12-04 11:57 ` [PATCH v6 03/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor Steven Price
2026-12-04 11:57 ` [PATCH v6 04/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-12-04 12:15 ` sashiko-bot
2026-12-04 11:57 ` [PATCH v6 05/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-12-04 12:28 ` sashiko-bot [this message]
2026-12-04 11:57 ` [PATCH v6 06/11] KVM: arm64: CCA: Destroy RTTs Steven Price
2026-12-04 12:28 ` sashiko-bot
2026-12-04 11:57 ` [PATCH v6 07/11] KVM: arm64: CCA: Restrict Realm memslots to the lower IPA half Steven Price
2026-12-04 15:48 ` Kohei Enju
2026-12-04 16:27 ` Steven Price
2026-12-04 11:57 ` [PATCH v6 08/11] KVM: arm64: CCA: Advertise private memory support for Realms Steven Price
2026-12-04 12:23 ` sashiko-bot
2026-12-04 11:57 ` [PATCH v6 09/11] KVM: arm64: Select protected VM behaviour by VM flavour Steven Price
2026-12-04 13:21 ` Fuad Tabba
2026-12-04 11:57 ` [PATCH v6 10/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-12-04 12:39 ` sashiko-bot
2026-12-04 15:32 ` Kohei Enju
2026-12-04 16:27 ` Steven Price
2026-12-04 11:57 ` [PATCH v6 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Steven Price
2026-12-04 12:44 ` sashiko-bot
2026-12-04 16:30 ` [PATCH v6 00/11] KVM: arm64: CCA: Prepare Realm memory management Kohei Enju
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-249790@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox