From: David Brazdil <dbrazdil@google.com>
To: kvmarm@lists.cs.columbia.edu
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Marc Zyngier <maz@kernel.org>,
James Morse <james.morse@arm.com>,
Julien Thierry <julien.thierry.kdev@gmail.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Dennis Zhou <dennis@kernel.org>,
Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
Mark Rutland <mark.rutland@arm.com>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Quentin Perret <qperret@google.com>,
Andrew Scull <ascull@google.com>,
kernel-team@android.com, David Brazdil <dbrazdil@google.com>
Subject: [RFC PATCH 07/26] kvm: arm64: Support per_cpu_ptr in nVHE hyp code
Date: Wed, 4 Nov 2020 18:36:11 +0000 [thread overview]
Message-ID: <20201104183630.27513-8-dbrazdil@google.com> (raw)
In-Reply-To: <20201104183630.27513-1-dbrazdil@google.com>
When compiling with __KVM_NVHE_HYPERVISOR__ redefine per_cpu_offset() to
__hyp_per_cpu_offset() which looks up the base of the nVHE per-CPU
region of the given cpu and computes its offset from the
.hyp.data..percpu section.
This enables use of per_cpu_ptr() helpers in nVHE hyp code. Until now
only this_cpu_ptr() was supported by setting TPIDR_EL2.
Signed-off-by: David Brazdil <dbrazdil@google.com>
---
arch/arm64/include/asm/percpu.h | 6 ++++++
arch/arm64/kernel/image-vars.h | 3 +++
arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++-
arch/arm64/kvm/hyp/nvhe/percpu.c | 22 ++++++++++++++++++++++
4 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 arch/arm64/kvm/hyp/nvhe/percpu.c
diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percpu.h
index 1599e17379d8..8f1661603b78 100644
--- a/arch/arm64/include/asm/percpu.h
+++ b/arch/arm64/include/asm/percpu.h
@@ -239,6 +239,12 @@ PERCPU_RET_OP(add, add, ldadd)
#define this_cpu_cmpxchg_8(pcp, o, n) \
_pcp_protect_return(cmpxchg_relaxed, pcp, o, n)
+#ifdef __KVM_NVHE_HYPERVISOR__
+extern unsigned long __hyp_per_cpu_offset(unsigned int cpu);
+#define __per_cpu_offset
+#define per_cpu_offset(cpu) __hyp_per_cpu_offset((cpu))
+#endif
+
#include <asm-generic/percpu.h>
/* Redefine macros for nVHE hyp under DEBUG_PREEMPT to avoid its dependencies. */
diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
index c615b285ff5b..78a42a7cdb72 100644
--- a/arch/arm64/kernel/image-vars.h
+++ b/arch/arm64/kernel/image-vars.h
@@ -103,6 +103,9 @@ KVM_NVHE_ALIAS(gic_nonsecure_priorities);
KVM_NVHE_ALIAS(__start___kvm_ex_table);
KVM_NVHE_ALIAS(__stop___kvm_ex_table);
+/* Array containing bases of nVHE per-CPU memory regions. */
+KVM_NVHE_ALIAS(kvm_arm_hyp_percpu_base);
+
#endif /* CONFIG_KVM */
#endif /* __ARM64_KERNEL_IMAGE_VARS_H */
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
index ddde15fe85f2..c45f440cce51 100644
--- a/arch/arm64/kvm/hyp/nvhe/Makefile
+++ b/arch/arm64/kvm/hyp/nvhe/Makefile
@@ -6,7 +6,8 @@
asflags-y := -D__KVM_NVHE_HYPERVISOR__
ccflags-y := -D__KVM_NVHE_HYPERVISOR__
-obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o
+obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
+ hyp-main.o percpu.o
obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
../fpsimd.o ../hyp-entry.o
diff --git a/arch/arm64/kvm/hyp/nvhe/percpu.c b/arch/arm64/kvm/hyp/nvhe/percpu.c
new file mode 100644
index 000000000000..5fd0c5696907
--- /dev/null
+++ b/arch/arm64/kvm/hyp/nvhe/percpu.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2020 - Google LLC
+ * Author: David Brazdil <dbrazdil@google.com>
+ */
+
+#include <asm/kvm_asm.h>
+#include <asm/kvm_hyp.h>
+#include <asm/kvm_mmu.h>
+
+unsigned long __hyp_per_cpu_offset(unsigned int cpu)
+{
+ unsigned long *cpu_base_array;
+ unsigned long this_cpu_base;
+
+ if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base))
+ hyp_panic();
+
+ cpu_base_array = kern_hyp_va(&kvm_arm_hyp_percpu_base[0]);
+ this_cpu_base = kern_hyp_va(cpu_base_array[cpu]);
+ return this_cpu_base - (unsigned long)&__per_cpu_start;
+}
--
2.29.1.341.ge80a0c044ae-goog
next prev parent reply other threads:[~2020-11-04 18:37 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 ` David Brazdil [this message]
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 ` [RFC PATCH 25/26] kvm: arm64: Trap host SMCs David Brazdil
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-8-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).