Add architecture agnostic code to support vCPU Hotplug
v7 cover Add architecture agnostic code to support vCPU Hotplug
Virtual CPU hotplug support is being added across various architectures[1][3]. This series adds various code bits common across all architectures:
1. vCPU creation and Parking code refactor [Patch 1]
2. Update ACPI GED framework to support vCPU Hotplug [Patch 2,3]
3. ACPI CPUs AML code change [Patch 4,5]
4. Helper functions to support unrealization of CPU objects [Patch 6,7]
5. Docs [Patch 8]
Repository:
[*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v7
Revision History:
Patch-set V6 -> V7
1. Addressed Alex Bennée's comments
- Updated the docs
2. Addressed Igor Mammedov's comments
- Merged patches [Patch V6 3/9] & [Patch V6 7/9] with [Patch V6 4/9]
- Updated commit-log of [Patch V6 1/9] and [Patch V6 5/9]
3. Added Shaoqin Huang's Reviewed-by tags for whole series.
Patch-set V5 -> V6
1. Addressed Gavin Shan's comments
- Fixed the assert() ranges of address spaces
- Rebased the patch-set to latest changes in the qemu.git
- Added Reviewed-by tags for patches {8,9}
2. Addressed Jonathan Cameron's comments
- Updated commit-log for [Patch V5 1/9] with mention of trace events
- Added Reviewed-by tags for patches {1,5}
3. Added Tested-by tags from Xianglai Li
4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9]
Patch-set V4 -> V5
1. Addressed Gavin Shan's comments
- Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
- Added Reviewed-by tag for patch {1}
2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
4. Dropped the ARM specific [Patch V4 10/10]
Patch-set V3 -> V4
1. Addressed David Hilderbrand's comments
- Fixed the wrong doc comment of kvm_park_vcpu API prototype
- Added Reviewed-by tags for patches {2,4}
Patch-set V2 -> V3
1. Addressed Jonathan Cameron's comments
- Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
- Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
- Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
- Updated [Patch V2 5/10] commit-log with details of conditional event handler method
- Added Reviewed-by tags for patches {2,3,4,6,7}
2. Addressed Gavin Shan's comments
- Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
- Fixed return value in kvm_get_vcpu from -1 to -ENOENT
- Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
- Fixed the kvm_{create,park}_vcpu prototypes docs
- Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
3. Addressed one earlier missed comment by Alex Bennée in RFC V1
- Added traces instead of DPRINTF in the newly added and some existing functions
Patch-set V1 -> V2
1. Addressed Alex Bennée's comments
- Refactored the kvm_create_vcpu logic to get rid of goto
- Added the docs for kvm_{create,park}_vcpu prototypes
- Splitted the gdbstub and AddressSpace destruction change into separate patches
- Added Reviewed-by tags for patches {2,10}
References:
[1] https://lore.kernel.org/qemu-devel/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/qemu-devel/[email protected]/
Salil Mehta (8):
accel/kvm: Extract common KVM vCPU {creation,parking} code hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file hw/acpi: Update ACPI GED framework to support vCPU Hotplug hw/acpi: Update GED _EVT method AML with CPU scan
hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
physmem: Add helper function to destroy CPU AddressSpace
gdbstub: Add helper function to unregister GDB register space docs/specs/acpi_hw_reduced_hotplug: Add the CPU Hotplug Event Bit
accel/kvm/kvm-all.c | 64 ++++++++++++++++++++------ accel/kvm/trace-events | 4 ++ docs/specs/acpi_hw_reduced_hotplug.rst | 3 +- gdbstub/gdbstub.c | 12 +++++ hw/acpi/acpi-cpu-hotplug-stub.c | 6 +++ hw/acpi/cpu.c | 27 +++++++---- hw/acpi/generic_event_device.c | 21 +++++++++ hw/i386/acpi-build.c | 3 +- include/exec/cpu-common.h | 8 ++++ include/exec/gdbstub.h | 5 ++ include/hw/acpi/cpu.h | 5 +- include/hw/acpi/cpu_hotplug.h | 4 ++ include/hw/acpi/generic_event_device.h | 4 ++ include/hw/core/cpu.h | 1 + include/sysemu/kvm.h | 16 +++++++ system/physmem.c | 29 ++++++++++++ 16 files changed, 184 insertions(+), 28 deletions(-)
Signature · 1 line
2.34.1
PATCH v7 1/8 accel/kvm: Extract common KVM vCPU {creation,parking} code
KVM vCPU creation is done once during the vCPU realization when Qemu vCPU thread is spawned. This is common to all the architectures as of now.
Hot-unplug of vCPU results in destruction of the vCPU object in QOM but the corresponding KVM vCPU object in the Host KVM is not destroyed as KVM doesn't support vCPU removal. Therefore, its representative KVM vCPU object/context in Qemu is parked.
Refactor architecture common logic so that some APIs could be reused by vCPU Hotplug code of some architectures likes ARM, Loongson etc. Update new/old APIs with trace events instead of DPRINTF. No functional change is intended here.
--- accel/kvm/kvm-all.c | 64 ++++++++++++++++++++++++++++++++---------- accel/kvm/trace-events | 4 +++ include/sysemu/kvm.h | 16 +++++++++++ 3 files changed, 69 insertions(+), 15 deletions(-)
accel/kvm/kvm-all.c +49 -15
@@ -137,6 +137,7 @@ static QemuMutex kml_slots_lock;#define kvm_slots_unlock () qemu_mutex_unlock(&kml_slots_lock)static void kvm_slot_init_dirty_bitmap (KVMSlot *mem); +static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {
@@ -320,14 +321,53 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu) +{ +struct KVMParkedVcpu *vcpu; + +trace_kvm_park_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id =kvm_arch_vcpu_id (cpu); + vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} + +int kvm_create_vcpu (CPUState *cpu) +{ +unsigned long vcpu_id =kvm_arch_vcpu_id (cpu); +KVMState *s = kvm_state; +int kvm_fd; + +trace_kvm_create_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); + +/* check if the KVM vCPU already exist but is parked */ + kvm_fd =kvm_get_vcpu (s, vcpu_id); +if (kvm_fd <0 ) { +/* vCPU not parked: create a new KVM vCPU */ + kvm_fd =kvm_vm_ioctl (s,KVM_CREATE_VCPU , vcpu_id); +if (kvm_fd <0 ) { +error_report ("KVM_CREATE_VCPU IOCTL failed for vCPU %lu" , vcpu_id); +return kvm_fd; + } + } + + cpu->kvm_fd = kvm_fd; + cpu->kvm_state = s; + cpu->vcpu_dirty = true; + cpu->dirty_pages =0 ; + cpu->throttle_us_per_full =0 ; + +return 0 ; +} +static int do_kvm_destroy_vcpu (CPUState *cpu) {KVMState *s = kvm_state;long mmap_size; -struct KVMParkedVcpu *vcpu =NULL ;int ret =0 ; -DPRINTF ("kvm_destroy_vcpu\n" ); +trace_kvm_destroy_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); ret =kvm_arch_destroy_vcpu (cpu);if (ret <0 ) {
@@ -353,10 +393,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu) } } - vcpu =g_malloc0 (sizeof (*vcpu)); - vcpu->vcpu_id =kvm_arch_vcpu_id (cpu); - vcpu->kvm_fd = cpu->kvm_fd; -QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +kvm_park_vcpu (cpu); err:return ret; }
@@ -377,6 +414,8 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)if (cpu->vcpu_id == vcpu_id) {int kvm_fd; +trace_kvm_get_vcpu (vcpu_id); +QLIST_REMOVE (cpu, node); kvm_fd = cpu->kvm_fd;g_free (cpu);
@@ -384,7 +423,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) } } -return kvm_vm_ioctl (s,KVM_CREATE_VCPU , (void *)vcpu_id); +return -ENOENT ; }int kvm_init_vcpu (CPUState *cpu,Error **errp)
@@ -395,19 +434,14 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)trace_kvm_init_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); - ret =kvm_get_vcpu (s,kvm_arch_vcpu_id (cpu)); + ret =kvm_create_vcpu (cpu);if (ret <0 ) { -error_setg_errno (errp, -ret,"kvm_init_vcpu: kvm_get_vcpu failed (%lu)" , +error_setg_errno (errp, -ret, +"kvm_init_vcpu: kvm_create_vcpu failed (%lu)" ,kvm_arch_vcpu_id (cpu)); goto err; } - cpu->kvm_fd = ret; - cpu->kvm_state = s; - cpu->vcpu_dirty = true; - cpu->dirty_pages =0 ; - cpu->throttle_us_per_full =0 ; - mmap_size =kvm_ioctl (s,KVM_GET_VCPU_MMAP_SIZE ,0 );if (mmap_size <0 ) { ret = mmap_size;
accel/kvm/trace-events +4 -0
@@ -9,6 +9,10 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p" kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s" kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s" kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" +kvm_create_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" +kvm_get_vcpu(unsigned long arch_cpu_id) "id: %lu" +kvm_destroy_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" +kvm_park_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" kvm_irqchip_commit_routes(void) "" kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d" kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
include/sysemu/kvm.h +16 -0
@@ -465,6 +465,22 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);int kvm_physical_memory_addr_from_host (KVMState *s,void *ram_addr,hwaddr *phys_addr); +/** +* kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU +* @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created. +* +* @returns: 0 when success, errno (<0) when failed. +*/ +int kvm_create_vcpu (CPUState *cpu); + +/** +* kvm_park_vcpu - Park QEMU KVM vCPU context +* @cpu: QOM CPUState object for which QEMU KVM vCPU context has to be parked. +* +* @returns: none +*/ +void kvm_park_vcpu (CPUState *cpu); +#endif /* NEED_CPU_H */ void kvm_cpu_synchronize_state (CPUState *cpu);
Signature · 1 line
2.34.1
Re: [PATCH V7 1/8] accel/kvm: Extract common KVM vCPU {creation,parking} code
Quoted 12 lines · On Mon, 13 Nov 2023 20:12:29 +0000 Salil Mehta <[email protected]> wrote:
KVM vCPU creation is done once during the vCPU realization when Qemu vCPU thread is spawned. This is common to all the architectures as of now.
Hot-unplug of vCPU results in destruction of the vCPU object in QOM but the corresponding KVM vCPU object in the Host KVM is not destroyed as KVM doesn't support vCPU removal. Therefore, its representative KVM vCPU object/context in Qemu is parked.
Refactor architecture common logic so that some APIs could be reused by vCPU Hotplug code of some architectures likes ARM, Loongson etc. Update new/old APIs with trace events instead of DPRINTF. No functional change is intended here.
Quoted 7 lines
Signed-off-by Salil Mehta <[email protected]>Reviewed-by Gavin Shan <[email protected]>Tested-by Vishnu Pajjuri <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Xianglai Li <[email protected]>Tested-by Miguel Luis <[email protected]>Reviewed-by Shaoqin Huang <[email protected]>
even though it will used by arm and loongarch later on with respective cpu hotplug series, it doesn't justify including refactoring without actual user.
(Put yourself in shoes of someone looking at git history and not finding a single user)
I'd suggest to include this patch in both (ARM & Loongson) CPU hotplug series, this way, whichever is merged 1st will get this patch in without causing conflicts.
Quoted 169 lines
--- accel/kvm/kvm-all.c | 64 ++++++++++++++++++++++++++++++++---------- accel/kvm/trace-events | 4 +++ include/sysemu/kvm.h | 16 +++++++++++ 3 files changed, 69 insertions(+), 15 deletions(-)accel/kvm/kvm-all.c +49
-15@@ -137,6 +137,7 @@ static QemuMutex kml_slots_lock;#define kvm_slots_unlock () qemu_mutex_unlock(&kml_slots_lock)static void kvm_slot_init_dirty_bitmap (KVMSlot *mem); +static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {@@ -320,14 +321,53 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu) +{ +struct KVMParkedVcpu *vcpu; + +trace_kvm_park_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id =kvm_arch_vcpu_id (cpu); + vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} + +int kvm_create_vcpu (CPUState *cpu) +{ +unsigned long vcpu_id =kvm_arch_vcpu_id (cpu); +KVMState *s = kvm_state; +int kvm_fd; + +trace_kvm_create_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); + +/* check if the KVM vCPU already exist but is parked */ + kvm_fd =kvm_get_vcpu (s, vcpu_id); +if (kvm_fd <0 ) { +/* vCPU not parked: create a new KVM vCPU */ + kvm_fd =kvm_vm_ioctl (s,KVM_CREATE_VCPU , vcpu_id); +if (kvm_fd <0 ) { +error_report ("KVM_CREATE_VCPU IOCTL failed for vCPU %lu" , vcpu_id); +return kvm_fd; + } + } + + cpu->kvm_fd = kvm_fd; + cpu->kvm_state = s; + cpu->vcpu_dirty = true; + cpu->dirty_pages =0 ; + cpu->throttle_us_per_full =0 ; + +return 0 ; +} +static int do_kvm_destroy_vcpu (CPUState *cpu) {KVMState *s = kvm_state;long mmap_size; -struct KVMParkedVcpu *vcpu =NULL ;int ret =0 ; -DPRINTF ("kvm_destroy_vcpu\n" ); +trace_kvm_destroy_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); ret =kvm_arch_destroy_vcpu (cpu);if (ret <0 ) {@@ -353,10 +393,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu) } } - vcpu =g_malloc0 (sizeof (*vcpu)); - vcpu->vcpu_id =kvm_arch_vcpu_id (cpu); - vcpu->kvm_fd = cpu->kvm_fd; -QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +kvm_park_vcpu (cpu); err:return ret; }@@ -377,6 +414,8 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)if (cpu->vcpu_id == vcpu_id) {int kvm_fd; +trace_kvm_get_vcpu (vcpu_id); +QLIST_REMOVE (cpu, node); kvm_fd = cpu->kvm_fd;g_free (cpu);@@ -384,7 +423,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) } } -return kvm_vm_ioctl (s,KVM_CREATE_VCPU , (void *)vcpu_id); +return -ENOENT ; }int kvm_init_vcpu (CPUState *cpu,Error **errp)@@ -395,19 +434,14 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)trace_kvm_init_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); - ret =kvm_get_vcpu (s,kvm_arch_vcpu_id (cpu)); + ret =kvm_create_vcpu (cpu);if (ret <0 ) { -error_setg_errno (errp, -ret,"kvm_init_vcpu: kvm_get_vcpu failed (%lu)" , +error_setg_errno (errp, -ret, +"kvm_init_vcpu: kvm_create_vcpu failed (%lu)" ,kvm_arch_vcpu_id (cpu)); goto err; } - cpu->kvm_fd = ret; - cpu->kvm_state = s; - cpu->vcpu_dirty = true; - cpu->dirty_pages =0 ; - cpu->throttle_us_per_full =0 ; - mmap_size =kvm_ioctl (s,KVM_GET_VCPU_MMAP_SIZE ,0 );if (mmap_size <0 ) { ret = mmap_size;accel/kvm/trace-events +4
-0@@ -9,6 +9,10 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p" kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s" kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s" kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" +kvm_create_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" +kvm_get_vcpu(unsigned long arch_cpu_id) "id: %lu" +kvm_destroy_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" +kvm_park_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu" kvm_irqchip_commit_routes(void) "" kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d" kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"include/sysemu/kvm.h +16
-0@@ -465,6 +465,22 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);int kvm_physical_memory_addr_from_host (KVMState *s,void *ram_addr,hwaddr *phys_addr); +/** +* kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU +* @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created. +* +* @returns: 0 when success, errno (<0) when failed. +*/ +int kvm_create_vcpu (CPUState *cpu); + +/** +* kvm_park_vcpu - Park QEMU KVM vCPU context +* @cpu: QOM CPUState object for which QEMU KVM vCPU context has to be parked. +* +* @returns: none +*/ +void kvm_park_vcpu (CPUState *cpu); +#endif /* NEED_CPU_H */ void kvm_cpu_synchronize_state (CPUState *cpu);
PATCH v7 2/8 hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
In reply to Salil MehtaCPU ctrl-dev MMIO region length could be used in ACPI GED and various other architecture specific places. Move ACPI_CPU_HOTPLUG_REG_LEN macro to more appropriate common header file.
--- hw/acpi/cpu.c | 2 +- include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
hw/acpi/cpu.c +1 -1
@@ -1,13 +1,13 @@#include "qemu/osdep.h" #include "migration/vmstate.h" #include "hw/acpi/cpu.h" +#include "hw/acpi/cpu_hotplug.h" #include "hw/core/cpu.h" #include "qapi/error.h" #include "qapi/qapi-events-acpi.h" #include "trace.h" #include "sysemu/numa.h" -#define ACPI_CPU_HOTPLUG_REG_LEN 12#define ACPI_CPU_SELECTOR_OFFSET_WR 0#define ACPI_CPU_FLAGS_OFFSET_RW 4#define ACPI_CPU_CMD_OFFSET_WR 5
include/hw/acpi/cpu_hotplug.h +2 -0
@@ -19,6 +19,8 @@#include "hw/hotplug.h" #include "hw/acpi/cpu.h" +#define ACPI_CPU_HOTPLUG_REG_LEN 12 + typedef struct AcpiCpuHotplug { Object *device; MemoryRegion io;
Signature · 1 line
2.34.1
Re: [PATCH V7 2/8] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
Quoted 13 lines · On Mon, 13 Nov 2023 20:12:30 +0000 Salil Mehta <[email protected]> wrote:
CPU ctrl-dev MMIO region length could be used in ACPI GED and various other architecture specific places. Move
ACPI_CPU_HOTPLUG_REG_LENmacro to more appropriate common header file.Signed-off-by Salil Mehta <[email protected]>Reviewed-by Alex Bennée <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Gavin Shan <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Shaoqin Huang <[email protected]>Tested-by Vishnu Pajjuri <[email protected]>Tested-by Xianglai Li <[email protected]>Tested-by Miguel Luis <[email protected]>
Quoted 3 lines
--- hw/acpi/cpu.c | 2 +- include/hw/acpi/cpu_hotplug.h | 2 ++
the header holds legacy stuff (mostly) and I'd say is destined for removal.
include/hw/acpi/cpu.h would be a better place for it.
Quoted 34 lines
2 files changed, 3 insertions(+), 1 deletion(-)hw/acpi/cpu.c +1
-1@@ -1,13 +1,13 @@#include "qemu/osdep.h" #include "migration/vmstate.h" #include "hw/acpi/cpu.h" +#include "hw/acpi/cpu_hotplug.h" #include "hw/core/cpu.h" #include "qapi/error.h" #include "qapi/qapi-events-acpi.h" #include "trace.h" #include "sysemu/numa.h" -#define ACPI_CPU_HOTPLUG_REG_LEN 12#define ACPI_CPU_SELECTOR_OFFSET_WR 0#define ACPI_CPU_FLAGS_OFFSET_RW 4#define ACPI_CPU_CMD_OFFSET_WR 5include/hw/acpi/cpu_hotplug.h +2
-0@@ -19,6 +19,8 @@#include "hw/hotplug.h" #include "hw/acpi/cpu.h" +#define ACPI_CPU_HOTPLUG_REG_LEN 12 + typedef struct AcpiCpuHotplug { Object *device; MemoryRegion io;
PATCH v7 3/8 hw/acpi: Update ACPI GED framework to support vCPU Hotplug
In reply to Salil MehtaACPI GED (as described in the ACPI 6.4 spec) uses an interrupt listed in the _CRS object of GED to intimate OSPM about an event. Later then demultiplexes the notified event by evaluating ACPI _EVT method to know the type of event. Use ACPI GED to also notify the guest kernel about any CPU hot(un)plug events.
ACPI CPU hotplug related initialization should only happen if ACPI_CPU_HOTPLUG support has been enabled for particular architecture. Add cpu_hotplug_hw_init() stub to avoid compilation break.
--- hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++ hw/acpi/generic_event_device.c | 17 +++++++++++++++++ include/hw/acpi/generic_event_device.h | 4 ++++ 3 files changed, 27 insertions(+)
hw/acpi/acpi-cpu-hotplug-stub.c +6 -0
@@ -19,6 +19,12 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,return ; } +void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner, +CPUHotplugState *state,hwaddr base_addr) +{ +return ; +} +void acpi_cpu_ospm_status (CPUHotplugState *cpu_st,ACPIOSTInfoList ***list) {return ;
hw/acpi/generic_event_device.c +17 -0
@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qapi/error.h" #include "hw/acpi/acpi.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/generic_event_device.h" #include "hw/irq.h" #include "hw/mem/pc-dimm.h"
@@ -25,6 +26,7 @@ static const uint32_t ged_supported_events[] = {ACPI_GED_MEM_HOTPLUG_EVT ,ACPI_GED_PWR_DOWN_EVT ,ACPI_GED_NVDIMM_HOTPLUG_EVT , + ACPI_GED_CPU_HOTPLUG_EVT, };/*
@@ -234,6 +236,8 @@ static void acpi_ged_device_plug_cb(HotplugHandler *hotplug_dev, }else {acpi_memory_plug_cb (hotplug_dev, &s->memhp_state, dev, errp); } + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +acpi_cpu_plug_cb (hotplug_dev, &s->cpuhp_state, dev, errp); }else {error_setg (errp,"virt: device plug request for unsupported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -248,6 +252,8 @@ static void acpi_ged_unplug_request_cb(HotplugHandler *hotplug_dev,if ((object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) && !(object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM )))) {acpi_memory_unplug_request_cb (hotplug_dev, &s->memhp_state, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +acpi_cpu_unplug_request_cb (hotplug_dev, &s->cpuhp_state, dev, errp); }else {error_setg (errp,"acpi: device unplug request for unsupported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -261,6 +267,8 @@ static void acpi_ged_unplug_cb(HotplugHandler *hotplug_dev,if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&s->memhp_state, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +acpi_cpu_unplug_cb (&s->cpuhp_state, dev, errp); }else {error_setg (errp,"acpi: device unplug for unsupported device" " type: %s" ,object_get_typename (OBJECT (dev)));
@@ -272,6 +280,7 @@ static void acpi_ged_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)AcpiGedState *s =ACPI_GED (adev);acpi_memory_ospm_status (&s->memhp_state, list); +acpi_cpu_ospm_status (&s->cpuhp_state, list); }static void acpi_ged_send_event (AcpiDeviceIf *adev,AcpiEventStatusBits ev)
@@ -286,6 +295,8 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) sel =ACPI_GED_PWR_DOWN_EVT ; }else if (ev &ACPI_NVDIMM_HOTPLUG_STATUS ) { sel =ACPI_GED_NVDIMM_HOTPLUG_EVT ; + }else if (ev &ACPI_CPU_HOTPLUG_STATUS ) { + sel =ACPI_GED_CPU_HOTPLUG_EVT ; }else {/* Unknown event. Return without generating interrupt. */ warn_report ("GED: Unsupported event %d. No irq injected" , ev);
@@ -400,6 +411,12 @@ static void acpi_ged_initfn(Object *obj)memory_region_init_io (&ged_st->regs, obj, &ged_regs_ops, ged_st,TYPE_ACPI_GED "-regs" ,ACPI_GED_REG_COUNT );sysbus_init_mmio (sbd, &ged_st->regs); + +memory_region_init (&s->container_cpuhp,OBJECT (dev),"cpuhp container" , +ACPI_CPU_HOTPLUG_REG_LEN ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->container_cpuhp); +cpu_hotplug_hw_init (&s->container_cpuhp,OBJECT (dev), + &s->cpuhp_state,0 ); }static void acpi_ged_class_init (ObjectClass *class,void *data)
include/hw/acpi/generic_event_device.h +4 -0
@@ -60,6 +60,7 @@#define HW_ACPI_GENERIC_EVENT_DEVICE_H #include "hw/sysbus.h" +#include "hw/acpi/cpu_hotplug.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/ghes.h" #include "qom/object.h"
@@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define ACPI_GED_MEM_HOTPLUG_EVT 0x1#define ACPI_GED_PWR_DOWN_EVT 0x2#define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4 +#define ACPI_GED_CPU_HOTPLUG_EVT 0x8 typedef struct GEDState { MemoryRegion evt;
@@ -106,6 +108,8 @@ struct AcpiGedState {SysBusDevice parent_obj;MemHotplugState memhp_state;MemoryRegion container_memhp; +CPUHotplugState cpuhp_state; +MemoryRegion container_cpuhp;GEDState ged_state;uint32_t ged_event_bitmap;qemu_irq irq;
Signature · 1 line
2.34.1
Re: [PATCH V7 3/8] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
Quoted 2 lines · On Mon, 13 Nov 2023 20:12:31 +0000 Salil Mehta <[email protected]> wrote:
ACPI GED (as described in the ACPI 6.4 spec) uses an interrupt listed in the
_CRSobject of GED to intimate OSPM about an event. Later then demultiplexes the
^^^ typo?
Quoted 1 line
notified event by evaluating ACPI
_EVTmethod to know the type of event. Use
^ new line/paragraph ?
Quoted 16 lines
ACPI GED to also notify the guest kernel about any CPU hot(un)plug events.
ACPI CPU hotplug related initialization should only happen if
ACPI_CPU_HOTPLUGsupport has been enabled for particular architecture. Addcpu_hotplug_hw_init()stub to avoid compilation break.Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Gavin Shan <[email protected]>Reviewed-by David Hildenbrand <[email protected]>Reviewed-by Shaoqin Huang <[email protected]>Tested-by Vishnu Pajjuri <[email protected]>Tested-by Xianglai Li <[email protected]>Tested-by Miguel Luis <[email protected]>
Quoted 1 line
---
FYI,
add per version changes here, ex:
v7:
- Add cpu_hotplug_hw_init() stub ...
(instigated@by)
this way reviewer isn't forced to check previous versions of it. otherwise:
Quoted 127 lines
hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++ hw/acpi/generic_event_device.c | 17 +++++++++++++++++ include/hw/acpi/generic_event_device.h | 4 ++++ 3 files changed, 27 insertions(+)hw/acpi/acpi-cpu-hotplug-stub.c +6
-0@@ -19,6 +19,12 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,return ; } +void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner, +CPUHotplugState *state,hwaddr base_addr) +{ +return ; +} +void acpi_cpu_ospm_status (CPUHotplugState *cpu_st,ACPIOSTInfoList ***list) {return ;hw/acpi/generic_event_device.c +17
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qapi/error.h" #include "hw/acpi/acpi.h" +#include "hw/acpi/cpu.h" #include "hw/acpi/generic_event_device.h" #include "hw/irq.h" #include "hw/mem/pc-dimm.h" @@ -25,6 +26,7 @@ static const uint32_t ged_supported_events[] = {ACPI_GED_MEM_HOTPLUG_EVT ,ACPI_GED_PWR_DOWN_EVT ,ACPI_GED_NVDIMM_HOTPLUG_EVT , + ACPI_GED_CPU_HOTPLUG_EVT, };/* @@ -234,6 +236,8 @@ static void acpi_ged_device_plug_cb(HotplugHandler *hotplug_dev, }else {acpi_memory_plug_cb (hotplug_dev, &s->memhp_state, dev, errp); } + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +acpi_cpu_plug_cb (hotplug_dev, &s->cpuhp_state, dev, errp); }else {error_setg (errp,"virt: device plug request for unsupported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -248,6 +252,8 @@ static void acpi_ged_unplug_request_cb(HotplugHandler *hotplug_dev,if ((object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM ) && !(object_dynamic_cast (OBJECT (dev),TYPE_NVDIMM )))) {acpi_memory_unplug_request_cb (hotplug_dev, &s->memhp_state, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +acpi_cpu_unplug_request_cb (hotplug_dev, &s->cpuhp_state, dev, errp); }else {error_setg (errp,"acpi: device unplug request for unsupported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -261,6 +267,8 @@ static void acpi_ged_unplug_cb(HotplugHandler *hotplug_dev,if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {acpi_memory_unplug_cb (&s->memhp_state, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_CPU )) { +acpi_cpu_unplug_cb (&s->cpuhp_state, dev, errp); }else {error_setg (errp,"acpi: device unplug for unsupported device" " type: %s" ,object_get_typename (OBJECT (dev)));@@ -272,6 +280,7 @@ static void acpi_ged_ospm_status(AcpiDeviceIf *adev, ACPIOSTInfoList ***list)AcpiGedState *s =ACPI_GED (adev);acpi_memory_ospm_status (&s->memhp_state, list); +acpi_cpu_ospm_status (&s->cpuhp_state, list); }static void acpi_ged_send_event (AcpiDeviceIf *adev,AcpiEventStatusBits ev)@@ -286,6 +295,8 @@ static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) sel =ACPI_GED_PWR_DOWN_EVT ; }else if (ev &ACPI_NVDIMM_HOTPLUG_STATUS ) { sel =ACPI_GED_NVDIMM_HOTPLUG_EVT ; + }else if (ev &ACPI_CPU_HOTPLUG_STATUS ) { + sel =ACPI_GED_CPU_HOTPLUG_EVT ; }else {/* Unknown event. Return without generating interrupt. */ warn_report ("GED: Unsupported event %d. No irq injected" , ev);@@ -400,6 +411,12 @@ static void acpi_ged_initfn(Object *obj)memory_region_init_io (&ged_st->regs, obj, &ged_regs_ops, ged_st,TYPE_ACPI_GED "-regs" ,ACPI_GED_REG_COUNT );sysbus_init_mmio (sbd, &ged_st->regs); + +memory_region_init (&s->container_cpuhp,OBJECT (dev),"cpuhp container" , +ACPI_CPU_HOTPLUG_REG_LEN ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->container_cpuhp); +cpu_hotplug_hw_init (&s->container_cpuhp,OBJECT (dev), + &s->cpuhp_state,0 ); }static void acpi_ged_class_init (ObjectClass *class,void *data)include/hw/acpi/generic_event_device.h +4
-0@@ -60,6 +60,7 @@#define HW_ACPI_GENERIC_EVENT_DEVICE_H #include "hw/sysbus.h" +#include "hw/acpi/cpu_hotplug.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/ghes.h" #include "qom/object.h" @@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define ACPI_GED_MEM_HOTPLUG_EVT 0x1#define ACPI_GED_PWR_DOWN_EVT 0x2#define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4 +#define ACPI_GED_CPU_HOTPLUG_EVT 0x8 typedef struct GEDState { MemoryRegion evt;@@ -106,6 +108,8 @@ struct AcpiGedState {SysBusDevice parent_obj;MemHotplugState memhp_state;MemoryRegion container_memhp; +CPUHotplugState cpuhp_state; +MemoryRegion container_cpuhp;GEDState ged_state;uint32_t ged_event_bitmap;qemu_irq irq;
Re: [PATCH V7 3/8] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
In reply to Salil MehtaHi Salil,
Quoted 6 lines · Salil Mehta via
Date: Mon, 13 Nov 2023 20:12:31 +0000
From: Salil Mehta via <[email protected]>
Subject: [PATCH V7 3/8] hw/acpi: Update ACPI GED framework to support vCPU
Hotplug
X-Mailer: git-send-email 2.8.3
[snip]
Review static void acpi_ged_initfn(Object *obj) · line 419
Quoted 10 lines
(quoted diff) +6
-0@@ -400,6 +411,12 @@ static void acpi_ged_initfn(Object *obj) memory_region_init_io(&ged_st->regs, obj, &ged_regs_ops, ged_st, TYPE_ACPI_GED "-regs", ACPI_GED_REG_COUNT); sysbus_init_mmio(sbd, &ged_st->regs); + + memory_region_init(&s->container_cpuhp, OBJECT(dev), "cpuhp container", + ACPI_CPU_HOTPLUG_REG_LEN); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container_cpuhp); + cpu_hotplug_hw_init(&s->container_cpuhp, OBJECT(dev), + &s->cpuhp_state, 0);
I find this cpu_hotplug_hw_init() can still cause qtest errors on x86
platforms as you mentioned in v6: https://lore.kernel.org/qemu-devel/[email protected]/T/#m108f102b2fe92b7dd7218f2f942f7b233a9d6af3
IIUC, microvm machine has its own 'possible_cpus_arch_ids' and that is inherited from its parent x86 machine.
The above error is because device-introspect-test sets the none-machine:
# starting QEMU: exec ./qemu-system-i386 -qtest unix:/tmp/qtest-3094820.sock -qtest-log /dev/null -chardev socket,path=/tmp/qtest-3094820.qmp,id=char0 -mon chardev=char0,mode=control -display none -audio none -nodefaults -machine none -accel qtest
So what about just checking mc->possible_cpu_arch_ids instead of an assert in cpu_hotplug_hw_init()?
hw/acpi/cpu.c +4 -1
@@ -221,7 +221,10 @@ void cpu_hotplug_hw_init(MemoryRegion *as, Object *owner,const CPUArchIdList *id_list;int i; -assert (mc->possible_cpu_arch_ids); +if (!mc->possible_cpu_arch_ids) { +return ; + } + id_list = mc->possible_cpu_arch_ids (machine); state->dev_count = id_list->len; state->devs =g_new0 (typeof (*state->devs), state->dev_count);
This check seems to be acceptable in the general code path? Not all machines have possible_cpu_arch_ids, after all.
Thanks,
Zhao
Quoted 36 lines
(quoted diff) +0
-0} static void acpi_ged_class_init(ObjectClass *class, void *data)include/hw/acpi/generic_event_device.h +4
-0@@ -60,6 +60,7 @@#define HW_ACPI_GENERIC_EVENT_DEVICE_H #include "hw/sysbus.h" +#include "hw/acpi/cpu_hotplug.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/ghes.h" #include "qom/object.h" @@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define ACPI_GED_MEM_HOTPLUG_EVT 0x1#define ACPI_GED_PWR_DOWN_EVT 0x2#define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4 +#define ACPI_GED_CPU_HOTPLUG_EVT 0x8 typedef struct GEDState { MemoryRegion evt;@@ -106,6 +108,8 @@ struct AcpiGedState {SysBusDevice parent_obj;MemHotplugState memhp_state;MemoryRegion container_memhp; +CPUHotplugState cpuhp_state; +MemoryRegion container_cpuhp;GEDState ged_state;uint32_t ged_event_bitmap;qemu_irq irq;Signature · 1 line
2.34.1
PATCH v7 4/8 hw/acpi: Update GED _EVT method AML with CPU scan
In reply to Salil MehtaOSPM evaluates _EVT method to map the event. The CPU hotplug event eventually results in start of the CPU scan. Scan figures out the CPU and the kind of event(plug/unplug) and notifies it back to the guest. Update the GED AML _EVT method with the call to \\_SB.CPUS.CSCN
Also, macro CPU_SCAN_METHOD might be referred in other places like during GED intialization so it makes sense to have its definition placed in some common header file like cpu_hotplug.h. But doing this can cause compilation break because of the conflicting macro definitions present in cpu.c and cpu_hotplug.c and because both these files get compiled due to historic reasons of x86 world i.e. decision to use legacy(GPE.2)/modern(GED) CPU hotplug interface happens during runtime [1]. To mitigate above, for now, declare a new common macro ACPI_CPU_SCAN_METHOD for CPU scan method instead.
(This needs a separate discussion later on for clean-up)
Reference:
[1] https://lore.kernel.org/qemu-devel/[email protected]/
--- hw/acpi/cpu.c | 2 +- hw/acpi/generic_event_device.c | 4 ++++ include/hw/acpi/cpu_hotplug.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-)
hw/acpi/cpu.c +1 -1
@@ -323,7 +323,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPUHP_RES_DEVICE "PRES"#define CPU_LOCK "CPLK"#define CPU_STS_METHOD "CSTA" -#define CPU_SCAN_METHOD "CSCN" +#define CPU_SCAN_METHOD ACPI_CPU_SCAN_METHOD#define CPU_NOTIFY_METHOD "CTFY"#define CPU_EJECT_METHOD "CEJ0"#define CPU_OST_METHOD "COST"
hw/acpi/generic_event_device.c +4 -0
@@ -109,6 +109,10 @@ void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev,aml_append (if_ctx,aml_call0 (MEMORY_DEVICES_CONTAINER "." MEMORY_SLOT_SCAN_METHOD ));break ; +case ACPI_GED_CPU_HOTPLUG_EVT : +aml_append (if_ctx,aml_call0 (ACPI_CPU_CONTAINER "." +ACPI_CPU_SCAN_METHOD )); +break ;case ACPI_GED_PWR_DOWN_EVT : aml_append(if_ctx, aml_notify(aml_name(ACPI_POWER_BUTTON_DEVICE),
include/hw/acpi/cpu_hotplug.h +2 -0
@@ -20,6 +20,8 @@#include "hw/acpi/cpu.h" #define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SCAN_METHOD "CSCN" +#define ACPI_CPU_CONTAINER "\\_SB.CPUS" typedef struct AcpiCpuHotplug { Object *device;
Signature · 1 line
2.34.1
Re: [PATCH V7 4/8] hw/acpi: Update GED _EVT method AML with CPU scan
Quoted 8 lines · On Mon, 13 Nov 2023 20:12:32 +0000 Salil Mehta <[email protected]> wrote:
OSPM evaluates
_EVTmethod to map the event. The CPU hotplug event eventually results in start of the CPU scan. Scan figures out the CPU and the kind of event(plug/unplug) and notifies it back to the guest. Update the GED AML_EVTmethod with the call to \\_SB.CPUS.CSCNAlso, macro
CPU_SCAN_METHODmight be referred in other places like during GED intialization so it makes sense to have its definition placed in some common header file likecpu_hotplug.h. But doing this can cause compilation break
hw/acpi/cpu.h would be a better place for it
Also, I'd rather rename w/acpi/cpu_hotplug.c:CPU_SCAN_METHOD to LEGACY_CPU_SCAN_METHOD while keeping newer CPU_SCAN_METHOD as is and making it public.
Quoted 66 lines
because of the conflicting macro definitions present in
cpu.candcpu_hotplug.cand because both these files get compiled due to historic reasons of x86 world i.e. decision to use legacy(GPE.2)/modern(GED) CPU hotplug interface happens during runtime [1]. To mitigate above, for now, declare a new common macroACPI_CPU_SCAN_METHODfor CPU scan method instead.
(This needs a separate discussion later on for clean-up)Reference:
[1] https://lore.kernel.org/qemu-devel/[email protected]/Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Gavin Shan <[email protected]>Tested-by Vishnu Pajjuri <[email protected]>Tested-by Xianglai Li <[email protected]>Tested-by Miguel Luis <[email protected]>Reviewed-by Shaoqin Huang <[email protected]>--- hw/acpi/cpu.c | 2 +- hw/acpi/generic_event_device.c | 4 ++++ include/hw/acpi/cpu_hotplug.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-)hw/acpi/cpu.c +1
-1@@ -323,7 +323,7 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPUHP_RES_DEVICE "PRES"#define CPU_LOCK "CPLK"#define CPU_STS_METHOD "CSTA" -#define CPU_SCAN_METHOD "CSCN" +#define CPU_SCAN_METHOD ACPI_CPU_SCAN_METHOD#define CPU_NOTIFY_METHOD "CTFY"#define CPU_EJECT_METHOD "CEJ0"#define CPU_OST_METHOD "COST"hw/acpi/generic_event_device.c +4
-0@@ -109,6 +109,10 @@ void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev,aml_append (if_ctx,aml_call0 (MEMORY_DEVICES_CONTAINER "." MEMORY_SLOT_SCAN_METHOD ));break ; +case ACPI_GED_CPU_HOTPLUG_EVT : +aml_append (if_ctx,aml_call0 (ACPI_CPU_CONTAINER "." +ACPI_CPU_SCAN_METHOD )); +break ;case ACPI_GED_PWR_DOWN_EVT : aml_append(if_ctx, aml_notify(aml_name(ACPI_POWER_BUTTON_DEVICE),include/hw/acpi/cpu_hotplug.h +2
-0@@ -20,6 +20,8 @@#include "hw/acpi/cpu.h" #define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SCAN_METHOD "CSCN" +#define ACPI_CPU_CONTAINER "\\_SB.CPUS" typedef struct AcpiCpuHotplug { Object *device;
PATCH v7 5/8 hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
In reply to Salil MehtaCPUs Control device(\\_SB.PCI0) register interface for the x86 arch is IO port based and existing CPUs AML code assumes _CRS objects would evaluate to a system resource which describes IO Port address. But on ARM arch CPUs control device(\\_SB.PRES) register interface is memory-mapped hence _CRS object should evaluate to system resource which describes memory-mapped base address. Update build CPUs AML function to accept both IO/MEMORY region spaces and accordingly update the _CRS object.
On x86, CPU Hotplug uses Generic ACPI GPE Block Bit 2 (GPE.2) event handler to notify OSPM about any CPU hot(un)plug events. Latest CPU Hotplug is based on ACPI Generic Event Device framework and uses ACPI GED device for the same. Not all architectures support GPE based CPU Hotplug event handler. Hence, make AML for GPE.2 event handler conditional.
--- hw/acpi/cpu.c | 23 ++++++++++++++++------- hw/i386/acpi-build.c | 3 ++- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 21 insertions(+), 10 deletions(-)
hw/acpi/cpu.c +16 -7
@@ -339,9 +339,10 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -build_madt_cpu_fn build_madt_cpu,hwaddr io_base, +build_madt_cpu_fn build_madt_cpu,hwaddr base_addr,const char *res_root, -const char *event_handler_method) +const char *event_handler_method, +AmlRegionSpace rs) {Aml *ifctx;Aml *field;
@@ -366,13 +367,19 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (cpu_ctrl_dev,aml_mutex (CPU_LOCK ,0 )); crs =aml_resource_template (); -aml_append (crs,aml_io (AML_DECODE16 , io_base, io_base,1 , +if (rs ==AML_SYSTEM_IO ) { +aml_append (crs,aml_io (AML_DECODE16 , base_addr, base_addr,1 ,ACPI_CPU_HOTPLUG_REG_LEN )); + }else { +aml_append (crs,aml_memory32_fixed (base_addr, +ACPI_CPU_HOTPLUG_REG_LEN ,AML_READ_WRITE )); + } +aml_append (cpu_ctrl_dev,aml_name_decl ("_CRS" , crs));/* declare CPU hotplug MMIO region with related access fields */ aml_append (cpu_ctrl_dev, -aml_operation_region ("PRST" ,AML_SYSTEM_IO ,aml_int (io_base), +aml_operation_region ("PRST" , rs,aml_int (base_addr),ACPI_CPU_HOTPLUG_REG_LEN )); field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,
@@ -696,9 +703,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (sb_scope, cpus_dev);aml_append (table, sb_scope); - method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); -aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); -aml_append (table, method); +if (event_handler_method) { + method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); +aml_append (table, method); + }g_free (cphp_res_path); }
hw/i386/acpi-build.c +2 -1
@@ -1550,7 +1550,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pc_madt_cpu_entry, - pm->cpu_hp_io_base,"\\_SB.PCI0" ,"\\_GPE._E02" ); + pm->cpu_hp_io_base,"\\_SB.PCI0" ,"\\_GPE._E02" , +AML_SYSTEM_IO ); }if (pcms->memhp_io_base && nr_mem) {
include/hw/acpi/cpu.h +3 -2
@@ -60,9 +60,10 @@ typedef void (*build_madt_cpu_fn)(int uid, const CPUArchIdList *apic_ids, GArray *entry, bool force_enabled);void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -build_madt_cpu_fn build_madt_cpu,hwaddr io_base, +build_madt_cpu_fn build_madt_cpu,hwaddr base_addr,const char *res_root, -const char *event_handler_method); +const char *event_handler_method, +AmlRegionSpace rs);void acpi_cpu_ospm_status (CPUHotplugState *cpu_st,ACPIOSTInfoList ***list);
Signature · 1 line
2.34.1
Re: [PATCH V7 5/8] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
On Mon, 13 Nov 2023 20:12:33 +0000
Salil Mehta <[email protected]> wrote:
wrt subj: 'cpu-(ctrl)dev change' doesn't make any sense to me, pls rephrase and be more specific.
Quoted 11 lines
CPUs Control
device(\\_SB.PCI0)register interface for the x86 arch is IO port based and existing CPUs AML code assumes_CRSobjects would evaluate to a system resource which describes IO Port address. But on ARM arch CPUs controldevice(\\_SB.PRES)register interface is memory-mapped hence_CRSobject should evaluate to system resource which describes memory-mapped base address. Update build CPUs AML function to accept both IO/MEMORY region spaces and accordingly update the_CRSobject.On x86, CPU Hotplug uses Generic ACPI GPE Block Bit 2 (GPE.2) event handler to notify OSPM about any CPU hot(un)plug events. Latest CPU Hotplug is based on
^^^ latest supported ATM is x86
and not based on GED vvvv, suggest to drop sentence or actually whole paragraph.
Quoted 3 lines
ACPI Generic Event Device framework and uses ACPI GED device for the same. Not all architectures support GPE based CPU Hotplug event handler. Hence, make AML for GPE.2 event handler conditional.
this is the 2nd different thing the patch does, pls split that into another, for more on that see related hunk.
Quoted 57 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>Reviewed-by Gavin Shan <[email protected]>Tested-by Vishnu Pajjuri <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Tested-by Xianglai Li <[email protected]>Tested-by Miguel Luis <[email protected]>Reviewed-by Shaoqin Huang <[email protected]>--- hw/acpi/cpu.c | 23 ++++++++++++++++------- hw/i386/acpi-build.c | 3 ++- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 21 insertions(+), 10 deletions(-)hw/acpi/cpu.c +11
-4@@ -339,9 +339,10 @@ const VMStateDescription vmstate_cpu_hotplug = {#define CPU_FW_EJECT_EVENT "CEJF"void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -build_madt_cpu_fn build_madt_cpu,hwaddr io_base, +build_madt_cpu_fn build_madt_cpu,hwaddr base_addr,const char *res_root, -const char *event_handler_method) +const char *event_handler_method, +AmlRegionSpace rs) {Aml *ifctx;Aml *field;@@ -366,13 +367,19 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (cpu_ctrl_dev,aml_mutex (CPU_LOCK ,0 )); crs =aml_resource_template (); -aml_append (crs,aml_io (AML_DECODE16 , io_base, io_base,1 , +if (rs ==AML_SYSTEM_IO ) { +aml_append (crs,aml_io (AML_DECODE16 , base_addr, base_addr,1 ,ACPI_CPU_HOTPLUG_REG_LEN )); + }else { +aml_append (crs,aml_memory32_fixed (base_addr, +ACPI_CPU_HOTPLUG_REG_LEN ,AML_READ_WRITE )); + } +aml_append (cpu_ctrl_dev,aml_name_decl ("_CRS" , crs));/* declare CPU hotplug MMIO region with related access fields */ aml_append (cpu_ctrl_dev, -aml_operation_region ("PRST" ,AML_SYSTEM_IO ,aml_int (io_base), +aml_operation_region ("PRST" , rs,aml_int (base_addr),ACPI_CPU_HOTPLUG_REG_LEN )); field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,@@ -696,9 +703,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (sb_scope, cpus_dev);
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts, · line 710
Quoted 10 lines
hw/acpi/cpu.c +5
-3aml_append (table, sb_scope); - method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); -aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); -aml_append (table, method); +if (event_handler_method) { + method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); +aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); +aml_append (table, method); + }
indeed, injecting a method won't work with GED (and well it's hackish to begin with). Suggest to get rid of it and make event source initiate the call to CPU_SCAN_METHOD. Something like (similar to what you do in 4/8): (maybe make it part of 4/8)
hw/acpi/cpu.c +1 -5
@@ -341,7 +341,7 @@ const VMStateDescription vmstate_cpu_hotplug = {void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts,build_madt_cpu_fn build_madt_cpu,hwaddr io_base, const char *res_root, -const char *event_handler_method) + ) {Aml *ifctx;Aml *field;
@@ -696,9 +696,5 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,aml_append (sb_scope, cpus_dev);aml_append (table, sb_scope); - method =aml_method (event_handler_method,0 ,AML_NOTSERIALIZED ); -aml_append (method,aml_call0 ("\\_SB.CPUS." CPU_SCAN_METHOD )); -aml_append (table, method); -g_free (cphp_res_path); }
hw/i386/acpi-build.c +1 -0
@@ -1856,6 +1856,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (method,aml_release (aml_name ("\\_SB.PCI0.BLCK" ))); }aml_append (scope, method); +if (!pcmc->legacy_cpu_hotplug) {
...
+ aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
...
}
}
aml_append(dsdt, scope);
}Quoted 34 lines
hw/acpi/cpu.c +0
-0g_free (cphp_res_path); }hw/i386/acpi-build.c +2
-1@@ -1550,7 +1550,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pc_madt_cpu_entry, - pm->cpu_hp_io_base,"\\_SB.PCI0" ,"\\_GPE._E02" ); + pm->cpu_hp_io_base,"\\_SB.PCI0" ,"\\_GPE._E02" , +AML_SYSTEM_IO ); }if (pcms->memhp_io_base && nr_mem) {include/hw/acpi/cpu.h +3
-2@@ -60,9 +60,10 @@ typedef void (*build_madt_cpu_fn)(int uid, const CPUArchIdList *apic_ids, GArray *entry, bool force_enabled);void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -build_madt_cpu_fn build_madt_cpu,hwaddr io_base, +build_madt_cpu_fn build_madt_cpu,hwaddr base_addr,const char *res_root, -const char *event_handler_method); +const char *event_handler_method, +AmlRegionSpace rs);void acpi_cpu_ospm_status (CPUHotplugState *cpu_st,ACPIOSTInfoList ***list);
PATCH v7 6/8 physmem: Add helper function to destroy CPU AddressSpace
In reply to Salil MehtaVirtual CPU Hot-unplug leads to unrealization of a CPU object. This also involves destruction of the CPU AddressSpace. Add common function to help destroy the CPU AddressSpace.
--- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + system/physmem.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+)
include/exec/cpu-common.h +8 -0
@@ -127,6 +127,14 @@ size_t qemu_ram_pagesize_largest(void);*/ void cpu_address_space_init (CPUState *cpu,int asidx,const char *prefix,MemoryRegion *mr); +/** +* cpu_address_space_destroy: +* @cpu: CPU for which address space needs to be destroyed +* @asidx: integer index of this address space +* +* Note that with KVM only one address space is supported. +*/ +void cpu_address_space_destroy (CPUState *cpu,int asidx);void cpu_physical_memory_rw (hwaddr addr,void *buf,hwaddr len,bool is_write);
include/hw/core/cpu.h +1 -0
@@ -496,6 +496,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list;CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;
system/physmem.c +29 -0
@@ -761,6 +761,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx,if (!cpu->cpu_ases) { cpu->cpu_ases =g_new0 (CPUAddressSpace, cpu->num_ases); + cpu->cpu_ases_count = cpu->num_ases; } newas = &cpu->cpu_ases[asidx];
@@ -774,6 +775,34 @@ void cpu_address_space_init(CPUState *cpu, int asidx, } } +void cpu_address_space_destroy (CPUState *cpu,int asidx) +{ +CPUAddressSpace *cpuas; + +assert (cpu->cpu_ases); +assert (asidx >=0 && asidx < cpu->num_ases); +/* KVM cannot currently support multiple address spaces. */ +assert (asidx ==0 || !kvm_enabled ()); + + cpuas = &cpu->cpu_ases[asidx]; +if (tcg_enabled ()) { +memory_listener_unregister (&cpuas->tcg_as_listener); + } + +address_space_destroy (cpuas->as); +g_free_rcu (cpuas->as, rcu); + +if (asidx ==0 ) { +/* reset the convenience alias for address space 0 */ + cpu->as =NULL ; + } + +if (--cpu->cpu_ases_count ==0 ) { +g_free (cpu->cpu_ases); + cpu->cpu_ases =NULL ; + } +} +AddressSpace *cpu_get_address_space (CPUState *cpu,int asidx) {/* Return the AddressSpace corresponding to the specified index */
Signature · 1 line
2.34.1
PATCH v7 7/8 gdbstub: Add helper function to unregister GDB register space
In reply to Salil MehtaAdd common function to help unregister the GDB register space. This shall be done in context to the CPU unrealization.
--- gdbstub/gdbstub.c | 12 ++++++++++++ include/exec/gdbstub.h | 5 +++++ 2 files changed, 17 insertions(+)
gdbstub/gdbstub.c +12 -0
@@ -498,6 +498,18 @@ void gdb_register_coprocessor(CPUState *cpu, } } +void gdb_unregister_coprocessor_all (CPUState *cpu) +{ +/* +* Safe to nuke everything. GDBRegisterState::xml is static const char so +* it won't be freed +*/ +g_array_free (cpu->gdb_regs, true); + + cpu->gdb_regs =NULL ; + cpu->gdb_num_g_regs =0 ; +} +static void gdb_process_breakpoint_remove_all (GDBProcess *p) {CPUState *cpu =gdb_get_first_cpu_in_process (p);
include/exec/gdbstub.h +5 -0
@@ -32,6 +32,11 @@ typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);void gdb_register_coprocessor (CPUState *cpu,gdb_get_reg_cb get_reg,gdb_set_reg_cb set_reg,int num_regs,const char *xml,int g_pos); +/** +* gdb_unregister_coprocessor_all() - unregisters supplemental set of registers +* @cpu - the CPU associated with registers +*/ +void gdb_unregister_coprocessor_all (CPUState *cpu);/** * gdbserver_start: start the gdb server
Signature · 1 line
2.34.1
PATCH v7 8/8 docs/specs/acpi_hw_reduced_hotplug: Add the CPU Hotplug Event Bit
In reply to Salil MehtaGED interface is used by many hotplug events like memory hotplug, NVDIMM hotplug and non-hotplug events like system power down event. Each of these can be selected using a bit in the 32 bit GED IO interface. A bit has been reserved for the CPU hotplug event.
--- docs/specs/acpi_hw_reduced_hotplug.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
docs/specs/acpi_hw_reduced_hotplug.rst +2 -1
@@ -64,7 +64,8 @@ GED IO interface (4 byte access) 0: Memory hotplug event 1: System power down event 2: NVDIMM hotplug event - 3-31: Reserved + 3: CPU hotplug event + 4-31: Reserved **write_access:**
Signature · 1 line
2.34.1
Re: [PATCH V7 8/8] docs/specs/acpi_hw_reduced_hotplug: Add the CPU Hotplug Event Bit
Quoted 10 lines · Salil Mehta
GED interface is used by many hotplug events like memory hotplug, NVDIMM hotplug and non-hotplug events like system power down event. Each of these can be selected using a bit in the 32 bit GED IO interface. A bit has been reserved for the CPU hotplug event.
Signed-off-by Salil Mehta <[email protected]>--- docs/specs/acpi_hw_reduced_hotplug.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Re: [PATCH V7 8/8] docs/specs/acpi_hw_reduced_hotplug: Add the CPU Hotplug Event Bit
In reply to Salil MehtaQuoted 6 lines · Salil Mehta via
GED interface is used by many hotplug events like memory hotplug, NVDIMM hotplug and non-hotplug events like system power down event. Each of these can be selected using a bit in the 32 bit GED IO interface. A bit has been reserved for the CPU hotplug event.
Signed-off-by Salil Mehta <[email protected]>
Quoted 18 lines
--- docs/specs/acpi_hw_reduced_hotplug.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)docs/specs/acpi_hw_reduced_hotplug.rst +2
-1@@ -64,7 +64,8 @@ GED IO interface (4 byte access) 0: Memory hotplug event 1: System power down event 2: NVDIMM hotplug event - 3-31: Reserved + 3: CPU hotplug event + 4-31: Reserved **write_access:**
Signature · 1 line
Shaoqin
Re: [PATCH V7 8/8] docs/specs/acpi_hw_reduced_hotplug: Add the CPU Hotplug Event Bit
In reply to Salil MehtaQuoted 6 lines · On Mon, 13 Nov 2023 20:12:36 +0000 Salil Mehta <[email protected]> wrote:
GED interface is used by many hotplug events like memory hotplug, NVDIMM hotplug and non-hotplug events like system power down event. Each of these can be selected using a bit in the 32 bit GED IO interface. A bit has been reserved for the CPU hotplug event.
Signed-off-by Salil Mehta <[email protected]>
Quoted 18 lines
--- docs/specs/acpi_hw_reduced_hotplug.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)docs/specs/acpi_hw_reduced_hotplug.rst +2
-1@@ -64,7 +64,8 @@ GED IO interface (4 byte access) 0: Memory hotplug event 1: System power down event 2: NVDIMM hotplug event - 3-31: Reserved + 3: CPU hotplug event + 4-31: Reserved **write_access:**
On Mon, 13 Nov 2023 20:12:28 +0000
Salil Mehta <[email protected]> wrote:
[...]
Quoted 2 lines
physmem: Add helper function to destroy CPU AddressSpace
gdbstub: Add helper function to unregister GDB register space
[...]
above patches look like potential bugfixes (modulo they aren't getting used actually), only commit messages do not mention adverse effects (which they should do).
Question is:
do un-destroyed/registered CPU AS and GDB RS affect machines that already support cpu hot-unplug? (x86/s380/spapr)
Quoted 8 lines · On Mon, 13 Nov 2023 20:12:28 +0000 Salil Mehta <[email protected]> wrote:
Virtual CPU hotplug support is being added across various architectures[1][3]. This series adds various code bits common across all architectures:
1. vCPU creation and Parking code refactor [Patch 1]
2. Update ACPI GED framework to support vCPU Hotplug [Patch 2,3]
3. ACPI CPUs AML code change [Patch 4,5]
4. Helper functions to support unrealization of CPU objects [Patch 6,7]
5. Docs [Patch 8]
[...]
forgot to mention, you probably need to add to series migration code as well as it should be the same for both targets.
(mostly copy-paste from q35 or piix4 and making sure it doesn't break old qemu (aka not enabled/sent over wire if cpu hotplug event is disabled))