Skip to contentSkip to conversation

hw/acpi: bump MADT to revision 5

PATCH Superseded Eric DeVolder 4 participants 22 messages Mar 28, 2023 – Apr 18, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover hw/acpi: bump MADT to revision 5

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

As part of the investigation into resolving this breakage, I learned that i386 QEMU reports revision 1, while technically it is at revision 3. (Arm QEMU reports revision 4, and that is valid/correct.)

ACPI 6.3 bumps MADT revision to 5 as it introduces an Online Capable flag that the above Linux patch utilizes to denote hot pluggable CPUs.

So in order to bump MADT to the current revision of 5, need to validate that all MADT table changes between 1 and 5 are present in QEMU.

Below is a table summarizing the changes to the MADT. This information gleamed from the ACPI specs on uefi.org.

ACPI MADT What
Version Version

1.0             MADT not present
2.0     1       Section 5.2.10.4
3.0     2       Section 5.2.11.4

5.2.11.13 Local SAPIC Structure added two new fields:
ACPI Processor UID Value
ACPI Processor UID String
5.2.10.14 Platform Interrupt Sources Structure:
Reserved changed to Platform Interrupt Sources Flags
3.0b 2 Section 5.2.11.4
Added a section describing guidelines for the ordering of processors in the MADT to support proper boot processor and multi-threaded logical processor operation.
4.0 3 Section 5.2.12
Adds Processor Local x2APIC structure type 9 Adds Local x2APIC NMI structure type 0xA

5.0     3       Section 5.2.12
6.0     3       Section 5.2.12
6.0a    4       Section 5.2.12
                 Adds ARM GIC structure types 0xB-0xF
6.2a    45      Section 5.2.12   <--- yep it says version 45!
6.2b    5       Section 5.2.12

GIC ITS last Reserved offset changed to 16 from 20 (typo)
6.3 5 Section 5.2.12
Adds Local APIC Flags Online Capable!
Adds GICC SPE Overflow Interrupt field
6.4 5 Section 5.2.12
Adds Multiprocessor Wakeup Structure type 0x10 (change notes says structure previously misplaced?)
6.5 5 Section 5.2.12

For the MADT revision change 1 -> 2, the spec has a change to the SAPIC structure. In general, QEMU does not generate/support SAPIC. So the QEMU i386 MADT revision can safely be moved to 2.

For the MADT revision change 2 -> 3, the spec adds Local x2APIC structures. QEMU has long supported x2apic ACPI structures. A simple search of x2apic within QEMU source and hw/i386/acpi-common.c specifically reveals this. So the QEMU i386 MADT revision can safely be moved to 3.

For the MADT revision change 3 -> 4, the spec adds support for the ARM GIC structures. QEMU ARM does in fact generate and report revision 4. As these will not be used by i386 QEMU, so then the QEMU i386 MADT revision can safely be moved to 4 as well.

Now for the MADT revision change 4 -> 5, the spec adds the Online Capable flag to the Local APIC structure, and the ARM GICC SPE Overflow Interrupt field.

For the ARM SPE, an existing 3-byte Reserved field is broken into a 1- byte Reserved field and a 2-byte SPE field. The spec says that is SPE Overflow is not supported, it should be zero.

For the i386 Local APIC flag Online Capable, the spec has certain rules about this value. And in particuar setting this value now explicitly indicates a hotpluggable CPU.

So this patch makes the needed changes to move both ARM and i386 MADT to revision 5. These are not complicated, thankfully.

Without these changes, the information below shows "how" CPU hotplug breaks with the current upstream Linux kernel 6.3. For example, a Linux guest started with:

qemu-system-x86_64 -smp 30,maxcpus=32 ...

and then attempting to hotplug a CPU:

(QEMU) device_add id=cpu30 driver=host-x86_64-cpu socket-id=0 core-id=30 thread-id=0

fails with the following:

APIC: NR_CPUS/possible_cpus limit of 30 reached. Processor 30/0x.
ACPI: Unable to map lapic to logical cpu number
acpi LNXCPU:1e: Enumeration failure

  # dmesg | grep smpboot
  smpboot: Allowing 30 CPUs, 0 hotplug CPUs
  smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x)
  smpboot: Max logical packages: 1
  smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
  # iasl -d /sys/firmware/tables/acpi/APIC
  [000h 0000   4]                    Signature : "APIC"    [Multiple APIC Descript
  [004h 0004   4]                 Table Length : 00000170
  [008h 0008   1]                     Revision : 01          <=====
  [009h 0009   1]                     Checksum : 9C
  [00Ah 0010   6]                       Oem ID : "BOCHS "
  [010h 0016   8]                 Oem Table ID : "BXPC    "
  [018h 0024   4]                 Oem Revision : 00000001
  [01Ch 0028   4]              Asl Compiler ID : "BXPC"
  [020h 0032   4]        Asl Compiler Revision : 00000001

...

  [114h 0276   1]                Subtable Type : 00 [Processor Local APIC]
  [115h 0277   1]                       Length : 08
  [116h 0278   1]                 Processor ID : 1D
  [117h 0279   1]                Local Apic ID : 1D
  [118h 0280   4]        Flags (decoded below) : 00000001
                             Processor Enabled : 1          <=====
  [11Ch 0284   1]                Subtable Type : 00 [Processor Local APIC]
  [11Dh 0285   1]                       Length : 08
  [11Eh 0286   1]                 Processor ID : 1E
  [11Fh 0287   1]                Local Apic ID : 1E
  [120h 0288   4]        Flags (decoded below) : 00000000
                             Processor Enabled : 0          <=====
  [124h 0292   1]                Subtable Type : 00 [Processor Local APIC]
  [125h 0293   1]                       Length : 08
  [126h 0294   1]                 Processor ID : 1F
  [127h 0295   1]                Local Apic ID : 1F
  [128h 0296   4]        Flags (decoded below) : 00000000
                             Processor Enabled : 0          <=====

The (latest upstream) Linux kernel sees 30 Enabled processors, and does not consider processors 31 and 32 to be hotpluggable.

With this patch series applied, by bumping MADT to revision 5, the latest upstream Linux kernel correctly identifies 30 CPUs plus 2 hotpluggable CPUS.

CPU30 has been hot-added
smpboot: Booting Node 0 Processor 30 APIC 0x1e
Will online and init hotplugged CPU: 30

  # dmesg | grep smpboot
  smpboot: Allowing 32 CPUs, 2 hotplug CPUs
  smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x6, model: 0x56, stepping: 0x3)
  smpboot: Max logical packages: 2
  smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
  # iasl -d /sys/firmware/tables/acpi/APIC
  [000h 0000 004h]                   Signature : "APIC"    [Multiple APIC Descript
  [004h 0004 004h]                Table Length : 00000170
  [008h 0008 001h]                    Revision : 05          <=====
  [009h 0009 001h]                    Checksum : 94
  [00Ah 0010 006h]                      Oem ID : "BOCHS "
  [010h 0016 008h]                Oem Table ID : "BXPC    "
  [018h 0024 004h]                Oem Revision : 00000001
  [01Ch 0028 004h]             Asl Compiler ID : "BXPC"
  [020h 0032 004h]       Asl Compiler Revision : 00000001

...

[114h 0276 001h] Subtable Type : 00 [Processor Local APIC]
[115h 0277 001h] Length : 08
[116h 0278 001h] Processor ID : 1D
[117h 0279 001h] Local Apic ID : 1D
[118h 0280 004h] Flags (decoded below) : 00000001

                             Processor Enabled : 1          <=====
                        Runtime Online Capable : 0          <=====

[11Ch 0284 001h] Subtable Type : 00 [Processor Local APIC]
[11Dh 0285 001h] Length : 08
[11Eh 0286 001h] Processor ID : 1E
[11Fh 0287 001h] Local Apic ID : 1E
[120h 0288 004h] Flags (decoded below) : 00000002

                             Processor Enabled : 0          <=====
                        Runtime Online Capable : 1          <=====

[124h 0292 001h] Subtable Type : 00 [Processor Local APIC]
[125h 0293 001h] Length : 08
[126h 0294 001h] Processor ID : 1F
[127h 0295 001h] Local Apic ID : 1F
[128h 0296 004h] Flags (decoded below) : 00000002

                             Processor Enabled : 0          <=====
                        Runtime Online Capable : 1          <=====

Regards,
Eric

Eric DeVolder (2):
hw/acpi: arm: bump MADT to revision 5
hw/acpi: i386: bump MADT to revision 5

 hw/arm/virt-acpi-build.c |  6 ++++--
 hw/i386/acpi-common.c    | 13 ++++++++++---
 2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/2 hw/acpi: arm: bump MADT to revision 5

Currently ARM QEMU generates, and reports, MADT revision 4. ACPI 6.3 introduces MADT revision 5.

For MADT revision 5, the GICC structure adds an SPE Overflow Interrupt field. This new 2-byte field is created from the existing 3-byte Reserved field. The spec indicates if the SPE overflow interrupt is not supported, to zero the field.

---
 hw/arm/virt-acpi-build.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/arm/virt-acpi-build.c +4 -2
index 4156111d49..23268dd981 100644
@@ -705,7 +705,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     int i;
     VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
     const MemMapEntry *memmap = vms->memmap;
-    AcpiTable table = { .sig = "APIC", .rev = 4, .oem_id = vms->oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = vms->oem_id,
                         .oem_table_id = vms->oem_table_id };
 
     acpi_table_begin(&table, table_data);
@@ -763,7 +763,9 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
         /* Processor Power Efficiency Class */
         build_append_int_noprefix(table_data, 0, 1);
         /* Reserved */
-        build_append_int_noprefix(table_data, 0, 3);
+        build_append_int_noprefix(table_data, 0, 1);
+        /* SPE overflow Interrupt */
+        build_append_int_noprefix(table_data, 0, 2);
     }
 
     if (vms->gic_version != VIRT_GIC_VERSION_2) {
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 1/2] hw/acpi: arm: bump MADT to revision 5

Quoted 9 lines · On Tue, 28 Mar 2023 11:59:25 -0400 Eric DeVolder <[email protected]>…

Currently ARM QEMU generates, and reports, MADT revision 4. ACPI 6.3 introduces MADT revision 5.

For MADT revision 5, the GICC structure adds an SPE Overflow Interrupt field. This new 2-byte field is created from the existing 3-byte Reserved field. The spec indicates if the SPE overflow interrupt is not supported, to zero the field.

needs ACK from ARM folks

Quoted 28 lines
---
 hw/arm/virt-acpi-build.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/arm/virt-acpi-build.c +4 -2
index 4156111d49..23268dd981 100644
@@ -705,7 +705,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     int i;
     VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
     const MemMapEntry *memmap = vms->memmap;
-    AcpiTable table = { .sig = "APIC", .rev = 4, .oem_id = vms->oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = vms->oem_id,
                         .oem_table_id = vms->oem_table_id };
 
     acpi_table_begin(&table, table_data);
@@ -763,7 +763,9 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
         /* Processor Power Efficiency Class */
         build_append_int_noprefix(table_data, 0, 1);
         /* Reserved */
-        build_append_int_noprefix(table_data, 0, 3);
+        build_append_int_noprefix(table_data, 0, 1);
+        /* SPE overflow Interrupt */
+        build_append_int_noprefix(table_data, 0, 2);
     }
 
     if (vms->gic_version != VIRT_GIC_VERSION_2) {
#3 lore raw

PATCH 2/2 hw/acpi: i386: bump MADT to revision 5

In reply to Eric DeVolder

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

---
 hw/i386/acpi-common.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +10 -3
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
 {
     uint32_t apic_id = apic_ids->cpus[uid].arch_id;
     /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;
 
     /* ACPI spec says that LAPIC entry for non present
      * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
     MachineClass *mc = MACHINE_GET_CLASS(x86ms);
     const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
     AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                         .oem_table_id = oem_table_id };
 
     acpi_table_begin(&table, table_data);
Signature · 1 line
2.31.1
#4 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

Quoted 6 lines · Eric DeVolder

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

Quoted 7 lines

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

I am looking for ways to reduce risk of breakage with this. We don't currently have a reason to change it if cpu hotplug is off, do we? Maybe make it conditional on that.

Quoted 40 lines
---
 hw/i386/acpi-common.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +10 -3
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
 {
     uint32_t apic_id = apic_ids->cpus[uid].arch_id;
     /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;
 
     /* ACPI spec says that LAPIC entry for non present
      * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
     MachineClass *mc = MACHINE_GET_CLASS(x86ms);
     const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
     AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                         .oem_table_id = oem_table_id };
 
     acpi_table_begin(&table, table_data);
Signature · 1 line
2.31.1
#5 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Eric DeVolder

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Quoted 8 lines
Quoted 4 lines

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

I am looking for ways to reduce risk of breakage with this. We don't currently have a reason to change it if cpu hotplug is off, do we? Maybe make it conditional on that.

By "cpu hotplug off", do you mean, for example, no maxcpus= option? In other words, how should I detect "cpu hotplug off"? eric

Quoted 46 lines
Quoted 45 lines




---
  hw/i386/acpi-common.c | 13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +10 -3
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
  {
      uint32_t apic_id = apic_ids->cpus[uid].arch_id;
      /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;
 
      /* ACPI spec says that LAPIC entry for non present
       * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
      MachineClass *mc = MACHINE_GET_CLASS(x86ms);
      const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
      AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                          .oem_table_id = oem_table_id };
 
      acpi_table_begin(&table, table_data);
Signature · 1 line
2.31.1
#6 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

Quoted 18 lines · Eric DeVolder
Quoted 15 lines · Michael S. Tsirkin
Quoted 13 lines · Eric DeVolder

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

Quoted 8 lines
Quoted 3 lines

I am looking for ways to reduce risk of breakage with this. We don't currently have a reason to change it if cpu hotplug is off, do we? Maybe make it conditional on that.

By "cpu hotplug off", do you mean, for example, no maxcpus= option? In other words, how should I detect "cpu hotplug off"? eric

Actually, if, for example, one had -smp 30,maxcpus=32, then there would be two hotpluggable cpus reported, the last two with the Enabled=0 and Online Capable=1. If one had -smp 32 (ie "cpu hotplug off"), then all cpus would be reported as Enabled and no cpu would have its Online Capable flag set.

Granted in both cases, MADT.revision would report 5, but it would still be accurate.

eric

Quoted 44 lines
Quoted 44 lines
Quoted 43 lines

---
  hw/i386/acpi-common.c | 13 ++++++++++---

  1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +10 -3
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
   {
       uint32_t apic_id = apic_ids->cpus[uid].arch_id;
       /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;
       /* ACPI spec says that LAPIC entry for non present
        * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
       MachineClass *mc = MACHINE_GET_CLASS(x86ms);
       const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
       AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                           .oem_table_id = oem_table_id };
       acpi_table_begin(&table, table_data);
Signature · 1 line
2.31.1
#7 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

Quoted 30 lines · Eric DeVolder
Quoted 18 lines · Eric DeVolder
Quoted 15 lines · Michael S. Tsirkin
Quoted 13 lines · Eric DeVolder

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

Quoted 8 lines
Quoted 3 lines

I am looking for ways to reduce risk of breakage with this. We don't currently have a reason to change it if cpu hotplug is off, do we? Maybe make it conditional on that.

By "cpu hotplug off", do you mean, for example, no maxcpus= option? In other words, how should I detect "cpu hotplug off"? eric

Quoted 8 lines

Actually, if, for example, one had -smp 30,maxcpus=32, then there would be two hotpluggable cpus reported, the last two with the Enabled=0 and Online Capable=1. If one had -smp 32 (ie "cpu hotplug off"), then all cpus would be reported as Enabled and no cpu would have its Online Capable flag set.

Granted in both cases, MADT.revision would report 5, but it would still be accurate.

eric

sounds good.

Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 43 lines

---
  hw/i386/acpi-common.c | 13 ++++++++++---

  1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +10 -3
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
   {
       uint32_t apic_id = apic_ids->cpus[uid].arch_id;
       /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;
       /* ACPI spec says that LAPIC entry for non present
        * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
       MachineClass *mc = MACHINE_GET_CLASS(x86ms);
       const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
       AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                           .oem_table_id = oem_table_id };
       acpi_table_begin(&table, table_data);
Signature · 1 line
2.31.1
#8 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

In reply to Eric DeVolder
Quoted 16 lines · On Wed, 29 Mar 2023 08:16:26 -0500 Eric DeVolder <[email protected]>…
Quoted 15 lines · Michael S. Tsirkin
Quoted 13 lines · Eric DeVolder

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

Quoted 7 lines
Quoted 3 lines

I am looking for ways to reduce risk of breakage with this. We don't currently have a reason to change it if cpu hotplug is off, do we? Maybe make it conditional on that.

By "cpu hotplug off", do you mean, for example, no maxcpus= option? In other words, how should I detect "cpu hotplug off"? eric

I'm not sure that it's possible disable CPU hotplug at all. even if one doesn't have maxcpus on CLI present CPUs are described as hotpluggbale and can be unplugged and re-plugged later.

#9 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

In reply to Eric DeVolder
Quoted 11 lines · On Tue, 28 Mar 2023 11:59:26 -0400 Eric DeVolder <[email protected]>…

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

So spec mandates 3 possible states
00t - not present and not can't be added later ever 01t - present
10t - not present but might be added later
and outlawed 11t combination

00t - doesn't make much sense (i.e. why put such entry in MADT in the 1st place)

but looking at kernel commit aa06e20f1be, it looks like ACPI_MADT_ONLINE_CAPABLE was introduced to accommodate firmware/hw folks who would stuff MADT with LAPIC entries for all possible CPU models, and then patch it depending on actually used CPU model instead of dynamically creating LAPIC entries. (insane)

Quoted 15 lines
---
 hw/i386/acpi-common.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +0 -2
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
 {
     uint32_t apic_id = apic_ids->cpus[uid].arch_id;
     /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;

hw/i386/acpi-common.c void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids, · line 50

Quoted 10 lines
hw/i386/acpi-common.c +9 -0
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */
 
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;

align the last line with onlinecapable ....'

move /* Enabled */ and /* Online Capable */ comments right to magic values i.e. onlinecapable ? 0x2 : 0x0 | /* Online Capable */ ...

Quoted 12 lines
hw/i386/acpi-common.c +1 -1
     /* ACPI spec says that LAPIC entry for non present
      * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
     MachineClass *mc = MACHINE_GET_CLASS(x86ms);
     const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
     AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                         .oem_table_id = oem_table_id };
 
     acpi_table_begin(&table, table_data);
#10 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

Quoted 21 lines · On Tue, 11 Apr 2023 18:00:49 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 11 lines · On Tue, 28 Mar 2023 11:59:26 -0400 Eric DeVolder <[email protected]>…

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

So spec mandates 3 possible states
00t - not present and not can't be added later ever 01t - present
10t - not present but might be added later
and outlawed 11t combination

Quoted 8 lines

00t - doesn't make much sense (i.e. why put such entry in MADT in the 1st place)

but looking at kernel commit aa06e20f1be, it looks like ACPI_MADT_ONLINE_CAPABLE was introduced to accommodate firmware/hw folks who would stuff MADT with LAPIC entries for all possible CPU models, and then patch it depending on actually used CPU model instead of dynamically creating LAPIC entries. (insane)

on second thought, QEMU doesn't need rev 5 MADT with this flag complications. Also I see that kernel side fix ended up in checking ACPI spec version instead of dealing with MADT revisions mess.

So for x86 lets bump revision to 3 or 4 to be in sync with what QEMU actually uses.

Quoted 45 lines
Quoted 17 lines
---
 hw/i386/acpi-common.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +0 -2
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
 {
     uint32_t apic_id = apic_ids->cpus[uid].arch_id;
     /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;

hw/i386/acpi-common.c void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids, · line 50

Quoted 10 lines
hw/i386/acpi-common.c +9 -0
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */  
 
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;  

align the last line with onlinecapable ....'

move /* Enabled */ and /* Online Capable */ comments right to magic values i.e. onlinecapable ? 0x2 : 0x0 | /* Online Capable */ ...

Quoted 12 lines
hw/i386/acpi-common.c +1 -1
     /* ACPI spec says that LAPIC entry for non present
      * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
     MachineClass *mc = MACHINE_GET_CLASS(x86ms);
     const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
     AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                         .oem_table_id = oem_table_id };
 
     acpi_table_begin(&table, table_data);  
#11 lore raw

Re: [PATCH 2/2] hw/acpi: i386: bump MADT to revision 5

Quoted 33 lines · Igor Mammedov
Quoted 21 lines · On Tue, 11 Apr 2023 18:00:49 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 11 lines · On Tue, 28 Mar 2023 11:59:26 -0400 Eric DeVolder <[email protected]>…

Currently i386 QEMU generates MADT revision 3, and reports MADT revision 1. ACPI 6.3 introduces MADT revision 5.

For MADT revision 4, that introduces ARM GIC structures, which do not apply to i386.

For MADT revision 5, the Local APIC flags introduces the Online Capable bitfield.

Making MADT generate and report revision 5 will solve problems with CPU hotplug (the Online Capable flag indicates hotpluggable CPUs).

So spec mandates 3 possible states
00t - not present and not can't be added later ever 01t - present
10t - not present but might be added later
and outlawed 11t combination

Quoted 8 lines

00t - doesn't make much sense (i.e. why put such entry in MADT in the 1st place)

but looking at kernel commit aa06e20f1be, it looks like ACPI_MADT_ONLINE_CAPABLE was introduced to accommodate firmware/hw folks who would stuff MADT with LAPIC entries for all possible CPU models, and then patch it depending on actually used CPU model instead of dynamically creating LAPIC entries. (insane)

Quoted 6 lines

on second thought, QEMU doesn't need rev 5 MADT with this flag complications. Also I see that kernel side fix ended up in checking ACPI spec version instead of dealing with MADT revisions mess.

So for x86 lets bump revision to 3 or 4 to be in sync with what QEMU actually uses.

If bumping to only 3 or 4, then there is no need for this patch series.

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
---
  hw/i386/acpi-common.c | 13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
hw/i386/acpi-common.c +7 -2
index 52e5c1439a..1e3a13a36c 100644
@@ -38,8 +38,15 @@ void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids,
  {
      uint32_t apic_id = apic_ids->cpus[uid].arch_id;
      /* Flags – Local APIC Flags */
-    uint32_t flags = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
-                     1 /* Enabled */ : 0;
+    bool enabled = apic_ids->cpus[uid].cpu != NULL || force_enabled ?
+                     true /* Enabled */ : false;
+    /*
+     * ACPI 6.3 5.2.12.2 Local APIC Flags: OnlineCapable must be 0
+     * if Enabled is set.
+     */
+    bool onlinecapable = enabled ? false : true; /* Online Capable */
Quoted 7 lines
Quoted 7 lines

hw/i386/acpi-common.c void pc_madt_cpu_entry(int uid, const CPUArchIdList *apic_ids, · line 49

Quoted 2 lines
hw/i386/acpi-common.c +2 -0
+    uint32_t flags = onlinecapable ? 0x2 : 0x0 |
+        enabled ? 0x1 : 0x0;

align the last line with onlinecapable ....'

move /* Enabled */ and /* Online Capable */ comments right to magic values i.e. onlinecapable ? 0x2 : 0x0 | /* Online Capable */ ...

Done.

I've gone ahead and posted a v2 with these changes; keeping MADT.revision at 5. eric

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
hw/i386/acpi-common.c +1 -1
      /* ACPI spec says that LAPIC entry for non present
       * CPU may be omitted from MADT or it must be marked
@@ -102,7 +109,7 @@ void acpi_build_madt(GArray *table_data, BIOSLinker *linker,
      MachineClass *mc = MACHINE_GET_CLASS(x86ms);
      const CPUArchIdList *apic_ids = mc->possible_cpu_arch_ids(MACHINE(x86ms));
      AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(adev);
-    AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = oem_id,
+    AcpiTable table = { .sig = "APIC", .rev = 5, .oem_id = oem_id,
                          .oem_table_id = oem_table_id };
 
      acpi_table_begin(&table, table_data);
#12 lore raw
In reply to Eric DeVolder

I forgot to include the updated ACPI tables. I will do that as part of v2. In the meantime, I appreciate any feedback...
eric

Quoted 203 lines · Eric DeVolder

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

As part of the investigation into resolving this breakage, I learned that i386 QEMU reports revision 1, while technically it is at revision 3. (Arm QEMU reports revision 4, and that is valid/correct.)

ACPI 6.3 bumps MADT revision to 5 as it introduces an Online Capable flag that the above Linux patch utilizes to denote hot pluggable CPUs.

So in order to bump MADT to the current revision of 5, need to validate that all MADT table changes between 1 and 5 are present in QEMU.

Below is a table summarizing the changes to the MADT. This information gleamed from the ACPI specs on uefi.org.

ACPI MADT What
Version Version

1.0             MADT not present
2.0     1       Section 5.2.10.4
3.0     2       Section 5.2.11.4

5.2.11.13 Local SAPIC Structure added two new fields:
ACPI Processor UID Value
ACPI Processor UID String
5.2.10.14 Platform Interrupt Sources Structure:
Reserved changed to Platform Interrupt Sources Flags
3.0b 2 Section 5.2.11.4
Added a section describing guidelines for the ordering of processors in the MADT to support proper boot processor and multi-threaded logical processor operation.
4.0 3 Section 5.2.12
Adds Processor Local x2APIC structure type 9 Adds Local x2APIC NMI structure type 0xA

5.0     3       Section 5.2.12
6.0     3       Section 5.2.12
6.0a    4       Section 5.2.12
                  Adds ARM GIC structure types 0xB-0xF
6.2a    45      Section 5.2.12   <--- yep it says version 45!
6.2b    5       Section 5.2.12

GIC ITS last Reserved offset changed to 16 from 20 (typo)
6.3 5 Section 5.2.12
Adds Local APIC Flags Online Capable!
Adds GICC SPE Overflow Interrupt field
6.4 5 Section 5.2.12
Adds Multiprocessor Wakeup Structure type 0x10 (change notes says structure previously misplaced?)
6.5 5 Section 5.2.12

For the MADT revision change 1 -> 2, the spec has a change to the SAPIC structure. In general, QEMU does not generate/support SAPIC. So the QEMU i386 MADT revision can safely be moved to 2.

For the MADT revision change 2 -> 3, the spec adds Local x2APIC structures. QEMU has long supported x2apic ACPI structures. A simple search of x2apic within QEMU source and hw/i386/acpi-common.c specifically reveals this. So the QEMU i386 MADT revision can safely be moved to 3.

For the MADT revision change 3 -> 4, the spec adds support for the ARM GIC structures. QEMU ARM does in fact generate and report revision 4. As these will not be used by i386 QEMU, so then the QEMU i386 MADT revision can safely be moved to 4 as well.

Now for the MADT revision change 4 -> 5, the spec adds the Online Capable flag to the Local APIC structure, and the ARM GICC SPE Overflow Interrupt field.

For the ARM SPE, an existing 3-byte Reserved field is broken into a 1- byte Reserved field and a 2-byte SPE field. The spec says that is SPE Overflow is not supported, it should be zero.

For the i386 Local APIC flag Online Capable, the spec has certain rules about this value. And in particuar setting this value now explicitly indicates a hotpluggable CPU.

So this patch makes the needed changes to move both ARM and i386 MADT to revision 5. These are not complicated, thankfully.

Without these changes, the information below shows "how" CPU hotplug breaks with the current upstream Linux kernel 6.3. For example, a Linux guest started with:

qemu-system-x86_64 -smp 30,maxcpus=32 ...

and then attempting to hotplug a CPU:

   (QEMU) device_add id=cpu30 driver=host-x86_64-cpu socket-id=0 core-id=30 thread-id=0

fails with the following:

APIC: NR_CPUS/possible_cpus limit of 30 reached. Processor 30/0x.
ACPI: Unable to map lapic to logical cpu number
acpi LNXCPU:1e: Enumeration failure

   # dmesg | grep smpboot
   smpboot: Allowing 30 CPUs, 0 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x)
   smpboot: Max logical packages: 1
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000   4]                    Signature : "APIC"    [Multiple APIC Descript
   [004h 0004   4]                 Table Length : 00000170
   [008h 0008   1]                     Revision : 01          <=====
   [009h 0009   1]                     Checksum : 9C
   [00Ah 0010   6]                       Oem ID : "BOCHS "
   [010h 0016   8]                 Oem Table ID : "BXPC    "
   [018h 0024   4]                 Oem Revision : 00000001
   [01Ch 0028   4]              Asl Compiler ID : "BXPC"
   [020h 0032   4]        Asl Compiler Revision : 00000001

...

   [114h 0276   1]                Subtable Type : 00 [Processor Local APIC]
   [115h 0277   1]                       Length : 08
   [116h 0278   1]                 Processor ID : 1D
   [117h 0279   1]                Local Apic ID : 1D
   [118h 0280   4]        Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
   [11Ch 0284   1]                Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285   1]                       Length : 08
   [11Eh 0286   1]                 Processor ID : 1E
   [11Fh 0287   1]                Local Apic ID : 1E
   [120h 0288   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====
   [124h 0292   1]                Subtable Type : 00 [Processor Local APIC]
   [125h 0293   1]                       Length : 08
   [126h 0294   1]                 Processor ID : 1F
   [127h 0295   1]                Local Apic ID : 1F
   [128h 0296   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====

The (latest upstream) Linux kernel sees 30 Enabled processors, and does not consider processors 31 and 32 to be hotpluggable.

With this patch series applied, by bumping MADT to revision 5, the latest upstream Linux kernel correctly identifies 30 CPUs plus 2 hotpluggable CPUS.

   CPU30 has been hot-added
   smpboot: Booting Node 0 Processor 30 APIC 0x1e
   Will online and init hotplugged CPU: 30

   # dmesg | grep smpboot
   smpboot: Allowing 32 CPUs, 2 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x6, model: 0x56, stepping: 0x3)
   smpboot: Max logical packages: 2
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)

   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000 004h]                   Signature : "APIC"    [Multiple APIC Descript
   [004h 0004 004h]                Table Length : 00000170
   [008h 0008 001h]                    Revision : 05          <=====
   [009h 0009 001h]                    Checksum : 94
   [00Ah 0010 006h]                      Oem ID : "BOCHS "
   [010h 0016 008h]                Oem Table ID : "BXPC    "
   [018h 0024 004h]                Oem Revision : 00000001
   [01Ch 0028 004h]             Asl Compiler ID : "BXPC"
   [020h 0032 004h]       Asl Compiler Revision : 00000001

   ...

   [114h 0276 001h]               Subtable Type : 00 [Processor Local APIC]
   [115h 0277 001h]                      Length : 08
   [116h 0278 001h]                Processor ID : 1D
   [117h 0279 001h]               Local Apic ID : 1D
   [118h 0280 004h]       Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
                         Runtime Online Capable : 0          <=====

   [11Ch 0284 001h]               Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285 001h]                      Length : 08
   [11Eh 0286 001h]                Processor ID : 1E
   [11Fh 0287 001h]               Local Apic ID : 1E
   [120h 0288 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====

   [124h 0292 001h]               Subtable Type : 00 [Processor Local APIC]
   [125h 0293 001h]                      Length : 08
   [126h 0294 001h]                Processor ID : 1F
   [127h 0295 001h]               Local Apic ID : 1F
   [128h 0296 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====

Regards,
Eric

Eric DeVolder (2):
hw/acpi: arm: bump MADT to revision 5
hw/acpi: i386: bump MADT to revision 5

  hw/arm/virt-acpi-build.c |  6 ++++--
  hw/i386/acpi-common.c    | 13 ++++++++++---
  2 files changed, 14 insertions(+), 5 deletions(-)
#13 lore raw
In reply to Eric DeVolder

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Quoted 4 lines · Eric DeVolder

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

Quoted 46 lines

As part of the investigation into resolving this breakage, I learned that i386 QEMU reports revision 1, while technically it is at revision 3. (Arm QEMU reports revision 4, and that is valid/correct.)

ACPI 6.3 bumps MADT revision to 5 as it introduces an Online Capable flag that the above Linux patch utilizes to denote hot pluggable CPUs.

So in order to bump MADT to the current revision of 5, need to validate that all MADT table changes between 1 and 5 are present in QEMU.

Below is a table summarizing the changes to the MADT. This information gleamed from the ACPI specs on uefi.org.

ACPI MADT What
Version Version

1.0             MADT not present
2.0     1       Section 5.2.10.4
3.0     2       Section 5.2.11.4

5.2.11.13 Local SAPIC Structure added two new fields:
ACPI Processor UID Value
ACPI Processor UID String
5.2.10.14 Platform Interrupt Sources Structure:
Reserved changed to Platform Interrupt Sources Flags
3.0b 2 Section 5.2.11.4
Added a section describing guidelines for the ordering of processors in the MADT to support proper boot processor and multi-threaded logical processor operation.
4.0 3 Section 5.2.12
Adds Processor Local x2APIC structure type 9 Adds Local x2APIC NMI structure type 0xA

5.0     3       Section 5.2.12
6.0     3       Section 5.2.12
6.0a    4       Section 5.2.12
                 Adds ARM GIC structure types 0xB-0xF
6.2a    45      Section 5.2.12   <--- yep it says version 45!
6.2b    5       Section 5.2.12

GIC ITS last Reserved offset changed to 16 from 20 (typo)
6.3 5 Section 5.2.12
Adds Local APIC Flags Online Capable!
Adds GICC SPE Overflow Interrupt field
6.4 5 Section 5.2.12
Adds Multiprocessor Wakeup Structure type 0x10 (change notes says structure previously misplaced?)
6.5 5 Section 5.2.12

Quoted 8 lines

For the MADT revision change 1 -> 2, the spec has a change to the SAPIC structure. In general, QEMU does not generate/support SAPIC. So the QEMU i386 MADT revision can safely be moved to 2.

For the MADT revision change 2 -> 3, the spec adds Local x2APIC structures. QEMU has long supported x2apic ACPI structures. A simple search of x2apic within QEMU source and hw/i386/acpi-common.c specifically reveals this.

But not unconditionally.

Quoted 130 lines

So the QEMU i386 MADT revision can safely
be moved to 3.

For the MADT revision change 3 -> 4, the spec adds support for the ARM GIC structures. QEMU ARM does in fact generate and report revision 4. As these will not be used by i386 QEMU, so then the QEMU i386 MADT revision can safely be moved to 4 as well.

Now for the MADT revision change 4 -> 5, the spec adds the Online Capable flag to the Local APIC structure, and the ARM GICC SPE Overflow Interrupt field.

For the ARM SPE, an existing 3-byte Reserved field is broken into a 1- byte Reserved field and a 2-byte SPE field. The spec says that is SPE Overflow is not supported, it should be zero.

For the i386 Local APIC flag Online Capable, the spec has certain rules about this value. And in particuar setting this value now explicitly indicates a hotpluggable CPU.

So this patch makes the needed changes to move both ARM and i386 MADT to revision 5. These are not complicated, thankfully.

Without these changes, the information below shows "how" CPU hotplug breaks with the current upstream Linux kernel 6.3. For example, a Linux guest started with:

qemu-system-x86_64 -smp 30,maxcpus=32 ...

and then attempting to hotplug a CPU:

(QEMU) device_add id=cpu30 driver=host-x86_64-cpu socket-id=0 core-id=30 thread-id=0

fails with the following:

APIC: NR_CPUS/possible_cpus limit of 30 reached. Processor 30/0x.
ACPI: Unable to map lapic to logical cpu number
acpi LNXCPU:1e: Enumeration failure

  # dmesg | grep smpboot
  smpboot: Allowing 30 CPUs, 0 hotplug CPUs
  smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x)
  smpboot: Max logical packages: 1
  smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
  # iasl -d /sys/firmware/tables/acpi/APIC
  [000h 0000   4]                    Signature : "APIC"    [Multiple APIC Descript
  [004h 0004   4]                 Table Length : 00000170
  [008h 0008   1]                     Revision : 01          <=====
  [009h 0009   1]                     Checksum : 9C
  [00Ah 0010   6]                       Oem ID : "BOCHS "
  [010h 0016   8]                 Oem Table ID : "BXPC    "
  [018h 0024   4]                 Oem Revision : 00000001
  [01Ch 0028   4]              Asl Compiler ID : "BXPC"
  [020h 0032   4]        Asl Compiler Revision : 00000001

...

  [114h 0276   1]                Subtable Type : 00 [Processor Local APIC]
  [115h 0277   1]                       Length : 08
  [116h 0278   1]                 Processor ID : 1D
  [117h 0279   1]                Local Apic ID : 1D
  [118h 0280   4]        Flags (decoded below) : 00000001
                             Processor Enabled : 1          <=====
  [11Ch 0284   1]                Subtable Type : 00 [Processor Local APIC]
  [11Dh 0285   1]                       Length : 08
  [11Eh 0286   1]                 Processor ID : 1E
  [11Fh 0287   1]                Local Apic ID : 1E
  [120h 0288   4]        Flags (decoded below) : 00000000
                             Processor Enabled : 0          <=====
  [124h 0292   1]                Subtable Type : 00 [Processor Local APIC]
  [125h 0293   1]                       Length : 08
  [126h 0294   1]                 Processor ID : 1F
  [127h 0295   1]                Local Apic ID : 1F
  [128h 0296   4]        Flags (decoded below) : 00000000
                             Processor Enabled : 0          <=====

The (latest upstream) Linux kernel sees 30 Enabled processors, and does not consider processors 31 and 32 to be hotpluggable.

With this patch series applied, by bumping MADT to revision 5, the latest upstream Linux kernel correctly identifies 30 CPUs plus 2 hotpluggable CPUS.

CPU30 has been hot-added
smpboot: Booting Node 0 Processor 30 APIC 0x1e
Will online and init hotplugged CPU: 30

  # dmesg | grep smpboot
  smpboot: Allowing 32 CPUs, 2 hotplug CPUs
  smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x6, model: 0x56, stepping: 0x3)
  smpboot: Max logical packages: 2
  smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
  # iasl -d /sys/firmware/tables/acpi/APIC
  [000h 0000 004h]                   Signature : "APIC"    [Multiple APIC Descript
  [004h 0004 004h]                Table Length : 00000170
  [008h 0008 001h]                    Revision : 05          <=====
  [009h 0009 001h]                    Checksum : 94
  [00Ah 0010 006h]                      Oem ID : "BOCHS "
  [010h 0016 008h]                Oem Table ID : "BXPC    "
  [018h 0024 004h]                Oem Revision : 00000001
  [01Ch 0028 004h]             Asl Compiler ID : "BXPC"
  [020h 0032 004h]       Asl Compiler Revision : 00000001

...

[114h 0276 001h] Subtable Type : 00 [Processor Local APIC]
[115h 0277 001h] Length : 08
[116h 0278 001h] Processor ID : 1D
[117h 0279 001h] Local Apic ID : 1D
[118h 0280 004h] Flags (decoded below) : 00000001

                             Processor Enabled : 1          <=====
                        Runtime Online Capable : 0          <=====

[11Ch 0284 001h] Subtable Type : 00 [Processor Local APIC]
[11Dh 0285 001h] Length : 08
[11Eh 0286 001h] Processor ID : 1E
[11Fh 0287 001h] Local Apic ID : 1E
[120h 0288 004h] Flags (decoded below) : 00000002

                             Processor Enabled : 0          <=====
                        Runtime Online Capable : 1          <=====

[124h 0292 001h] Subtable Type : 00 [Processor Local APIC]
[125h 0293 001h] Length : 08
[126h 0294 001h] Processor ID : 1F
[127h 0295 001h] Local Apic ID : 1F
[128h 0296 004h] Flags (decoded below) : 00000002

Quoted 5 lines
                             Processor Enabled : 0          <=====
                        Runtime Online Capable : 1          <=====

Regards,
Eric

Can you please report which guests were tested?

Quoted 14 lines

Eric DeVolder (2):
hw/acpi: arm: bump MADT to revision 5
hw/acpi: i386: bump MADT to revision 5

 hw/arm/virt-acpi-build.c |  6 ++++--
 hw/i386/acpi-common.c    | 13 ++++++++++---
 2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
#14 lore raw
Quoted 5 lines · Michael S. Tsirkin

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Quoted 10 lines · Eric DeVolder
Quoted 4 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Quoted 52 lines
Quoted 52 lines

As part of the investigation into resolving this breakage, I learned that i386 QEMU reports revision 1, while technically it is at revision 3. (Arm QEMU reports revision 4, and that is valid/correct.)

ACPI 6.3 bumps MADT revision to 5 as it introduces an Online Capable flag that the above Linux patch utilizes to denote hot pluggable CPUs.

So in order to bump MADT to the current revision of 5, need to validate that all MADT table changes between 1 and 5 are present in QEMU.

Below is a table summarizing the changes to the MADT. This information gleamed from the ACPI specs on uefi.org.

ACPI MADT What
Version Version

1.0             MADT not present
2.0     1       Section 5.2.10.4
3.0     2       Section 5.2.11.4

5.2.11.13 Local SAPIC Structure added two new fields:
ACPI Processor UID Value
ACPI Processor UID String
5.2.10.14 Platform Interrupt Sources Structure:
Reserved changed to Platform Interrupt Sources Flags
3.0b 2 Section 5.2.11.4
Added a section describing guidelines for the ordering of processors in the MADT to support proper boot processor and multi-threaded logical processor operation.
4.0 3 Section 5.2.12
Adds Processor Local x2APIC structure type 9 Adds Local x2APIC NMI structure type 0xA

5.0     3       Section 5.2.12
6.0     3       Section 5.2.12
6.0a    4       Section 5.2.12
                  Adds ARM GIC structure types 0xB-0xF
6.2a    45      Section 5.2.12   <--- yep it says version 45!
6.2b    5       Section 5.2.12

GIC ITS last Reserved offset changed to 16 from 20 (typo)
6.3 5 Section 5.2.12
Adds Local APIC Flags Online Capable!
Adds GICC SPE Overflow Interrupt field
6.4 5 Section 5.2.12
Adds Multiprocessor Wakeup Structure type 0x10 (change notes says structure previously misplaced?)
6.5 5 Section 5.2.12

For the MADT revision change 1 -> 2, the spec has a change to the SAPIC structure. In general, QEMU does not generate/support SAPIC. So the QEMU i386 MADT revision can safely be moved to 2.

Quoted 6 lines
Quoted 4 lines

For the MADT revision change 2 -> 3, the spec adds Local x2APIC structures. QEMU has long supported x2apic ACPI structures. A simple search of x2apic within QEMU source and hw/i386/acpi-common.c specifically reveals this.

But not unconditionally.

I don't think that reporting revision 3 requires that generation of x2apic; one could still see apic, x2apic, or sapic in theory. I realize qemu doesn't do sapic...

Quoted 134 lines
Quoted 134 lines

So the QEMU i386 MADT revision can safely
be moved to 3.

For the MADT revision change 3 -> 4, the spec adds support for the ARM GIC structures. QEMU ARM does in fact generate and report revision 4. As these will not be used by i386 QEMU, so then the QEMU i386 MADT revision can safely be moved to 4 as well.

Now for the MADT revision change 4 -> 5, the spec adds the Online Capable flag to the Local APIC structure, and the ARM GICC SPE Overflow Interrupt field.

For the ARM SPE, an existing 3-byte Reserved field is broken into a 1- byte Reserved field and a 2-byte SPE field. The spec says that is SPE Overflow is not supported, it should be zero.

For the i386 Local APIC flag Online Capable, the spec has certain rules about this value. And in particuar setting this value now explicitly indicates a hotpluggable CPU.

So this patch makes the needed changes to move both ARM and i386 MADT to revision 5. These are not complicated, thankfully.

Without these changes, the information below shows "how" CPU hotplug breaks with the current upstream Linux kernel 6.3. For example, a Linux guest started with:

qemu-system-x86_64 -smp 30,maxcpus=32 ...

and then attempting to hotplug a CPU:

   (QEMU) device_add id=cpu30 driver=host-x86_64-cpu socket-id=0 core-id=30 thread-id=0

fails with the following:

APIC: NR_CPUS/possible_cpus limit of 30 reached. Processor 30/0x.
ACPI: Unable to map lapic to logical cpu number
acpi LNXCPU:1e: Enumeration failure

   # dmesg | grep smpboot
   smpboot: Allowing 30 CPUs, 0 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x)
   smpboot: Max logical packages: 1
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000   4]                    Signature : "APIC"    [Multiple APIC Descript
   [004h 0004   4]                 Table Length : 00000170
   [008h 0008   1]                     Revision : 01          <=====
   [009h 0009   1]                     Checksum : 9C
   [00Ah 0010   6]                       Oem ID : "BOCHS "
   [010h 0016   8]                 Oem Table ID : "BXPC    "
   [018h 0024   4]                 Oem Revision : 00000001
   [01Ch 0028   4]              Asl Compiler ID : "BXPC"
   [020h 0032   4]        Asl Compiler Revision : 00000001

...

   [114h 0276   1]                Subtable Type : 00 [Processor Local APIC]
   [115h 0277   1]                       Length : 08
   [116h 0278   1]                 Processor ID : 1D
   [117h 0279   1]                Local Apic ID : 1D
   [118h 0280   4]        Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
   [11Ch 0284   1]                Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285   1]                       Length : 08
   [11Eh 0286   1]                 Processor ID : 1E
   [11Fh 0287   1]                Local Apic ID : 1E
   [120h 0288   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====
   [124h 0292   1]                Subtable Type : 00 [Processor Local APIC]
   [125h 0293   1]                       Length : 08
   [126h 0294   1]                 Processor ID : 1F
   [127h 0295   1]                Local Apic ID : 1F
   [128h 0296   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====

The (latest upstream) Linux kernel sees 30 Enabled processors, and does not consider processors 31 and 32 to be hotpluggable.

With this patch series applied, by bumping MADT to revision 5, the latest upstream Linux kernel correctly identifies 30 CPUs plus 2 hotpluggable CPUS.

   CPU30 has been hot-added
   smpboot: Booting Node 0 Processor 30 APIC 0x1e
   Will online and init hotplugged CPU: 30

   # dmesg | grep smpboot
   smpboot: Allowing 32 CPUs, 2 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x6, model: 0x56, stepping: 0x3)
   smpboot: Max logical packages: 2
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)

   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000 004h]                   Signature : "APIC"    [Multiple APIC Descript
   [004h 0004 004h]                Table Length : 00000170
   [008h 0008 001h]                    Revision : 05          <=====
   [009h 0009 001h]                    Checksum : 94
   [00Ah 0010 006h]                      Oem ID : "BOCHS "
   [010h 0016 008h]                Oem Table ID : "BXPC    "
   [018h 0024 004h]                Oem Revision : 00000001
   [01Ch 0028 004h]             Asl Compiler ID : "BXPC"
   [020h 0032 004h]       Asl Compiler Revision : 00000001

   ...

   [114h 0276 001h]               Subtable Type : 00 [Processor Local APIC]
   [115h 0277 001h]                      Length : 08
   [116h 0278 001h]                Processor ID : 1D
   [117h 0279 001h]               Local Apic ID : 1D
   [118h 0280 004h]       Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
                         Runtime Online Capable : 0          <=====

   [11Ch 0284 001h]               Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285 001h]                      Length : 08
   [11Eh 0286 001h]                Processor ID : 1E
   [11Fh 0287 001h]               Local Apic ID : 1E
   [120h 0288 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====

   [124h 0292 001h]               Subtable Type : 00 [Processor Local APIC]
   [125h 0293 001h]                      Length : 08
   [126h 0294 001h]                Processor ID : 1F
   [127h 0295 001h]               Local Apic ID : 1F
   [128h 0296 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====
Quoted 4 lines
Quoted 2 lines

Regards,
Eric

Can you please report which guests were tested?

I've been using primarily upstream Linux. Kernels at and before 6.2.0 didn't have the "broken" patch mentioned above, and worked (for the reasons cited in the patch discussion to "fix" that patch). Any kernel since has the "broken" patch and will exhibit the issue.

I've been using q35.

If there are other samples you'd like to see, let me know and I'll try.

Also, my responses will be delayed as I'm traveling the remainder of the week.

Thanks!
eric

Quoted 17 lines
Quoted 16 lines

Eric DeVolder (2):
hw/acpi: arm: bump MADT to revision 5
hw/acpi: i386: bump MADT to revision 5

  hw/arm/virt-acpi-build.c |  6 ++++--
  hw/i386/acpi-common.c    | 13 ++++++++++---
  2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
#15 lore raw
Quoted 9 lines · Eric DeVolder
Quoted 5 lines · Michael S. Tsirkin

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Don't much care. x-madt-rev?

Quoted 6 lines
Quoted 6 lines · Eric DeVolder
Quoted 3 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Great! Maybe stick a Link: tag in the commit log.

Quoted 207 lines
Quoted 52 lines
Quoted 52 lines

As part of the investigation into resolving this breakage, I learned that i386 QEMU reports revision 1, while technically it is at revision 3. (Arm QEMU reports revision 4, and that is valid/correct.)

ACPI 6.3 bumps MADT revision to 5 as it introduces an Online Capable flag that the above Linux patch utilizes to denote hot pluggable CPUs.

So in order to bump MADT to the current revision of 5, need to validate that all MADT table changes between 1 and 5 are present in QEMU.

Below is a table summarizing the changes to the MADT. This information gleamed from the ACPI specs on uefi.org.

ACPI MADT What
Version Version

1.0             MADT not present
2.0     1       Section 5.2.10.4
3.0     2       Section 5.2.11.4

5.2.11.13 Local SAPIC Structure added two new fields:
ACPI Processor UID Value
ACPI Processor UID String
5.2.10.14 Platform Interrupt Sources Structure:
Reserved changed to Platform Interrupt Sources Flags
3.0b 2 Section 5.2.11.4
Added a section describing guidelines for the ordering of processors in the MADT to support proper boot processor and multi-threaded logical processor operation.
4.0 3 Section 5.2.12
Adds Processor Local x2APIC structure type 9 Adds Local x2APIC NMI structure type 0xA

5.0     3       Section 5.2.12
6.0     3       Section 5.2.12
6.0a    4       Section 5.2.12
                  Adds ARM GIC structure types 0xB-0xF
6.2a    45      Section 5.2.12   <--- yep it says version 45!
6.2b    5       Section 5.2.12

GIC ITS last Reserved offset changed to 16 from 20 (typo)
6.3 5 Section 5.2.12
Adds Local APIC Flags Online Capable!
Adds GICC SPE Overflow Interrupt field
6.4 5 Section 5.2.12
Adds Multiprocessor Wakeup Structure type 0x10 (change notes says structure previously misplaced?)
6.5 5 Section 5.2.12

For the MADT revision change 1 -> 2, the spec has a change to the SAPIC structure. In general, QEMU does not generate/support SAPIC. So the QEMU i386 MADT revision can safely be moved to 2.

Quoted 6 lines
Quoted 4 lines

For the MADT revision change 2 -> 3, the spec adds Local x2APIC structures. QEMU has long supported x2apic ACPI structures. A simple search of x2apic within QEMU source and hw/i386/acpi-common.c specifically reveals this.

But not unconditionally.

I don't think that reporting revision 3 requires that generation of x2apic; one could still see apic, x2apic, or sapic in theory. I realize qemu doesn't do sapic...

Quoted 134 lines
Quoted 134 lines

So the QEMU i386 MADT revision can safely
be moved to 3.

For the MADT revision change 3 -> 4, the spec adds support for the ARM GIC structures. QEMU ARM does in fact generate and report revision 4. As these will not be used by i386 QEMU, so then the QEMU i386 MADT revision can safely be moved to 4 as well.

Now for the MADT revision change 4 -> 5, the spec adds the Online Capable flag to the Local APIC structure, and the ARM GICC SPE Overflow Interrupt field.

For the ARM SPE, an existing 3-byte Reserved field is broken into a 1- byte Reserved field and a 2-byte SPE field. The spec says that is SPE Overflow is not supported, it should be zero.

For the i386 Local APIC flag Online Capable, the spec has certain rules about this value. And in particuar setting this value now explicitly indicates a hotpluggable CPU.

So this patch makes the needed changes to move both ARM and i386 MADT to revision 5. These are not complicated, thankfully.

Without these changes, the information below shows "how" CPU hotplug breaks with the current upstream Linux kernel 6.3. For example, a Linux guest started with:

qemu-system-x86_64 -smp 30,maxcpus=32 ...

and then attempting to hotplug a CPU:

   (QEMU) device_add id=cpu30 driver=host-x86_64-cpu socket-id=0 core-id=30 thread-id=0

fails with the following:

APIC: NR_CPUS/possible_cpus limit of 30 reached. Processor 30/0x.
ACPI: Unable to map lapic to logical cpu number
acpi LNXCPU:1e: Enumeration failure

   # dmesg | grep smpboot
   smpboot: Allowing 30 CPUs, 0 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x)
   smpboot: Max logical packages: 1
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000   4]                    Signature : "APIC"    [Multiple APIC Descript
   [004h 0004   4]                 Table Length : 00000170
   [008h 0008   1]                     Revision : 01          <=====
   [009h 0009   1]                     Checksum : 9C
   [00Ah 0010   6]                       Oem ID : "BOCHS "
   [010h 0016   8]                 Oem Table ID : "BXPC    "
   [018h 0024   4]                 Oem Revision : 00000001
   [01Ch 0028   4]              Asl Compiler ID : "BXPC"
   [020h 0032   4]        Asl Compiler Revision : 00000001

...

   [114h 0276   1]                Subtable Type : 00 [Processor Local APIC]
   [115h 0277   1]                       Length : 08
   [116h 0278   1]                 Processor ID : 1D
   [117h 0279   1]                Local Apic ID : 1D
   [118h 0280   4]        Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
   [11Ch 0284   1]                Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285   1]                       Length : 08
   [11Eh 0286   1]                 Processor ID : 1E
   [11Fh 0287   1]                Local Apic ID : 1E
   [120h 0288   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====
   [124h 0292   1]                Subtable Type : 00 [Processor Local APIC]
   [125h 0293   1]                       Length : 08
   [126h 0294   1]                 Processor ID : 1F
   [127h 0295   1]                Local Apic ID : 1F
   [128h 0296   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====

The (latest upstream) Linux kernel sees 30 Enabled processors, and does not consider processors 31 and 32 to be hotpluggable.

With this patch series applied, by bumping MADT to revision 5, the latest upstream Linux kernel correctly identifies 30 CPUs plus 2 hotpluggable CPUS.

   CPU30 has been hot-added
   smpboot: Booting Node 0 Processor 30 APIC 0x1e
   Will online and init hotplugged CPU: 30

   # dmesg | grep smpboot
   smpboot: Allowing 32 CPUs, 2 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x6, model: 0x56, stepping: 0x3)
   smpboot: Max logical packages: 2
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)

   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000 004h]                   Signature : "APIC"    [Multiple APIC Descript
   [004h 0004 004h]                Table Length : 00000170
   [008h 0008 001h]                    Revision : 05          <=====
   [009h 0009 001h]                    Checksum : 94
   [00Ah 0010 006h]                      Oem ID : "BOCHS "
   [010h 0016 008h]                Oem Table ID : "BXPC    "
   [018h 0024 004h]                Oem Revision : 00000001
   [01Ch 0028 004h]             Asl Compiler ID : "BXPC"
   [020h 0032 004h]       Asl Compiler Revision : 00000001

   ...

   [114h 0276 001h]               Subtable Type : 00 [Processor Local APIC]
   [115h 0277 001h]                      Length : 08
   [116h 0278 001h]                Processor ID : 1D
   [117h 0279 001h]               Local Apic ID : 1D
   [118h 0280 004h]       Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
                         Runtime Online Capable : 0          <=====

   [11Ch 0284 001h]               Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285 001h]                      Length : 08
   [11Eh 0286 001h]                Processor ID : 1E
   [11Fh 0287 001h]               Local Apic ID : 1E
   [120h 0288 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====

   [124h 0292 001h]               Subtable Type : 00 [Processor Local APIC]
   [125h 0293 001h]                      Length : 08
   [126h 0294 001h]                Processor ID : 1F
   [127h 0295 001h]               Local Apic ID : 1F
   [128h 0296 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====
Quoted 4 lines
Quoted 2 lines

Regards,
Eric

Can you please report which guests were tested?

I've been using primarily upstream Linux. Kernels at and before 6.2.0 didn't have the "broken" patch mentioned above, and worked (for the reasons cited in the patch discussion to "fix" that patch). Any kernel since has the "broken" patch and will exhibit the issue.

Quoted 8 lines

I've been using q35.

If there are other samples you'd like to see, let me know and I'll try.

Also, my responses will be delayed as I'm traveling the remainder of the week.

Thanks!
eric

As a minimum some windows versions. The older the better.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

Eric DeVolder (2):
hw/acpi: arm: bump MADT to revision 5
hw/acpi: i386: bump MADT to revision 5

  hw/arm/virt-acpi-build.c |  6 ++++--
  hw/i386/acpi-common.c    | 13 ++++++++++---
  2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
#16 lore raw
Quoted 19 lines · Michael S. Tsirkin
Quoted 9 lines · Eric DeVolder
Quoted 5 lines · Michael S. Tsirkin

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Don't much care. x-madt-rev?

Quoted 6 lines
Quoted 6 lines · Eric DeVolder
Quoted 3 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Great! Maybe stick a Link: tag in the commit log.

If the original bug is in the kernel and kernel upstream has accepted both your fix and Mario's patch on the acpi revision mess, I see no urgency to fix this in QEMU.

Maybe we can address this in the 8.1 development window.

#17 lore raw
Quoted 30 lines · Ani Sinha
Quoted 26 lines · Michael S. Tsirkin
Quoted 9 lines · Eric DeVolder
Quoted 5 lines · Michael S. Tsirkin

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Don't much care. x-madt-rev?

Quoted 12 lines
Quoted 10 lines · Eric DeVolder
Quoted 4 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Quoted 7 lines
Quoted 1 line

Great! Maybe stick a Link: tag in the commit log.

If the original bug is in the kernel and kernel upstream has accepted both your fix and Mario's patch on the acpi revision mess, I see no urgency to fix this in QEMU.

Maybe we can address this in the 8.1 development window.

Why "maybe"? Eric is working on a patch I don't see why we won't address it.

Signature · 1 line
MST
#18 lore raw
Quoted 33 lines · Michael S. Tsirkin
Quoted 32 lines · Ani Sinha
Quoted 27 lines · Michael S. Tsirkin
Quoted 9 lines · Eric DeVolder
Quoted 5 lines · Michael S. Tsirkin

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Don't much care. x-madt-rev?

Quoted 6 lines
Quoted 6 lines · Eric DeVolder
Quoted 3 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Great! Maybe stick a Link: tag in the commit log.

Quoted 9 lines
Quoted 5 lines

If the original bug is in the kernel and kernel upstream has accepted both your fix and Mario's patch on the acpi revision mess, I see no urgency to fix this in QEMU.

Maybe we can address this in the 8.1 development window.

Why "maybe"? Eric is working on a patch I don't see why we won't address it.

I am not opposed to addressing it. I just think it might be too risky for 8.0 given that we are already past the hard feature freeze date.

#19 lore raw
Quoted 41 lines · Ani Sinha
Quoted 37 lines · Michael S. Tsirkin
Quoted 36 lines · Ani Sinha
Quoted 19 lines · Michael S. Tsirkin
Quoted 9 lines · Eric DeVolder
Quoted 5 lines · Michael S. Tsirkin

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Don't much care. x-madt-rev?

Quoted 6 lines
Quoted 6 lines · Eric DeVolder
Quoted 3 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Great! Maybe stick a Link: tag in the commit log.

If the original bug is in the kernel and kernel upstream has accepted both your fix and Mario's patch on the acpi revision mess, I see no urgency to fix this in QEMU.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Maybe we can address this in the 8.1 development window.

Why "maybe"? Eric is working on a patch I don't see why we won't address it.

I am not opposed to addressing it. I just think it might be too risky for 8.0 given that we are already past the hard feature freeze date.

This does not look to me like a justified change for 8.0. We have rev = 1 for years.

Signature · 1 line
MST
#20 lore raw
In reply to Michael S. Tsirkin
Quoted 4 lines · On Wed, 29 Mar 2023 12:47:05 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Eric DeVolder

On 3/29/23 00:19, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Don't much care. x-madt-rev?

if it works fine (cold & hot-plug) with older linux/windows guests I'd rather avoid adding compat knob (we typically do that in ACPI tables only when change breaks something).

(as old guest I'd define WinXP sp3 (/me wonders if we still care about dead EOLed OS) perhaps WS2008 would be a better minimum target these days and RHEL6 (or some older ACPI enabled kernel with hotplug support))

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Eric DeVolder
Quoted 3 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Great! Maybe stick a Link: tag in the commit log.

So it's guest bug which is in process of being fixed. (i.e. QEMU technically correct as long as MADT revision < 5)

In this case I'd not touch x86 MADT at all (It should be upto downstream distros to fix guest kernel).

Probably the same applies to ARM variant
i.e. we should bump rev only when current one gets in the way (aka we are pulling in new fields/definitions from new version)

Quoted 236 lines
Quoted 205 lines
Quoted 50 lines
Quoted 50 lines

As part of the investigation into resolving this breakage, I learned that i386 QEMU reports revision 1, while technically it is at revision 3. (Arm QEMU reports revision 4, and that is valid/correct.)

ACPI 6.3 bumps MADT revision to 5 as it introduces an Online Capable flag that the above Linux patch utilizes to denote hot pluggable CPUs.

So in order to bump MADT to the current revision of 5, need to validate that all MADT table changes between 1 and 5 are present in QEMU.

Below is a table summarizing the changes to the MADT. This information gleamed from the ACPI specs on uefi.org.

ACPI MADT What
Version Version

1.0             MADT not present
2.0     1       Section 5.2.10.4
3.0     2       Section 5.2.11.4

5.2.11.13 Local SAPIC Structure added two new fields:
ACPI Processor UID Value
ACPI Processor UID String
5.2.10.14 Platform Interrupt Sources Structure:
Reserved changed to Platform Interrupt Sources Flags
3.0b 2 Section 5.2.11.4
Added a section describing guidelines for the ordering of processors in the MADT to support proper boot processor and multi-threaded logical processor operation.
4.0 3 Section 5.2.12
Adds Processor Local x2APIC structure type 9 Adds Local x2APIC NMI structure type 0xA

5.0     3       Section 5.2.12
6.0     3       Section 5.2.12
6.0a    4       Section 5.2.12
                  Adds ARM GIC structure types 0xB-0xF
6.2a    45      Section 5.2.12   <--- yep it says version 45!
6.2b    5       Section 5.2.12

GIC ITS last Reserved offset changed to 16 from 20 (typo)
6.3 5 Section 5.2.12
Adds Local APIC Flags Online Capable!
Adds GICC SPE Overflow Interrupt field
6.4 5 Section 5.2.12
Adds Multiprocessor Wakeup Structure type 0x10 (change notes says structure previously misplaced?)
6.5 5 Section 5.2.12

For the MADT revision change 1 -> 2, the spec has a change to the SAPIC structure. In general, QEMU does not generate/support SAPIC. So the QEMU i386 MADT revision can safely be moved to 2.

Quoted 6 lines
Quoted 4 lines

For the MADT revision change 2 -> 3, the spec adds Local x2APIC structures. QEMU has long supported x2apic ACPI structures. A simple search of x2apic within QEMU source and hw/i386/acpi-common.c specifically reveals this.

But not unconditionally.

I don't think that reporting revision 3 requires that generation of x2apic; one could still see apic, x2apic, or sapic in theory. I realize qemu doesn't do sapic...

Quoted 134 lines
Quoted 134 lines

So the QEMU i386 MADT revision can safely
be moved to 3.

For the MADT revision change 3 -> 4, the spec adds support for the ARM GIC structures. QEMU ARM does in fact generate and report revision 4. As these will not be used by i386 QEMU, so then the QEMU i386 MADT revision can safely be moved to 4 as well.

Now for the MADT revision change 4 -> 5, the spec adds the Online Capable flag to the Local APIC structure, and the ARM GICC SPE Overflow Interrupt field.

For the ARM SPE, an existing 3-byte Reserved field is broken into a 1- byte Reserved field and a 2-byte SPE field. The spec says that is SPE Overflow is not supported, it should be zero.

For the i386 Local APIC flag Online Capable, the spec has certain rules about this value. And in particuar setting this value now explicitly indicates a hotpluggable CPU.

So this patch makes the needed changes to move both ARM and i386 MADT to revision 5. These are not complicated, thankfully.

Without these changes, the information below shows "how" CPU hotplug breaks with the current upstream Linux kernel 6.3. For example, a Linux guest started with:

qemu-system-x86_64 -smp 30,maxcpus=32 ...

and then attempting to hotplug a CPU:

   (QEMU) device_add id=cpu30 driver=host-x86_64-cpu socket-id=0 core-id=30 thread-id=0

fails with the following:

APIC: NR_CPUS/possible_cpus limit of 30 reached. Processor 30/0x.
ACPI: Unable to map lapic to logical cpu number
acpi LNXCPU:1e: Enumeration failure

   # dmesg | grep smpboot
   smpboot: Allowing 30 CPUs, 0 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x)
   smpboot: Max logical packages: 1
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)
   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000   4]                    Signature : "APIC"    [Multiple APIC Descript
   [004h 0004   4]                 Table Length : 00000170
   [008h 0008   1]                     Revision : 01          <=====
   [009h 0009   1]                     Checksum : 9C
   [00Ah 0010   6]                       Oem ID : "BOCHS "
   [010h 0016   8]                 Oem Table ID : "BXPC    "
   [018h 0024   4]                 Oem Revision : 00000001
   [01Ch 0028   4]              Asl Compiler ID : "BXPC"
   [020h 0032   4]        Asl Compiler Revision : 00000001

...

   [114h 0276   1]                Subtable Type : 00 [Processor Local APIC]
   [115h 0277   1]                       Length : 08
   [116h 0278   1]                 Processor ID : 1D
   [117h 0279   1]                Local Apic ID : 1D
   [118h 0280   4]        Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
   [11Ch 0284   1]                Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285   1]                       Length : 08
   [11Eh 0286   1]                 Processor ID : 1E
   [11Fh 0287   1]                Local Apic ID : 1E
   [120h 0288   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====
   [124h 0292   1]                Subtable Type : 00 [Processor Local APIC]
   [125h 0293   1]                       Length : 08
   [126h 0294   1]                 Processor ID : 1F
   [127h 0295   1]                Local Apic ID : 1F
   [128h 0296   4]        Flags (decoded below) : 00000000
                              Processor Enabled : 0          <=====

The (latest upstream) Linux kernel sees 30 Enabled processors, and does not consider processors 31 and 32 to be hotpluggable.

With this patch series applied, by bumping MADT to revision 5, the latest upstream Linux kernel correctly identifies 30 CPUs plus 2 hotpluggable CPUS.

   CPU30 has been hot-added
   smpboot: Booting Node 0 Processor 30 APIC 0x1e
   Will online and init hotplugged CPU: 30

   # dmesg | grep smpboot
   smpboot: Allowing 32 CPUs, 2 hotplug CPUs
   smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x6, model: 0x56, stepping: 0x3)
   smpboot: Max logical packages: 2
   smpboot: Total of 30 processors activated (125708.76 BogoMIPS)

   # iasl -d /sys/firmware/tables/acpi/APIC
   [000h 0000 004h]                   Signature : "APIC"    [Multiple APIC Descript
   [004h 0004 004h]                Table Length : 00000170
   [008h 0008 001h]                    Revision : 05          <=====
   [009h 0009 001h]                    Checksum : 94
   [00Ah 0010 006h]                      Oem ID : "BOCHS "
   [010h 0016 008h]                Oem Table ID : "BXPC    "
   [018h 0024 004h]                Oem Revision : 00000001
   [01Ch 0028 004h]             Asl Compiler ID : "BXPC"
   [020h 0032 004h]       Asl Compiler Revision : 00000001

   ...

   [114h 0276 001h]               Subtable Type : 00 [Processor Local APIC]
   [115h 0277 001h]                      Length : 08
   [116h 0278 001h]                Processor ID : 1D
   [117h 0279 001h]               Local Apic ID : 1D
   [118h 0280 004h]       Flags (decoded below) : 00000001
                              Processor Enabled : 1          <=====
                         Runtime Online Capable : 0          <=====

   [11Ch 0284 001h]               Subtable Type : 00 [Processor Local APIC]
   [11Dh 0285 001h]                      Length : 08
   [11Eh 0286 001h]                Processor ID : 1E
   [11Fh 0287 001h]               Local Apic ID : 1E
   [120h 0288 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====

   [124h 0292 001h]               Subtable Type : 00 [Processor Local APIC]
   [125h 0293 001h]                      Length : 08
   [126h 0294 001h]                Processor ID : 1F
   [127h 0295 001h]               Local Apic ID : 1F
   [128h 0296 004h]       Flags (decoded below) : 00000002
                              Processor Enabled : 0          <=====
                         Runtime Online Capable : 1          <=====
Quoted 4 lines
Quoted 2 lines

Regards,
Eric

Can you please report which guests were tested?

I've been using primarily upstream Linux. Kernels at and before 6.2.0 didn't have the "broken" patch mentioned above, and worked (for the reasons cited in the patch discussion to "fix" that patch). Any kernel since has the "broken" patch and will exhibit the issue.

Quoted 8 lines

I've been using q35.

If there are other samples you'd like to see, let me know and I'll try.

Also, my responses will be delayed as I'm traveling the remainder of the week.

Thanks!
eric

As a minimum some windows versions. The older the better.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

Eric DeVolder (2):
hw/acpi: arm: bump MADT to revision 5
hw/acpi: i386: bump MADT to revision 5

  hw/arm/virt-acpi-build.c |  6 ++++--
  hw/i386/acpi-common.c    | 13 ++++++++++---
  2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
#21 lore raw

I'm back from travel and catching up. More info below. eric

Quoted 16 lines · Igor Mammedov
Quoted 4 lines · On Wed, 29 Mar 2023 12:47:05 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 3 lines · Eric DeVolder

On 3/29/23 00:19, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Hmm I don't think we can reasonably make such a change for 8.0. Seems too risky.
Also, I feel we want to have an internal (with "x-" prefix") flag to revert to old behaviour, in case of breakage on some guests. and maybe we want to keep old revision for old machine types.

Ok, what option name, for keeping old behavior, would you like?

Don't much care. x-madt-rev?

Quoted 7 lines

if it works fine (cold & hot-plug) with older linux/windows guests I'd rather avoid adding compat knob (we typically do that in ACPI tables only when change breaks something).

(as old guest I'd define WinXP sp3 (/me wonders if we still care about dead EOLed OS) perhaps WS2008 would be a better minimum target these days and RHEL6 (or some older ACPI enabled kernel with hotplug support))

Thus far I've tested this patch series with the following guests. In both cases below, the guest started with -smp 8,maxcpus=16, and I simply attempted to hot plug and unplug cpu8, with: device_add id=cpu8 driver=host-x86_64-cpu socket-id=0 core-id=8 thread-id=0.

1) Windows Server 2008.
In Windows, after logging-in, I close the first full-screen window and then "Server Manager" window pops up. I navigate to left hand pane and choose Diagnostics -> Device Manager -> Processors. I count them before and after.
When hotplugging a cpu, you can see the new processor show up in the processor list. That is, it goes from 8 to 9.
When hot unplugging the CPU, Windows refuses:

The 'Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz' device is not removable and cannot be ejected or unplugged.

2) RHEL 6.9
From dmesg:
ACPI: APIC 000000007ffe32f0 000F0 (v05 BOCHS BXPC 00000001 BXPC 00000001)
SMP: Allowing 16 CPUs, 8 hotplug CPUs

 # cat /sys/devices/system/cpu/online
 0-7

(QEMU) device_add ...

CPU 8 got hotplugged
Booting Node 0 Processor 8 APIC 0x8
kvm-clock: cpu 8, msr 2830ed00
Will online and init hotplugged CPU: 8
microcode: CPU8 sig=0x50663, pf=0x1, revision=0x700001c platform microcode: firmware: requesting intel-ucode/06-56-03

 # cat /sys/devices/system/cpu/online
 0-8

(QEMU) device_del ...

Broke affinity for irq 24
CPU 8 is now offline

 # cat /sys/devices/system/cpu/online
 0-7

RHEL 6.9
kernel 2.6.32-696.el6.x86_64
build Feb 21 2017

So with these two older guest OS, it appears to still work. If there are others to be tested, let me know.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Eric DeVolder
Quoted 3 lines

The following Linux kernel change broke CPU hotplug for MADT revision less than 5.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

commit e2869bd7af60 ("x86/acpi/boot: Do not register processors that cannot be onlined for x2APIC")

Presumably it's being fixed? Link to discussion? Patch fixing that in Linux?

https://lore.kernel.org/linux-acpi/[email protected]/T/#t

Great! Maybe stick a Link: tag in the commit log.

Sure, will include that with v2.

Quoted 3 lines

So it's guest bug which is in process of being fixed. (i.e. QEMU technically correct as long as MADT revision < 5)

Iiuc, if QEMU generates x2apic tables with .revision = 1, that is not correct (as x2APIC shows up in .revision=3).
But if QEMU generates, apic, sapic, or x2apic tables with .revision = 5, that is correct (as all are valid options thru .revision 5).

Quoted 3 lines

In this case I'd not touch x86 MADT at all (It should be upto downstream distros to fix guest kernel).

Fwiw, this has been fixed and should show up in 6.3-rc6 this weekend.

Quoted 243 lines

Probably the same applies to ARM variant
i.e. we should bump rev only when current one gets in the way (aka we are pulling in new fields/definitions from new version)

Quoted 236 lines
Quoted 205 lines
Quoted 50 lines
Quoted 50 lines

As part of the investigation into resolving this breakage, I learned that i386 QEMU reports revision 1, while technically it is at revision 3. (Arm QEMU reports revision 4, and that is valid/correct.)

ACPI 6.3 bumps MADT revision to 5 as it introduces an Online Capable flag that the above Linux patch utilizes to denote hot pluggable CPUs.

So in order to bump MADT to the current revision of 5, need to validate that all MADT table changes between 1 and 5 are present in QEMU.

Below is a table summarizing the changes to the MADT. This information gleamed from the ACPI specs on uefi.org.

ACPI MADT What
Version Version

1.0             MADT not present
2.0     1       Section 5.2.10.4
3.0     2       Section 5.2.11.4

5.2.11.13 Local SAPIC Structure added two new fields:
ACPI Processor UID Value
ACPI Processor UID String
5.2.10.14 Platform Interrupt Sources Structure:
Reserved changed to Platform Interrupt Sources Flags
3.0b 2 Section 5.2.11.4
Added a section describing guidelines for the ordering of processors in the MADT to support proper boot processor and multi-threaded logical processor operation.
4.0 3 Section 5.2.12
Adds Processor Local x2APIC structure type 9 Adds Local x2APIC NMI structure type 0xA

5.0     3       Section 5.2.12
6.0     3       Section 5.2.12
6.0a    4       Section 5.2.12
                   Adds ARM GIC structure types 0xB-0xF
6.2a    45      Section 5.2.12   <--- yep it says version 45!
6.2b    5       Section 5.2.12

GIC ITS last Reserved offset changed to 16 from 20 (typo)
6.3 5 Section 5.2.12
Adds Local APIC Flags Online Capable!
Adds GICC SPE Overflow Interrupt field
6.4 5 Section 5.2.12
Adds Multiprocessor Wakeup Structure type 0x10 (change notes says structure previously misplaced?)
6.5 5 Section 5.2.12

For the MADT revision change 1 -> 2, the spec has a change to the SAPIC structure. In general, QEMU does not generate/support SAPIC. So the QEMU i386 MADT revision can safely be moved to 2.

Quoted 6 lines
Quoted 4 lines

For the MADT revision change 2 -> 3, the spec adds Local x2APIC structures. QEMU has long supported x2apic ACPI structures. A simple search of x2apic within QEMU source and hw/i386/acpi-common.c specifically reveals this.

But not unconditionally.

I don't think that reporting revision 3 requires that generation of x2apic; one could still see apic, x2apic, or sapic in theory. I realize qemu doesn't do sapic...

Quoted 134 lines
Quoted 134 lines

So the QEMU i386 MADT revision can safely
be moved to 3.

For the MADT revision change 3 -> 4, the spec adds support for the ARM GIC structures. QEMU ARM does in fact generate and report revision 4. As these will not be used by i386 QEMU, so then the QEMU i386 MADT revision can safely be moved to 4 as well.

Now for the MADT revision change 4 -> 5, the spec adds the Online Capable flag to the Local APIC structure, and the ARM GICC SPE Overflow Interrupt field.

For the ARM SPE, an existing 3-byte Reserved field is broken into a 1- byte Reserved field and a 2-byte SPE field. The spec says that is SPE Overflow is not supported, it should be zero.

For the i386 Local APIC flag Online Capable, the spec has certain rules about this value. And in particuar setting this value now explicitly indicates a hotpluggable CPU.

So this patch makes the needed changes to move both ARM and i386 MADT to revision 5. These are not complicated, thankfully.

Without these changes, the information below shows "how" CPU hotplug breaks with the current upstream Linux kernel 6.3. For example, a Linux guest started with:

   qemu-system-x86_64 -smp 30,maxcpus=32 ...

and then attempting to hotplug a CPU:

    (QEMU) device_add id=cpu30 driver=host-x86_64-cpu socket-id=0 core-id=30 thread-id=0

fails with the following:

APIC: NR_CPUS/possible_cpus limit of 30 reached. Processor 30/0x.
ACPI: Unable to map lapic to logical cpu number
acpi LNXCPU:1e: Enumeration failure

# dmesg | grep smpboot
smpboot: Allowing 30 CPUs, 0 hotplug CPUs
smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x)
smpboot: Max logical packages: 1
smpboot: Total of 30 processors activated (125708.76 BogoMIPS)

# iasl -d /sys/firmware/tables/acpi/APIC
[000h 0000 4] Signature : "APIC" [Multiple APIC Descript
[004h 0004 4] Table Length : 00000170
[008h 0008 1] Revision : 01 <=====
[009h 0009 1] Checksum : 9C
[00Ah 0010 6] Oem ID : "BOCHS "
[010h 0016 8] Oem Table ID : "BXPC "
[018h 0024 4] Oem Revision : 00000001
[01Ch 0028 4] Asl Compiler ID : "BXPC"
[020h 0032 4] Asl Compiler Revision : 00000001

...

[114h 0276 1] Subtable Type : 00 [Processor Local APIC]
[115h 0277 1] Length : 08
[116h 0278 1] Processor ID : 1D
[117h 0279 1] Local Apic ID : 1D
[118h 0280 4] Flags (decoded below) : 00000001
Processor Enabled : 1 <=====

[11Ch 0284 1] Subtable Type : 00 [Processor Local APIC]
[11Dh 0285 1] Length : 08
[11Eh 0286 1] Processor ID : 1E
[11Fh 0287 1] Local Apic ID : 1E
[120h 0288 4] Flags (decoded below) : 00000000
Processor Enabled : 0 <=====

[124h 0292 1] Subtable Type : 00 [Processor Local APIC]
[125h 0293 1] Length : 08
[126h 0294 1] Processor ID : 1F
[127h 0295 1] Local Apic ID : 1F
[128h 0296 4] Flags (decoded below) : 00000000
Processor Enabled : 0 <=====

The (latest upstream) Linux kernel sees 30 Enabled processors, and does not consider processors 31 and 32 to be hotpluggable.

With this patch series applied, by bumping MADT to revision 5, the latest upstream Linux kernel correctly identifies 30 CPUs plus 2 hotpluggable CPUS.

    CPU30 has been hot-added
    smpboot: Booting Node 0 Processor 30 APIC 0x1e
    Will online and init hotplugged CPU: 30

    # dmesg | grep smpboot
    smpboot: Allowing 32 CPUs, 2 hotplug CPUs
    smpboot: CPU0: Intel(R) Xeon(R) CPU D-1533 @ 2.10GHz (family: 0x6, model: 0x56, stepping: 0x3)
    smpboot: Max logical packages: 2
    smpboot: Total of 30 processors activated (125708.76 BogoMIPS)

    # iasl -d /sys/firmware/tables/acpi/APIC
    [000h 0000 004h]                   Signature : "APIC"    [Multiple APIC Descript
    [004h 0004 004h]                Table Length : 00000170
    [008h 0008 001h]                    Revision : 05          <=====
    [009h 0009 001h]                    Checksum : 94
    [00Ah 0010 006h]                      Oem ID : "BOCHS "
    [010h 0016 008h]                Oem Table ID : "BXPC    "
    [018h 0024 004h]                Oem Revision : 00000001
    [01Ch 0028 004h]             Asl Compiler ID : "BXPC"
    [020h 0032 004h]       Asl Compiler Revision : 00000001

    ...

    [114h 0276 001h]               Subtable Type : 00 [Processor Local APIC]
    [115h 0277 001h]                      Length : 08
    [116h 0278 001h]                Processor ID : 1D
    [117h 0279 001h]               Local Apic ID : 1D
    [118h 0280 004h]       Flags (decoded below) : 00000001
                               Processor Enabled : 1          <=====
                          Runtime Online Capable : 0          <=====

    [11Ch 0284 001h]               Subtable Type : 00 [Processor Local APIC]
    [11Dh 0285 001h]                      Length : 08
    [11Eh 0286 001h]                Processor ID : 1E
    [11Fh 0287 001h]               Local Apic ID : 1E
    [120h 0288 004h]       Flags (decoded below) : 00000002
                               Processor Enabled : 0          <=====
                          Runtime Online Capable : 1          <=====

    [124h 0292 001h]               Subtable Type : 00 [Processor Local APIC]
    [125h 0293 001h]                      Length : 08
    [126h 0294 001h]                Processor ID : 1F
    [127h 0295 001h]               Local Apic ID : 1F
    [128h 0296 004h]       Flags (decoded below) : 00000002
                               Processor Enabled : 0          <=====
                          Runtime Online Capable : 1          <=====
Quoted 4 lines
Quoted 2 lines

Regards,
Eric

Can you please report which guests were tested?

I've been using primarily upstream Linux. Kernels at and before 6.2.0 didn't have the "broken" patch mentioned above, and worked (for the reasons cited in the patch discussion to "fix" that patch). Any kernel since has the "broken" patch and will exhibit the issue.

Quoted 8 lines

I've been using q35.

If there are other samples you'd like to see, let me know and I'll try.

Also, my responses will be delayed as I'm traveling the remainder of the week.

Thanks!
eric

As a minimum some windows versions. The older the better.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

Eric DeVolder (2):
hw/acpi: arm: bump MADT to revision 5
hw/acpi: i386: bump MADT to revision 5

   hw/arm/virt-acpi-build.c |  6 ++++--
   hw/i386/acpi-common.c    | 13 ++++++++++---
   2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1