Kernel KVM virtualization development
 help / color / mirror / Atom feed
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 10/11] KVM: arm64: CCA: Support runtime faulting of memory
Date: Mon, 30 Nov 2026 14:58:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-241452@kernel.org> (raw)
In-Reply-To: <20261130142534.219108-11-steven.price@arm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] KVM: arm64: block mapping over child RTT fails in
  realm_map_unprotected()
--

commit 23c673437d9940025385704ad240e79450d0dcaa
Author: Steven Price <steven.price@arm.com>

KVM: arm64: CCA: Support runtime faulting of memory

This commit adds runtime stage-2 fault handling for Realm VMs, mapping
private guest_memfd pages into the protected IPA range via the RMM and
shared guest_memfd or userspace-backed memslot pages into the unprotected
IPA range.

> diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c
> index 4690df0a5d29a..ce1e7f9a8011c 100644
> --- a/arch/arm64/kvm/rmi.c
> +++ b/arch/arm64/kvm/rmi.c
> @@ -478,6 +478,273 @@ void kvm_realm_unmap_range_filter(struct kvm *kvm, unsigned long start,
>  	}
>  }
>  
> +static unsigned long addr_range_desc(struct realm *realm,
> +				     unsigned long ipa, unsigned long phys,
> +				     unsigned long size, unsigned long state)
> +{
> +	unsigned long count = 1;
> +	unsigned long out;
> +	int rmi_size;
> +
> +	for (rmi_size = KVM_PGTABLE_LAST_LEVEL - realm->start_level;
> +	     rmi_size >= 0; rmi_size--) {
> +		unsigned long entry_size = rmi_addr_block_size_to_bytes(rmi_size);
> +
> +		if (size >= entry_size && IS_ALIGNED(ipa, entry_size) &&
> +		    IS_ALIGNED(phys, entry_size))
> +			break;
> +	}

[ ... ]

> +static int realm_map_unprotected(struct kvm *kvm,
> +				 unsigned long ipa,
> +				 kvm_pfn_t pfn,
> +				 unsigned long size,
> +				 enum kvm_pgtable_prot prot,
> +				 struct kvm_mmu_memory_cache *memcache,
> +				 phys_addr_t *mapped_top)
> +{

[ ... ]

> +	while (ipa < ipa_top) {
> +		unsigned long range_desc = addr_range_desc(realm, ipa, phys,
> +							   ipa_top - ipa,
> +							   RMI_OP_MEM_UNDELEGATED);
> +		unsigned long call_top = ipa + RMI_ADDR_RANGE_COUNT(range_desc) *
> +			rmi_addr_block_size_to_bytes(RMI_ADDR_RANGE_BLOCK_SIZE(range_desc));
> +		unsigned long out_top;
> +
> +		ret = rmi_rtt_unprot_map(rd, ipa, call_top, flags, range_desc,
> +					 &out_top);
> +		if (ret < 0)
> +			return ret;
> +
> +		if (ret) {
> +			/* Create missing RTTs and retry */
> +			int level = RMI_RESULT_DATA_LEVEL(ret);
> +			int req_level = KVM_PGTABLE_LAST_LEVEL -
> +				RMI_ADDR_RANGE_BLOCK_SIZE(range_desc);
> +
> +			if (RMI_RESULT_STATUS(ret) == RMI_BLOCKED)
> +				return -EAGAIN;
> +			if (RMI_RESULT_STATUS(ret) != RMI_ERROR_RTT ||
> +			    ++retries > KVM_PGTABLE_LAST_LEVEL + 2 ||
> +			    level < realm->start_level)
> +				return -ENXIO;
> +
> +			/* Replace an existing mapping to update its permissions. */
> +			if (level >= req_level) {
> +				realm_unmap_shared_range(kvm, ipa, ipa_top, false,
> +							 memcache);
> +				continue;
> +			}

[Severity: High]
Can realm_map_unprotected() fail with -ENXIO when installing a block
mapping over an IPA range that already has a deeper child RTT table?

When realm_s2_fault_map() promotes mapping_size to PMD_SIZE for a THP
(for example, on a write fault or after khugepaged collapse in a 2MB
range where a 4KB page was previously faulted in), addr_range_desc()
selects a block mapping at req_level = 2.  Because a level 3 RTT table
already exists, rmi_rtt_unprot_map() fails with RMI_ERROR_RTT and returns
level >= req_level.

realm_unmap_shared_range() only calls rmi_rtt_unprot_unmap() to clear
leaf entries and does not destroy or fold the empty child RTT table.
Each retry therefore attempts the same level 2 block mapping over the
still-present table entry until retries exceeds KVM_PGTABLE_LAST_LEVEL + 2
and KVM_RUN fails with -ENXIO.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130142534.219108-1-steven.price@arm.com?part=10

  reply	other threads:[~2026-11-30 14:58 UTC|newest]

Thread overview: 15+ 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 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-11-30 14:25 ` [PATCH v5 06/11] KVM: arm64: CCA: Destroy RTTs Steven Price
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
2026-11-30 14:25 ` [PATCH v5 08/11] KVM: arm64: CCA: Restrict Realm memslots to the lower IPA half Steven Price
2026-11-30 14:25 ` [PATCH v5 09/11] KVM: arm64: CCA: Advertise private memory support for Realms Steven Price
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 [this message]
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-241452@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