[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 03/12] target/arm/kvm32: make MPIDR consistent with CPU Topol
From: |
Ying Fang |
Subject: |
[RFC PATCH 03/12] target/arm/kvm32: make MPIDR consistent with CPU Topology |
Date: |
Thu, 17 Sep 2020 11:20:24 +0800 |
MPIDR helps to provide an additional PE identification in a multiprocessor
system. This patch adds support for setting MPIDR from userspace, so that
MPIDR is consistent with CPU topology configured.
Signed-off-by: Ying Fang <fangying1@huawei.com>
---
target/arm/kvm32.c | 46 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 38 insertions(+), 8 deletions(-)
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
index 0af46b41c8..85694dc8bf 100644
--- a/target/arm/kvm32.c
+++ b/target/arm/kvm32.c
@@ -201,11 +201,47 @@ int kvm_arm_cpreg_level(uint64_t regidx)
#define ARM_CPU_ID_MPIDR 0, 0, 0, 5
+static int kvm_arm_set_mp_affinity(CPUState *cs)
+{
+ uint32_t mpidr;
+ ARMCPU *cpu = ARM_CPU(cs);
+
+ if (kvm_check_extension(kvm_state, KVM_CAP_ARM_MP_AFFINITY)) {
+ /* Make MPIDR consistent with CPU topology */
+ MachineState *ms = MACHINE(qdev_get_machine());
+
+ mpidr = (kvm_arch_vcpu_id(cs) % ms->smp.threads) << ARM_AFF0_SHIFT;
+ mpidr |= ((kvm_arch_vcpu_id(cs) / ms->smp.threads % ms->smp.cores)
+ & 0xff) << ARM_AFF1_SHIFT;
+ mpidr |= (kvm_arch_vcpu_id(cs) / (ms->smp.cores * ms->smp.threads)
+ & 0xff) << ARM_AFF2_SHIFT;
+
+ /* Override mp affinity when KVM is in use */
+ cpu->mp_affinity = mpidr & ARM32_AFFINITY_MASK;
+
+ /* Bit 31 is RES1 indicates the ARMv7 Multiprocessing Extensions */
+ mpidr |= (1ULL << 31);
+ return kvm_vcpu_ioctl(cs, KVM_ARM_SET_MP_AFFINITY, &mpidr);
+ } else {
+ /*
+ * When KVM_CAP_ARM_MP_AFFINITY is not supported, it means KVM has its
+ * own idea about MPIDR assignment, so we override our defaults with
+ * what we get from KVM.
+ */
+ int ret = kvm_get_one_reg(cs, ARM_CP15_REG32(ARM_CPU_ID_MPIDR),
&mpidr);
+ if (ret) {
+ error_report("failed to set MPIDR");
+ return ret;
+ }
+ cpu->mp_affinity = mpidr & ARM32_AFFINITY_MASK;
+ return ret;
+ }
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
int ret;
uint64_t v;
- uint32_t mpidr;
struct kvm_one_reg r;
ARMCPU *cpu = ARM_CPU(cs);
@@ -244,16 +280,10 @@ int kvm_arch_init_vcpu(CPUState *cs)
return -EINVAL;
}
- /*
- * When KVM is in use, PSCI is emulated in-kernel and not by qemu.
- * Currently KVM has its own idea about MPIDR assignment, so we
- * override our defaults with what we get from KVM.
- */
- ret = kvm_get_one_reg(cs, ARM_CP15_REG32(ARM_CPU_ID_MPIDR), &mpidr);
+ ret = kvm_arm_set_mp_affinity(cs);
if (ret) {
return ret;
}
- cpu->mp_affinity = mpidr & ARM32_AFFINITY_MASK;
/* Check whether userspace can specify guest syndrome value */
kvm_arm_init_serror_injection(cs);
--
2.23.0
- Re: [RFC PATCH 09/12] target/arm/cpu: Add CPU cache description for arm, (continued)
[RFC PATCH 03/12] target/arm/kvm32: make MPIDR consistent with CPU Topology,
Ying Fang <=
[RFC PATCH 06/12] hw/arm/virt-acpi-build: distinguish possible and present cpus, Ying Fang, 2020/09/16
[RFC PATCH 12/12] hw/arm/virt-acpi-build: Enable CPU cache topology, Ying Fang, 2020/09/16
[RFC PATCH 08/12] hw/arm/virt-acpi-build: add PPTT table, Ying Fang, 2020/09/16
[RFC PATCH 11/12] hw/acpi/aml-build: build ACPI CPU cache topology information, Ying Fang, 2020/09/16
[RFC PATCH 10/12] hw/arm/virt: add fdt cache information, Ying Fang, 2020/09/16