Add architecture agnostic code to support vCPU Hotplug
v16 cover Add architecture agnostic code to support vCPU Hotplug
[Note: References are present at the last after the revision history]
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]
Repository:
[*] Architecture *Agnostic* Patch-set (This series)
V14: https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v3.arch.agnostic.v15
NOTE: This series is meant to work in conjunction with the architecture-specific patch-set. For ARM, a combined patch-set (architecture agnostic + specific) was earlier pushed as RFC V2 [1]. Later, RFC V2 was split into the ARM Architecture specific patch-set RFC V3 [4] (a subset of RFC V2) and the architecture agnostic patch-set. Patch-set V16 is the latest version in that series. This series works in conjunction with RFC V4-rc3, present at the following link.
[*] ARM Architecture *Specific* Patch-set
RFC V3 [4]: https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v3 RFC V4-rc3: https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v4-rc3 (combined)
Revision History:
Patch-set V15 -> V16
1. Addressed feedbacks from Igor Mammedov on [PATCH V15 1/7,3/7,7/7]
- Fixed the checkpatch.pl errors and warnings
- Made initialization of CPU hotplug regions within GED realize conditional
- Collected {Reviewed,Acked}-Bys for [PATCH V15 1/7,2/7,4/7,5/7,7/7]
Patch-set V14 -> V15
1. Addressed comment by Igor Mammedov on [PATCH V14 4/7]
- Removed ACPI_CPU_SCAN_METHOD
- Introduced AML_GED_EVT_CPU_SCAN_METHOD ("\\_SB.GED.CPSCN") macro
2. Fix the stray change of "assert (" in "PATCH V14 3/7"
Patch-set V13 -> V14
1. Addressed Igor Mammedov's following review comments
- Mentioned abput new external APIs in the header note of [PATCH 1/7]
- Merged Doc [PATCH V13 8/8] with [PATCH V14 3/7]
- Introduced GED realize function for various CPU Hotplug regions initializations
- Added back event handler method to indirectly expose \\_SB.CPUS.CSCN to GED _EVT. Like for ARM, it would be through \\_SB.GED.CSCN event handler method
- Collected the Ack given for [Patch V13 6/8]
- Added back the gfree'ing of GDB regs in common finalize and made it conditional
- Updated the header notes of [PATCH V13 3/8,4/8,5/8] to reflect the changes
Patch-set V12 -> V13
1. Added Reviewed-by Tag of Harsh Prateek Bora's (IBM) [PATCH V12 1/8]
2. Moved the kvm_{create,park,unpark}_vcpu prototypes from accel/kvm/kvm-cpus.h to include/sysemu/kvm.h. These can later be exported through AccelOps.
Patch-set V11 -> V12
1. Addressed Harsh Prateek Bora's (IBM) comment
- Changed @cpu to @vcpu_id in the kvm_unpark_vcpu protoype header/
2. Added Zhao Liu's (Intel) Tested-by for whole series
- Qtest does not breaks on Intel platforms now.
3. Added Zhao Liu's (Intel) Reviewed-by for [PATCH V11 {1/8 - 3/8}]
Patch-set V10 -> V11
1. Addressed Nicholas Piggin's (IBM) comment
- moved the traces in kvm_unpark_vcpu and kvm_create_vcpu at the end
- Added the Reviewed-by Tag for [PATCH V10 1/8]
2. Addressed Alex Bennée's (Linaro) comments
- Added a note explaining dependency of the [PATCH V10 7/8] on Arch specific patch-set
Patch-set V9 -> V10
1. Addressed Nicholas Piggin's (IBM) & Philippe Mathieu-Daudé (Linaro) comments
- carved out kvm_unpark_vcpu and added its trace
- Widened the scope of the kvm_unpark_vcpu so that it can be used by generic framework being thought out
Patch-set V8 -> V9
1. Addressed Vishnu Pajjuri's (Ampere) comments
- Added kvm_fd to trace in kvm_create_vcpu
- Some clean ups: arch vcpu-id and sbd variable
- Added the missed initialization of cpu->gdb_num_regs
2. Addressed the commnet from Zhao Liu (Intel)
- Make initialization of CPU Hotplug state conditional (possible_cpu_arch_ids!=NULL)
Patch-set V7 -> V8
1. Rebased and Fixed the conflicts
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]/
[4] https://lore.kernel.org/qemu-devel/[email protected]/
Salil Mehta (7):
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
accel/kvm/kvm-all.c | 95 +++++++++++++++++--------- accel/kvm/kvm-cpus.h | 1 - accel/kvm/trace-events | 5 +- docs/specs/acpi_hw_reduced_hotplug.rst | 3 +- gdbstub/gdbstub.c | 13 ++++ hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++ hw/acpi/cpu.c | 18 +++-- hw/acpi/generic_event_device.c | 50 ++++++++++++++ hw/core/cpu-common.c | 5 +- hw/i386/acpi-build.c | 3 +- include/exec/cpu-common.h | 8 +++ include/exec/gdbstub.h | 6 ++ include/hw/acpi/cpu.h | 7 +- include/hw/acpi/generic_event_device.h | 5 ++ include/hw/core/cpu.h | 1 + include/sysemu/kvm.h | 25 +++++++ system/physmem.c | 29 ++++++++ 17 files changed, 236 insertions(+), 44 deletions(-)
Signature · 1 line
2.34.1
PATCH v16 1/7 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. New APIs qemu_{create,park,unpark}_vcpu() can be externally called. No functional change is intended here.
--- accel/kvm/kvm-all.c | 95 ++++++++++++++++++++++++++++-------------- accel/kvm/kvm-cpus.h | 1 - accel/kvm/trace-events | 5 ++- include/sysemu/kvm.h | 25 +++++++++++ 4 files changed, 92 insertions(+), 34 deletions(-)
accel/kvm/kvm-all.c +63 -32
@@ -340,14 +340,71 @@ 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_unpark_vcpu (KVMState *s,unsigned long vcpu_id) +{ +struct KVMParkedVcpu *cpu; +int kvm_fd = -ENOENT ; + + QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) { +if (cpu->vcpu_id == vcpu_id) { +QLIST_REMOVE (cpu, node); + kvm_fd = cpu->kvm_fd; +g_free (cpu); + } + } + +trace_kvm_unpark_vcpu (vcpu_id, kvm_fd >0 ?"unparked" :"!found parked" ); + +return kvm_fd; +} + +int kvm_create_vcpu (CPUState *cpu) +{ +unsigned long vcpu_id =kvm_arch_vcpu_id (cpu); +KVMState *s = kvm_state; +int kvm_fd; + +/* check if the KVM vCPU already exist but is parked */ + kvm_fd =kvm_unpark_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 ; + +trace_kvm_create_vcpu (cpu->cpu_index, vcpu_id, kvm_fd); + +return 0 ; +} +static int do_kvm_destroy_vcpu (CPUState *cpu) {KVMState *s = kvm_state;long mmap_size; -struct KVMParkedVcpu *vcpu =NULL ;int ret =0 ; -trace_kvm_destroy_vcpu (); +trace_kvm_destroy_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu)); ret =kvm_arch_destroy_vcpu (cpu);if (ret <0 ) {
@@ -373,10 +430,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; }
@@ -389,24 +443,6 @@ void kvm_destroy_vcpu(CPUState *cpu) } } -static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id) -{ -struct KVMParkedVcpu *cpu; - - QLIST_FOREACH(cpu, &s->kvm_parked_vcpus, node) { -if (cpu->vcpu_id == vcpu_id) { -int kvm_fd; - -QLIST_REMOVE (cpu, node); - kvm_fd = cpu->kvm_fd; -g_free (cpu); -return kvm_fd; - } - } - -return kvm_vm_ioctl (s,KVM_CREATE_VCPU , (void *)vcpu_id); -} -int kvm_init_vcpu (CPUState *cpu,Error **errp) {KVMState *s = kvm_state;
@@ -415,19 +451,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/kvm-cpus.h +0 -1
@@ -22,5 +22,4 @@ bool kvm_supports_guest_debug(void);int kvm_insert_breakpoint (CPUState *cpu,int type,vaddr addr,vaddr len);int kvm_remove_breakpoint (CPUState *cpu,int type,vaddr addr,vaddr len);void kvm_remove_all_breakpoints (CPUState *cpu); -#endif /* KVM_CPUS_H */
accel/kvm/trace-events +4 -1
@@ -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, int kvm_fd) "index: %d, id: %lu, kvm fd: %d" +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_unpark_vcpu(unsigned long arch_cpu_id, const char *msg) "id: %lu %s" 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"
@@ -25,7 +29,6 @@ kvm_dirty_ring_reaper(const char *s) "%s" kvm_dirty_ring_reap(uint64_t count, int64_t t) "reaped %"PRIu64" pages (took %"PRIi64" us)" kvm_dirty_ring_reaper_kick(const char *reason) "%s" kvm_dirty_ring_flush(int finished) "%d" -kvm_destroy_vcpu(void) "" kvm_failed_get_vcpu_mmap_size(void) "" kvm_cpu_exec(void) "" kvm_interrupt_exit_request(void) ""
include/sysemu/kvm.h +25 -0
@@ -313,6 +313,31 @@ int kvm_create_device(KVMState *s, uint64_t type, bool test);*/ bool kvm_device_supported (int vmfd,uint64_t type); +/** +* 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); + +/** +* kvm_unpark_vcpu - unpark QEMU KVM vCPU context +* @s: KVM State +* @vcpu_id: Architecture vCPU ID of the parked vCPU +* +* @returns: KVM fd +*/ +int kvm_unpark_vcpu (KVMState *s,unsigned long vcpu_id); +/* Arch specific hooks */ extern const KVMCapabilityInfo kvm_arch_required_capabilities[];
Signature · 1 line
2.34.1
PATCH v16 2/7 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 | 1 - include/hw/acpi/cpu.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-)
hw/acpi/cpu.c +0 -1
@@ -7,7 +7,6 @@#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.h +2 -0
@@ -19,6 +19,8 @@#include "hw/boards.h" #include "hw/hotplug.h" +#define ACPI_CPU_HOTPLUG_REG_LEN 12 + typedef struct AcpiCpuStatus { CPUState *cpu; uint64_t arch_id;
Signature · 1 line
2.34.1
PATCH v16 3/7 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.
Note, 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.
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.
--- docs/specs/acpi_hw_reduced_hotplug.rst | 3 +- hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++ hw/acpi/generic_event_device.c | 47 ++++++++++++++++++++++++++ include/hw/acpi/generic_event_device.h | 4 +++ 4 files changed, 59 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:**
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 +47 -0
95 lines not on this page · raw message
include/hw/acpi/generic_event_device.h +4 -0
@@ -62,6 +62,7 @@#include "hw/sysbus.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/ghes.h" +#include "hw/acpi/cpu.h" #include "qom/object.h" #define ACPI_POWER_BUTTON_DEVICE "PWRB"
@@ -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 V16 3/7] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
Quoted 14 lines · On Tue, 16 Jul 2024 12:14:58 +0100 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 notified event by evaluating ACPI_EVTmethod to know the type of event. Use ACPI GED to also notify the guest kernel about any CPU hot(un)plug events.Note, 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.
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.
Quoted 13 lines
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]>Reviewed-by Vishnu Pajjuri <[email protected]>Tested-by Zhao Liu <[email protected]>Reviewed-by Zhao Liu <[email protected]>
I haven't tested it but looks fine to me,
it missing migration bits, but as long as there is no actual users in this release it could be a patch on top later on.
Quoted 174 lines
--- docs/specs/acpi_hw_reduced_hotplug.rst | 3 +- hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++ hw/acpi/generic_event_device.c | 47 ++++++++++++++++++++++++++ include/hw/acpi/generic_event_device.h | 4 +++ 4 files changed, 59 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:**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 +47
-0@@ -25,6 +25,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 +235,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 +251,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 +266,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 +279,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 +294,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);@@ -371,6 +381,42 @@ static const VMStateDescription vmstate_acpi_ged = { } }; +static void acpi_ged_realize (DeviceState *dev,Error **errp) +{ +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +AcpiGedState *s =ACPI_GED (dev); +uint32_t ged_events; +int i; + + ged_events =ctpop32 (s->ged_event_bitmap); + +for (i =0 ; i <ARRAY_SIZE (ged_supported_events) && ged_events; i++) { +uint32_t event = s->ged_event_bitmap & ged_supported_events[i]; + +if (!event) { +continue ; + } + +switch (event) { +case ACPI_GED_CPU_HOTPLUG_EVT : +/* initialize CPU Hotplug related regions */ +memory_region_init (&s->container_cpuhp,OBJECT (dev), +"cpuhp container" , +ACPI_CPU_HOTPLUG_REG_LEN ); +sysbus_init_mmio (sbd, &s->container_cpuhp); +cpu_hotplug_hw_init (&s->container_cpuhp,OBJECT (dev), + &s->cpuhp_state,0 ); +break ; + } + ged_events--; + } + +if (ged_events) { +error_report ("Unsupported events specified" ); +abort (); + } +} +static void acpi_ged_initfn (Object *obj) {DeviceState *dev =DEVICE (obj);@@ -411,6 +457,7 @@ static void acpi_ged_class_init(ObjectClass *class, void *data) dc->desc ="ACPI Generic Event Device" ;device_class_set_props (dc, acpi_ged_properties); dc->vmsd = &vmstate_acpi_ged; + dc->realize = acpi_ged_realize; hc->plug = acpi_ged_device_plug_cb; hc->unplug_request = acpi_ged_unplug_request_cb;include/hw/acpi/generic_event_device.h +4
-0@@ -62,6 +62,7 @@#include "hw/sysbus.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/ghes.h" +#include "hw/acpi/cpu.h" #include "qom/object.h" #define ACPI_POWER_BUTTON_DEVICE "PWRB"@@ -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 V16 3/7] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
Quoted 38 lines
From: Igor Mammedov <[email protected]>
Sent: Tuesday, July 16, 2024 3:53 PM
To: Salil Mehta <[email protected]>Quoted 4 lines · On Tue, 16 Jul 2024 12:14:58 +0100 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 notified event by evaluating ACPI_EVTmethod to know the type of event. Use ACPI GED to also notify the guest kernelabout any CPU hot(un)plug events.
Quoted 3 lines
Note, GED interface is used by many hotplug events like memory hotplug, NVDIMM hotplug and non-hotplug events like system power
down
Quoted 5 lines
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.
ACPI CPU hotplug related initialization should only happen if
ACPI_CPU_HOTPLUGsupport has been enabled for particulararchitecture.
Quoted 15 lines
Add
cpu_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]>Reviewed-by Vishnu Pajjuri <[email protected]>Tested-by Zhao Liu <[email protected]>Reviewed-by Zhao Liu <[email protected]>
Quoted 4 lines
I haven't tested it but looks fine to me, it missing migration bits, but as long as there is no actual users in this release it could be a patch on top later on.
Acked-by Igor Mammedov <[email protected]>
Many thanks!
Best regards
Salil.
Quoted 189 lines
Quoted 3 lines
docs/specs/acpi_hw_reduced_hotplug.rst | 3 +- hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++ hw/acpi/generic_event_device.c | 47++++++++++++++++++++++++++
hw/acpi/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion
Quoted 23 lines
include/hw/acpi/generic_event_device.h | 4 +++ 4 files changed, 59 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:**(quoted diff) +0
-0
b/hw/acpi/acpi-cpu-hotplug-stub.cindex3fc4b14c26..c6c61bb9cd100644hw/acpi/acpi-cpu-hotplug-stub.c +0
-0@@ -19,6 +19,12 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion*parent, Object *owner,
hw/acpi/generic_event_device.c static void
Quoted 24 lines
hw/acpi/acpi-cpu-hotplug-stub.c +5
-0return ; } +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 ;(quoted diff) +0
-0
b/hw/acpi/generic_event_device.cindex2d6e91b124..4641933a0f100644hw/acpi/generic_event_device.c +1
-0@@ -25,6 +25,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 +235,8 @@ static voidacpi_ged_device_plug_cb(HotplugHandler
*hotplug_dev,hw/acpi/generic_event_device.c static void · line 236
Quoted 2 lines
hw/acpi/generic_event_device.c +0
-0}else { acpi_memory_plug_cb(hotplug_dev, &s->memhp_state, dev,errp);
hw/acpi/generic_event_device.c static void
Quoted 7 lines
hw/acpi/generic_event_device.c +2
-0} + }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 +251,8 @@ static voidacpi_ged_unplug_request_cb(HotplugHandler
*hotplug_dev,hw/acpi/generic_event_device.c static void
Quoted 9 lines
hw/acpi/generic_event_device.c +3
-0if ((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 unsupporteddevice"
hw/acpi/generic_event_device.c static void acpi_ged_ospm_status(AcpiDeviceIf
Quoted 12 lines
" type: %s", object_get_typename(OBJECT(dev)));hw/acpi/generic_event_device.c +2
-0@@ -261,6 +266,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)));hw/acpi/generic_event_device.c +0
-0@@ -272,6 +279,7 @@ static void acpi_ged_ospm_status(AcpiDeviceIf*adev, ACPIOSTInfoList ***list)
Quoted 8 lines
hw/acpi/generic_event_device.c +1
-0AcpiGedState *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 +294,8 @@ static void
acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)Quoted 9 lines
sel = ACPI_GED_PWR_DOWN_EVT; } else if (ev & ACPI_NVDIMM_HOTPLUG_STATUS) { sel = ACPI_GED_NVDIMM_HOTPLUG_EVT;hw/acpi/generic_event_device.c +2
-0+ }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); @@ -371,6 +381,42 @@ static const VMStateDescription
vmstate_acpi_ged= {hw/acpi/generic_event_device.c static const VMStateDescription vmstate_acpi_ged = {
Quoted 12 lines
}};
hw/acpi/generic_event_device.c +9
-0+static void acpi_ged_realize (DeviceState *dev,Error **errp) { +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +AcpiGedState *s =ACPI_GED (dev); +uint32_t ged_events; +int i; + + ged_events =ctpop32 (s->ged_event_bitmap); + +for (i =0 ; i <ARRAY_SIZE (ged_supported_events) && ged_events; i++){
hw/acpi/generic_event_device.c static void acpi_ged_class_init(ObjectClass *class,
Quoted 30 lines
hw/acpi/generic_event_device.c +27
-0+uint32_t event = s->ged_event_bitmap & + ged_supported_events[i]; + +if (!event) { +continue ; + } + +switch (event) { +case ACPI_GED_CPU_HOTPLUG_EVT : +/* initialize CPU Hotplug related regions */ +memory_region_init (&s->container_cpuhp,OBJECT (dev), +"cpuhp container" , +ACPI_CPU_HOTPLUG_REG_LEN ); +sysbus_init_mmio (sbd, &s->container_cpuhp); +cpu_hotplug_hw_init (&s->container_cpuhp,OBJECT (dev), + &s->cpuhp_state,0 ); +break ; + } + ged_events--; + } + +if (ged_events) { +error_report ("Unsupported events specified" ); +abort (); + } +} +static void acpi_ged_initfn (Object *obj) {DeviceState *dev =DEVICE (obj);@@ -411,6 +457,7 @@ static void acpi_ged_class_init(ObjectClass *class,void *data)
include/hw/acpi/generic_event_device.h OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState,
Quoted 21 lines
hw/acpi/generic_event_device.c +1
-0dc->desc ="ACPI Generic Event Device" ;device_class_set_props (dc, acpi_ged_properties); dc->vmsd = &vmstate_acpi_ged; + dc->realize = acpi_ged_realize; hc->plug = acpi_ged_device_plug_cb; hc->unplug_request = acpi_ged_unplug_request_cb; diff --git
a/include/hw/acpi/generic_event_device.hb/include/hw/acpi/generic_event_device.h
indexba84ce0214..e091ac2108100644include/hw/acpi/generic_event_device.h +1
-0@@ -62,6 +62,7 @@#include "hw/sysbus.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/ghes.h" +#include "hw/acpi/cpu.h" #include "qom/object.h" #define ACPI_POWER_BUTTON_DEVICE "PWRB"@@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState,
ACPI_GED)Quoted 16 lines
include/hw/acpi/generic_event_device.h +3
-0#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;
PATCH v16 4/7 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 method \\_SB.CPUS.CSCN (via \\_SB.GED.CSCN)
Architecture specific code [1] might initialize its CPUs AML code by calling common function build_cpus_aml() like below for ARM:
build_cpus_aml(scope, ms, opts, xx_madt_cpu_entry, memmap[VIRT_CPUHP_ACPI].base,
"\\_SB", "\\_SB.GED.CSCN", AML_SYSTEM_MEMORY);
[1] https://lore.kernel.org/qemu-devel/[email protected]/
--- hw/acpi/generic_event_device.c | 3 +++ include/hw/acpi/generic_event_device.h | 1 + 2 files changed, 4 insertions(+)
hw/acpi/generic_event_device.c +3 -0
@@ -108,6 +108,9 @@ 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 (AML_GED_EVT_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/generic_event_device.h +1 -0
@@ -87,6 +87,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)#define GED_DEVICE "GED"#define AML_GED_EVT_REG "EREG"#define AML_GED_EVT_SEL "ESEL" +#define AML_GED_EVT_CPU_SCAN_METHOD "\\_SB.GED.CSCN"/* * Platforms need to specify the GED event bitmap
Signature · 1 line
2.34.1
PATCH v16 5/7 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.
--- hw/acpi/cpu.c | 17 +++++++++++++---- hw/i386/acpi-build.c | 3 ++- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 18 insertions(+), 7 deletions(-)
hw/acpi/cpu.c +13 -4
@@ -338,9 +338,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;
@@ -364,14 +365,22 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts, aml_name_decl("_UID", aml_string("CPU Hotplug resources")));aml_append (cpu_ctrl_dev,aml_mutex (CPU_LOCK ,0 )); +assert ((rs ==AML_SYSTEM_IO ) || (rs ==AML_SYSTEM_MEMORY )); + 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 if (rs ==AML_SYSTEM_MEMORY ) { +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,
hw/i386/acpi-build.c +2 -1
@@ -1536,7 +1536,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
@@ -63,9 +63,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
PATCH v16 6/7 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
@@ -129,6 +129,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;struct CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;
system/physmem.c +29 -0
@@ -763,6 +763,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];
@@ -776,6 +777,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 v16 7/7 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.
Note: These are common functions exported to arch specific code. For example, for ARM this code is being referred in associated arch specific patch-set:
--- gdbstub/gdbstub.c | 13 +++++++++++++ hw/core/cpu-common.c | 5 ++++- include/exec/gdbstub.h | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-)
gdbstub/gdbstub.c +13 -0
@@ -618,6 +618,19 @@ 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_regs =0 ; + cpu->gdb_num_g_regs =0 ; +} +static void gdb_process_breakpoint_remove_all (GDBProcess *p) {CPUState *cpu =gdb_get_first_cpu_in_process (p);
hw/core/cpu-common.c +4 -1
@@ -281,7 +281,10 @@ static void cpu_common_finalize(Object *obj) g_free(cpu->plugin_state); }#endif -g_array_free (cpu->gdb_regs, TRUE); +/* If cleanup didn't happen in context to gdb_unregister_coprocessor_all */ +if (cpu->gdb_regs) { +g_array_free (cpu->gdb_regs, TRUE); + }qemu_lockcnt_destroy (&cpu->in_ioctl_lock);qemu_mutex_destroy (&cpu->work_mutex);qemu_cond_destroy (cpu->halt_cond);
include/exec/gdbstub.h +6 -0
@@ -40,6 +40,12 @@ void gdb_register_coprocessor(CPUState *cpu, gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, const GDBFeature *feature, 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 * @port_or_device: connection spec for gdb
Signature · 1 line
2.34.1