linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Marc Zyngier <marc.zyngier@arm.com>,
	Shannon Zhao <shannon.zhao@linaro.org>,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 3.12 27/63] ARM: KVM: trap VM system registers until MMU and caches are ON
Date: Thu, 30 Apr 2015 14:11:56 +0200	[thread overview]
Message-ID: <4247324050f4465cfb0a8feb7b5bee262a083245.1430387326.git.jslaby@suse.cz> (raw)
In-Reply-To: <45aaf85687dd6ac119c55c5ec0dbe0bef0e62235.1430387326.git.jslaby@suse.cz>
In-Reply-To: <cover.1430387326.git.jslaby@suse.cz>

From: Marc Zyngier <marc.zyngier@arm.com>

3.12-stable review patch.  If anyone has any objections, please let me know.

===============

commit 8034699a42d68043b495c7e0cfafccd920707ec8 upstream.

In order to be able to detect the point where the guest enables
its MMU and caches, trap all the VM related system registers.

Once we see the guest enabling both the MMU and the caches, we
can go back to a saner mode of operation, which is to leave these
registers in complete control of the guest.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 arch/arm/include/asm/kvm_arm.h |  3 ++-
 arch/arm/kvm/coproc.c          | 60 +++++++++++++++++++++++++++++-------------
 arch/arm/kvm/coproc.h          |  4 +++
 arch/arm/kvm/coproc_a15.c      |  2 +-
 4 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/arch/arm/include/asm/kvm_arm.h b/arch/arm/include/asm/kvm_arm.h
index a843e74a384c..816db0bf2dd8 100644
--- a/arch/arm/include/asm/kvm_arm.h
+++ b/arch/arm/include/asm/kvm_arm.h
@@ -55,6 +55,7 @@
  * The bits we set in HCR:
  * TAC:		Trap ACTLR
  * TSC:		Trap SMC
+ * TVM:		Trap VM ops (until MMU and caches are on)
  * TSW:		Trap cache operations by set/way
  * TWI:		Trap WFI
  * TWE:		Trap WFE
@@ -68,7 +69,7 @@
  */
 #define HCR_GUEST_MASK (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \
 			HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \
-			HCR_TWE | HCR_SWIO | HCR_TIDCP)
+			HCR_TVM | HCR_TWE | HCR_SWIO | HCR_TIDCP)
 
 /* System Control Register (SCTLR) bits */
 #define SCTLR_TE	(1 << 30)
diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
index 5e882043864d..24edbdea617e 100644
--- a/arch/arm/kvm/coproc.c
+++ b/arch/arm/kvm/coproc.c
@@ -23,6 +23,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>
@@ -117,8 +118,8 @@ done:
  * is set.
  */
 static bool access_vm_reg(struct kvm_vcpu *vcpu,
-			 const struct coproc_params *p,
-			 const struct coproc_reg *r)
+			  const struct coproc_params *p,
+			  const struct coproc_reg *r)
 {
 	BUG_ON(!p->is_write);
 
@@ -130,6 +131,27 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu,
 }
 
 /*
+ * SCTLR accessor. Only called as long as HCR_TVM is set.  If the
+ * guest enables the MMU, we stop trapping the VM sys_regs and leave
+ * it in complete control of the caches.
+ *
+ * Used by the cpu-specific code.
+ */
+bool access_sctlr(struct kvm_vcpu *vcpu,
+		  const struct coproc_params *p,
+		  const struct coproc_reg *r)
+{
+	access_vm_reg(vcpu, p, r);
+
+	if (vcpu_has_cache_enabled(vcpu)) {	/* MMU+Caches enabled? */
+		vcpu->arch.hcr &= ~HCR_TVM;
+		stage2_flush_vm(vcpu->kvm);
+	}
+
+	return true;
+}
+
+/*
  * We could trap ID_DFR0 and tell the guest we don't support performance
  * monitoring.  Unfortunately the patch to make the kernel check ID_DFR0 was
  * NAKed, so it will read the PMCR anyway.
@@ -174,33 +196,35 @@ static const struct coproc_reg cp15_regs[] = {
 	{ CRn( 0), CRm( 0), Op1( 2), Op2( 0), is32,
 			NULL, reset_unknown, c0_CSSELR },
 
-	/* TTBR0/TTBR1: swapped by interrupt.S. */
-	{ CRm64( 2), Op1( 0), is64, NULL, reset_unknown64, c2_TTBR0 },
-	{ CRm64( 2), Op1( 1), is64, NULL, reset_unknown64, c2_TTBR1 },
-
-	/* TTBCR: swapped by interrupt.S. */
+	/* TTBR0/TTBR1/TTBCR: swapped by interrupt.S. */
+	{ CRm64( 2), Op1( 0), is64, access_vm_reg, reset_unknown64, c2_TTBR0 },
+	{ CRn(2), CRm( 0), Op1( 0), Op2( 0), is32,
+			access_vm_reg, reset_unknown, c2_TTBR0 },
+	{ CRn(2), CRm( 0), Op1( 0), Op2( 1), is32,
+			access_vm_reg, reset_unknown, c2_TTBR1 },
 	{ CRn( 2), CRm( 0), Op1( 0), Op2( 2), is32,
-			NULL, reset_val, c2_TTBCR, 0x00000000 },
+			access_vm_reg, reset_val, c2_TTBCR, 0x00000000 },
+	{ CRm64( 2), Op1( 1), is64, access_vm_reg, reset_unknown64, c2_TTBR1 },
 
 	/* DACR: swapped by interrupt.S. */
 	{ CRn( 3), CRm( 0), Op1( 0), Op2( 0), is32,
-			NULL, reset_unknown, c3_DACR },
+			access_vm_reg, reset_unknown, c3_DACR },
 
 	/* DFSR/IFSR/ADFSR/AIFSR: swapped by interrupt.S. */
 	{ CRn( 5), CRm( 0), Op1( 0), Op2( 0), is32,
-			NULL, reset_unknown, c5_DFSR },
+			access_vm_reg, reset_unknown, c5_DFSR },
 	{ CRn( 5), CRm( 0), Op1( 0), Op2( 1), is32,
-			NULL, reset_unknown, c5_IFSR },
+			access_vm_reg, reset_unknown, c5_IFSR },
 	{ CRn( 5), CRm( 1), Op1( 0), Op2( 0), is32,
-			NULL, reset_unknown, c5_ADFSR },
+			access_vm_reg, reset_unknown, c5_ADFSR },
 	{ CRn( 5), CRm( 1), Op1( 0), Op2( 1), is32,
-			NULL, reset_unknown, c5_AIFSR },
+			access_vm_reg, reset_unknown, c5_AIFSR },
 
 	/* DFAR/IFAR: swapped by interrupt.S. */
 	{ CRn( 6), CRm( 0), Op1( 0), Op2( 0), is32,
-			NULL, reset_unknown, c6_DFAR },
+			access_vm_reg, reset_unknown, c6_DFAR },
 	{ CRn( 6), CRm( 0), Op1( 0), Op2( 2), is32,
-			NULL, reset_unknown, c6_IFAR },
+			access_vm_reg, reset_unknown, c6_IFAR },
 
 	/* PAR swapped by interrupt.S */
 	{ CRm64( 7), Op1( 0), is64, NULL, reset_unknown64, c7_PAR },
@@ -230,9 +254,9 @@ static const struct coproc_reg cp15_regs[] = {
 
 	/* PRRR/NMRR (aka MAIR0/MAIR1): swapped by interrupt.S. */
 	{ CRn(10), CRm( 2), Op1( 0), Op2( 0), is32,
-			NULL, reset_unknown, c10_PRRR},
+			access_vm_reg, reset_unknown, c10_PRRR},
 	{ CRn(10), CRm( 2), Op1( 0), Op2( 1), is32,
-			NULL, reset_unknown, c10_NMRR},
+			access_vm_reg, reset_unknown, c10_NMRR},
 
 	/* AMAIR0/AMAIR1: swapped by interrupt.S. */
 	{ CRn(10), CRm( 3), Op1( 0), Op2( 0), is32,
@@ -246,7 +270,7 @@ static const struct coproc_reg cp15_regs[] = {
 
 	/* CONTEXTIDR/TPIDRURW/TPIDRURO/TPIDRPRW: swapped by interrupt.S. */
 	{ CRn(13), CRm( 0), Op1( 0), Op2( 1), is32,
-			NULL, reset_val, c13_CID, 0x00000000 },
+			access_vm_reg, reset_val, c13_CID, 0x00000000 },
 	{ CRn(13), CRm( 0), Op1( 0), Op2( 2), is32,
 			NULL, reset_unknown, c13_TID_URW },
 	{ CRn(13), CRm( 0), Op1( 0), Op2( 3), is32,
diff --git a/arch/arm/kvm/coproc.h b/arch/arm/kvm/coproc.h
index 8dda870e84f9..1a44bbe39643 100644
--- a/arch/arm/kvm/coproc.h
+++ b/arch/arm/kvm/coproc.h
@@ -153,4 +153,8 @@ static inline int cmp_reg(const struct coproc_reg *i1,
 #define is64		.is_64 = true
 #define is32		.is_64 = false
 
+bool access_sctlr(struct kvm_vcpu *vcpu,
+		  const struct coproc_params *p,
+		  const struct coproc_reg *r);
+
 #endif /* __ARM_KVM_COPROC_LOCAL_H__ */
diff --git a/arch/arm/kvm/coproc_a15.c b/arch/arm/kvm/coproc_a15.c
index 935fa0fddb29..e6ec43ab5c41 100644
--- a/arch/arm/kvm/coproc_a15.c
+++ b/arch/arm/kvm/coproc_a15.c
@@ -130,7 +130,7 @@ static const struct coproc_reg a15_regs[] = {
 
 	/* SCTLR: swapped by interrupt.S. */
 	{ CRn( 1), CRm( 0), Op1( 0), Op2( 0), is32,
-			NULL, reset_val, c1_SCTLR, 0x00C50078 },
+			access_sctlr, reset_val, c1_SCTLR, 0x00C50078 },
 	/* ACTLR: trapped by HCR.TAC bit. */
 	{ CRn( 1), CRm( 0), Op1( 0), Op2( 1), is32,
 			access_actlr, reset_actlr, c1_ACTLR },
-- 
2.3.5


  parent reply	other threads:[~2015-04-30 12:21 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30 12:12 [PATCH 3.12 00/63] 3.12.42-stable review Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 01/63] KVM: ARM: Fix calculation of virtual CPU ID Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 02/63] KVM: ARM: fix the size of TTBCR_{T0SZ,T1SZ} masks Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 03/63] ARM: KVM: Yield CPU when vcpu executes a WFE Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 04/63] ARM: KVM: Fix MPIDR computing to support virtual clusters Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 05/63] KVM: ARM: Update comments for kvm_handle_wfi Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 06/63] ARM: KVM: fix L2CTLR to be per-cluster Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 07/63] arm/arm64: KVM: PSCI: use MPIDR to identify a target CPU Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 08/63] arm64: KVM: Yield CPU when vcpu executes a WFE Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 09/63] arm/arm64: KVM: arch_timer: Initialize cntvoff at kvm_init Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 10/63] ARM: KVM: Allow creating the VGIC after VCPUs Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 11/63] arm/arm64: kvm: Set vcpu->cpu to -1 on vcpu_put Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 12/63] arm64: KVM: Force undefined exception for Guest SMC intructions Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 13/63] arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 14/63] KVM: ARM: Remove duplicate include Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 15/63] arm: kvm: implement CPU PM notifier Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 16/63] arm/arm64: KVM: detect CPU reset on CPU_PM_EXIT Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 17/63] arm64: KVM: force cache clean on page fault when caches are off Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 18/63] arm64: KVM: allows discrimination of AArch32 sysreg access Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 19/63] arm64: KVM: trap VM system registers until MMU and caches are ON Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 20/63] ARM: KVM: introduce kvm_p*d_addr_end Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 21/63] arm64: KVM: flush VM pages before letting the guest enable caches Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 22/63] ARM: KVM: force cache clean on page fault when caches are off Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 23/63] ARM: KVM: fix handling of trapped 64bit coprocessor accesses Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 24/63] ARM: KVM: fix ordering of " Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 25/63] ARM: KVM: introduce per-vcpu HYP Configuration Register Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 26/63] ARM: KVM: add world-switch for AMAIR{0,1} Jiri Slaby
2015-04-30 12:11 ` Jiri Slaby [this message]
2015-04-30 12:11 ` [PATCH 3.12 28/63] ARM: KVM: fix non-VGIC compilation Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 29/63] ARM: KVM: disable KVM in Kconfig on big-endian systems Jiri Slaby
2015-04-30 12:11 ` [PATCH 3.12 30/63] KVM: arm/arm64: vgic: fix GICD_ICFGR register accesses Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 31/63] KVM: ARM: vgic: Fix the overlap check action about setting the GICD & GICC base address Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 32/63] arm64: kvm: use inner-shareable barriers for inner-shareable maintenance Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 33/63] kvm: arm64: vgic: fix hyp panic with 64k pages on juno platform Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 34/63] arm/arm64: KVM: Fix and refactor unmap_range Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 35/63] ARM: KVM: Unmap IPA on memslot delete/move Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 36/63] ARM: KVM: user_mem_abort: support stage 2 MMIO page mapping Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 37/63] arm64: KVM: export demux regids as KVM_REG_ARM64 Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 38/63] ARM: virt: fix wrong HSCTLR.EE bit setting Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 39/63] ARM64: KVM: store kvm_vcpu_fault_info est_el2 as word Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 40/63] KVM: ARM/arm64: fix non-const declaration of function returning const Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 41/63] KVM: ARM/arm64: fix broken __percpu annotation Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 42/63] KVM: ARM/arm64: avoid returning negative error code as bool Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 43/63] KVM: vgic: return int instead of bool when checking I/O ranges Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 44/63] ARM/ARM64: KVM: Nuke Hyp-mode tlbs before enabling MMU Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 45/63] arm/arm64: KVM: Complete WFI/WFE instructions Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 46/63] ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault() Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 47/63] KVM: ARM: vgic: plug irq injection race Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 48/63] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 49/63] arm: kvm: fix CPU hotplug Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 50/63] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 51/63] arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 52/63] arm64/kvm: Fix assembler compatibility of macros Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 53/63] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn() Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 54/63] arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 55/63] arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 56/63] arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 57/63] arm/arm64: KVM: Introduce stage2_unmap_vm Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 58/63] arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 59/63] arm/arm64: KVM: Require in-kernel vgic for the arch timers Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 60/63] arm64: KVM: Fix TLB invalidation by IPA/VMID Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 61/63] arm64: KVM: Fix HCR setting for 32bit guests Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 62/63] arm64: KVM: Do not use pgd_index to index stage-2 pgd Jiri Slaby
2015-04-30 12:12 ` [PATCH 3.12 63/63] arm/arm64: KVM: Keep elrsr/aisr in sync with software model Jiri Slaby
2015-04-30 13:12 ` [PATCH 3.12 00/63] 3.12.42-stable review Guenter Roeck
2015-05-04 13:27   ` Jiri Slaby
2015-04-30 14:26 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4247324050f4465cfb0a8feb7b5bee262a083245.1430387326.git.jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=shannon.zhao@linaro.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).