From 1a48a88fcb0aae008b14ef1610dd3467ebfdb79a Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Wed, 27 Mar 2024 12:48:51 +0000 Subject: [PATCH] FROMGIT: BACKPORT: KVM: arm64: Don't pass a TLBI level hint when zapping table entries commit 36e008323926036650299cfbb2dca704c7aba849 upstream. The TLBI level hints are for leaf entries only, so take care not to pass them incorrectly after clearing a table entry. Cc: Gavin Shan Cc: Marc Zyngier Cc: Quentin Perret Fixes: 82bb02445de5 ("KVM: arm64: Implement kvm_pgtable_hyp_unmap() at EL2") Fixes: 6d9d2115c480 ("KVM: arm64: Add support for stage-2 map()/unmap() in generic page-table") Reviewed-by: Shaoqin Huang Reviewed-by: Marc Zyngier Link: https://lore.kernel.org/r/20240327124853.11206-3-will@kernel.org Signed-off-by: Oliver Upton Cc: # 6.1.y only [will@: Use '0' instead of TLBI_TTL_UNKNOWN_to indicate "no level". Force level to 0 in stage2_put_pte() if we're clearing a table entry.] Signed-off-by: Will Deacon (cherry picked from commit 298e875b36613fe02d622b7ac16d0112f57707e1 stable/linux-6.1.y) Bug: 311571169 Signed-off-by: Will Deacon Change-Id: Icefe7099ccf03c4ba96e395dfc225f0015e3fccc --- arch/arm64/kvm/hyp/pgtable.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index ea51f04be78f..52e17cfac0d7 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -420,7 +420,7 @@ static int hyp_unmap_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, kvm_clear_pte(ptep); dsb(ishst); - __tlbi_level(vae2is, __TLBI_VADDR(addr, 0), level); + __tlbi_level(vae2is, __TLBI_VADDR(addr, 0), 0); } else { if (end - addr < granule) return -EINVAL; @@ -661,10 +661,15 @@ static bool stage2_pte_needs_update(struct kvm_pgtable *pgt, static void stage2_clear_pte(kvm_pte_t *ptep, struct kvm_s2_mmu *mmu, u64 addr, u32 level) { - if (!kvm_pte_valid(*ptep)) + kvm_pte_t pte = *ptep; + + if (!kvm_pte_valid(pte)) return; kvm_clear_pte(ptep); + + if (kvm_pte_table(pte, level)) + level = 0; kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, addr, level); }