From ca5e2707ba4cc26f61680231f4501eb5c55f76f5 Mon Sep 17 00:00:00 2001 From: Sebastian Ene Date: Wed, 10 Aug 2022 13:38:34 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Split stage2_put_pte function Refactor the code and add stage2_clear_pte(..) which removes the PTE without dropping the refcount for an entry. Bug: 222044487 Signed-off-by: Sebastian Ene Change-Id: Ia2cb47f2ffad6faa5c6b4ec8a37bcbe61be0bc2f Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/pgtable.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index ead0c5e5c6ba..6dddfc20c7dc 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -662,6 +662,16 @@ static bool stage2_pte_is_counted(kvm_pte_t pte) return !!pte; } +static void stage2_clear_pte(kvm_pte_t *ptep, struct kvm_s2_mmu *mmu, u64 addr, + u32 level) +{ + if (!kvm_pte_valid(*ptep)) + return; + + kvm_clear_pte(ptep); + kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, addr, level); +} + static void stage2_put_pte(kvm_pte_t *ptep, struct kvm_s2_mmu *mmu, u64 addr, u32 level, struct kvm_pgtable_mm_ops *mm_ops) { @@ -669,11 +679,7 @@ static void stage2_put_pte(kvm_pte_t *ptep, struct kvm_s2_mmu *mmu, u64 addr, * Clear the existing PTE, and perform break-before-make with * TLB maintenance if it was valid. */ - if (kvm_pte_valid(*ptep)) { - kvm_clear_pte(ptep); - kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, mmu, addr, level); - } - + stage2_clear_pte(ptep, mmu, addr, level); mm_ops->put_page(ptep); }