[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 013/113] spapr: consolidate the VCPU id numbering lo
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 013/113] spapr: consolidate the VCPU id numbering logic in a single place |
Date: |
Mon, 18 Jun 2018 20:41:39 -0500 |
From: Greg Kurz <address@hidden>
Several places in the code need to calculate a VCPU id:
(cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads
(core_id / smp_threads) * spapr->vsmt (1 user)
index * spapr->vsmt (2 users)
or guess that the VCPU id of a given VCPU is the first thread of a virtual
core:
index % spapr->vsmt != 0
Even if the numbering logic isn't that complex, it is rather fragile to
have these assumptions open-coded in several places. FWIW this was
proved with recent issues related to VSMT.
This patch moves the VCPU id formula to a single function to be called
everywhere the code needs to compute one. It also adds an helper to
guess if a VCPU is the first thread of a VCORE.
Signed-off-by: Greg Kurz <address@hidden>
[dwg: Rename spapr_is_vcore() to spapr_is_thread0_in_vcore() for clarity]
Signed-off-by: David Gibson <address@hidden>
(cherry picked from commit 5d0fb1508e2d279da74ef4a103e8def9b52c6304)
Signed-off-by: Greg Kurz <address@hidden>
---
hw/ppc/spapr.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 0be60fb044..a36494b87b 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -100,6 +100,21 @@
#define PHANDLE_XICP 0x00001111
+/* These two functions implement the VCPU id numbering: one to compute them
+ * all and one to identify thread 0 of a VCORE. Any change to the first one
+ * is likely to have an impact on the second one, so let's keep them close.
+ */
+static int spapr_vcpu_id(sPAPRMachineState *spapr, int cpu_index)
+{
+ return
+ (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads;
+}
+static bool spapr_is_thread0_in_vcore(sPAPRMachineState *spapr,
+ PowerPCCPU *cpu)
+{
+ return spapr_get_vcpu_id(cpu) % spapr->vsmt == 0;
+}
+
static ICSState *spapr_ics_create(sPAPRMachineState *spapr,
const char *type_ics,
int nr_irqs, Error **errp)
@@ -346,7 +361,7 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPRMachineState
*spapr)
int index = spapr_get_vcpu_id(cpu);
int compat_smt = MIN(smp_threads, ppc_compat_max_vthreads(cpu));
- if (index % spapr->vsmt != 0) {
+ if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
continue;
}
@@ -630,7 +645,7 @@ static void spapr_populate_cpus_dt_node(void *fdt,
sPAPRMachineState *spapr)
DeviceClass *dc = DEVICE_GET_CLASS(cs);
int offset;
- if (index % spapr->vsmt != 0) {
+ if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
continue;
}
@@ -2230,7 +2245,7 @@ static void spapr_init_cpus(sPAPRMachineState *spapr)
if (mc->has_hotpluggable_cpus) {
spapr_dr_connector_new(OBJECT(spapr), TYPE_SPAPR_DRC_CPU,
- (core_id / smp_threads) * spapr->vsmt);
+ spapr_vcpu_id(spapr, core_id));
}
if (i < boot_cores_nr) {
@@ -3274,7 +3289,8 @@ void spapr_core_unplug_request(HotplugHandler
*hotplug_dev, DeviceState *dev,
return;
}
- drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, index * spapr->vsmt);
+ drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU,
+ spapr_vcpu_id(spapr, cc->core_id));
g_assert(drc);
spapr_drc_detach(drc);
@@ -3303,7 +3319,8 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev,
DeviceState *dev,
cc->core_id);
return;
}
- drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU, index * spapr->vsmt);
+ drc = spapr_drc_by_id(TYPE_SPAPR_DRC_CPU,
+ spapr_vcpu_id(spapr, cc->core_id));
g_assert(drc || !mc->has_hotpluggable_cpus);
@@ -3652,8 +3669,7 @@ void spapr_set_vcpu_id(PowerPCCPU *cpu, int cpu_index,
Error **errp)
sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
int vcpu_id;
- vcpu_id =
- (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads;
+ vcpu_id = spapr_vcpu_id(spapr, cpu_index);
if (kvm_enabled() && !kvm_vcpu_id_is_valid(vcpu_id)) {
error_setg(errp, "Can't create CPU with id %d in KVM", vcpu_id);
--
2.11.0
- [Qemu-devel] [PATCH 107/113] i386: Define the Virt SSBD MSR and handling of it (CVE-2018-3639), (continued)
- [Qemu-devel] [PATCH 107/113] i386: Define the Virt SSBD MSR and handling of it (CVE-2018-3639), Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 108/113] i386: define the AMD 'virt-ssbd' CPUID feature bit (CVE-2018-3639), Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 109/113] tap: set vhostfd passed from qemu cli to non-blocking, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 110/113] vhost-user: delete net client if necessary, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 010/113] spapr: move VCPU calculation to core machine code, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 111/113] qemu-img: Fix assert when mapping unaligned raw file, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 112/113] iotests: Add test 221 to catch qemu-img map regression, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 113/113] arm_gicv3_kvm: kvm_dist_get/put_priority: skip the registers banked by GICR_IPRIORITYR, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 011/113] target/ppc: Clarify compat mode max_threads value, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 012/113] spapr: rename spapr_vcpu_id() to spapr_get_vcpu_id(), Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 013/113] spapr: consolidate the VCPU id numbering logic in a single place,
Michael Roth <=
- [Qemu-devel] [PATCH 014/113] spapr: fix missing CPU core nodes in DT when running with TCG, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 015/113] spapr: register dummy ICPs later, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 016/113] spapr: make pseries-2.11 the default machine type, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 017/113] nbd: Honor server's advertised minimum block size, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 018/113] specs/qcow2: Fix documentation of the compressed cluster descriptor, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 020/113] tpm: Set the flags of the CMD_INIT command to 0, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 019/113] rbd: Fix use after free in qemu_rbd_set_keypairs() error path, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 001/113] block/ssh: fix possible segmentation fault when .desc is not null-terminated, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 021/113] loader: don't perform overlapping address check for memory region ROM images, Michael Roth, 2018/06/18
- [Qemu-devel] [PATCH 022/113] target/xtensa: dump correct physical registers, Michael Roth, 2018/06/18