[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC V3 17/29] arm/virt: Release objects for *disabled* possible v
From: |
Salil Mehta |
Subject: |
[PATCH RFC V3 17/29] arm/virt: Release objects for *disabled* possible vCPUs after init |
Date: |
Fri, 14 Jun 2024 00:36:27 +0100 |
During `machvirt_init()`, QOM ARMCPU objects are pre-created along with the
corresponding KVM vCPUs in the host for all possible vCPUs. This is necessary
due to the architectural constraint that KVM restricts the deferred creation of
KVM vCPUs and VGIC initialization/sizing after VM initialization. Hence, VGIC is
pre-sized with possible vCPUs.
After the initialization of the machine is complete, the disabled possible KVM
vCPUs are parked in the per-virt-machine list "kvm_parked_vcpus," and we release
the QOM ARMCPU objects for the disabled vCPUs. These will be re-created when the
vCPU is hotplugged again. The QOM ARMCPU object is then re-attached to the
corresponding parked KVM vCPU.
Alternatively, we could have chosen not to release the QOM CPU objects and kept
reusing them. This approach might require some modifications to the
`qdevice_add()` interface to retrieve the old ARMCPU object instead of creating
a new one for the hotplug request.
Each of these approaches has its own pros and cons. This prototype uses the
first approach (suggestions are welcome!).
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>
---
hw/arm/virt.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 9d33f30a6a..a72cd3b20d 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2050,6 +2050,7 @@ static void virt_cpu_post_init(VirtMachineState *vms,
MemoryRegion *sysmem)
{
CPUArchIdList *possible_cpus = vms->parent.possible_cpus;
int max_cpus = MACHINE(vms)->smp.max_cpus;
+ MachineState *ms = MACHINE(vms);
bool aarch64, steal_time;
CPUState *cpu;
int n;
@@ -2111,6 +2112,37 @@ static void virt_cpu_post_init(VirtMachineState *vms,
MemoryRegion *sysmem)
}
}
}
+
+ if (kvm_enabled() || tcg_enabled()) {
+ for (n = 0; n < possible_cpus->len; n++) {
+ cpu = qemu_get_possible_cpu(n);
+
+ /*
+ * Now, GIC has been sized with possible CPUs and we dont require
+ * disabled vCPU objects to be represented in the QOM. Release the
+ * disabled ARMCPU objects earlier used during init for pre-sizing.
+ *
+ * We fake to the guest through ACPI about the
presence(_STA.PRES=1)
+ * of these non-existent vCPUs at VMM/qemu and present these as
+ * disabled vCPUs(_STA.ENA=0) so that they cant be used. These
vCPUs
+ * can be later added to the guest through hotplug exchanges when
+ * ARMCPU objects are created back again using 'device_add' QMP
+ * command.
+ */
+ /*
+ * RFC: Question: Other approach could've been to keep them forever
+ * and release it only once when qemu exits as part of finalize or
+ * when new vCPU is hotplugged. In the later old could be released
+ * for the newly created object for the same vCPU?
+ */
+ if (!qemu_enabled_cpu(cpu)) {
+ CPUArchId *cpu_slot;
+ cpu_slot = virt_find_cpu_slot(ms, cpu->cpu_index);
+ cpu_slot->cpu = NULL;
+ object_unref(OBJECT(cpu));
+ }
+ }
+ }
}
static void virt_cpu_set_properties(Object *cpuobj, const CPUArchId *cpu_slot,
--
2.34.1
- [PATCH RFC V3 07/29] arm/virt, gicv3: Changes to pre-size GIC with possible vcpus @machine init, (continued)
- [PATCH RFC V3 07/29] arm/virt, gicv3: Changes to pre-size GIC with possible vcpus @machine init, Salil Mehta, 2024/06/13
- [PATCH RFC V3 08/29] arm/virt: Init PMU at host for all possible vcpus, Salil Mehta, 2024/06/13
- [PATCH RFC V3 09/29] arm/acpi: Enable ACPI support for vcpu hotplug, Salil Mehta, 2024/06/13
- [PATCH RFC V3 10/29] arm/virt: Add cpu hotplug events to GED during creation, Salil Mehta, 2024/06/13
- [PATCH RFC V3 11/29] arm/virt: Create GED dev before *disabled* CPU Objs are destroyed, Salil Mehta, 2024/06/13
- [PATCH RFC V3 12/29] arm/virt/acpi: Build CPUs AML with CPU Hotplug support, Salil Mehta, 2024/06/13
- [PATCH RFC V3 13/29] arm/virt: Make ARM vCPU *present* status ACPI *persistent*, Salil Mehta, 2024/06/13
- [PATCH RFC V3 14/29] hw/acpi: ACPI/AML Changes to reflect the correct _STA.{PRES, ENA} Bits to Guest, Salil Mehta, 2024/06/13
- [PATCH RFC V3 15/29] hw/arm: MADT Tbl change to size the guest with possible vCPUs, Salil Mehta, 2024/06/13
- [PATCH RFC V3 16/29] hw/acpi: Make _MAT method optional, Salil Mehta, 2024/06/13
- [PATCH RFC V3 17/29] arm/virt: Release objects for *disabled* possible vCPUs after init,
Salil Mehta <=
- [PATCH RFC V3 18/29] arm/virt: Add/update basic hot-(un)plug framework, Salil Mehta, 2024/06/13
- [PATCH RFC V3 19/29] arm/virt: Changes to (un)wire GICC<->vCPU IRQs during hot-(un)plug, Salil Mehta, 2024/06/13
- [PATCH RFC V3 20/29] hw/arm, gicv3: Changes to update GIC with vCPU hot-plug notification, Salil Mehta, 2024/06/13
- [PATCH RFC V3 21/29] hw/intc/arm-gicv3*: Changes required to (re)init the vCPU register info, Salil Mehta, 2024/06/13
- [PATCH RFC V3 22/29] arm/virt: Update the guest(via GED) about CPU hot-(un)plug events, Salil Mehta, 2024/06/13
- [PATCH RFC V3 23/29] hw/arm: Changes required for reset and to support next boot, Salil Mehta, 2024/06/13
- [PATCH RFC V3 24/29] target/arm: Add support of *unrealize* ARMCPU during vCPU Hot-unplug, Salil Mehta, 2024/06/13
- [PATCH RFC V3 25/29] target/arm/kvm: Write CPU state back to KVM on reset, Salil Mehta, 2024/06/13
- [PATCH RFC V3 26/29] target/arm/kvm, tcg: Register/Handle SMCCC hypercall exits to VMM/Qemu, Salil Mehta, 2024/06/13
- [PATCH RFC V3 27/29] hw/arm: Support hotplug capability check using _OSC method, Salil Mehta, 2024/06/13