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 v6 10/11] KVM: arm64: CCA: Support runtime faulting of memory
Date: Fri, 04 Dec 2026 12:39:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-249818@kernel.org> (raw)
In-Reply-To: <20261204115725.45272-11-steven.price@arm.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] KVM: arm64: realm_mem_abort() returns -EINVAL without
  KVM_EXIT_MEMORY_FAULT
- [Medium] KVM: arm64: realm_map_protected() ignores
  rmi_delegate_range() errors
- [Medium] KVM: arm64: realm_map_protected() leaves failed undelegate
  page unpinned
- [Low] KVM: arm64: commit message describes changes moved to preceding
  commit
- [Low] KVM: arm64: does realm_s2_fault_map() omit needed
  sanitise_mte_tags()?
--

commit b74285b1140496ce40baae3d7c0ccb94905144dd
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 guests,
introducing private guest_memfd and shared memory mapping helpers in
mmu.c and rmi.c along with IPA-to-GPA conversion helpers.

> Realm faults may need to create RTTs, including when updating a
> mapping after a permission fault. Take the write side of mmu_lock
> and top up the MMU cache for these faults. Do not pre-fault Realm
> memory.
>
> The lock helpers are in a header compiled by nVHE too. Make
> kvm_vm_hyp_is_distrusting() available there for the lock choice.

[Severity: Low]
These two paragraphs appear to be stale after the v5 split into commit
"KVM: arm64: Select protected VM behaviour by VM flavour".  That preceding
patch already moves kvm_vm_hyp_is_distrusting() for nVHE, updates
kvm_fault_lock(), tops up the memcache on permission faults, and disables
pre-faulting, while this commit only adds a comment line in
user_mem_abort().

> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index a1ae89ce37074..ee81d147336c2 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c

[ ... ]

> @@ -2297,8 +2364,63 @@ static int kvm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd,
>  	return ret;
>  }
>  
> +static int realm_s2_fault_map(const struct kvm_s2_fault_desc *s2fd,
> +			      const struct kvm_s2_fault_vma_info *s2vi,
> +			      enum kvm_pgtable_prot prot,
> +			      void *memcache,
> +			      struct kvm_s2_fault_result *result)
> +{

[ ... ]

> +	map_start = ALIGN_DOWN(s2fd->fault_ipa, mapping_size);
> +	ret = realm_map_ipa(kvm, s2fd->fault_ipa, pfn, mapping_size,
> +			    prot, memcache, &mapped_top);

[Severity: Low]
This question rests on an RMM/RME architecture detail that could not be
confirmed from the kernel source: can a Realm guest on an MTE-capable host
observe MTE allocation tags on unprotected Normal Cacheable
(MT_S2_FWB_NORMAL) stage-2 mappings?

If so, realm_s2_fault_map() omits sanitise_mte_tags() before mapping
cacheable userspace pages into a shared IPA (and kvm_vm_ioctl_enable_cap()
does not reject KVM_CAP_ARM_MTE for Realms), which would expose stale host
allocation tags to the guest.  If the RMM unconditionally prevents Realm
access to MTE tags, a short comment here would clarify the invariant.

[ ... ]

> +static int __maybe_unused realm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
> +{
> +	struct kvm *kvm = s2fd->vcpu->kvm;
> +
> +	VM_WARN_ON_ONCE(kvm_s2_fault_is_perm(s2fd) &&
> +			!esr_abt_is_write_fault(s2fd->esr) &&
> +			!kvm_s2_fault_is_exec(s2fd));
> +
> +	if (kvm_realm_is_private_address(&kvm->arch.realm, s2fd->fault_ipa) &&
> +	    !kvm_slot_has_gmem(s2fd->memslot))
> +		return -EINVAL;

[Severity: Medium]
Should a private-IPA fault on a non-guest_memfd memslot prepare a
KVM_EXIT_MEMORY_FAULT exit and return -EFAULT instead of -EINVAL?

Per Documentation/virt/kvm/api.rst, userspace must treat
kvm_run.exit_reason as undefined when KVM_RUN returns anything other than
-EFAULT or -EHWPOISON, so returning -EINVAL leaves the VMM without the
faulting GPA, size, or KVM_MEMORY_EXIT_FLAG_PRIVATE metadata.  Both
realm_gmem_abort() on attribute mismatch and x86 kvm_mmu_faultin_pfn_gmem()
prepare KVM_EXIT_MEMORY_FAULT and return -EFAULT here.

> diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c
> index f176ea9184d7c..d48481a33f8f7 100644
> --- a/arch/arm64/kvm/rmi.c
> +++ b/arch/arm64/kvm/rmi.c

[ ... ]

> +static int realm_map_protected(struct kvm *kvm,
> +			       unsigned long ipa,
> +			       kvm_pfn_t pfn,
> +			       unsigned long map_size,
> +			       struct kvm_mmu_memory_cache *memcache,
> +			       phys_addr_t *mapped_top)
> +{

[ ... ]

> +	if (rmi_delegate_range(phys, map_size, &delegated_phys)) {
> +		if (delegated_phys == phys) {
> +			/*
> +			 * It's likely we raced with another VCPU on the same
> +			 * fault. Assume the other VCPU has handled the fault
> +			 * and return to the guest.
> +			 */
> +			return 0;
> +		}
> +		/* Partial delegation - map as much as we can */
> +		map_size = delegated_phys - phys;
> +	}

[Severity: Medium]
Can discarding the return value of rmi_delegate_range() here trap the vCPU
in an infinite stage-2 fault loop?

If a previous fault delegated the page, failed in rmi_rtt_data_map() (for
example returning -EAGAIN on an IRQ), and then failed to undelegate it in
err_undelegate, the guest_memfd page stays delegated while the IPA remains
unmapped.  On the next fault, rmi_delegate_range() fails with
delegated_phys == phys and realm_map_protected() returns 0 without checking
the error or verifying the mapping, so the guest re-enters and faults on
the same IPA indefinitely.

[ ... ]

> +err_undelegate:
> +	/*
> +	 * Keep completed mappings: unmapping them would destroy their RIPAS.
> +	 * A range which cannot be undelegated remains owned by the RMM.
> +	 */
> +	WARN_ON(rmi_undelegate_range(phys, ipa_top - ipa));
> +	return ret < 0 ? ret : -ENXIO;
> +}

[Severity: Medium]
If rmi_undelegate_range() fails here, does the still-delegated page risk
being freed back to the normal-world allocator?

kvm_gmem_get_pfn() drops its temporary folio reference before returning to
realm_gmem_abort(), so only the guest_memfd page cache holds a reference to
the page.  When userspace later punches a hole or closes the guest_memfd
inode, realm_unmap_private_range() finds no RTT entry to undelegate and the
still-delegated page is returned to the buddy allocator, where normal-world
access triggers a Granule Protection Fault.  Pinning the folio on
undelegation failure (matching rmi_free_delegated_page() leaking
undelegatable pages) would prevent it from being freed while owned by the
RMM.

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

  reply	other threads:[~2026-12-04 12:39 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
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 [this message]
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-249818@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