Skip to contentSkip to conversation

Patch "arm64: KVM: flush VM pages before letting the guest enable caches" has been added to the 3.14-stable tree

PATCH [email protected] 1 participant 1 message May 15, 2015

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

arm64: KVM: flush VM pages before letting the guest enable caches

to the 3.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
arm64-kvm-flush-vm-pages-before-letting-the-guest-enable-caches.patch
and it can be found in the queue-3.14 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From 9d218a1fcf4c6b759d442ef702842fae92e1ea61 Mon Sep 17 00:00:00 2001

From: Marc Zyngier <[email protected]>
Date: Wed, 15 Jan 2014 12:50:23 +0000
Subject: arm64: KVM: flush VM pages before letting the guest enable caches

From: Marc Zyngier <[email protected]>

commit 9d218a1fcf4c6b759d442ef702842fae92e1ea61 upstream.

When the guest runs with caches disabled (like in an early boot sequence, for example), all the writes are diectly going to RAM, bypassing the caches altogether.

Once the MMU and caches are enabled, whatever sits in the cache becomes suddenly visible, which isn't what the guest expects.

A way to avoid this potential disaster is to invalidate the cache when the MMU is being turned on. For this, we hook into the SCTLR_EL1 trapping code, and scan the stage-2 page tables, invalidating the pages/sections that have already been mapped in.

---
 arch/arm/include/asm/kvm_mmu.h   |    2 
 arch/arm/kvm/mmu.c               |   93 +++++++++++++++++++++++++++++++++++++++
 arch/arm64/include/asm/kvm_mmu.h |    2 
 arch/arm64/kvm/sys_regs.c        |    5 +-
 4 files changed, 101 insertions(+), 1 deletion(-)
arch/arm/include/asm/kvm_mmu.h +2 -0
@@ -155,6 +155,8 @@ static inline void coherent_cache_guest_
 #define kvm_flush_dcache_to_poc(a,l)	__cpuc_flush_dcache_area((a), (l))
 #define kvm_virt_to_phys(x)		virt_to_idmap((unsigned long)(x))
 
+void stage2_flush_vm(struct kvm *kvm);
+
 #endif	/* !__ASSEMBLY__ */
 
 #endif /* __ARM_KVM_MMU_H__ */
arch/arm/kvm/mmu.c +93 -0

99 lines not on this page · raw message

arch/arm64/include/asm/kvm_mmu.h +2 -0
@@ -150,5 +150,7 @@ static inline void coherent_cache_guest_
 
 #define kvm_virt_to_phys(x)		__virt_to_phys((unsigned long)(x))
 
+void stage2_flush_vm(struct kvm *kvm);
+
 #endif /* __ASSEMBLY__ */
 #endif /* __ARM64_KVM_MMU_H__ */
arch/arm64/kvm/sys_regs.c +4 -1
@@ -27,6 +27,7 @@
 #include <asm/kvm_host.h>
 #include <asm/kvm_emulate.h>
 #include <asm/kvm_coproc.h>
+#include <asm/kvm_mmu.h>
 #include <asm/cacheflush.h>
 #include <asm/cputype.h>
 #include <trace/events/kvm.h>
@@ -154,8 +155,10 @@ static bool access_sctlr(struct kvm_vcpu
 {
 	access_vm_reg(vcpu, p, r);
 
-	if (vcpu_has_cache_enabled(vcpu))	/* MMU+Caches enabled? */
+	if (vcpu_has_cache_enabled(vcpu)) {	/* MMU+Caches enabled? */
 		vcpu->arch.hcr_el2 &= ~HCR_TVM;
+		stage2_flush_vm(vcpu->kvm);
+	}
 
 	return true;
 }

Patches currently in stable-queue which might be from [email protected] are

queue-3.14/kvm-arm-arm64-vgic-fix-gicd_icfgr-register-accesses.patch queue-3.14/arm-kvm-introduce-per-vcpu-hyp-configuration-register.patch queue-3.14/arm-kvm-fix-handling-of-trapped-64bit-coprocessor-accesses.patch queue-3.14/kvm-arm64-vgic-fix-hyp-panic-with-64k-pages-on-juno-platform.patch queue-3.14/arm64-kvm-force-cache-clean-on-page-fault-when-caches-are-off.patch queue-3.14/arm-kvm-introduce-kvm_p-d_addr_end.patch queue-3.14/arm64-kvm-flush-vm-pages-before-letting-the-guest-enable-caches.patch queue-3.14/arm-kvm-force-cache-clean-on-page-fault-when-caches-are-off.patch queue-3.14/arm-kvm-add-world-switch-for-amair-0-1.patch queue-3.14/kvm-arm-vgic-fix-the-overlap-check-action-about-setting-the-gicd-gicc-base-address.patch queue-3.14/arm64-kvm-use-inner-shareable-barriers-for-inner-shareable-maintenance.patch queue-3.14/arm64-kvm-allows-discrimination-of-aarch32-sysreg-access.patch queue-3.14/arm-kvm-trap-vm-system-registers-until-mmu-and-caches-are-on.patch queue-3.14/arm-kvm-fix-ordering-of-64bit-coprocessor-accesses.patch queue-3.14/arm64-kvm-trap-vm-system-registers-until-mmu-and-caches-are-on.patch