Skip to contentSkip to conversation

ACPI CPU hotplug refactoring to support unplug and more than 255 CPUs

PATCH In review Igor Mammedov 3 participants 24 messages Jun 16, 2016 – Jun 27, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover ACPI CPU hotplug refactoring to support unplug and more than 255 CPUs

Changelog:
v1->v2:
- dropped consolidate legacy ACPI CPU hotplug as they are in master by now
- pc: start with legacy hotplug and let 2.7 machine type and older to switch inot new hotplug mode. That way legacy BIOS will still work fine as it uses built in ACPI tables and will continue to use legacy CPU hotplug interface.
- poll for CPU objects with events (insert/remove) instead of looping over all CPUs to find CPUs with events.
- drop dynamic PXM support as it could be implemented in static way at acpi tabels build time. It will be an additional series on top of this.
- resplit patches on basic present CPU support, hot-add and hot-remove parts Patches:
1-7: add new CPU hotplug impl.
8: makes 2.7 machine type to use new AML code that
will switch piix4/ich9 into new mode +
switching logic with migration glue for piix4/ich9
9: drops the last dependency in ACPI parts on apic_id_limit
sized map.
RFC->v1:
- drop machine.cpu-hotplug property and leave CPU hotplug always enabled as it used to be.
(it also simplifies, series a bit)
- reshuffle/squash some patches to make series bisectable
wrt 'make check' failures
- add doc comment in qapi schema
- fix 'make check' error for mips target, disableCPU hotplug code path in piix4_pm for mips
- drop some intermediate expected ACPI tables updates
- replace _MAT method with named buffer object

Current ACPI interface for CPU hotplug supports hoti-adding only upto 255 CPUs and lacks means to convey additional information needed _OST methods support.
Also being bitmap based with bit position specifying APIC ID it doesn't scale up well for 32-bit APIC IDs that will come with x2APIC support.

So add another QEMU-guest interface using as model memory-hotplug. New interface will be used since 2.7 machine types and will support:
- more than 255 CPUs with 32-bit APIC ID value
- a registers set to communicate OST information (extendable without breaking IO layout)
- possible to reuse for ARM's 'virt' machine type with minimal tweaks (add init for MMIO, add
ACPI hooks on CPU hotplug path, MADT generation)

Tested with following guests: RHEL7, WS2003EEx64, WS2012R2x64
* unplug is tested only with RHEL7 as Windows doesn't support it.
* tested that migration works as well.

git tree for testing:
[email protected]:imammedo/qemu.git modern_cpu_hotplug_v2
viewing:
https://github.com/imammedo/qemu/commits/modern_cpu_hotplug_v2

Igor Mammedov (10):
docs: update ACPI CPU hotplug spec with new protocol
pc: piix4/ich9: add 'cpu-hotplug-legacy' property
acpi: cpuhp: add CPU devices AML with _STA method
pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
acpi: cpuhp: implement hot-add parts of CPU hotplug interface
acpi: cpuhp: implement hot-remove parts of CPU hotplug interface
acpi: cpuhp: add cpu._OST handling
pc: use new CPU hotplug interface since 2.7 machine type
tests: acpi: add CPU hotplug testcase
pc: acpi: drop intermediate PCMachineState.node_cpu

 docs/specs/acpi_cpu_hotplug.txt      |  94 +++++-
 hw/acpi/Makefile.objs                |   1 +
 hw/acpi/cpu.c                        | 561 +++++++++++++++++++++++++++++++++++
 hw/acpi/cpu_hotplug.c                |  21 +-
 hw/acpi/ich9.c                       |  69 ++++-
 hw/acpi/piix4.c                      |  71 ++++-
 hw/i386/acpi-build.c                 |  68 +++--
 hw/i386/pc.c                         |  63 +++-
 hw/i386/pc_piix.c                    |   2 +
 hw/i386/pc_q35.c                     |   2 +
 hw/isa/lpc_ich9.c                    |   1 +
 include/hw/acpi/acpi_dev_interface.h |   7 +
 include/hw/acpi/cpu.h                |  67 +++++
 include/hw/acpi/cpu_hotplug.h        |   6 +
 include/hw/acpi/ich9.h               |   3 +
 include/hw/i386/pc.h                 |   8 +-
 qapi-schema.json                     |   3 +-
 stubs/Makefile.objs                  |   1 +
 stubs/pc_madt_cpu_entry.c            |   7 +
 tests/bios-tables-test.c             |  28 ++
 trace-events                         |  14 +
 21 files changed, 1043 insertions(+), 54 deletions(-)
 create mode 100644 hw/acpi/cpu.c
 create mode 100644 include/hw/acpi/cpu.h
 create mode 100644 stubs/pc_madt_cpu_entry.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/10 docs: update ACPI CPU hotplug spec with new protocol

Add description of new CPU hotplug interface.

To switch from from legacy mode into new mode use fact that write accesses into CPU present bitmap were never used before and were ignored by QEMU.
So use it to as a way to switch from legacy mode. That way pc/q35 machine starts in legacy mode and QEMU generated ACPI tables will switch to new CPU hotplug interface during runtime.
In case QEMU is started with legacy BIOS (that doesn't support QEMU generated ACPI tables), legacy CPU hotplug will remain active and could be used by BIOS built in ACPI tables for CPU hotplug.

---
 docs/specs/acpi_cpu_hotplug.txt | 94 +++++++++++++++++++++++++++++++++++------
 1 file changed, 82 insertions(+), 12 deletions(-)
docs/specs/acpi_cpu_hotplug.txt +82 -12
index 340b751..ee219c8 100644
@@ -4,21 +4,91 @@ QEMU<->ACPI BIOS CPU hotplug interface
 QEMU supports CPU hotplug via ACPI. This document
 describes the interface between QEMU and the ACPI BIOS.
 
-ACPI GPE block (IO ports 0xafe0-0xafe3, byte access):
------------------------------------------
-
-Generic ACPI GPE block. Bit 2 (GPE.2) used to notify CPU
-hot-add/remove event to ACPI BIOS, via SCI interrupt.
+ACPI BIOS GPE.2 handler is dedicated for notifying OS about CPU hot-add
+and hot-remove events.
 
+============================================
+Legacy ACPI CPU hotplug interface registers:
+--------------------------------------------
 CPU present bitmap for:
   ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access)
   PIIX-PM  (IO port 0xaf00-0xaf1f, 1-byte access)
+  One bit per CPU. Bit position reflects corresponding CPU APIC ID. Read-only.
+  The first DWORD in bitmap is used in write mode to switch from legacy
+  to new CPU hotplug interface, write 0 into it to do switch.
 ---------------------------------------------------------------
-One bit per CPU. Bit position reflects corresponding CPU APIC ID.
-Read-only.
+QEMU sets corresponding CPU bit on hot-add event and issues SCI
+with GPE.2 event set. CPU present map is read by ACPI BIOS GPE.2 handler
+to notify OS about CPU hot-add events. CPU hot-remove isn't supported.
+
+=====================================
+ACPI CPU hotplug interface registers:
+-------------------------------------
+Register block base address:
+    ICH9-LPC IO port 0x0cd8
+    PIIX-PM  IO port 0xaf00
+Register block size:
+    ACPI_CPU_HOTPLUG_REG_LEN = 12
+
+read access:
+    offset:
+    [0x0-0x3] reserved
+    [0x4] CPU device status fields: (1 byte access)
+        bits:
+           0: Device is enabled and may be used by guest
+           1: Device insert event, used to distinguish device for which
+              no device check event to OSPM was issued.
+              It's valid only when bit 0 is set.
+           2: Device remove event, used to distinguish device for which
+              no device eject request to OSPM was issued.
+           3-7: reserved and should be ignored by OSPM
+    [0x5-0x7] reserved
+    [0x8] Command data: (DWORD access)
+          in case of error or unsupported command reads is 0xFFFFFFFF
+          current 'Command field' value:
+              0: returns PXM value corresponding to device
+
+write access:
+    offset:
+    [0x0-0x3] CPU selector: (DWORD access)
+              selects active CPU device. All following accesses to other
+              registers will read/store data from/to selected CPU.
+    [0x4] CPU device control fields: (1 byte access)
+        bits:
+            0: reserved, OSPM must clear it before writing to register.
+            1: if set to 1 clears device insert event, set by OSPM
+               after it has emitted device check event for the
+               selected CPU device
+            2: if set to 1 clears device remove event, set by OSPM
+               after it has emitted device eject request for the
+               selected CPU device
+            3: if set to 1 initiates device eject, set by OSPM when it
+               triggers CPU device removal and calls _EJ0 method
+            4-7: reserved, OSPM must clear them before writing to register
+    [0x5] Command field: (1 byte access)
+          value:
+            0: selects a CPU device with inserting/removing events and
+               following reads from 'Command data' register return
+               selected CPU (CPU selector value). If no CPU with events
+               found, the current CPU selector doesn't change and
+               corresponding insert/remove event flags are not set.
+            1: following writes to 'Command data' register set OST event
+               register in QEMU
+            2: following writes to 'Command data' register set OST status
+               register in QEMU
+            other values: reserved
+    [0x6-0x7] reserved
+    [0x8] Command data: (DWORD access)
+          current 'Command field' value:
+              0: OSPM reads value of CPU selector
+              1: stores value into OST event register
+              2: stores value into OST status register, triggers
+                 ACPI_DEVICE_OST QMP event from QEMU to external applications
+                 with current values of OST event and status registers.
+            other values: reserved
 
-CPU hot-add/remove notification:
------------------------------------------------------
-QEMU sets/clears corresponding CPU bit on hot-add/remove event.
-CPU present map read by ACPI BIOS GPE.2 handler to notify OS of CPU
-hot-(un)plug events.
+Selecting CPU device beyond possible range has no effect on platform:
+   - write accesses to CPU hot-plug registers not documented above are
+     ignored
+   - read accesses to CPU hot-plug registers not documented above return
+     all bits set to 0.
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v2 2/10 pc: piix4/ich9: add 'cpu-hotplug-legacy' property

In reply to Igor Mammedov

It will be used to select which hotplug call-back is called and for switching from legacy mode into new one.

---
 hw/acpi/ich9.c         | 23 ++++++++++++++++++++++-
 hw/acpi/piix4.c        | 24 +++++++++++++++++++++++-
 include/hw/acpi/ich9.h |  1 +
 3 files changed, 46 insertions(+), 2 deletions(-)
hw/acpi/ich9.c +22 -1
index 853c9c4..ed16940 100644
@@ -306,6 +306,21 @@ static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value,
     s->pm.acpi_memory_hotplug.is_enabled = value;
 }
 
+static bool ich9_pm_get_cpu_hotplug_legacy(Object *obj, Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    return s->pm.cpu_hotplug_legacy;
+}
+
+static void ich9_pm_set_cpu_hotplug_legacy(Object *obj, bool value,
+                                           Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    s->pm.cpu_hotplug_legacy = value;
+}
+
 static void ich9_pm_get_disable_s3(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
@@ -397,6 +412,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
 {
     static const uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
     pm->acpi_memory_hotplug.is_enabled = true;
+    pm->cpu_hotplug_legacy = true;
     pm->disable_s3 = 0;
     pm->disable_s4 = 0;
     pm->s4_val = 2;
@@ -412,6 +428,10 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
                              ich9_pm_get_memory_hotplug_support,
                              ich9_pm_set_memory_hotplug_support,
                              NULL);
+    object_property_add_bool(obj, "cpu-hotplug-legacy",
+                             ich9_pm_get_cpu_hotplug_legacy,
+                             ich9_pm_set_cpu_hotplug_legacy,
+                             NULL);
     object_property_add(obj, ACPI_PM_PROP_S3_DISABLED, "uint8",
                         ich9_pm_get_disable_s3,
                         ich9_pm_set_disable_s3,
@@ -439,7 +459,8 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
         object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         acpi_memory_plug_cb(hotplug_dev, &lpc->pm.acpi_memory_hotplug,
                             dev, errp);
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+    } else if (lpc->pm.cpu_hotplug_legacy &&
+               object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
         legacy_acpi_cpu_plug_cb(hotplug_dev, &lpc->pm.gpe_cpu, dev, errp);
     } else {
         error_setg(errp, "acpi: device plug request for not supported device"
hw/acpi/piix4.c +23 -1
index c48cb1b..9ae3964 100644
@@ -86,6 +86,7 @@ typedef struct PIIX4PMState {
     uint8_t disable_s4;
     uint8_t s4_val;
 
+    bool cpu_hotplug_legacy;
     AcpiCpuHotplug gpe_cpu;
 
     MemHotplugState acpi_memory_hotplug;
@@ -351,7 +352,8 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
         acpi_memory_plug_cb(hotplug_dev, &s->acpi_memory_hotplug, dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
         acpi_pcihp_device_plug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev, errp);
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+    } else if (s->cpu_hotplug_legacy &&
+               object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
         legacy_acpi_cpu_plug_cb(hotplug_dev, &s->gpe_cpu, dev, errp);
     } else {
         error_setg(errp, "acpi: device plug request for not supported device"
@@ -560,6 +562,21 @@ static const MemoryRegionOps piix4_gpe_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
+
+static bool piix4_get_cpu_hotplug_legacy(Object *obj, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(obj);
+
+    return s->cpu_hotplug_legacy;
+}
+
+static void piix4_set_cpu_hotplug_legacy(Object *obj, bool value, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(obj);
+
+    s->cpu_hotplug_legacy = value;
+}
+
 static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
                                            PCIBus *bus, PIIX4PMState *s)
 {
@@ -570,6 +587,11 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
     acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
                     s->use_acpi_pci_hotplug);
 
+    s->cpu_hotplug_legacy = true;
+    object_property_add_bool(OBJECT(s), "cpu-hotplug-legacy",
+                             piix4_get_cpu_hotplug_legacy,
+                             piix4_set_cpu_hotplug_legacy,
+                             NULL);
     legacy_acpi_cpu_hotplug_init(parent, OBJECT(s), &s->gpe_cpu,
                                  PIIX4_CPU_HOTPLUG_IO_BASE);
 
include/hw/acpi/ich9.h +1 -0
index bbd657c..e29a856 100644
@@ -48,6 +48,7 @@ typedef struct ICH9LPCPMRegs {
     uint32_t pm_io_base;
     Notifier powerdown_notifier;
 
+    bool cpu_hotplug_legacy;
     AcpiCpuHotplug gpe_cpu;
 
     MemHotplugState acpi_memory_hotplug;
Signature · 1 line
1.8.3.1
Reviewed-by on v2 2/10
#3 lore raw

Re: [Qemu-devel] [PATCH v2 02/10] pc: piix4/ich9: add 'cpu-hotplug-legacy' property

Quoted 127 lines · Igor Mammedov

It will be used to select which hotplug call-back is called and for switching from legacy mode into new one.

---
  hw/acpi/ich9.c         | 23 ++++++++++++++++++++++-
  hw/acpi/piix4.c        | 24 +++++++++++++++++++++++-
  include/hw/acpi/ich9.h |  1 +
  3 files changed, 46 insertions(+), 2 deletions(-)
hw/acpi/ich9.c +22 -1
index 853c9c4..ed16940 100644
@@ -306,6 +306,21 @@ static void ich9_pm_set_memory_hotplug_support(Object *obj, bool value,
      s->pm.acpi_memory_hotplug.is_enabled = value;
  }
 
+static bool ich9_pm_get_cpu_hotplug_legacy(Object *obj, Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    return s->pm.cpu_hotplug_legacy;
+}
+
+static void ich9_pm_set_cpu_hotplug_legacy(Object *obj, bool value,
+                                           Error **errp)
+{
+    ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
+
+    s->pm.cpu_hotplug_legacy = value;
+}
+
  static void ich9_pm_get_disable_s3(Object *obj, Visitor *v, const char *name,
                                     void *opaque, Error **errp)
  {
@@ -397,6 +412,7 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
  {
      static const uint32_t gpe0_len = ICH9_PMIO_GPE0_LEN;
      pm->acpi_memory_hotplug.is_enabled = true;
+    pm->cpu_hotplug_legacy = true;
      pm->disable_s3 = 0;
      pm->disable_s4 = 0;
      pm->s4_val = 2;
@@ -412,6 +428,10 @@ void ich9_pm_add_properties(Object *obj, ICH9LPCPMRegs *pm, Error **errp)
                               ich9_pm_get_memory_hotplug_support,
                               ich9_pm_set_memory_hotplug_support,
                               NULL);
+    object_property_add_bool(obj, "cpu-hotplug-legacy",
+                             ich9_pm_get_cpu_hotplug_legacy,
+                             ich9_pm_set_cpu_hotplug_legacy,
+                             NULL);
      object_property_add(obj, ACPI_PM_PROP_S3_DISABLED, "uint8",
                          ich9_pm_get_disable_s3,
                          ich9_pm_set_disable_s3,
@@ -439,7 +459,8 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
          object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
          acpi_memory_plug_cb(hotplug_dev, &lpc->pm.acpi_memory_hotplug,
                              dev, errp);
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+    } else if (lpc->pm.cpu_hotplug_legacy &&
+               object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
          legacy_acpi_cpu_plug_cb(hotplug_dev, &lpc->pm.gpe_cpu, dev, errp);
      } else {
          error_setg(errp, "acpi: device plug request for not supported device"
hw/acpi/piix4.c +23 -1
index c48cb1b..9ae3964 100644
@@ -86,6 +86,7 @@ typedef struct PIIX4PMState {
      uint8_t disable_s4;
      uint8_t s4_val;
 
+    bool cpu_hotplug_legacy;
      AcpiCpuHotplug gpe_cpu;
 
      MemHotplugState acpi_memory_hotplug;
@@ -351,7 +352,8 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
          acpi_memory_plug_cb(hotplug_dev, &s->acpi_memory_hotplug, dev, errp);
      } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
          acpi_pcihp_device_plug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev, errp);
-    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+    } else if (s->cpu_hotplug_legacy &&
+               object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
          legacy_acpi_cpu_plug_cb(hotplug_dev, &s->gpe_cpu, dev, errp);
      } else {
          error_setg(errp, "acpi: device plug request for not supported device"
@@ -560,6 +562,21 @@ static const MemoryRegionOps piix4_gpe_ops = {
      .endianness = DEVICE_LITTLE_ENDIAN,
  };
 
+
+static bool piix4_get_cpu_hotplug_legacy(Object *obj, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(obj);
+
+    return s->cpu_hotplug_legacy;
+}
+
+static void piix4_set_cpu_hotplug_legacy(Object *obj, bool value, Error **errp)
+{
+    PIIX4PMState *s = PIIX4_PM(obj);
+
+    s->cpu_hotplug_legacy = value;
+}
+
  static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
                                             PCIBus *bus, PIIX4PMState *s)
  {
@@ -570,6 +587,11 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
      acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
                      s->use_acpi_pci_hotplug);
 
+    s->cpu_hotplug_legacy = true;
+    object_property_add_bool(OBJECT(s), "cpu-hotplug-legacy",
+                             piix4_get_cpu_hotplug_legacy,
+                             piix4_set_cpu_hotplug_legacy,
+                             NULL);
      legacy_acpi_cpu_hotplug_init(parent, OBJECT(s), &s->gpe_cpu,
                                   PIIX4_CPU_HOTPLUG_IO_BASE);
 
include/hw/acpi/ich9.h +0 -0
index bbd657c..e29a856 100644

include/hw/acpi/ich9.h typedef struct ICH9LPCPMRegs { · line 54

Quoted 7 lines
include/hw/acpi/ich9.h +1 -0
@@ -48,6 +48,7 @@ typedef struct ICH9LPCPMRegs {
      uint32_t pm_io_base;
      Notifier powerdown_notifier;
 
+    bool cpu_hotplug_legacy;
      AcpiCpuHotplug gpe_cpu;
 
      MemHotplugState acpi_memory_hotplug;

Thanks,
Marcel

#4 lore raw

PATCH v2 3/10 acpi: cpuhp: add CPU devices AML with _STA method

In reply to Igor Mammedov

it adds CPU objects to DSDT with _STA method
and QEMU side of CPU hotplug interface initialization with registers sufficient to handle _STA requests, including necessary hotplug callbacks in piix4,ich9 code.

Hot-(un)plug hw/acpi parts will be added by
corresponding follow up patches.

---
v2:
- merge relevant hw and AML togethe on one patch
- use UID in Device(CPUxxx) instead of apic id,
i.e. do the same as for Processor object

---
 hw/acpi/Makefile.objs  |   1 +
 hw/acpi/cpu.c          | 240 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/ich9.c         |   9 +-
 hw/acpi/piix4.c        |  11 ++-
 include/hw/acpi/cpu.h  |  51 +++++++++++
 include/hw/acpi/ich9.h |   2 +
 trace-events           |   5 ++
 7 files changed, 313 insertions(+), 6 deletions(-)
 create mode 100644 hw/acpi/cpu.c
 create mode 100644 include/hw/acpi/cpu.h
hw/acpi/Makefile.objs +1 -0
index 66bd727..f200419 100644
@@ -2,6 +2,7 @@ common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o
 common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
 common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.o
+common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
 obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
 common-obj-$(CONFIG_ACPI) += acpi_interface.o
 common-obj-$(CONFIG_ACPI) += bios-linker-loader.o
hw/acpi/cpu.c new file +240 -0

240 lines not on this page · raw message

hw/acpi/ich9.c +6 -3
index ed16940..9a81da8 100644
@@ -459,9 +459,12 @@ void ich9_pm_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
         object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         acpi_memory_plug_cb(hotplug_dev, &lpc->pm.acpi_memory_hotplug,
                             dev, errp);
-    } else if (lpc->pm.cpu_hotplug_legacy &&
-               object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
-        legacy_acpi_cpu_plug_cb(hotplug_dev, &lpc->pm.gpe_cpu, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+        if (lpc->pm.cpu_hotplug_legacy) {
+            legacy_acpi_cpu_plug_cb(hotplug_dev, &lpc->pm.gpe_cpu, dev, errp);
+        } else {
+            acpi_cpu_plug_cb(hotplug_dev, &lpc->pm.cpuhp_state, dev, errp);
+        }
     } else {
         error_setg(errp, "acpi: device plug request for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
hw/acpi/piix4.c +8 -3
index 9ae3964..6351d2e 100644
@@ -34,6 +34,7 @@
 #include "hw/acpi/piix4.h"
 #include "hw/acpi/pcihp.h"
 #include "hw/acpi/cpu_hotplug.h"
+#include "hw/acpi/cpu.h"
 #include "hw/hotplug.h"
 #include "hw/mem/pc-dimm.h"
 #include "hw/acpi/memory_hotplug.h"
@@ -88,6 +89,7 @@ typedef struct PIIX4PMState {
 
     bool cpu_hotplug_legacy;
     AcpiCpuHotplug gpe_cpu;
+    CPUHotplugState cpuhp_state;
 
     MemHotplugState acpi_memory_hotplug;
 } PIIX4PMState;
@@ -352,9 +354,12 @@ static void piix4_device_plug_cb(HotplugHandler *hotplug_dev,
         acpi_memory_plug_cb(hotplug_dev, &s->acpi_memory_hotplug, dev, errp);
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
         acpi_pcihp_device_plug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev, errp);
-    } else if (s->cpu_hotplug_legacy &&
-               object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
-        legacy_acpi_cpu_plug_cb(hotplug_dev, &s->gpe_cpu, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
+        if (s->cpu_hotplug_legacy) {
+            legacy_acpi_cpu_plug_cb(hotplug_dev, &s->gpe_cpu, dev, errp);
+        } else {
+            acpi_cpu_plug_cb(hotplug_dev, &s->cpuhp_state, dev, errp);
+        }
     } else {
         error_setg(errp, "acpi: device plug request for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
include/hw/acpi/cpu.h new file +51 -0

51 lines not on this page · raw message

include/hw/acpi/ich9.h +2 -0
index e29a856..a352c94 100644
@@ -23,6 +23,7 @@
 
 #include "hw/acpi/acpi.h"
 #include "hw/acpi/cpu_hotplug.h"
+#include "hw/acpi/cpu.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/acpi_dev_interface.h"
 #include "hw/acpi/tco.h"
@@ -50,6 +51,7 @@ typedef struct ICH9LPCPMRegs {
 
     bool cpu_hotplug_legacy;
     AcpiCpuHotplug gpe_cpu;
+    CPUHotplugState cpuhp_state;
 
     MemHotplugState acpi_memory_hotplug;
 
trace-events +5 -0
index 2f14205..66ec813 100644
@@ -2164,3 +2164,8 @@ e1000e_cfg_support_virtio(bool support) "Virtio header supported: %d"
 
 e1000e_vm_state_running(void) "VM state is running"
 e1000e_vm_state_stopped(void) "VM state is stopped"
+
+# hw/acpi/cpu.c
+cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32
+cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8
+cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v2 4/10 pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook

In reply to Igor Mammedov

Add madt_cpu callback to AcpiDeviceIfClass and use it for generating LAPIC MADT entries for CPUs.

Later it will be used for generating x2APIC entries in case of more than 255 CPUs and also would be reused by ARM target when ACPI CPU hotplug is introduced there.

---
 hw/acpi/piix4.c                      |  1 +
 hw/i386/acpi-build.c                 | 45 +++++++++++++++++++++---------------
 hw/isa/lpc_ich9.c                    |  1 +
 include/hw/acpi/acpi_dev_interface.h |  7 ++++++
 include/hw/i386/pc.h                 |  5 ++++
 stubs/Makefile.objs                  |  1 +
 stubs/pc_madt_cpu_entry.c            |  7 ++++++
 7 files changed, 49 insertions(+), 18 deletions(-)
 create mode 100644 stubs/pc_madt_cpu_entry.c
hw/acpi/piix4.c +1 -0
index 6351d2e..6d24cb5 100644
@@ -658,6 +658,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data)
     hc->unplug = piix4_device_unplug_cb;
     adevc->ospm_status = piix4_ospm_status;
     adevc->send_event = piix4_send_gpe;
+    adevc->madt_cpu = pc_madt_cpu_entry;
 }
 
 static const TypeInfo piix4_pm_info = {
hw/i386/acpi-build.c +27 -18

63 lines not on this page · raw message

hw/isa/lpc_ich9.c +1 -0
index 213741b..c1a4f1b 100644
@@ -714,6 +714,7 @@ static void ich9_lpc_class_init(ObjectClass *klass, void *data)
     hc->unplug = ich9_pm_device_unplug_cb;
     adevc->ospm_status = ich9_pm_ospm_status;
     adevc->send_event = ich9_send_gpe;
+    adevc->madt_cpu = pc_madt_cpu_entry;
 }
 
 static const TypeInfo ich9_lpc_info = {
include/hw/acpi/acpi_dev_interface.h +7 -0
index a0c4a33..da4ef7f 100644
@@ -3,6 +3,7 @@
 
 #include "qom/object.h"
 #include "qapi-types.h"
+#include "hw/boards.h"
 
 /* These values are part of guest ABI, and can not be changed */
 typedef enum {
@@ -37,6 +38,10 @@ void acpi_send_event(DeviceState *dev, AcpiEventStatusBits event);
  * ospm_status: returns status of ACPI device objects, reported
  *              via _OST method if device supports it.
  * send_event: inject a specified event into guest
+ * madt_cpu: fills @entry with Interrupt Controller Structure
+ *           for CPU indexed by @uid in @apic_ids array,
+ *           returned structure types are:
+ *           0 - Local APIC, 9 - Local x2APIC, 0xB - GICC
  *
  * Interface is designed for providing unified interface
  * to generic ACPI functionality that could be used without
@@ -50,5 +55,7 @@ typedef struct AcpiDeviceIfClass {
     /* <public> */
     void (*ospm_status)(AcpiDeviceIf *adev, ACPIOSTInfoList ***list);
     void (*send_event)(AcpiDeviceIf *adev, AcpiEventStatusBits ev);
+    void (*madt_cpu)(AcpiDeviceIf *adev, int uid,
+                     CPUArchIdList *apic_ids, GArray *entry);
 } AcpiDeviceIfClass;
 #endif
include/hw/i386/pc.h +5 -0
index 49566c8..9e23929 100644
@@ -17,6 +17,7 @@
 #include "hw/compat.h"
 #include "hw/mem/pc-dimm.h"
 #include "hw/mem/nvdimm.h"
+#include "hw/acpi/acpi_dev_interface.h"
 
 #define HPET_INTCAP "hpet-intcap"
 
@@ -345,6 +346,10 @@ void pc_system_firmware_init(MemoryRegion *rom_memory,
 /* pvpanic.c */
 uint16_t pvpanic_port(void);
 
+/* acpi-build.c */
+void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
+                       CPUArchIdList *apic_ids, GArray *entry);
+
 /* e820 types */
 #define E820_RAM        1
 #define E820_RESERVED   2
stubs/Makefile.objs +1 -0
index 4b258a6..e8ff38d 100644
@@ -41,3 +41,4 @@ stub-obj-y += target-monitor-defs.o
 stub-obj-y += target-get-monitor-def.o
 stub-obj-y += vhost.o
 stub-obj-y += iohandler.o
+stub-obj-y += pc_madt_cpu_entry.o
stubs/pc_madt_cpu_entry.c new file +7 -0
new file mode 100644
index 0000000..427e772
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/i386/pc.h"
+
+void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
+                       CPUArchIdList *apic_ids, GArray *entry)
+{
+}
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v2 5/10 acpi: cpuhp: implement hot-add parts of CPU hotplug interface

In reply to Igor Mammedov

it adds hw registers needed for handling CPU hot-add and corresponding AML methods to handle hot-add events on guest side.

---
 hw/acpi/cpu.c         | 150 +++++++++++++++++++++++++++++++++++++++++++++++++-
 include/hw/acpi/cpu.h |   5 +-
 trace-events          |   4 ++
 3 files changed, 157 insertions(+), 2 deletions(-)
hw/acpi/cpu.c +149 -1
index d99002c..811be8a 100644
@@ -7,6 +7,13 @@
 #define ACPI_CPU_HOTPLUG_REG_LEN 12
 #define ACPI_CPU_SELECTOR_OFFSET_WR 0
 #define ACPI_CPU_FLAGS_OFFSET_RW 4
+#define ACPI_CPU_CMD_OFFSET_WR 5
+#define ACPI_CPU_CMD_DATA_OFFSET_RW 8
+
+enum {
+    CPHP_GET_NEXT_CPU_WITH_EVENT_CMD = 0,
+    CPHP_CMD_MAX
+};
 
 static uint64_t cpu_hotplug_rd(void *opaque, hwaddr addr, unsigned size)
 {
@@ -22,8 +29,19 @@ static uint64_t cpu_hotplug_rd(void *opaque, hwaddr addr, unsigned size)
     switch (addr) {
     case ACPI_CPU_FLAGS_OFFSET_RW: /* pack and return is_* fields */
         val |= cdev->cpu ? 1 : 0;
+        val |= cdev->is_inserting ? 2 : 0;
         trace_cpuhp_acpi_read_flags(cpu_st->selector, val);
         break;
+    case ACPI_CPU_CMD_DATA_OFFSET_RW:
+        switch (cpu_st->command) {
+        case CPHP_GET_NEXT_CPU_WITH_EVENT_CMD:
+           val = cpu_st->selector;
+           break;
+        default:
+           break;
+        }
+        trace_cpuhp_acpi_read_cmd_data(cpu_st->selector, val);
+        break;
     default:
         break;
     }
@@ -34,6 +52,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
                            unsigned int size)
 {
     CPUHotplugState *cpu_st = opaque;
+    AcpiCpuStatus *cdev;
 
     assert(cpu_st->dev_count);
 
@@ -49,6 +68,33 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
         cpu_st->selector = data;
         trace_cpuhp_acpi_write_idx(cpu_st->selector);
         break;
+    case ACPI_CPU_FLAGS_OFFSET_RW: /* set is_* fields  */
+        cdev = &cpu_st->devs[cpu_st->selector];
+        if (data & 2) { /* clear insert event */
+            cdev->is_inserting = false;
+            trace_cpuhp_acpi_clear_inserting_evt(cpu_st->selector);
+        }
+        break;
+    case ACPI_CPU_CMD_OFFSET_WR:
+        trace_cpuhp_acpi_write_cmd(cpu_st->selector, data);
+        if (data < CPHP_CMD_MAX) {
+            cpu_st->command = data;
+            if (cpu_st->command == CPHP_GET_NEXT_CPU_WITH_EVENT_CMD) {
+                uint32_t iter = cpu_st->selector;
+
+                do {
+                    cdev = &cpu_st->devs[iter];
+                    if (cdev->is_inserting) {
+                        cpu_st->selector = iter;
+                        trace_cpuhp_acpi_cpu_has_events(cpu_st->selector,
+                            cdev->is_inserting);
+                        break;
+                    }
+                    iter = iter + 1 < cpu_st->dev_count ? iter + 1 : 0;
+                } while (iter != cpu_st->selector);
+            }
+        }
+        break;
     default:
         break;
     }
@@ -111,8 +157,23 @@ void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev,
     }
 
     cdev->cpu = CPU(dev);
+    if (dev->hotplugged) {
+        cdev->is_inserting = true;
+        acpi_send_event(DEVICE(hotplug_dev), ACPI_CPU_HOTPLUG_STATUS);
+    }
 }
 
+static const VMStateDescription vmstate_cpuhp_sts = {
+    .name = "CPU hotplug device state",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField[]) {
+        VMSTATE_BOOL(is_inserting, AcpiCpuStatus),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_cpu_hotplug = {
     .name = "CPU hotplug state",
     .version_id = 1,
@@ -120,6 +181,9 @@ const VMStateDescription vmstate_cpu_hotplug = {
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
         VMSTATE_UINT32(selector, CPUHotplugState),
+        VMSTATE_UINT8(command, CPUHotplugState),
+        VMSTATE_STRUCT_VARRAY_POINTER_UINT32(devs, CPUHotplugState, dev_count,
+                                             vmstate_cpuhp_sts, AcpiCpuStatus),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -128,13 +192,19 @@ const VMStateDescription vmstate_cpu_hotplug = {
 #define CPUHP_RES_DEVICE  "PRES"
 #define CPU_LOCK          "CPLK"
 #define CPU_STS_METHOD    "CSTA"
+#define CPU_SCAN_METHOD   "CSCN"
+#define CPU_NOTIFY_METHOD "CTFY"
 
 #define CPU_ENABLED       "CPEN"
 #define CPU_SELECTOR      "CSEL"
+#define CPU_COMMAND       "CCMD"
+#define CPU_DATA          "CDAT"
+#define CPU_INSERT_EVENT  "CINS"
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                     hwaddr io_base,
-                    const char *res_root)
+                    const char *res_root,
+                    const char *event_handler_method)
 {
     Aml *ifctx;
     Aml *field;
@@ -147,6 +217,9 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
     MachineClass *mc = MACHINE_GET_CLASS(machine);
     CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(machine);
     char *cphp_res_path = g_strdup_printf("%s." CPUHP_RES_DEVICE, res_root);
+    Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, NULL);
+    AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
+    AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
 
     cpu_ctrl_dev = aml_device("%s", cphp_res_path);
     {
@@ -173,11 +246,18 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         aml_append(field, aml_reserved_field(ACPI_CPU_FLAGS_OFFSET_RW * 8));
         /* 1 if enabled, read only */
         aml_append(field, aml_named_field(CPU_ENABLED, 1));
+        /* (read) 1 if has a insert event. (write) 1 to clear event */
+        aml_append(field, aml_named_field(CPU_INSERT_EVENT, 1));
+        aml_append(field, aml_reserved_field(6));
+        aml_append(field, aml_named_field(CPU_COMMAND, 8));
         aml_append(cpu_ctrl_dev, field);
 
         field = aml_field("PRST", AML_DWORD_ACC, AML_NOLOCK, AML_PRESERVE);
         /* CPU selector, write only */
         aml_append(field, aml_named_field(CPU_SELECTOR, 32));
+        /* flags + cmd + 2byte align */
+        aml_append(field, aml_reserved_field(4 * 8));
+        aml_append(field, aml_named_field(CPU_DATA, 32));
         aml_append(cpu_ctrl_dev, field);
 
     }
@@ -189,10 +269,27 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         Aml *ctrl_lock = aml_name("%s.%s", cphp_res_path, CPU_LOCK);
         Aml *cpu_selector = aml_name("%s.%s", cphp_res_path, CPU_SELECTOR);
         Aml *is_enabled = aml_name("%s.%s", cphp_res_path, CPU_ENABLED);
+        Aml *cpu_cmd = aml_name("%s.%s", cphp_res_path, CPU_COMMAND);
+        Aml *cpu_data = aml_name("%s.%s", cphp_res_path, CPU_DATA);
+        Aml *ins_evt = aml_name("%s.%s", cphp_res_path, CPU_INSERT_EVENT);
 
         aml_append(cpus_dev, aml_name_decl("_HID", aml_string("ACPI0010")));
         aml_append(cpus_dev, aml_name_decl("_CID", aml_eisaid("PNP0A05")));
 
+        method = aml_method(CPU_NOTIFY_METHOD, 2, AML_NOTSERIALIZED);
+        for (i = 0; i < arch_ids->len; i++) {
+            Aml *cpu = aml_name(CPU_NAME_FMT, i);
+            Aml *uid = aml_arg(0);
+            Aml *event = aml_arg(1);
+
+            ifctx = aml_if(aml_equal(uid, aml_int(i)));
+            {
+                aml_append(ifctx, aml_notify(cpu, event));
+            }
+            aml_append(method, ifctx);
+        }
+        aml_append(cpus_dev, method);
+
         method = aml_method(CPU_STS_METHOD, 1, AML_SERIALIZED);
         {
             Aml *idx = aml_arg(0);
@@ -211,10 +308,41 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         }
         aml_append(cpus_dev, method);
 
+        method = aml_method(CPU_SCAN_METHOD, 0, AML_SERIALIZED);
+        {
+            Aml *while_ctx;
+            Aml *has_event = aml_local(0);
+            Aml *dev_chk = aml_int(1);
+            Aml *next_cpu_cmd = aml_int(CPHP_GET_NEXT_CPU_WITH_EVENT_CMD);
+
+            aml_append(method, aml_acquire(ctrl_lock, 0xFFFF));
+            aml_append(method, aml_store(one, has_event));
+            while_ctx = aml_while(aml_equal(has_event, one));
+            {
+                 /* clear loop exit condition, ins_evt check
+                  * will set it to 1 while next_cpu_cmd returns a CPU
+                  * with events */
+                 aml_append(while_ctx, aml_store(zero, has_event));
+                 aml_append(while_ctx, aml_store(next_cpu_cmd, cpu_cmd));
+                 ifctx = aml_if(aml_equal(ins_evt, one));
+                 {
+                     aml_append(ifctx,
+                         aml_call2(CPU_NOTIFY_METHOD, cpu_data, dev_chk));
+                     aml_append(ifctx, aml_store(one, ins_evt));
+                     aml_append(ifctx, aml_store(one, has_event));
+                 }
+                 aml_append(while_ctx, ifctx);
+            }
+            aml_append(method, while_ctx);
+            aml_append(method, aml_release(ctrl_lock));
+        }
+        aml_append(cpus_dev, method);
+
         /* build Processor object for each processor */
         for (i = 0; i < arch_ids->len; i++) {
             Aml *dev;
             Aml *uid = aml_int(i);
+            GArray *madt_buf = g_array_new(0, 1, 1);
             int arch_id = arch_ids->cpus[i].arch_id;
 
             if (opts.apci_1_compatible && arch_id < 255) {
@@ -229,12 +357,32 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
             aml_append(method, aml_return(aml_call1(CPU_STS_METHOD, uid)));
             aml_append(dev, method);
 
+            /* build _MAT object */
+            assert(adevc && adevc->madt_cpu);
+            adevc->madt_cpu(adev, i, arch_ids, madt_buf);
+            switch (madt_buf->data[0]) {
+            case ACPI_APIC_PROCESSOR: {
+                AcpiMadtProcessorApic *apic = (void *)madt_buf->data;
+                apic->flags = cpu_to_le32(1);
+                break;
+            }
+            default:
+                assert(0);
+            }
+            aml_append(dev, aml_name_decl("_MAT",
+                aml_buffer(madt_buf->len, (uint8_t *)madt_buf->data)));
+            g_array_free(madt_buf, true);
+
             aml_append(cpus_dev, dev);
         }
     }
     aml_append(sb_scope, cpus_dev);
     aml_append(table, sb_scope);
 
+    method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
+    aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
+    aml_append(table, method);
+
     g_free(cphp_res_path);
     g_free(arch_ids);
 }
include/hw/acpi/cpu.h +4 -1
index f345447..55c3166 100644
@@ -20,11 +20,13 @@
 typedef struct AcpiCpuStatus {
     struct CPUState *cpu;
     uint64_t arch_id;
+    bool is_inserting;
 } AcpiCpuStatus;
 
 typedef struct CPUHotplugState {
     MemoryRegion ctrl_reg;
     uint32_t selector;
+    uint8_t command;
     uint32_t dev_count;
     AcpiCpuStatus *devs;
 } CPUHotplugState;
@@ -41,7 +43,8 @@ typedef struct CPUHotplugFeatures {
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                     hwaddr io_base,
-                    const char *res_root);
+                    const char *res_root,
+                    const char *event_handler_method);
 
 extern const VMStateDescription vmstate_cpu_hotplug;
 #define VMSTATE_CPU_HOTPLUG(cpuhp, state) \
trace-events +4 -0
index 66ec813..fac1f51 100644
@@ -2169,3 +2169,7 @@ e1000e_vm_state_stopped(void) "VM state is stopped"
 cpuhp_acpi_invalid_idx_selected(uint32_t idx) "0x%"PRIx32
 cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"PRIx8
 cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32
+cpuhp_acpi_write_cmd(uint32_t idx, uint8_t cmd) "idx[0x%"PRIx32"] cmd: 0x%"PRIx8
+cpuhp_acpi_read_cmd_data(uint32_t idx, uint32_t data) "idx[0x%"PRIx32"] data: 0x%"PRIx32
+cpuhp_acpi_cpu_has_events(uint32_t idx, bool ins) "idx[0x%"PRIx32"] inserting: %d"
+cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]"
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v2 6/10 acpi: cpuhp: implement hot-remove parts of CPU hotplug interface

In reply to Igor Mammedov

it adds hw registers needed for handling CPU hot-remove and corresponding AML methods to request and eject a CPU with necessary hotplug callbacks in pc,piix4,ich9 code.

---
 hw/acpi/cpu.c         | 90 ++++++++++++++++++++++++++++++++++++++++++++++++---
 hw/acpi/ich9.c        |  7 ++++
 hw/acpi/piix4.c       |  6 ++++
 hw/i386/pc.c          | 47 +++++++++++++++++++++++++++
 include/hw/acpi/cpu.h |  8 +++++
 trace-events          |  5 ++-
 6 files changed, 158 insertions(+), 5 deletions(-)
hw/acpi/cpu.c +86 -4
index 811be8a..483b808 100644
@@ -30,6 +30,7 @@ static uint64_t cpu_hotplug_rd(void *opaque, hwaddr addr, unsigned size)
     case ACPI_CPU_FLAGS_OFFSET_RW: /* pack and return is_* fields */
         val |= cdev->cpu ? 1 : 0;
         val |= cdev->is_inserting ? 2 : 0;
+        val |= cdev->is_removing  ? 4 : 0;
         trace_cpuhp_acpi_read_flags(cpu_st->selector, val);
         break;
     case ACPI_CPU_CMD_DATA_OFFSET_RW:
@@ -73,6 +74,22 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
         if (data & 2) { /* clear insert event */
             cdev->is_inserting = false;
             trace_cpuhp_acpi_clear_inserting_evt(cpu_st->selector);
+        } else if (data & 4) { /* clear remove event */
+            cdev->is_removing = false;
+            trace_cpuhp_acpi_clear_remove_evt(cpu_st->selector);
+        } else if (data & 8) {
+            DeviceState *dev = NULL;
+            HotplugHandler *hotplug_ctrl = NULL;
+
+            if (!cdev->cpu) {
+                trace_cpuhp_acpi_ejecting_invalid_cpu(cpu_st->selector);
+                break;
+            }
+
+            trace_cpuhp_acpi_ejecting_cpu(cpu_st->selector);
+            dev = DEVICE(cdev->cpu);
+            hotplug_ctrl = qdev_get_hotplug_handler(dev);
+            hotplug_handler_unplug(hotplug_ctrl, dev, NULL);
         }
         break;
     case ACPI_CPU_CMD_OFFSET_WR:
@@ -84,10 +101,10 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
 
                 do {
                     cdev = &cpu_st->devs[iter];
-                    if (cdev->is_inserting) {
+                    if (cdev->is_inserting || cdev->is_removing) {
                         cpu_st->selector = iter;
                         trace_cpuhp_acpi_cpu_has_events(cpu_st->selector,
-                            cdev->is_inserting);
+                            cdev->is_inserting, cdev->is_removing);
                         break;
                     }
                     iter = iter + 1 < cpu_st->dev_count ? iter + 1 : 0;
@@ -163,6 +180,34 @@ void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev,
     }
 }
 
+void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                CPUHotplugState *cpu_st,
+                                DeviceState *dev, Error **errp)
+{
+    AcpiCpuStatus *cdev;
+
+    cdev = get_cpu_status(cpu_st, dev);
+    if (!cdev) {
+        return;
+    }
+
+    cdev->is_removing = true;
+    acpi_send_event(DEVICE(hotplug_dev), ACPI_CPU_HOTPLUG_STATUS);
+}
+
+void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,
+                        DeviceState *dev, Error **errp)
+{
+    AcpiCpuStatus *cdev;
+
+    cdev = get_cpu_status(cpu_st, dev);
+    if (!cdev) {
+        return;
+    }
+
+    cdev->cpu = NULL;
+}
+
 static const VMStateDescription vmstate_cpuhp_sts = {
     .name = "CPU hotplug device state",
     .version_id = 1,
@@ -170,6 +215,7 @@ static const VMStateDescription vmstate_cpuhp_sts = {
     .minimum_version_id_old = 1,
     .fields      = (VMStateField[]) {
         VMSTATE_BOOL(is_inserting, AcpiCpuStatus),
+        VMSTATE_BOOL(is_removing, AcpiCpuStatus),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -194,12 +240,15 @@ const VMStateDescription vmstate_cpu_hotplug = {
 #define CPU_STS_METHOD    "CSTA"
 #define CPU_SCAN_METHOD   "CSCN"
 #define CPU_NOTIFY_METHOD "CTFY"
+#define CPU_EJECT_METHOD  "CEJ0"
 
 #define CPU_ENABLED       "CPEN"
 #define CPU_SELECTOR      "CSEL"
 #define CPU_COMMAND       "CCMD"
 #define CPU_DATA          "CDAT"
 #define CPU_INSERT_EVENT  "CINS"
+#define CPU_REMOVE_EVENT  "CRMV"
+#define CPU_EJECT_EVENT   "CEJ0"
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                     hwaddr io_base,
@@ -248,7 +297,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         aml_append(field, aml_named_field(CPU_ENABLED, 1));
         /* (read) 1 if has a insert event. (write) 1 to clear event */
         aml_append(field, aml_named_field(CPU_INSERT_EVENT, 1));
-        aml_append(field, aml_reserved_field(6));
+        /* (read) 1 if has a remove event. (write) 1 to clear event */
+        aml_append(field, aml_named_field(CPU_REMOVE_EVENT, 1));
+        /* initiates device eject, write only */
+        aml_append(field, aml_named_field(CPU_EJECT_EVENT, 1));
+        aml_append(field, aml_reserved_field(4));
         aml_append(field, aml_named_field(CPU_COMMAND, 8));
         aml_append(cpu_ctrl_dev, field);
 
@@ -272,6 +325,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         Aml *cpu_cmd = aml_name("%s.%s", cphp_res_path, CPU_COMMAND);
         Aml *cpu_data = aml_name("%s.%s", cphp_res_path, CPU_DATA);
         Aml *ins_evt = aml_name("%s.%s", cphp_res_path, CPU_INSERT_EVENT);
+        Aml *rm_evt = aml_name("%s.%s", cphp_res_path, CPU_REMOVE_EVENT);
+        Aml *ej_evt = aml_name("%s.%s", cphp_res_path, CPU_EJECT_EVENT);
 
         aml_append(cpus_dev, aml_name_decl("_HID", aml_string("ACPI0010")));
         aml_append(cpus_dev, aml_name_decl("_CID", aml_eisaid("PNP0A05")));
@@ -308,18 +363,31 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         }
         aml_append(cpus_dev, method);
 
+        method = aml_method(CPU_EJECT_METHOD, 1, AML_SERIALIZED);
+        {
+            Aml *idx = aml_arg(0);
+
+            aml_append(method, aml_acquire(ctrl_lock, 0xFFFF));
+            aml_append(method, aml_store(idx, cpu_selector));
+            aml_append(method, aml_store(one, ej_evt));
+            aml_append(method, aml_release(ctrl_lock));
+        }
+        aml_append(cpus_dev, method);
+
         method = aml_method(CPU_SCAN_METHOD, 0, AML_SERIALIZED);
         {
+            Aml *else_ctx;
             Aml *while_ctx;
             Aml *has_event = aml_local(0);
             Aml *dev_chk = aml_int(1);
+            Aml *eject_req = aml_int(3);
             Aml *next_cpu_cmd = aml_int(CPHP_GET_NEXT_CPU_WITH_EVENT_CMD);
 
             aml_append(method, aml_acquire(ctrl_lock, 0xFFFF));
             aml_append(method, aml_store(one, has_event));
             while_ctx = aml_while(aml_equal(has_event, one));
             {
-                 /* clear loop exit condition, ins_evt check
+                 /* clear loop exit condition, ins_evt/rm_evt checks
                   * will set it to 1 while next_cpu_cmd returns a CPU
                   * with events */
                  aml_append(while_ctx, aml_store(zero, has_event));
@@ -332,6 +400,16 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                      aml_append(ifctx, aml_store(one, has_event));
                  }
                  aml_append(while_ctx, ifctx);
+                 else_ctx = aml_else();
+                 ifctx = aml_if(aml_equal(rm_evt, one));
+                 {
+                     aml_append(ifctx,
+                         aml_call2(CPU_NOTIFY_METHOD, cpu_data, eject_req));
+                     aml_append(ifctx, aml_store(one, rm_evt));
+                     aml_append(ifctx, aml_store(one, has_event));
+                 }
+                 aml_append(else_ctx, ifctx);
+                 aml_append(while_ctx, else_ctx);
             }
             aml_append(method, while_ctx);
             aml_append(method, aml_release(ctrl_lock));
@@ -373,6 +451,10 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                 aml_buffer(madt_buf->len, (uint8_t *)madt_buf->data)));
             g_array_free(madt_buf, true);
 
+            method = aml_method("_EJ0", 1, AML_NOTSERIALIZED);
+            aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
+            aml_append(dev, method);
+
             aml_append(cpus_dev, dev);
         }
     }
hw/acpi/ich9.c +7 -0
index 9a81da8..0abe2ce 100644
@@ -481,6 +481,10 @@ void ich9_pm_device_unplug_request_cb(HotplugHandler *hotplug_dev,
         acpi_memory_unplug_request_cb(hotplug_dev,
                                       &lpc->pm.acpi_memory_hotplug, dev,
                                       errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
+               !lpc->pm.cpu_hotplug_legacy) {
+        acpi_cpu_unplug_request_cb(hotplug_dev, &lpc->pm.cpuhp_state,
+                                   dev, errp);
     } else {
         error_setg(errp, "acpi: device unplug request for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
@@ -495,6 +499,9 @@ void ich9_pm_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
     if (lpc->pm.acpi_memory_hotplug.is_enabled &&
         object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         acpi_memory_unplug_cb(&lpc->pm.acpi_memory_hotplug, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
+               !lpc->pm.cpu_hotplug_legacy) {
+        acpi_cpu_unplug_cb(&lpc->pm.cpuhp_state, dev, errp);
     } else {
         error_setg(errp, "acpi: device unplug for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
hw/acpi/piix4.c +6 -0
index 6d24cb5..8cdc1da 100644
@@ -378,6 +378,9 @@ static void piix4_device_unplug_request_cb(HotplugHandler *hotplug_dev,
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {
         acpi_pcihp_device_unplug_cb(hotplug_dev, &s->acpi_pci_hotplug, dev,
                                     errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
+               !s->cpu_hotplug_legacy) {
+        acpi_cpu_unplug_request_cb(hotplug_dev, &s->cpuhp_state, dev, errp);
     } else {
         error_setg(errp, "acpi: device unplug request for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
@@ -392,6 +395,9 @@ static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev,
     if (s->acpi_memory_hotplug.is_enabled &&
         object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
         acpi_memory_unplug_cb(&s->acpi_memory_hotplug, dev, errp);
+    } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) &&
+               !s->cpu_hotplug_legacy) {
+        acpi_cpu_unplug_cb(&s->cpuhp_state, dev, errp);
     } else {
         error_setg(errp, "acpi: device unplug for not supported device"
                    " type: %s", object_get_typename(OBJECT(dev)));
hw/i386/pc.c +47 -0

65 lines not on this page · raw message

include/hw/acpi/cpu.h +8 -0
index 55c3166..f334221 100644
@@ -21,6 +21,7 @@ typedef struct AcpiCpuStatus {
     struct CPUState *cpu;
     uint64_t arch_id;
     bool is_inserting;
+    bool is_removing;
 } AcpiCpuStatus;
 
 typedef struct CPUHotplugState {
@@ -34,6 +35,13 @@ typedef struct CPUHotplugState {
 void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev,
                       CPUHotplugState *cpu_st, DeviceState *dev, Error **errp);
 
+void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                CPUHotplugState *cpu_st,
+                                DeviceState *dev, Error **errp);
+
+void acpi_cpu_unplug_cb(CPUHotplugState *cpu_st,
+                        DeviceState *dev, Error **errp);
+
 void cpu_hotplug_hw_init(MemoryRegion *as, Object *owner,
                          CPUHotplugState *state, hwaddr base_addr);
 
trace-events +4 -1
index fac1f51..53ad387 100644
@@ -2171,5 +2171,8 @@ cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%"
 cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32
 cpuhp_acpi_write_cmd(uint32_t idx, uint8_t cmd) "idx[0x%"PRIx32"] cmd: 0x%"PRIx8
 cpuhp_acpi_read_cmd_data(uint32_t idx, uint32_t data) "idx[0x%"PRIx32"] data: 0x%"PRIx32
-cpuhp_acpi_cpu_has_events(uint32_t idx, bool ins) "idx[0x%"PRIx32"] inserting: %d"
+cpuhp_acpi_cpu_has_events(uint32_t idx, bool ins, bool rm) "idx[0x%"PRIx32"] inserting: %d, removing: %d"
 cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]"
+cpuhp_acpi_clear_remove_evt(uint32_t idx) "idx[0x%"PRIx32"]"
+cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32
+cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v2 7/10 acpi: cpuhp: add cpu._OST handling

In reply to Igor Mammedov

it adds HW and AML parts for CPU_Device._OST method handling to allow OSPM reports status of hot-(un)plug operation.
And extends QMP command query-acpi-ospm-status to report CPU's OST info along with already reported PC-DIMM devices.

---
 hw/acpi/cpu.c         | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi/ich9.c        |  3 ++
 hw/acpi/piix4.c       |  3 ++
 include/hw/acpi/cpu.h |  4 +++
 qapi-schema.json      |  3 +-
 trace-events          |  2 ++
 6 files changed, 96 insertions(+), 1 deletion(-)
hw/acpi/cpu.c +82 -0
index 483b808..401ac0d 100644
@@ -2,6 +2,7 @@
 #include "hw/boards.h"
 #include "hw/acpi/cpu.h"
 #include "qapi/error.h"
+#include "qapi-event.h"
 #include "trace.h"
 
 #define ACPI_CPU_HOTPLUG_REG_LEN 12
@@ -12,9 +13,42 @@
 
 enum {
     CPHP_GET_NEXT_CPU_WITH_EVENT_CMD = 0,
+    CPHP_OST_EVENT_CMD = 1,
+    CPHP_OST_STATUS_CMD = 2,
     CPHP_CMD_MAX
 };
 
+static ACPIOSTInfo *acpi_cpu_device_status(int idx, AcpiCpuStatus *cdev)
+{
+    ACPIOSTInfo *info = g_new0(ACPIOSTInfo, 1);
+
+    info->slot_type = ACPI_SLOT_TYPE_CPU;
+    info->slot = g_strdup_printf("%d", idx);
+    info->source = cdev->ost_event;
+    info->status = cdev->ost_status;
+    if (cdev->cpu) {
+        DeviceState *dev = DEVICE(cdev->cpu);
+        if (dev->id) {
+            info->device = g_strdup(dev->id);
+            info->has_device = true;
+        }
+    }
+    return info;
+}
+
+void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list)
+{
+    int i;
+
+    for (i = 0; i < cpu_st->dev_count; i++) {
+        ACPIOSTInfoList *elem = g_new0(ACPIOSTInfoList, 1);
+        elem->value = acpi_cpu_device_status(i, &cpu_st->devs[i]);
+        elem->next = NULL;
+        **list = elem;
+        *list = &elem->next;
+    }
+}
+
 static uint64_t cpu_hotplug_rd(void *opaque, hwaddr addr, unsigned size)
 {
     uint64_t val = 0;
@@ -54,6 +88,7 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
 {
     CPUHotplugState *cpu_st = opaque;
     AcpiCpuStatus *cdev;
+    ACPIOSTInfo *info;
 
     assert(cpu_st->dev_count);
 
@@ -112,6 +147,28 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data,
             }
         }
         break;
+    case ACPI_CPU_CMD_DATA_OFFSET_RW:
+        switch (cpu_st->command) {
+        case CPHP_OST_EVENT_CMD: {
+           cdev = &cpu_st->devs[cpu_st->selector];
+           cdev->ost_event = data;
+           trace_cpuhp_acpi_write_ost_ev(cpu_st->selector, cdev->ost_event);
+           break;
+        }
+        case CPHP_OST_STATUS_CMD: {
+           cdev = &cpu_st->devs[cpu_st->selector];
+           cdev->ost_status = data;
+           info = acpi_cpu_device_status(cpu_st->selector, cdev);
+           qapi_event_send_acpi_device_ost(info, &error_abort);
+           qapi_free_ACPIOSTInfo(info);
+           trace_cpuhp_acpi_write_ost_status(cpu_st->selector,
+                                             cdev->ost_status);
+           break;
+        }
+        default:
+           break;
+        }
+        break;
     default:
         break;
     }
@@ -216,6 +273,8 @@ static const VMStateDescription vmstate_cpuhp_sts = {
     .fields      = (VMStateField[]) {
         VMSTATE_BOOL(is_inserting, AcpiCpuStatus),
         VMSTATE_BOOL(is_removing, AcpiCpuStatus),
+        VMSTATE_UINT32(ost_event, AcpiCpuStatus),
+        VMSTATE_UINT32(ost_status, AcpiCpuStatus),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -241,6 +300,7 @@ const VMStateDescription vmstate_cpu_hotplug = {
 #define CPU_SCAN_METHOD   "CSCN"
 #define CPU_NOTIFY_METHOD "CTFY"
 #define CPU_EJECT_METHOD  "CEJ0"
+#define CPU_OST_METHOD    "COST"
 
 #define CPU_ENABLED       "CPEN"
 #define CPU_SELECTOR      "CSEL"
@@ -416,6 +476,22 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         }
         aml_append(cpus_dev, method);
 
+        method = aml_method(CPU_OST_METHOD, 4, AML_SERIALIZED);
+        {
+            Aml *uid = aml_arg(0);
+            Aml *ev_cmd = aml_int(CPHP_OST_EVENT_CMD);
+            Aml *st_cmd = aml_int(CPHP_OST_STATUS_CMD);
+
+            aml_append(method, aml_acquire(ctrl_lock, 0xFFFF));
+            aml_append(method, aml_store(uid, cpu_selector));
+            aml_append(method, aml_store(ev_cmd, cpu_cmd));
+            aml_append(method, aml_store(aml_arg(1), cpu_data));
+            aml_append(method, aml_store(st_cmd, cpu_cmd));
+            aml_append(method, aml_store(aml_arg(2), cpu_data));
+            aml_append(method, aml_release(ctrl_lock));
+        }
+        aml_append(cpus_dev, method);
+
         /* build Processor object for each processor */
         for (i = 0; i < arch_ids->len; i++) {
             Aml *dev;
@@ -455,6 +531,12 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
             aml_append(method, aml_call1(CPU_EJECT_METHOD, uid));
             aml_append(dev, method);
 
+            method = aml_method("_OST", 3, AML_SERIALIZED);
+            aml_append(method,
+                aml_call4(CPU_OST_METHOD, uid, aml_arg(0),
+                          aml_arg(1), aml_arg(2))
+            );
+            aml_append(dev, method);
             aml_append(cpus_dev, dev);
         }
     }
hw/acpi/ich9.c +3 -0
index 0abe2ce..d12cc62 100644
@@ -513,4 +513,7 @@ void ich9_pm_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
     ICH9LPCState *s = ICH9_LPC_DEVICE(adev);
 
     acpi_memory_ospm_status(&s->pm.acpi_memory_hotplug, list);
+    if (!s->pm.cpu_hotplug_legacy) {
+        acpi_cpu_ospm_status(&s->pm.cpuhp_state, list);
+    }
 }
hw/acpi/piix4.c +3 -0
index 8cdc1da..858244a 100644
@@ -616,6 +616,9 @@ static void piix4_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)
     PIIX4PMState *s = PIIX4_PM(adev);
 
     acpi_memory_ospm_status(&s->acpi_memory_hotplug, list);
+    if (!s->cpu_hotplug_legacy) {
+        acpi_cpu_ospm_status(&s->cpuhp_state, list);
+    }
 }
 
 static void piix4_send_gpe(AcpiDeviceIf *adev, AcpiEventStatusBits ev)
include/hw/acpi/cpu.h +4 -0
index f334221..980a83c 100644
@@ -22,6 +22,8 @@ typedef struct AcpiCpuStatus {
     uint64_t arch_id;
     bool is_inserting;
     bool is_removing;
+    uint32_t ost_event;
+    uint32_t ost_status;
 } AcpiCpuStatus;
 
 typedef struct CPUHotplugState {
@@ -54,6 +56,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
                     const char *res_root,
                     const char *event_handler_method);
 
+void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list);
+
 extern const VMStateDescription vmstate_cpu_hotplug;
 #define VMSTATE_CPU_HOTPLUG(cpuhp, state) \
     VMSTATE_STRUCT(cpuhp, state, 1, \
qapi-schema.json +2 -1
index 40b1db4..d9e8c1b 100644
@@ -4079,8 +4079,9 @@
 ## @ACPISlotType
 #
 # @DIMM: memory slot
+# @CPU: logical CPU slot (since 2.7)
 #
-{ 'enum': 'ACPISlotType', 'data': [ 'DIMM' ] }
+{ 'enum': 'ACPISlotType', 'data': [ 'DIMM', 'CPU' ] }
 
 ## @ACPIOSTInfo
 #
trace-events +2 -0
index 53ad387..f4dbedb 100644
@@ -2176,3 +2176,5 @@ cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]"
 cpuhp_acpi_clear_remove_evt(uint32_t idx) "idx[0x%"PRIx32"]"
 cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32
 cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32
+cpuhp_acpi_write_ost_ev(uint32_t slot, uint32_t ev) "idx[0x%"PRIx32"] OST EVENT: 0x%"PRIx32
+cpuhp_acpi_write_ost_status(uint32_t slot, uint32_t st) "idx[0x%"PRIx32"] OST STATUS: 0x%"PRIx32
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v2 8/10 pc: use new CPU hotplug interface since 2.7 machine type

In reply to Igor Mammedov

For compatibility reasons PC/Q35 will start with legacy CPU hotplug interface by default but with new CPU hotplug AML code since 2.7 machine type. That way legacy firmware that doesn't use QEMU generated ACPI tables will be able to continue using legacy CPU hotplug interface.

While new machine type, with firmware supporting QEMU provided ACPI tables, will generate new CPU hotplug AML, which will switch to new CPU hotplug interface when guest OS executes its _INI method on ACPI tables loading.

---
 hw/acpi/cpu.c                 |  9 +++++++++
 hw/acpi/cpu_hotplug.c         | 21 ++++++++++++++++++++-
 hw/acpi/ich9.c                | 33 +++++++++++++++++++++++++++++++++
 hw/acpi/piix4.c               | 32 ++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c          | 12 +++++++++++-
 hw/i386/pc_piix.c             |  2 ++
 hw/i386/pc_q35.c              |  2 ++
 include/hw/acpi/cpu.h         |  1 +
 include/hw/acpi/cpu_hotplug.h |  6 ++++++
 include/hw/i386/pc.h          |  2 ++
 10 files changed, 118 insertions(+), 2 deletions(-)
hw/acpi/cpu.c +9 -0
index 401ac0d..c13b65c 100644
@@ -373,6 +373,15 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         aml_append(field, aml_named_field(CPU_DATA, 32));
         aml_append(cpu_ctrl_dev, field);
 
+        if (opts.has_legacy_cphp) {
+            method = aml_method("_INI", 0, AML_SERIALIZED);
+            /* switch off legacy CPU hotplug HW and use new one,
+             * on reboot system is in new mode and writing 0
+             * in CPU_SELECTOR selects BSP, which is NOP at
+             * the time _INI is called */
+            aml_append(method, aml_store(zero, aml_name(CPU_SELECTOR)));
+            aml_append(cpu_ctrl_dev, method);
+        }
     }
     aml_append(sb_scope, cpu_ctrl_dev);
 
hw/acpi/cpu_hotplug.c +20 -1
index fe75bd9..e19d902 100644
@@ -34,7 +34,15 @@ static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
 static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
                              unsigned int size)
 {
-    /* TODO: implement VCPU removal on guest signal that CPU can be removed */
+    /* firmware never used to write in CPU present bitmap so use
+       this fact as means to switch QEMU into modern CPU hotplug
+       mode by writing 0 at the beginning of legacy CPU bitmap
+     */
+    if (addr == 0 && data == 0) {
+        AcpiCpuHotplug *cpus = opaque;
+        object_property_set_bool(cpus->device, false, "cpu-hotplug-legacy",
+                                 &error_abort);
+    }
 }
 
 static const MemoryRegionOps AcpiCpuHotplug_ops = {
@@ -83,6 +91,17 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
     memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
                           gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
     memory_region_add_subregion(parent, base, &gpe_cpu->io);
+    gpe_cpu->device = owner;
+}
+
+void acpi_switch_to_modern_cphp(AcpiCpuHotplug *gpe_cpu,
+                                CPUHotplugState *cpuhp_state,
+                                uint16_t io_port)
+{
+    MemoryRegion *parent = pci_address_space_io(PCI_DEVICE(gpe_cpu->device));
+
+    memory_region_del_subregion(parent, &gpe_cpu->io);
+    cpu_hotplug_hw_init(parent, gpe_cpu->device, cpuhp_state, io_port);
 }
 
 void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,
hw/acpi/ich9.c +33 -0
index d12cc62..e5a3c18 100644
@@ -189,6 +189,33 @@ static const VMStateDescription vmstate_tco_io_state = {
     }
 };
 
+static bool vmstate_test_use_cpuhp(void *opaque)
+{
+    ICH9LPCPMRegs *s = opaque;
+    return !s->cpu_hotplug_legacy;
+}
+
+static int vmstate_cpuhp_pre_load(void *opaque)
+{
+    ICH9LPCPMRegs *s = opaque;
+    Object *obj = OBJECT(s->gpe_cpu.device);
+    object_property_set_bool(obj, false, "cpu-hotplug-legacy", &error_abort);
+    return 0;
+}
+
+static const VMStateDescription vmstate_cpuhp_state = {
+    .name = "ich9_pm/cpuhp",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .needed = vmstate_test_use_cpuhp,
+    .pre_load = vmstate_cpuhp_pre_load,
+    .fields      = (VMStateField[]) {
+        VMSTATE_CPU_HOTPLUG(cpuhp_state, ICH9LPCPMRegs),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_ich9_pm = {
     .name = "ich9_pm",
     .version_id = 1,
@@ -209,6 +236,7 @@ const VMStateDescription vmstate_ich9_pm = {
     .subsections = (const VMStateDescription*[]) {
         &vmstate_memhp_state,
         &vmstate_tco_io_state,
+        &vmstate_cpuhp_state,
         NULL
     }
 };
@@ -318,6 +346,11 @@ static void ich9_pm_set_cpu_hotplug_legacy(Object *obj, bool value,
 {
     ICH9LPCState *s = ICH9_LPC_DEVICE(obj);
 
+    assert(!value);
+    if (s->pm.cpu_hotplug_legacy && value == false) {
+        acpi_switch_to_modern_cphp(&s->pm.gpe_cpu, &s->pm.cpuhp_state,
+                                   ICH9_CPU_HOTPLUG_IO_BASE);
+    }
     s->pm.cpu_hotplug_legacy = value;
 }
 
hw/acpi/piix4.c +32 -0
index 858244a..2adc246 100644
@@ -276,6 +276,32 @@ static const VMStateDescription vmstate_memhp_state = {
     }
 };
 
+static bool vmstate_test_use_cpuhp(void *opaque)
+{
+    PIIX4PMState *s = opaque;
+    return !s->cpu_hotplug_legacy;
+}
+
+static int vmstate_cpuhp_pre_load(void *opaque)
+{
+    Object *obj = OBJECT(opaque);
+    object_property_set_bool(obj, false, "cpu-hotplug-legacy", &error_abort);
+    return 0;
+}
+
+static const VMStateDescription vmstate_cpuhp_state = {
+    .name = "piix4_pm/cpuhp",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .needed = vmstate_test_use_cpuhp,
+    .pre_load = vmstate_cpuhp_pre_load,
+    .fields      = (VMStateField[]) {
+        VMSTATE_CPU_HOTPLUG(cpuhp_state, PIIX4PMState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 /* qemu-kvm 1.2 uses version 3 but advertised as 2
  * To support incoming qemu-kvm 1.2 migration, change version_id
  * and minimum_version_id to 2 below (which breaks migration from
@@ -310,6 +336,7 @@ static const VMStateDescription vmstate_acpi = {
     },
     .subsections = (const VMStateDescription*[]) {
          &vmstate_memhp_state,
+         &vmstate_cpuhp_state,
          NULL
     }
 };
@@ -585,6 +612,11 @@ static void piix4_set_cpu_hotplug_legacy(Object *obj, bool value, Error **errp)
 {
     PIIX4PMState *s = PIIX4_PM(obj);
 
+    assert(!value);
+    if (s->cpu_hotplug_legacy && value == false) {
+        acpi_switch_to_modern_cphp(&s->gpe_cpu, &s->cpuhp_state,
+                                   PIIX4_CPU_HOTPLUG_IO_BASE);
+    }
     s->cpu_hotplug_legacy = value;
 }
 
hw/i386/acpi-build.c +11 -1
index 3e1afe2..0642cf8 100644
@@ -33,6 +33,7 @@
 #include "hw/timer/hpet.h"
 #include "hw/acpi/acpi-defs.h"
 #include "hw/acpi/acpi.h"
+#include "hw/acpi/cpu.h"
 #include "hw/nvram/fw_cfg.h"
 #include "hw/acpi/bios-linker-loader.h"
 #include "hw/loader.h"
@@ -1883,6 +1884,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
     GPtrArray *mem_ranges = g_ptr_array_new_with_free_func(crs_range_free);
     GPtrArray *io_ranges = g_ptr_array_new_with_free_func(crs_range_free);
     PCMachineState *pcms = PC_MACHINE(machine);
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(machine);
     uint32_t nr_mem = machine->ram_slots;
     int root_bus_limit = 0xFF;
     PCIBus *bus = NULL;
@@ -1938,7 +1940,15 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         build_q35_pci0_int(dsdt);
     }
 
-    build_legacy_cpu_hotplug_aml(dsdt, machine, pm->cpu_hp_io_base);
+    if (pcmc->legacy_cpu_hotplug) {
+        build_legacy_cpu_hotplug_aml(dsdt, machine, pm->cpu_hp_io_base);
+    } else {
+        CPUHotplugFeatures opts = {
+            .apci_1_compatible = true, .has_legacy_cphp = true
+        };
+        build_cpus_aml(dsdt, machine, opts, pm->cpu_hp_io_base,
+                       "\\_SB.PCI0", "\\_GPE._E02");
+    }
     build_memory_hotplug_aml(dsdt, nr_mem, pm->mem_hp_io_base,
                              pm->mem_hp_io_len);
 
hw/i386/pc_piix.c +2 -0
index 53bc968..c7d70af 100644
@@ -445,9 +445,11 @@ DEFINE_I440FX_MACHINE(v2_7, "pc-i440fx-2.7", NULL,
 
 static void pc_i440fx_2_6_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_i440fx_2_7_machine_options(m);
     m->is_default = 0;
     m->alias = NULL;
+    pcmc->legacy_cpu_hotplug = true;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
 }
 
hw/i386/pc_q35.c +2 -0
index e4b541f..97a8835 100644
@@ -294,8 +294,10 @@ DEFINE_Q35_MACHINE(v2_7, "pc-q35-2.7", NULL,
 
 static void pc_q35_2_6_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_2_7_machine_options(m);
     m->alias = NULL;
+    pcmc->legacy_cpu_hotplug = true;
     SET_MACHINE_COMPAT(m, PC_COMPAT_2_6);
 }
 
include/hw/acpi/cpu.h +1 -0
index 980a83c..89ce172 100644
@@ -49,6 +49,7 @@ void cpu_hotplug_hw_init(MemoryRegion *as, Object *owner,
 
 typedef struct CPUHotplugFeatures {
     bool apci_1_compatible;
+    bool has_legacy_cphp;
 } CPUHotplugFeatures;
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
include/hw/acpi/cpu_hotplug.h +6 -0
index 6fef67e..b995ef2 100644
@@ -16,8 +16,10 @@
 #include "hw/acpi/pc-hotplug.h"
 #include "hw/acpi/aml-build.h"
 #include "hw/hotplug.h"
+#include "hw/acpi/cpu.h"
 
 typedef struct AcpiCpuHotplug {
+    Object *device;
     MemoryRegion io;
     uint8_t sts[ACPI_GPE_PROC_LEN];
 } AcpiCpuHotplug;
@@ -28,6 +30,10 @@ void legacy_acpi_cpu_plug_cb(HotplugHandler *hotplug_dev,
 void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
                                   AcpiCpuHotplug *gpe_cpu, uint16_t base);
 
+void acpi_switch_to_modern_cphp(AcpiCpuHotplug *gpe_cpu,
+                                CPUHotplugState *cpuhp_state,
+                                uint16_t io_port);
+
 void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineState *machine,
                                   uint16_t io_base);
 #endif
include/hw/i386/pc.h +2 -0
index 9e23929..884224e 100644
@@ -137,6 +137,8 @@ struct PCMachineClass {
 
     /* TSC rate migration: */
     bool save_tsc_khz;
+    /* generate legacy CPU hotplug AML */
+    bool legacy_cpu_hotplug;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v2 9/10 tests: acpi: add CPU hotplug testcase

In reply to Igor Mammedov

Test with:

    -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
 tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
tests/bios-tables-test.c +28 -0
index 16d11aa..a7abe91 100644
@@ -788,6 +788,32 @@ static void test_acpi_q35_tcg_bridge(void)
     free_test_data(&data);
 }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
 int main(int argc, char *argv[])
 {
     const char *arch = qtest_get_arch();
@@ -804,6 +830,8 @@ int main(int argc, char *argv[])
         qtest_add_func("acpi/piix4/tcg/bridge", test_acpi_piix4_tcg_bridge);
         qtest_add_func("acpi/q35/tcg", test_acpi_q35_tcg);
         qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge);
+        qtest_add_func("acpi/piix4/tcg/cpuhp", test_acpi_piix4_tcg_cphp);
+        qtest_add_func("acpi/q35/tcg/cpuhp", test_acpi_q35_tcg_cphp);
     }
     ret = g_test_run();
     boot_sector_cleanup(disk);
Signature · 1 line
1.8.3.1
Reviewed-by on v2 9/10
#11 lore raw

Re: [Qemu-devel] [PATCH v2 09/10] tests: acpi: add CPU hotplug testcase

Quoted 51 lines · Igor Mammedov

Test with:

     -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
  tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
tests/bios-tables-test.c +26 -0
index 16d11aa..a7abe91 100644
@@ -788,6 +788,32 @@ static void test_acpi_q35_tcg_bridge(void)
      free_test_data(&data);
  }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
  int main(int argc, char *argv[])
  {
      const char *arch = qtest_get_arch();

tests/bios-tables-test.c int main(int argc, char *argv[]) · line 837

Quoted 8 lines
tests/bios-tables-test.c +2 -0
@@ -804,6 +830,8 @@ int main(int argc, char *argv[])
          qtest_add_func("acpi/piix4/tcg/bridge", test_acpi_piix4_tcg_bridge);
          qtest_add_func("acpi/q35/tcg", test_acpi_q35_tcg);
          qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge);
+        qtest_add_func("acpi/piix4/tcg/cpuhp", test_acpi_piix4_tcg_cphp);
+        qtest_add_func("acpi/q35/tcg/cpuhp", test_acpi_q35_tcg_cphp);
      }
      ret = g_test_run();
      boot_sector_cleanup(disk);

It looks good, but did you miss the .cphp variant expected files on purpose?

Thanks,
Marcel

#12 lore raw

Re: [Qemu-devel] [PATCH v2 09/10] tests: acpi: add CPU hotplug testcase

Quoted 57 lines · On Thu, 23 Jun 2016 16:08:38 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 56 lines · Igor Mammedov

Test with:

     -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
  tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
tests/bios-tables-test.c +27 -0
index 16d11aa..a7abe91 100644
@@ -788,6 +788,32 @@ static void test_acpi_q35_tcg_bridge(void)
      free_test_data(&data);
  }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
  int main(int argc, char *argv[])
  {
      const char *arch = qtest_get_arch();
@@ -804,6 +830,8 @@ int main(int argc, char *argv[])
          qtest_add_func("acpi/piix4/tcg/bridge",
 test_acpi_piix4_tcg_bridge); qtest_add_func("acpi/q35/tcg",
 test_acpi_q35_tcg); qtest_add_func("acpi/q35/tcg/bridge",
 test_acpi_q35_tcg_bridge);
+        qtest_add_func("acpi/piix4/tcg/cpuhp",
 test_acpi_piix4_tcg_cphp);
Quoted 8 lines
Quoted 5 lines
tests/bios-tables-test.c +1 -0
+        qtest_add_func("acpi/q35/tcg/cpuhp",
 test_acpi_q35_tcg_cphp); }
      ret = g_test_run();
      boot_sector_cleanup(disk);

It looks good, but did you miss the .cphp variant expected files on purpose?

yes, it was in separate commit and I've dropped it before publishing tree, per Michael's suggestion not to post ACPI tables blobs since he updates them himself.
I can regenerate blob and post it any time as commit on top of this if needed.

Quoted 5 lines

Thanks,
Marcel

Thanks!

#13 lore raw

Re: [Qemu-devel] [PATCH v2 09/10] tests: acpi: add CPU hotplug testcase

Quoted 68 lines · Igor Mammedov
Quoted 57 lines · On Thu, 23 Jun 2016 16:08:38 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 56 lines · Igor Mammedov

Test with:

     -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
  tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
tests/bios-tables-test.c +27 -0
index 16d11aa..a7abe91 100644
@@ -788,6 +788,32 @@ static void test_acpi_q35_tcg_bridge(void)
      free_test_data(&data);
  }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
  int main(int argc, char *argv[])
  {
      const char *arch = qtest_get_arch();
@@ -804,6 +830,8 @@ int main(int argc, char *argv[])
          qtest_add_func("acpi/piix4/tcg/bridge",
 test_acpi_piix4_tcg_bridge); qtest_add_func("acpi/q35/tcg",
 test_acpi_q35_tcg); qtest_add_func("acpi/q35/tcg/bridge",
 test_acpi_q35_tcg_bridge);
+        qtest_add_func("acpi/piix4/tcg/cpuhp",
 test_acpi_piix4_tcg_cphp);
Quoted 8 lines
Quoted 5 lines
tests/bios-tables-test.c +1 -0
+        qtest_add_func("acpi/q35/tcg/cpuhp",
 test_acpi_q35_tcg_cphp); }
      ret = g_test_run();
      boot_sector_cleanup(disk);

It looks good, but did you miss the .cphp variant expected files on purpose?

Quoted 5 lines

yes, it was in separate commit and I've dropped it before publishing tree, per Michael's suggestion not to post ACPI tables blobs since he updates them himself.
I can regenerate blob and post it any time as commit on top of this if needed.

you need to patch the script that updates the blob. I can run it myself but you should mention it in commit log.

Quoted 6 lines
Quoted 5 lines

Thanks,
Marcel

Thanks!

#14 lore raw

Re: [Qemu-devel] [PATCH v2 09/10] tests: acpi: add CPU hotplug testcase

Quoted 69 lines · On Fri, 24 Jun 2016 08:53:25 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 68 lines · Igor Mammedov
Quoted 65 lines · On Thu, 23 Jun 2016 16:08:38 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 58 lines · Igor Mammedov

Test with:

     -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
  tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
tests/bios-tables-test.c +28 -0
index 16d11aa..a7abe91 100644
@@ -788,6 +788,32 @@ static void test_acpi_q35_tcg_bridge(void)
      free_test_data(&data);
  }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
  int main(int argc, char *argv[])
  {
      const char *arch = qtest_get_arch();
@@ -804,6 +830,8 @@ int main(int argc, char *argv[])
          qtest_add_func("acpi/piix4/tcg/bridge",
 test_acpi_piix4_tcg_bridge); qtest_add_func("acpi/q35/tcg",
 test_acpi_q35_tcg); qtest_add_func("acpi/q35/tcg/bridge",
 test_acpi_q35_tcg_bridge);
+        qtest_add_func("acpi/piix4/tcg/cpuhp",
 test_acpi_piix4_tcg_cphp);
+        qtest_add_func("acpi/q35/tcg/cpuhp",
 test_acpi_q35_tcg_cphp); }
Quoted 3 lines
      ret = g_test_run();
      boot_sector_cleanup(disk);

It looks good, but did you miss the .cphp variant expected files on purpose?

Quoted 8 lines
Quoted 5 lines

yes, it was in separate commit and I've dropped it before publishing tree, per Michael's suggestion not to post ACPI tables blobs since he updates them himself.
I can regenerate blob and post it any time as commit on top of this if needed.

you need to patch the script that updates the blob. I can run it myself but you should mention it in commit log.

I guess I've misunderstood.
I'll post extra patch here with blob update.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Thanks,
Marcel

Thanks!

#15 lore raw

Re: [Qemu-devel] [PATCH v2 09/10] tests: acpi: add CPU hotplug testcase

Quoted 78 lines · Igor Mammedov
Quoted 75 lines · On Fri, 24 Jun 2016 08:53:25 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 73 lines · Igor Mammedov
Quoted 57 lines · On Thu, 23 Jun 2016 16:08:38 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 56 lines · Igor Mammedov

Test with:

     -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
  tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
tests/bios-tables-test.c +27 -0
index 16d11aa..a7abe91 100644
@@ -788,6 +788,32 @@ static void test_acpi_q35_tcg_bridge(void)
      free_test_data(&data);
  }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
  int main(int argc, char *argv[])
  {
      const char *arch = qtest_get_arch();
@@ -804,6 +830,8 @@ int main(int argc, char *argv[])
          qtest_add_func("acpi/piix4/tcg/bridge",
 test_acpi_piix4_tcg_bridge); qtest_add_func("acpi/q35/tcg",
 test_acpi_q35_tcg); qtest_add_func("acpi/q35/tcg/bridge",
 test_acpi_q35_tcg_bridge);
+        qtest_add_func("acpi/piix4/tcg/cpuhp",
 test_acpi_piix4_tcg_cphp);
Quoted 8 lines
Quoted 5 lines
tests/bios-tables-test.c +1 -0
+        qtest_add_func("acpi/q35/tcg/cpuhp",
 test_acpi_q35_tcg_cphp); }
      ret = g_test_run();
      boot_sector_cleanup(disk);

It looks good, but did you miss the .cphp variant expected files on purpose?

yes, it was in separate commit and I've dropped it before publishing tree, per Michael's suggestion not to post ACPI tables blobs since he updates them himself.
I can regenerate blob and post it any time as commit on top of this if needed.

Quoted 4 lines
Quoted 2 lines

you need to patch the script that updates the blob. I can run it myself but you should mention it in commit log.

I guess I've misunderstood.
I'll post extra patch here with blob update.

No that's ok, point was to include
tests/acpi-test-data/rebuild-expected-aml.sh
if you add new files.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Thanks,
Marcel

Thanks!

#16 lore raw

Re: [Qemu-devel] [PATCH v2 09/10] tests: acpi: add CPU hotplug testcase

Quoted 79 lines · On Sat, 25 Jun 2016 00:58:14 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 78 lines · Igor Mammedov
Quoted 75 lines · On Fri, 24 Jun 2016 08:53:25 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 73 lines · Igor Mammedov
Quoted 57 lines · On Thu, 23 Jun 2016 16:08:38 +0300 Marcel Apfelbaum <[email protected]> wrote:
Quoted 56 lines · Igor Mammedov

Test with:

     -smp 2,cores=3,sockets=2,maxcpus=6

to capture sparse APIC ID values that default
AMD CPU has in above configuration.

---
  tests/bios-tables-test.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)
tests/bios-tables-test.c +27 -0
index 16d11aa..a7abe91 100644
@@ -788,6 +788,32 @@ static void test_acpi_q35_tcg_bridge(void)
      free_test_data(&data);
  }
 
+static void test_acpi_piix4_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_PC;
+    data.variant = ".cphp";
+    test_acpi_one("-machine accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
+static void test_acpi_q35_tcg_cphp(void)
+{
+    test_data data;
+
+    memset(&data, 0, sizeof(data));
+    data.machine = MACHINE_Q35;
+    data.variant = ".cphp";
+    test_acpi_one("-machine q35,accel=tcg"
+                  " -smp 2,cores=3,sockets=2,maxcpus=6",
+                  &data);
+    free_test_data(&data);
+}
+
  int main(int argc, char *argv[])
  {
      const char *arch = qtest_get_arch();
@@ -804,6 +830,8 @@ int main(int argc, char *argv[])
          qtest_add_func("acpi/piix4/tcg/bridge",
 test_acpi_piix4_tcg_bridge); qtest_add_func("acpi/q35/tcg",
 test_acpi_q35_tcg); qtest_add_func("acpi/q35/tcg/bridge",
 test_acpi_q35_tcg_bridge);
+        qtest_add_func("acpi/piix4/tcg/cpuhp",
 test_acpi_piix4_tcg_cphp);
Quoted 8 lines
Quoted 5 lines
tests/bios-tables-test.c +1 -0
+        qtest_add_func("acpi/q35/tcg/cpuhp",
 test_acpi_q35_tcg_cphp); }
      ret = g_test_run();
      boot_sector_cleanup(disk);

It looks good, but did you miss the .cphp variant expected files on purpose?

yes, it was in separate commit and I've dropped it before publishing tree, per Michael's suggestion not to post ACPI tables blobs since he updates them himself.
I can regenerate blob and post it any time as commit on top of this if needed.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

you need to patch the script that updates the blob. I can run it myself but you should mention it in commit log.

I guess I've misunderstood.
I'll post extra patch here with blob update.

No that's ok, point was

look like I'm still missing point,

Quoted 3 lines

to include
tests/acpi-test-data/rebuild-expected-aml.sh
if you add new files.

what does above mean?

as I see, there aren't any blobs mentioned in rebuild-expected-aml.sh

Anyway I need to respin this patch as it doesn't apply doe conflicts with ipmi patches.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Thanks,
Marcel

Thanks!

#17 lore raw

PATCH v2 10/10 pc: acpi: drop intermediate PCMachineState.node_cpu

In reply to Igor Mammedov

PCMachineState.node_cpu was used for mapping APIC ID
to numa node id as CPU entries in SRAT used to be
built on sparse APIC ID bitmap (up to apic_id_limit). However since commit
5803fce pc: acpi: SRAT: create only valid processor lapic entries
CPU entries in SRAT aren't build using apic bitmap
but using 0..maxcpus index instead which is also used for creating numa_info[x].node_cpu map.
So instead of doing useless intermediate conversion from
1. node by cpu index -> node by apic id

       i.e. numa_info[x].node_cpu -> PCMachineState.node_cpu
  2. apic id -> srat entry PMX
       PCMachineState.node_cpu[apic id] -> PMX value

use numa_info[x].node_cpu map directly like ARM does and do
1. numa_info[x].node_cpu -> PMX value using index in range 0..maxcpus
and drop not necessary PCMachineState.node_cpu and related code.

That also removes the last (not counting legacy hotplug) dependency of ACPI code on apic_id_limit and need to allocate huge sparse PCMachineState.node_cpu array in case of 32-bit APIC IDs.

---
 hw/i386/acpi-build.c | 11 ++++++++---
 hw/i386/pc.c         | 16 +---------------
 include/hw/i386/pc.h |  1 -
 3 files changed, 9 insertions(+), 19 deletions(-)
hw/i386/acpi-build.c +8 -3
index 0642cf8..3f7e9fb 100644
@@ -44,6 +44,7 @@
 #include "hw/acpi/tpm.h"
 #include "sysemu/tpm_backend.h"
 #include "hw/timer/mc146818rtc_regs.h"
+#include "sysemu/numa.h"
 
 /* Supported chipsets: */
 #include "hw/acpi/piix4.h"
@@ -2316,7 +2317,6 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     AcpiSratMemoryAffinity *numamem;
 
     int i;
-    uint64_t curnode;
     int srat_start, numa_start, slots;
     uint64_t mem_len, mem_base, next_base;
     MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -2332,14 +2332,19 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
     srat->reserved1 = cpu_to_le32(1);
 
     for (i = 0; i < apic_ids->len; i++) {
+        int j;
         int apic_id = apic_ids->cpus[i].arch_id;
 
         core = acpi_data_push(table_data, sizeof *core);
         core->type = ACPI_SRAT_PROCESSOR_APIC;
         core->length = sizeof(*core);
         core->local_apic_id = apic_id;
-        curnode = pcms->node_cpu[apic_id];
-        core->proximity_lo = curnode;
+        for (j = 0; j < nb_numa_nodes; j++) {
+            if (test_bit(i, numa_info[j].node_cpu)) {
+                core->proximity_lo = j;
+                break;
+            }
+        }
         memset(core->proximity_hi, 0, 3);
         core->local_sapic_eid = 0;
         core->flags = cpu_to_le32(1);
hw/i386/pc.c +1 -15
index dbfba5c..b8fead3 100644
@@ -1179,7 +1179,7 @@ void pc_machine_done(Notifier *notifier, void *data)
 
 void pc_guest_info_init(PCMachineState *pcms)
 {
-    int i, j;
+    int i;
 
     pcms->apic_xrupt_override = kvm_allows_irq0_override();
     pcms->numa_nodes = nb_numa_nodes;
@@ -1189,20 +1189,6 @@ void pc_guest_info_init(PCMachineState *pcms)
         pcms->node_mem[i] = numa_info[i].node_mem;
     }
 
-    pcms->node_cpu = g_malloc0(pcms->apic_id_limit *
-                                     sizeof *pcms->node_cpu);
-
-    for (i = 0; i < max_cpus; i++) {
-        unsigned int apic_id = x86_cpu_apic_id_from_index(i);
-        assert(apic_id < pcms->apic_id_limit);
-        for (j = 0; j < nb_numa_nodes; j++) {
-            if (test_bit(i, numa_info[j].node_cpu)) {
-                pcms->node_cpu[apic_id] = j;
-                break;
-            }
-        }
-    }
-
     pcms->machine_done.notify = pc_machine_done;
     qemu_add_machine_init_done_notifier(&pcms->machine_done);
 }
include/hw/i386/pc.h +0 -1
index 884224e..948ed0c 100644
@@ -72,7 +72,6 @@ struct PCMachineState {
     /* NUMA information: */
     uint64_t numa_nodes;
     uint64_t *node_mem;
-    uint64_t *node_cpu;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
Signature · 1 line
1.8.3.1
#18 lore raw
In reply to Igor Mammedov

On Thu, 16 Jun 2016 18:55:33 +0200
Igor Mammedov <[email protected]> wrote:

Michael,
Do you think that this series will make into 2.7?

Quoted 112 lines

Changelog:
v1->v2:
- dropped consolidate legacy ACPI CPU hotplug as they are in master
by now
- pc: start with legacy hotplug and let 2.7 machine type and
older to switch inot new hotplug mode. That way legacy BIOS will still work fine as it uses built in ACPI tables and will continue to use legacy CPU hotplug
interface.
- poll for CPU objects with events (insert/remove) instead
of looping over all CPUs to find CPUs with
events.
- drop dynamic PXM support as it could be implemented in static
way at acpi tabels build time. It will be an additional series on top of this.
- resplit patches on basic present CPU support, hot-add and
hot-remove parts
Patches: 1-7: add new CPU hotplug
impl. 8: makes 2.7 machine type to use new AML code
that will switch piix4/ich9 into new mode
+ switching logic with migration glue for piix4/ich9
9: drops the last dependency in ACPI parts on
apic_id_limit sized
map.
RFC->v1:
- drop machine.cpu-hotplug property and leave CPU
hotplug always enabled as it used to
be. (it also simplifies, series a
bit)
- reshuffle/squash some patches to make series
bisectable wrt 'make check'
failures
- add doc comment in qapi
schema
- fix 'make check' error for mips target, disableCPU
hotplug code path in piix4_pm for
mips
- drop some intermediate expected ACPI tables
updates
- replace _MAT method with named buffer
object
Current ACPI interface for CPU hotplug supports hoti-adding only upto 255 CPUs and lacks means to convey additional information needed _OST methods
support. Also being bitmap based with bit position specifying APIC ID it doesn't scale up well for 32-bit APIC IDs that will come with x2APIC
support.
So add another QEMU-guest interface using as model memory-hotplug. New interface will be used since 2.7 machine types and will
support:
- more than 255 CPUs with 32-bit APIC ID
value
- a registers set to communicate OST
information (extendable without breaking IO
layout)
- possible to reuse for ARM's 'virt' machine
type with minimal tweaks (add init for MMIO,
add ACPI hooks on CPU hotplug path, MADT
generation)

Tested with following guests: RHEL7, WS2003EEx64, WS2012R2x64
* unplug is tested only with RHEL7 as Windows doesn't support
it.
* tested that migration works as
well.
git tree for
testing: [email protected]:imammedo/qemu.git modern_cpu_hotplug_v2
viewing:
https://github.com/imammedo/qemu/commits/modern_cpu_hotplug_v2

Igor Mammedov (10):
docs: update ACPI CPU hotplug spec with new protocol
pc: piix4/ich9: add 'cpu-hotplug-legacy' property
acpi: cpuhp: add CPU devices AML with _STA method
pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
acpi: cpuhp: implement hot-add parts of CPU hotplug interface
acpi: cpuhp: implement hot-remove parts of CPU hotplug interface
acpi: cpuhp: add cpu._OST handling
pc: use new CPU hotplug interface since 2.7 machine type
tests: acpi: add CPU hotplug testcase
pc: acpi: drop intermediate PCMachineState.node_cpu

 docs/specs/acpi_cpu_hotplug.txt      |  94 +++++-
 hw/acpi/Makefile.objs                |   1 +
 hw/acpi/cpu.c                        | 561
+++++++++++++++++++++++++++++++++++
hw/acpi/cpu_hotplug.c                |  21 +-
hw/acpi/ich9.c                       |  69 ++++-
hw/acpi/piix4.c                      |  71 ++++-
hw/i386/acpi-build.c                 |  68 +++--
hw/i386/pc.c                         |  63 +++-
hw/i386/pc_piix.c                    |   2 +
hw/i386/pc_q35.c                     |   2 +
hw/isa/lpc_ich9.c                    |   1 +
include/hw/acpi/acpi_dev_interface.h |   7 +
include/hw/acpi/cpu.h                |  67 +++++
include/hw/acpi/cpu_hotplug.h        |   6 +
include/hw/acpi/ich9.h               |   3 +
include/hw/i386/pc.h                 |   8 +-
qapi-schema.json                     |   3 +-
stubs/Makefile.objs                  |   1 +
stubs/pc_madt_cpu_entry.c            |   7 +
tests/bios-tables-test.c             |  28 ++
trace-events                         |  14 + 21 files changed, 1043
insertions(+), 54 deletions(-) create mode 100644 hw/acpi/cpu.c
 create mode 100644 include/hw/acpi/cpu.h
 create mode 100644 stubs/pc_madt_cpu_entry.c
#19 lore raw
Quoted 5 lines · Igor Mammedov

On Thu, 16 Jun 2016 18:55:33 +0200
Igor Mammedov <[email protected]> wrote:

Michael,
Do you think that this series will make into 2.7?

Yes, I think it will. I'll try to prioritize review.

Quoted 113 lines
Quoted 112 lines

Changelog:
v1->v2:
- dropped consolidate legacy ACPI CPU hotplug as they are in master
by now
- pc: start with legacy hotplug and let 2.7 machine type and
older to switch inot new hotplug mode. That way legacy BIOS will still work fine as it uses built in ACPI tables and will continue to use legacy CPU hotplug
interface.
- poll for CPU objects with events (insert/remove) instead
of looping over all CPUs to find CPUs with
events.
- drop dynamic PXM support as it could be implemented in static
way at acpi tabels build time. It will be an additional series on top of this.
- resplit patches on basic present CPU support, hot-add and
hot-remove parts
Patches: 1-7: add new CPU hotplug
impl. 8: makes 2.7 machine type to use new AML code
that will switch piix4/ich9 into new mode
+ switching logic with migration glue for piix4/ich9
9: drops the last dependency in ACPI parts on
apic_id_limit sized
map.
RFC->v1:
- drop machine.cpu-hotplug property and leave CPU
hotplug always enabled as it used to
be. (it also simplifies, series a
bit)
- reshuffle/squash some patches to make series
bisectable wrt 'make check'
failures
- add doc comment in qapi
schema
- fix 'make check' error for mips target, disableCPU
hotplug code path in piix4_pm for
mips
- drop some intermediate expected ACPI tables
updates
- replace _MAT method with named buffer
object
Current ACPI interface for CPU hotplug supports hoti-adding only upto 255 CPUs and lacks means to convey additional information needed _OST methods
support. Also being bitmap based with bit position specifying APIC ID it doesn't scale up well for 32-bit APIC IDs that will come with x2APIC
support.
So add another QEMU-guest interface using as model memory-hotplug. New interface will be used since 2.7 machine types and will
support:
- more than 255 CPUs with 32-bit APIC ID
value
- a registers set to communicate OST
information (extendable without breaking IO
layout)
- possible to reuse for ARM's 'virt' machine
type with minimal tweaks (add init for MMIO,
add ACPI hooks on CPU hotplug path, MADT
generation)

Tested with following guests: RHEL7, WS2003EEx64, WS2012R2x64
* unplug is tested only with RHEL7 as Windows doesn't support
it.
* tested that migration works as
well.
git tree for
testing: [email protected]:imammedo/qemu.git modern_cpu_hotplug_v2
viewing:
https://github.com/imammedo/qemu/commits/modern_cpu_hotplug_v2

Igor Mammedov (10):
docs: update ACPI CPU hotplug spec with new protocol
pc: piix4/ich9: add 'cpu-hotplug-legacy' property
acpi: cpuhp: add CPU devices AML with _STA method
pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
acpi: cpuhp: implement hot-add parts of CPU hotplug interface
acpi: cpuhp: implement hot-remove parts of CPU hotplug interface
acpi: cpuhp: add cpu._OST handling
pc: use new CPU hotplug interface since 2.7 machine type
tests: acpi: add CPU hotplug testcase
pc: acpi: drop intermediate PCMachineState.node_cpu

 docs/specs/acpi_cpu_hotplug.txt      |  94 +++++-
 hw/acpi/Makefile.objs                |   1 +
 hw/acpi/cpu.c                        | 561
+++++++++++++++++++++++++++++++++++
hw/acpi/cpu_hotplug.c                |  21 +-
hw/acpi/ich9.c                       |  69 ++++-
hw/acpi/piix4.c                      |  71 ++++-
hw/i386/acpi-build.c                 |  68 +++--
hw/i386/pc.c                         |  63 +++-
hw/i386/pc_piix.c                    |   2 +
hw/i386/pc_q35.c                     |   2 +
hw/isa/lpc_ich9.c                    |   1 +
include/hw/acpi/acpi_dev_interface.h |   7 +
include/hw/acpi/cpu.h                |  67 +++++
include/hw/acpi/cpu_hotplug.h        |   6 +
include/hw/acpi/ich9.h               |   3 +
include/hw/i386/pc.h                 |   8 +-
qapi-schema.json                     |   3 +-
stubs/Makefile.objs                  |   1 +
stubs/pc_madt_cpu_entry.c            |   7 +
tests/bios-tables-test.c             |  28 ++
trace-events                         |  14 + 21 files changed, 1043
insertions(+), 54 deletions(-) create mode 100644 hw/acpi/cpu.c
 create mode 100644 include/hw/acpi/cpu.h
 create mode 100644 stubs/pc_madt_cpu_entry.c
#20 lore raw
Quoted 8 lines · On Tue, 21 Jun 2016 19:50:14 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov

On Thu, 16 Jun 2016 18:55:33 +0200
Igor Mammedov <[email protected]> wrote:

Michael,
Do you think that this series will make into 2.7?

Yes, I think it will. I'll try to prioritize review.

Thanks,

then I'll try to post dependent x2APIC and 'device-add cpu' series ASAP.

Quoted 114 lines
Quoted 114 lines
Quoted 113 lines

Changelog:
v1->v2:
- dropped consolidate legacy ACPI CPU hotplug as they are in
master by now
- pc: start with legacy hotplug and let 2.7 machine type and
older to switch inot new hotplug mode. That way legacy BIOS will still work fine as it uses built in ACPI tables and will continue to use legacy CPU hotplug
interface.
- poll for CPU objects with events (insert/remove) instead
of looping over all CPUs to find CPUs with
events.
- drop dynamic PXM support as it could be implemented in static
way at acpi tabels build time. It will be an additional series on top of this.
- resplit patches on basic present CPU support, hot-add and
hot-remove parts
Patches: 1-7: add new CPU hotplug
impl. 8: makes 2.7 machine type to use new AML code that will switch piix4/ich9 into new mode
+ switching logic with migration glue for
piix4/ich9 9: drops the last dependency in ACPI parts on apic_id_limit sized
map.
RFC->v1:
- drop machine.cpu-hotplug property and leave CPU
hotplug always enabled as it used to
be. (it also simplifies, series a
bit)
- reshuffle/squash some patches to make series
bisectable wrt 'make check'
failures
- add doc comment in qapi
schema
- fix 'make check' error for mips target, disableCPU
hotplug code path in piix4_pm for
mips
- drop some intermediate expected ACPI tables
updates
- replace _MAT method with named buffer
object
Current ACPI interface for CPU hotplug supports hoti-adding only upto 255 CPUs and lacks means to convey additional information needed _OST methods
support. Also being bitmap based with bit position specifying APIC ID it doesn't scale up well for 32-bit APIC IDs that will come with x2APIC
support.
So add another QEMU-guest interface using as model memory-hotplug. New interface will be used since 2.7 machine types and will
support:
- more than 255 CPUs with 32-bit APIC ID
value
- a registers set to communicate OST
information (extendable without breaking IO
layout)
- possible to reuse for ARM's 'virt' machine
type with minimal tweaks (add init for MMIO,
add ACPI hooks on CPU hotplug path, MADT
generation)

Tested with following guests: RHEL7, WS2003EEx64, WS2012R2x64
* unplug is tested only with RHEL7 as Windows doesn't support
it.
* tested that migration works as
well.
git tree for
testing: [email protected]:imammedo/qemu.git modern_cpu_hotplug_v2
viewing:
https://github.com/imammedo/qemu/commits/modern_cpu_hotplug_v2

Igor Mammedov (10):
docs: update ACPI CPU hotplug spec with new protocol
pc: piix4/ich9: add 'cpu-hotplug-legacy' property
acpi: cpuhp: add CPU devices AML with _STA method
pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
acpi: cpuhp: implement hot-add parts of CPU hotplug interface
acpi: cpuhp: implement hot-remove parts of CPU hotplug interface
acpi: cpuhp: add cpu._OST handling
pc: use new CPU hotplug interface since 2.7 machine type
tests: acpi: add CPU hotplug testcase
pc: acpi: drop intermediate PCMachineState.node_cpu

 docs/specs/acpi_cpu_hotplug.txt      |  94 +++++-
 hw/acpi/Makefile.objs                |   1 +
 hw/acpi/cpu.c                        | 561
+++++++++++++++++++++++++++++++++++
hw/acpi/cpu_hotplug.c                |  21 +-
hw/acpi/ich9.c                       |  69 ++++-
hw/acpi/piix4.c                      |  71 ++++-
hw/i386/acpi-build.c                 |  68 +++--
hw/i386/pc.c                         |  63 +++-
hw/i386/pc_piix.c                    |   2 +
hw/i386/pc_q35.c                     |   2 +
hw/isa/lpc_ich9.c                    |   1 +
include/hw/acpi/acpi_dev_interface.h |   7 +
include/hw/acpi/cpu.h                |  67 +++++
include/hw/acpi/cpu_hotplug.h        |   6 +
include/hw/acpi/ich9.h               |   3 +
include/hw/i386/pc.h                 |   8 +-
qapi-schema.json                     |   3 +-
stubs/Makefile.objs                  |   1 +
stubs/pc_madt_cpu_entry.c            |   7 +
tests/bios-tables-test.c             |  28 ++
trace-events                         |  14 + 21 files changed,
1043 insertions(+), 54 deletions(-) create mode 100644
hw/acpi/cpu.c create mode 100644 include/hw/acpi/cpu.h
 create mode 100644 stubs/pc_madt_cpu_entry.c
#21 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · On Tue, 21 Jun 2016 19:50:14 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov

On Thu, 16 Jun 2016 18:55:33 +0200
Igor Mammedov <[email protected]> wrote:

Michael,
Do you think that this series will make into 2.7?

Yes, I think it will. I'll try to prioritize review.

Michael,

v2 no longer applies to master cleanly due to trivial conflicts because of trace-events file split. I've rebased it on top of current master so you can fetch series with resolved conflicts from following tree:

https://github.com/imammedo/qemu.git modern_cpu_hotplug_v3

Quoted 115 lines
Quoted 114 lines
Quoted 113 lines

Changelog:
v1->v2:
- dropped consolidate legacy ACPI CPU hotplug as they are in
master by now
- pc: start with legacy hotplug and let 2.7 machine type and
older to switch inot new hotplug mode. That way legacy BIOS will still work fine as it uses built in ACPI tables and will continue to use legacy CPU hotplug
interface.
- poll for CPU objects with events (insert/remove) instead
of looping over all CPUs to find CPUs with
events.
- drop dynamic PXM support as it could be implemented in static
way at acpi tabels build time. It will be an additional series on top of this.
- resplit patches on basic present CPU support, hot-add and
hot-remove parts
Patches: 1-7: add new CPU hotplug
impl. 8: makes 2.7 machine type to use new AML code that will switch piix4/ich9 into new mode
+ switching logic with migration glue for
piix4/ich9 9: drops the last dependency in ACPI parts on apic_id_limit sized
map.
RFC->v1:
- drop machine.cpu-hotplug property and leave CPU
hotplug always enabled as it used to
be. (it also simplifies, series a
bit)
- reshuffle/squash some patches to make series
bisectable wrt 'make check'
failures
- add doc comment in qapi
schema
- fix 'make check' error for mips target, disableCPU
hotplug code path in piix4_pm for
mips
- drop some intermediate expected ACPI tables
updates
- replace _MAT method with named buffer
object
Current ACPI interface for CPU hotplug supports hoti-adding only upto 255 CPUs and lacks means to convey additional information needed _OST methods
support. Also being bitmap based with bit position specifying APIC ID it doesn't scale up well for 32-bit APIC IDs that will come with x2APIC
support.
So add another QEMU-guest interface using as model memory-hotplug. New interface will be used since 2.7 machine types and will
support:
- more than 255 CPUs with 32-bit APIC ID
value
- a registers set to communicate OST
information (extendable without breaking IO
layout)
- possible to reuse for ARM's 'virt' machine
type with minimal tweaks (add init for MMIO,
add ACPI hooks on CPU hotplug path, MADT
generation)

Tested with following guests: RHEL7, WS2003EEx64, WS2012R2x64
* unplug is tested only with RHEL7 as Windows doesn't support
it.
* tested that migration works as
well.
git tree for
testing: [email protected]:imammedo/qemu.git modern_cpu_hotplug_v2
viewing:
https://github.com/imammedo/qemu/commits/modern_cpu_hotplug_v2

Igor Mammedov (10):
docs: update ACPI CPU hotplug spec with new protocol
pc: piix4/ich9: add 'cpu-hotplug-legacy' property
acpi: cpuhp: add CPU devices AML with _STA method
pc: acpi: introduce AcpiDeviceIfClass.madt_cpu hook
acpi: cpuhp: implement hot-add parts of CPU hotplug interface
acpi: cpuhp: implement hot-remove parts of CPU hotplug interface
acpi: cpuhp: add cpu._OST handling
pc: use new CPU hotplug interface since 2.7 machine type
tests: acpi: add CPU hotplug testcase
pc: acpi: drop intermediate PCMachineState.node_cpu

 docs/specs/acpi_cpu_hotplug.txt      |  94 +++++-
 hw/acpi/Makefile.objs                |   1 +
 hw/acpi/cpu.c                        | 561
+++++++++++++++++++++++++++++++++++
hw/acpi/cpu_hotplug.c                |  21 +-
hw/acpi/ich9.c                       |  69 ++++-
hw/acpi/piix4.c                      |  71 ++++-
hw/i386/acpi-build.c                 |  68 +++--
hw/i386/pc.c                         |  63 +++-
hw/i386/pc_piix.c                    |   2 +
hw/i386/pc_q35.c                     |   2 +
hw/isa/lpc_ich9.c                    |   1 +
include/hw/acpi/acpi_dev_interface.h |   7 +
include/hw/acpi/cpu.h                |  67 +++++
include/hw/acpi/cpu_hotplug.h        |   6 +
include/hw/acpi/ich9.h               |   3 +
include/hw/i386/pc.h                 |   8 +-
qapi-schema.json                     |   3 +-
stubs/Makefile.objs                  |   1 +
stubs/pc_madt_cpu_entry.c            |   7 +
tests/bios-tables-test.c             |  28 ++
trace-events                         |  14 + 21 files changed,
1043 insertions(+), 54 deletions(-) create mode 100644
hw/acpi/cpu.c create mode 100644 include/hw/acpi/cpu.h
 create mode 100644 stubs/pc_madt_cpu_entry.c
#22 lore raw

[Qemu-devel] [PATCH v2 11/10] pc: acpi: update expected DSDT blobs with new CPU hotplug AML

In reply to Igor Mammedov
---
 tests/acpi-test-data/pc/DSDT         | Bin 5503 -> 6008 bytes
 tests/acpi-test-data/pc/DSDT.bridge  | Bin 7362 -> 7867 bytes
 tests/acpi-test-data/q35/DSDT        | Bin 8265 -> 8770 bytes
 tests/acpi-test-data/q35/DSDT.bridge | Bin 8282 -> 8787 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/pc/DSDT binary +0 -0
index 8b4f1a09b87f8361fb572022f69d304ddeeace99..8053d711058c0f9541d6d97690819f9de697751c 100644
GIT binary patch
tests/acpi-test-data/pc/DSDT.bridge binary +0 -0
index 0d09b5cc61114b68fee0f14729732786854b19fe..850e71a973e52cc5e546fdd2757f0e089fed7192 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT binary +0 -0
index 67445428d935bd6ea5957526089ba7e719a1783a..58fbb3d2e2dc8e8256984744bfb9411feb2e35fe 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT.bridge binary +0 -0
index e85f5b1af9fcd36c9522b05e0085af84d6c010cb..c392802a95cb5690c6719b7909c9f8fa2213e503 100644
GIT binary patch
Signature · 1 line
1.8.3.1
#23 lore raw

[Qemu-devel] [PATCH v2 12/10] pc: acpi: add expected DSDT/MADT blobs for CPU hotplug testscase

---
 tests/acpi-test-data/pc/APIC.cphp  | Bin 0 -> 160 bytes
 tests/acpi-test-data/pc/DSDT.cphp  | Bin 0 -> 6435 bytes
 tests/acpi-test-data/q35/APIC.cphp | Bin 0 -> 160 bytes
 tests/acpi-test-data/q35/DSDT.cphp | Bin 0 -> 9197 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/APIC.cphp
 create mode 100644 tests/acpi-test-data/pc/DSDT.cphp
 create mode 100644 tests/acpi-test-data/q35/APIC.cphp
 create mode 100644 tests/acpi-test-data/q35/DSDT.cphp
tests/acpi-test-data/pc/APIC.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1bf8a0a63bc1c9b716d937b96eb34b05016b9366
GIT binary patch
tests/acpi-test-data/pc/DSDT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..e8b146208eb3877e1cde2cc361c5afd270d194c6
GIT binary patch
tests/acpi-test-data/q35/APIC.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..1bf8a0a63bc1c9b716d937b96eb34b05016b9366
GIT binary patch
tests/acpi-test-data/q35/DSDT.cphp new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..6cc28c6daec2b331030ab0600a4d79034c1dfc40
GIT binary patch
Signature · 1 line
1.8.3.1