From 255b30f804ac6b0383bc7ca2ec1db4028233acc9 Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Tue, 1 Mar 2022 10:22:55 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Ignore length of 0 in kvm_flush_dcache_to_poc() kvm_flush_dcache_to_poc() converts its (start,len) parameters into (start,end) parameters for dcache_clean_inval_poc(). This mostly works out except for the case when 'len == 0', where dcache_clean_inval_poc() will still issue cache maintenance for the cache line containing 'start'. If 'start' is not mapped, then this can generate an unexpected fault. Don't call into dcache_clean_inval_poc() from kvm_flush_dcache_to_poc() if the supplied length is 0. Reported-by: John Stultz Bug: 196204410 Signed-off-by: Will Deacon Change-Id: Idae2b22289398e941938821d1d3b3a5a1da3fd8f --- arch/arm64/include/asm/kvm_mmu.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 0c2589513be3..7a8dc3f343ec 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -182,8 +182,13 @@ static inline void *__kvm_vector_slot2addr(void *base, struct kvm; -#define kvm_flush_dcache_to_poc(a,l) \ - dcache_clean_inval_poc((unsigned long)(a), (unsigned long)(a)+(l)) +#define kvm_flush_dcache_to_poc(a, l) do { \ + unsigned long __a = (unsigned long)(a); \ + unsigned long __l = (unsigned long)(l); \ + \ + if (__l) \ + dcache_clean_inval_poc(__a, __a + __l); \ +} while (0) static inline bool vcpu_has_cache_enabled(struct kvm_vcpu *vcpu) {