KVM: arm64: pkvm: Use the mm_ops indirection for cache maintenance
Marc Zyngier
maintainerPATCH 1/1 KVM: arm64: pkvm: Use the mm_ops indirection for cache maintenance
CMOs issued from EL2 cannot directly use the kernel helpers, as EL2 doesn't have a mapping of the guest pages. Oops.
Instead, use the mm_ops indirection to use helpers that will perform a mapping at EL2 and allow the CMO to be effective.
Fixes 25aa28691bb9 ("KVM: arm64: Move guest CMOs to the fault handlers")
Signed-off-by Marc Zyngier <[email protected]>
--- arch/arm64/kvm/hyp/pgtable.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
arch/arm64/kvm/hyp/pgtable.c +6 -12
@@ -983,13 +983,9 @@ static int stage2_unmap_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,*/ stage2_put_pte (ptep, mmu, addr, level, mm_ops); -if (need_flush) { -kvm_pte_t *pte_follow =kvm_pte_follow (pte, mm_ops); - -dcache_clean_inval_poc ((unsigned long )pte_follow, - (unsigned long )pte_follow + -kvm_granule_size (level)); - } +if (need_flush && mm_ops->dcache_clean_inval_poc) + mm_ops->dcache_clean_inval_poc (kvm_pte_follow (pte, mm_ops), +kvm_granule_size (level));if (childp) mm_ops->put_page (childp);
@@ -1151,15 +1147,13 @@ static int stage2_flush_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,struct kvm_pgtable *pgt = arg;struct kvm_pgtable_mm_ops *mm_ops = pgt->mm_ops;kvm_pte_t pte = *ptep; -kvm_pte_t *pte_follow;if (!kvm_pte_valid (pte) || !stage2_pte_cacheable (pgt, pte))return 0 ; - pte_follow =kvm_pte_follow (pte, mm_ops); -dcache_clean_inval_poc ((unsigned long )pte_follow, - (unsigned long )pte_follow + -kvm_granule_size (level)); +if (mm_ops->dcache_clean_inval_poc) + mm_ops->dcache_clean_inval_poc (kvm_pte_follow (pte, mm_ops), +kvm_granule_size (level));return 0 ; }
Signature · 1 line
2.30.2
Quoted 5 lines · Marc Zyngier
CMOs issued from EL2 cannot directly use the kernel helpers, as EL2 doesn't have a mapping of the guest pages. Oops.
Instead, use the
mm_opsindirection to use helpers that will perform a mapping at EL2 and allow the CMO to be effective.
Right, we were clearly lucky not to use those paths at EL2 _yet_, but that's going to change soon and this is better for consistency, so:
Reviewed-by Quentin Perret <[email protected]>
Quoted 49 lines
Fixes 25aa28691bb9 ("KVM: arm64: Move guest CMOs to the fault handlers")Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp/pgtable.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)arch/arm64/kvm/hyp/pgtable.c +6
-12@@ -983,13 +983,9 @@ static int stage2_unmap_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,*/ stage2_put_pte (ptep, mmu, addr, level, mm_ops); -if (need_flush) { -kvm_pte_t *pte_follow =kvm_pte_follow (pte, mm_ops); - -dcache_clean_inval_poc ((unsigned long )pte_follow, - (unsigned long )pte_follow + -kvm_granule_size (level)); - } +if (need_flush && mm_ops->dcache_clean_inval_poc) + mm_ops->dcache_clean_inval_poc (kvm_pte_follow (pte, mm_ops), +kvm_granule_size (level));if (childp) mm_ops->put_page (childp);@@ -1151,15 +1147,13 @@ static int stage2_flush_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep,struct kvm_pgtable *pgt = arg;struct kvm_pgtable_mm_ops *mm_ops = pgt->mm_ops;kvm_pte_t pte = *ptep; -kvm_pte_t *pte_follow;if (!kvm_pte_valid (pte) || !stage2_pte_cacheable (pgt, pte))return 0 ; - pte_follow =kvm_pte_follow (pte, mm_ops); -dcache_clean_inval_poc ((unsigned long )pte_follow, - (unsigned long )pte_follow + -kvm_granule_size (level)); +if (mm_ops->dcache_clean_inval_poc) + mm_ops->dcache_clean_inval_poc (kvm_pte_follow (pte, mm_ops), +kvm_granule_size (level));return 0 ; }Signature · 1 line
2.30.2