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=1796387951; b=tkEjdz8qmRy5QJS34zYjKc7wlqj5vaIejcT52FdgWD2xUmq8TtB2rCs/msClkDBPZ+DH rkDDDglEwV1vOSJo2EA7gTs/WRZ9s4M5MOjX9+BuLDbkIIF64w4mIQquDNL8Pk/flgzBq 905UxOPFyTqY1cW8/nqtzOS9h8It1jYhKz+S3mRMkf3Ggr6Un30ECBo2Hu5gyOcEPIPf9 OvrFhgkfdUvlnociISUu0dFPsFkBZ8Ad3SMMNb38gDUDxJD+aowHJhLmVHnoKHHMrastd KXAiOTEyQ2E3W2dwRtMzJtY8m8dn6HDiz1sXJ37jRn3sa2nFngMNYtcD1ucSTjsNx7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387951; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=raGPw3Dz3mB8807MrqqzdyP1wXyvNN9VfTMrlBapDoQ=; b=I1Nz2NZC+xdcweTTb0Ep5TMZxYFeyMlT0YhrpAl9+SWaSrQL2apwx1mgtEoLmmrOjB3Q WEk8qNcIVpbmoJmKZ0HHpdz4aIrenEkwNwdOawaUDUDCHMqMneaX0FJNDmEotJty9y42v 8/Oq7gLU9qwrK0xyJCfpVV/EZ8YNg9uTy/QJvYGnXO0ZobzTj32JeBwP7kaxn+r2c3uwA mojMCshF6lgT0O7lsQhK2CzdNK/PCV+1Um1DkLFK/YNIhVlwPB/HLfwrh5NX0N7Gl0T65 yKUI0OVHaW5qKF/aqj80DDqSpY08HSxkoai5tUMdGJ4m8d3ReDLfozT7hyUTm//KtQg== 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="hKN+/a9n"; 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 BCD86606A32D; Fri, 4 Dec 2026 12:39:11 +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=hKN+/a9n Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60B4D1F000CE; Fri, 4 Dec 2026 12:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796387951; bh=raGPw3Dz3mB8807MrqqzdyP1wXyvNN9VfTMrlBapDoQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hKN+/a9nkatqg1X0CcmsFhNpPxizx4sNdBYiAtjyerp3t+mToVocIg/P1hFcjmxx1 nIdFv40buTPAP6/G2h+yN0upIze5deHAETtw3ASbozKG9JzoMv+p7fL8XLyohdFNTQ lnR2lIH/5shnUiHqRQy7/Fdvuka4AfLJRjLHXqulwk/E8MFmAlrG0VexJc4bTbTUT1 8/PtXjLm7hrsoowXeql3aJ//F1X2jZHRmLQReKXbS4ERzzShaCShey9067jQ5MNZrR uGZ4ljlN8tSHh8ruMZ2qgnWNcbzIjPoXC++iAegz+YGSlCrqM58YlMz5sh1eNgKaai jNz6+fm5CovQQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 10/11] KVM: arm64: CCA: Support runtime faulting of memory 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-11-steven.price@arm.com> References: <20261204115725.45272-1-steven.price@arm.com> <20261204115725.45272-11-steven.price@arm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 12:39:11 +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: - [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 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_fa= ult_desc *s2fd, > return ret; > } > =20 > +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 =3D ALIGN_DOWN(s2fd->fault_ipa, mapping_size); > + ret =3D 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 =3D 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 =3D=3D 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 =3D 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 =3D=3D phys and realm_map_protected() returns 0 without chec= king 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204115725.4527= 2-1-steven.price@arm.com?part=3D10