From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org> mainline inclusion from mainline-v7.4-rc1 commit d27acc152c62f368d4d4d9d3f0faa891c154e4ce category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/10374 CVE: NA Reference: https://github.com/torvalds/linux/commit/d27acc152c62f368d4d4d9d3f0faa891c15... -------------------------------- commit d27acc152c62f368d4d4d9d3f0faa891c154e4ce upstream topup_mmu_memcache() sizes the page-table cache from vcpu->arch.hw_mmu, which is the MMU that faulted. Pass the target s2fd->mmu instead, so the mmu used can be controlled by the caller. For a guest abort this is vcpu->arch.hw_mmu, so this commit introduces no functional change in practice. However, it's necessary for a future change which introduces stage 2 pre-faulting which must always target the canonical MMU regardless of the vCPU's last-run context. No functional change intended. [Backport note] Adapted for OLK-6.6: - OLK-6.6 has no topup_mmu_memcache() helper and sizes the cache inline in user_mem_abort() via kvm_mmu_cache_min_pages(kvm), which derives the level count from kvm->arch.vtcr rather than from a kvm_s2_mmu. - A small kvm_mmu_cache_min_pages_mmu() wrapper recovers the owning kvm from the target MMU and is used by user_mem_abort(), preserving the upstream intent of sizing the cache from the fault MMU. - The PVM path sizes its cache from the same fault MMU; the existing PVM_PGTABLE_LEVELS() lower bound is still applied afterwards. Reviewed-by: Oliver Upton <oupton@kernel.org> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Tested-by: Fuad Tabba <fuad.tabba@linux.dev> Link: https://patch.msgid.link/20260923-kvm-arm-prefault-v4-7-d4b0b4dfa8c3@kernel.... Signed-off-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Yanan Wang <wangyanan55@huawei.com> --- arch/arm64/kvm/mmu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 67e76e2096bb..47c1e6f46af9 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1610,6 +1610,11 @@ struct kvm_s2_fault_result { unsigned long mapping_size; }; +static int kvm_mmu_cache_min_pages_mmu(struct kvm_s2_mmu *mmu) +{ + return kvm_mmu_cache_min_pages(kvm_s2_mmu_to_kvm(mmu)); +} + static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd, struct kvm_s1_trans *result, unsigned long fault_status, unsigned long shadow_seq, @@ -1643,7 +1648,7 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd, enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; bool kernel_shadow = result && kvm_pvm_is_kernel_va(fault_ipa); - int cache_min_pages = kvm_mmu_cache_min_pages(kvm); + int cache_min_pages = kvm_mmu_cache_min_pages_mmu(mmu); fault_granule = result ? PAGE_SIZE : 1UL << ARM64_HW_PGTABLE_LEVEL_SHIFT(fault_level); -- 2.43.0