Add architecture agnostic code to support vCPU Hotplug
v2 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 4,6,7]
3. ACPI CPUs AML code change [Patch 5]
3. Helper functions to support unrealization of CPU objects [Patch 8,9]
4. Misc [Patch 2,3,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]/
Jean-Philippe Brucker (1):
target/arm/kvm: Write CPU state back to KVM on reset
Salil Mehta (9):
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: Add ACPI CPU hotplug init stub
hw/acpi: Init GED framework with cpu hotplug events hw/acpi: Update CPUs AML with cpu-(ctrl)dev change hw/acpi: Update GED _EVT method AML with cpu scan
hw/acpi: Update ACPI GED framework to support vCPU Hotplug
physmem: Add helper function to destroy CPU AddressSpace
gdbstub: Add helper function to unregister GDB register space
accel/kvm/kvm-all.c | 63 +++++++++++++++++++------- gdbstub/gdbstub.c | 14 ++++++ hw/acpi/acpi-cpu-hotplug-stub.c | 6 +++ hw/acpi/cpu.c | 25 ++++++---- hw/acpi/generic_event_device.c | 22 +++++++++ hw/i386/acpi-build.c | 2 +- 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 | 5 ++ include/hw/core/cpu.h | 1 + include/sysemu/kvm.h | 14 ++++++ softmmu/physmem.c | 25 ++++++++++ target/arm/kvm.c | 8 +++- 15 files changed, 179 insertions(+), 28 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/10 accel/kvm: Extract common KVM vCPU {creation,parking} code
KVM vCPU creation is done once during the initialization of the VM when Qemu threads are spawned. This is common to all the architectures.
Hot-unplug of vCPU results in destruction of the vCPU objects in QOM but the KVM vCPU objects in the Host KVM are not destroyed and their representative KVM vCPU objects/context in Qemu are parked.
Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
--- accel/kvm/kvm-all.c | 63 +++++++++++++++++++++++++++++++++----------- include/sysemu/kvm.h | 14 ++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-)
accel/kvm/kvm-all.c +47 -16
@@ -80,7 +80,7 @@#endif struct KVMParkedVcpu { -unsigned long vcpu_id; +int vcpu_id;int kvm_fd;QLIST_ENTRY (KVMParkedVcpu) node; };
@@ -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,int vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {
@@ -320,11 +321,49 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index; +struct KVMParkedVcpu *vcpu; + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id = vcpu_id; + vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} + +int kvm_create_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index; +KVMState *s = kvm_state; +int kvm_fd; + +DPRINTF ("kvm_create_vcpu\n" ); + +/* 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 %d" , vcpu_id); +return kvm_fd; + } + } + + cpu->vcpu_dirty = true; + cpu->kvm_fd = kvm_fd; + cpu->kvm_state = s; + 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" );
@@ -353,10 +392,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; }
@@ -369,7 +405,7 @@ void kvm_destroy_vcpu(CPUState *cpu) } } -static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id) +static int kvm_get_vcpu (KVMState *s,int vcpu_id) {struct KVMParkedVcpu *cpu;
@@ -384,7 +420,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) } } -return kvm_vm_ioctl (s,KVM_CREATE_VCPU , (void *)vcpu_id); +return -1 ; }int kvm_init_vcpu (CPUState *cpu,Error **errp)
@@ -395,19 +431,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;
include/sysemu/kvm.h +14 -0
@@ -464,6 +464,20 @@ 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 created/fetched. +* +* @returns: 0 when success, errno (<0) when failed. +*/ +int kvm_create_vcpu (CPUState *cpu); +/** +* kvm_park_vcpu - Gets a parked KVM vCPU if it exists +* @cpu: QOM CPUState object for which parked KVM vCPU has to be fetched. +* +* @returns: kvm_fd (>0) when success, -1 when failed. +*/ +void kvm_park_vcpu (CPUState *cpu);#endif /* NEED_CPU_H */
Signature · 1 line
2.34.1
Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} code
Quoted 10 lines · On Sat, 30 Sep 2023 01:19:24 +0100 Salil Mehta <[email protected]> wrote:
KVM vCPU creation is done once during the initialization of the VM when Qemu threads are spawned. This is common to all the architectures.
Hot-unplug of vCPU results in destruction of the vCPU objects in QOM but the KVM vCPU objects in the Host KVM are not destroyed and their representative KVM vCPU objects/context in Qemu are parked.
Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Signed-off-by Salil Mehta <[email protected]>
Hi Salil,
A few trivial things inline, plus a question about why cpu->cpu_index can now be used but kvm_arch_vcpu_id(cpu); was previously needed.
Thanks,
Jonathan
Quoted 27 lines
--- accel/kvm/kvm-all.c | 63 +++++++++++++++++++++++++++++++++----------- include/sysemu/kvm.h | 14 ++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-)accel/kvm/kvm-all.c +2
-1@@ -80,7 +80,7 @@#endif struct KVMParkedVcpu { -unsigned long vcpu_id; +int vcpu_id;int kvm_fd;QLIST_ENTRY (KVMParkedVcpu) node; };@@ -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,int vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {
accel/kvm/kvm-all.c err: · line 330
Quoted 10 lines
accel/kvm/kvm-all.c +7
-0@@ -320,11 +321,49 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index; +struct KVMParkedVcpu *vcpu; + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id = vcpu_id;
As vcpu_id is only used here why have the local variable? Maybe that changes in later patches, in which case ignore this.
vcpu->vcpu_id = cpu->cpu_index;
Why is kvm_arch_vcpu_id() not necessary here any more but was before?
accel/kvm/kvm-all.c err: · line 337
Quoted 7 lines
accel/kvm/kvm-all.c +7
-0+ vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} + +int kvm_create_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index;
See below. I'm not sure why it's safe not to use kvm_arch_vcpu_id() Seems a few architectures have less than trivial implementations of that function currently.
Quoted 11 lines
accel/kvm/kvm-all.c +11
-0+KVMState *s = kvm_state; +int kvm_fd; + +DPRINTF ("kvm_create_vcpu\n" ); + +/* 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 ) {
accel/kvm/kvm-all.c err: · line 358
Quoted 10 lines
accel/kvm/kvm-all.c +10
-0+error_report ("KVM_CREATE_VCPU IOCTL failed for vCPU %d" , vcpu_id); +return kvm_fd; + } + } + + cpu->vcpu_dirty = true; + cpu->kvm_fd = kvm_fd; + cpu->kvm_state = s; + cpu->dirty_pages =0 ; + cpu->throttle_us_per_full =0 ;
Trivial but I would have maintained the order wrt to the code removed below just to avoid a reviewer having to check the two bits of code do the same thing after the reorder.
Quoted 43 lines
accel/kvm/kvm-all.c +7
-7+ +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" );@@ -353,10 +392,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; }@@ -369,7 +405,7 @@ void kvm_destroy_vcpu(CPUState *cpu) } } -static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id) +static int kvm_get_vcpu (KVMState *s,int vcpu_id) {struct KVMParkedVcpu *cpu;@@ -384,7 +420,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) } } -return kvm_vm_ioctl (s,KVM_CREATE_VCPU , (void *)vcpu_id); +return -1 ; }int kvm_init_vcpu (CPUState *cpu,Error **errp)
accel/kvm/kvm-all.c int kvm_init_vcpu(CPUState *cpu, Error **errp) · line 434
Quoted 5 lines
accel/kvm/kvm-all.c +1
-1@@ -395,19 +431,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);
The switch from kvm_arch_vcpu_id(cpu) to using
int vcpu_id = cpu->cpu_index;
Seems like a functional change on some arch.
accel/kvm/kvm-all.c int kvm_init_vcpu(CPUState *cpu, Error **errp) · line 437
Quoted 4 lines
accel/kvm/kvm-all.c +2
-1if (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)",
The rewrap of the lines above seems like an unrelated change.
Quoted 18 lines
accel/kvm/kvm-all.c +0
-6kvm_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;include/sysemu/kvm.h +0
-0
include/sysemu/kvm.h void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len); · line 469
Quoted 6 lines
include/sysemu/kvm.h +3
-0@@ -464,6 +464,20 @@ 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 created/fetched.
Extra space before QOM (same below)
include/sysemu/kvm.h void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len); · line 473
Quoted 4 lines
include/sysemu/kvm.h +4
-0+* +* @returns: 0 when success, errno (<0) when failed. +*/ +int kvm_create_vcpu (CPUState *cpu);
Blank line here perhaps.
include/sysemu/kvm.h void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len); · line 476
Quoted 3 lines
include/sysemu/kvm.h +3
-0+/** +* kvm_park_vcpu - Gets a parked KVM vCPU if it exists +* @cpu: QOM CPUState object for which parked KVM vCPU has to be fetched.
We aren't returning anything, so why fetch?
Quoted 7 lines
include/sysemu/kvm.h +4
-0+* +* @returns: kvm_fd (>0) when success, -1 when failed. +*/ +void kvm_park_vcpu (CPUState *cpu);#endif /* NEED_CPU_H */
RE: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} code
Hi Jonathan,
Quoted 31 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 4:53 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} codeQuoted 9 lines · On Sat, 30 Sep 2023 01:19:24 +0100 Salil Mehta <[email protected]> wrote:
KVM vCPU creation is done once during the initialization of the VM when Qemu threads are spawned. This is common to all the architectures.
Hot-unplug of vCPU results in destruction of the vCPU objects in QOM but the KVM vCPU objects in the Host KVM are not destroyed and their representative KVM vCPU objects/context in Qemu are parked.
Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Quoted 7 lines
Quoted 1 line
Signed-off-by Salil Mehta <[email protected]>Hi Salil,
A few trivial things inline, plus a question about why
cpu->cpu_indexcan now be used butkvm_arch_vcpu_id(cpu); was previously needed.
Good point. I used the API because it was returning 'unsigned long' and it was being used across the archs. I thought maybe the size of the index could vary across archs. For example, for PowerPC above API returns vcpu_id which presumably could have different data type than an 'integer'.
But after Alex's comment, I was made to believe that this assumption might not be correct and CPU index is an 'integer' across archs and perhaps semantics of above API is not correct.
But perhaps original code was functionally correct?
Quoted 40 lines
Quoted 26 lines
accel/kvm/kvm-all.c | 63 +++++++++++++++++++++++++++++++++----------- include/sysemu/kvm.h | 14 ++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-)accel/kvm/kvm-all.c +2
-1@@ -80,7 +80,7 @@#endif struct KVMParkedVcpu { -unsigned long vcpu_id; +int vcpu_id;int kvm_fd;QLIST_ENTRY (KVMParkedVcpu) node; };@@ -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,int vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {accel/kvm/kvm-all.c err: · line 330
Quoted 10 lines
accel/kvm/kvm-all.c +7
-0@@ -320,11 +321,49 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index; +struct KVMParkedVcpu *vcpu; + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id = vcpu_id;As
vcpu_idis only used here why have the local variable? Maybe that changes in later patches, in which case ignore this.
Quoted 1 line
vcpu->vcpu_id = cpu->cpu_index;
Yes, thanks.
Quoted 3 lines
Why is
kvm_arch_vcpu_id()not necessary here any more but was before?
Because I have now changed the type of vcpu_id from 'unsigned long' to an 'integer'.
Quoted 12 lines
accel/kvm/kvm-all.c err: · line 337
Quoted 8 lines
accel/kvm/kvm-all.c +7
-0+ vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} + +int kvm_create_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index;See below. I'm not sure why it's safe not to use
kvm_arch_vcpu_id()Seems a few architectures have less than trivial implementations of that function currently.
I doubt this as well. Other architectures like PowerPC are returning different type?
Quoted 17 lines
Quoted 17 lines
accel/kvm/kvm-all.c +17
-0+KVMState *s = kvm_state; +int kvm_fd; + +DPRINTF ("kvm_create_vcpu\n" ); + +/* 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 %d" , vcpu_id); +return kvm_fd; + } + } + + cpu->vcpu_dirty = true;
Quoted 8 lines
accel/kvm/kvm-all.c err: · line 358
Quoted 4 lines
accel/kvm/kvm-all.c +4
-0+ cpu->kvm_fd = kvm_fd; + cpu->kvm_state = s; + cpu->dirty_pages =0 ; + cpu->throttle_us_per_full =0 ;Trivial but I would have maintained the order wrt to the code removed below just to avoid a reviewer having to check the two bits of code do the same thing after the reorder.
I can do that. No problem.
[...]
Quoted 5 lines
Quoted 5 lines
accel/kvm/kvm-all.c +0
-0int kvm_init_vcpu (CPUState *cpu,Error **errp)@@ -395,19 +431,14 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)trace_kvm_init_vcpu (cpu->cpu_index,kvm_arch_vcpu_id (cpu));
Quoted 7 lines
accel/kvm/kvm-all.c int kvm_init_vcpu(CPUState *cpu, Error **errp) · line 434
Quoted 2 lines
accel/kvm/kvm-all.c +1
-1- ret =kvm_get_vcpu (s,kvm_arch_vcpu_id (cpu)); + ret =kvm_create_vcpu (cpu);The switch from
kvm_arch_vcpu_id(cpu)to using
intvcpu_id=cpu->cpu_index;Seems like a functional change on some arch.
Yes, but then we need to revert to original change inside the new kvm_create_vcpu() API.
Quoted 7 lines
accel/kvm/kvm-all.c int kvm_init_vcpu(CPUState *cpu, Error **errp) · line 400
Quoted 2 lines
accel/kvm/kvm-all.c +0
-1if (ret <0 ) { - error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed(%lu)",
accel/kvm/kvm-all.c int kvm_init_vcpu(CPUState *cpu, Error **errp) · line 437
Quoted 2 lines
accel/kvm/kvm-all.c +2
-0+ error_setg_errno(errp, -ret, + "kvm_init_vcpu: kvm_create_vcpu failed (%lu)",The rewrap of the lines above seems like an unrelated change.
Function has changed from kvm_get_vcpu to kvm_create_vcpu
[...]
Quoted 7 lines
include/sysemu/kvm.h void kvm_set_sigmask_len(KVMState *s, unsigned int
Quoted 5 lines
include/sysemu/kvm.h +0
-0@@ -464,6 +464,20 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int
sigmask_len);Quoted 1 line
Quoted 8 lines
Quoted 5 lines
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 becreated/fetched.
Extra space before QOM (same below)
:)
Quoted 7 lines
Quoted 5 lines
+ *
+ * @returns: 0 when success, errno (<0) when failed.
+ */
+intkvm_create_vcpu(CPUState *cpu);Blank line here perhaps.
Ok.
Quoted 7 lines
Quoted 4 lines
+/**
+ *kvm_park_vcpu- Gets a parked KVM vCPU if it exists
+ * @cpu: QOM CPUState object for which parked KVM vCPU has to befetched.
We aren't returning anything, so why fetch?
copy-paste comment error, I think. Thanks!
cheers
Salil.
Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} code
Quoted 48 lines · On Tue, 3 Oct 2023 12:05:11 +0100 Salil Mehta <[email protected]> wrote:
Hi Jonathan,
Quoted 31 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 4:53 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} codeQuoted 9 lines · On Sat, 30 Sep 2023 01:19:24 +0100 Salil Mehta <[email protected]> wrote:
KVM vCPU creation is done once during the initialization of the VM when Qemu threads are spawned. This is common to all the architectures.
Hot-unplug of vCPU results in destruction of the vCPU objects in QOM but the KVM vCPU objects in the Host KVM are not destroyed and their representative KVM vCPU objects/context in Qemu are parked.
Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Quoted 7 lines
Quoted 1 line
Signed-off-by Salil Mehta <[email protected]>Hi Salil,
A few trivial things inline, plus a question about why
cpu->cpu_indexcan now be used butkvm_arch_vcpu_id(cpu); was previously needed.Good point. I used the API because it was returning 'unsigned long' and it was being used across the archs. I thought maybe the size of the index could vary across archs. For example, for PowerPC above API returns
vcpu_idwhich presumably could have different data type than an 'integer'.
Quoted 6 lines
But after Alex's comment, I was made to believe that this assumption might not be correct and CPU index is an 'integer' across archs and perhaps semantics of above API is not correct.
But perhaps original code was functionally correct?
I wasn't concerned with the type, but rather that the value comes from other places than cpu->cpu_index on some architectures.
Quoted 69 lines
Quoted 42 lines
Quoted 28 lines
accel/kvm/kvm-all.c | 63 +++++++++++++++++++++++++++++++++----------- include/sysemu/kvm.h | 14 ++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-)accel/kvm/kvm-all.c +2
-1@@ -80,7 +80,7 @@#endif struct KVMParkedVcpu { -unsigned long vcpu_id; +int vcpu_id;int kvm_fd;QLIST_ENTRY (KVMParkedVcpu) node; };@@ -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,int vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {accel/kvm/kvm-all.c err: · line 330
Quoted 10 lines
accel/kvm/kvm-all.c +7
-0@@ -320,11 +321,49 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index; +struct KVMParkedVcpu *vcpu; + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id = vcpu_id;As
vcpu_idis only used here why have the local variable? Maybe that changes in later patches, in which case ignore this.Quoted 1 line
vcpu->vcpu_id = cpu->cpu_index;Yes, thanks.
Quoted 3 lines
Why is
kvm_arch_vcpu_id()not necessary here any more but was before?Because I have now changed the type of
vcpu_idfrom 'unsigned long' to an 'integer'.Quoted 12 lines
accel/kvm/kvm-all.c err: · line 337
Quoted 8 lines
accel/kvm/kvm-all.c +7
-0+ vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} + +int kvm_create_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index;See below. I'm not sure why it's safe not to use
kvm_arch_vcpu_id()Seems a few architectures have less than trivial implementations of that function currently.
Quoted 3 lines
I doubt this as well. Other architectures like PowerPC are returning different type?
It wasn't the type that bothered, me but rather that the source of the data isn't always cpu->cpu_index so I have no idea if the values are consistent.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
accel/kvm/kvm-all.c +0
-1if (ret <0 ) { - error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed
Quoted 8 lines
Quoted 5 lines
(%lu)",
accel/kvm/kvm-all.c int kvm_init_vcpu(CPUState *cpu, Error **errp) · line 437
Quoted 2 lines
accel/kvm/kvm-all.c +2
-0+ error_setg_errno(errp, -ret, + "kvm_init_vcpu: kvm_create_vcpu failed (%lu)",The rewrap of the lines above seems like an unrelated change.
Function has changed from
kvm_get_vcputokvm_create_vcpu
ah. Eyes jumped over that :)
RE: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} code
Quoted 75 lines
From: Jonathan Cameron <[email protected]>
Sent: Tuesday, October 3, 2023 12:51 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} codeQuoted 53 lines · On Tue, 3 Oct 2023 12:05:11 +0100 Salil Mehta <[email protected]> wrote:
Hi Jonathan,
Quoted 31 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 4:53 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} codeQuoted 9 lines · On Sat, 30 Sep 2023 01:19:24 +0100 Salil Mehta <[email protected]> wrote:
KVM vCPU creation is done once during the initialization of the VM when Qemu threads are spawned. This is common to all the architectures.
Hot-unplug of vCPU results in destruction of the vCPU objects in QOM but the KVM vCPU objects in the Host KVM are not destroyed and their representative KVM vCPU objects/context in Qemu are parked.
Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Quoted 7 lines
Quoted 1 line
Signed-off-by Salil Mehta <[email protected]>Hi Salil,
A few trivial things inline, plus a question about why
cpu->cpu_indexcan now be used butkvm_arch_vcpu_id(cpu); was previously needed.Good point. I used the API because it was returning 'unsigned long' and it was being used across the archs. I thought maybe the size of the index could vary across archs. For example, for PowerPC above API returns
vcpu_idwhich presumably could have different data type than an 'integer'.But after Alex's comment, I was made to believe that this assumption might not be correct and CPU index is an 'integer' across archs and perhaps semantics of above API is not correct.
Quoted 5 lines
Quoted 1 line
But perhaps original code was functionally correct?
I wasn't concerned with the type, but rather that the value comes from other places than
cpu->cpu_indexon some architectures.
Sure, I meant there is a reason why type was chosen as 'unsigned long' and not an 'integer'. Perhaps the value can exceed the 'integer' size limits because of the way CPU index is being created on certain archs?
If we try to put value from a larger container 'unsigned long' to a smaller container 'integer' things can go wrong.
[...]
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
accel/kvm/kvm-all.c err: · line 337
Quoted 8 lines
accel/kvm/kvm-all.c +7
-0+ vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} + +int kvm_create_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index;See below. I'm not sure why it's safe not to use
kvm_arch_vcpu_id()Seems a few architectures have less than trivial implementations of that function currently.
Quoted 6 lines
Quoted 3 lines
I doubt this as well. Other architectures like PowerPC are returning different type?
It wasn't the type that bothered, me but rather that the source of the data isn't always
cpu->cpu_indexso I have no idea if the values are consistent.
Got it.
I meant 'unsigned long' return type in the kvm_arch_vcpu_id(). On some Architectures, the required container size for their vcpu-id could exceed an 'integer'. Sorry, for not making it clear.
Thanks
Salil.
Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} code
In reply to Salil MehtaQuoted 2 lines · Salil Mehta
KVM vCPU creation is done once during the initialization of the VM when Qemu threads are spawned. This is common to all the architectures.
^^^^^^^^^^^^^^^^^^^
thread is spawned.
Quoted 18 lines
Hot-unplug of vCPU results in destruction of the vCPU objects in QOM but the KVM vCPU objects in the Host KVM are not destroyed and their representative KVM vCPU objects/context in Qemu are parked.
Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Signed-off-by Salil Mehta <[email protected]>--- accel/kvm/kvm-all.c | 63 +++++++++++++++++++++++++++++++++----------- include/sysemu/kvm.h | 14 ++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-)accel/kvm/kvm-all.c +0
-0
accel/kvm/kvm-all.c line 83
Quoted 5 lines
accel/kvm/kvm-all.c +1
-1@@ -80,7 +80,7 @@#endif struct KVMParkedVcpu { -unsigned long vcpu_id; +int vcpu_id;
@vcpu_id represents the vCPU index (CPUState::cpu_index) instead of the architectural CPU ID any more. However, I don't understand how it works for x86, and more comments regarding it can be seen below.
Quoted 16 lines
accel/kvm/kvm-all.c +2
-0int kvm_fd;QLIST_ENTRY (KVMParkedVcpu) node; };@@ -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,int vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {@@ -320,11 +321,49 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu)
accel/kvm/kvm-all.c err: · line 334
Quoted 10 lines
accel/kvm/kvm-all.c +10
-0+{ +int vcpu_id = cpu->cpu_index; +struct KVMParkedVcpu *vcpu; + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id = vcpu_id; + vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} +
@vcpu_id can be dropped as suggested previously.
vcpu->vcpu_id = cpu->cpu_index;
Quoted 18 lines
accel/kvm/kvm-all.c +18
-0+int kvm_create_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index; +KVMState *s = kvm_state; +int kvm_fd; + +DPRINTF ("kvm_create_vcpu\n" ); + +/* 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 %d" , vcpu_id); +return kvm_fd; + } + }
accel/kvm/kvm-all.c err: · line 362
Quoted 10 lines
accel/kvm/kvm-all.c +10
-0+ + cpu->vcpu_dirty = true; + cpu->kvm_fd = kvm_fd; + cpu->kvm_state = s; + cpu->dirty_pages =0 ; + cpu->throttle_us_per_full =0 ; + +return 0 ; +} +
The comments here can be dropped since the code is self-explaining.
@vcpu_id represents vCPU index, instead of the architecrual vCPU ID any more. @vcpu_id is passed to host through ioctl(KVM_CREATE_VCPU), which is expected as an architecrual vCPU ID instead of a vCPU index by host. It's indicated by 'struct kvm_vcpu' as below.
struct kvm_vcpu {
:
int vcpu_id; /* id given by userspace at creation */
int vcpu_idx; /* index into kvm->vcpu_array */
};Function kvm_arch_vcpu_id() converts the vCPU instance or vCPU index to the architecrual vCPU ID. All architectures except x86 simply returns vCPU index (CPUState::cpu_index) as the architecrural vCPU ID. x86 returns the APIC ID. Treating them equally seems to break x86.
Quoted 30 lines
accel/kvm/kvm-all.c +2
-6static 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" );@@ -353,10 +392,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; }@@ -369,7 +405,7 @@ void kvm_destroy_vcpu(CPUState *cpu) } } -static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id) +static int kvm_get_vcpu (KVMState *s,int vcpu_id) {struct KVMParkedVcpu *cpu;
accel/kvm/kvm-all.c static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) · line 425
Quoted 7 lines
accel/kvm/kvm-all.c +1
-1@@ -384,7 +420,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) } } -return kvm_vm_ioctl (s,KVM_CREATE_VCPU , (void *)vcpu_id); +return -1 ; }
Why we have -1 here. -ENOENT seems more descriptive?
Quoted 39 lines
accel/kvm/kvm-all.c +3
-8int kvm_init_vcpu (CPUState *cpu,Error **errp)@@ -395,19 +431,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;include/sysemu/kvm.h +7
-0@@ -464,6 +464,20 @@ 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 created/fetched. +* +* @returns: 0 when success, errno (<0) when failed. +*/ +int kvm_create_vcpu (CPUState *cpu);
include/sysemu/kvm.h void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len); · line 483
Quoted 10 lines
include/sysemu/kvm.h +7
-0+/** +* kvm_park_vcpu - Gets a parked KVM vCPU if it exists +* @cpu: QOM CPUState object for which parked KVM vCPU has to be fetched. +* +* @returns: kvm_fd (>0) when success, -1 when failed. +*/ +void kvm_park_vcpu (CPUState *cpu);#endif /* NEED_CPU_H */
Thanks,
Gavin
RE: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} code
Hi Gavin,
Quoted 20 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 12:18 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 01/10] accel/kvm: Extract common KVM vCPU {creation,parking} code
Quoted 5 lines
Quoted 2 lines · Salil Mehta
KVM vCPU creation is done once during the initialization of the VM when Qemu threads are spawned. This is common to all the architectures.
^^^^^^^^^^^^^^^^^^^
thread is spawned.
Yes, will fix.
Thanks
Salil.
Quoted 20 lines
Quoted 2 lines
Hot-unplug of vCPU results in destruction of the vCPU objects in QOM but the KVM vCPU objects in the Host KVM are not destroyed and their
representative
Quoted 17 lines
KVM vCPU objects/context in Qemu are parked.
Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Signed-off-by Salil Mehta <[email protected]>--- accel/kvm/kvm-all.c | 63 +++++++++++++++++++++++++++++++++----------- include/sysemu/kvm.h | 14 ++++++++++ 2 files changed, 61 insertions(+), 16 deletions(-)accel/kvm/kvm-all.c +0
-0@@ -80,7 +80,7 @@#endif
Quoted 7 lines
accel/kvm/kvm-all.c line 83
Quoted 3 lines
accel/kvm/kvm-all.c +1
-1struct KVMParkedVcpu { -unsigned long vcpu_id; +int vcpu_id;@vcpu_id represents the vCPU index (
CPUState::cpu_index) instead of the architectural CPU ID any more. However, I don't understand how it works for x86, and more comments regarding it can be seen below.
I missed the reason why I had used 'unsigned long' everywhere in the first change. You can check the PowerPC, it returns vcpu_id which might not be an 'integer'. Hence, this change could actually create a problem.
Quoted 29 lines
Quoted 16 lines
accel/kvm/kvm-all.c +2
-0int kvm_fd;QLIST_ENTRY (KVMParkedVcpu) node; };@@ -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,int vcpu_id);static inline void kvm_resample_fd_remove (int gsi) {@@ -320,11 +321,49 @@ err:return ret; } +void kvm_park_vcpu (CPUState *cpu)accel/kvm/kvm-all.c err: · line 334
Quoted 10 lines
accel/kvm/kvm-all.c +10
-0+{ +int vcpu_id = cpu->cpu_index; +struct KVMParkedVcpu *vcpu; + + vcpu =g_malloc0 (sizeof (*vcpu)); + vcpu->vcpu_id = vcpu_id; + vcpu->kvm_fd = cpu->kvm_fd; +QLIST_INSERT_HEAD (&kvm_state->kvm_parked_vcpus, vcpu, node); +} +@vcpu_id can be dropped as suggested previously.
Quoted 1 line
vcpu->vcpu_id = cpu->cpu_index;
Yes, agreed.
Thanks
Salil.
Quoted 31 lines
Quoted 18 lines
accel/kvm/kvm-all.c +18
-0+int kvm_create_vcpu (CPUState *cpu) +{ +int vcpu_id = cpu->cpu_index; +KVMState *s = kvm_state; +int kvm_fd; + +DPRINTF ("kvm_create_vcpu\n" ); + +/* 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 %d" , vcpu_id); +return kvm_fd; + } + }accel/kvm/kvm-all.c err: · line 362
Quoted 10 lines
accel/kvm/kvm-all.c +10
-0+ + cpu->vcpu_dirty = true; + cpu->kvm_fd = kvm_fd; + cpu->kvm_state = s; + cpu->dirty_pages =0 ; + cpu->throttle_us_per_full =0 ; + +return 0 ; +} +The comments here can be dropped since the code is self-explaining.
Quoted 6 lines
@vcpu_id represents vCPU index, instead of the architecrual vCPU ID any more.
@vcpu_id is passed to host throughioctl(KVM_CREATE_VCPU), which is expected
as an architecrual vCPU ID instead of a vCPU index by host. It's indicated by 'structkvm_vcpu' as below.
That should not be part of this change. I think.
Quoted 10 lines
struct kvm_vcpu { : int vcpu_id; /* id given by userspace at creation */ int vcpu_idx; /* index into kvm->vcpu_array */ };Function
kvm_arch_vcpu_id()converts the vCPU instance or vCPU index to the architecrual vCPU ID. All architectures except x86 simply returns vCPU index (CPUState::cpu_index) as the architecrural vCPU ID. x86 returns the APIC ID. Treating them equally seems to break x86.
I think PowerPC returns a different Id as well.
[...]
Quoted 10 lines
accel/kvm/kvm-all.c static int kvm_get_vcpu(KVMState *s, unsigned long
Quoted 6 lines
accel/kvm/kvm-all.c +1
-1-static int kvm_get_vcpu (KVMState *s,unsigned long vcpu_id) +static int kvm_get_vcpu (KVMState *s,int vcpu_id) {struct KVMParkedVcpu *cpu;@@ -384,7 +420,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long
vcpu_id)Quoted 3 lines
accel/kvm/kvm-all.c +0
-0} }
Quoted 6 lines
accel/kvm/kvm-all.c static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id) · line 425
Quoted 4 lines
accel/kvm/kvm-all.c +1
-1-return kvm_vm_ioctl (s,KVM_CREATE_VCPU , (void *)vcpu_id); +return -1 ; }Why we have -1 here.
-ENOENTseems more descriptive?
Agreed.
Thanks
Salil.
PATCH v2 2/10 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,12 +1,12 @@#include "qemu/osdep.h" #include "migration/vmstate.h" #include "hw/acpi/cpu.h" +#include "hw/acpi/cpu_hotplug.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 V2 02/10] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
Quoted 6 lines · On Sat, 30 Sep 2023 01:19:25 +0100 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]>
LGTM
Quoted 36 lines
--- 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,12 +1,12 @@#include "qemu/osdep.h" #include "migration/vmstate.h" #include "hw/acpi/cpu.h" +#include "hw/acpi/cpu_hotplug.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;
RE: [PATCH V2 02/10] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
Hi Jonathan,
Quoted 24 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 4:55 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 02/10] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header fileQuoted 1 line · On Sat, 30 Sep 2023 01:19:25 +0100 Salil Mehta <[email protected]> wrote:
CPU ctrl-dev MMIO region length could be used in ACPI GED and various
other
Quoted 8 lines
Quoted 5 lines
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]>LGTM
Reviewed-by Jonathan Cameron <[email protected]>
Thanks
Salil.
Re: [PATCH V2 02/10] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
In reply to Salil MehtaQuoted 11 lines · Salil Mehta
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]>--- hw/acpi/cpu.c | 2 +- include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
RE: [PATCH V2 02/10] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
Hi Gavin,
Quoted 34 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 12:20 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 02/10] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header fileQuoted 1 line · Salil Mehta
CPU ctrl-dev MMIO region length could be used in ACPI GED and various
other
Quoted 10 lines
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]>--- hw/acpi/cpu.c | 2 +- include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Quoted 1 line
Reviewed-by Gavin Shan <[email protected]>
Thanks
Salil.
PATCH v2 3/10 hw/acpi: Add ACPI CPU hotplug init stub
In reply to Salil MehtaACPI 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 ++++++ 1 file changed, 6 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 ;
Signature · 1 line
2.34.1
Re: [PATCH V2 03/10] hw/acpi: Add ACPI CPU hotplug init stub
Quoted 5 lines · On Sat, 30 Sep 2023 01:19:26 +0100 Salil Mehta <[email protected]> wrote:
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.Signed-off-by Salil Mehta <[email protected]>
Seems reasonable. For the other similar cases a stub isn't needed because GED is built when CONFIG_ACPI_HW_REDUCED=y and that select ACPI_MEMORY_HOTPLUG and ACPI_NVDIMM
You could do the same for the CPU hotplug case and instantiate a potentially useless memory region etc. This seems more sensible to me
Quoted 21 lines
--- hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++ 1 file changed, 6 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 ;
RE: [PATCH V2 03/10] hw/acpi: Add ACPI CPU hotplug init stub
Quoted 28 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 5:01 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 03/10] hw/acpi: Add ACPI CPU hotplug init stubQuoted 1 line · On Sat, 30 Sep 2023 01:19:26 +0100 Salil Mehta <[email protected]> wrote:
ACPI CPU hotplug related initialization should only happen if
ACPI_CPU_HOTPLUGQuoted 1 line
support has been enabled for particular architecture. Add
cpu_hotplug_hw_init()Quoted 3 lines
stub to avoid compilation break.
Signed-off-by Salil Mehta <[email protected]>
Quoted 8 lines
Seems reasonable. For the other similar cases a stub isn't needed because GED is built when
CONFIG_ACPI_HW_REDUCED=yand that selectACPI_MEMORY_HOTPLUGandACPI_NVDIMMYou could do the same for the CPU hotplug case and instantiate a potentially useless memory region etc. This seems more sensible to me
Reviewed-by Jonathan Cameron <[email protected]>
Thanks
Salil.
Quoted 23 lines
hw/acpi/acpi-cpu-hotplug-
Quoted 4 lines
hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/acpi/acpi-cpu-hotplug- renamed from hw/acpi/acpi-cpu-hotplug-stub.c +0
-0
stub.chw/acpi/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion
Quoted 4 lines
index
3fc4b14c26..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/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
Quoted 10 lines
hw/acpi/acpi-cpu-hotplug-stub.c +6
-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)
Quoted 2 lines
hw/acpi/acpi-cpu-hotplug-stub.c +0
-0{return ;
Re: [PATCH V2 03/10] hw/acpi: Add ACPI CPU hotplug init stub
In reply to Salil MehtaQuoted 9 lines · Salil Mehta
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.Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/acpi/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, · line 25
Quoted 12 lines
hw/acpi/acpi-cpu-hotplug-stub.c +4
-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 ;
^^^^^^
hw/acpi/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, · line 27
Quoted 2 lines
hw/acpi/acpi-cpu-hotplug-stub.c +2
-0+} +
I guess the return is the outcome by following the pattern of other functions ;-)
hw/acpi/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, · line 30
Quoted 3 lines
hw/acpi/acpi-cpu-hotplug-stub.c +0
-0void acpi_cpu_ospm_status (CPUHotplugState *cpu_st,ACPIOSTInfoList ***list) {return ;
Thanks,
Gavin
RE: [PATCH V2 03/10] hw/acpi: Add ACPI CPU hotplug init stub
Quoted 27 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 12:25 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 03/10] hw/acpi: Add ACPI CPU hotplug init stubQuoted 1 line · Salil Mehta
ACPI CPU hotplug related initialization should only happen if
ACPI_CPU_HOTPLUGQuoted 1 line
support has been enabled for particular architecture. Add
cpu_hotplug_hw_init()Quoted 2 lines
stub to avoid compilation break.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++ 1 file changed, 6 insertions(+)Reviewed-by Gavin Shan <[email protected]>
Thanks
Salil.
Quoted 16 lines
hw/acpi/acpi-cpu-hotplug-
Quoted 2 lines
hw/acpi/acpi-cpu-hotplug- renamed from hw/acpi/acpi-cpu-hotplug-stub.c +0
-0
stub.chw/acpi/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion
Quoted 4 lines
index
3fc4b14c26..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/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, · line 25
Quoted 7 lines
hw/acpi/acpi-cpu-hotplug-stub.c +4
-0return ; } +void cpu_hotplug_hw_init (MemoryRegion *as,Object *owner, +CPUHotplugState *state,hwaddr base_addr) +{ +return ;^^^^^^
Quoted 5 lines
hw/acpi/acpi-cpu-hotplug-stub.c void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, · line 27
Quoted 2 lines
hw/acpi/acpi-cpu-hotplug-stub.c +2
-0+} +I guess the return is the outcome by following the pattern of other functions ;-)
I can remove it. :)
PATCH v2 4/10 hw/acpi: Init GED framework with cpu hotplug events
In reply to Salil MehtaACPI GED(as described in the ACPI 6.2 spec) can be used to generate ACPI events when OSPM/guest receives an interrupt listed in the _CRS object of GED. OSPM then maps or demultiplexes the event by evaluating _EVT method.
This change adds the support of cpu hotplug event initialization in the existing GED framework.
--- hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/generic_event_device.h | 5 +++++ 2 files changed, 13 insertions(+)
hw/acpi/generic_event_device.c +8 -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, };/*
@@ -400,6 +401,13 @@ 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); + + s->cpuhp.device =OBJECT (s); +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 +5 -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"
@@ -97,6 +98,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;
@@ -108,6 +110,9 @@ struct AcpiGedState {SysBusDevice parent_obj;MemHotplugState memhp_state;MemoryRegion container_memhp; +CPUHotplugState cpuhp_state; +MemoryRegion container_cpuhp; +AcpiCpuHotplug cpuhp;GEDState ged_state;uint32_t ged_event_bitmap;qemu_irq irq;
Signature · 1 line
2.34.1
Re: [PATCH V2 04/10] hw/acpi: Init GED framework with cpu hotplug events
Quoted 10 lines · On Sat, 30 Sep 2023 01:19:27 +0100 Salil Mehta <[email protected]> wrote:
ACPI GED(as described in the ACPI 6.2 spec) can be used to generate ACPI events when OSPM/guest receives an interrupt listed in the
_CRSobject of GED. OSPM then maps or demultiplexes the event by evaluating_EVTmethod.This change adds the support of cpu hotplug event initialization in the existing GED framework.
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>
Oops. I replied to v1 I think.
Quoted 61 lines
--- hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/generic_event_device.h | 5 +++++ 2 files changed, 13 insertions(+)hw/acpi/generic_event_device.c +8
-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, };/* @@ -400,6 +401,13 @@ 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); + + s->cpuhp.device =OBJECT (s); +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 +5
-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" @@ -97,6 +98,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;@@ -108,6 +110,9 @@ struct AcpiGedState {SysBusDevice parent_obj;MemHotplugState memhp_state;MemoryRegion container_memhp; +CPUHotplugState cpuhp_state; +MemoryRegion container_cpuhp; +AcpiCpuHotplug cpuhp;GEDState ged_state;uint32_t ged_event_bitmap;qemu_irq irq;
RE: [PATCH V2 04/10] hw/acpi: Init GED framework with cpu hotplug events
Quoted 31 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 5:07 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 04/10] hw/acpi: Init GED framework with cpu hotplug eventsQuoted 1 line · On Sat, 30 Sep 2023 01:19:27 +0100 Salil Mehta <[email protected]> wrote:
ACPI GED(as described in the ACPI 6.2 spec) can be used to generate ACPI
events
Quoted 1 line
when OSPM/guest receives an interrupt listed in the
_CRSobject of GED.OSPM
Quoted 5 lines
then maps or demultiplexes the event by evaluating
_EVTmethod.This change adds the support of cpu hotplug event initialization in the existing GED framework.
Quoted 6 lines
Quoted 3 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>Oops. I replied to v1 I think.
Reviewed-by Jonathan Cameron <[email protected]>
Thanks
Salil.
Re: [PATCH V2 04/10] hw/acpi: Init GED framework with cpu hotplug events
In reply to Salil MehtaQuoted 7 lines · Salil Mehta
ACPI GED(as described in the ACPI 6.2 spec) can be used to generate ACPI events when OSPM/guest receives an interrupt listed in the
_CRSobject of GED. OSPM then maps or demultiplexes the event by evaluating_EVTmethod.This change adds the support of cpu hotplug event initialization in the existing GED framework.
Quoted 8 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/generic_event_device.h | 5 +++++ 2 files changed, 13 insertions(+)
RE: [PATCH V2 04/10] hw/acpi: Init GED framework with cpu hotplug events
Quoted 39 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 12:29 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 04/10] hw/acpi: Init GED framework with cpu hotplug eventsQuoted 1 line · Salil Mehta
ACPI GED(as described in the ACPI 6.2 spec) can be used to generate ACPI
events
Quoted 1 line
when OSPM/guest receives an interrupt listed in the
_CRSobject of GED.OSPM
Quoted 5 lines
then maps or demultiplexes the event by evaluating
_EVTmethod.This change adds the support of cpu hotplug event initialization in the existing GED framework.
Quoted 8 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/generic_event_device.c | 8 ++++++++ include/hw/acpi/generic_event_device.h | 5 +++++ 2 files changed, 13 insertions(+)
Quoted 1 line
Reviewed-by Gavin Shan <[email protected]>
Thanks
Salil.
PATCH v2 5/10 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 based on PCI and is IO port based and hence 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.
This cpus AML code change updates the existing inerface of the build cpus AML function to accept both IO/MEMORY type regions and update the _CRS object correspondingly.
--- hw/acpi/cpu.c | 23 ++++++++++++++++------- hw/i386/acpi-build.c | 2 +- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 20 insertions(+), 10 deletions(-)
hw/acpi/cpu.c +16 -7
@@ -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, -hwaddr io_base, +hwaddr base_addr,const char *res_root, -const char *event_handler_method) +const char *event_handler_method, +AmlRegionSpace rs) {Aml *ifctx;Aml *field;
@@ -367,13 +368,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,
@@ -699,9 +706,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 +1 -1
@@ -1550,7 +1550,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); +"\\_SB.PCI0" ,"\\_GPE._E02" ,AML_SYSTEM_IO ); }if (pcms->memhp_io_base && nr_mem) {
include/hw/acpi/cpu.h +3 -2
@@ -56,9 +56,10 @@ typedef struct CPUHotplugFeatures { } CPUHotplugFeatures;void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +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 V2 05/10] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
Quoted 10 lines · On Sat, 30 Sep 2023 01:19:28 +0100 Salil Mehta <[email protected]> wrote:
CPUs Control
device(\\_SB.PCI0)register interface for the x86 arch is based on PCI and is IO port based and hence 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.This cpus AML code change updates the existing inerface of the build cpus AML function to accept both IO/MEMORY type regions and update the
_CRSobject correspondingly.
This also makes a change to make the event_handler_method optional. Would be good to explain why or leave that for a future patch.
Otherwise looks fine.
Quoted 94 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/cpu.c | 23 ++++++++++++++++------- hw/i386/acpi-build.c | 2 +- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 20 insertions(+), 10 deletions(-)hw/acpi/cpu.c +16
-7@@ -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, -hwaddr io_base, +hwaddr base_addr,const char *res_root, -const char *event_handler_method) +const char *event_handler_method, +AmlRegionSpace rs) {Aml *ifctx;Aml *field;@@ -367,13 +368,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,@@ -699,9 +706,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 +1
-1@@ -1550,7 +1550,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); +"\\_SB.PCI0" ,"\\_GPE._E02" ,AML_SYSTEM_IO ); }if (pcms->memhp_io_base && nr_mem) {include/hw/acpi/cpu.h +3
-2@@ -56,9 +56,10 @@ typedef struct CPUHotplugFeatures { } CPUHotplugFeatures;void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +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);
RE: [PATCH V2 05/10] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
Quoted 29 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 5:10 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 05/10] hw/acpi: Update CPUs AML with cpu-(ctrl)dev changeQuoted 7 lines · On Sat, 30 Sep 2023 01:19:28 +0100 Salil Mehta <[email protected]> wrote:
CPUs Control
device(\\_SB.PCI0)register interface for the x86 arch is based on PCI and is IO port based and hence 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.
Quoted 6 lines
Quoted 3 lines
This cpus AML code change updates the existing inerface of the build cpus AML function to accept both IO/MEMORY type regions and update the
_CRSobject correspondingly.This also makes a change to make the
event_handler_methodoptional. Would be good to explain why or leave that for a future patch.
Will add.
Thanks
Salil.
Quoted 105 lines
Otherwise looks fine.
Quoted 15 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/cpu.c | 23 ++++++++++++++++------- hw/i386/acpi-build.c | 2 +- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 20 insertions(+), 10 deletions(-)hw/acpi/cpu.c +0
-0hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug = { · line 340
Quoted 3 lines
hw/acpi/cpu.c +0
-0@@ -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,
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 10 lines
hw/acpi/cpu.c +3
-2-hwaddr io_base, +hwaddr base_addr, const char *res_root, - const char *event_handler_method) + const char *event_handler_method, + AmlRegionSpace rs) { Aml *ifctx;Aml *field;@@ -367,13 +368,19 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 6 lines
hw/acpi/cpu.c +2
-1aml_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,
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 4 lines
hw/acpi/cpu.c +3
-0ACPI_CPU_HOTPLUG_REG_LEN)); + }else { + aml_append(crs, aml_memory32_fixed(base_addr, + ACPI_CPU_HOTPLUG_REG_LEN,
AML_READ_WRITE));hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 7 lines
hw/acpi/cpu.c +2
-1+ } +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),hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 5 lines
hw/acpi/cpu.c +1
-0+aml_operation_region ("PRST" , rs,aml_int (base_addr), ACPI_CPU_HOTPLUG_REG_LEN)); field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,@@ -699,9 +706,11 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 32 lines
hw/acpi/cpu.c +5
-3aml_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 +1
-1@@ -1550,7 +1550,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); +"\\_SB.PCI0" ,"\\_GPE._E02" ,AML_SYSTEM_IO ); }if (pcms->memhp_io_base && nr_mem) {include/hw/acpi/cpu.h +0
-0include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures { · line 58
Quoted 3 lines
include/hw/acpi/cpu.h +0
-0@@ -56,9 +56,10 @@ typedef struct CPUHotplugFeatures { } CPUHotplugFeatures; void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures {
Quoted 8 lines
include/hw/acpi/cpu.h +3
-2-hwaddr io_base, +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);
Quoted 1 line
Re: [PATCH V2 05/10] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
In reply to Salil MehtaQuoted 11 lines · Salil Mehta
CPUs Control
device(\\_SB.PCI0)register interface for the x86 arch is based on PCI and is IO port based and hence 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.This cpus AML code change updates the existing inerface of the build cpus AML function to accept both IO/MEMORY type regions and update the
_CRSobject correspondingly.
Quoted 9 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/cpu.c | 23 ++++++++++++++++------- hw/i386/acpi-build.c | 2 +- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 20 insertions(+), 10 deletions(-)
With commit log improved to address Jonathan's comments why @event_handler_method won't be needed on aarch64:
Quoted 74 lines
hw/acpi/cpu.c +16
-7@@ -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, -hwaddr io_base, +hwaddr base_addr,const char *res_root, -const char *event_handler_method) +const char *event_handler_method, +AmlRegionSpace rs) {Aml *ifctx;Aml *field;@@ -367,13 +368,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,@@ -699,9 +706,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 +1
-1@@ -1550,7 +1550,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); +"\\_SB.PCI0" ,"\\_GPE._E02" ,AML_SYSTEM_IO ); }if (pcms->memhp_io_base && nr_mem) {include/hw/acpi/cpu.h +0
-0@@ -56,9 +56,10 @@ typedef struct CPUHotplugFeatures { } CPUHotplugFeatures;
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures { · line 65
Quoted 10 lines
include/hw/acpi/cpu.h +3
-2void build_cpus_aml (Aml *table,MachineState *machine,CPUHotplugFeatures opts, -hwaddr io_base, +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);
Thanks,
Gavin
RE: [PATCH V2 05/10] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
Quoted 42 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 1:09 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 05/10] hw/acpi: Update CPUs AML with cpu-(ctrl)dev changeQuoted 11 lines · Salil Mehta
CPUs Control
device(\\_SB.PCI0)register interface for the x86 arch is based on PCI and is IO port based and hence 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.This cpus AML code change updates the existing inerface of the build cpus AML function to accept both IO/MEMORY type regions and update the
_CRSobject correspondingly.Quoted 9 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/cpu.c | 23 ++++++++++++++++------- hw/i386/acpi-build.c | 2 +- include/hw/acpi/cpu.h | 5 +++-- 3 files changed, 20 insertions(+), 10 deletions(-)
Quoted 5 lines
With commit log improved to address Jonathan's comments why @event_handler_method
won't be needed on aarch64:Reviewed-by Gavin Shan <[email protected]>
Thanks
Salil.
Quoted 97 lines
hw/acpi/cpu.c const VMStateDescription vmstate_cpu_hotplug = { · line 340
Quoted 9 lines
hw/acpi/cpu.c +0
-0@@ -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,
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 10 lines
hw/acpi/cpu.c +3
-2-hwaddr io_base, +hwaddr base_addr, const char *res_root, - const char *event_handler_method) + const char *event_handler_method, + AmlRegionSpace rs) { Aml *ifctx;Aml *field;@@ -367,13 +368,19 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 6 lines
hw/acpi/cpu.c +2
-1aml_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,
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 4 lines
hw/acpi/cpu.c +3
-0ACPI_CPU_HOTPLUG_REG_LEN)); + }else { + aml_append(crs, aml_memory32_fixed(base_addr, + ACPI_CPU_HOTPLUG_REG_LEN,
AML_READ_WRITE));hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
Quoted 5 lines
hw/acpi/cpu.c +2
-0+ } +aml_append (cpu_ctrl_dev,aml_name_decl ("_CRS" , crs));/* declare CPU hotplug MMIO region with related access fields */
hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState · line 376
Quoted 2 lines
hw/acpi/cpu.c +0
-1aml_append(cpu_ctrl_dev, - aml_operation_region("PRST", AML_SYSTEM_IO,
aml_int(io_base),hw/acpi/cpu.c void build_cpus_aml(Aml *table, MachineState
Quoted 5 lines
hw/acpi/cpu.c +1
-0+aml_operation_region ("PRST" , rs,aml_int (base_addr), ACPI_CPU_HOTPLUG_REG_LEN)); field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,@@ -699,9 +706,11 @@ void build_cpus_aml(Aml *table, MachineState*machine, CPUHotplugFeatures opts,
Quoted 32 lines
hw/acpi/cpu.c +5
-3aml_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 +1
-1@@ -1550,7 +1550,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, .fw_unplugs_cpu = pm->smi_on_cpu_unplug, };build_cpus_aml (dsdt, machine, opts, pm->cpu_hp_io_base, -"\\_SB.PCI0" ,"\\_GPE._E02" ); +"\\_SB.PCI0" ,"\\_GPE._E02" ,AML_SYSTEM_IO ); }if (pcms->memhp_io_base && nr_mem) {include/hw/acpi/cpu.h +0
-0include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures { · line 58
Quoted 3 lines
include/hw/acpi/cpu.h +0
-0@@ -56,9 +56,10 @@ typedef struct CPUHotplugFeatures { } CPUHotplugFeatures; void build_cpus_aml(Aml *table, MachineState *machine,CPUHotplugFeatures opts,
include/hw/acpi/cpu.h typedef struct CPUHotplugFeatures {
Quoted 8 lines
include/hw/acpi/cpu.h +3
-2-hwaddr io_base, +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);
Quoted 1 line
Thanks,
Gavin
PATCH v2 6/10 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.
The change in this patch updates the GED AML _EVT method with the call to \\_SB.CPUS.CSCN which will do above.
--- hw/acpi/generic_event_device.c | 4 ++++ include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 6 insertions(+)
hw/acpi/generic_event_device.c +4 -0
@@ -108,6 +108,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 V2 06/10] hw/acpi: Update GED _EVT method AML with cpu scan
Quoted 10 lines · On Sat, 30 Sep 2023 01:19:29 +0100 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.The change in this patch updates the GED AML
_EVTmethod with the call to \\_SB.CPUS.CSCN which will do above.Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>
One trivial suggested addition inline (dropping existing definition that this replicates). With that tidied up
Quoted 25 lines
--- hw/acpi/generic_event_device.c | 4 ++++ include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 6 insertions(+)hw/acpi/generic_event_device.c +4
-0@@ -108,6 +108,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 +0
-0
include/hw/acpi/cpu_hotplug.h line 23
Quoted 4 lines
include/hw/acpi/cpu_hotplug.h +1
-0@@ -20,6 +20,8 @@#include "hw/acpi/cpu.h" #define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SCAN_METHOD "CSCN"
This seems to already be defined in hw/acpi/cpu.c Can we drop it from there given that file now includes this header anyway.
Quoted 4 lines
include/hw/acpi/cpu_hotplug.h +1
-0+#define ACPI_CPU_CONTAINER "\\_SB.CPUS" typedef struct AcpiCpuHotplug { Object *device;
RE: [PATCH V2 06/10] hw/acpi: Update GED _EVT method AML with cpu scan
Quoted 29 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 5:14 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 06/10] hw/acpi: Update GED_EVTmethod AML with cpu scanQuoted 7 lines · On Sat, 30 Sep 2023 01:19:29 +0100 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.The change in this patch updates the GED AML
_EVTmethod with the call to \\_SB.CPUS.CSCN which will do above.
Quoted 7 lines
Quoted 3 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>One trivial suggested addition inline (dropping existing definition that this replicates). With that tidied up
Reviewed-by Jonathan Cameron <[email protected]>
Thanks
Salil.
Quoted 33 lines
Review
Quoted 7 lines
--- hw/acpi/generic_event_device.c | 4 ++++ include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 6 insertions(+)(quoted diff) +0
-0
b/hw/acpi/generic_event_device.chw/acpi/generic_event_device.c void build_ged_aml(Aml *table, const char *name,
Quoted 4 lines
index
d2fa1d0e4a..62d504d231100644hw/acpi/generic_event_device.c +0
-0@@ -108,6 +108,10 @@ void build_ged_aml(Aml *table, const char *name,HotplugHandler
*hotplug_dev,hw/acpi/generic_event_device.c void build_ged_aml(Aml *table, const char *name, · line 108
Quoted 1 line
hw/acpi/generic_event_device.c +0
-0aml_append(if_ctx, aml_call0(MEMORY_DEVICES_CONTAINER"."
hw/acpi/generic_event_device.c void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_dev,
Quoted 9 lines
hw/acpi/generic_event_device.c +4
-0MEMORY_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),
Review
Quoted 1 line
(quoted diff) +0
-0
b/include/hw/acpi/cpu_hotplug.hQuoted 6 lines
index
48b291e45e..ef631750b4100644include/hw/acpi/cpu_hotplug.h +0
-0@@ -20,6 +20,8 @@#include "hw/acpi/cpu.h"
Quoted 6 lines
include/hw/acpi/cpu_hotplug.h line 23
Quoted 2 lines
include/hw/acpi/cpu_hotplug.h +1
-0#define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SCAN_METHOD "CSCN"This seems to already be defined in
hw/acpi/cpu.cCan we drop it from there given that file now includes this header anyway.
Perhaps I can assign this to the macro in the hw/acpi/cpu.c?
Thanks
Salil.
Re: [PATCH V2 06/10] hw/acpi: Update GED _EVT method AML with cpu scan
Quoted 10 lines
Quoted 10 lines
aml_notify(aml_name(ACPI_POWER_BUTTON_DEVICE),
Review
Quoted 1 line
(quoted diff) +0
-0
b/include/hw/acpi/cpu_hotplug.hQuoted 6 lines
index
48b291e45e..ef631750b4100644include/hw/acpi/cpu_hotplug.h +0
-0@@ -20,6 +20,8 @@#include "hw/acpi/cpu.h"
Quoted 8 lines
Quoted 6 lines
include/hw/acpi/cpu_hotplug.h line 23
Quoted 2 lines
include/hw/acpi/cpu_hotplug.h +1
-0#define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SCAN_METHOD "CSCN"This seems to already be defined in
hw/acpi/cpu.cCan we drop it from there given that file now includes this header anyway.Perhaps I can assign this to the macro in the
hw/acpi/cpu.c?
hw/acpi/cpu.c includes this header now anyway I think. So just drop that definition and should all be good.
Jonathan
Quoted 3 lines
Thanks
Salil.
RE: [PATCH V2 06/10] hw/acpi: Update GED _EVT method AML with cpu scan
Quoted 36 lines
From: Jonathan Cameron <[email protected]>
Sent: Tuesday, October 3, 2023 12:54 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 06/10] hw/acpi: Update GED_EVTmethod AML with cpu scanQuoted 16 lines
Quoted 15 lines
aml_notify(aml_name(ACPI_POWER_BUTTON_DEVICE),
Review
Quoted 1 line
(quoted diff) +0
-0
b/include/hw/acpi/cpu_hotplug.hinclude/hw/acpi/cpu_hotplug.h line 23
Quoted 8 lines
index
48b291e45e..ef631750b4100644include/hw/acpi/cpu_hotplug.h +1
-0@@ -20,6 +20,8 @@#include "hw/acpi/cpu.h" #define ACPI_CPU_HOTPLUG_REG_LEN 12 +#define ACPI_CPU_SCAN_METHOD "CSCN"This seems to already be defined in
hw/acpi/cpu.cCan we drop it from there given that file now includes this header anyway.
Quoted 3 lines
Quoted 1 line
Perhaps I can assign this to the macro in the
hw/acpi/cpu.c?
hw/acpi/cpu.cincludes this header now anyway I think. So just drop that definition and should all be good.
Ok.
Re: [PATCH V2 06/10] hw/acpi: Update GED _EVT method AML with cpu scan
In reply to Salil MehtaQuoted 7 lines · Salil Mehta
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.The change in this patch updates the GED AML
_EVTmethod with the call to \\_SB.CPUS.CSCN which will do above.
Quoted 8 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/generic_event_device.c | 4 ++++ include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 6 insertions(+)
RE: [PATCH V2 06/10] hw/acpi: Update GED _EVT method AML with cpu scan
Quoted 39 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 1:11 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 06/10] hw/acpi: Update GED_EVTmethod AML with cpu scanQuoted 1 line · Salil Mehta
OSPM evaluates
_EVTmethod to map the event. The cpu hotplug eventeventually
Quoted 1 line
results in start of the cpu scan. Scan figures out the cpu and the kind
of
Quoted 5 lines
event(plug/unplug) and notifies it back to the guest.
The change in this patch updates the GED AML
_EVTmethod with the call to \\_SB.CPUS.CSCN which will do above.Quoted 8 lines
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/generic_event_device.c | 4 ++++ include/hw/acpi/cpu_hotplug.h | 2 ++ 2 files changed, 6 insertions(+)
Quoted 1 line
Reviewed-by Gavin Shan <[email protected]>
Thanks
Salil.
PATCH v2 7/10 hw/acpi: Update ACPI GED framework to support vCPU Hotplug
In reply to Salil MehtaACPI GED shall be used to convey to the guest kernel about any CPU hot-(un)plug events. Therefore, existing ACPI GED framework inside QEMU needs to be enhanced to support CPU hotplug state and events.
--- hw/acpi/generic_event_device.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/acpi/generic_event_device.c +10 -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"
@@ -239,6 +240,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)));
@@ -253,6 +256,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)));
@@ -266,6 +271,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)));
@@ -277,6 +284,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)
@@ -291,6 +299,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);
Signature · 1 line
2.34.1
Re: [PATCH V2 07/10] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
Quoted 7 lines · On Sat, 30 Sep 2023 01:19:30 +0100 Salil Mehta <[email protected]> wrote:
ACPI GED shall be used to convey to the guest kernel about any CPU hot-(un)plug events. Therefore, existing ACPI GED framework inside QEMU needs to be enhanced to support CPU hotplug state and events.
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>
Quoted 60 lines
--- hw/acpi/generic_event_device.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/acpi/generic_event_device.c +10
-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" @@ -239,6 +240,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)));@@ -253,6 +256,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)));@@ -266,6 +271,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)));@@ -277,6 +284,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)@@ -291,6 +299,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);
RE: [PATCH V2 07/10] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
Quoted 22 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 5:16 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 07/10] hw/acpi: Update ACPI GED framework to support vCPU HotplugOn Sat, 30 Sep 2023 01:19:30 +0100
Salil Mehta <[email protected]> wrote:
Quoted 8 lines
Quoted 7 lines
ACPI GED shall be used to convey to the guest kernel about any CPU hot-(un)plug events. Therefore, existing ACPI GED framework inside QEMU needs to be enhanced to support CPU hotplug state and events.
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]>
Thanks
Salil.
Re: [PATCH V2 07/10] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
In reply to Salil MehtaQuoted 11 lines · Salil Mehta
ACPI GED shall be used to convey to the guest kernel about any CPU hot-(un)plug events. Therefore, existing ACPI GED framework inside QEMU needs to be enhanced to support CPU hotplug state and events.
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/generic_event_device.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
RE: [PATCH V2 07/10] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
Quoted 35 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 1:12 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 07/10] hw/acpi: Update ACPI GED framework to support vCPU HotplugQuoted 1 line · Salil Mehta
ACPI GED shall be used to convey to the guest kernel about any CPU hot-
(un)plug
Quoted 1 line
events. Therefore, existing ACPI GED framework inside QEMU needs to be
enhanced
Quoted 9 lines
to support CPU hotplug state and events.
Co-developed-by Keqian Zhu <[email protected]>Signed-off-by Keqian Zhu <[email protected]>Signed-off-by Salil Mehta <[email protected]>--- hw/acpi/generic_event_device.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
Quoted 1 line
Reviewed-by Gavin Shan <[email protected]>
Thanks
Salil.
PATCH v2 8/10 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 + softmmu/physmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+)
include/exec/cpu-common.h +8 -0
@@ -120,6 +120,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
@@ -355,6 +355,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list;CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;
softmmu/physmem.c +25 -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,30 @@ void cpu_address_space_init(CPUState *cpu, int asidx, } } +void cpu_address_space_destroy (CPUState *cpu,int asidx) +{ +CPUAddressSpace *cpuas; + +assert (asidx < cpu->num_ases); +assert (asidx ==0 || !kvm_enabled ()); +assert (cpu->cpu_ases); + + 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 (cpu->cpu_ases_count ==1 ) { +g_free (cpu->cpu_ases); + cpu->cpu_ases =NULL ; + } + + cpu->cpu_ases_count--; +} +AddressSpace *cpu_get_address_space (CPUState *cpu,int asidx) {/* Return the AddressSpace corresponding to the specified index */
Signature · 1 line
2.34.1
Re: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpace
Quoted 5 lines · On Sat, 30 Sep 2023 01:19:31 +0100 Salil Mehta <[email protected]> wrote:
Virtual 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.
Signed-off-by Salil Mehta <[email protected]>
I'm not that familiar with this bit of the code, so no tag, but as far as I can tell from a fairly superficial look, this is good.
Quoted 80 lines
--- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + softmmu/physmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+)include/exec/cpu-common.h +8
-0@@ -120,6 +120,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@@ -355,6 +355,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list;CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;softmmu/physmem.c +25
-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,30 @@ void cpu_address_space_init(CPUState *cpu, int asidx, } } +void cpu_address_space_destroy (CPUState *cpu,int asidx) +{ +CPUAddressSpace *cpuas; + +assert (asidx < cpu->num_ases); +assert (asidx ==0 || !kvm_enabled ()); +assert (cpu->cpu_ases); + + 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 (cpu->cpu_ases_count ==1 ) { +g_free (cpu->cpu_ases); + cpu->cpu_ases =NULL ; + } + + cpu->cpu_ases_count--; +} +AddressSpace *cpu_get_address_space (CPUState *cpu,int asidx) {/* Return the AddressSpace corresponding to the specified index */
RE: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpace
Hi Jonathan,
Quoted 22 lines
From: Jonathan Cameron <[email protected]>
Sent: Monday, October 2, 2023 5:20 PM
To: Salil Mehta <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; jean- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpaceOn Sat, 30 Sep 2023 01:19:31 +0100
Salil Mehta <[email protected]> wrote:
Quoted 8 lines
Quoted 5 lines
Virtual 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.
Signed-off-by Salil Mehta <[email protected]>I'm not that familiar with this bit of the code, so no tag, but as far as I can tell from a fairly superficial look, this is good.
Ok no problem. Thanks.
Salil.
Quoted 80 lines
softmmu/physmem.c void cpu_address_space_init(CPUState *cpu, int
Quoted 49 lines
include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + softmmu/physmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+)include/exec/cpu-common.h +8
-0@@ -120,6 +120,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@@ -355,6 +355,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list;CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;softmmu/physmem.c +1
-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,30 @@ void cpu_address_space_init(CPUState *cpu, intasidx,
Quoted 30 lines
softmmu/physmem.c +24
-0} } +void cpu_address_space_destroy (CPUState *cpu,int asidx) +{ +CPUAddressSpace *cpuas; + +assert (asidx < cpu->num_ases); +assert (asidx ==0 || !kvm_enabled ()); +assert (cpu->cpu_ases); + + 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 (cpu->cpu_ases_count ==1 ) { +g_free (cpu->cpu_ases); + cpu->cpu_ases =NULL ; + } + + cpu->cpu_ases_count--; +} +AddressSpace *cpu_get_address_space (CPUState *cpu,int asidx) {/* Return the AddressSpace corresponding to the specified index */
Re: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpace
In reply to Salil MehtaQuoted 35 lines · Salil Mehta
Virtual 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.
Signed-off-by Salil Mehta <[email protected]>--- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + softmmu/physmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+)include/exec/cpu-common.h +8
-0@@ -120,6 +120,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 +0
-0
include/hw/core/cpu.h struct CPUState { · line 361
Quoted 7 lines
include/hw/core/cpu.h +1
-0@@ -355,6 +355,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list;CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;
@num_ases and @cpu_ases_count are duplicate to each other to some extent. The real problem is @cpu_ases is allocated at once and we need to make the allocation sparse. In that way, each CPU address space is independent and can be destroyed independently. The sparse allocation for the CPU address space can be done in cpu_address_space_init() like below:
#define CPU_ADDRESS_SPACE_MAX 8
struct CPUState {
CPUAddressSpace *cpu_ases[CPU_ADDRESS_SPACE_MAX];
}void cpu_address_space_init(CPUState *cpu, int asidx, const char *prefix, MemoryRegion *mr)
{
assert(asidx < CPU_ADDRESS_SPACE_MAX);
/* The address space has been initialized ? */
if (cpu->cpu_ases[asidx]) {
return;
}
cpu->cpu_ases[asidx] = g_new0(CPUAddressSpace, 1);}
void cpu_address_destroy(CPUState *cpu, int asidx)
{
assert(asidx < CPU_ADDRESS_SPACE_MAX);
/* The address space isn't initialized? */
if (!cpu->cpu_ases[asidx]) {
return;
}
:
g_free(cpu->cpu_ases[asidx]);
cpu->cpu_ases[asidx] = NULL;}
Quoted 33 lines
softmmu/physmem.c +18
-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,30 @@ void cpu_address_space_init(CPUState *cpu, int asidx, } } +void cpu_address_space_destroy (CPUState *cpu,int asidx) +{ +CPUAddressSpace *cpuas; + +assert (asidx < cpu->num_ases); +assert (asidx ==0 || !kvm_enabled ()); +assert (cpu->cpu_ases); + + 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 (cpu->cpu_ases_count ==1 ) {
softmmu/physmem.c void cpu_address_space_init(CPUState *cpu, int asidx, · line 804
Quoted 10 lines
softmmu/physmem.c +7
-0+g_free (cpu->cpu_ases); + cpu->cpu_ases =NULL ; + } + + cpu->cpu_ases_count--; +} +AddressSpace *cpu_get_address_space (CPUState *cpu,int asidx) {/* Return the AddressSpace corresponding to the specified index */
Thanks,
Gavin
RE: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpace
Hi Gavin,
Quoted 58 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 2:37 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpaceQuoted 37 lines · Salil Mehta
Virtual 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.
Signed-off-by Salil Mehta <[email protected]>--- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + softmmu/physmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+)include/exec/cpu-common.h +8
-0@@ -120,6 +120,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 +0
-0@@ -355,6 +355,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list;
Quoted 11 lines
include/hw/core/cpu.h struct CPUState { · line 361
Quoted 5 lines
include/hw/core/cpu.h +1
-0CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;@num_ases and @cpu_ases_count are duplicate to each other to some extent. The real problem is @cpu_ases is allocated at once and we need to make the allocation sparse. In that way, each CPU address space is independent and can be destroyed independently. The sparse allocation for the CPU address space can be done in
cpu_address_space_init()like below:
Well, I think Phil/Richard are pointing to something else here i.e. destroy at once.
https://lore.kernel.org/qemu-devel/[email protected]/
I used reference counter because I was not sure if it is safe to assume that AddressSpace will always be destroyed at once.
BTW, there is no functional problem with above patch. Just that we do not have to maintain the reference counter.
You can use below command to check CPU memory address spaces are getting destroyed properly and get re-created again with CPU hot(un)plug:
Qemu> info mtree
Thanks
Salil.
RE: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpace
In reply to Gavin ShanHi Gavin,
Revisited your comments again.
Quoted 58 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 2:37 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 08/10] physmem: Add helper function to destroy CPU AddressSpaceQuoted 37 lines · Salil Mehta
Virtual 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.
Signed-off-by Salil Mehta <[email protected]>--- include/exec/cpu-common.h | 8 ++++++++ include/hw/core/cpu.h | 1 + softmmu/physmem.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+)include/exec/cpu-common.h +8
-0@@ -120,6 +120,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 +0
-0@@ -355,6 +355,7 @@ struct CPUState { QSIMPLEQ_HEAD(, qemu_work_item) work_list;
Quoted 13 lines
include/hw/core/cpu.h struct CPUState { · line 361
Quoted 5 lines
include/hw/core/cpu.h +1
-0CPUAddressSpace *cpu_ases; +int cpu_ases_count;int num_ases;AddressSpace *as;MemoryRegion *memory;@num_ases and @cpu_ases_count are duplicate to each other to some extent. The
real problem is @cpu_ases is allocated at once and we need to make the allocation
sparse. In that way, each CPU address space is independent and can be destroyed
independently.
(revisiting this comment i.e. 'sparse')
If you meant, the order of initialization and destruction might not be same then yes, AddressSpace can be *conditionally* allocated during CPU realization phase and should be *conditionally* destroyed as well during CPU un-realization phase. Later means, it is not safe to assume that indexes to the array of AddressSpace might be consecutive. Hence, their destruction at once can create problems.
https://lore.kernel.org/qemu-devel/[email protected]/T/#m44b81fbbba33a346dd2292256012f86ef7c8e761
The sparse allocation for the CPU address space can be done
Quoted 8 lines
in
cpu_address_space_init()like below:#define
CPU_ADDRESS_SPACE_MAX8struct CPUState { CPUAddressSpace *cpu_ases[CPU_ADDRESS_SPACE_MAX]; }
Yes, this will also work but we will end up refactoring existing initialization interface. Do we require all of this when counter based approach also works without changing anything?
Thanks
Salil.
PATCH v2 9/10 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 | 14 ++++++++++++++ include/exec/gdbstub.h | 5 +++++ 2 files changed, 19 insertions(+)
gdbstub/gdbstub.c +14 -0
@@ -491,6 +491,20 @@ void gdb_register_coprocessor(CPUState *cpu, } } +void gdb_unregister_coprocessor_all (CPUState *cpu) +{ +GDBRegisterState *s, *p; + + p = cpu->gdb_regs; +while (p) { + s = p; + p = p->next; +/* s->xml is static const char so isn't freed */ +g_free (s); + } + cpu->gdb_regs =NULL ; +} +static void gdb_process_breakpoint_remove_all (GDBProcess *p) {CPUState *cpu =gdb_get_first_cpu_in_process (p);
include/exec/gdbstub.h +5 -0
@@ -27,6 +27,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
Re: [PATCH V2 09/10] gdbstub: Add helper function to unregister GDB register space
Quoted 9 lines · Salil Mehta
Add common function to help unregister the GDB Register Space. This shall be done in context to the CPU unrealization.
Signed-off-by Salil Mehta <[email protected]>--- gdbstub/gdbstub.c | 14 ++++++++++++++ include/exec/gdbstub.h | 5 +++++ 2 files changed, 19 insertions(+)
With the following nits addressed:
Quoted 7 lines
gdbstub/gdbstub.c +0
-0@@ -491,6 +491,20 @@ void gdb_register_coprocessor(CPUState *cpu, } }
gdbstub/gdbstub.c void gdb_register_coprocessor(CPUState *cpu, · line 502
Quoted 10 lines
gdbstub/gdbstub.c +9
-0+void gdb_unregister_coprocessor_all (CPUState *cpu) +{ +GDBRegisterState *s, *p; + + p = cpu->gdb_regs; +while (p) { + s = p; + p = p->next; +/* s->xml is static const char so isn't freed */
^^^
string so that it needn't be freed
gdbstub/gdbstub.c void gdb_register_coprocessor(CPUState *cpu, · line 507
Quoted 5 lines
gdbstub/gdbstub.c +5
-0+g_free (s); + } + cpu->gdb_regs =NULL ; +} +
For consistency, CPUState::gdb_num_regs and CPUState::gdb_num_g_regs need to be updated accordingly, even the CPU instance will be destroyed shortly.
Quoted 9 lines
gdbstub/gdbstub.c +0
-0static void gdb_process_breakpoint_remove_all (GDBProcess *p) {CPUState *cpu =gdb_get_first_cpu_in_process (p);include/exec/gdbstub.h +0
-0@@ -27,6 +27,11 @@ typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg); void gdb_register_coprocessor(CPUState *cpu,
include/exec/gdbstub.h typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg); · line 37
Quoted 10 lines
include/exec/gdbstub.h +5
-0gdb_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
Thanks,
Gavin
RE: [PATCH V2 09/10] gdbstub: Add helper function to unregister GDB register space
Quoted 56 lines
From: Gavin Shan <[email protected]>
Sent: Tuesday, October 3, 2023 4:17 AM
To: Salil Mehta <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; Jonathan Cameron <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; zhukeqian <[email protected]>; wangxiongfeng (C) <[email protected]>; wangyanan (Y) <[email protected]>; [email protected]; [email protected]; [email protected]; Linuxarm <[email protected]>
Subject: Re: [PATCH V2 09/10] gdbstub: Add helper function to unregister GDB register spaceQuoted 1 line · Salil Mehta
Add common function to help unregister the GDB Register Space. This shall
be
Quoted 8 lines
done in context to the CPU unrealization.
Signed-off-by Salil Mehta <[email protected]>--- gdbstub/gdbstub.c | 14 ++++++++++++++ include/exec/gdbstub.h | 5 +++++ 2 files changed, 19 insertions(+)With the following nits addressed:
Reviewed-by Gavin Shan <[email protected]>Quoted 7 lines
gdbstub/gdbstub.c +0
-0@@ -491,6 +491,20 @@ void gdb_register_coprocessor(CPUState *cpu, } }gdbstub/gdbstub.c void gdb_register_coprocessor(CPUState *cpu, · line 502
Quoted 10 lines
gdbstub/gdbstub.c +9
-0+void gdb_unregister_coprocessor_all (CPUState *cpu) +{ +GDBRegisterState *s, *p; + + p = cpu->gdb_regs; +while (p) { + s = p; + p = p->next; +/* s->xml is static const char so isn't freed */ ^^^
string so that it needn't be freed
Quoted 9 lines
gdbstub/gdbstub.c void gdb_register_coprocessor(CPUState *cpu, · line 507
Quoted 5 lines
gdbstub/gdbstub.c +5
-0+g_free (s); + } + cpu->gdb_regs =NULL ; +} +For consistency,
CPUState::gdb_num_regsandCPUState::gdb_num_g_regsneed to be updated accordingly, even the CPU instance will be destroyed shortly.
Good point.
Thanks
Salil.
PATCH v2 10/10 target/arm/kvm: Write CPU state back to KVM on reset
In reply to Salil MehtaFrom: Jean-Philippe Brucker <[email protected]>
When a KVM vCPU is reset following a PSCI CPU_ON call, its power state is not synchronized with KVM at the moment. Because the vCPU is not marked dirty, we miss the call to kvm_arch_put_registers() that writes to KVM's MP_STATE. Force mp_state synchronization.
--- target/arm/kvm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
target/arm/kvm.c +7 -1
@@ -642,11 +642,12 @@ void kvm_arm_cpu_post_load(ARMCPU *cpu)void kvm_arm_reset_vcpu (ARMCPU *cpu) {int ret; +CPUState *cs =CPU (cpu);/* Re-init VCPU so that all registers are set to * their respective reset values. */ - ret =kvm_arm_vcpu_init (CPU (cpu)); + ret =kvm_arm_vcpu_init (cs);if (ret <0 ) {fprintf (stderr,"kvm_arm_vcpu_init failed: %s\n" ,strerror (-ret));abort ();
@@ -663,6 +664,11 @@ void kvm_arm_reset_vcpu(ARMCPU *cpu)* for the same reason we do so in kvm_arch_get_registers(). */ write_list_to_cpustate (cpu); +/* +* Ensure we call kvm_arch_put_registers(). The vCPU isn't marked dirty if +* it was parked in KVM and is now booting from a PSCI CPU_ON call. +*/ + cs->vcpu_dirty = true; }/*
Signature · 1 line
2.34.1
Re: [PATCH V2 10/10] target/arm/kvm: Write CPU state back to KVM on reset
Quoted 7 lines · Salil Mehta
From: Jean-Philippe Brucker <[email protected]>
When a KVM vCPU is reset following a PSCI
CPU_ONcall, its power state is not synchronized with KVM at the moment. Because the vCPU is not marked dirty, we miss the call tokvm_arch_put_registers()that writes to KVM'sMP_STATE. Forcemp_statesynchronization.
Quoted 7 lines
Signed-off-by Jean-Philippe Brucker <[email protected]>Signed-off-by Salil Mehta <[email protected]>Reviewed-by Alex Bennée <[email protected]>--- target/arm/kvm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)