From: Haibo Xu <haibo.xu@linaro.org>
To: drjones@redhat.com, richard.henderson@linaro.org
Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, philmd@redhat.com,
qemu-devel@nongnu.org, Haibo Xu <haibo.xu@linaro.org>
Subject: [PATCH v2 03/12] target/arm/cpu: spe: Add an option to turn on/off vSPE support
Date: Tue, 8 Sep 2020 08:13:21 +0000 [thread overview]
Message-ID: <77b57f43d4fa6319cfa666d6c77e39ec76c44d88.1599549462.git.haibo.xu@linaro.org> (raw)
In-Reply-To: <cover.1599549462.git.haibo.xu@linaro.org>
Adds a spe=[on/off] option to enable/disable vSPE support in
guest vCPU.
Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
---
target/arm/cpu.c | 6 ++++++
target/arm/cpu.h | 13 ++++++++++++
target/arm/cpu64.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index c179e0752d..f211958eaa 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1310,6 +1310,12 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)
error_propagate(errp, local_err);
return;
}
+
+ arm_cpu_spe_finalize(cpu, &local_err);
+ if (local_err != NULL) {
+ error_propagate(errp, local_err);
+ return;
+ }
}
}
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index a1c7d8ebae..baf2bbcee8 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -24,6 +24,7 @@
#include "hw/registerfields.h"
#include "cpu-qom.h"
#include "exec/cpu-defs.h"
+#include "qapi/qapi-types-common.h"
/* ARM processors have a weak memory model */
#define TCG_GUEST_DEFAULT_MO (0)
@@ -196,9 +197,11 @@ typedef struct {
#ifdef TARGET_AARCH64
# define ARM_MAX_VQ 16
void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp);
+void arm_cpu_spe_finalize(ARMCPU *cpu, Error **errp);
#else
# define ARM_MAX_VQ 1
static inline void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp) { }
+static inline void arm_cpu_spe_finalize(ARMCPU *cpu, Error **errp) { }
#endif
typedef struct ARMVectorReg {
@@ -829,6 +832,8 @@ struct ARMCPU {
bool has_el3;
/* CPU has PMU (Performance Monitor Unit) */
bool has_pmu;
+ /* CPU has SPE (Statistical Profiling Extension) */
+ OnOffAuto has_spe;
/* CPU has VFP */
bool has_vfp;
/* CPU has Neon */
@@ -3869,6 +3874,14 @@ static inline bool isar_feature_aa64_pmu_8_4(const ARMISARegisters *id)
FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
}
+/*
+ * Currently we don't differentiate between the ARMv8.2-SPE and ARMv8.3-SPE.
+ */
+static inline bool isar_feature_aa64_spe(const ARMISARegisters *id)
+{
+ return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMSVER) != 0;
+}
+
static inline bool isar_feature_aa64_rcpc_8_3(const ARMISARegisters *id)
{
return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) != 0;
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 3c2b3d9599..4997c4a3c0 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -572,6 +572,55 @@ void aarch64_add_sve_properties(Object *obj)
}
}
+void arm_cpu_spe_finalize(ARMCPU *cpu, Error **errp)
+{
+ uint64_t t;
+ uint32_t value = 0;
+
+ if (cpu->has_spe == ON_OFF_AUTO_AUTO) {
+ if (kvm_enabled() && kvm_arm_spe_supported()) {
+ cpu->has_spe = ON_OFF_AUTO_ON;
+ } else {
+ cpu->has_spe = ON_OFF_AUTO_OFF;
+ }
+ } else if (cpu->has_spe == ON_OFF_AUTO_ON) {
+ if (!kvm_enabled() || !kvm_arm_spe_supported()) {
+ error_setg(errp, "'spe' cannot be enabled on this host");
+ return;
+ }
+ }
+
+ /*
+ * According to the ARM ARM, the ID_AA64DFR0[PMSVER] currently
+ * support 3 values:
+ *
+ * 0b0000: SPE not implemented
+ * 0b0001: ARMv8.2-SPE implemented
+ * 0b0010: ARMv8.3-SPE implemented
+ *
+ * But the kernel KVM API didn't expose all these 3 values, and
+ * we can only get whether the SPE feature is supported or not.
+ * So here we just set the PMSVER to 1 if this feature was supported.
+ */
+ if (cpu->has_spe == ON_OFF_AUTO_ON) {
+ value = 1;
+ }
+
+ t = cpu->isar.id_aa64dfr0;
+ t = FIELD_DP64(t, ID_AA64DFR0, PMSVER, value);
+ cpu->isar.id_aa64dfr0 = t;
+}
+
+static bool arm_spe_get(Object *obj, Error **errp)
+{
+ return ARM_CPU(obj)->has_spe != ON_OFF_AUTO_OFF;
+}
+
+static void arm_spe_set(Object *obj, bool value, Error **errp)
+{
+ ARM_CPU(obj)->has_spe = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
+}
+
/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
* otherwise, a CPU with as many features enabled as our emulation supports.
* The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
@@ -721,6 +770,9 @@ static void aarch64_max_initfn(Object *obj)
aarch64_add_sve_properties(obj);
object_property_add(obj, "sve-max-vq", "uint32", cpu_max_get_sve_max_vq,
cpu_max_set_sve_max_vq, NULL, NULL);
+
+ cpu->has_spe = ON_OFF_AUTO_AUTO;
+ object_property_add_bool(obj, "spe", arm_spe_get, arm_spe_set);
}
static const ARMCPUInfo aarch64_cpus[] = {
--
2.17.1
next prev parent reply other threads:[~2020-09-08 8:16 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-08 8:13 [PATCH v2 00/12] target/arm: Add vSPE support to KVM guest Haibo Xu
2020-09-08 8:13 ` [PATCH v2 01/12] update Linux headers with new vSPE macros Haibo Xu
2020-09-08 8:13 ` [PATCH v2 02/12] target/arm/kvm: spe: Add helper to detect SPE when using KVM Haibo Xu
2020-09-08 10:43 ` Andrew Jones
2020-09-08 8:13 ` Haibo Xu [this message]
2020-09-08 10:51 ` [PATCH v2 03/12] target/arm/cpu: spe: Add an option to turn on/off vSPE support Andrew Jones
2020-09-08 8:13 ` [PATCH v2 04/12] target/arm: spe: Only enable SPE from 5.2 compat machines Haibo Xu
2020-09-08 10:52 ` Andrew Jones
2020-09-08 8:13 ` [PATCH v2 05/12] target/arm/kvm: spe: Unify device attr operation helper Haibo Xu
2020-09-08 10:56 ` Andrew Jones
2020-09-09 2:39 ` Haibo Xu
2020-09-08 8:13 ` [PATCH v2 06/12] target/arm/kvm: spe: Add device init and set_irq operations Haibo Xu
2020-09-08 10:58 ` Andrew Jones
2020-09-08 8:13 ` [PATCH v2 07/12] hw/arm/virt: Move post cpu realize check into its own function Haibo Xu
2020-09-08 11:03 ` Andrew Jones
2020-09-09 6:54 ` Haibo Xu
2020-09-08 8:13 ` [PATCH v2 08/12] hw/arm/virt: Move kvm pmu setup to virt_cpu_post_init Haibo Xu
2020-09-08 11:07 ` Andrew Jones
2020-09-08 8:13 ` [PATCH v2 09/12] hw/arm/virt: spe: Add SPE fdt binding for virt machine Haibo Xu
2020-09-08 11:16 ` Andrew Jones
2020-09-09 7:51 ` Haibo Xu
2020-09-09 9:34 ` Andrew Jones
2020-09-10 0:31 ` Haibo Xu
2020-09-08 8:13 ` [PATCH v2 10/12] target/arm/cpu: spe: Enable spe to work with host cpu Haibo Xu
2020-09-08 11:32 ` Andrew Jones
2020-09-09 8:35 ` Haibo Xu
2020-09-08 8:13 ` [PATCH v2 11/12] target/arm/kvm: spe: Enable userspace irqchip support Haibo Xu
2020-09-08 11:34 ` Andrew Jones
2020-09-09 3:12 ` Haibo Xu
2020-09-08 8:13 ` [PATCH v2 12/12] target/arm: spe: Add corresponding doc and test Haibo Xu
2020-09-08 11:41 ` Andrew Jones
2020-09-09 3:19 ` Haibo Xu
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=77b57f43d4fa6319cfa666d6c77e39ec76c44d88.1599549462.git.haibo.xu@linaro.org \
--to=haibo.xu@linaro.org \
--cc=drjones@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).