arm/arm64: KVM: Enforce unconditional flush to PoC when mapping to stage-2
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
RFC PATCH 1/6 arm/arm64: KVM: Enforce unconditional flush to PoC when mapping to stage-2
From: Marc Zyngier <[email protected]>
When we fault in a page, we flush it to the PoC (Point of Coherency) if the faulting vcpu has its own caches off, so that it can observe the page we just brought it.
But if the vcpu has its caches on, we skip that step. Bad things happen when *another* vcpu tries to access that page with its own caches disabled. At that point, there is no garantee that the data has made it to the PoC, and we access stale data.
The obvious fix is to always flush to PoC when a page is faulted in, no matter what the state of the vcpu is.
--- arch/arm/include/asm/kvm_mmu.h | 9 +-------- arch/arm64/include/asm/kvm_mmu.h | 3 +-- 2 files changed, 2 insertions(+), 10 deletions(-)
arch/arm/include/asm/kvm_mmu.h +1 -8
@@ -150,18 +150,12 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu,* and iterate over the range. */ -bool need_flush = !vcpu_has_cache_enabled (vcpu) || ipa_uncached; -VM_BUG_ON (size & ~PAGE_MASK ); -if (!need_flush && !icache_is_pipt ()) - goto vipt_cache; -while (size) {void *va =kmap_atomic_pfn (pfn); -if (need_flush) -kvm_flush_dcache_to_poc (va,PAGE_SIZE ); +kvm_flush_dcache_to_poc (va,PAGE_SIZE );if (icache_is_pipt ()) __cpuc_coherent_user_range((unsigned long)va,
@@ -173,7 +167,6 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu,kunmap_atomic (va); } -vipt_cache:if (!icache_is_pipt () && !icache_is_vivt_asid_tagged ()) {/* any kind of VIPT cache */ __flush_icache_all ();
arch/arm64/include/asm/kvm_mmu.h +1 -2
@@ -241,8 +241,7 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu, {void *va =page_address (pfn_to_page (pfn)); -if (!vcpu_has_cache_enabled (vcpu) || ipa_uncached) -kvm_flush_dcache_to_poc (va, size); +kvm_flush_dcache_to_poc (va, size);if (!icache_is_aliasing ()) {/* PIPT */ flush_icache_range((unsigned long)va,
Signature · 1 line
2.11.0
Apologies for the span. Please ignore the previous posting. I messed up the git send-email rune and the email escaped into the wild.
Need to improve email workflow.
Apologies,
Punit
Quoted 60 lines · Punit Agrawal
From: Marc Zyngier <[email protected]>
When we fault in a page, we flush it to the PoC (Point of Coherency) if the faulting vcpu has its own caches off, so that it can observe the page we just brought it.
But if the vcpu has its caches on, we skip that step. Bad things happen when *another* vcpu tries to access that page with its own caches disabled. At that point, there is no garantee that the data has made it to the PoC, and we access stale data.
The obvious fix is to always flush to PoC when a page is faulted in, no matter what the state of the vcpu is.
Fixes 2d58b733c876 ("arm64: KVM: force cache clean on page fault when caches are off")Signed-off-by Marc Zyngier <[email protected]>--- arch/arm/include/asm/kvm_mmu.h | 9 +-------- arch/arm64/include/asm/kvm_mmu.h | 3 +-- 2 files changed, 2 insertions(+), 10 deletions(-)arch/arm/include/asm/kvm_mmu.h +1
-8@@ -150,18 +150,12 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu,* and iterate over the range. */ -bool need_flush = !vcpu_has_cache_enabled (vcpu) || ipa_uncached; -VM_BUG_ON (size & ~PAGE_MASK ); -if (!need_flush && !icache_is_pipt ()) - goto vipt_cache; -while (size) {void *va =kmap_atomic_pfn (pfn); -if (need_flush) -kvm_flush_dcache_to_poc (va,PAGE_SIZE ); +kvm_flush_dcache_to_poc (va,PAGE_SIZE );if (icache_is_pipt ()) __cpuc_coherent_user_range((unsigned long)va,@@ -173,7 +167,6 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu,kunmap_atomic (va); } -vipt_cache:if (!icache_is_pipt () && !icache_is_vivt_asid_tagged ()) {/* any kind of VIPT cache */ __flush_icache_all ();arch/arm64/include/asm/kvm_mmu.h +0
-0
arch/arm64/include/asm/kvm_mmu.h static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu, · line 247
Quoted 9 lines
arch/arm64/include/asm/kvm_mmu.h +1
-2@@ -241,8 +241,7 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu, {void *va =page_address (pfn_to_page (pfn)); -if (!vcpu_has_cache_enabled (vcpu) || ipa_uncached) -kvm_flush_dcache_to_poc (va, size); +kvm_flush_dcache_to_poc (va, size);if (!icache_is_aliasing ()) {/* PIPT */ flush_icache_range((unsigned long)va,
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.