* [PATCH 0/2] x86/cpu: initialize SMM cpu address space for hotplugged cpus @ 2025-10-14 9:42 Xiaoyao Li 2025-10-14 9:42 ` [PATCH 1/2] i386/kvm/cpu: Init SMM cpu address space for hotplugged CPUs Xiaoyao Li 2025-10-14 9:42 ` [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() Xiaoyao Li 0 siblings, 2 replies; 6+ messages in thread From: Xiaoyao Li @ 2025-10-14 9:42 UTC (permalink / raw) To: Paolo Bonzini, Peter Maydell; +Cc: qemu-devel, Xiaoyao Li (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(-) -- 2.43.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] i386/kvm/cpu: Init SMM cpu address space for hotplugged CPUs 2025-10-14 9:42 [PATCH 0/2] x86/cpu: initialize SMM cpu address space for hotplugged cpus Xiaoyao Li @ 2025-10-14 9:42 ` Xiaoyao Li 2025-10-14 9:42 ` [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() Xiaoyao Li 1 sibling, 0 replies; 6+ messages in thread From: Xiaoyao Li @ 2025-10-14 9:42 UTC (permalink / raw) To: Paolo Bonzini, Peter Maydell; +Cc: qemu-devel, Xiaoyao Li 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. Fixes: 591f817d819f ("target/i386: Define enum X86ASIdx for x86's address spaces") Reported-by: Peter Maydell <peter.maydell@linaro.org> Closes: https://lore.kernel.org/qemu-devel/CAFEAcA_3kkZ+a5rTZGmK8W5K6J7qpYD31HkvjBnxWr-fGT2h_A@mail.gmail.com/ Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> --- hw/i386/x86-common.c | 11 +++++++++++ target/i386/kvm/kvm.c | 6 ++++++ target/i386/kvm/kvm_i386.h | 1 + 3 files changed, 18 insertions(+) diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c index 7512be64d67b..dd6ac3f3b741 100644 --- a/hw/i386/x86-common.c +++ b/hw/i386/x86-common.c @@ -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: diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index db40caa3412f..c339d8c84434 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -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; diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index 5f83e8850a2b..35017ba07a4a 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -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 -- 2.43.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() 2025-10-14 9:42 [PATCH 0/2] x86/cpu: initialize SMM cpu address space for hotplugged cpus Xiaoyao Li 2025-10-14 9:42 ` [PATCH 1/2] i386/kvm/cpu: Init SMM cpu address space for hotplugged CPUs Xiaoyao Li @ 2025-10-14 9:42 ` Xiaoyao Li 2025-10-16 8:43 ` Philippe Mathieu-Daudé 1 sibling, 1 reply; 6+ messages in thread From: Xiaoyao Li @ 2025-10-14 9:42 UTC (permalink / raw) To: Paolo Bonzini, Peter Maydell; +Cc: qemu-devel, 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/20250730095253.1833411-3-xiaoyao.li@intel.com/ Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> --- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 58802f7c3cc1..3030c47d55b1 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -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); -- 2.43.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() 2025-10-14 9:42 ` [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() Xiaoyao Li @ 2025-10-16 8:43 ` Philippe Mathieu-Daudé 2025-10-16 9:23 ` Paolo Bonzini 0 siblings, 1 reply; 6+ messages in thread From: Philippe Mathieu-Daudé @ 2025-10-16 8:43 UTC (permalink / raw) To: Xiaoyao Li, Paolo Bonzini, Peter Maydell; +Cc: qemu-devel On 14/10/25 11:42, Xiaoyao Li wrote: > 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/20250730095253.1833411-3-xiaoyao.li@intel.com/ > > Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> > --- > accel/kvm/kvm-all.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c > index 58802f7c3cc1..3030c47d55b1 100644 > --- a/accel/kvm/kvm-all.c > +++ b/accel/kvm/kvm-all.c > @@ -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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() 2025-10-16 8:43 ` Philippe Mathieu-Daudé @ 2025-10-16 9:23 ` Paolo Bonzini 2025-10-16 9:46 ` Xiaoyao Li 0 siblings, 1 reply; 6+ messages in thread From: Paolo Bonzini @ 2025-10-16 9:23 UTC (permalink / raw) To: Philippe Mathieu-Daudé, Xiaoyao Li, Peter Maydell; +Cc: qemu-devel On 10/16/25 10:43, Philippe Mathieu-Daudé wrote: > On 14/10/25 11:42, Xiaoyao Li wrote: >> 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 >> Change the leftover in kvm_init() to make the usage consistent. >> >> [0] https://lore.kernel.org/qemu-devel/20250730095253.1833411-3- >> xiaoyao.li@intel.com/ >> >> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> >> --- >> accel/kvm/kvm-all.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c >> index 58802f7c3cc1..3030c47d55b1 100644 >> --- a/accel/kvm/kvm-all.c >> +++ b/accel/kvm/kvm-all.c >> @@ -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. > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() 2025-10-16 9:23 ` Paolo Bonzini @ 2025-10-16 9:46 ` Xiaoyao Li 0 siblings, 0 replies; 6+ messages in thread From: Xiaoyao Li @ 2025-10-16 9:46 UTC (permalink / raw) To: Paolo Bonzini, Philippe Mathieu-Daudé, Peter Maydell; +Cc: qemu-devel On 10/16/2025 5:23 PM, Paolo Bonzini wrote: > On 10/16/25 10:43, Philippe Mathieu-Daudé wrote: >> On 14/10/25 11:42, Xiaoyao Li wrote: >>> 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. > Paolo > >>> Change the leftover in kvm_init() to make the usage consistent. >>> >>> [0] https://lore.kernel.org/qemu-devel/20250730095253.1833411-3- >>> xiaoyao.li@intel.com/ >>> >>> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com> >>> --- >>> accel/kvm/kvm-all.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c >>> index 58802f7c3cc1..3030c47d55b1 100644 >>> --- a/accel/kvm/kvm-all.c >>> +++ b/accel/kvm/kvm-all.c >>> @@ -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. >> >> > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-10-16 9:47 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-10-14 9:42 [PATCH 0/2] x86/cpu: initialize SMM cpu address space for hotplugged cpus Xiaoyao Li 2025-10-14 9:42 ` [PATCH 1/2] i386/kvm/cpu: Init SMM cpu address space for hotplugged CPUs Xiaoyao Li 2025-10-14 9:42 ` [PATCH 2/2] target/i386: Use X86ASIdx_MEM in kvm_init() Xiaoyao Li 2025-10-16 8:43 ` Philippe Mathieu-Daudé 2025-10-16 9:23 ` Paolo Bonzini 2025-10-16 9:46 ` Xiaoyao Li
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).