QEMU-Devel Archive mirror
 help / color / mirror / Atom feed
* [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
@ 2023-10-13 10:51 Salil Mehta via
  2023-10-13 10:51 ` Salil Mehta
                   ` (12 more replies)
  0 siblings, 13 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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]
4. Helper functions to support unrealization of CPU objects [Patch 8,9]
5. Misc [Patch 2,3]


Repository:

[*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v6


Revision History:

Patch-set  V5 -> V6
1. Addressed Gavin Shan's comments
   - Fixed the assert() ranges of address spaces
   - Rebased the patch-set to latest changes in the qemu.git
   - Added Reviewed-by tags for patches {8,9}
2. Addressed Jonathan Cameron's comments
   - Updated commit-log for [Patch V5 1/9] with mention of trace events
   - Added Reviewed-by tags for patches {1,5}
3. Added Tested-by tags from Xianglai Li
4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9] 
Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-salil.mehta@huawei.com/

Patch-set  V4 -> V5
1. Addressed Gavin Shan's comments
   - Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
   - Added Reviewed-by tag for patch {1}
2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
4. Dropped the ARM specific [Patch V4 10/10]
Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-salil.mehta@huawei.com/

Patch-set  V3 -> V4
1. Addressed David Hilderbrand's comments
   - Fixed the wrong doc comment of kvm_park_vcpu API prototype
   - Added Reviewed-by tags for patches {2,4}
Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-salil.mehta@huawei.com/

Patch-set  V2 -> V3
1. Addressed Jonathan Cameron's comments
   - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
   - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
   - Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
   - Updated [Patch V2 5/10] commit-log with details of conditional event handler method
   - Added Reviewed-by tags for patches {2,3,4,6,7}
2. Addressed Gavin Shan's comments
   - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
   - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
   - Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
   - Fixed the kvm_{create,park}_vcpu prototypes docs
   - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
3. Addressed one earlier missed comment by Alex Bennée in RFC V1
   - Added traces instead of DPRINTF in the newly added and some existing functions
Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-salil.mehta@huawei.com/

Patch-set V1 -> V2
1. Addressed Alex Bennée's comments
   - Refactored the kvm_create_vcpu logic to get rid of goto
   - Added the docs for kvm_{create,park}_vcpu prototypes
   - Splitted the gdbstub and AddressSpace destruction change into separate patches
   - Added Reviewed-by tags for patches {2,10}
Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-salil.mehta@huawei.com/

References:

[1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-salil.mehta@huawei.com/
[2] https://lore.kernel.org/all/20230913163823.7880-1-james.morse@arm.com/
[3] https://lore.kernel.org/qemu-devel/cover.1695697701.git.lixianglai@loongson.cn/


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                    | 64 ++++++++++++++++++++------
 accel/kvm/trace-events                 |  4 ++
 gdbstub/gdbstub.c                      | 12 +++++
 hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
 hw/acpi/cpu.c                          | 27 +++++++----
 hw/acpi/generic_event_device.c         | 22 +++++++++
 hw/i386/acpi-build.c                   |  3 +-
 include/exec/cpu-common.h              |  8 ++++
 include/exec/gdbstub.h                 |  5 ++
 include/hw/acpi/cpu.h                  |  5 +-
 include/hw/acpi/cpu_hotplug.h          |  4 ++
 include/hw/acpi/generic_event_device.h |  5 ++
 include/hw/core/cpu.h                  |  1 +
 include/sysemu/kvm.h                   | 16 +++++++
 system/physmem.c                       | 29 ++++++++++++
 15 files changed, 184 insertions(+), 27 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 47+ messages in thread

* [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta
  2023-10-13 10:51 ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation, parking} code Salil Mehta via
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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]
4. Helper functions to support unrealization of CPU objects [Patch 8,9]
5. Misc [Patch 2,3]


Repository:

[*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v6


Revision History:

Patch-set  V5 -> V6
1. Addressed Gavin Shan's comments
   - Fixed the assert() ranges of address spaces
   - Rebased the patch-set to latest changes in the qemu.git
   - Added Reviewed-by tags for patches {8,9}
2. Addressed Jonathan Cameron's comments
   - Updated commit-log for [Patch V5 1/9] with mention of trace events
   - Added Reviewed-by tags for patches {1,5}
3. Added Tested-by tags from Xianglai Li
4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9] 
Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-salil.mehta@huawei.com/

Patch-set  V4 -> V5
1. Addressed Gavin Shan's comments
   - Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
   - Added Reviewed-by tag for patch {1}
2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
4. Dropped the ARM specific [Patch V4 10/10]
Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-salil.mehta@huawei.com/

Patch-set  V3 -> V4
1. Addressed David Hilderbrand's comments
   - Fixed the wrong doc comment of kvm_park_vcpu API prototype
   - Added Reviewed-by tags for patches {2,4}
Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-salil.mehta@huawei.com/

Patch-set  V2 -> V3
1. Addressed Jonathan Cameron's comments
   - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
   - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
   - Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
   - Updated [Patch V2 5/10] commit-log with details of conditional event handler method
   - Added Reviewed-by tags for patches {2,3,4,6,7}
2. Addressed Gavin Shan's comments
   - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
   - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
   - Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
   - Fixed the kvm_{create,park}_vcpu prototypes docs
   - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
3. Addressed one earlier missed comment by Alex Bennée in RFC V1
   - Added traces instead of DPRINTF in the newly added and some existing functions
Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-salil.mehta@huawei.com/

Patch-set V1 -> V2
1. Addressed Alex Bennée's comments
   - Refactored the kvm_create_vcpu logic to get rid of goto
   - Added the docs for kvm_{create,park}_vcpu prototypes
   - Splitted the gdbstub and AddressSpace destruction change into separate patches
   - Added Reviewed-by tags for patches {2,10}
Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-salil.mehta@huawei.com/

References:

[1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-salil.mehta@huawei.com/
[2] https://lore.kernel.org/all/20230913163823.7880-1-james.morse@arm.com/
[3] https://lore.kernel.org/qemu-devel/cover.1695697701.git.lixianglai@loongson.cn/


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                    | 64 ++++++++++++++++++++------
 accel/kvm/trace-events                 |  4 ++
 gdbstub/gdbstub.c                      | 12 +++++
 hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
 hw/acpi/cpu.c                          | 27 +++++++----
 hw/acpi/generic_event_device.c         | 22 +++++++++
 hw/i386/acpi-build.c                   |  3 +-
 include/exec/cpu-common.h              |  8 ++++
 include/exec/gdbstub.h                 |  5 ++
 include/hw/acpi/cpu.h                  |  5 +-
 include/hw/acpi/cpu_hotplug.h          |  4 ++
 include/hw/acpi/generic_event_device.h |  5 ++
 include/hw/core/cpu.h                  |  1 +
 include/sysemu/kvm.h                   | 16 +++++++
 system/physmem.c                       | 29 ++++++++++++
 15 files changed, 184 insertions(+), 27 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 47+ messages in thread

* [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation, parking} code
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
  2023-10-13 10:51 ` Salil Mehta
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-27 12:56   ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation,parking} code Igor Mammedov
  2023-10-13 10:51 ` [PATCH V6 2/9] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file Salil Mehta via
                   ` (10 subsequent siblings)
  12 siblings, 2 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

KVM vCPU creation is done once during the initialization of the VM when Qemu
thread is spawned. This is common to all the architectures.

Hot-unplug of vCPU results in destruction of the vCPU object in QOM but the
corresponding KVM vCPU object in the Host KVM is not destroyed and its
representative KVM vCPU object/context in Qemu is parked.

Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Update new/old APIs with trace events instead of DTRACE.

Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 accel/kvm/kvm-all.c    | 64 ++++++++++++++++++++++++++++++++----------
 accel/kvm/trace-events |  4 +++
 include/sysemu/kvm.h   | 16 +++++++++++
 3 files changed, 69 insertions(+), 15 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 72e1d1141c..bfa7816aaa 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -137,6 +137,7 @@ static QemuMutex kml_slots_lock;
 #define kvm_slots_unlock()  qemu_mutex_unlock(&kml_slots_lock)
 
 static void kvm_slot_init_dirty_bitmap(KVMSlot *mem);
+static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id);
 
 static inline void kvm_resample_fd_remove(int gsi)
 {
@@ -320,14 +321,53 @@ err:
     return ret;
 }
 
+void kvm_park_vcpu(CPUState *cpu)
+{
+    struct KVMParkedVcpu *vcpu;
+
+    trace_kvm_park_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
+
+    vcpu = g_malloc0(sizeof(*vcpu));
+    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
+    vcpu->kvm_fd = cpu->kvm_fd;
+    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
+}
+
+int kvm_create_vcpu(CPUState *cpu)
+{
+    unsigned long vcpu_id = kvm_arch_vcpu_id(cpu);
+    KVMState *s = kvm_state;
+    int kvm_fd;
+
+    trace_kvm_create_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
+
+    /* check if the KVM vCPU already exist but is parked */
+    kvm_fd = kvm_get_vcpu(s, vcpu_id);
+    if (kvm_fd < 0) {
+        /* vCPU not parked: create a new KVM vCPU */
+        kvm_fd = kvm_vm_ioctl(s, KVM_CREATE_VCPU, vcpu_id);
+        if (kvm_fd < 0) {
+            error_report("KVM_CREATE_VCPU IOCTL failed for vCPU %lu", vcpu_id);
+            return kvm_fd;
+        }
+    }
+
+    cpu->kvm_fd = kvm_fd;
+    cpu->kvm_state = s;
+    cpu->vcpu_dirty = true;
+    cpu->dirty_pages = 0;
+    cpu->throttle_us_per_full = 0;
+
+    return 0;
+}
+
 static int do_kvm_destroy_vcpu(CPUState *cpu)
 {
     KVMState *s = kvm_state;
     long mmap_size;
-    struct KVMParkedVcpu *vcpu = NULL;
     int ret = 0;
 
-    DPRINTF("kvm_destroy_vcpu\n");
+    trace_kvm_destroy_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
 
     ret = kvm_arch_destroy_vcpu(cpu);
     if (ret < 0) {
@@ -353,10 +393,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
         }
     }
 
-    vcpu = g_malloc0(sizeof(*vcpu));
-    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
-    vcpu->kvm_fd = cpu->kvm_fd;
-    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
+    kvm_park_vcpu(cpu);
 err:
     return ret;
 }
@@ -377,6 +414,8 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
         if (cpu->vcpu_id == vcpu_id) {
             int kvm_fd;
 
+            trace_kvm_get_vcpu(vcpu_id);
+
             QLIST_REMOVE(cpu, node);
             kvm_fd = cpu->kvm_fd;
             g_free(cpu);
@@ -384,7 +423,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
         }
     }
 
-    return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id);
+    return -ENOENT;
 }
 
 int kvm_init_vcpu(CPUState *cpu, Error **errp)
@@ -395,19 +434,14 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
 
     trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
 
-    ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
+    ret = kvm_create_vcpu(cpu);
     if (ret < 0) {
-        error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed (%lu)",
+        error_setg_errno(errp, -ret,
+                         "kvm_init_vcpu: kvm_create_vcpu failed (%lu)",
                          kvm_arch_vcpu_id(cpu));
         goto err;
     }
 
-    cpu->kvm_fd = ret;
-    cpu->kvm_state = s;
-    cpu->vcpu_dirty = true;
-    cpu->dirty_pages = 0;
-    cpu->throttle_us_per_full = 0;
-
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
         ret = mmap_size;
diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
index 399aaeb0ec..cdd0c95c09 100644
--- a/accel/kvm/trace-events
+++ b/accel/kvm/trace-events
@@ -9,6 +9,10 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p"
 kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
 kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
 kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
+kvm_create_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
+kvm_get_vcpu(unsigned long arch_cpu_id) "id: %lu"
+kvm_destroy_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
+kvm_park_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
 kvm_irqchip_commit_routes(void) ""
 kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d"
 kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index ee9025f8e9..8137e6a44c 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -465,6 +465,22 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
 int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
                                        hwaddr *phys_addr);
 
+/**
+ * kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU
+ * @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created.
+ *
+ * @returns: 0 when success, errno (<0) when failed.
+ */
+int kvm_create_vcpu(CPUState *cpu);
+
+/**
+ * kvm_park_vcpu - Park QEMU KVM vCPU context
+ * @cpu: QOM CPUState object for which QEMU KVM vCPU context has to be parked.
+ *
+ * @returns: none
+ */
+void kvm_park_vcpu(CPUState *cpu);
+
 #endif /* NEED_CPU_H */
 
 void kvm_cpu_synchronize_state(CPUState *cpu);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation, parking} code
  2023-10-13 10:51 ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation, parking} code Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  2023-10-27 12:56   ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation,parking} code Igor Mammedov
  1 sibling, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

KVM vCPU creation is done once during the initialization of the VM when Qemu
thread is spawned. This is common to all the architectures.

Hot-unplug of vCPU results in destruction of the vCPU object in QOM but the
corresponding KVM vCPU object in the Host KVM is not destroyed and its
representative KVM vCPU object/context in Qemu is parked.

Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
Update new/old APIs with trace events instead of DTRACE.

Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 accel/kvm/kvm-all.c    | 64 ++++++++++++++++++++++++++++++++----------
 accel/kvm/trace-events |  4 +++
 include/sysemu/kvm.h   | 16 +++++++++++
 3 files changed, 69 insertions(+), 15 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 72e1d1141c..bfa7816aaa 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -137,6 +137,7 @@ static QemuMutex kml_slots_lock;
 #define kvm_slots_unlock()  qemu_mutex_unlock(&kml_slots_lock)
 
 static void kvm_slot_init_dirty_bitmap(KVMSlot *mem);
+static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id);
 
 static inline void kvm_resample_fd_remove(int gsi)
 {
@@ -320,14 +321,53 @@ err:
     return ret;
 }
 
+void kvm_park_vcpu(CPUState *cpu)
+{
+    struct KVMParkedVcpu *vcpu;
+
+    trace_kvm_park_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
+
+    vcpu = g_malloc0(sizeof(*vcpu));
+    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
+    vcpu->kvm_fd = cpu->kvm_fd;
+    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
+}
+
+int kvm_create_vcpu(CPUState *cpu)
+{
+    unsigned long vcpu_id = kvm_arch_vcpu_id(cpu);
+    KVMState *s = kvm_state;
+    int kvm_fd;
+
+    trace_kvm_create_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
+
+    /* check if the KVM vCPU already exist but is parked */
+    kvm_fd = kvm_get_vcpu(s, vcpu_id);
+    if (kvm_fd < 0) {
+        /* vCPU not parked: create a new KVM vCPU */
+        kvm_fd = kvm_vm_ioctl(s, KVM_CREATE_VCPU, vcpu_id);
+        if (kvm_fd < 0) {
+            error_report("KVM_CREATE_VCPU IOCTL failed for vCPU %lu", vcpu_id);
+            return kvm_fd;
+        }
+    }
+
+    cpu->kvm_fd = kvm_fd;
+    cpu->kvm_state = s;
+    cpu->vcpu_dirty = true;
+    cpu->dirty_pages = 0;
+    cpu->throttle_us_per_full = 0;
+
+    return 0;
+}
+
 static int do_kvm_destroy_vcpu(CPUState *cpu)
 {
     KVMState *s = kvm_state;
     long mmap_size;
-    struct KVMParkedVcpu *vcpu = NULL;
     int ret = 0;
 
-    DPRINTF("kvm_destroy_vcpu\n");
+    trace_kvm_destroy_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
 
     ret = kvm_arch_destroy_vcpu(cpu);
     if (ret < 0) {
@@ -353,10 +393,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
         }
     }
 
-    vcpu = g_malloc0(sizeof(*vcpu));
-    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
-    vcpu->kvm_fd = cpu->kvm_fd;
-    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
+    kvm_park_vcpu(cpu);
 err:
     return ret;
 }
@@ -377,6 +414,8 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
         if (cpu->vcpu_id == vcpu_id) {
             int kvm_fd;
 
+            trace_kvm_get_vcpu(vcpu_id);
+
             QLIST_REMOVE(cpu, node);
             kvm_fd = cpu->kvm_fd;
             g_free(cpu);
@@ -384,7 +423,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
         }
     }
 
-    return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id);
+    return -ENOENT;
 }
 
 int kvm_init_vcpu(CPUState *cpu, Error **errp)
@@ -395,19 +434,14 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
 
     trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
 
-    ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
+    ret = kvm_create_vcpu(cpu);
     if (ret < 0) {
-        error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed (%lu)",
+        error_setg_errno(errp, -ret,
+                         "kvm_init_vcpu: kvm_create_vcpu failed (%lu)",
                          kvm_arch_vcpu_id(cpu));
         goto err;
     }
 
-    cpu->kvm_fd = ret;
-    cpu->kvm_state = s;
-    cpu->vcpu_dirty = true;
-    cpu->dirty_pages = 0;
-    cpu->throttle_us_per_full = 0;
-
     mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
     if (mmap_size < 0) {
         ret = mmap_size;
diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
index 399aaeb0ec..cdd0c95c09 100644
--- a/accel/kvm/trace-events
+++ b/accel/kvm/trace-events
@@ -9,6 +9,10 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p"
 kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
 kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
 kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
+kvm_create_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
+kvm_get_vcpu(unsigned long arch_cpu_id) "id: %lu"
+kvm_destroy_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
+kvm_park_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
 kvm_irqchip_commit_routes(void) ""
 kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d"
 kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index ee9025f8e9..8137e6a44c 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -465,6 +465,22 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
 int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
                                        hwaddr *phys_addr);
 
+/**
+ * kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU
+ * @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created.
+ *
+ * @returns: 0 when success, errno (<0) when failed.
+ */
+int kvm_create_vcpu(CPUState *cpu);
+
+/**
+ * kvm_park_vcpu - Park QEMU KVM vCPU context
+ * @cpu: QOM CPUState object for which QEMU KVM vCPU context has to be parked.
+ *
+ * @returns: none
+ */
+void kvm_park_vcpu(CPUState *cpu);
+
 #endif /* NEED_CPU_H */
 
 void kvm_cpu_synchronize_state(CPUState *cpu);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 2/9] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
  2023-10-13 10:51 ` Salil Mehta
  2023-10-13 10:51 ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation, parking} code Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-13 10:51 ` [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub Salil Mehta via
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

CPU 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.

Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/cpu.c                 | 2 +-
 include/hw/acpi/cpu_hotplug.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 011d2c6c2d..4b24a25003 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -1,13 +1,13 @@
 #include "qemu/osdep.h"
 #include "migration/vmstate.h"
 #include "hw/acpi/cpu.h"
+#include "hw/acpi/cpu_hotplug.h"
 #include "hw/core/cpu.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-acpi.h"
 #include "trace.h"
 #include "sysemu/numa.h"
 
-#define ACPI_CPU_HOTPLUG_REG_LEN 12
 #define ACPI_CPU_SELECTOR_OFFSET_WR 0
 #define ACPI_CPU_FLAGS_OFFSET_RW 4
 #define ACPI_CPU_CMD_OFFSET_WR 5
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 3b932abbbb..48b291e45e 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 2/9] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
  2023-10-13 10:51 ` [PATCH V6 2/9] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

CPU 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.

Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/cpu.c                 | 2 +-
 include/hw/acpi/cpu_hotplug.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 011d2c6c2d..4b24a25003 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -1,13 +1,13 @@
 #include "qemu/osdep.h"
 #include "migration/vmstate.h"
 #include "hw/acpi/cpu.h"
+#include "hw/acpi/cpu_hotplug.h"
 #include "hw/core/cpu.h"
 #include "qapi/error.h"
 #include "qapi/qapi-events-acpi.h"
 #include "trace.h"
 #include "sysemu/numa.h"
 
-#define ACPI_CPU_HOTPLUG_REG_LEN 12
 #define ACPI_CPU_SELECTOR_OFFSET_WR 0
 #define ACPI_CPU_FLAGS_OFFSET_RW 4
 #define ACPI_CPU_CMD_OFFSET_WR 5
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 3b932abbbb..48b291e45e 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (2 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 2/9] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-27 13:05   ` Igor Mammedov
  2023-10-13 10:51 ` [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events Salil Mehta via
                   ` (8 subsequent siblings)
  12 siblings, 2 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

ACPI CPU hotplug related initialization should only happen if ACPI_CPU_HOTPLUG
support has been enabled for particular architecture. Add cpu_hotplug_hw_init()
stub to avoid compilation break.

Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/acpi/acpi-cpu-hotplug-stub.c b/hw/acpi/acpi-cpu-hotplug-stub.c
index 3fc4b14c26..c6c61bb9cd 100644
--- a/hw/acpi/acpi-cpu-hotplug-stub.c
+++ b/hw/acpi/acpi-cpu-hotplug-stub.c
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub
  2023-10-13 10:51 ` [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  2023-10-27 13:05   ` Igor Mammedov
  1 sibling, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

ACPI CPU hotplug related initialization should only happen if ACPI_CPU_HOTPLUG
support has been enabled for particular architecture. Add cpu_hotplug_hw_init()
stub to avoid compilation break.

Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/acpi/acpi-cpu-hotplug-stub.c b/hw/acpi/acpi-cpu-hotplug-stub.c
index 3fc4b14c26..c6c61bb9cd 100644
--- a/hw/acpi/acpi-cpu-hotplug-stub.c
+++ b/hw/acpi/acpi-cpu-hotplug-stub.c
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (3 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
                     ` (2 more replies)
  2023-10-13 10:51 ` [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change Salil Mehta via
                   ` (7 subsequent siblings)
  12 siblings, 3 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 _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.

Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/generic_event_device.c         | 8 ++++++++
 include/hw/acpi/generic_event_device.h | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
index a3d31631fe..d2fa1d0e4a 100644
--- a/hw/acpi/generic_event_device.c
+++ b/hw/acpi/generic_event_device.c
@@ -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)
diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h
index ba84ce0214..a803ea818e 100644
--- a/include/hw/acpi/generic_event_device.h
+++ b/include/hw/acpi/generic_event_device.h
@@ -60,6 +60,7 @@
 #define HW_ACPI_GENERIC_EVENT_DEVICE_H
 
 #include "hw/sysbus.h"
+#include "hw/acpi/cpu_hotplug.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/ghes.h"
 #include "qom/object.h"
@@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
 #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
 #define ACPI_GED_PWR_DOWN_EVT      0x2
 #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
+#define ACPI_GED_CPU_HOTPLUG_EVT    0x8
 
 typedef struct GEDState {
     MemoryRegion evt;
@@ -106,6 +108,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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events
  2023-10-13 10:51 ` [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  2023-10-19 10:16   ` Alex Bennée
  2023-10-27 14:08   ` Igor Mammedov
  2 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 _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.

Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/generic_event_device.c         | 8 ++++++++
 include/hw/acpi/generic_event_device.h | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
index a3d31631fe..d2fa1d0e4a 100644
--- a/hw/acpi/generic_event_device.c
+++ b/hw/acpi/generic_event_device.c
@@ -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)
diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h
index ba84ce0214..a803ea818e 100644
--- a/include/hw/acpi/generic_event_device.h
+++ b/include/hw/acpi/generic_event_device.h
@@ -60,6 +60,7 @@
 #define HW_ACPI_GENERIC_EVENT_DEVICE_H
 
 #include "hw/sysbus.h"
+#include "hw/acpi/cpu_hotplug.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/ghes.h"
 #include "qom/object.h"
@@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
 #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
 #define ACPI_GED_PWR_DOWN_EVT      0x2
 #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
+#define ACPI_GED_CPU_HOTPLUG_EVT    0x8
 
 typedef struct GEDState {
     MemoryRegion evt;
@@ -106,6 +108,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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (4 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-27 13:46   ` Igor Mammedov
  2023-10-13 10:51 ` [PATCH V6 6/9] hw/acpi: Update GED _EVT method AML with CPU scan Salil Mehta via
                   ` (6 subsequent siblings)
  12 siblings, 2 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 _CRS objects
would evaluate to a system resource which describes IO Port address. But on ARM
arch CPUs control device(\\_SB.PRES) register interface is memory-mapped hence
_CRS object should evaluate to system resource which describes memory-mapped
base address. Update build CPUs AML function to accept both IO/MEMORY region
spaces and accordingly update the _CRS object.

On x86, Legacy CPU Hotplug uses Generic ACPI GPE Block Bit 2 (GPE.2) event
handler to notify OSPM about any CPU hot(un)plug events. Latest CPU Hotplug is
based on ACPI Generic Event Device framework and uses ACPI GED device for the
same. Not all architectures support Legacy CPU Hotplug. Hence, make AML for
GPE.2 event handler conditional.

Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/cpu.c         | 23 ++++++++++++++++-------
 hw/i386/acpi-build.c  |  3 ++-
 include/hw/acpi/cpu.h |  5 +++--
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 4b24a25003..596b6d9d81 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -339,9 +339,10 @@ const VMStateDescription vmstate_cpu_hotplug = {
 #define CPU_FW_EJECT_EVENT "CEJF"
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
-                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
+                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
                     const char *res_root,
-                    const char *event_handler_method)
+                    const char *event_handler_method,
+                    AmlRegionSpace rs)
 {
     Aml *ifctx;
     Aml *field;
@@ -366,13 +367,19 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         aml_append(cpu_ctrl_dev, aml_mutex(CPU_LOCK, 0));
 
         crs = aml_resource_template();
-        aml_append(crs, aml_io(AML_DECODE16, io_base, io_base, 1,
+        if (rs == AML_SYSTEM_IO) {
+            aml_append(crs, aml_io(AML_DECODE16, base_addr, base_addr, 1,
                                ACPI_CPU_HOTPLUG_REG_LEN));
+        } else {
+            aml_append(crs, aml_memory32_fixed(base_addr,
+                               ACPI_CPU_HOTPLUG_REG_LEN, AML_READ_WRITE));
+        }
+
         aml_append(cpu_ctrl_dev, aml_name_decl("_CRS", crs));
 
         /* declare CPU hotplug MMIO region with related access fields */
         aml_append(cpu_ctrl_dev,
-            aml_operation_region("PRST", AML_SYSTEM_IO, aml_int(io_base),
+            aml_operation_region("PRST", rs, aml_int(base_addr),
                                  ACPI_CPU_HOTPLUG_REG_LEN));
 
         field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,
@@ -696,9 +703,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
     aml_append(sb_scope, cpus_dev);
     aml_append(table, sb_scope);
 
-    method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
-    aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
-    aml_append(table, method);
+    if (event_handler_method) {
+        method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
+        aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
+        aml_append(table, method);
+    }
 
     g_free(cphp_res_path);
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 3f2b27cf75..f9f31f9db5 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1550,7 +1550,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
             .fw_unplugs_cpu = pm->smi_on_cpu_unplug,
         };
         build_cpus_aml(dsdt, machine, opts, pc_madt_cpu_entry,
-                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02");
+                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02",
+                       AML_SYSTEM_IO);
     }
 
     if (pcms->memhp_io_base && nr_mem) {
diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
index bc901660fb..b521a4e0de 100644
--- a/include/hw/acpi/cpu.h
+++ b/include/hw/acpi/cpu.h
@@ -60,9 +60,10 @@ typedef void (*build_madt_cpu_fn)(int uid, const CPUArchIdList *apic_ids,
                                   GArray *entry, bool force_enabled);
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
-                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
+                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
                     const char *res_root,
-                    const char *event_handler_method);
+                    const char *event_handler_method,
+                    AmlRegionSpace rs);
 
 void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list);
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
  2023-10-13 10:51 ` [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  2023-10-27 13:46   ` Igor Mammedov
  1 sibling, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 _CRS objects
would evaluate to a system resource which describes IO Port address. But on ARM
arch CPUs control device(\\_SB.PRES) register interface is memory-mapped hence
_CRS object should evaluate to system resource which describes memory-mapped
base address. Update build CPUs AML function to accept both IO/MEMORY region
spaces and accordingly update the _CRS object.

On x86, Legacy CPU Hotplug uses Generic ACPI GPE Block Bit 2 (GPE.2) event
handler to notify OSPM about any CPU hot(un)plug events. Latest CPU Hotplug is
based on ACPI Generic Event Device framework and uses ACPI GED device for the
same. Not all architectures support Legacy CPU Hotplug. Hence, make AML for
GPE.2 event handler conditional.

Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/cpu.c         | 23 ++++++++++++++++-------
 hw/i386/acpi-build.c  |  3 ++-
 include/hw/acpi/cpu.h |  5 +++--
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 4b24a25003..596b6d9d81 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -339,9 +339,10 @@ const VMStateDescription vmstate_cpu_hotplug = {
 #define CPU_FW_EJECT_EVENT "CEJF"
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
-                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
+                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
                     const char *res_root,
-                    const char *event_handler_method)
+                    const char *event_handler_method,
+                    AmlRegionSpace rs)
 {
     Aml *ifctx;
     Aml *field;
@@ -366,13 +367,19 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
         aml_append(cpu_ctrl_dev, aml_mutex(CPU_LOCK, 0));
 
         crs = aml_resource_template();
-        aml_append(crs, aml_io(AML_DECODE16, io_base, io_base, 1,
+        if (rs == AML_SYSTEM_IO) {
+            aml_append(crs, aml_io(AML_DECODE16, base_addr, base_addr, 1,
                                ACPI_CPU_HOTPLUG_REG_LEN));
+        } else {
+            aml_append(crs, aml_memory32_fixed(base_addr,
+                               ACPI_CPU_HOTPLUG_REG_LEN, AML_READ_WRITE));
+        }
+
         aml_append(cpu_ctrl_dev, aml_name_decl("_CRS", crs));
 
         /* declare CPU hotplug MMIO region with related access fields */
         aml_append(cpu_ctrl_dev,
-            aml_operation_region("PRST", AML_SYSTEM_IO, aml_int(io_base),
+            aml_operation_region("PRST", rs, aml_int(base_addr),
                                  ACPI_CPU_HOTPLUG_REG_LEN));
 
         field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,
@@ -696,9 +703,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
     aml_append(sb_scope, cpus_dev);
     aml_append(table, sb_scope);
 
-    method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
-    aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
-    aml_append(table, method);
+    if (event_handler_method) {
+        method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
+        aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
+        aml_append(table, method);
+    }
 
     g_free(cphp_res_path);
 }
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 3f2b27cf75..f9f31f9db5 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1550,7 +1550,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
             .fw_unplugs_cpu = pm->smi_on_cpu_unplug,
         };
         build_cpus_aml(dsdt, machine, opts, pc_madt_cpu_entry,
-                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02");
+                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02",
+                       AML_SYSTEM_IO);
     }
 
     if (pcms->memhp_io_base && nr_mem) {
diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
index bc901660fb..b521a4e0de 100644
--- a/include/hw/acpi/cpu.h
+++ b/include/hw/acpi/cpu.h
@@ -60,9 +60,10 @@ typedef void (*build_madt_cpu_fn)(int uid, const CPUArchIdList *apic_ids,
                                   GArray *entry, bool force_enabled);
 
 void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
-                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
+                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
                     const char *res_root,
-                    const char *event_handler_method);
+                    const char *event_handler_method,
+                    AmlRegionSpace rs);
 
 void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list);
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 6/9] hw/acpi: Update GED _EVT method AML with CPU scan
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (5 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-13 10:51 ` [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug Salil Mehta via
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

OSPM evaluates _EVT method to map the event. The CPU hotplug event eventually
results in start of the CPU scan. Scan figures out the CPU and the kind of
event(plug/unplug) and notifies it back to the guest. Update the GED AML _EVT
method with the call to \\_SB.CPUS.CSCN

Also, macro CPU_SCAN_METHOD might be referred in other places like during GED
intialization so it makes sense to have its definition placed in some common
header file like cpu_hotplug.h. But doing this can cause compilation break
because of the conflicting macro definitions present in cpu.c and cpu_hotplug.c
and because both these files get compiled due to historic reasons of x86 world
i.e. decision to use legacy(GPE.2)/modern(GED) CPU hotplug interface happens
during runtime [1]. To mitigate above, for now, declare a new common macro
ACPI_CPU_SCAN_METHOD for CPU scan method instead.
(This needs a separate discussion later on for clean-up)

Reference:
[1] https://lore.kernel.org/qemu-devel/1463496205-251412-24-git-send-email-imammedo@redhat.com/

Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/cpu.c                  | 2 +-
 hw/acpi/generic_event_device.c | 4 ++++
 include/hw/acpi/cpu_hotplug.h  | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 596b6d9d81..5b0eaad1c5 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -323,7 +323,7 @@ const VMStateDescription vmstate_cpu_hotplug = {
 #define CPUHP_RES_DEVICE  "PRES"
 #define CPU_LOCK          "CPLK"
 #define CPU_STS_METHOD    "CSTA"
-#define CPU_SCAN_METHOD   "CSCN"
+#define CPU_SCAN_METHOD   ACPI_CPU_SCAN_METHOD
 #define CPU_NOTIFY_METHOD "CTFY"
 #define CPU_EJECT_METHOD  "CEJ0"
 #define CPU_OST_METHOD    "COST"
diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
index d2fa1d0e4a..62d504d231 100644
--- a/hw/acpi/generic_event_device.c
+++ b/hw/acpi/generic_event_device.c
@@ -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),
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 48b291e45e..ef631750b4 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 6/9] hw/acpi: Update GED _EVT method AML with CPU scan
  2023-10-13 10:51 ` [PATCH V6 6/9] hw/acpi: Update GED _EVT method AML with CPU scan Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

OSPM evaluates _EVT method to map the event. The CPU hotplug event eventually
results in start of the CPU scan. Scan figures out the CPU and the kind of
event(plug/unplug) and notifies it back to the guest. Update the GED AML _EVT
method with the call to \\_SB.CPUS.CSCN

Also, macro CPU_SCAN_METHOD might be referred in other places like during GED
intialization so it makes sense to have its definition placed in some common
header file like cpu_hotplug.h. But doing this can cause compilation break
because of the conflicting macro definitions present in cpu.c and cpu_hotplug.c
and because both these files get compiled due to historic reasons of x86 world
i.e. decision to use legacy(GPE.2)/modern(GED) CPU hotplug interface happens
during runtime [1]. To mitigate above, for now, declare a new common macro
ACPI_CPU_SCAN_METHOD for CPU scan method instead.
(This needs a separate discussion later on for clean-up)

Reference:
[1] https://lore.kernel.org/qemu-devel/1463496205-251412-24-git-send-email-imammedo@redhat.com/

Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/cpu.c                  | 2 +-
 hw/acpi/generic_event_device.c | 4 ++++
 include/hw/acpi/cpu_hotplug.h  | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
index 596b6d9d81..5b0eaad1c5 100644
--- a/hw/acpi/cpu.c
+++ b/hw/acpi/cpu.c
@@ -323,7 +323,7 @@ const VMStateDescription vmstate_cpu_hotplug = {
 #define CPUHP_RES_DEVICE  "PRES"
 #define CPU_LOCK          "CPLK"
 #define CPU_STS_METHOD    "CSTA"
-#define CPU_SCAN_METHOD   "CSCN"
+#define CPU_SCAN_METHOD   ACPI_CPU_SCAN_METHOD
 #define CPU_NOTIFY_METHOD "CTFY"
 #define CPU_EJECT_METHOD  "CEJ0"
 #define CPU_OST_METHOD    "COST"
diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
index d2fa1d0e4a..62d504d231 100644
--- a/hw/acpi/generic_event_device.c
+++ b/hw/acpi/generic_event_device.c
@@ -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),
diff --git a/include/hw/acpi/cpu_hotplug.h b/include/hw/acpi/cpu_hotplug.h
index 48b291e45e..ef631750b4 100644
--- a/include/hw/acpi/cpu_hotplug.h
+++ b/include/hw/acpi/cpu_hotplug.h
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (6 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 6/9] hw/acpi: Update GED _EVT method AML with CPU scan Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-27 13:18   ` Igor Mammedov
  2023-10-13 10:51 ` [PATCH V6 8/9] physmem: Add helper function to destroy CPU AddressSpace Salil Mehta via
                   ` (4 subsequent siblings)
  12 siblings, 2 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/generic_event_device.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
index 62d504d231..0d5f0140e5 100644
--- a/hw/acpi/generic_event_device.c
+++ b/hw/acpi/generic_event_device.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
  2023-10-13 10:51 ` [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  2023-10-27 13:18   ` Igor Mammedov
  1 sibling, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 <zhukeqian1@huawei.com>
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 hw/acpi/generic_event_device.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
index 62d504d231..0d5f0140e5 100644
--- a/hw/acpi/generic_event_device.c
+++ b/hw/acpi/generic_event_device.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 8/9] physmem: Add helper function to destroy CPU AddressSpace
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (7 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-13 10:51 ` [PATCH V6 9/9] gdbstub: Add helper function to unregister GDB register space Salil Mehta via
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 <salil.mehta@huawei.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 include/exec/cpu-common.h |  8 ++++++++
 include/hw/core/cpu.h     |  1 +
 system/physmem.c          | 29 +++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 605b160a7e..a930e49e02 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -127,6 +127,14 @@ size_t qemu_ram_pagesize_largest(void);
  */
 void cpu_address_space_init(CPUState *cpu, int asidx,
                             const char *prefix, MemoryRegion *mr);
+/**
+ * cpu_address_space_destroy:
+ * @cpu: CPU for which address space needs to be destroyed
+ * @asidx: integer index of this address space
+ *
+ * Note that with KVM only one address space is supported.
+ */
+void cpu_address_space_destroy(CPUState *cpu, int asidx);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 3968369554..708b6b48de 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -496,6 +496,7 @@ struct CPUState {
     QSIMPLEQ_HEAD(, qemu_work_item) work_list;
 
     CPUAddressSpace *cpu_ases;
+    int cpu_ases_count;
     int num_ases;
     AddressSpace *as;
     MemoryRegion *memory;
diff --git a/system/physmem.c b/system/physmem.c
index edc3ed8ab9..a16f1d4056 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -761,6 +761,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
 
     if (!cpu->cpu_ases) {
         cpu->cpu_ases = g_new0(CPUAddressSpace, cpu->num_ases);
+        cpu->cpu_ases_count = cpu->num_ases;
     }
 
     newas = &cpu->cpu_ases[asidx];
@@ -774,6 +775,34 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
     }
 }
 
+void cpu_address_space_destroy(CPUState *cpu, int asidx)
+{
+    CPUAddressSpace *cpuas;
+
+    assert(cpu->cpu_ases);
+    assert(asidx >= 0 && asidx < cpu->num_ases);
+    /* KVM cannot currently support multiple address spaces. */
+    assert(asidx == 0 || !kvm_enabled());
+
+    cpuas = &cpu->cpu_ases[asidx];
+    if (tcg_enabled()) {
+        memory_listener_unregister(&cpuas->tcg_as_listener);
+    }
+
+    address_space_destroy(cpuas->as);
+    g_free_rcu(cpuas->as, rcu);
+
+    if (asidx == 0) {
+        /* reset the convenience alias for address space 0 */
+        cpu->as = NULL;
+    }
+
+    if (--cpu->cpu_ases_count == 0) {
+        g_free(cpu->cpu_ases);
+        cpu->cpu_ases = NULL;
+    }
+}
+
 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
 {
     /* Return the AddressSpace corresponding to the specified index */
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 8/9] physmem: Add helper function to destroy CPU AddressSpace
  2023-10-13 10:51 ` [PATCH V6 8/9] physmem: Add helper function to destroy CPU AddressSpace Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 <salil.mehta@huawei.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 include/exec/cpu-common.h |  8 ++++++++
 include/hw/core/cpu.h     |  1 +
 system/physmem.c          | 29 +++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 605b160a7e..a930e49e02 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -127,6 +127,14 @@ size_t qemu_ram_pagesize_largest(void);
  */
 void cpu_address_space_init(CPUState *cpu, int asidx,
                             const char *prefix, MemoryRegion *mr);
+/**
+ * cpu_address_space_destroy:
+ * @cpu: CPU for which address space needs to be destroyed
+ * @asidx: integer index of this address space
+ *
+ * Note that with KVM only one address space is supported.
+ */
+void cpu_address_space_destroy(CPUState *cpu, int asidx);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 3968369554..708b6b48de 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -496,6 +496,7 @@ struct CPUState {
     QSIMPLEQ_HEAD(, qemu_work_item) work_list;
 
     CPUAddressSpace *cpu_ases;
+    int cpu_ases_count;
     int num_ases;
     AddressSpace *as;
     MemoryRegion *memory;
diff --git a/system/physmem.c b/system/physmem.c
index edc3ed8ab9..a16f1d4056 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -761,6 +761,7 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
 
     if (!cpu->cpu_ases) {
         cpu->cpu_ases = g_new0(CPUAddressSpace, cpu->num_ases);
+        cpu->cpu_ases_count = cpu->num_ases;
     }
 
     newas = &cpu->cpu_ases[asidx];
@@ -774,6 +775,34 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
     }
 }
 
+void cpu_address_space_destroy(CPUState *cpu, int asidx)
+{
+    CPUAddressSpace *cpuas;
+
+    assert(cpu->cpu_ases);
+    assert(asidx >= 0 && asidx < cpu->num_ases);
+    /* KVM cannot currently support multiple address spaces. */
+    assert(asidx == 0 || !kvm_enabled());
+
+    cpuas = &cpu->cpu_ases[asidx];
+    if (tcg_enabled()) {
+        memory_listener_unregister(&cpuas->tcg_as_listener);
+    }
+
+    address_space_destroy(cpuas->as);
+    g_free_rcu(cpuas->as, rcu);
+
+    if (asidx == 0) {
+        /* reset the convenience alias for address space 0 */
+        cpu->as = NULL;
+    }
+
+    if (--cpu->cpu_ases_count == 0) {
+        g_free(cpu->cpu_ases);
+        cpu->cpu_ases = NULL;
+    }
+}
+
 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
 {
     /* Return the AddressSpace corresponding to the specified index */
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 9/9] gdbstub: Add helper function to unregister GDB register space
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (8 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 8/9] physmem: Add helper function to destroy CPU AddressSpace Salil Mehta via
@ 2023-10-13 10:51 ` Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-13 16:33 ` [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Miguel Luis
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 47+ messages in thread
From: Salil Mehta via @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 <salil.mehta@huawei.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 gdbstub/gdbstub.c      | 12 ++++++++++++
 include/exec/gdbstub.h |  5 +++++
 2 files changed, 17 insertions(+)

diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index b1532118d1..7bd6d45857 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -498,6 +498,18 @@ void gdb_register_coprocessor(CPUState *cpu,
     }
 }
 
+void gdb_unregister_coprocessor_all(CPUState *cpu)
+{
+    /*
+     * Safe to nuke everything. GDBRegisterState::xml is static const char so
+     * it won't be freed
+     */
+    g_array_free(cpu->gdb_regs, true);
+
+    cpu->gdb_regs = NULL;
+    cpu->gdb_num_g_regs = 0;
+}
+
 static void gdb_process_breakpoint_remove_all(GDBProcess *p)
 {
     CPUState *cpu = gdb_get_first_cpu_in_process(p);
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 1a01c35f8e..3744257ed3 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -32,6 +32,11 @@ typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);
 void gdb_register_coprocessor(CPUState *cpu,
                               gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
                               int num_regs, const char *xml, int g_pos);
+/**
+ * gdb_unregister_coprocessor_all() - unregisters supplemental set of registers
+ * @cpu - the CPU associated with registers
+ */
+void gdb_unregister_coprocessor_all(CPUState *cpu);
 
 /**
  * gdbserver_start: start the gdb server
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH V6 9/9] gdbstub: Add helper function to unregister GDB register space
  2023-10-13 10:51 ` [PATCH V6 9/9] gdbstub: Add helper function to unregister GDB register space Salil Mehta via
@ 2023-10-13 10:51   ` Salil Mehta
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-13 10:51 UTC (permalink / raw)
  To: qemu-devel, qemu-arm
  Cc: salil.mehta, maz, jean-philippe, jonathan.cameron, lpieralisi,
	peter.maydell, richard.henderson, imammedo, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

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 <salil.mehta@huawei.com>
Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Tested-by: Xianglai Li <lixianglai@loongson.cn>
---
 gdbstub/gdbstub.c      | 12 ++++++++++++
 include/exec/gdbstub.h |  5 +++++
 2 files changed, 17 insertions(+)

diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index b1532118d1..7bd6d45857 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -498,6 +498,18 @@ void gdb_register_coprocessor(CPUState *cpu,
     }
 }
 
+void gdb_unregister_coprocessor_all(CPUState *cpu)
+{
+    /*
+     * Safe to nuke everything. GDBRegisterState::xml is static const char so
+     * it won't be freed
+     */
+    g_array_free(cpu->gdb_regs, true);
+
+    cpu->gdb_regs = NULL;
+    cpu->gdb_num_g_regs = 0;
+}
+
 static void gdb_process_breakpoint_remove_all(GDBProcess *p)
 {
     CPUState *cpu = gdb_get_first_cpu_in_process(p);
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 1a01c35f8e..3744257ed3 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -32,6 +32,11 @@ typedef int (*gdb_set_reg_cb)(CPUArchState *env, uint8_t *buf, int reg);
 void gdb_register_coprocessor(CPUState *cpu,
                               gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg,
                               int num_regs, const char *xml, int g_pos);
+/**
+ * gdb_unregister_coprocessor_all() - unregisters supplemental set of registers
+ * @cpu - the CPU associated with registers
+ */
+void gdb_unregister_coprocessor_all(CPUState *cpu);
 
 /**
  * gdbserver_start: start the gdb server
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (9 preceding siblings ...)
  2023-10-13 10:51 ` [PATCH V6 9/9] gdbstub: Add helper function to unregister GDB register space Salil Mehta via
@ 2023-10-13 16:33 ` Miguel Luis
  2023-10-16  9:52   ` Salil Mehta via
  2023-10-19  9:04 ` Shaoqin Huang
  2023-10-26 12:41 ` Igor Mammedov
  12 siblings, 1 reply; 47+ messages in thread
From: Miguel Luis @ 2023-10-13 16:33 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Marc Zyngier,
	jean-philippe@linaro.org, jonathan.cameron@huawei.com,
	lpieralisi@kernel.org, Peter Maydell, Richard Henderson,
	imammedo@redhat.com, andrew.jones@linux.dev, david@redhat.com,
	philmd@linaro.org, eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	Karl Heubaum, salil.mehta@opnsrc.net, zhukeqian1@huawei.com,
	wangxiongfeng2@huawei.com, wangyanan55@huawei.com,
	jiakernel2@gmail.com, maobibo@loongson.cn, lixianglai@loongson.cn,
	linuxarm@huawei.com

Hi Salil,

> On 13 Oct 2023, at 10:51, Salil Mehta <salil.mehta@huawei.com> wrote:
> 
> Virtual CPU hotplug support is being added across various architectures[1][3].
> This series adds various code bits common across all architectures:
> 
> 1. vCPU creation and Parking code refactor [Patch 1]
> 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
> 3. ACPI CPUs AML code change [Patch 5]
> 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
> 5. Misc [Patch 2,3]
> 
> 
> Repository:
> 
> [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v6
> 
> 
> Revision History:
> 
> Patch-set  V5 -> V6
> 1. Addressed Gavin Shan's comments
>   - Fixed the assert() ranges of address spaces
>   - Rebased the patch-set to latest changes in the qemu.git
>   - Added Reviewed-by tags for patches {8,9}
> 2. Addressed Jonathan Cameron's comments
>   - Updated commit-log for [Patch V5 1/9] with mention of trace events
>   - Added Reviewed-by tags for patches {1,5}
> 3. Added Tested-by tags from Xianglai Li
> 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9] 
> Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-salil.mehta@huawei.com/
> 
> Patch-set  V4 -> V5
> 1. Addressed Gavin Shan's comments
>   - Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
>   - Added Reviewed-by tag for patch {1}
> 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
> 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
> 4. Dropped the ARM specific [Patch V4 10/10]
> Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-salil.mehta@huawei.com/
> 
> Patch-set  V3 -> V4
> 1. Addressed David Hilderbrand's comments
>   - Fixed the wrong doc comment of kvm_park_vcpu API prototype
>   - Added Reviewed-by tags for patches {2,4}
> Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-salil.mehta@huawei.com/
> 
> Patch-set  V2 -> V3
> 1. Addressed Jonathan Cameron's comments
>   - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
>   - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
>   - Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
>   - Updated [Patch V2 5/10] commit-log with details of conditional event handler method
>   - Added Reviewed-by tags for patches {2,3,4,6,7}
> 2. Addressed Gavin Shan's comments
>   - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
>   - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
>   - Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
>   - Fixed the kvm_{create,park}_vcpu prototypes docs
>   - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
> 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
>   - Added traces instead of DPRINTF in the newly added and some existing functions
> Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-salil.mehta@huawei.com/
> 
> Patch-set V1 -> V2
> 1. Addressed Alex Bennée's comments
>   - Refactored the kvm_create_vcpu logic to get rid of goto
>   - Added the docs for kvm_{create,park}_vcpu prototypes
>   - Splitted the gdbstub and AddressSpace destruction change into separate patches
>   - Added Reviewed-by tags for patches {2,10}
> Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-salil.mehta@huawei.com/
> 
> References:
> 
> [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-salil.mehta@huawei.com/
> [2] https://lore.kernel.org/all/20230913163823.7880-1-james.morse@arm.com/
> [3] https://lore.kernel.org/qemu-devel/cover.1695697701.git.lixianglai@loongson.cn/
> 
> 
> 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                    | 64 ++++++++++++++++++++------
> accel/kvm/trace-events                 |  4 ++
> gdbstub/gdbstub.c                      | 12 +++++
> hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
> hw/acpi/cpu.c                          | 27 +++++++----
> hw/acpi/generic_event_device.c         | 22 +++++++++
> hw/i386/acpi-build.c                   |  3 +-
> include/exec/cpu-common.h              |  8 ++++
> include/exec/gdbstub.h                 |  5 ++
> include/hw/acpi/cpu.h                  |  5 +-
> include/hw/acpi/cpu_hotplug.h          |  4 ++
> include/hw/acpi/generic_event_device.h |  5 ++
> include/hw/core/cpu.h                  |  1 +
> include/sysemu/kvm.h                   | 16 +++++++
> system/physmem.c                       | 29 ++++++++++++
> 15 files changed, 184 insertions(+), 27 deletions(-)
> 

I tested it for Arm64, make check, boot/reboot, live migration and found no issues,
so for this, please feel free to add:

Tested-by: Miguel Luis <miguel.luis@oracle.com>

Thank you,
Miguel

> -- 
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-13 16:33 ` [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Miguel Luis
@ 2023-10-16  9:52   ` Salil Mehta via
  2023-10-16  9:52     ` Salil Mehta
  2023-10-16 10:01     ` Miguel Luis
  0 siblings, 2 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-16  9:52 UTC (permalink / raw)
  To: Miguel Luis
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Marc Zyngier,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	Peter Maydell, Richard Henderson, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	Karl Heubaum, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

Hi Miguel,

> From: Miguel Luis <miguel.luis@oracle.com>
> Sent: Friday, October 13, 2023 5:34 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; Marc Zyngier
> <maz@kernel.org>; jean-philippe@linaro.org; Jonathan Cameron
> <jonathan.cameron@huawei.com>; lpieralisi@kernel.org; Peter Maydell
> <peter.maydell@linaro.org>; Richard Henderson
> <richard.henderson@linaro.org>; imammedo@redhat.com;
> andrew.jones@linux.dev; david@redhat.com; philmd@linaro.org;
> eric.auger@redhat.com; oliver.upton@linux.dev; pbonzini@redhat.com;
> mst@redhat.com; will@kernel.org; gshan@redhat.com; rafael@kernel.org;
> alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; Karl Heubaum <karl.heubaum@oracle.com>;
> salil.mehta@opnsrc.net; zhukeqian <zhukeqian1@huawei.com>; wangxiongfeng
> (C) <wangxiongfeng2@huawei.com>; wangyanan (Y) <wangyanan55@huawei.com>;
> jiakernel2@gmail.com; maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm
> <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> Hotplug
> 
> Hi Salil,
> 
> > On 13 Oct 2023, at 10:51, Salil Mehta <salil.mehta@huawei.com> wrote:
> >
> > Virtual CPU hotplug support is being added across various
> architectures[1][3].
> > This series adds various code bits common across all architectures:


[...]


> I tested it for Arm64, make check, boot/reboot, live migration and found no
> issues,
> so for this, please feel free to add:
> 
> Tested-by: Miguel Luis <miguel.luis@oracle.com>

Great. Many thanks for the confirmation. 

I guess you are repeating the same for x86 as well?

Salil.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-16  9:52   ` Salil Mehta via
@ 2023-10-16  9:52     ` Salil Mehta
  2023-10-16 10:01     ` Miguel Luis
  1 sibling, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-16  9:52 UTC (permalink / raw)
  To: Miguel Luis
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Marc Zyngier,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	Peter Maydell, Richard Henderson, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	Karl Heubaum, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

Hi Miguel,

> From: Miguel Luis <miguel.luis@oracle.com>
> Sent: Friday, October 13, 2023 5:34 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; Marc Zyngier
> <maz@kernel.org>; jean-philippe@linaro.org; Jonathan Cameron
> <jonathan.cameron@huawei.com>; lpieralisi@kernel.org; Peter Maydell
> <peter.maydell@linaro.org>; Richard Henderson
> <richard.henderson@linaro.org>; imammedo@redhat.com;
> andrew.jones@linux.dev; david@redhat.com; philmd@linaro.org;
> eric.auger@redhat.com; oliver.upton@linux.dev; pbonzini@redhat.com;
> mst@redhat.com; will@kernel.org; gshan@redhat.com; rafael@kernel.org;
> alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; Karl Heubaum <karl.heubaum@oracle.com>;
> salil.mehta@opnsrc.net; zhukeqian <zhukeqian1@huawei.com>; wangxiongfeng
> (C) <wangxiongfeng2@huawei.com>; wangyanan (Y) <wangyanan55@huawei.com>;
> jiakernel2@gmail.com; maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm
> <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> Hotplug
> 
> Hi Salil,
> 
> > On 13 Oct 2023, at 10:51, Salil Mehta <salil.mehta@huawei.com> wrote:
> >
> > Virtual CPU hotplug support is being added across various
> architectures[1][3].
> > This series adds various code bits common across all architectures:


[...]


> I tested it for Arm64, make check, boot/reboot, live migration and found no
> issues,
> so for this, please feel free to add:
> 
> Tested-by: Miguel Luis <miguel.luis@oracle.com>

Great. Many thanks for the confirmation. 

I guess you are repeating the same for x86 as well?

Salil.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-16  9:52   ` Salil Mehta via
  2023-10-16  9:52     ` Salil Mehta
@ 2023-10-16 10:01     ` Miguel Luis
  2023-10-16 10:09       ` Salil Mehta via
  2023-10-19  9:50       ` Miguel Luis
  1 sibling, 2 replies; 47+ messages in thread
From: Miguel Luis @ 2023-10-16 10:01 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Marc Zyngier,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	Peter Maydell, Richard Henderson, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	Karl Heubaum, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

Hi Salil,

> On 16 Oct 2023, at 09:52, Salil Mehta <salil.mehta@huawei.com> wrote:
> 
> Hi Miguel,
> 
>> From: Miguel Luis <miguel.luis@oracle.com>
>> Sent: Friday, October 13, 2023 5:34 PM
>> To: Salil Mehta <salil.mehta@huawei.com>
>> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; Marc Zyngier
>> <maz@kernel.org>; jean-philippe@linaro.org; Jonathan Cameron
>> <jonathan.cameron@huawei.com>; lpieralisi@kernel.org; Peter Maydell
>> <peter.maydell@linaro.org>; Richard Henderson
>> <richard.henderson@linaro.org>; imammedo@redhat.com;
>> andrew.jones@linux.dev; david@redhat.com; philmd@linaro.org;
>> eric.auger@redhat.com; oliver.upton@linux.dev; pbonzini@redhat.com;
>> mst@redhat.com; will@kernel.org; gshan@redhat.com; rafael@kernel.org;
>> alex.bennee@linaro.org; linux@armlinux.org.uk;
>> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
>> vishnu@os.amperecomputing.com; Karl Heubaum <karl.heubaum@oracle.com>;
>> salil.mehta@opnsrc.net; zhukeqian <zhukeqian1@huawei.com>; wangxiongfeng
>> (C) <wangxiongfeng2@huawei.com>; wangyanan (Y) <wangyanan55@huawei.com>;
>> jiakernel2@gmail.com; maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm
>> <linuxarm@huawei.com>
>> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
>> Hotplug
>> 
>> Hi Salil,
>> 
>>> On 13 Oct 2023, at 10:51, Salil Mehta <salil.mehta@huawei.com> wrote:
>>> 
>>> Virtual CPU hotplug support is being added across various
>> architectures[1][3].
>>> This series adds various code bits common across all architectures:
> 
> 
> [...]
> 
> 
>> I tested it for Arm64, make check, boot/reboot, live migration and found no
>> issues,
>> so for this, please feel free to add:
>> 
>> Tested-by: Miguel Luis <miguel.luis@oracle.com>
> 
> Great. Many thanks for the confirmation. 
> 
> I guess you are repeating the same for x86 as well?
> 

You are welcome!

Absolutely, I’m repeating those same tests for x86.

Thanks
Miguel

> Salil.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-16 10:01     ` Miguel Luis
@ 2023-10-16 10:09       ` Salil Mehta via
  2023-10-16 10:09         ` Salil Mehta
  2023-10-19  9:50       ` Miguel Luis
  1 sibling, 1 reply; 47+ messages in thread
From: Salil Mehta via @ 2023-10-16 10:09 UTC (permalink / raw)
  To: Miguel Luis
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Marc Zyngier,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	Peter Maydell, Richard Henderson, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	Karl Heubaum, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

> From: Miguel Luis <miguel.luis@oracle.com>
> Sent: Monday, October 16, 2023 11:02 AM
> To: Salil Mehta <salil.mehta@huawei.com>
> 
> Hi Salil,
> 
> > On 16 Oct 2023, at 09:52, Salil Mehta <salil.mehta@huawei.com> wrote:
> >
> > Hi Miguel,
> >
> >> From: Miguel Luis <miguel.luis@oracle.com>
> >> Sent: Friday, October 13, 2023 5:34 PM
> >> To: Salil Mehta <salil.mehta@huawei.com>

[...]

> >> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> >> Hotplug
> >>
> >> Hi Salil,
> >>
> >>> On 13 Oct 2023, at 10:51, Salil Mehta <salil.mehta@huawei.com> wrote:
> >>>
> >>> Virtual CPU hotplug support is being added across various
> >> architectures[1][3].
> >>> This series adds various code bits common across all architectures:
> >
> > [...]
> >
> >> I tested it for Arm64, make check, boot/reboot, live migration and found no
> >> issues,
> >> so for this, please feel free to add:
> >>
> >> Tested-by: Miguel Luis <miguel.luis@oracle.com>
> >
> > Great. Many thanks for the confirmation.
> >
> > I guess you are repeating the same for x86 as well?
> >
> 
> You are welcome!
> 
> Absolutely, I’m repeating those same tests for x86.

Brilliant. Thanks for proactively taking this up.

Salil.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-16 10:09       ` Salil Mehta via
@ 2023-10-16 10:09         ` Salil Mehta
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-16 10:09 UTC (permalink / raw)
  To: Miguel Luis
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Marc Zyngier,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	Peter Maydell, Richard Henderson, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	Karl Heubaum, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

> From: Miguel Luis <miguel.luis@oracle.com>
> Sent: Monday, October 16, 2023 11:02 AM
> To: Salil Mehta <salil.mehta@huawei.com>
> 
> Hi Salil,
> 
> > On 16 Oct 2023, at 09:52, Salil Mehta <salil.mehta@huawei.com> wrote:
> >
> > Hi Miguel,
> >
> >> From: Miguel Luis <miguel.luis@oracle.com>
> >> Sent: Friday, October 13, 2023 5:34 PM
> >> To: Salil Mehta <salil.mehta@huawei.com>

[...]

> >> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> >> Hotplug
> >>
> >> Hi Salil,
> >>
> >>> On 13 Oct 2023, at 10:51, Salil Mehta <salil.mehta@huawei.com> wrote:
> >>>
> >>> Virtual CPU hotplug support is being added across various
> >> architectures[1][3].
> >>> This series adds various code bits common across all architectures:
> >
> > [...]
> >
> >> I tested it for Arm64, make check, boot/reboot, live migration and found no
> >> issues,
> >> so for this, please feel free to add:
> >>
> >> Tested-by: Miguel Luis <miguel.luis@oracle.com>
> >
> > Great. Many thanks for the confirmation.
> >
> > I guess you are repeating the same for x86 as well?
> >
> 
> You are welcome!
> 
> Absolutely, I’m repeating those same tests for x86.

Brilliant. Thanks for proactively taking this up.

Salil.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (10 preceding siblings ...)
  2023-10-13 16:33 ` [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Miguel Luis
@ 2023-10-19  9:04 ` Shaoqin Huang
  2023-10-19  9:34   ` Salil Mehta via
  2023-10-26 12:41 ` Igor Mammedov
  12 siblings, 1 reply; 47+ messages in thread
From: Shaoqin Huang @ 2023-10-19  9:04 UTC (permalink / raw)
  To: Salil Mehta, qemu-devel, qemu-arm
  Cc: maz, jean-philippe, jonathan.cameron, lpieralisi, peter.maydell,
	richard.henderson, imammedo, andrew.jones, david, philmd,
	eric.auger, oliver.upton, pbonzini, mst, will, gshan, rafael,
	alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm



On 10/13/23 18:51, Salil Mehta via wrote:
> Virtual CPU hotplug support is being added across various architectures[1][3].
> This series adds various code bits common across all architectures:
> 
> 1. vCPU creation and Parking code refactor [Patch 1]
> 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
> 3. ACPI CPUs AML code change [Patch 5]
> 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
> 5. Misc [Patch 2,3]
> 
> 
> Repository:
> 
> [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v6
> 
> 
> Revision History:
> 
> Patch-set  V5 -> V6
> 1. Addressed Gavin Shan's comments
>     - Fixed the assert() ranges of address spaces
>     - Rebased the patch-set to latest changes in the qemu.git
>     - Added Reviewed-by tags for patches {8,9}
> 2. Addressed Jonathan Cameron's comments
>     - Updated commit-log for [Patch V5 1/9] with mention of trace events
>     - Added Reviewed-by tags for patches {1,5}
> 3. Added Tested-by tags from Xianglai Li
> 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9]
> Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-salil.mehta@huawei.com/
> 
> Patch-set  V4 -> V5
> 1. Addressed Gavin Shan's comments
>     - Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
>     - Added Reviewed-by tag for patch {1}
> 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
> 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
> 4. Dropped the ARM specific [Patch V4 10/10]
> Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-salil.mehta@huawei.com/
> 
> Patch-set  V3 -> V4
> 1. Addressed David Hilderbrand's comments
>     - Fixed the wrong doc comment of kvm_park_vcpu API prototype
>     - Added Reviewed-by tags for patches {2,4}
> Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-salil.mehta@huawei.com/
> 
> Patch-set  V2 -> V3
> 1. Addressed Jonathan Cameron's comments
>     - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
>     - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
>     - Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
>     - Updated [Patch V2 5/10] commit-log with details of conditional event handler method
>     - Added Reviewed-by tags for patches {2,3,4,6,7}
> 2. Addressed Gavin Shan's comments
>     - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
>     - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
>     - Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
>     - Fixed the kvm_{create,park}_vcpu prototypes docs
>     - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
> 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
>     - Added traces instead of DPRINTF in the newly added and some existing functions
> Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-salil.mehta@huawei.com/
> 
> Patch-set V1 -> V2
> 1. Addressed Alex Bennée's comments
>     - Refactored the kvm_create_vcpu logic to get rid of goto
>     - Added the docs for kvm_{create,park}_vcpu prototypes
>     - Splitted the gdbstub and AddressSpace destruction change into separate patches
>     - Added Reviewed-by tags for patches {2,10}
> Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-salil.mehta@huawei.com/
> 
> References:
> 
> [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-salil.mehta@huawei.com/
> [2] https://lore.kernel.org/all/20230913163823.7880-1-james.morse@arm.com/
> [3] https://lore.kernel.org/qemu-devel/cover.1695697701.git.lixianglai@loongson.cn/
> 
> 
> 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                    | 64 ++++++++++++++++++++------
>   accel/kvm/trace-events                 |  4 ++
>   gdbstub/gdbstub.c                      | 12 +++++
>   hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
>   hw/acpi/cpu.c                          | 27 +++++++----
>   hw/acpi/generic_event_device.c         | 22 +++++++++
>   hw/i386/acpi-build.c                   |  3 +-
>   include/exec/cpu-common.h              |  8 ++++
>   include/exec/gdbstub.h                 |  5 ++
>   include/hw/acpi/cpu.h                  |  5 +-
>   include/hw/acpi/cpu_hotplug.h          |  4 ++
>   include/hw/acpi/generic_event_device.h |  5 ++
>   include/hw/core/cpu.h                  |  1 +
>   include/sysemu/kvm.h                   | 16 +++++++
>   system/physmem.c                       | 29 ++++++++++++
>   15 files changed, 184 insertions(+), 27 deletions(-)
> 

Hi salil,

All patches looks good to me. Thanks for you effort to update it so 
actively. No issues being found by simply testing and several daily use.

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

Thanks,
Shaoqin

-- 
Shaoqin



^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-19  9:04 ` Shaoqin Huang
@ 2023-10-19  9:34   ` Salil Mehta via
  2023-10-19  9:34     ` Salil Mehta
  2023-10-20  3:30     ` Shaoqin Huang
  0 siblings, 2 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-10-19  9:34 UTC (permalink / raw)
  To: Shaoqin Huang, qemu-devel@nongnu.org, qemu-arm@nongnu.org
  Cc: maz@kernel.org, jean-philippe@linaro.org, Jonathan Cameron,
	lpieralisi@kernel.org, peter.maydell@linaro.org,
	richard.henderson@linaro.org, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Shaoqin,

> From: Shaoqin Huang <shahuang@redhat.com>
> Sent: Thursday, October 19, 2023 10:05 AM
> To: Salil Mehta <salil.mehta@huawei.com>; qemu-devel@nongnu.org; qemu-
> arm@nongnu.org
> Cc: maz@kernel.org; jean-philippe@linaro.org; Jonathan Cameron
> <jonathan.cameron@huawei.com>; lpieralisi@kernel.org;
> peter.maydell@linaro.org; richard.henderson@linaro.org;
> imammedo@redhat.com; andrew.jones@linux.dev; david@redhat.com;
> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> Hotplug
> 
> 
> 
> On 10/13/23 18:51, Salil Mehta via wrote:
> > Virtual CPU hotplug support is being added across various
> architectures[1][3].
> > This series adds various code bits common across all architectures:
> >
> > 1. vCPU creation and Parking code refactor [Patch 1]
> > 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
> > 3. ACPI CPUs AML code change [Patch 5]
> > 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
> > 5. Misc [Patch 2,3]
> >
> >
> > Repository:
> >
> > [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-
> v2.common.v6
> >
> >
> > Revision History:
> >
> > Patch-set  V5 -> V6
> > 1. Addressed Gavin Shan's comments
> >     - Fixed the assert() ranges of address spaces
> >     - Rebased the patch-set to latest changes in the qemu.git
> >     - Added Reviewed-by tags for patches {8,9}
> > 2. Addressed Jonathan Cameron's comments
> >     - Updated commit-log for [Patch V5 1/9] with mention of trace events
> >     - Added Reviewed-by tags for patches {1,5}
> > 3. Added Tested-by tags from Xianglai Li
> > 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9]
> > Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-
> salil.mehta@huawei.com/
> >
> > Patch-set  V4 -> V5
> > 1. Addressed Gavin Shan's comments
> >     - Fixed the trace events print string for
> kvm_{create,get,park,destroy}_vcpu
> >     - Added Reviewed-by tag for patch {1}
> > 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
> > 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
> > 4. Dropped the ARM specific [Patch V4 10/10]
> > Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-
> salil.mehta@huawei.com/
> >
> > Patch-set  V3 -> V4
> > 1. Addressed David Hilderbrand's comments
> >     - Fixed the wrong doc comment of kvm_park_vcpu API prototype
> >     - Added Reviewed-by tags for patches {2,4}
> > Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-
> salil.mehta@huawei.com/
> >
> > Patch-set  V2 -> V3
> > 1. Addressed Jonathan Cameron's comments
> >     - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to
> 'integer'
> >     - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
> >     - Updated [Patch V2 3/10] commit-log with details of
> ACPI_CPU_SCAN_METHOD macro
> >     - Updated [Patch V2 5/10] commit-log with details of conditional
> event handler method
> >     - Added Reviewed-by tags for patches {2,3,4,6,7}
> > 2. Addressed Gavin Shan's comments
> >     - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
> >     - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
> >     - Reset the value of 'gdb_num_g_regs' in
> gdb_unregister_coprocessor_all
> >     - Fixed the kvm_{create,park}_vcpu prototypes docs
> >     - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
> > 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
> >     - Added traces instead of DPRINTF in the newly added and some
> existing functions
> > Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-
> salil.mehta@huawei.com/
> >
> > Patch-set V1 -> V2
> > 1. Addressed Alex Bennée's comments
> >     - Refactored the kvm_create_vcpu logic to get rid of goto
> >     - Added the docs for kvm_{create,park}_vcpu prototypes
> >     - Splitted the gdbstub and AddressSpace destruction change into
> separate patches
> >     - Added Reviewed-by tags for patches {2,10}
> > Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-
> salil.mehta@huawei.com/
> >
> > References:
> >
> > [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-
> salil.mehta@huawei.com/
> > [2] https://lore.kernel.org/all/20230913163823.7880-1-
> james.morse@arm.com/
> > [3] https://lore.kernel.org/qemu-
> devel/cover.1695697701.git.lixianglai@loongson.cn/
> >
> >
> > 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                    | 64 ++++++++++++++++++++------
> >   accel/kvm/trace-events                 |  4 ++
> >   gdbstub/gdbstub.c                      | 12 +++++
> >   hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
> >   hw/acpi/cpu.c                          | 27 +++++++----
> >   hw/acpi/generic_event_device.c         | 22 +++++++++
> >   hw/i386/acpi-build.c                   |  3 +-
> >   include/exec/cpu-common.h              |  8 ++++
> >   include/exec/gdbstub.h                 |  5 ++
> >   include/hw/acpi/cpu.h                  |  5 +-
> >   include/hw/acpi/cpu_hotplug.h          |  4 ++
> >   include/hw/acpi/generic_event_device.h |  5 ++
> >   include/hw/core/cpu.h                  |  1 +
> >   include/sysemu/kvm.h                   | 16 +++++++
> >   system/physmem.c                       | 29 ++++++++++++
> >   15 files changed, 184 insertions(+), 27 deletions(-)
> >
> 
> Hi salil,
> 
> All patches looks good to me. Thanks for you effort to update it so
> actively. No issues being found by simply testing and several daily use.
> 
> Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

Many thanks! Just wanted to confirm if you have tested this patch over
x86 platform as well?


Cheers
Salil.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-19  9:34   ` Salil Mehta via
@ 2023-10-19  9:34     ` Salil Mehta
  2023-10-20  3:30     ` Shaoqin Huang
  1 sibling, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-19  9:34 UTC (permalink / raw)
  To: Shaoqin Huang, qemu-devel@nongnu.org, qemu-arm@nongnu.org
  Cc: maz@kernel.org, jean-philippe@linaro.org, Jonathan Cameron,
	lpieralisi@kernel.org, peter.maydell@linaro.org,
	richard.henderson@linaro.org, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Shaoqin,

> From: Shaoqin Huang <shahuang@redhat.com>
> Sent: Thursday, October 19, 2023 10:05 AM
> To: Salil Mehta <salil.mehta@huawei.com>; qemu-devel@nongnu.org; qemu-
> arm@nongnu.org
> Cc: maz@kernel.org; jean-philippe@linaro.org; Jonathan Cameron
> <jonathan.cameron@huawei.com>; lpieralisi@kernel.org;
> peter.maydell@linaro.org; richard.henderson@linaro.org;
> imammedo@redhat.com; andrew.jones@linux.dev; david@redhat.com;
> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> Hotplug
> 
> 
> 
> On 10/13/23 18:51, Salil Mehta via wrote:
> > Virtual CPU hotplug support is being added across various
> architectures[1][3].
> > This series adds various code bits common across all architectures:
> >
> > 1. vCPU creation and Parking code refactor [Patch 1]
> > 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
> > 3. ACPI CPUs AML code change [Patch 5]
> > 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
> > 5. Misc [Patch 2,3]
> >
> >
> > Repository:
> >
> > [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-
> v2.common.v6
> >
> >
> > Revision History:
> >
> > Patch-set  V5 -> V6
> > 1. Addressed Gavin Shan's comments
> >     - Fixed the assert() ranges of address spaces
> >     - Rebased the patch-set to latest changes in the qemu.git
> >     - Added Reviewed-by tags for patches {8,9}
> > 2. Addressed Jonathan Cameron's comments
> >     - Updated commit-log for [Patch V5 1/9] with mention of trace events
> >     - Added Reviewed-by tags for patches {1,5}
> > 3. Added Tested-by tags from Xianglai Li
> > 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9]
> > Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-
> salil.mehta@huawei.com/
> >
> > Patch-set  V4 -> V5
> > 1. Addressed Gavin Shan's comments
> >     - Fixed the trace events print string for
> kvm_{create,get,park,destroy}_vcpu
> >     - Added Reviewed-by tag for patch {1}
> > 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
> > 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
> > 4. Dropped the ARM specific [Patch V4 10/10]
> > Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-
> salil.mehta@huawei.com/
> >
> > Patch-set  V3 -> V4
> > 1. Addressed David Hilderbrand's comments
> >     - Fixed the wrong doc comment of kvm_park_vcpu API prototype
> >     - Added Reviewed-by tags for patches {2,4}
> > Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-
> salil.mehta@huawei.com/
> >
> > Patch-set  V2 -> V3
> > 1. Addressed Jonathan Cameron's comments
> >     - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to
> 'integer'
> >     - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
> >     - Updated [Patch V2 3/10] commit-log with details of
> ACPI_CPU_SCAN_METHOD macro
> >     - Updated [Patch V2 5/10] commit-log with details of conditional
> event handler method
> >     - Added Reviewed-by tags for patches {2,3,4,6,7}
> > 2. Addressed Gavin Shan's comments
> >     - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
> >     - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
> >     - Reset the value of 'gdb_num_g_regs' in
> gdb_unregister_coprocessor_all
> >     - Fixed the kvm_{create,park}_vcpu prototypes docs
> >     - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
> > 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
> >     - Added traces instead of DPRINTF in the newly added and some
> existing functions
> > Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-
> salil.mehta@huawei.com/
> >
> > Patch-set V1 -> V2
> > 1. Addressed Alex Bennée's comments
> >     - Refactored the kvm_create_vcpu logic to get rid of goto
> >     - Added the docs for kvm_{create,park}_vcpu prototypes
> >     - Splitted the gdbstub and AddressSpace destruction change into
> separate patches
> >     - Added Reviewed-by tags for patches {2,10}
> > Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-
> salil.mehta@huawei.com/
> >
> > References:
> >
> > [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-
> salil.mehta@huawei.com/
> > [2] https://lore.kernel.org/all/20230913163823.7880-1-
> james.morse@arm.com/
> > [3] https://lore.kernel.org/qemu-
> devel/cover.1695697701.git.lixianglai@loongson.cn/
> >
> >
> > 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                    | 64 ++++++++++++++++++++------
> >   accel/kvm/trace-events                 |  4 ++
> >   gdbstub/gdbstub.c                      | 12 +++++
> >   hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
> >   hw/acpi/cpu.c                          | 27 +++++++----
> >   hw/acpi/generic_event_device.c         | 22 +++++++++
> >   hw/i386/acpi-build.c                   |  3 +-
> >   include/exec/cpu-common.h              |  8 ++++
> >   include/exec/gdbstub.h                 |  5 ++
> >   include/hw/acpi/cpu.h                  |  5 +-
> >   include/hw/acpi/cpu_hotplug.h          |  4 ++
> >   include/hw/acpi/generic_event_device.h |  5 ++
> >   include/hw/core/cpu.h                  |  1 +
> >   include/sysemu/kvm.h                   | 16 +++++++
> >   system/physmem.c                       | 29 ++++++++++++
> >   15 files changed, 184 insertions(+), 27 deletions(-)
> >
> 
> Hi salil,
> 
> All patches looks good to me. Thanks for you effort to update it so
> actively. No issues being found by simply testing and several daily use.
> 
> Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

Many thanks! Just wanted to confirm if you have tested this patch over
x86 platform as well?


Cheers
Salil.

^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-16 10:01     ` Miguel Luis
  2023-10-16 10:09       ` Salil Mehta via
@ 2023-10-19  9:50       ` Miguel Luis
  1 sibling, 0 replies; 47+ messages in thread
From: Miguel Luis @ 2023-10-19  9:50 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Marc Zyngier,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	Peter Maydell, Richard Henderson, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	Karl Heubaum, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm


> On 16 Oct 2023, at 10:01, Miguel Luis <miguel.luis@oracle.com> wrote:
> 
> Hi Salil,
> 
>> On 16 Oct 2023, at 09:52, Salil Mehta <salil.mehta@huawei.com> wrote:
>> 
>> Hi Miguel,
>> 
>>> From: Miguel Luis <miguel.luis@oracle.com>
>>> Sent: Friday, October 13, 2023 5:34 PM
>>> To: Salil Mehta <salil.mehta@huawei.com>
>>> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; Marc Zyngier
>>> <maz@kernel.org>; jean-philippe@linaro.org; Jonathan Cameron
>>> <jonathan.cameron@huawei.com>; lpieralisi@kernel.org; Peter Maydell
>>> <peter.maydell@linaro.org>; Richard Henderson
>>> <richard.henderson@linaro.org>; imammedo@redhat.com;
>>> andrew.jones@linux.dev; david@redhat.com; philmd@linaro.org;
>>> eric.auger@redhat.com; oliver.upton@linux.dev; pbonzini@redhat.com;
>>> mst@redhat.com; will@kernel.org; gshan@redhat.com; rafael@kernel.org;
>>> alex.bennee@linaro.org; linux@armlinux.org.uk;
>>> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
>>> vishnu@os.amperecomputing.com; Karl Heubaum <karl.heubaum@oracle.com>;
>>> salil.mehta@opnsrc.net; zhukeqian <zhukeqian1@huawei.com>; wangxiongfeng
>>> (C) <wangxiongfeng2@huawei.com>; wangyanan (Y) <wangyanan55@huawei.com>;
>>> jiakernel2@gmail.com; maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm
>>> <linuxarm@huawei.com>
>>> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
>>> Hotplug
>>> 
>>> Hi Salil,
>>> 
>>>> On 13 Oct 2023, at 10:51, Salil Mehta <salil.mehta@huawei.com> wrote:
>>>> 
>>>> Virtual CPU hotplug support is being added across various
>>> architectures[1][3].
>>>> This series adds various code bits common across all architectures:
>> 
>> 
>> [...]
>> 
>> 
>>> I tested it for Arm64, make check, boot/reboot, live migration and found no
>>> issues,
>>> so for this, please feel free to add:
>>> 
>>> Tested-by: Miguel Luis <miguel.luis@oracle.com>
>> 
>> Great. Many thanks for the confirmation. 
>> 
>> I guess you are repeating the same for x86 as well?
>> 
> 
> You are welcome!
> 
> Absolutely, I’m repeating those same tests for x86.
> 

Unfortunately, there's a qtest failing for x86.

The failing test is device-introspect-test in which the assert for mc->possible_cpu_arch_ids fails.

There’s also a suggestion to fix it here: https://lore.kernel.org/qemu-devel/15e70616-6abb-63a4-17d0-820f4a254607@opnsrc.net/T/#m108f102b2fe92b7dd7218f2f942f7b233a9d6af3

Thanks,
Miguel


> Thanks
> Miguel
> 
>> Salil.



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events
  2023-10-13 10:51 ` [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
@ 2023-10-19 10:16   ` Alex Bennée
  2023-10-19 10:27     ` Salil Mehta via
  2023-10-27 14:08   ` Igor Mammedov
  2 siblings, 1 reply; 47+ messages in thread
From: Alex Bennée @ 2023-10-19 10:16 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel, qemu-arm, maz, jean-philippe, jonathan.cameron,
	lpieralisi, peter.maydell, richard.henderson, imammedo,
	andrew.jones, david, philmd, eric.auger, oliver.upton, pbonzini,
	mst, will, gshan, rafael, linux, darren, ilkka, vishnu,
	karl.heubaum, miguel.luis, salil.mehta, zhukeqian1,
	wangxiongfeng2, wangyanan55, jiakernel2, maobibo, lixianglai,
	linuxarm


Salil Mehta <salil.mehta@huawei.com> writes:

> 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 _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.

Should we also update the docs here:

  https://qemu.readthedocs.io/en/master/specs/acpi_hw_reduced_hotplug.html

(see docs/specs/acpi_hw_reduced_hotplug.rst)

to add the new bits? Or maybe an update to documentation as the last
commit?

>
> Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Reviewed-by: Gavin Shan <gshan@redhat.com>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> Tested-by: Xianglai Li <lixianglai@loongson.cn>
> ---
>  hw/acpi/generic_event_device.c         | 8 ++++++++
>  include/hw/acpi/generic_event_device.h | 5 +++++
>  2 files changed, 13 insertions(+)
>
> diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> index a3d31631fe..d2fa1d0e4a 100644
> --- a/hw/acpi/generic_event_device.c
> +++ b/hw/acpi/generic_event_device.c
> @@ -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)
> diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h
> index ba84ce0214..a803ea818e 100644
> --- a/include/hw/acpi/generic_event_device.h
> +++ b/include/hw/acpi/generic_event_device.h
> @@ -60,6 +60,7 @@
>  #define HW_ACPI_GENERIC_EVENT_DEVICE_H
>  
>  #include "hw/sysbus.h"
> +#include "hw/acpi/cpu_hotplug.h"
>  #include "hw/acpi/memory_hotplug.h"
>  #include "hw/acpi/ghes.h"
>  #include "qom/object.h"
> @@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
>  #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
>  #define ACPI_GED_PWR_DOWN_EVT      0x2
>  #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
> +#define ACPI_GED_CPU_HOTPLUG_EVT    0x8
>  
>  typedef struct GEDState {
>      MemoryRegion evt;
> @@ -106,6 +108,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;


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events
  2023-10-19 10:16   ` Alex Bennée
@ 2023-10-19 10:27     ` Salil Mehta via
  2023-10-19 10:27       ` Salil Mehta
  0 siblings, 1 reply; 47+ messages in thread
From: Salil Mehta via @ 2023-10-19 10:27 UTC (permalink / raw)
  To: Alex Bennée
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	imammedo@redhat.com, andrew.jones@linux.dev, david@redhat.com,
	philmd@linaro.org, eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, linux@armlinux.org.uk,
	darren@os.amperecomputing.com, ilkka@os.amperecomputing.com,
	vishnu@os.amperecomputing.com, karl.heubaum@oracle.com,
	miguel.luis@oracle.com, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

Hi Alex,

> From: Alex Bennée <alex.bennee@linaro.org>
> Sent: Thursday, October 19, 2023 11:16 AM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; maz@kernel.org; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>;
> lpieralisi@kernel.org; peter.maydell@linaro.org;
> richard.henderson@linaro.org; imammedo@redhat.com; andrew.jones@linux.dev;
> david@redhat.com; philmd@linaro.org; eric.auger@redhat.com;
> oliver.upton@linux.dev; pbonzini@redhat.com; mst@redhat.com;
> will@kernel.org; gshan@redhat.com; rafael@kernel.org;
> linux@armlinux.org.uk; darren@os.amperecomputing.com;
> ilkka@os.amperecomputing.com; vishnu@os.amperecomputing.com;
> karl.heubaum@oracle.com; miguel.luis@oracle.com; salil.mehta@opnsrc.net;
> zhukeqian <zhukeqian1@huawei.com>; wangxiongfeng (C)
> <wangxiongfeng2@huawei.com>; wangyanan (Y) <wangyanan55@huawei.com>;
> jiakernel2@gmail.com; maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm
> <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug
> events
> 
> 
> Salil Mehta <salil.mehta@huawei.com> writes:
> 
> > 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 _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.
> 
> Should we also update the docs here:
> 
>   https://qemu.readthedocs.io/en/master/specs/acpi_hw_reduced_hotplug.html
> 
> (see docs/specs/acpi_hw_reduced_hotplug.rst)


Good point. Will do.


> to add the new bits? Or maybe an update to documentation as the last
> commit?

Will add one more patch at the last for this documentation change.

Thanks for identifying this.

Cheers
Salil.


> 
> >
> > Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Reviewed-by: Gavin Shan <gshan@redhat.com>
> > Reviewed-by: David Hildenbrand <david@redhat.com>
> > Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> > Tested-by: Xianglai Li <lixianglai@loongson.cn>
> > ---
> >  hw/acpi/generic_event_device.c         | 8 ++++++++
> >  include/hw/acpi/generic_event_device.h | 5 +++++
> >  2 files changed, 13 insertions(+)
> >
> > diff --git a/hw/acpi/generic_event_device.c
> b/hw/acpi/generic_event_device.c
> > index a3d31631fe..d2fa1d0e4a 100644
> > --- a/hw/acpi/generic_event_device.c
> > +++ b/hw/acpi/generic_event_device.c
> > @@ -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)
> > diff --git a/include/hw/acpi/generic_event_device.h
> b/include/hw/acpi/generic_event_device.h
> > index ba84ce0214..a803ea818e 100644
> > --- a/include/hw/acpi/generic_event_device.h
> > +++ b/include/hw/acpi/generic_event_device.h
> > @@ -60,6 +60,7 @@
> >  #define HW_ACPI_GENERIC_EVENT_DEVICE_H
> >
> >  #include "hw/sysbus.h"
> > +#include "hw/acpi/cpu_hotplug.h"
> >  #include "hw/acpi/memory_hotplug.h"
> >  #include "hw/acpi/ghes.h"
> >  #include "qom/object.h"
> > @@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
> >  #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
> >  #define ACPI_GED_PWR_DOWN_EVT      0x2
> >  #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
> > +#define ACPI_GED_CPU_HOTPLUG_EVT    0x8
> >
> >  typedef struct GEDState {
> >      MemoryRegion evt;
> > @@ -106,6 +108,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;
> 
> 
> --
> Alex Bennée
> Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events
  2023-10-19 10:27     ` Salil Mehta via
@ 2023-10-19 10:27       ` Salil Mehta
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-19 10:27 UTC (permalink / raw)
  To: Alex Bennée
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	imammedo@redhat.com, andrew.jones@linux.dev, david@redhat.com,
	philmd@linaro.org, eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, linux@armlinux.org.uk,
	darren@os.amperecomputing.com, ilkka@os.amperecomputing.com,
	vishnu@os.amperecomputing.com, karl.heubaum@oracle.com,
	miguel.luis@oracle.com, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

Hi Alex,

> From: Alex Bennée <alex.bennee@linaro.org>
> Sent: Thursday, October 19, 2023 11:16 AM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; maz@kernel.org; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>;
> lpieralisi@kernel.org; peter.maydell@linaro.org;
> richard.henderson@linaro.org; imammedo@redhat.com; andrew.jones@linux.dev;
> david@redhat.com; philmd@linaro.org; eric.auger@redhat.com;
> oliver.upton@linux.dev; pbonzini@redhat.com; mst@redhat.com;
> will@kernel.org; gshan@redhat.com; rafael@kernel.org;
> linux@armlinux.org.uk; darren@os.amperecomputing.com;
> ilkka@os.amperecomputing.com; vishnu@os.amperecomputing.com;
> karl.heubaum@oracle.com; miguel.luis@oracle.com; salil.mehta@opnsrc.net;
> zhukeqian <zhukeqian1@huawei.com>; wangxiongfeng (C)
> <wangxiongfeng2@huawei.com>; wangyanan (Y) <wangyanan55@huawei.com>;
> jiakernel2@gmail.com; maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm
> <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug
> events
> 
> 
> Salil Mehta <salil.mehta@huawei.com> writes:
> 
> > 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 _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.
> 
> Should we also update the docs here:
> 
>   https://qemu.readthedocs.io/en/master/specs/acpi_hw_reduced_hotplug.html
> 
> (see docs/specs/acpi_hw_reduced_hotplug.rst)


Good point. Will do.


> to add the new bits? Or maybe an update to documentation as the last
> commit?

Will add one more patch at the last for this documentation change.

Thanks for identifying this.

Cheers
Salil.


> 
> >
> > Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Reviewed-by: Gavin Shan <gshan@redhat.com>
> > Reviewed-by: David Hildenbrand <david@redhat.com>
> > Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> > Tested-by: Xianglai Li <lixianglai@loongson.cn>
> > ---
> >  hw/acpi/generic_event_device.c         | 8 ++++++++
> >  include/hw/acpi/generic_event_device.h | 5 +++++
> >  2 files changed, 13 insertions(+)
> >
> > diff --git a/hw/acpi/generic_event_device.c
> b/hw/acpi/generic_event_device.c
> > index a3d31631fe..d2fa1d0e4a 100644
> > --- a/hw/acpi/generic_event_device.c
> > +++ b/hw/acpi/generic_event_device.c
> > @@ -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)
> > diff --git a/include/hw/acpi/generic_event_device.h
> b/include/hw/acpi/generic_event_device.h
> > index ba84ce0214..a803ea818e 100644
> > --- a/include/hw/acpi/generic_event_device.h
> > +++ b/include/hw/acpi/generic_event_device.h
> > @@ -60,6 +60,7 @@
> >  #define HW_ACPI_GENERIC_EVENT_DEVICE_H
> >
> >  #include "hw/sysbus.h"
> > +#include "hw/acpi/cpu_hotplug.h"
> >  #include "hw/acpi/memory_hotplug.h"
> >  #include "hw/acpi/ghes.h"
> >  #include "qom/object.h"
> > @@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
> >  #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
> >  #define ACPI_GED_PWR_DOWN_EVT      0x2
> >  #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
> > +#define ACPI_GED_CPU_HOTPLUG_EVT    0x8
> >
> >  typedef struct GEDState {
> >      MemoryRegion evt;
> > @@ -106,6 +108,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;
> 
> 
> --
> Alex Bennée
> Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-19  9:34   ` Salil Mehta via
  2023-10-19  9:34     ` Salil Mehta
@ 2023-10-20  3:30     ` Shaoqin Huang
  1 sibling, 0 replies; 47+ messages in thread
From: Shaoqin Huang @ 2023-10-20  3:30 UTC (permalink / raw)
  To: Salil Mehta, qemu-devel@nongnu.org, qemu-arm@nongnu.org
  Cc: maz@kernel.org, jean-philippe@linaro.org, Jonathan Cameron,
	lpieralisi@kernel.org, peter.maydell@linaro.org,
	richard.henderson@linaro.org, imammedo@redhat.com,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm



On 10/19/23 17:34, Salil Mehta wrote:
> Hi Shaoqin,
> 
>> From: Shaoqin Huang <shahuang@redhat.com>
>> Sent: Thursday, October 19, 2023 10:05 AM
>> To: Salil Mehta <salil.mehta@huawei.com>; qemu-devel@nongnu.org; qemu-
>> arm@nongnu.org
>> Cc: maz@kernel.org; jean-philippe@linaro.org; Jonathan Cameron
>> <jonathan.cameron@huawei.com>; lpieralisi@kernel.org;
>> peter.maydell@linaro.org; richard.henderson@linaro.org;
>> imammedo@redhat.com; andrew.jones@linux.dev; david@redhat.com;
>> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
>> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
>> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
>> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
>> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
>> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
>> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
>> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
>> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
>> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
>> Hotplug
>>
>>
>>
>> On 10/13/23 18:51, Salil Mehta via wrote:
>>> Virtual CPU hotplug support is being added across various
>> architectures[1][3].
>>> This series adds various code bits common across all architectures:
>>>
>>> 1. vCPU creation and Parking code refactor [Patch 1]
>>> 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
>>> 3. ACPI CPUs AML code change [Patch 5]
>>> 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
>>> 5. Misc [Patch 2,3]
>>>
>>>
>>> Repository:
>>>
>>> [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-
>> v2.common.v6
>>>
>>>
>>> Revision History:
>>>
>>> Patch-set  V5 -> V6
>>> 1. Addressed Gavin Shan's comments
>>>      - Fixed the assert() ranges of address spaces
>>>      - Rebased the patch-set to latest changes in the qemu.git
>>>      - Added Reviewed-by tags for patches {8,9}
>>> 2. Addressed Jonathan Cameron's comments
>>>      - Updated commit-log for [Patch V5 1/9] with mention of trace events
>>>      - Added Reviewed-by tags for patches {1,5}
>>> 3. Added Tested-by tags from Xianglai Li
>>> 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9]
>>> Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-
>> salil.mehta@huawei.com/
>>>
>>> Patch-set  V4 -> V5
>>> 1. Addressed Gavin Shan's comments
>>>      - Fixed the trace events print string for
>> kvm_{create,get,park,destroy}_vcpu
>>>      - Added Reviewed-by tag for patch {1}
>>> 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
>>> 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
>>> 4. Dropped the ARM specific [Patch V4 10/10]
>>> Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-
>> salil.mehta@huawei.com/
>>>
>>> Patch-set  V3 -> V4
>>> 1. Addressed David Hilderbrand's comments
>>>      - Fixed the wrong doc comment of kvm_park_vcpu API prototype
>>>      - Added Reviewed-by tags for patches {2,4}
>>> Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-
>> salil.mehta@huawei.com/
>>>
>>> Patch-set  V2 -> V3
>>> 1. Addressed Jonathan Cameron's comments
>>>      - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to
>> 'integer'
>>>      - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
>>>      - Updated [Patch V2 3/10] commit-log with details of
>> ACPI_CPU_SCAN_METHOD macro
>>>      - Updated [Patch V2 5/10] commit-log with details of conditional
>> event handler method
>>>      - Added Reviewed-by tags for patches {2,3,4,6,7}
>>> 2. Addressed Gavin Shan's comments
>>>      - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
>>>      - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
>>>      - Reset the value of 'gdb_num_g_regs' in
>> gdb_unregister_coprocessor_all
>>>      - Fixed the kvm_{create,park}_vcpu prototypes docs
>>>      - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
>>> 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
>>>      - Added traces instead of DPRINTF in the newly added and some
>> existing functions
>>> Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-
>> salil.mehta@huawei.com/
>>>
>>> Patch-set V1 -> V2
>>> 1. Addressed Alex Bennée's comments
>>>      - Refactored the kvm_create_vcpu logic to get rid of goto
>>>      - Added the docs for kvm_{create,park}_vcpu prototypes
>>>      - Splitted the gdbstub and AddressSpace destruction change into
>> separate patches
>>>      - Added Reviewed-by tags for patches {2,10}
>>> Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-
>> salil.mehta@huawei.com/
>>>
>>> References:
>>>
>>> [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-
>> salil.mehta@huawei.com/
>>> [2] https://lore.kernel.org/all/20230913163823.7880-1-
>> james.morse@arm.com/
>>> [3] https://lore.kernel.org/qemu-
>> devel/cover.1695697701.git.lixianglai@loongson.cn/
>>>
>>>
>>> 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                    | 64 ++++++++++++++++++++------
>>>    accel/kvm/trace-events                 |  4 ++
>>>    gdbstub/gdbstub.c                      | 12 +++++
>>>    hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
>>>    hw/acpi/cpu.c                          | 27 +++++++----
>>>    hw/acpi/generic_event_device.c         | 22 +++++++++
>>>    hw/i386/acpi-build.c                   |  3 +-
>>>    include/exec/cpu-common.h              |  8 ++++
>>>    include/exec/gdbstub.h                 |  5 ++
>>>    include/hw/acpi/cpu.h                  |  5 +-
>>>    include/hw/acpi/cpu_hotplug.h          |  4 ++
>>>    include/hw/acpi/generic_event_device.h |  5 ++
>>>    include/hw/core/cpu.h                  |  1 +
>>>    include/sysemu/kvm.h                   | 16 +++++++
>>>    system/physmem.c                       | 29 ++++++++++++
>>>    15 files changed, 184 insertions(+), 27 deletions(-)
>>>
>>
>> Hi salil,
>>
>> All patches looks good to me. Thanks for you effort to update it so
>> actively. No issues being found by simply testing and several daily use.
>>
>> Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
> 
> Many thanks! Just wanted to confirm if you have tested this patch over
> x86 platform as well?

Hi Salil,

I used it on Ampere One Machine, so didn't test it on x86 platform.

Thanks,
Shaoqin

> 
> 
> Cheers
> Salil.

-- 
Shaoqin



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
                   ` (11 preceding siblings ...)
  2023-10-19  9:04 ` Shaoqin Huang
@ 2023-10-26 12:41 ` Igor Mammedov
  2023-10-27 10:23   ` Salil Mehta via
  12 siblings, 1 reply; 47+ messages in thread
From: Igor Mammedov @ 2023-10-26 12:41 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel, qemu-arm, maz, jean-philippe, jonathan.cameron,
	lpieralisi, peter.maydell, richard.henderson, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

On Fri, 13 Oct 2023 11:51:20 +0100
Salil Mehta <salil.mehta@huawei.com> wrote:

> Virtual CPU hotplug support is being added across various architectures[1][3].
> This series adds various code bits common across all architectures:
> 
> 1. vCPU creation and Parking code refactor [Patch 1]
> 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
> 3. ACPI CPUs AML code change [Patch 5]
> 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
> 5. Misc [Patch 2,3]

Thanks Salil!

Overall series looks good to me (modulo some points, I'd like to be addressed)
I'll do some testing and follow with per patch review tomorrow. 

> Repository:
> 
> [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v6
> 
> 
> Revision History:
> 
> Patch-set  V5 -> V6
> 1. Addressed Gavin Shan's comments
>    - Fixed the assert() ranges of address spaces
>    - Rebased the patch-set to latest changes in the qemu.git
>    - Added Reviewed-by tags for patches {8,9}
> 2. Addressed Jonathan Cameron's comments
>    - Updated commit-log for [Patch V5 1/9] with mention of trace events
>    - Added Reviewed-by tags for patches {1,5}
> 3. Added Tested-by tags from Xianglai Li
> 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9] 
> Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-salil.mehta@huawei.com/
> 
> Patch-set  V4 -> V5
> 1. Addressed Gavin Shan's comments
>    - Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
>    - Added Reviewed-by tag for patch {1}
> 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
> 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
> 4. Dropped the ARM specific [Patch V4 10/10]
> Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-salil.mehta@huawei.com/
> 
> Patch-set  V3 -> V4
> 1. Addressed David Hilderbrand's comments
>    - Fixed the wrong doc comment of kvm_park_vcpu API prototype
>    - Added Reviewed-by tags for patches {2,4}
> Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-salil.mehta@huawei.com/
> 
> Patch-set  V2 -> V3
> 1. Addressed Jonathan Cameron's comments
>    - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
>    - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
>    - Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
>    - Updated [Patch V2 5/10] commit-log with details of conditional event handler method
>    - Added Reviewed-by tags for patches {2,3,4,6,7}
> 2. Addressed Gavin Shan's comments
>    - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
>    - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
>    - Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
>    - Fixed the kvm_{create,park}_vcpu prototypes docs
>    - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
> 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
>    - Added traces instead of DPRINTF in the newly added and some existing functions
> Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1-salil.mehta@huawei.com/
> 
> Patch-set V1 -> V2
> 1. Addressed Alex Bennée's comments
>    - Refactored the kvm_create_vcpu logic to get rid of goto
>    - Added the docs for kvm_{create,park}_vcpu prototypes
>    - Splitted the gdbstub and AddressSpace destruction change into separate patches
>    - Added Reviewed-by tags for patches {2,10}
> Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-salil.mehta@huawei.com/
> 
> References:
> 
> [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-salil.mehta@huawei.com/
> [2] https://lore.kernel.org/all/20230913163823.7880-1-james.morse@arm.com/
> [3] https://lore.kernel.org/qemu-devel/cover.1695697701.git.lixianglai@loongson.cn/
> 
> 
> 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                    | 64 ++++++++++++++++++++------
>  accel/kvm/trace-events                 |  4 ++
>  gdbstub/gdbstub.c                      | 12 +++++
>  hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
>  hw/acpi/cpu.c                          | 27 +++++++----
>  hw/acpi/generic_event_device.c         | 22 +++++++++
>  hw/i386/acpi-build.c                   |  3 +-
>  include/exec/cpu-common.h              |  8 ++++
>  include/exec/gdbstub.h                 |  5 ++
>  include/hw/acpi/cpu.h                  |  5 +-
>  include/hw/acpi/cpu_hotplug.h          |  4 ++
>  include/hw/acpi/generic_event_device.h |  5 ++
>  include/hw/core/cpu.h                  |  1 +
>  include/sysemu/kvm.h                   | 16 +++++++
>  system/physmem.c                       | 29 ++++++++++++
>  15 files changed, 184 insertions(+), 27 deletions(-)
> 



^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-26 12:41 ` Igor Mammedov
@ 2023-10-27 10:23   ` Salil Mehta via
  2023-10-27 10:23     ` Salil Mehta
  0 siblings, 1 reply; 47+ messages in thread
From: Salil Mehta via @ 2023-10-27 10:23 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Igor,

> From: Igor Mammedov <imammedo@redhat.com>
> Sent: Thursday, October 26, 2023 1:41 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; maz@kernel.org; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>;
> lpieralisi@kernel.org; peter.maydell@linaro.org;
> richard.henderson@linaro.org; andrew.jones@linux.dev; david@redhat.com;
> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> Hotplug
> 
> On Fri, 13 Oct 2023 11:51:20 +0100
> Salil Mehta <salil.mehta@huawei.com> wrote:
> 
> > Virtual CPU hotplug support is being added across various
> architectures[1][3].
> > This series adds various code bits common across all architectures:
> >
> > 1. vCPU creation and Parking code refactor [Patch 1]
> > 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
> > 3. ACPI CPUs AML code change [Patch 5]
> > 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
> > 5. Misc [Patch 2,3]
> 
> Thanks Salil!
> 
> Overall series looks good to me (modulo some points, I'd like to be addressed)
> I'll do some testing and follow with per patch review tomorrow.

Many thanks! that would be helpful.

Meanwhile, I am preparing the V7 version of this to address the x86/microvm
qtest break reported by Miguel.

https://lore.kernel.org/qemu-devel/51B6C120-3707-4730-AE14-0F5CD32DC984@oracle.com/


Solution suggested here:
https://lore.kernel.org/qemu-devel/15e70616-6abb-63a4-17d0-820f4a254607@opnsrc.net/T/#m108f102b2fe92b7dd7218f2f942f7b233a9d6af3


cheers
Salil.


> > Repository:
> >
> > [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v6
> >
> >
> > Revision History:
> >
> > Patch-set  V5 -> V6
> > 1. Addressed Gavin Shan's comments
> >    - Fixed the assert() ranges of address spaces
> >    - Rebased the patch-set to latest changes in the qemu.git
> >    - Added Reviewed-by tags for patches {8,9}
> > 2. Addressed Jonathan Cameron's comments
> >    - Updated commit-log for [Patch V5 1/9] with mention of trace events
> >    - Added Reviewed-by tags for patches {1,5}
> > 3. Added Tested-by tags from Xianglai Li
> > 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9]
> > Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-salil.mehta@huawei.com/
> >
> > Patch-set  V4 -> V5
> > 1. Addressed Gavin Shan's comments
> >    - Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
> >    - Added Reviewed-by tag for patch {1}
> > 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
> > 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
> > 4. Dropped the ARM specific [Patch V4 10/10]
> > Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-salil.mehta@huawei.com/
> >
> > Patch-set  V3 -> V4
> > 1. Addressed David Hilderbrand's comments
> >    - Fixed the wrong doc comment of kvm_park_vcpu API prototype
> >    - Added Reviewed-by tags for patches {2,4}
> > Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-salil.mehta@huawei.com/
> >
> > Patch-set  V2 -> V3
> > 1. Addressed Jonathan Cameron's comments
> >    - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
> >    - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
> >    - Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
> >    - Updated [Patch V2 5/10] commit-log with details of conditional event handler method
> >    - Added Reviewed-by tags for patches {2,3,4,6,7}
> > 2. Addressed Gavin Shan's comments
> >    - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
> >    - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
> >    - Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
> >    - Fixed the kvm_{create,park}_vcpu prototypes docs
> >    - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
> > 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
> >    - Added traces instead of DPRINTF in the newly added and some existing functions
> > Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1- salil.mehta@huawei.com/
> >
> > Patch-set V1 -> V2
> > 1. Addressed Alex Bennée's comments
> >    - Refactored the kvm_create_vcpu logic to get rid of goto
> >    - Added the docs for kvm_{create,park}_vcpu prototypes
> >    - Splitted the gdbstub and AddressSpace destruction change into separate patches
> >    - Added Reviewed-by tags for patches {2,10}
> > Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-salil.mehta@huawei.com/
> >
> > References:
> >
> > [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-salil.mehta@huawei.com/
> > [2] https://lore.kernel.org/all/20230913163823.7880-1-james.morse@arm.com/
> > [3] https://lore.kernel.org/qemu-devel/cover.1695697701.git.lixianglai@loongson.cn/
> >
> >
> > 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                    | 64 ++++++++++++++++++++------
> >  accel/kvm/trace-events                 |  4 ++
> >  gdbstub/gdbstub.c                      | 12 +++++
> >  hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
> >  hw/acpi/cpu.c                          | 27 +++++++----
> >  hw/acpi/generic_event_device.c         | 22 +++++++++
> >  hw/i386/acpi-build.c                   |  3 +-
> >  include/exec/cpu-common.h              |  8 ++++
> >  include/exec/gdbstub.h                 |  5 ++
> >  include/hw/acpi/cpu.h                  |  5 +-
> >  include/hw/acpi/cpu_hotplug.h          |  4 ++
> >  include/hw/acpi/generic_event_device.h |  5 ++
> >  include/hw/core/cpu.h                  |  1 +
> >  include/sysemu/kvm.h                   | 16 +++++++
> >  system/physmem.c                       | 29 ++++++++++++
> >  15 files changed, 184 insertions(+), 27 deletions(-)
> >


^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug
  2023-10-27 10:23   ` Salil Mehta via
@ 2023-10-27 10:23     ` Salil Mehta
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta @ 2023-10-27 10:23 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Igor,

> From: Igor Mammedov <imammedo@redhat.com>
> Sent: Thursday, October 26, 2023 1:41 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; maz@kernel.org; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>;
> lpieralisi@kernel.org; peter.maydell@linaro.org;
> richard.henderson@linaro.org; andrew.jones@linux.dev; david@redhat.com;
> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 0/9] Add architecture agnostic code to support vCPU
> Hotplug
> 
> On Fri, 13 Oct 2023 11:51:20 +0100
> Salil Mehta <salil.mehta@huawei.com> wrote:
> 
> > Virtual CPU hotplug support is being added across various
> architectures[1][3].
> > This series adds various code bits common across all architectures:
> >
> > 1. vCPU creation and Parking code refactor [Patch 1]
> > 2. Update ACPI GED framework to support vCPU Hotplug [Patch 4,6,7]
> > 3. ACPI CPUs AML code change [Patch 5]
> > 4. Helper functions to support unrealization of CPU objects [Patch 8,9]
> > 5. Misc [Patch 2,3]
> 
> Thanks Salil!
> 
> Overall series looks good to me (modulo some points, I'd like to be addressed)
> I'll do some testing and follow with per patch review tomorrow.

Many thanks! that would be helpful.

Meanwhile, I am preparing the V7 version of this to address the x86/microvm
qtest break reported by Miguel.

https://lore.kernel.org/qemu-devel/51B6C120-3707-4730-AE14-0F5CD32DC984@oracle.com/


Solution suggested here:
https://lore.kernel.org/qemu-devel/15e70616-6abb-63a4-17d0-820f4a254607@opnsrc.net/T/#m108f102b2fe92b7dd7218f2f942f7b233a9d6af3


cheers
Salil.


> > Repository:
> >
> > [*] https://github.com/salil-mehta/qemu.git virt-cpuhp-armv8/rfc-v2.common.v6
> >
> >
> > Revision History:
> >
> > Patch-set  V5 -> V6
> > 1. Addressed Gavin Shan's comments
> >    - Fixed the assert() ranges of address spaces
> >    - Rebased the patch-set to latest changes in the qemu.git
> >    - Added Reviewed-by tags for patches {8,9}
> > 2. Addressed Jonathan Cameron's comments
> >    - Updated commit-log for [Patch V5 1/9] with mention of trace events
> >    - Added Reviewed-by tags for patches {1,5}
> > 3. Added Tested-by tags from Xianglai Li
> > 4. Fixed checkpatch.pl error "Qemu -> QEMU" in [Patch V5 1/9]
> > Link: https://lore.kernel.org/qemu-devel/20231011194355.15628-1-salil.mehta@huawei.com/
> >
> > Patch-set  V4 -> V5
> > 1. Addressed Gavin Shan's comments
> >    - Fixed the trace events print string for kvm_{create,get,park,destroy}_vcpu
> >    - Added Reviewed-by tag for patch {1}
> > 2. Added Shaoqin Huang's Reviewed-by tags for Patches {2,3}
> > 3. Added Tested-by Tag from Vishnu Pajjuri to the patch-set
> > 4. Dropped the ARM specific [Patch V4 10/10]
> > Link: https://lore.kernel.org/qemu-devel/20231009203601.17584-1-salil.mehta@huawei.com/
> >
> > Patch-set  V3 -> V4
> > 1. Addressed David Hilderbrand's comments
> >    - Fixed the wrong doc comment of kvm_park_vcpu API prototype
> >    - Added Reviewed-by tags for patches {2,4}
> > Link: https://lore.kernel.org/qemu-devel/20231009112812.10612-1-salil.mehta@huawei.com/
> >
> > Patch-set  V2 -> V3
> > 1. Addressed Jonathan Cameron's comments
> >    - Fixed 'vcpu-id' type wrongly changed from 'unsigned long' to 'integer'
> >    - Removed unnecessary use of variable 'vcpu_id' in kvm_park_vcpu
> >    - Updated [Patch V2 3/10] commit-log with details of ACPI_CPU_SCAN_METHOD macro
> >    - Updated [Patch V2 5/10] commit-log with details of conditional event handler method
> >    - Added Reviewed-by tags for patches {2,3,4,6,7}
> > 2. Addressed Gavin Shan's comments
> >    - Remove unnecessary use of variable 'vcpu_id' in kvm_par_vcpu
> >    - Fixed return value in kvm_get_vcpu from -1 to -ENOENT
> >    - Reset the value of 'gdb_num_g_regs' in gdb_unregister_coprocessor_all
> >    - Fixed the kvm_{create,park}_vcpu prototypes docs
> >    - Added Reviewed-by tags for patches {2,3,4,5,6,7,9,10}
> > 3. Addressed one earlier missed comment by Alex Bennée in RFC V1
> >    - Added traces instead of DPRINTF in the newly added and some existing functions
> > Link: https://lore.kernel.org/qemu-devel/20230930001933.2660-1- salil.mehta@huawei.com/
> >
> > Patch-set V1 -> V2
> > 1. Addressed Alex Bennée's comments
> >    - Refactored the kvm_create_vcpu logic to get rid of goto
> >    - Added the docs for kvm_{create,park}_vcpu prototypes
> >    - Splitted the gdbstub and AddressSpace destruction change into separate patches
> >    - Added Reviewed-by tags for patches {2,10}
> > Link: https://lore.kernel.org/qemu-devel/20230929124304.13672-1-salil.mehta@huawei.com/
> >
> > References:
> >
> > [1] https://lore.kernel.org/qemu-devel/20230926100436.28284-1-salil.mehta@huawei.com/
> > [2] https://lore.kernel.org/all/20230913163823.7880-1-james.morse@arm.com/
> > [3] https://lore.kernel.org/qemu-devel/cover.1695697701.git.lixianglai@loongson.cn/
> >
> >
> > 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                    | 64 ++++++++++++++++++++------
> >  accel/kvm/trace-events                 |  4 ++
> >  gdbstub/gdbstub.c                      | 12 +++++
> >  hw/acpi/acpi-cpu-hotplug-stub.c        |  6 +++
> >  hw/acpi/cpu.c                          | 27 +++++++----
> >  hw/acpi/generic_event_device.c         | 22 +++++++++
> >  hw/i386/acpi-build.c                   |  3 +-
> >  include/exec/cpu-common.h              |  8 ++++
> >  include/exec/gdbstub.h                 |  5 ++
> >  include/hw/acpi/cpu.h                  |  5 +-
> >  include/hw/acpi/cpu_hotplug.h          |  4 ++
> >  include/hw/acpi/generic_event_device.h |  5 ++
> >  include/hw/core/cpu.h                  |  1 +
> >  include/sysemu/kvm.h                   | 16 +++++++
> >  system/physmem.c                       | 29 ++++++++++++
> >  15 files changed, 184 insertions(+), 27 deletions(-)
> >


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation,parking} code
  2023-10-13 10:51 ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation, parking} code Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
@ 2023-10-27 12:56   ` Igor Mammedov
  2023-11-06 14:37     ` Salil Mehta via
  1 sibling, 1 reply; 47+ messages in thread
From: Igor Mammedov @ 2023-10-27 12:56 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel, qemu-arm, maz, jean-philippe, jonathan.cameron,
	lpieralisi, peter.maydell, richard.henderson, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

On Fri, 13 Oct 2023 11:51:21 +0100
Salil Mehta <salil.mehta@huawei.com> wrote:

> KVM vCPU creation is done once during the initialization of the VM when Qemu
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> thread is spawned. This is common to all the architectures.

is it really true fox x86?

> 
> Hot-unplug of vCPU results in destruction of the vCPU object in QOM but the
> corresponding KVM vCPU object in the Host KVM is not destroyed and its
                                                                ^
since KVM doesn't support vCPU removal

> representative KVM vCPU object/context in Qemu is parked.
> 
> Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
'reused' part doesn't happen within this series. So a reason
why patch exists is not clear/no one can deduce the reason
without the actual user here.

Suggest to move it to a series that actually will use this patch.


> Update new/old APIs with trace events instead of DTRACE.
> 
> Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> Reviewed-by: Gavin Shan <gshan@redhat.com>
> Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Tested-by: Xianglai Li <lixianglai@loongson.cn>
> ---
>  accel/kvm/kvm-all.c    | 64 ++++++++++++++++++++++++++++++++----------
>  accel/kvm/trace-events |  4 +++
>  include/sysemu/kvm.h   | 16 +++++++++++
>  3 files changed, 69 insertions(+), 15 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 72e1d1141c..bfa7816aaa 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -137,6 +137,7 @@ static QemuMutex kml_slots_lock;
>  #define kvm_slots_unlock()  qemu_mutex_unlock(&kml_slots_lock)
>  
>  static void kvm_slot_init_dirty_bitmap(KVMSlot *mem);
> +static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id);
>  
>  static inline void kvm_resample_fd_remove(int gsi)
>  {
> @@ -320,14 +321,53 @@ err:
>      return ret;
>  }
>  
> +void kvm_park_vcpu(CPUState *cpu)
> +{
> +    struct KVMParkedVcpu *vcpu;
> +
> +    trace_kvm_park_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
> +
> +    vcpu = g_malloc0(sizeof(*vcpu));
> +    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
> +    vcpu->kvm_fd = cpu->kvm_fd;
> +    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
> +}
> +
> +int kvm_create_vcpu(CPUState *cpu)
> +{
> +    unsigned long vcpu_id = kvm_arch_vcpu_id(cpu);
> +    KVMState *s = kvm_state;
> +    int kvm_fd;
> +
> +    trace_kvm_create_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
> +
> +    /* check if the KVM vCPU already exist but is parked */
> +    kvm_fd = kvm_get_vcpu(s, vcpu_id);
> +    if (kvm_fd < 0) {
> +        /* vCPU not parked: create a new KVM vCPU */
> +        kvm_fd = kvm_vm_ioctl(s, KVM_CREATE_VCPU, vcpu_id);
> +        if (kvm_fd < 0) {
> +            error_report("KVM_CREATE_VCPU IOCTL failed for vCPU %lu", vcpu_id);
> +            return kvm_fd;
> +        }
> +    }
> +
> +    cpu->kvm_fd = kvm_fd;
> +    cpu->kvm_state = s;
> +    cpu->vcpu_dirty = true;
> +    cpu->dirty_pages = 0;
> +    cpu->throttle_us_per_full = 0;
> +
> +    return 0;
> +}
> +
>  static int do_kvm_destroy_vcpu(CPUState *cpu)
>  {
>      KVMState *s = kvm_state;
>      long mmap_size;
> -    struct KVMParkedVcpu *vcpu = NULL;
>      int ret = 0;
>  
> -    DPRINTF("kvm_destroy_vcpu\n");
> +    trace_kvm_destroy_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
>  
>      ret = kvm_arch_destroy_vcpu(cpu);
>      if (ret < 0) {
> @@ -353,10 +393,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
>          }
>      }
>  
> -    vcpu = g_malloc0(sizeof(*vcpu));
> -    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
> -    vcpu->kvm_fd = cpu->kvm_fd;
> -    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
> +    kvm_park_vcpu(cpu);
>  err:
>      return ret;
>  }
> @@ -377,6 +414,8 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
>          if (cpu->vcpu_id == vcpu_id) {
>              int kvm_fd;
>  
> +            trace_kvm_get_vcpu(vcpu_id);
> +
>              QLIST_REMOVE(cpu, node);
>              kvm_fd = cpu->kvm_fd;
>              g_free(cpu);
> @@ -384,7 +423,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id)
>          }
>      }
>  
> -    return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id);
> +    return -ENOENT;
>  }
>  
>  int kvm_init_vcpu(CPUState *cpu, Error **errp)
> @@ -395,19 +434,14 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
>  
>      trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
>  
> -    ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
> +    ret = kvm_create_vcpu(cpu);
>      if (ret < 0) {
> -        error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed (%lu)",
> +        error_setg_errno(errp, -ret,
> +                         "kvm_init_vcpu: kvm_create_vcpu failed (%lu)",
>                           kvm_arch_vcpu_id(cpu));
>          goto err;
>      }
>  
> -    cpu->kvm_fd = ret;
> -    cpu->kvm_state = s;
> -    cpu->vcpu_dirty = true;
> -    cpu->dirty_pages = 0;
> -    cpu->throttle_us_per_full = 0;
> -
>      mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
>      if (mmap_size < 0) {
>          ret = mmap_size;
> diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
> index 399aaeb0ec..cdd0c95c09 100644
> --- a/accel/kvm/trace-events
> +++ b/accel/kvm/trace-events
> @@ -9,6 +9,10 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p"
>  kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
>  kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
>  kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
> +kvm_create_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
> +kvm_get_vcpu(unsigned long arch_cpu_id) "id: %lu"
> +kvm_destroy_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
> +kvm_park_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id: %lu"
>  kvm_irqchip_commit_routes(void) ""
>  kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d"
>  kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
> diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> index ee9025f8e9..8137e6a44c 100644
> --- a/include/sysemu/kvm.h
> +++ b/include/sysemu/kvm.h
> @@ -465,6 +465,22 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
>  int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
>                                         hwaddr *phys_addr);
>  
> +/**
> + * kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU
> + * @cpu: QOM CPUState object for which KVM vCPU has to be fetched/created.
> + *
> + * @returns: 0 when success, errno (<0) when failed.
> + */
> +int kvm_create_vcpu(CPUState *cpu);
> +
> +/**
> + * kvm_park_vcpu - Park QEMU KVM vCPU context
> + * @cpu: QOM CPUState object for which QEMU KVM vCPU context has to be parked.
> + *
> + * @returns: none
> + */
> +void kvm_park_vcpu(CPUState *cpu);
> +
>  #endif /* NEED_CPU_H */
>  
>  void kvm_cpu_synchronize_state(CPUState *cpu);



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub
  2023-10-13 10:51 ` [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
@ 2023-10-27 13:05   ` Igor Mammedov
  2023-11-06 14:40     ` Salil Mehta via
  1 sibling, 1 reply; 47+ messages in thread
From: Igor Mammedov @ 2023-10-27 13:05 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel, qemu-arm, maz, jean-philippe, jonathan.cameron,
	lpieralisi, peter.maydell, richard.henderson, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

On Fri, 13 Oct 2023 11:51:23 +0100
Salil Mehta <salil.mehta@huawei.com> wrote:

> ACPI CPU hotplug related initialization should only happen if ACPI_CPU_HOTPLUG
> support has been enabled for particular architecture. Add cpu_hotplug_hw_init()
> stub to avoid compilation break.

merge this with 4/9 that actually requires this to be done. 

> 
> Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Reviewed-by: Gavin Shan <gshan@redhat.com>
> Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
> Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> Tested-by: Xianglai Li <lixianglai@loongson.cn>
> ---
>  hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/hw/acpi/acpi-cpu-hotplug-stub.c b/hw/acpi/acpi-cpu-hotplug-stub.c
> index 3fc4b14c26..c6c61bb9cd 100644
> --- a/hw/acpi/acpi-cpu-hotplug-stub.c
> +++ b/hw/acpi/acpi-cpu-hotplug-stub.c
> @@ -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;



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
  2023-10-13 10:51 ` [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
@ 2023-10-27 13:18   ` Igor Mammedov
  2023-11-08 10:58     ` Salil Mehta via
  1 sibling, 1 reply; 47+ messages in thread
From: Igor Mammedov @ 2023-10-27 13:18 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel, qemu-arm, maz, jean-philippe, jonathan.cameron,
	lpieralisi, peter.maydell, richard.henderson, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

On Fri, 13 Oct 2023 11:51:27 +0100
Salil Mehta <salil.mehta@huawei.com> 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.
> 

This is a part of hw wiring which you started to introduce in 4/9
Given patches are small, I'd merge this into 4/9 to avoid broken context.
So essentially GED improvement would consist from hw and aml parts.
with some extra refactoring (5/9) in a separate patch.

> Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Reviewed-by: Gavin Shan <gshan@redhat.com>
> Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> Tested-by: Xianglai Li <lixianglai@loongson.cn>
> ---
>  hw/acpi/generic_event_device.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> index 62d504d231..0d5f0140e5 100644
> --- a/hw/acpi/generic_event_device.c
> +++ b/hw/acpi/generic_event_device.c
> @@ -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);



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
  2023-10-13 10:51 ` [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
@ 2023-10-27 13:46   ` Igor Mammedov
  2023-11-13 17:45     ` Salil Mehta via
  1 sibling, 1 reply; 47+ messages in thread
From: Igor Mammedov @ 2023-10-27 13:46 UTC (permalink / raw)
  To: Salil Mehta, mst
  Cc: qemu-devel, qemu-arm, maz, jean-philippe, jonathan.cameron,
	lpieralisi, peter.maydell, richard.henderson, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, will, gshan, rafael,
	alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

On Fri, 13 Oct 2023 11:51:25 +0100
Salil Mehta <salil.mehta@huawei.com> 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 _CRS objects
                               ^^^^
being placed in PCI0 context is no the reason why resource was described as IO.
being IO is probably historical thing (as legacy hp was implemented as IO)

_CRS could have been at _SB level as motherboard resource but, in that case
we would need to carve out hole in PCI's _CRS  explicitly to exclude it.
Hence it was placed in PCI0 context as a hack that helps to avoid us that.
Perhaps it also applies to other targets.



> would evaluate to a system resource which describes IO Port address. But on ARM
> arch CPUs control device(\\_SB.PRES) register interface is memory-mapped hence
> _CRS object should evaluate to system resource which describes memory-mapped
> base address. Update build CPUs AML function to accept both IO/MEMORY region
> spaces and accordingly update the _CRS object.

Also x86 should be able to switch to and work with MMIO region
(I think QEMU wise IO and MMIO are the same)
and we can just use MMIO, likely without any compat machinery.

aka. existing/running/migrated x86 guests will use IO instructions to access region
(since CRS they have read, says it is IO), while new VMs will access region
as MMIO.

I might be wrong though,
  Michael?

> On x86, Legacy CPU Hotplug uses Generic ACPI GPE Block Bit 2 (GPE.2) event
> handler to notify OSPM about any CPU hot(un)plug events. Latest CPU Hotplug is
> based on ACPI Generic Event Device framework and uses ACPI GED device for the
> same. Not all architectures support Legacy CPU Hotplug. Hence, make AML for
> GPE.2 event handler conditional.

x86 has support for Legacy and Modern CPU hotplug (the later is enabled at runtime).
And both use GPE for event delivery, so above statement is not entirely
correct/confusing.

> 
> Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> Reviewed-by: Gavin Shan <gshan@redhat.com>
> Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Tested-by: Xianglai Li <lixianglai@loongson.cn>
> ---
>  hw/acpi/cpu.c         | 23 ++++++++++++++++-------
>  hw/i386/acpi-build.c  |  3 ++-
>  include/hw/acpi/cpu.h |  5 +++--
>  3 files changed, 21 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> index 4b24a25003..596b6d9d81 100644
> --- a/hw/acpi/cpu.c
> +++ b/hw/acpi/cpu.c
> @@ -339,9 +339,10 @@ const VMStateDescription vmstate_cpu_hotplug = {
>  #define CPU_FW_EJECT_EVENT "CEJF"
>  
>  void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
> -                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
> +                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
>                      const char *res_root,
> -                    const char *event_handler_method)
> +                    const char *event_handler_method,
> +                    AmlRegionSpace rs)
>  {
>      Aml *ifctx;
>      Aml *field;
> @@ -366,13 +367,19 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
>          aml_append(cpu_ctrl_dev, aml_mutex(CPU_LOCK, 0));
>  
>          crs = aml_resource_template();
> -        aml_append(crs, aml_io(AML_DECODE16, io_base, io_base, 1,
> +        if (rs == AML_SYSTEM_IO) {
> +            aml_append(crs, aml_io(AML_DECODE16, base_addr, base_addr, 1,
>                                 ACPI_CPU_HOTPLUG_REG_LEN));
> +        } else {
> +            aml_append(crs, aml_memory32_fixed(base_addr,
> +                               ACPI_CPU_HOTPLUG_REG_LEN, AML_READ_WRITE));
> +        }
> +
>          aml_append(cpu_ctrl_dev, aml_name_decl("_CRS", crs));
>  
>          /* declare CPU hotplug MMIO region with related access fields */
>          aml_append(cpu_ctrl_dev,
> -            aml_operation_region("PRST", AML_SYSTEM_IO, aml_int(io_base),
> +            aml_operation_region("PRST", rs, aml_int(base_addr),
>                                   ACPI_CPU_HOTPLUG_REG_LEN));
>  
>          field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,
> @@ -696,9 +703,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
>      aml_append(sb_scope, cpus_dev);
>      aml_append(table, sb_scope);
>  
> -    method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
> -    aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
> -    aml_append(table, method);
> +    if (event_handler_method) {
> +        method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
> +        aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
> +        aml_append(table, method);
> +    }
>  
>      g_free(cphp_res_path);
>  }
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 3f2b27cf75..f9f31f9db5 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -1550,7 +1550,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
>              .fw_unplugs_cpu = pm->smi_on_cpu_unplug,
>          };
>          build_cpus_aml(dsdt, machine, opts, pc_madt_cpu_entry,
> -                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02");
> +                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02",
> +                       AML_SYSTEM_IO);
>      }
>  
>      if (pcms->memhp_io_base && nr_mem) {
> diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
> index bc901660fb..b521a4e0de 100644
> --- a/include/hw/acpi/cpu.h
> +++ b/include/hw/acpi/cpu.h
> @@ -60,9 +60,10 @@ typedef void (*build_madt_cpu_fn)(int uid, const CPUArchIdList *apic_ids,
>                                    GArray *entry, bool force_enabled);
>  
>  void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
> -                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
> +                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
>                      const char *res_root,
> -                    const char *event_handler_method);
> +                    const char *event_handler_method,
> +                    AmlRegionSpace rs);
>  
>  void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list);
>  



^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events
  2023-10-13 10:51 ` [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events Salil Mehta via
  2023-10-13 10:51   ` Salil Mehta
  2023-10-19 10:16   ` Alex Bennée
@ 2023-10-27 14:08   ` Igor Mammedov
  2023-11-13 17:36     ` Salil Mehta via
  2 siblings, 1 reply; 47+ messages in thread
From: Igor Mammedov @ 2023-10-27 14:08 UTC (permalink / raw)
  To: Salil Mehta
  Cc: qemu-devel, qemu-arm, maz, jean-philippe, jonathan.cameron,
	lpieralisi, peter.maydell, richard.henderson, andrew.jones, david,
	philmd, eric.auger, oliver.upton, pbonzini, mst, will, gshan,
	rafael, alex.bennee, linux, darren, ilkka, vishnu, karl.heubaum,
	miguel.luis, salil.mehta, zhukeqian1, wangxiongfeng2, wangyanan55,
	jiakernel2, maobibo, lixianglai, linuxarm

On Fri, 13 Oct 2023 11:51:24 +0100
Salil Mehta <salil.mehta@huawei.com> 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 _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.
> 
> Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Reviewed-by: Gavin Shan <gshan@redhat.com>
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> Tested-by: Xianglai Li <lixianglai@loongson.cn>
> ---
>  hw/acpi/generic_event_device.c         | 8 ++++++++
>  include/hw/acpi/generic_event_device.h | 5 +++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> index a3d31631fe..d2fa1d0e4a 100644
> --- a/hw/acpi/generic_event_device.c
> +++ b/hw/acpi/generic_event_device.c
> @@ -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);
ain't OBJECT(s) == OBJECT(dev)m


> +    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);

we really should refactor GED to initfn/realizefn pattern.
then at create_acpi_ged() one would enable cpu_hotplug event
and later realizefs would call cpu_hotplug_hw_init() if event is enabled.

>  }
>  
>  static void acpi_ged_class_init(ObjectClass *class, void *data)
> diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/generic_event_device.h
> index ba84ce0214..a803ea818e 100644
> --- a/include/hw/acpi/generic_event_device.h
> +++ b/include/hw/acpi/generic_event_device.h
> @@ -60,6 +60,7 @@
>  #define HW_ACPI_GENERIC_EVENT_DEVICE_H
>  
>  #include "hw/sysbus.h"
> +#include "hw/acpi/cpu_hotplug.h"
>  #include "hw/acpi/memory_hotplug.h"
>  #include "hw/acpi/ghes.h"
>  #include "qom/object.h"
> @@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
>  #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
>  #define ACPI_GED_PWR_DOWN_EVT      0x2
>  #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
> +#define ACPI_GED_CPU_HOTPLUG_EVT    0x8
>  
>  typedef struct GEDState {
>      MemoryRegion evt;
> @@ -106,6 +108,9 @@ struct AcpiGedState {
>      SysBusDevice parent_obj;
>      MemHotplugState memhp_state;
>      MemoryRegion container_memhp;
> +    CPUHotplugState cpuhp_state;
> +    MemoryRegion container_cpuhp;
> +    AcpiCpuHotplug cpuhp;

how about merging CPUHotplugState and AcpiCpuHotplug
and isolating AcpiCpuHotplug::sts to x86 legacy hotplug code only?

then you won't have to pull in 2 states (one of which includes
GPE specific array that's not applicable to GED)

>      GEDState ged_state;
>      uint32_t ged_event_bitmap;
>      qemu_irq irq;



^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation,parking} code
  2023-10-27 12:56   ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation,parking} code Igor Mammedov
@ 2023-11-06 14:37     ` Salil Mehta via
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-11-06 14:37 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Igor,
Thanks for the review comments. I was bit on and off so could not address
the comments. Please find my replies inline.

> From: Igor Mammedov <imammedo@redhat.com>
> Sent: Friday, October 27, 2023 1:57 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; maz@kernel.org; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>;
> lpieralisi@kernel.org; peter.maydell@linaro.org;
> richard.henderson@linaro.org; andrew.jones@linux.dev; david@redhat.com;
> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU
> {creation,parking} code
> 
> On Fri, 13 Oct 2023 11:51:21 +0100
> Salil Mehta <salil.mehta@huawei.com> wrote:
> 
> > KVM vCPU creation is done once during the initialization of the VM when Qemu
>                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > thread is spawned. This is common to all the architectures.
> 
> is it really true fox x86?

Thanks for pointing out. I just meant,

"KVM vCPU creation is done once either during VM initialization or during
vCPU realization during Hotplug...."


> > Hot-unplug of vCPU results in destruction of the vCPU object in QOM but the
> > corresponding KVM vCPU object in the Host KVM is not destroyed and its
>                                                                 ^
> since KVM doesn't support vCPU removal

Correct. Will add.


> > representative KVM vCPU object/context in Qemu is parked.
> >
> > Refactor common logic so that some APIs could be reused by vCPU Hotplug code.
> 'reused' part doesn't happen within this series. So a reason
> why patch exists is not clear/no one can deduce the reason
> without the actual user here.
> 
> Suggest to move it to a series that actually will use this patch.


I can do that but I think Loongson guys might need bit of this logic
as well. This patch also brings a good restructuring to the existing
code and fixes the traces etc.

I would humbly suggest to keep it unless you have strong views.

Thanks
Salil.

> > Update new/old APIs with trace events instead of DTRACE.
> >
> > Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> > Reviewed-by: Gavin Shan <gshan@redhat.com>
> > Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Tested-by: Xianglai Li <lixianglai@loongson.cn>
> > ---
> >  accel/kvm/kvm-all.c    | 64 ++++++++++++++++++++++++++++++++----------
> >  accel/kvm/trace-events |  4 +++
> >  include/sysemu/kvm.h   | 16 +++++++++++
> >  3 files changed, 69 insertions(+), 15 deletions(-)
> >
> > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> > index 72e1d1141c..bfa7816aaa 100644
> > --- a/accel/kvm/kvm-all.c
> > +++ b/accel/kvm/kvm-all.c
> > @@ -137,6 +137,7 @@ static QemuMutex kml_slots_lock;
> >  #define kvm_slots_unlock()  qemu_mutex_unlock(&kml_slots_lock)
> >
> >  static void kvm_slot_init_dirty_bitmap(KVMSlot *mem);
> > +static int kvm_get_vcpu(KVMState *s, unsigned long vcpu_id);
> >
> >  static inline void kvm_resample_fd_remove(int gsi)
> >  {
> > @@ -320,14 +321,53 @@ err:
> >      return ret;
> >  }
> >
> > +void kvm_park_vcpu(CPUState *cpu)
> > +{
> > +    struct KVMParkedVcpu *vcpu;
> > +
> > +    trace_kvm_park_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
> > +
> > +    vcpu = g_malloc0(sizeof(*vcpu));
> > +    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
> > +    vcpu->kvm_fd = cpu->kvm_fd;
> > +    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
> > +}
> > +
> > +int kvm_create_vcpu(CPUState *cpu)
> > +{
> > +    unsigned long vcpu_id = kvm_arch_vcpu_id(cpu);
> > +    KVMState *s = kvm_state;
> > +    int kvm_fd;
> > +
> > +    trace_kvm_create_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
> > +
> > +    /* check if the KVM vCPU already exist but is parked */
> > +    kvm_fd = kvm_get_vcpu(s, vcpu_id);
> > +    if (kvm_fd < 0) {
> > +        /* vCPU not parked: create a new KVM vCPU */
> > +        kvm_fd = kvm_vm_ioctl(s, KVM_CREATE_VCPU, vcpu_id);
> > +        if (kvm_fd < 0) {
> > +            error_report("KVM_CREATE_VCPU IOCTL failed for vCPU %lu",
> vcpu_id);
> > +            return kvm_fd;
> > +        }
> > +    }
> > +
> > +    cpu->kvm_fd = kvm_fd;
> > +    cpu->kvm_state = s;
> > +    cpu->vcpu_dirty = true;
> > +    cpu->dirty_pages = 0;
> > +    cpu->throttle_us_per_full = 0;
> > +
> > +    return 0;
> > +}
> > +
> >  static int do_kvm_destroy_vcpu(CPUState *cpu)
> >  {
> >      KVMState *s = kvm_state;
> >      long mmap_size;
> > -    struct KVMParkedVcpu *vcpu = NULL;
> >      int ret = 0;
> >
> > -    DPRINTF("kvm_destroy_vcpu\n");
> > +    trace_kvm_destroy_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
> >
> >      ret = kvm_arch_destroy_vcpu(cpu);
> >      if (ret < 0) {
> > @@ -353,10 +393,7 @@ static int do_kvm_destroy_vcpu(CPUState *cpu)
> >          }
> >      }
> >
> > -    vcpu = g_malloc0(sizeof(*vcpu));
> > -    vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
> > -    vcpu->kvm_fd = cpu->kvm_fd;
> > -    QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
> > +    kvm_park_vcpu(cpu);
> >  err:
> >      return ret;
> >  }
> > @@ -377,6 +414,8 @@ static int kvm_get_vcpu(KVMState *s, unsigned long
> vcpu_id)
> >          if (cpu->vcpu_id == vcpu_id) {
> >              int kvm_fd;
> >
> > +            trace_kvm_get_vcpu(vcpu_id);
> > +
> >              QLIST_REMOVE(cpu, node);
> >              kvm_fd = cpu->kvm_fd;
> >              g_free(cpu);
> > @@ -384,7 +423,7 @@ static int kvm_get_vcpu(KVMState *s, unsigned long
> vcpu_id)
> >          }
> >      }
> >
> > -    return kvm_vm_ioctl(s, KVM_CREATE_VCPU, (void *)vcpu_id);
> > +    return -ENOENT;
> >  }
> >
> >  int kvm_init_vcpu(CPUState *cpu, Error **errp)
> > @@ -395,19 +434,14 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
> >
> >      trace_kvm_init_vcpu(cpu->cpu_index, kvm_arch_vcpu_id(cpu));
> >
> > -    ret = kvm_get_vcpu(s, kvm_arch_vcpu_id(cpu));
> > +    ret = kvm_create_vcpu(cpu);
> >      if (ret < 0) {
> > -        error_setg_errno(errp, -ret, "kvm_init_vcpu: kvm_get_vcpu failed
> (%lu)",
> > +        error_setg_errno(errp, -ret,
> > +                         "kvm_init_vcpu: kvm_create_vcpu failed (%lu)",
> >                           kvm_arch_vcpu_id(cpu));
> >          goto err;
> >      }
> >
> > -    cpu->kvm_fd = ret;
> > -    cpu->kvm_state = s;
> > -    cpu->vcpu_dirty = true;
> > -    cpu->dirty_pages = 0;
> > -    cpu->throttle_us_per_full = 0;
> > -
> >      mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
> >      if (mmap_size < 0) {
> >          ret = mmap_size;
> > diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
> > index 399aaeb0ec..cdd0c95c09 100644
> > --- a/accel/kvm/trace-events
> > +++ b/accel/kvm/trace-events
> > @@ -9,6 +9,10 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd
> %d, type 0x%x, arg %p"
> >  kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to
> retrieve ONEREG %" PRIu64 " from KVM: %s"
> >  kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set
> ONEREG %" PRIu64 " to KVM: %s"
> >  kvm_init_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id:
> %lu"
> > +kvm_create_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id:
> %lu"
> > +kvm_get_vcpu(unsigned long arch_cpu_id) "id: %lu"
> > +kvm_destroy_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d
> id: %lu"
> > +kvm_park_vcpu(int cpu_index, unsigned long arch_cpu_id) "index: %d id:
> %lu"
> >  kvm_irqchip_commit_routes(void) ""
> >  kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s
> vector %d virq %d"
> >  kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
> > diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
> > index ee9025f8e9..8137e6a44c 100644
> > --- a/include/sysemu/kvm.h
> > +++ b/include/sysemu/kvm.h
> > @@ -465,6 +465,22 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int
> sigmask_len);
> >  int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
> >                                         hwaddr *phys_addr);
> >
> > +/**
> > + * kvm_create_vcpu - Gets a parked KVM vCPU or creates a KVM vCPU
> > + * @cpu: QOM CPUState object for which KVM vCPU has to be
> fetched/created.
> > + *
> > + * @returns: 0 when success, errno (<0) when failed.
> > + */
> > +int kvm_create_vcpu(CPUState *cpu);
> > +
> > +/**
> > + * kvm_park_vcpu - Park QEMU KVM vCPU context
> > + * @cpu: QOM CPUState object for which QEMU KVM vCPU context has to be
> parked.
> > + *
> > + * @returns: none
> > + */
> > +void kvm_park_vcpu(CPUState *cpu);
> > +
> >  #endif /* NEED_CPU_H */
> >
> >  void kvm_cpu_synchronize_state(CPUState *cpu);



^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub
  2023-10-27 13:05   ` Igor Mammedov
@ 2023-11-06 14:40     ` Salil Mehta via
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-11-06 14:40 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Igor,

> From: Igor Mammedov <imammedo@redhat.com>
> Sent: Friday, October 27, 2023 2:06 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; maz@kernel.org; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>;
> lpieralisi@kernel.org; peter.maydell@linaro.org;
> richard.henderson@linaro.org; andrew.jones@linux.dev; david@redhat.com;
> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub
> 
> On Fri, 13 Oct 2023 11:51:23 +0100
> Salil Mehta <salil.mehta@huawei.com> wrote:
> 
> > ACPI CPU hotplug related initialization should only happen if ACPI_CPU_HOTPLUG
> > support has been enabled for particular architecture. Add cpu_hotplug_hw_init()
> > stub to avoid compilation break.
> 
> merge this with 4/9 that actually requires this to be done.

Sure. No issues.


Thanks
Salil.


> > Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Reviewed-by: Gavin Shan <gshan@redhat.com>
> > Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
> > Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> > Tested-by: Xianglai Li <lixianglai@loongson.cn>
> > ---
> >  hw/acpi/acpi-cpu-hotplug-stub.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/hw/acpi/acpi-cpu-hotplug-stub.c b/hw/acpi/acpi-cpu-hotplug-
> stub.c
> > index 3fc4b14c26..c6c61bb9cd 100644
> > --- a/hw/acpi/acpi-cpu-hotplug-stub.c
> > +++ b/hw/acpi/acpi-cpu-hotplug-stub.c
> > @@ -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;
> 



^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug
  2023-10-27 13:18   ` Igor Mammedov
@ 2023-11-08 10:58     ` Salil Mehta via
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-11-08 10:58 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Igor,

> From: Igor Mammedov <imammedo@redhat.com>
> Sent: Friday, October 27, 2023 2:18 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> Cc: qemu-devel@nongnu.org; qemu-arm@nongnu.org; maz@kernel.org; jean-
> philippe@linaro.org; Jonathan Cameron <jonathan.cameron@huawei.com>;
> lpieralisi@kernel.org; peter.maydell@linaro.org;
> richard.henderson@linaro.org; andrew.jones@linux.dev; david@redhat.com;
> philmd@linaro.org; eric.auger@redhat.com; oliver.upton@linux.dev;
> pbonzini@redhat.com; mst@redhat.com; will@kernel.org; gshan@redhat.com;
> rafael@kernel.org; alex.bennee@linaro.org; linux@armlinux.org.uk;
> darren@os.amperecomputing.com; ilkka@os.amperecomputing.com;
> vishnu@os.amperecomputing.com; karl.heubaum@oracle.com;
> miguel.luis@oracle.com; salil.mehta@opnsrc.net; zhukeqian
> <zhukeqian1@huawei.com>; wangxiongfeng (C) <wangxiongfeng2@huawei.com>;
> wangyanan (Y) <wangyanan55@huawei.com>; jiakernel2@gmail.com;
> maobibo@loongson.cn; lixianglai@loongson.cn; Linuxarm <linuxarm@huawei.com>
> Subject: Re: [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support
> vCPU Hotplug
> 
> On Fri, 13 Oct 2023 11:51:27 +0100
> Salil Mehta <salil.mehta@huawei.com> 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.
> >
> 
> This is a part of hw wiring which you started to introduce in 4/9
> Given patches are small, I'd merge this into 4/9 to avoid broken context.
> So essentially GED improvement would consist from hw and aml parts.
> with some extra refactoring (5/9) in a separate patch.


No issues. Will merge.

Thanks
Salil.

> > Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Reviewed-by: Gavin Shan <gshan@redhat.com>
> > Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> > Tested-by: Xianglai Li <lixianglai@loongson.cn>
> > ---
> >  hw/acpi/generic_event_device.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> > index 62d504d231..0d5f0140e5 100644
> > --- a/hw/acpi/generic_event_device.c
> > +++ b/hw/acpi/generic_event_device.c
> > @@ -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);



^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events
  2023-10-27 14:08   ` Igor Mammedov
@ 2023-11-13 17:36     ` Salil Mehta via
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-11-13 17:36 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, mst@redhat.com, will@kernel.org,
	gshan@redhat.com, rafael@kernel.org, alex.bennee@linaro.org,
	linux@armlinux.org.uk, darren@os.amperecomputing.com,
	ilkka@os.amperecomputing.com, vishnu@os.amperecomputing.com,
	karl.heubaum@oracle.com, miguel.luis@oracle.com,
	salil.mehta@opnsrc.net, zhukeqian, wangxiongfeng (C),
	wangyanan (Y), jiakernel2@gmail.com, maobibo@loongson.cn,
	lixianglai@loongson.cn, Linuxarm

Hi Igor,
Sorry, I realized I missed to reply this review comment.

> From: Igor Mammedov <imammedo@redhat.com>
> Sent: Friday, October 27, 2023 3:08 PM
> To: Salil Mehta <salil.mehta@huawei.com>
> 
> On Fri, 13 Oct 2023 11:51:24 +0100
> Salil Mehta <salil.mehta@huawei.com> 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 _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.
> >
> > Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Reviewed-by: Gavin Shan <gshan@redhat.com>
> > Reviewed-by: David Hildenbrand <david@redhat.com>
> > Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> > Tested-by: Xianglai Li <lixianglai@loongson.cn>
> > ---
> >  hw/acpi/generic_event_device.c         | 8 ++++++++
> >  include/hw/acpi/generic_event_device.h | 5 +++++
> >  2 files changed, 13 insertions(+)
> >
> > diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> > index a3d31631fe..d2fa1d0e4a 100644
> > --- a/hw/acpi/generic_event_device.c
> > +++ b/hw/acpi/generic_event_device.c
> > @@ -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);
> ain't OBJECT(s) == OBJECT(dev)m


Thanks for pointing. And going deeper to looks this is *stray* and
surprisingly has been lurking since I first floated the RFC V1
in Jun 2020. Sorry I missed it in earlier context although David
did point to this.

Salil.


> > +    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);
> 
> we really should refactor GED to initfn/realizefn pattern.
> then at create_acpi_ged() one would enable cpu_hotplug event
> and later realizefs would call cpu_hotplug_hw_init() if event is enabled.


Maybe. Why not instance_init() ?


> >  }
> >
> >  static void acpi_ged_class_init(ObjectClass *class, void *data)
> > diff --git a/include/hw/acpi/generic_event_device.h
> b/include/hw/acpi/generic_event_device.h
> > index ba84ce0214..a803ea818e 100644
> > --- a/include/hw/acpi/generic_event_device.h
> > +++ b/include/hw/acpi/generic_event_device.h
> > @@ -60,6 +60,7 @@
> >  #define HW_ACPI_GENERIC_EVENT_DEVICE_H
> >
> >  #include "hw/sysbus.h"
> > +#include "hw/acpi/cpu_hotplug.h"
> >  #include "hw/acpi/memory_hotplug.h"
> >  #include "hw/acpi/ghes.h"
> >  #include "qom/object.h"
> > @@ -95,6 +96,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AcpiGedState, ACPI_GED)
> >  #define ACPI_GED_MEM_HOTPLUG_EVT   0x1
> >  #define ACPI_GED_PWR_DOWN_EVT      0x2
> >  #define ACPI_GED_NVDIMM_HOTPLUG_EVT 0x4
> > +#define ACPI_GED_CPU_HOTPLUG_EVT    0x8
> >
> >  typedef struct GEDState {
> >      MemoryRegion evt;
> > @@ -106,6 +108,9 @@ struct AcpiGedState {
> >      SysBusDevice parent_obj;
> >      MemHotplugState memhp_state;
> >      MemoryRegion container_memhp;
> > +    CPUHotplugState cpuhp_state;
> > +    MemoryRegion container_cpuhp;
> > +    AcpiCpuHotplug cpuhp;
> 
> how about merging CPUHotplugState and AcpiCpuHotplug
> and isolating AcpiCpuHotplug::sts to x86 legacy hotplug code only?
> 
> then you won't have to pull in 2 states (one of which includes
> GPE specific array that's not applicable to GED)

To be frank, I do not remember the context what I was trying to do
4 years back. But above looks stray and will remove it.


Thanks
Salil.



^ permalink raw reply	[flat|nested] 47+ messages in thread

* RE: [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
  2023-10-27 13:46   ` Igor Mammedov
@ 2023-11-13 17:45     ` Salil Mehta via
  0 siblings, 0 replies; 47+ messages in thread
From: Salil Mehta via @ 2023-11-13 17:45 UTC (permalink / raw)
  To: Igor Mammedov, mst@redhat.com
  Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, maz@kernel.org,
	jean-philippe@linaro.org, Jonathan Cameron, lpieralisi@kernel.org,
	peter.maydell@linaro.org, richard.henderson@linaro.org,
	andrew.jones@linux.dev, david@redhat.com, philmd@linaro.org,
	eric.auger@redhat.com, oliver.upton@linux.dev,
	pbonzini@redhat.com, will@kernel.org, gshan@redhat.com,
	rafael@kernel.org, alex.bennee@linaro.org, linux@armlinux.org.uk,
	darren@os.amperecomputing.com, ilkka@os.amperecomputing.com,
	vishnu@os.amperecomputing.com, karl.heubaum@oracle.com,
	miguel.luis@oracle.com, salil.mehta@opnsrc.net, zhukeqian,
	wangxiongfeng (C), wangyanan (Y), jiakernel2@gmail.com,
	maobibo@loongson.cn, lixianglai@loongson.cn, Linuxarm

Hi Igor,
Sorry, I missed this as well.

> From: Igor Mammedov <imammedo@redhat.com>
> Sent: Friday, October 27, 2023 2:47 PM
> To: Salil Mehta <salil.mehta@huawei.com>; mst@redhat.com
> 
> On Fri, 13 Oct 2023 11:51:25 +0100
> Salil Mehta <salil.mehta@huawei.com> 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 _CRS objects
>                                ^^^^
> being placed in PCI0 context is no the reason why resource was described as IO.
> being IO is probably historical thing (as legacy hp was implemented as IO)


I just meant that because it is IO port based therefore existing CPUs AML code
would evaluate to a system resource which describes IO Port address.



> _CRS could have been at _SB level as motherboard resource but, in that case
> we would need to carve out hole in PCI's _CRS  explicitly to exclude it.
> Hence it was placed in PCI0 context as a hack that helps to avoid us that.
> Perhaps it also applies to other targets.

Sure.

> > would evaluate to a system resource which describes IO Port address. But on ARM
> > arch CPUs control device(\\_SB.PRES) register interface is memory-mapped hence
> > _CRS object should evaluate to system resource which describes memory-mapped
> > base address. Update build CPUs AML function to accept both IO/MEMORY region
> > spaces and accordingly update the _CRS object.
> 
> Also x86 should be able to switch to and work with MMIO region
> (I think QEMU wise IO and MMIO are the same)
> and we can just use MMIO, likely without any compat machinery.
> 
> aka. existing/running/migrated x86 guests will use IO instructions to access region
> (since CRS they have read, says it is IO), while new VMs will access region as MMIO.


Ok got it. But I guess existing CPUs AML code for ctrl-dev did not have this
change. Or did I miss anything?

 
> I might be wrong though,
>   Michael?
> 
> > On x86, Legacy CPU Hotplug uses Generic ACPI GPE Block Bit 2 (GPE.2) event
> > handler to notify OSPM about any CPU hot(un)plug events. Latest CPU Hotplug is
> > based on ACPI Generic Event Device framework and uses ACPI GED device for the
> > same. Not all architectures support Legacy CPU Hotplug. Hence, make AML for
> > GPE.2 event handler conditional.
> 
> x86 has support for Legacy and Modern CPU hotplug (the later is enabled at runtime).
> And both use GPE for event delivery, so above statement is not entirely correct/confusing.

Ok yes. I will rephrase part of it.


Thanks
Salil.

> > Co-developed-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
> > Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> > Reviewed-by: Gavin Shan <gshan@redhat.com>
> > Tested-by: Vishnu Pajjuri <vishnu@os.amperecomputing.com>
> > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > Tested-by: Xianglai Li <lixianglai@loongson.cn>
> > ---
> >  hw/acpi/cpu.c         | 23 ++++++++++++++++-------
> >  hw/i386/acpi-build.c  |  3 ++-
> >  include/hw/acpi/cpu.h |  5 +++--
> >  3 files changed, 21 insertions(+), 10 deletions(-)
> >
> > diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> > index 4b24a25003..596b6d9d81 100644
> > --- a/hw/acpi/cpu.c
> > +++ b/hw/acpi/cpu.c
> > @@ -339,9 +339,10 @@ const VMStateDescription vmstate_cpu_hotplug = {
> >  #define CPU_FW_EJECT_EVENT "CEJF"
> >
> >  void build_cpus_aml(Aml *table, MachineState *machine,
> CPUHotplugFeatures opts,
> > -                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
> > +                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
> >                      const char *res_root,
> > -                    const char *event_handler_method)
> > +                    const char *event_handler_method,
> > +                    AmlRegionSpace rs)
> >  {
> >      Aml *ifctx;
> >      Aml *field;
> > @@ -366,13 +367,19 @@ void build_cpus_aml(Aml *table, MachineState
> *machine, CPUHotplugFeatures opts,
> >          aml_append(cpu_ctrl_dev, aml_mutex(CPU_LOCK, 0));
> >
> >          crs = aml_resource_template();
> > -        aml_append(crs, aml_io(AML_DECODE16, io_base, io_base, 1,
> > +        if (rs == AML_SYSTEM_IO) {
> > +            aml_append(crs, aml_io(AML_DECODE16, base_addr, base_addr,
> 1,
> >                                 ACPI_CPU_HOTPLUG_REG_LEN));
> > +        } else {
> > +            aml_append(crs, aml_memory32_fixed(base_addr,
> > +                               ACPI_CPU_HOTPLUG_REG_LEN,
> AML_READ_WRITE));
> > +        }
> > +
> >          aml_append(cpu_ctrl_dev, aml_name_decl("_CRS", crs));
> >
> >          /* declare CPU hotplug MMIO region with related access fields */
> >          aml_append(cpu_ctrl_dev,
> > -            aml_operation_region("PRST", AML_SYSTEM_IO,
> aml_int(io_base),
> > +            aml_operation_region("PRST", rs, aml_int(base_addr),
> >                                   ACPI_CPU_HOTPLUG_REG_LEN));
> >
> >          field = aml_field("PRST", AML_BYTE_ACC, AML_NOLOCK,
> > @@ -696,9 +703,11 @@ void build_cpus_aml(Aml *table, MachineState
> *machine, CPUHotplugFeatures opts,
> >      aml_append(sb_scope, cpus_dev);
> >      aml_append(table, sb_scope);
> >
> > -    method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
> > -    aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
> > -    aml_append(table, method);
> > +    if (event_handler_method) {
> > +        method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED);
> > +        aml_append(method, aml_call0("\\_SB.CPUS." CPU_SCAN_METHOD));
> > +        aml_append(table, method);
> > +    }
> >
> >      g_free(cphp_res_path);
> >  }
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index 3f2b27cf75..f9f31f9db5 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -1550,7 +1550,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
> >              .fw_unplugs_cpu = pm->smi_on_cpu_unplug,
> >          };
> >          build_cpus_aml(dsdt, machine, opts, pc_madt_cpu_entry,
> > -                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02");
> > +                       pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02",
> > +                       AML_SYSTEM_IO);
> >      }
> >
> >      if (pcms->memhp_io_base && nr_mem) {
> > diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
> > index bc901660fb..b521a4e0de 100644
> > --- a/include/hw/acpi/cpu.h
> > +++ b/include/hw/acpi/cpu.h
> > @@ -60,9 +60,10 @@ typedef void (*build_madt_cpu_fn)(int uid, const
> CPUArchIdList *apic_ids,
> >                                    GArray *entry, bool force_enabled);
> >
> >  void build_cpus_aml(Aml *table, MachineState *machine,
> CPUHotplugFeatures opts,
> > -                    build_madt_cpu_fn build_madt_cpu, hwaddr io_base,
> > +                    build_madt_cpu_fn build_madt_cpu, hwaddr base_addr,
> >                      const char *res_root,
> > -                    const char *event_handler_method);
> > +                    const char *event_handler_method,
> > +                    AmlRegionSpace rs);
> >
> >  void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList
> ***list);
> >



^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2023-11-13 17:46 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-13 10:51 [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Salil Mehta via
2023-10-13 10:51 ` Salil Mehta
2023-10-13 10:51 ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation, parking} code Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-27 12:56   ` [PATCH V6 1/9] accel/kvm: Extract common KVM vCPU {creation,parking} code Igor Mammedov
2023-11-06 14:37     ` Salil Mehta via
2023-10-13 10:51 ` [PATCH V6 2/9] hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-13 10:51 ` [PATCH V6 3/9] hw/acpi: Add ACPI CPU hotplug init stub Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-27 13:05   ` Igor Mammedov
2023-11-06 14:40     ` Salil Mehta via
2023-10-13 10:51 ` [PATCH V6 4/9] hw/acpi: Init GED framework with CPU hotplug events Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-19 10:16   ` Alex Bennée
2023-10-19 10:27     ` Salil Mehta via
2023-10-19 10:27       ` Salil Mehta
2023-10-27 14:08   ` Igor Mammedov
2023-11-13 17:36     ` Salil Mehta via
2023-10-13 10:51 ` [PATCH V6 5/9] hw/acpi: Update CPUs AML with cpu-(ctrl)dev change Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-27 13:46   ` Igor Mammedov
2023-11-13 17:45     ` Salil Mehta via
2023-10-13 10:51 ` [PATCH V6 6/9] hw/acpi: Update GED _EVT method AML with CPU scan Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-13 10:51 ` [PATCH V6 7/9] hw/acpi: Update ACPI GED framework to support vCPU Hotplug Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-27 13:18   ` Igor Mammedov
2023-11-08 10:58     ` Salil Mehta via
2023-10-13 10:51 ` [PATCH V6 8/9] physmem: Add helper function to destroy CPU AddressSpace Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-13 10:51 ` [PATCH V6 9/9] gdbstub: Add helper function to unregister GDB register space Salil Mehta via
2023-10-13 10:51   ` Salil Mehta
2023-10-13 16:33 ` [PATCH V6 0/9] Add architecture agnostic code to support vCPU Hotplug Miguel Luis
2023-10-16  9:52   ` Salil Mehta via
2023-10-16  9:52     ` Salil Mehta
2023-10-16 10:01     ` Miguel Luis
2023-10-16 10:09       ` Salil Mehta via
2023-10-16 10:09         ` Salil Mehta
2023-10-19  9:50       ` Miguel Luis
2023-10-19  9:04 ` Shaoqin Huang
2023-10-19  9:34   ` Salil Mehta via
2023-10-19  9:34     ` Salil Mehta
2023-10-20  3:30     ` Shaoqin Huang
2023-10-26 12:41 ` Igor Mammedov
2023-10-27 10:23   ` Salil Mehta via
2023-10-27 10:23     ` Salil Mehta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).