From: Quentin Perret <qperret@xxxxxxxxxx> Add support for cache flushing a range of the stage-2 address space to the generic page-table code. Cc: Marc Zyngier <maz@xxxxxxxxxx> Signed-off-by: Quentin Perret <qperret@xxxxxxxxxx> Signed-off-by: Will Deacon <will@xxxxxxxxxx> --- arch/arm64/include/asm/kvm_pgtable.h | 12 ++++++++++++ arch/arm64/kvm/pgtable.c | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index ce90432ec6b9..e4d99556a22f 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -208,6 +208,18 @@ kvm_pte_t kvm_pgtable_stage2_mkold(void *cookie, u64 addr); */ bool kvm_pgtable_stage2_is_young(void *cookie, u64 addr); +/** + * kvm_pgtable_stage2_flush_range() - Clean and invalidate data cache to Point + * of Coherency for guest stage-2 address + * range. + * @cookie: Opaque cookie allocated by kvm_pgtable_stage2_alloc_cookie(). + * @addr: Intermediate physical address from which to flush. + * @size: Size of the range. + * + * Return: 0 on success, negative error code on failure. + */ +int kvm_pgtable_stage2_flush(void *cookie, u64 addr, u64 size); + /** * kvm_pgtable_get_pgd_phys() - Get physical pgd pointer for a page-table. * @cookie: Opaque cookie allocated by kvm_pgtable_*_alloc_cookie(). diff --git a/arch/arm64/kvm/pgtable.c b/arch/arm64/kvm/pgtable.c index 52cb3d5f156e..eb41f162a36a 100644 --- a/arch/arm64/kvm/pgtable.c +++ b/arch/arm64/kvm/pgtable.c @@ -800,6 +800,33 @@ bool kvm_pgtable_stage2_is_young(void *cookie, u64 addr) return !!(pte & KVM_PTE_LEAF_ATTR_LO_S2_AF); } + +static int stage2_flush_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, + enum kvm_pgtable_walk_flags flag, + void * const arg) +{ + kvm_pte_t pte = *ptep; + + if (!kvm_pte_valid(pte) || !stage2_pte_cacheable(pte)) + return 0; + + stage2_flush_dcache(kvm_pte_follow(pte), kvm_granule_size(level)); + return 0; +} + +int kvm_pgtable_stage2_flush(void *cookie, u64 addr, u64 size) +{ + struct kvm_pgtable_walker walker = { + .cb = stage2_flush_walker, + .flags = KVM_PGTABLE_WALK_LEAF, + }; + + if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB)) + return 0; + + return kvm_pgtable_walk(cookie, addr, size, &walker); +} + void *kvm_pgtable_stage2_alloc_cookie(struct kvm *kvm) { size_t pgd_sz; -- 2.28.0.rc0.142.g3c755180ce-goog _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm