Re: [PATCH v7 04/16] ACPI: processor: Move checks and availability of acpi_processor earlier

From: Rafael J. Wysocki
Date: Mon Apr 22 2024 - 14:57:18 EST


On Thu, Apr 18, 2024 at 3:56 PM Jonathan Cameron
<Jonathan.Cameron@xxxxxxxxxx> wrote:
>
> Make the per_cpu(processors, cpu) entries available earlier so that
> they are available in arch_register_cpu() as ARM64 will need access
> to the acpi_handle to distinguish between acpi_processor_add()
> and earlier registration attempts (which will fail as _STA cannot
> be checked).
>
> Reorder the remove flow to clear this per_cpu() after
> arch_unregister_cpu() has completed, allowing it to be used in
> there as well.
>
> Note that on x86 for the CPU hotplug case, the pr->id prior to
> acpi_map_cpu() may be invalid. Thus the per_cpu() structures
> must be initialized after that call or after checking the ID
> is valid (not hotplug path).
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> ---
> v7: Swap order with acpi_unmap_cpu() in acpi_processor_remove()
> to keep it in reverse order of the setup path. (thanks Salil)
> Fix an issue with placement of CONFIG_ACPI_HOTPLUG_CPU guards.
> v6: As per discussion in v5 thread, don't use the cpu->dev and
> make this data available earlier by moving the assignment checks
> int acpi_processor_get_info().
> ---
> drivers/acpi/acpi_processor.c | 78 +++++++++++++++++++++--------------
> 1 file changed, 46 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
> index ba0a6f0ac841..ac7ddb30f10e 100644
> --- a/drivers/acpi/acpi_processor.c
> +++ b/drivers/acpi/acpi_processor.c
> @@ -183,8 +183,36 @@ static void __init acpi_pcc_cpufreq_init(void) {}
> #endif /* CONFIG_X86 */
>
> /* Initialization */
> +static DEFINE_PER_CPU(void *, processor_device_array);
> +
> +static void acpi_processor_set_per_cpu(struct acpi_processor *pr,
> + struct acpi_device *device)
> +{
> + BUG_ON(pr->id >= nr_cpu_ids);
> + /*
> + * Buggy BIOS check.
> + * ACPI id of processors can be reported wrongly by the BIOS.
> + * Don't trust it blindly
> + */
> + if (per_cpu(processor_device_array, pr->id) != NULL &&
> + per_cpu(processor_device_array, pr->id) != device) {
> + dev_warn(&device->dev,
> + "BIOS reported wrong ACPI id %d for the processor\n",
> + pr->id);
> + /* Give up, but do not abort the namespace scan. */
> + return;

In this case the caller should make acpi_pricessor_add() return 0, I
think, because otherwise it will attempt to acpi_bind_one() "pr" to
"device" which will confuse things.

So I would make this return false to indicate that.

Or just fold it into the caller and do the error handling there.