Hello!
v0.1? Yeah, this is v0 from gitlab, rebased onto v6.0-rc3.
This series has only been lightly tested....
---
Hello!
This series adds what looks like cpuhotplug support to arm64 for use in
virtual machines. It does this by moving the cpu_register() calls for
architectures that support ACPI out of the arch code by using
GENERIC_CPU_DEVICES, then into the ACPI processor driver.
The kubernetes folk really want to be able to add CPUs to an existing VM,
in exactly the same way they do on x86. The use-case is pre-booting guests
with one CPU, then adding the number that were actually needed when the
workload is provisioned.
Wait? Doesn't arm64 support cpuhotplug already!?
In the arm world, cpuhotplug gets used to mean removing the power from a CPU.
The CPU is offline, and remains present. For x86, and ACPI, cpuhotplug
has the additional step of physically removing the CPU, so that it isn't
present anymore.
Arm64 doesn't support this, and can't support it: CPUs are really a slice
of the SoC, and there is not enough information in the existing ACPI tables
to describe which bits of the slice also got removed. Without a reference
machine adding this support to the spec is a wild goose chase.
Critically: everything described in the firmware tables must remain present.
For a virtual machine this is easy as all the other bits of 'virtual SoC'
are emulated, so they can (and do) remain present when a vCPU is 'removed'.
On a system that supports cpuhotplug the MADT has to describe every possible
CPU at boot. Under KVM, the vGIC needs to know about every possible vCPU before
the guest is started.
With these constraints, virtual-cpuhotplug is really just a hypervisor/firmware
policy about which CPUs can be brought online.
This series adds support for virtual-cpuhotplug as exactly that: firmware
policy. This may even work on a physical machine too; for a guest the part of
firmware is played by the VMM. (typically Qemu).
PSCI support is modified to return 'DENIED' if the CPU can't be brought
online/enabled yet. The CPU object's _STA method's enabled bit is used to
indicate firmware's current disposition. If the CPU has its enabled bit clear,
it will not be registered with sysfs, and attempts to bring it online will
fail. The notifications that _STA has changed its value then work in the same
way, and firmware can cause the CPU to be registered some time later, allowing
it to be brought online.
This creates something that looks like cpuhotplug to user-space, as the sysfs
files appear and disappear, and the udev notifications look the same.
One notable difference is the CPU present mask, which is exposed via sysfs.
Because the CPUs remain present throughout, they can still be seen in that mask.
This value does get used by webbrowsers to estimate the number of CPUs
as the CPU online mask is constantly changed on mobile phones.
Linux is tolerant of PSCI returning errors, as its always been allowed to do
that. To avoid confusing OS that can't tolerate this, we'd need an additional
bit in the MADT GICC flags. This series copies ACPI_MADT_ONLINE_CAPABLE, which
appears to be for this purpose, but calls it ACPI_MADT_GICC_CPU_CAPABLE as it
has a different bit position in the GICC.
I assume all x86 firmware vendors set the ENABLED bit in the CPU object's _STA
method. This code is unconditionally enabled for all ACPI architectures.
If there are problems with firmware tables on some devices, the CPUs will
already be online by the time the acpi_processor_make_enabled() is called.
A mismatch here causes a firmware-bug message and kernel taint. This should
only affect people with broken firmware who also boot with maxcpus=1, and
bring CPUs online later.
I had a go at switching the remaining architectures over to GENERIC_CPU_DEVICES,
so that the Kconfig symbol can be removed, but I got stuck with powerpc
and s390.
Thanks,
James Morse (22):
ACPI: Move ACPI_HOTPLUG_CPU to be enabled per architecture
drivers: base: Use present CPUs in GENERIC_CPU_DEVICES
drivers: base: Allow parts of GENERIC_CPU_DEVICES to be overridden
drivers: base: Move node_dev_init() before cpu_dev_init()
arm64: setup: Switch over to GENERIC_CPU_DEVICES using
arch_register_cpu()
ia64/topology: Switch over to GENERIC_CPU_DEVICES
x86/topology: Switch over to GENERIC_CPU_DEVICES
LoongArch: Switch over to GENERIC_CPU_DEVICES
ACPI: processor: Register all CPUs from acpi_processor_get_info()
ACPI: Rename ACPI_HOTPLUG_CPU to include 'present'
ACPI: Rename acpi_processor_hotadd_init and remove pre-processor
guards
ACPI: Check _STA present bit before making CPUs not present
ACPI: Warn when the present bit changes but the feature is not enabled
drivers: base: Implement weak arch_unregister_cpu()
LoongArch: Use the __weak version of arch_unregister_cpu()
arm64: acpi: Move get_cpu_for_acpi_id() to a header
ACPICA: Add new MADT GICC flags fields [code first?]
arm64, irqchip/gic-v3, ACPI: Move MADT GICC enabled check into a
helper
irqchip/gic-v3: Don't return errors from gic_acpi_match_gicc()
irqchip/gic-v3: Add support for ACPI's disabled but 'online capable'
CPUs
ACPI: add support to register CPUs based on the _STA enabled bit
arm64: document virtual CPU hotplug's expectations
Jean-Philippe Brucker (3):
arm64: psci: Ignore DENIED CPUs
KVM: arm64: Pass hypercalls to userspace
KVM: arm64: Pass PSCI calls to userspace
Documentation/arm64/cpu-hotplug.rst | 79 ++++++++++++++++++
Documentation/arm64/index.rst | 1 +
Documentation/virt/kvm/api.rst | 31 ++++++-
Documentation/virt/kvm/arm/hypercalls.rst | 1 +
arch/arm64/Kconfig | 1 +
arch/arm64/include/asm/acpi.h | 11 +++
arch/arm64/include/asm/cpu.h | 1 -
arch/arm64/include/asm/kvm_host.h | 2 +
arch/arm64/kernel/acpi_numa.c | 11 ---
arch/arm64/kernel/psci.c | 2 +-
arch/arm64/kernel/setup.c | 13 +--
arch/arm64/kernel/smp.c | 5 +-
arch/arm64/kvm/arm.c | 15 +++-
arch/arm64/kvm/hypercalls.c | 28 ++++++-
arch/arm64/kvm/psci.c | 13 +++
arch/ia64/Kconfig | 2 +
arch/ia64/include/asm/acpi.h | 2 +-
arch/ia64/include/asm/cpu.h | 11 ---
arch/ia64/kernel/acpi.c | 6 +-
arch/ia64/kernel/setup.c | 2 +-
arch/ia64/kernel/topology.c | 35 ++------
arch/loongarch/Kconfig | 2 +
arch/loongarch/kernel/topology.c | 31 +------
arch/x86/Kconfig | 2 +
arch/x86/include/asm/cpu.h | 6 --
arch/x86/kernel/acpi/boot.c | 4 +-
arch/x86/kernel/topology.c | 19 +----
drivers/acpi/Kconfig | 5 +-
drivers/acpi/acpi_processor.c | 99 ++++++++++++++++-------
drivers/acpi/processor_core.c | 2 +-
drivers/base/cpu.c | 21 +++--
drivers/base/init.c | 2 +-
drivers/firmware/psci/psci.c | 2 +
drivers/irqchip/irq-gic-v3.c | 38 +++++----
include/acpi/actbl2.h | 1 +
include/kvm/arm_hypercalls.h | 1 +
include/kvm/arm_psci.h | 4 +
include/linux/acpi.h | 10 ++-
include/linux/cpu.h | 6 ++
include/uapi/linux/kvm.h | 2 +
40 files changed, 339 insertions(+), 190 deletions(-)
create mode 100644 Documentation/arm64/cpu-hotplug.rst
--
2.30.2
Hi,
We don't have any topics for the meeting today, so let's cancel it.
The time slot we've allocated for this meeting is either bad or worse
for me so I'd like to try and find a new time slot. Please use the
doodle link [1] below to record your preferences. The doodle poll is
public so feel free to email me directly instead in case you're more
comfortable with that. This is my first time creating a doodle poll,
so apologies if I've made a mess of it.
As noted in the poll we're looking for a day and time in the fourth
week of the month. We're using the CET time zone as many of us are in
the time zone.
If you can't find any time that works for you please send me a mail
with more suitable times and I'll try to work out something. Let's
give this a week or so to possibly settle on a new time slot.
[1] https://doodle.com/meeting/participate/id/dJqR4Eyb
Thanks,
Jens
Hi Jonathan,Lorenzo,all,
Do we have any topic to sync next week?
Thanks:)
Joyce
> 在 2022年9月13日,上午8:00,linaro-open-discussions-request@op-lists.linaro.org 写道:
>
> Send Linaro-open-discussions mailing list submissions to
> linaro-open-discussions(a)op-lists.linaro.org
>
> To subscribe or unsubscribe via email, send a message with subject or
> body 'help' to
> linaro-open-discussions-request(a)op-lists.linaro.org
>
> You can reach the person managing the list at
> linaro-open-discussions-owner(a)op-lists.linaro.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Linaro-open-discussions digest..."
>
> Today's Topics:
>
> 1. Re: [RFC PATCH v0.1 22/25] ACPI: add support to register CPUs based on the _STA enabled bit
> (Salil Mehta)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 12 Sep 2022 18:09:34 +0000
> From: Salil Mehta <salil.mehta(a)huawei.com>
> Subject: [Linaro-open-discussions] Re: [RFC PATCH v0.1 22/25] ACPI:
> add support to register CPUs based on the _STA enabled bit
> To: James Morse <james.morse(a)arm.com>,
> "linaro-open-discussions(a)op-lists.linaro.org"
> <linaro-open-discussions(a)op-lists.linaro.org>
> Cc: "lorenzo.pieralisi(a)linaro.org" <lorenzo.pieralisi(a)linaro.org>
> Message-ID: <65c52e8ba75e4cc59ec4b88a44c8a13b(a)huawei.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi James
>
>> From: James Morse [mailto:james.morse@arm.com]
>> Sent: Friday, September 9, 2022 5:53 PM
>> To: Salil Mehta <salil.mehta(a)huawei.com>;
>> linaro-open-discussions(a)op-lists.linaro.org
>> Cc: lorenzo.pieralisi(a)linaro.org; Jean-Philippe Brucker
>> <jean-philippe(a)linaro.org>; Jonathan Cameron <jonathan.cameron(a)huawei.com>
>> Subject: Re: [RFC PATCH v0.1 22/25] ACPI: add support to register CPUs based
>> on the _STA enabled bit
>>
>> Hi Salil,
>>
>> On 09/09/2022 15:53, Salil Mehta wrote:
>>>> From: James Morse [mailto:james.morse@arm.com]
>>>> Sent: Wednesday, August 31, 2022 12:09 PM
>>>> To: linaro-open-discussions(a)op-lists.linaro.org
>>>> Cc: Salil Mehta <salil.mehta(a)huawei.com>; james.morse(a)arm.com;
>>>> lorenzo.pieralisi(a)linaro.org; Jean-Philippe Brucker
>>>> <jean-philippe(a)linaro.org>
>>>> Subject: [RFC PATCH v0.1 22/25] ACPI: add support to register CPUs based on
>> the
>>>> _STA enabled bit
>>>>
>>>> acpi_processor_get_info() registers all present CPUs. Registering a
>>>> CPU is what creates the sysfs entries and triggers the udev
>>>> notifications.
>>>>
>>>> arm64 virtual machines that support 'virtual cpu hotplug' use the
>>>> enabled bit to indicate whether the CPU can be brought online, as
>>>> the existing ACPI tables require all hardware to be described and
>>>> present.
>>>>
>>>> If firmware describes a CPU as present, but disabled, skip the
>>>> registration. Such CPUs are present, but can't be brought online for
>>>> whatever reason. (e.g. firmware/hypervisor policy).
>>>>
>>>> Once firmware sets the enabled bit, the CPU can be registered and
>>>> brought online by user-space. Online CPUs, or CPUs that are missing
>>>> an _STA method must always be registered.
>>
>>>> diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
>>>> index 1bd6e4b8ab66..42521d89c378 100644
>>>> --- a/drivers/acpi/acpi_processor.c
>>>> +++ b/drivers/acpi/acpi_processor.c
>>>> @@ -194,6 +194,32 @@ static int acpi_processor_make_present(struct
>>>> acpi_processor *pr)
>>>> return ret;
>>>> }
>>>>
>>>> +static int acpi_processor_make_enabled(struct acpi_processor *pr)
>>>> +{
>>>> + unsigned long long sta;
>>>> + acpi_status status;
>>>> + bool present, enabled;
>>>> +
>>>> + if (!acpi_has_method(pr->handle, "_STA"))
>>>> + return arch_register_cpu(pr->id);
>>>> +
>>>> + status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
>>>> + if (ACPI_FAILURE(status))
>>>> + return -ENODEV;
>>>> +
>>>> + present = sta & ACPI_STA_DEVICE_PRESENT;
>>>> + enabled = sta & ACPI_STA_DEVICE_ENABLED;
>>>> +
>>>> + if (cpu_online(pr->id) && (!present || !enabled)) {
>>>> + pr_err_once(FW_BUG "CPU %u is online, but described as not present
>> or
>>>> disabled!\n", pr->id);
>>>> + add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
>>>> + } else if (!present || !enabled) {
>>>> + return -ENODEV;
>>>> + }
>>
>>> This change and setting all possible cpus as *present* in smp_prepare_cpus()
>>> will always cause all present == possible in the guest kernel.
>>
>> This is quite deliberate. I don't want to redefine present without a machine
>> that actually
>> supports hotplug/package-hotadd. This stuff is the tip of an ill-defined iceberg
>> in the
>> ACPI spec. Once there is hardware that supports this, we will have a better idea
>> of what
>> needs changing. Until then: everything described by ACPI must be present.
>
>
> Present mask operates on the logical cpuids. Later are more closely related to
> the Linux abstract model. I see no problem in masking certain available devices(in
> this case cpus) from upper user. This is done at many places inside the kernel to
> intentionally not/conditionally expose certain devices to user even after getting
> discovered at the boot time or later.
>
> As such, this change can co-exists irrespective of whether Hotplug or Hotadd will
> ever exist in the system.
>
> I agree with the ACPI part and maybe interface is broken but then you have used
> ACPI_STA_DEVICE_ENABLED which has not been used yet in acpi_processor.c code
> which is ACPI related. How can you make sure this bit is being set by firmware
> of other architectures, especially legacy?
>
>
>>> I think we
>>> can avoid that by the trick which Jean-Phillipe exploited in his patch-set[1]
>>> sent earlier last year.
>>
>> That was the other side of this:
>> https://gitlab.arm.com/linux-arm/linux-jm/-/commit/3106cccf5b9f01f44789b748
>> aaee3a95fee99a97
>>
>> This was an attempt to do all this without changes to the ACPI spec - it doesn't
>> touch the
>> present cpumask.
>
>
> Yes, I did refer those but the idea was not to use that change as it is.
>
>
>> [..]
>>
>>> This shall ensure that we correctly reflect only present vcpus to the linux
>>> kernel although the sizing and initialization of the GICC/GICR would have
>>> already happened for the complete set for possible vcpus i.e. the ones with
>>>
>>> [1] _STA[0] is set & _STA[1] bit is set and
>>> [2] Either GICC_flag_Intf_Flag.Enabled set OR GICC_flag.online_capable set
>>>
>>> so effectively we are only deferring populating the cpu present mask for the
>>> disabled cpus but which are now online capable(or Hotplug capable in future?)
>>
>> What is the user observable effect of the kernel knowing this CPUs are really
>> present?
>
> User Interface looks inconsistent and can break existing scripts.
>
> As you can see, user requested max possible cpus(=6) and cold booted cpus(=4)
> Hence, the number of cpus directories correctly being shown are 4 but then
> total number of cpus present are being shown as 6 (i.e. 0-5).
>
> If we can defer the registration of the disabled cpus (but are online capable
> i.e. for possible - present) then I don’t see why we can't mask availability
> of these cpus by not marking them as present to user so that the entries
> are consistent. With this scripts/utils using these values can go horribly
> wrong.
>
> At Guest Kernel
> ---------------
> estuary:/$ ls -al /sys/devices/system/cpu/
> total 0
> drwxr-xr-x 12 root 0 0 Sep 9 19:19 .
> drwxr-xr-x 8 root 0 0 Sep 9 19:19 ..
> drwxr-xr-x 7 root 0 0 Sep 9 19:19 cpu0
> drwxr-xr-x 7 root 0 0 Sep 9 19:19 cpu1
> drwxr-xr-x 7 root 0 0 Sep 9 19:19 cpu2
> drwxr-xr-x 7 root 0 0 Sep 9 19:19 cpu3
> drwxr-xr-x 2 root 0 0 Sep 9 19:19 cpufreq
> drwxr-xr-x 2 root 0 0 Sep 9 19:19 cpuidle
> [...]
>
> estuary:/$ cat /sys/devices/system/cpu/possible
> 0-5
> estuary:/$ cat /sys/devices/system/cpu/present
> 0-5
> estuary:/$ cat /sys/devices/system/cpu/offline
> 4-5
> estuary:/$
>
> At Qemu
> -------
> $QEMUBIN --enable-kvm -machine virt,gic-version=3 -cpu host -smp cpus=4,maxcpus=6
> -append "console=ttyAMA0 root=/dev/ram earlycon rdinit=/init maxcpus=4 acpi=force"
>
>
>> The intention of this series is to do this as pure policy.
>>
>> I anticipate pressure on the "use the MADT GICR" line, even though ACPI doesn't
>> say
>> anything about the presence of MADT GICC's redistributor entry. If this happens,
>> we'd
>> depend on present meaning present.
>
>
> If we are confident that flag ACPI_STA_DEVICE_ENABLED is being set properly by
> ARM and other architecture firmware, then Qemu can take care of that policy. It
> has all the information of the vcpus which are possible and disabled (but are
> online capable). We can use this info to conditionally return appropriate status
> when _STA ACPI method is evaluated.
>
> I intentionally refrained to use the this approach in my first RFC[1] as the
> default code in the acpi_processor.c was only making use of the
> ACPI_STA_DEVICE_PRESENT bit after evaluation of _STA method. Qemu was also
> setting only present bit in the returned status value. Plus, I wanted to
> minimize the changes in the kernel in the first version of the RFC.
>
>
> [1] https://lore.kernel.org/qemu-devel/38a034f82da78b8861af6d25a83fddea@kernel.…
>
>>
>> All the hotplug/package-hotadd machinery is triggered by udev. We don't need
>> to hack the
>> cpu present mask to make that work.
>
>
> May I know what exactly are your apprehensions with 'udev'?
>
> As such 'udev' should make use of the Linux device model and it is not necessary
> to present 1:1 picture of the hardware to the abstract model(and which by the way
> we are not doing by not registering the disabled cpus). It will just expose that
> limited picture of the hardware to the user whatever is being presented by the
> kernel.
>
> AFAICS it should work just fine but we need to limit the present cpus.
>
>
>>> Question:
>>> Q1: Current acpi_processor.c code is not using ACPI_STA_DEVICE_{ENABLED, UI}
>>> bits. Could it break other architecture if we use these bits but some of their
>>> legacy devices or firmware does not initialize these bits to their defaults?
>>
>> Almost certainly! I'm pretty confident some vendors generate their ACPI tables
>> using
>> markov-models. (It boots! Ship it!)
>>
>> The approach that used the UI bit to mean sysfs had to be hidden behind a Kconfig
>> symbol,
>> which is only marginally better than #ifdef CONFIG_ARM64.
>
>
> If there are problems in using the ACPI_STA_DEVICE_UI Bit because it might
> conflict with the legacy firmware of other architectures then let us drop that.
>
> We can alternatively use the ACPI_STA_DEVICE_ENABLED Bit in the _STA method
> which can be conditionally set by the Qemu?
>
>
>> This new version walks a fine line described in the cover-letter: any platform
>> with
>> firmware tables that get this wrong should get the same user-experience as there
>> is no
>> policy enforcement on x86, so the !online_capable CPUs can be detected as being
>> online,
>> and the policy stuff gets ignored.
>
> Yes, I do understand your predicament, but ideally user experience is dictated
> by what *end* user sees. Here, by not masking the disabled cpus in the cpu present
> mask user will not have similar experience on ARM64 and x86_64 platforms and that
> is undeniable and will in the end matter the most since this feature will mostly
> be used on the servers.
>
>
> Thanks
> Salil
>
> ------------------------------
>
> Subject: Digest Footer
>
> Linaro-open-discussions mailing list -- linaro-open-discussions(a)op-lists.linaro.org
> To unsubscribe send an email to linaro-open-discussions-leave(a)op-lists.linaro.org
>
>
> ------------------------------
>
> End of Linaro-open-discussions Digest, Vol 24, Issue 4
> ******************************************************
Hi all,
in the meeting held today we decided to go ahead as follows in relation
to ARM64 virt CPU hotplug patches and QEmu changes:
- James requires QEmu changes to test his branch[1]
- Huawei (Salil) agreed to upgrade the QEmu patches to the latest ACPI
specs (and James' code [1])
- QEmu updates will be given with a branch/link in reply to this email thread
so that James can complete [1] testing against them
- Any testing, bug report, communication will take place through this
mailing list before public posting on a kernel ML, so please keep an
eye on this thread if you'd like to collaborate/help
- It would be good to get some feedback from containers/kubernetes
developers on the full software stack - after all we are making these
changes to enable the ecosystem
Please chime in if I forgot something or reach out, all comments are
welcome.
Lorenzo
[1] https://gitlab.arm.com/linux-arm/linux-jm/-/tree/virtual_cpu_hotplug/rfc/v0