linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: David Brazdil <dbrazdil@google.com>
To: kvmarm@lists.cs.columbia.edu
Cc: Mark Rutland <mark.rutland@arm.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	kernel-team@android.com,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Marc Zyngier <maz@kernel.org>,
	Quentin Perret <qperret@google.com>,
	linux-kernel@vger.kernel.org, James Morse <james.morse@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	Catalin Marinas <catalin.marinas@arm.com>,
	Tejun Heo <tj@kernel.org>, Dennis Zhou <dennis@kernel.org>,
	Christoph Lameter <cl@linux.com>,
	David Brazdil <dbrazdil@google.com>,
	Will Deacon <will@kernel.org>,
	Julien Thierry <julien.thierry.kdev@gmail.com>,
	Andrew Scull <ascull@google.com>
Subject: [RFC PATCH 25/26] kvm: arm64: Trap host SMCs
Date: Wed,  4 Nov 2020 18:36:29 +0000	[thread overview]
Message-ID: <20201104183630.27513-26-dbrazdil@google.com> (raw)
In-Reply-To: <20201104183630.27513-1-dbrazdil@google.com>

While nVHE KVM is installed, start trapping all host SMCs. By default,
these are simply forwarded to EL3, but PSCI SMCs are validated first.

Create new constant HCR_HOST_NVHE_STUB_FLAGS with the old set of HCR
flags to use before the nVHE vector is installed or when switching back
to stub vector.

Extend HCR_HOST_NVHE_FLAGS to contain HCR_TSC. Set HCR_EL2 to it before
installing nVHE vector.

Signed-off-by: David Brazdil <dbrazdil@google.com>
---
 arch/arm64/include/asm/kvm_arm.h   | 3 ++-
 arch/arm64/kernel/head.S           | 2 +-
 arch/arm64/kvm/hyp/nvhe/hyp-init.S | 6 ++++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 64ce29378467..04b862955f32 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -79,7 +79,8 @@
 			 HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \
 			 HCR_FMO | HCR_IMO | HCR_PTW )
 #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF)
-#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA)
+#define HCR_HOST_NVHE_STUB_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA)
+#define HCR_HOST_NVHE_FLAGS (HCR_HOST_NVHE_STUB_FLAGS | HCR_TSC)
 #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H)
 
 /* TCR_EL2 Registers bits */
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index e7270b63abed..ea17413a04e0 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -522,7 +522,7 @@ SYM_FUNC_START(el2_setup)
 #endif
 
 SYM_INNER_LABEL(el2_setup_nvhe, SYM_L_LOCAL)
-	mov_q	x0, HCR_HOST_NVHE_FLAGS
+	mov_q	x0, HCR_HOST_NVHE_STUB_FLAGS
 	msr	hcr_el2, x0
 	isb
 
diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
index dd297a1a8f82..97684deba6c1 100644
--- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S
+++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S
@@ -88,6 +88,10 @@ SYM_CODE_END(__kvm_hyp_init)
  * x0: struct kvm_nvhe_init_params PA
  */
 SYM_CODE_START(___kvm_hyp_init)
+	mov_q	x1, HCR_HOST_NVHE_FLAGS
+	msr	hcr_el2, x1
+	isb
+
 	ldr	x1, [x0, #NVHE_INIT_TPIDR_EL2]
 	msr	tpidr_el2, x1
 
@@ -220,6 +224,8 @@ reset:
 	bic	x5, x5, x6		// Clear SCTL_M and etc
 	pre_disable_mmu_workaround
 	msr	sctlr_el2, x5
+	mov_q	x5, HCR_HOST_NVHE_STUB_FLAGS
+	msr	hcr_el2, x5
 	isb
 
 	/* Install stub vectors */
-- 
2.29.1.341.ge80a0c044ae-goog


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-11-04 18:43 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04 18:36 [RFC PATCH 00/26] kvm: arm64: Always-on nVHE hypervisor David Brazdil
2020-11-04 18:36 ` [RFC PATCH 01/26] psci: Export configured PSCI version David Brazdil
2020-11-05  9:47   ` Marc Zyngier
2020-11-04 18:36 ` [RFC PATCH 02/26] psci: Export configured PSCI function IDs David Brazdil
2020-11-05  9:53   ` Marc Zyngier
2020-11-04 18:36 ` [RFC PATCH 03/26] psci: Export psci_cpu_suspend_feature David Brazdil
2020-11-04 18:36 ` [RFC PATCH 04/26] arm64: Move MAIR_EL1_SET to asm/memory.h David Brazdil
2020-11-04 18:36 ` [RFC PATCH 05/26] kvm: arm64: Initialize MAIR_EL2 using a constant David Brazdil
2020-11-04 18:36 ` [RFC PATCH 06/26] kvm: arm64: Add .hyp.data ELF section David Brazdil
2020-11-04 18:36 ` [RFC PATCH 07/26] kvm: arm64: Support per_cpu_ptr in nVHE hyp code David Brazdil
2020-11-04 18:36 ` [RFC PATCH 08/26] kvm: arm64: Create nVHE copy of cpu_logical_map David Brazdil
2020-11-04 18:36 ` [RFC PATCH 09/26] kvm: arm64: Move hyp-init params to a per-CPU struct David Brazdil
2020-11-04 18:36 ` [RFC PATCH 10/26] kvm: arm64: Refactor handle_trap to use a switch David Brazdil
2020-11-04 18:36 ` [RFC PATCH 11/26] kvm: arm64: Extract parts of el2_setup into a macro David Brazdil
2020-11-04 18:36 ` [RFC PATCH 12/26] kvm: arm64: Add SMC handler in nVHE EL2 David Brazdil
2020-11-05 11:08   ` Marc Zyngier
2020-11-04 18:36 ` [RFC PATCH 13/26] kvm: arm64: Bootstrap PSCI " David Brazdil
2020-11-04 18:36 ` [RFC PATCH 14/26] kvm: arm64: Forward safe PSCI SMCs coming from host David Brazdil
2020-11-04 18:36 ` [RFC PATCH 15/26] arm64: kvm: Add standalone ticket spinlock implementation for use at hyp David Brazdil
2020-11-04 18:36 ` [RFC PATCH 16/26] kvm: arm64: Add offset for hyp VA <-> PA conversion David Brazdil
2020-11-04 18:36 ` [RFC PATCH 17/26] kvm: arm64: Bootstrap PSCI power state of host CPUs David Brazdil
2020-11-04 18:36 ` [RFC PATCH 18/26] kvm: arm64: Intercept PSCI_CPU_OFF host SMC calls David Brazdil
2020-11-05 11:30   ` Marc Zyngier
2020-11-05 11:42     ` David Brazdil
2020-11-04 18:36 ` [RFC PATCH 19/26] kvm: arm64: Extract __do_hyp_init into a helper function David Brazdil
2020-11-04 18:36 ` [RFC PATCH 20/26] kvm: arm64: Add CPU entry point in nVHE hyp David Brazdil
2020-11-04 18:36 ` [RFC PATCH 21/26] kvm: arm64: Add function to enter host from KVM nVHE hyp code David Brazdil
2020-11-04 18:36 ` [RFC PATCH 22/26] kvm: arm64: Intercept PSCI_CPU_ON host SMC calls David Brazdil
2020-11-04 18:36 ` [RFC PATCH 23/26] kvm: arm64: Intercept host's CPU_SUSPEND PSCI SMCs David Brazdil
2020-11-05 10:34   ` Andrew Walbran
2020-11-05 11:04     ` David Brazdil
2020-11-04 18:36 ` [RFC PATCH 24/26] kvm: arm64: Keep nVHE EL2 vector installed David Brazdil
2020-11-04 18:36 ` David Brazdil [this message]
2020-11-04 18:36 ` [RFC PATCH 26/26] kvm: arm64: Fix EL2 mode availability checks David Brazdil
2020-11-06 12:25 ` [RFC PATCH 00/26] kvm: arm64: Always-on nVHE hypervisor Marc Zyngier

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=20201104183630.27513-26-dbrazdil@google.com \
    --to=dbrazdil@google.com \
    --cc=ascull@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@linux.com \
    --cc=dennis@kernel.org \
    --cc=james.morse@arm.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kernel-team@android.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=qperret@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tj@kernel.org \
    --cc=will@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).