From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388271; b=zif6Pxwcq93nlrliA479nc01XOZMuZ2gScdHogThsJ7/TzM1YQ3qdQ4+8zHxsaPpQY22 ZUeqNYPAqOTxy4hmgECy8beV1afrr8GJ3V6X1d3vD6PnmhACCrVkvjhOASD9VO83Y00na 2Q1o+lYg518HMtRyoMg9IGSjufoYHzSTO8O/rRsxdfE985SfdcWeJppgJyVnvczlr2RpD +p06Cil64R5yqquo4jWfp98mOJm0TeT/CPeclPTpcZQ8bxMFvaV++NJA2VjHhaizl7QEp U8/0QhjWMxpw/78ylbzwM6KkIF/C9Qkx0SO2uOmIPaKNEilOC7lE7Bn0H6UT/WWEuKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388271; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=BkeLkWJi/NrSA0XapUGrBN0ccX5US1SFVCUkOML6ExM=; b=f5PLEdFFv+dFjBNEMkoowJlEPGwS9p654lo/+25lvi/owHF4f7VSDqtMiVMHv4GD5cKb WZpFV1axeA4EZIkR3JHz+V9EVmjV12kQ6bXuvhXr7ZtzJWsva/Abx7O046wZmtuC5pS4b nevZUIGqvDLIxBhyxQFvxysa/9UbUr9FFxno1p+3X3h5FdP8Wl7Q81mXN9ApJl3bDRGwP rHredIovw3Eo8Lx+p8uHJKzz+OQPvAfmRxJllCgV4MDbAHQ58lXMiitfHoDGmDweM5yNV 06p6+XJGskIezs1hMbA2pVpRSXMjR5vyJAb5mypcqeRhAEZab2xJedW+VGOEZ8cm48g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NJGVTpY7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A502606A338; Fri, 4 Dec 2026 12:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NJGVTpY7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA9E41F000CE; Fri, 4 Dec 2026 12:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796388271; bh=BkeLkWJi/NrSA0XapUGrBN0ccX5US1SFVCUkOML6ExM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NJGVTpY7EkhRA1sp4hUInPH+rV2/wyZEMYQr4111s6Ae/N4+S+JCfRDa+h6NLk8sT o+mC/Q239972zjeNTZk3hj7iRVMfs8vgcGRsz3HEh6zM23+hiCghDWRkD0Bn1sYHH/ BQNjgzsRLTuF9W0TD6bTd3Ao+Jek2jdRXWI3ZPS0O79VUe50FZueZqFS+X9kfTKsF1 wYxlRIPZbNw4N0HsOmNdLfwqjXLho1LS6ueKnQlnusuK2PpvUF4LUNeepWhJfQJ/9D lnSKZAa5QwRDDl5Vl1M5u4XMDzjhUSPgp+pZXNs4MFtam7bzf53AcDMokmx7kCU3PE YYJ9pYoKGC5aA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Reply-To: sashiko-reviews@lists.linux.dev To: "Steven Price" , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: "Oliver Upton" , "Marc Zyngier" In-Reply-To: <20261204115725.45272-12-steven.price@arm.com> References: <20261204115725.45272-1-steven.price@arm.com> <20261204115725.45272-12-steven.price@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 12:44:30 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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, > { > } > =20 > +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 =3D 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) tim= es 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_des= c() (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 confir= med from the kernel source: do SMC_RMI_RTT_UNPROT_UNMAP and SMC_RMI_RTT_DATA_UN= MAP 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 >=3D 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, kv= m) if that allocation fails. [ ... ] > @@ -2478,7 +2511,7 @@ static int kvm_vm_mem_abort(const struct kvm_s2_fau= lt_desc *s2fd) > return user_mem_abort(s2fd, NULL, kvm_s2_fault_map); > } > =20 > -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 =3D s2fd->vcpu->kvm; > =20 [Severity: Low] This question rests on an RMM architectural detail that could not be confir= med from the kernel source: does SMC_RMI_RTT_UNPROT_MAP reject a 2MB block descriptor (block_size =3D=3D 1, req_level =3D=3D 2) with RMI_ERROR_RTT at = level >=3D 2 when the L2 RTT entry is a table pointing to an existing empty L3 RTT, rath= er 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 ran= ge on level >=3D 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_s= 2_ops =3D { > .vm_mem_abort =3D kvm_vm_mem_abort, > }; > =20 > +static const struct kvm_vm_s2_ops realm_vm_s2_ops =3D { > + .vm_stage2_destroy =3D realm_stage2_destroy, > + .vm_flush_remote_tlbs =3D realm_flush_remote_tlbs, > + .vm_flush_remote_tlbs_range =3D realm_flush_remote_tlbs_range, > + .vm_age_gfn =3D no_age_gfn, > + .vm_test_age_gfn =3D no_age_gfn, > + .vm_stage2_unmap_range =3D realm_stage2_unmap_range, > + .vm_mem_abort =3D realm_mem_abort, > +}; > + > #define KVM_VM_S2_OPS(flavor, ops) \ > [(flavor)] =3D &(ops) > =20 > @@ -3365,7 +3408,7 @@ static const struct kvm_vm_s2_ops *arm64_vm_s2_ops[= ] =3D { > 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] =3D 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 pag= es are freed. [Severity: Low] This question rests on an architecture detail that could not be confirmed f= rom 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(es= r) 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() direc= tly on mmu->pgt, walking the RMM-delegated root RTT pages from the host and triggering a Granule Protection Fault. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204115725.4527= 2-1-steven.price@arm.com?part=3D11