qemu/hw
Greg Kurz 72194664c8 spapr: use spapr->vsmt to compute VCPU ids
Since the introduction of VSMT in 2.11, the spacing of VCPU ids
between cores is controllable through a machine property instead
of being only dictated by the SMT mode of the host:

    cpu->vcpu_id = (cc->core_id * spapr->vsmt / smp_threads) + i

Until recently, the machine code would try to change the SMT mode
of the host to be equal to VSMT or exit. This allowed the rest of
the code to assume that kvmppc_smt_threads() == spapr->vsmt is
always true.

Recent commit "8904e5a75005 spapr: Adjust default VSMT value for
better migration compatibility" relaxed the rule. If the VSMT
mode cannot be set in KVM for some reasons, but the requested
CPU topology is compatible with the current SMT mode, then we
let the guest run with  kvmppc_smt_threads() != spapr->vsmt.

This breaks quite a few places in the code, in particular when
calculating DRC indexes.

This is what happens on a POWER host with subcores-per-core=2 (ie,
supports up to SMT4) when passing the following topology:

    -smp threads=4,maxcpus=16 \
    -device host-spapr-cpu-core,core-id=4,id=core1 \
    -device host-spapr-cpu-core,core-id=8,id=core2

qemu-system-ppc64: warning: Failed to set KVM's VSMT mode to 8 (errno -22)

This is expected since KVM is limited to SMT4, but the guest is started
anyway because this topology can run on SMT4 even with a VSMT8 spacing.

But when we look at the DT, things get nastier:

cpus {
        ...
        ibm,drc-indexes = <0x4 0x10000000 0x10000004 0x10000008 0x1000000c>;

This means that we have the following association:

 CPU core device |     DRC    | VCPU id
-----------------+------------+---------
   boot core     | 0x10000000 | 0
   core1         | 0x10000004 | 4
   core2         | 0x10000008 | 8
   core3         | 0x1000000c | 12

But since the spacing of VCPU ids is 8, the DRC for core1 points to a
VCPU that doesn't exist, the DRC for core2 points to the first VCPU of
core1 and and so on...

        ...

        PowerPC,POWER8@0 {
                ...
                ibm,my-drc-index = <0x10000000>;
                ...
        };

        PowerPC,POWER8@8 {
                ...
                ibm,my-drc-index = <0x10000008>;
                ...
        };

        PowerPC,POWER8@10 {
                ...

No ibm,my-drc-index property for this core since 0x10000010 doesn't
exist in ibm,drc-indexes above.

                ...
        };
};

...

interrupt-controller {
        ...
        ibm,interrupt-server-ranges = <0x0 0x10>;

With a spacing of 8, the highest VCPU id for the given topology should be:
        16 * 8 / 4 = 32 and not 16

        ...
        linux,phandle = <0x7e7323b8>;
        interrupt-controller;
};

And CPU hot-plug/unplug is broken:

(qemu) device_del core1
pseries-hotplug-cpu: Cannot find CPU (drc index 10000004) to remove

(qemu) device_del core2
cpu 4 (hwid 8) Ready to die...
cpu 5 (hwid 9) Ready to die...
cpu 6 (hwid 10) Ready to die...
cpu 7 (hwid 11) Ready to die...

These are the VCPU ids of core1 actually

(qemu) device_add host-spapr-cpu-core,core-id=12,id=core3
(qemu) device_del core3
pseries-hotplug-cpu: Cannot find CPU (drc index 1000000c) to remove

This patches all the code in hw/ppc/spapr.c to assume the VSMT
spacing when manipulating VCPU ids.

Fixes: 8904e5a750
Signed-off-by: Greg Kurz <groug@kaod.org>

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-02-16 12:14:26 +11:00
..
9pfs Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
acpi Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
adc Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
alpha Merge remote-tracking branch 'origin/master' into HEAD 2018-01-11 22:03:50 +02:00
arm raspi: Raspberry Pi 3 support 2018-02-15 18:33:46 +00:00
audio hw/audio/sb16.c: change dolog() to qemu_log_mask() 2018-02-02 08:19:47 +01:00
block virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
bt hw/bt: Replace fprintf(stderr, "*\n" with error_report() 2018-01-22 09:51:00 +01:00
char hw/char: remove legacy interface escc_init() 2018-02-16 12:14:26 +11:00
core machine: Polish -machine xxx,help 2018-02-10 10:06:20 +03:00
cpu hw: use "qemu/osdep.h" as first #include in source files 2017-12-18 17:07:02 +03:00
cris
display memory: hide memory_region_sync_dirty_bitmap behind DirtyBitmapSnapshot 2018-02-13 16:15:09 +01:00
dma hw/dma: Replace fprintf(stderr, "*\n" with error_report() 2018-02-06 18:29:09 +01:00
gpio Replace all occurances of __FUNCTION__ with __func__ 2018-01-22 09:46:18 +01:00
hppa hw/hppa: Use qemu_log_mask instead of fprintf to stderr 2018-02-04 14:11:03 -08:00
i2c Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
i386 Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
ide Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
input qdev: use device_class_set_parent_realize/unrealize/reset() 2018-02-05 13:54:38 +01:00
intc hw/intc/armv7m_nvic: Fix byte-to-interrupt number conversions 2018-02-15 18:29:49 +00:00
ipack
ipmi Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
isa lpc: drop pcie host dependency 2018-02-13 18:25:48 +02:00
lm32 hw/lm32: Replace fprintf(stderr, "*\n" with error_report() 2018-02-06 18:29:26 +01:00
m68k
mem nvdimm: add 'unarmed' option 2018-01-19 11:18:51 -02:00
microblaze xlnx-zynqmp-pmu: Connect the IPI device to the PMU 2018-01-26 11:09:09 +01:00
mips Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
misc cuda: convert to trace-events 2018-02-16 12:14:26 +11:00
moxie hw/moxie: Replace fprintf(stderr, "*\n" with error_report() 2018-02-06 18:29:26 +01:00
net * CAN bus (will be under network maintainner) 2018-02-13 18:24:08 +00:00
nios2 Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
nvram Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
openrisc hw/openrisc: Replace fprintf(stderr, "*\n" with error_report() 2018-02-06 18:29:26 +01:00
pci virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
pci-bridge virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
pci-host virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
pcmcia
ppc spapr: use spapr->vsmt to compute VCPU ids 2018-02-16 12:14:26 +11:00
s390x Miscellaneous patches for 2018-02-07 2018-02-09 14:39:09 +00:00
scsi virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
sd sdhci: add Spec v4.2 register definitions 2018-02-13 16:15:09 +01:00
sh4
smbios Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
sparc hw/char: remove legacy interface escc_init() 2018-02-16 12:14:26 +11:00
sparc64 Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
ssi Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
timer Miscellaneous patches for 2018-02-07 2018-02-09 14:39:09 +00:00
tpm Clean up includes 2018-02-09 05:05:11 +01:00
tricore
unicore32 hw/unicore32: restrict hw addr defines to source file 2017-12-18 17:07:02 +03:00
usb virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
vfio virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
virtio virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
watchdog Eliminate qapi/qmp/types.h 2018-02-09 13:52:15 +01:00
xen virtio,vhost,pci,pc: features, fixes and cleanups 2018-02-13 16:33:31 +00:00
xenpv hw/xen*: Replace fprintf(stderr, "*\n" with error_report() 2018-02-06 18:29:46 +01:00
xtensa Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
Makefile.objs hw/net/can: SJA1000 chip register level emulation for QEMU 2018-02-13 11:44:13 +01:00