All of lore.kernel.org
 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 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations
Date: Fri, 04 Dec 2026 12:44:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-249829@kernel.org> (raw)
In-Reply-To: <20261204115725.45272-12-steven.price@arm.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Critical] KVM: arm64: kvm_realm_unmap_stage2_all() omits shared
  mappings on mm release
- [High] KVM: arm64: realm stage-2 unmap aborts early on RMI_BLOCKED or
  undelegate
- [Low] KVM: arm64: handle_access_fault() unguarded for VM_REALM stage-2
  walk
- [Low] KVM: arm64: realm_map_unprotected() retries block map without
  RTT destroy
- [Low] KVM: arm64: realm unmap allocates RTT levels on RMI_ERROR_RTT
  err_level
--

commit 0969bc581a2fdc2d828121e71b83004a225097a1
Author: Suzuki K Poulose <suzuki.poulose@arm.com>

KVM: arm64: CCA: Add Realm stage-2 MMU operations

This commit defines realm_vm_s2_ops and registers it for VM_REALM, wiring
Realm stage-2 unmapping, fault handling, TLB flushing, and root PGD teardown
into the arm64 VM stage-2 operations table.

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

[ ... ]

> @@ -353,6 +366,15 @@ static void no_stage2_unmap_range(struct kvm_s2_mmu *mmu,
>  {
>  }
>  
> +static void realm_stage2_unmap_range(struct kvm_s2_mmu *mmu,
> +				     phys_addr_t start, u64 size, bool may_block,
> +				     enum kvm_gfn_range_filter filter)
> +{
> +	struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu);
> +
> +	kvm_realm_unmap_range_filter(kvm, start, size, may_block, filter);
> +}
> +

[Severity: High]
Can realm_stage2_unmap_range() leave part of the requested range mapped when
an RMI call returns RMI_BLOCKED?

rmi_smccc_invoke() only retries RMI_BLOCKED RMM_BLOCKED_RETRY_COUNT (2) times
and expects callers to reissue if needed.  Unlike realm_map_protected() and
realm_map_unprotected(), neither realm_unmap_shared_range() nor
realm_unmap_private_range() handles RMI_BLOCKED; both hit the default case
with WARN_ON(1) and return early, abandoning the rest of the range.

In realm_unmap_private_range(), a non-zero return from undelegate_range_desc()
(including RMI_BLOCKED from rmi_undelegate_range()) also logs WARN_ON(ret) and
returns immediately without undelegating the rest of out_range or unmapping
the remaining IPAs.

Because vm_stage2_unmap_range() returns void, callers such as MMU notifier
invalidations assume the whole range is gone.  Leaving shared mappings live
after Linux frees the backing pages allows guest-to-host physical memory
use-after-free, while leaving private granules mapped or delegated in Realm
PAS causes host Granule Protection Faults once Linux reuses them.

[Severity: Low]
This question rests on an RMM architectural detail that could not be confirmed
from the kernel source: do SMC_RMI_RTT_UNPROT_UNMAP and SMC_RMI_RTT_DATA_UNMAP
return RMI_ERROR_RTT with err_level < level when walking an unassigned RTT
entry above the target page level (no child RTT exists), or do they return
RMI_SUCCESS for unassigned entries and only return RMI_ERROR_RTT for mapped
blocks that need splitting?

If they return RMI_ERROR_RTT for unassigned entries, unmapping a 4KB page in
an unpopulated 1GB or 2MB region (for example via madvise(MADV_DONTNEED) or
FALLOC_FL_PUNCH_HOLE) fails the err_level >= level check in both
realm_unmap_shared_range() and realm_unmap_private_range().  Both then call
realm_create_rtt_levels() to allocate and delegate new child RTT pages for
untouched memory, and realm_unmap_private_range() triggers KVM_BUG_ON(1, kvm)
if that allocation fails.

[ ... ]

> @@ -2478,7 +2511,7 @@ static int kvm_vm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
>  		return user_mem_abort(s2fd, NULL, kvm_s2_fault_map);
>  }
>  
> -static int __maybe_unused realm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
> +static int realm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
>  {
>  	struct kvm *kvm = s2fd->vcpu->kvm;
>  

[Severity: Low]
This question rests on an RMM architectural detail that could not be confirmed
from the kernel source: does SMC_RMI_RTT_UNPROT_MAP reject a 2MB block
descriptor (block_size == 1, req_level == 2) with RMI_ERROR_RTT at level >= 2
when the L2 RTT entry is a table pointing to an existing empty L3 RTT, rather
than replacing or folding the L3 RTT?

If it does, upgrading a previously 4KB-faulted shared userspace region to a
2MB transparent huge page via realm_s2_fault_map() -> realm_map_ipa() ->
realm_map_unprotected() will fail.  Since realm_unmap_shared_range() never
folds or destroys child L3 RTTs, realm_map_unprotected() will unmap the range
on level >= req_level and retry the same 2MB block mapping until retries are
exhausted and KVM_RUN returns -ENXIO.

[ ... ]

> @@ -3357,6 +3390,16 @@ static const struct kvm_vm_s2_ops kvm_default_vm_s2_ops = {
>  	.vm_mem_abort			= kvm_vm_mem_abort,
>  };
>  
> +static const struct kvm_vm_s2_ops realm_vm_s2_ops = {
> +	.vm_stage2_destroy		= realm_stage2_destroy,
> +	.vm_flush_remote_tlbs		= realm_flush_remote_tlbs,
> +	.vm_flush_remote_tlbs_range	= realm_flush_remote_tlbs_range,
> +	.vm_age_gfn			= no_age_gfn,
> +	.vm_test_age_gfn		= no_age_gfn,
> +	.vm_stage2_unmap_range		= realm_stage2_unmap_range,
> +	.vm_mem_abort			= realm_mem_abort,
> +};
> +
>  #define KVM_VM_S2_OPS(flavor, ops)		\
>  		[(flavor)] = &(ops)
>  
> @@ -3365,7 +3408,7 @@ static const struct kvm_vm_s2_ops *arm64_vm_s2_ops[] = {
>  	KVM_VM_S2_OPS(VM_NVHE, kvm_default_vm_s2_ops),
>  	KVM_VM_S2_OPS(VM_PKVM, pkvm_vm_s2_ops),
>  	KVM_VM_S2_OPS(VM_PROTECTED_PKVM, protected_pkvm_vm_s2_ops),
> -	[VM_REALM] = NULL,
> +	KVM_VM_S2_OPS(VM_REALM, realm_vm_s2_ops),
>  };

[Severity: Critical]
Does registering realm_mem_abort() leave unprotected shared stage-2 mappings
live across kvm_mmu_notifier_release()?

realm_mem_abort() allows a Realm guest to install unpinned userspace-backed
shared mappings via user_mem_abort() -> realm_s2_fault_map(), which releases
its page reference immediately and relies on MMU notifiers to tear down all
stage-2 mappings before host pages are freed.  During exit_mmap(),
mn_hlist_release() invokes kvm_mmu_notifier_release() ->
kvm_uninit_stage2_mmu() -> kvm_realm_uninit_stage2() ->
kvm_realm_unmap_stage2_all() and unlinks the notifier before unmap_vmas()
frees the mm pages without calling invalidate_range_start().

arch/arm64/kvm/rmi.c:kvm_realm_unmap_stage2_all() {
    ...
	write_lock(&kvm->mmu_lock);
	kvm_realm_unmap_range_filter(kvm, 0,
				     BIT(realm->ia_bits - 1), true,
				     KVM_FILTER_PRIVATE);
	write_unlock(&kvm->mmu_lock);
    ...
}

Because kvm_realm_unmap_stage2_all() omits KVM_FILTER_SHARED, shared RTT
entries remain live after exit_mmap() returns those physical pages to the
kernel allocator.  If another process holds the VM or vCPU fd, a Realm vCPU
can read and write reallocated host RAM (guest-to-host physical memory
use-after-free).  Passing KVM_FILTER_PRIVATE | KVM_FILTER_SHARED in
kvm_realm_unmap_stage2_all() would tear down shared mappings before the pages
are freed.

[Severity: Low]
This question rests on an architecture detail that could not be confirmed from
the kernel source: can a Realm REC exit ever report a stage-2 access flag
fault FSC in ESR that reaches kvm_handle_guest_abort() (for example on a
shared IPA)?

If it can, kvm_handle_guest_abort() handles esr_fsc_is_access_flag_fault(esr)
via handle_access_fault() before dispatching to vm_mem_abort().  Unlike
protected pKVM, which guards pkvm_pgtable_stage2_mkyoung() with
WARN_ON(kvm_vm_is_protected(...)), is_protected_kvm_enabled() is false for
VM_REALM, so handle_access_fault() calls kvm_pgtable_stage2_mkyoung() directly
on mmu->pgt, walking the RMM-delegated root RTT pages from the host and
triggering a Granule Protection Fault.

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

  reply	other threads:[~2026-12-04 12:44 UTC|newest]

Thread overview: 27+ 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-05 11:51     ` Suzuki K Poulose
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 [this message]
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-249829@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.