Skip to contentSkip to conversation

x86/cpu: initialize SMM cpu address space for hotplugged cpus

PATCH NAK Xiaoyao Li 3 participants 6 messages Oct 14, 2025 – Oct 16, 2025

lore
Share & tools
lore

Xiaoyao Li

author
#0 lore raw

cover x86/cpu: initialize SMM cpu address space for hotplugged cpus

(Sorry for being late to post the fixing patch, due to Chinese National holiday.)

Patch 1 fixes the issue reported by Peter that hotplugged cpu doesn't get SMM cpu addresspace initialized.

Patch 2 "fixes" the part that was missed when the original patch got merged.

Xiaoyao Li (2):
i386/kvm/cpu: Init SMM cpu address space for hotplugged CPUs target/i386: Use X86ASIdx_MEM in kvm_init()

 accel/kvm/kvm-all.c        |  2 +-
 hw/i386/x86-common.c       | 11 +++++++++++
 target/i386/kvm/kvm.c      |  6 ++++++
 target/i386/kvm/kvm_i386.h |  1 +
 4 files changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 i386/kvm/cpu: Init SMM cpu address space for hotplugged CPUs

The SMM cpu address space is initialized in a machine_init_done notifier. It only runs once when QEMU starts up, which leads to the issue that for any hotplugged CPU after the machine is ready, SMM cpu address space doesn't get initialized.

Fix the issue by initializing the SMM cpu address space in x86_cpu_plug() when the cpu is hotplugged.

---
 hw/i386/x86-common.c       | 11 +++++++++++
 target/i386/kvm/kvm.c      |  6 ++++++
 target/i386/kvm/kvm_i386.h |  1 +
 3 files changed, 18 insertions(+)
hw/i386/x86-common.c +11 -0
index 7512be64d67b..dd6ac3f3b741 100644
@@ -183,6 +183,17 @@ void x86_cpu_plug(HotplugHandler *hotplug_dev,
         fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus);
     }
 
+    /*
+     * Non-hotplugged CPUs get their SMM cpu address space initialized in
+     * machine init done notifier: register_smram_listener().
+     *
+     * We need initialize the SMM cpu address space for the hotplugged CPU
+     * specifically.
+     */
+    if (dev->hotplugged && kvm_enabled() && x86_machine_is_smm_enabled(x86ms)) {
+        kvm_smm_cpu_address_space_init(cpu);
+    }
+
     found_cpu = x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, NULL);
     found_cpu->cpu = CPU(dev);
 out:
target/i386/kvm/kvm.c +6 -0
index db40caa3412f..c339d8c84434 100644
@@ -2731,6 +2731,12 @@ static void register_smram_listener(Notifier *n, void *unused)
     }
 }
 
+/* It should only be called in cpu's hotplug callback */
+void kvm_smm_cpu_address_space_init(X86CPU *cpu)
+{
+    cpu_address_space_init(CPU(cpu), X86ASIdx_SMM, "cpu-smm", &smram_as_root);
+}
+
 static void *kvm_msr_energy_thread(void *data)
 {
     KVMState *s = data;
target/i386/kvm/kvm_i386.h +1 -0
index 5f83e8850a2b..35017ba07a4a 100644
@@ -74,6 +74,7 @@ uint32_t kvm_x86_build_cpuid(CPUX86State *env, struct kvm_cpuid_entry2 *entries,
                              uint32_t cpuid_i);
 #endif /* CONFIG_KVM */
 
+void kvm_smm_cpu_address_space_init(X86CPU *cpu);
 void kvm_pc_setup_irq_routing(bool pci_enabled);
 
 #endif
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/2 target/i386: Use X86ASIdx_MEM in kvm_init()

In reply to Xiaoyao Li

When the patch introduces 'enum X86ADIdx'[0] got merged, it somehow missed the change to replace as id 0 with X86ASIdx_MEM in kvm_init().

Change the leftover in kvm_init() to make the usage consistent.

[0] https://lore.kernel.org/qemu-devel/[email protected]/

---
 accel/kvm/kvm-all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
accel/kvm/kvm-all.c +1 -1
index 58802f7c3cc1..3030c47d55b1 100644
@@ -2800,7 +2800,7 @@ static int kvm_init(AccelState *as, MachineState *ms)
     s->memory_listener.listener.coalesced_io_del = kvm_uncoalesce_mmio_region;
 
     kvm_memory_listener_register(s, &s->memory_listener,
-                                 &address_space_memory, 0, "kvm-memory");
+                                 &address_space_memory, X86ASIdx_MEM, "kvm-memory");
     memory_listener_register(&kvm_io_listener,
                              &address_space_io);
 
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init()

Quoted 17 lines · Xiaoyao Li

When the patch introduces 'enum X86ADIdx'[0] got merged, it somehow missed the change to replace as id 0 with X86ASIdx_MEM in kvm_init().

Change the leftover in kvm_init() to make the usage consistent.

[0] https://lore.kernel.org/qemu-devel/[email protected]/

---
  accel/kvm/kvm-all.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
accel/kvm/kvm-all.c +0 -0
index 58802f7c3cc1..3030c47d55b1 100644

accel/kvm/kvm-all.c static int kvm_init(AccelState *as, MachineState *ms) · line 2803

Quoted 5 lines
accel/kvm/kvm-all.c +1 -1
@@ -2800,7 +2800,7 @@ static int kvm_init(AccelState *as, MachineState *ms)
      s->memory_listener.listener.coalesced_io_del = kvm_uncoalesce_mmio_region;
 
      kvm_memory_listener_register(s, &s->memory_listener,
-                                 &address_space_memory, 0, "kvm-memory");
+                                 &address_space_memory, X86ASIdx_MEM, "kvm-memory");

NAck: this is a generic code use by multiple architectures.

#4 lore raw

Re: [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init()

Quoted 3 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Xiaoyao Li

When the patch introduces 'enum X86ADIdx'[0] got merged, it somehow missed the change to replace as id 0 with X86ASIdx_MEM in kvm_init().

It wasn't missed, it broke CI. ;)

Paolo

Quoted 25 lines
Quoted 14 lines

Change the leftover in kvm_init() to make the usage consistent.

[0] https://lore.kernel.org/qemu-devel/20250730095253.1833411-3- [email protected]/

---
  accel/kvm/kvm-all.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
accel/kvm/kvm-all.c +0 -0
index 58802f7c3cc1..3030c47d55b1 100644

accel/kvm/kvm-all.c static int kvm_init(AccelState *as, MachineState · line 2805

Quoted 7 lines
accel/kvm/kvm-all.c +1 -1
@@ -2800,7 +2800,7 @@ static int kvm_init(AccelState *as, MachineState 
 *ms)
       s->memory_listener.listener.coalesced_io_del = kvm_uncoalesce_mmio_region;
       kvm_memory_listener_register(s, &s->memory_listener,
-                                 &address_space_memory, 0, "kvm- 
 memory");
+                                 &address_space_memory, X86ASIdx_MEM, 
 "kvm-memory");

NAck: this is a generic code use by multiple architectures.

author
#5 lore raw

Re: [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init()

Quoted 6 lines · Paolo Bonzini
Quoted 3 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Xiaoyao Li

When the patch introduces 'enum X86ADIdx'[0] got merged, it somehow missed the change to replace as id 0 with X86ASIdx_MEM in kvm_init().

It wasn't missed, it broke CI. ;)

I see.

I missed the fact that Philippe pointed out:

this is a generic code use by multiple architectures.

Sorry for the wrong patch.

Quoted 28 lines

Paolo

Quoted 25 lines
Quoted 14 lines

Change the leftover in kvm_init() to make the usage consistent.

[0] https://lore.kernel.org/qemu-devel/20250730095253.1833411-3- [email protected]/

---
  accel/kvm/kvm-all.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
accel/kvm/kvm-all.c +0 -0
index 58802f7c3cc1..3030c47d55b1 100644

accel/kvm/kvm-all.c static int kvm_init(AccelState *as, · line 2805

Quoted 7 lines
accel/kvm/kvm-all.c +1 -1
@@ -2800,7 +2800,7 @@ static int kvm_init(AccelState *as, 
 MachineState *ms)
       s->memory_listener.listener.coalesced_io_del = kvm_uncoalesce_mmio_region;
       kvm_memory_listener_register(s, &s->memory_listener,
-                                 &address_space_memory, 0, "kvm- 
 memory");
+                                 &address_space_memory, 
 X86ASIdx_MEM, "kvm-memory");

NAck: this is a generic code use by multiple architectures.