From: Gustavo Romero <gustavo.romero@linaro.org>
To: Salil Mehta <salil.mehta@huawei.com>,
qemu-devel@nongnu.org, qemu-arm@nongnu.org, mst@redhat.com
Cc: maz@kernel.org, jean-philippe@linaro.org,
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, will@kernel.org,
ardb@kernel.org, oliver.upton@linux.dev, pbonzini@redhat.com,
gshan@redhat.com, rafael@kernel.org, borntraeger@linux.ibm.com,
alex.bennee@linaro.org, npiggin@gmail.com, harshpb@linux.ibm.com,
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, zhukeqian1@huawei.com,
wangxiongfeng2@huawei.com, wangyanan55@huawei.com,
jiakernel2@gmail.com, maobibo@loongson.cn,
lixianglai@loongson.cn, shahuang@redhat.com, zhao1.liu@intel.com,
linuxarm@huawei.com
Subject: Re: [PATCH V1 1/4] hw/acpi: Initialize ACPI Hotplug CPU Status with Support for vCPU `Persistence`
Date: Wed, 16 Oct 2024 18:01:14 -0300 [thread overview]
Message-ID: <2d4a0d78-f3cc-4644-a9ea-d02114c242b8@linaro.org> (raw)
In-Reply-To: <20241014192205.253479-2-salil.mehta@huawei.com>
Hi Salil,
On 10/14/24 16:22, Salil Mehta wrote:
> Certain CPU architecture specifications [1][2][3] prohibit changes to CPU
> presence after the kernel has booted. This limitation exists because many system
> initializations rely on the exact CPU count at boot time and do not expect it to
> change later. For example, components like interrupt controllers, which are
> closely tied to CPUs, or various per-CPU features, may not support configuration
> changes once the kernel has been initialized. This presents a challenge for
> virtualization features such as vCPU hotplug.
>
> To address this issue, introduce an `is_enabled` state in the `AcpiCpuStatus`,
> which reflects whether a vCPU has been hot-plugged or hot-unplugged in QEMU,
> marking it as (un)available in the Guest Kernel. The `is_present` state should
> be set based on the `acpi_persistent` flag. In cases where unplugged vCPUs need
> to be deliberately simulated in the ACPI to maintain a persistent view of vCPUs,
> this flag ensures the guest kernel continues to see those vCPUs.
>
> Additionally, introduce an `acpi_persistent` property that can be used to
> initialize the ACPI vCPU presence state accordingly. Architectures requiring
> ACPI to expose a persistent view of vCPUs can override its default value. Refer
> to the patch-set implelenting vCPU hotplug support for ARM for more details on
nit: implementation
Cheers,
Gustavo
> its usage.
>
> References:
> [1] KVMForum 2023 Presentation: Challenges Revisited in Supporting Virt CPU Hotplug on
> architectures that don’t Support CPU Hotplug (like ARM64)
> a. Kernel Link: https://kvm-forum.qemu.org/2023/KVM-forum-cpu-hotplug_7OJ1YyJ.pdf
> b. Qemu Link: https://kvm-forum.qemu.org/2023/Challenges_Revisited_in_Supporting_Virt_CPU_Hotplug_-__ii0iNb3.pdf
> [2] KVMForum 2020 Presentation: Challenges in Supporting Virtual CPU Hotplug on
> SoC Based Systems (like ARM64)
> Link: https://kvmforum2020.sched.com/event/eE4m
> [3] Check comment 5 in the bugzilla entry
> Link: https://bugzilla.tianocore.org/show_bug.cgi?id=4481#c5
>
> Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
> ---
> cpu-target.c | 1 +
> hw/acpi/cpu.c | 35 ++++++++++++++++++++++++++++++++++-
> include/hw/acpi/cpu.h | 21 +++++++++++++++++++++
> include/hw/core/cpu.h | 21 +++++++++++++++++++++
> 4 files changed, 77 insertions(+), 1 deletion(-)
>
> diff --git a/cpu-target.c b/cpu-target.c
> index 499facf774..c8a29ab495 100644
> --- a/cpu-target.c
> +++ b/cpu-target.c
> @@ -200,6 +200,7 @@ static Property cpu_common_props[] = {
> */
> DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
> MemoryRegion *),
> + DEFINE_PROP_BOOL("acpi-persistent", CPUState, acpi_persistent, false),
> #endif
> DEFINE_PROP_END_OF_LIST(),
> };
> diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> index 5cb60ca8bc..083c4010c2 100644
> --- a/hw/acpi/cpu.c
> +++ b/hw/acpi/cpu.c
> @@ -225,7 +225,40 @@ void cpu_hotplug_hw_init(MemoryRegion *as, Object *owner,
> state->dev_count = id_list->len;
> state->devs = g_new0(typeof(*state->devs), state->dev_count);
> for (i = 0; i < id_list->len; i++) {
> - state->devs[i].cpu = CPU(id_list->cpus[i].cpu);
> + struct CPUState *cpu = CPU(id_list->cpus[i].cpu);
> + /*
> + * In most architectures, CPUs that are marked as ACPI 'present' are
> + * also ACPI 'enabled' by default. These states remain consistent at
> + * both the QOM and ACPI levels.
> + */
> + if (cpu) {
> + state->devs[i].is_enabled = true;
> + state->devs[i].is_present = true;
> + state->devs[i].cpu = cpu;
> + } else {
> + state->devs[i].is_enabled = false;
> + /*
> + * In some architectures, even 'unplugged' or 'disabled' QOM CPUs
> + * may be exposed as ACPI 'present.' This approach provides a
> + * persistent view of the vCPUs to the guest kernel. This could be
> + * due to an architectural constraint that requires every per-CPU
> + * component to be present at boot time, meaning the exact count of
> + * vCPUs must be known and cannot be altered after the kernel has
> + * booted. As a result, the vCPU states at the QOM and ACPI levels
> + * might become inconsistent. However, in such cases, the presence
> + * of vCPUs has been deliberately simulated at the ACPI level.
> + */
> + if (acpi_persistent_cpu(first_cpu)) {
> + state->devs[i].is_present = true;
> + /*
> + * `CPUHotplugState::AcpiCpuStatus::cpu` becomes insignificant
> + * in this case
> + */
> + } else {
> + state->devs[i].is_present = false;
> + state->devs[i].cpu = cpu;
> + }
> + }
> state->devs[i].arch_id = id_list->cpus[i].arch_id;
> }
> memory_region_init_io(&state->ctrl_reg, owner, &cpu_hotplug_ops, state,
> diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h
> index 32654dc274..bd3f9973c9 100644
> --- a/include/hw/acpi/cpu.h
> +++ b/include/hw/acpi/cpu.h
> @@ -26,6 +26,8 @@ typedef struct AcpiCpuStatus {
> uint64_t arch_id;
> bool is_inserting;
> bool is_removing;
> + bool is_present;
> + bool is_enabled;
> bool fw_remove;
> uint32_t ost_event;
> uint32_t ost_status;
> @@ -75,4 +77,23 @@ extern const VMStateDescription vmstate_cpu_hotplug;
> VMSTATE_STRUCT(cpuhp, state, 1, \
> vmstate_cpu_hotplug, CPUHotplugState)
>
> +/**
> + * acpi_persistent_cpu:
> + * @cpu: The vCPU to check
> + *
> + * Checks if the vCPU state should always be reflected as *present* via ACPI
> + * to the Guest. By default, this is False on all architectures and has to be
> + * explicity set during initialization.
> + *
> + * Returns: True if it is ACPI 'persistent' CPU
> + *
> + */
> +static inline bool acpi_persistent_cpu(CPUState *cpu)
> +{
> + /*
> + * returns if 'Presence' of the vCPU is persistent and should be simulated
> + * via ACPI even after vCPUs have been unplugged in QOM
> + */
> + return cpu && cpu->acpi_persistent;
> +}
> #endif
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index 04e9ad4996..299e96c45b 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -542,6 +542,27 @@ struct CPUState {
> CPUPluginState *plugin_state;
> #endif
>
> + /*
> + * To implement the vCPU hotplug feature (which simulates CPU hotplug
> + * behavior), we need to dynamically create and destroy QOM vCPU objects,
> + * and (de)associate them with pre-existing KVM vCPUs while (un)parking the
> + * KVM vCPU context. One challenge is ensuring that these dynamically
> + * appearing or disappearing QOM vCPU objects are accurately reflected
> + * through ACPI to the Guest Kernel. Due to architectural constraints,
> + * changing the number of vCPUs after the guest kernel has booted may not
> + * always be possible.
> + *
> + * In certain architectures, to provide the guest kernel with a *persistent*
> + * view of vCPU presence, even when the QOM does not have a corresponding
> + * vCPU object, ACPI may simulate the presence of vCPUs by marking them as
> + * ACPI-disabled. This is achieved by setting `_STA.PRES=True` and
> + * `_STA.Ena=False` for unplugged vCPUs in QEMU's QOM.
> + *
> + * By default, this flag is set to `FALSE`, and it must be explicitly set
> + * to `TRUE` for architectures like ARM.
> + */
> + bool acpi_persistent;
> +
> /* TODO Move common fields from CPUArchState here. */
> int cpu_index;
> int cluster_index;
next prev parent reply other threads:[~2024-10-16 21:02 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 19:22 [PATCH V1 0/4] Arch agnostic ACPI changes to support vCPU Hotplug (on Archs like ARM) Salil Mehta via
2024-10-14 19:22 ` [PATCH V1 1/4] hw/acpi: Initialize ACPI Hotplug CPU Status with Support for vCPU `Persistence` Salil Mehta via
2024-10-16 21:01 ` Gustavo Romero [this message]
2024-10-21 20:50 ` Salil Mehta
2024-10-17 5:27 ` Gavin Shan
2024-10-21 21:19 ` Salil Mehta
2024-10-17 5:35 ` Gavin Shan
2024-10-17 20:25 ` Gustavo Romero
2024-10-21 21:22 ` Salil Mehta
2024-10-18 14:11 ` Igor Mammedov
2024-10-21 21:50 ` Salil Mehta
2024-10-25 13:52 ` Igor Mammedov
2024-11-01 10:53 ` Salil Mehta via
2024-11-04 11:43 ` Salil Mehta via
2024-10-14 19:22 ` [PATCH V1 2/4] hw/acpi: Update ACPI CPU Status `is_{present, enabled}` during vCPU hot(un)plug Salil Mehta via
2024-10-18 14:18 ` Igor Mammedov
2024-10-22 23:02 ` Salil Mehta via
2024-10-14 19:22 ` [PATCH V1 3/4] hw/acpi: Reflect ACPI vCPU {present, enabled} states in ACPI _STA.{PRES, ENA} Bits Salil Mehta via
2024-10-18 5:12 ` [PATCH V1 3/4] hw/acpi: Reflect ACPI vCPU {present,enabled} states in ACPI _STA.{PRES,ENA} Bits Zhao Liu
2024-10-18 14:19 ` Igor Mammedov
2024-10-22 23:50 ` Salil Mehta via
2024-10-22 23:45 ` Salil Mehta via
2024-10-18 14:24 ` Igor Mammedov
2024-10-22 23:57 ` Salil Mehta via
2024-10-21 2:09 ` Gustavo Romero
2024-10-23 1:01 ` Salil Mehta via
2024-10-14 19:22 ` [PATCH V1 4/4] hw/acpi: Populate vCPU Hotplug VMSD to migrate `is_{present, enabled}` states Salil Mehta via
2024-10-18 14:31 ` [PATCH V1 4/4] hw/acpi: Populate vCPU Hotplug VMSD to migrate `is_{present,enabled}` states Igor Mammedov
2024-10-22 23:22 ` Salil Mehta via
2024-10-15 3:30 ` [PATCH V1 0/4] Arch agnostic ACPI changes to support vCPU Hotplug (on Archs like ARM) maobibo
2024-10-15 14:31 ` Salil Mehta via
2024-10-16 6:00 ` maobibo
2024-10-15 18:41 ` Miguel Luis
2024-10-18 17:57 ` Gustavo Romero
2024-10-21 8:04 ` Miguel Luis
2024-10-22 12:32 ` Gustavo Romero
2024-10-18 14:46 ` Igor Mammedov
2024-10-21 2:33 ` Gustavo Romero
2024-10-23 1:50 ` Salil Mehta via
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d4a0d78-f3cc-4644-a9ea-d02114c242b8@linaro.org \
--to=gustavo.romero@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=andrew.jones@linux.dev \
--cc=ardb@kernel.org \
--cc=borntraeger@linux.ibm.com \
--cc=darren@os.amperecomputing.com \
--cc=david@redhat.com \
--cc=eric.auger@redhat.com \
--cc=gshan@redhat.com \
--cc=harshpb@linux.ibm.com \
--cc=ilkka@os.amperecomputing.com \
--cc=imammedo@redhat.com \
--cc=jean-philippe@linaro.org \
--cc=jiakernel2@gmail.com \
--cc=jonathan.cameron@huawei.com \
--cc=karl.heubaum@oracle.com \
--cc=linux@armlinux.org.uk \
--cc=linuxarm@huawei.com \
--cc=lixianglai@loongson.cn \
--cc=lpieralisi@kernel.org \
--cc=maobibo@loongson.cn \
--cc=maz@kernel.org \
--cc=miguel.luis@oracle.com \
--cc=mst@redhat.com \
--cc=npiggin@gmail.com \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rafael@kernel.org \
--cc=richard.henderson@linaro.org \
--cc=salil.mehta@huawei.com \
--cc=salil.mehta@opnsrc.net \
--cc=shahuang@redhat.com \
--cc=vishnu@os.amperecomputing.com \
--cc=wangxiongfeng2@huawei.com \
--cc=wangyanan55@huawei.com \
--cc=will@kernel.org \
--cc=zhao1.liu@intel.com \
--cc=zhukeqian1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).