On Mon, 22 Apr 2024 20:56:55 +0200 "Rafael J. Wysocki" <rafael@xxxxxxxxxx> wrote: > 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. The bios bug mentioned in reply to patch 14 (DSDT entries for non existent CPUs that have no _STA entries) showed me that we need to know if this succeeded (I'd not read this at that point). I'll make it return a bool to say this succeeded and in both call sites return 0 if not to deal with the bios bug here. Making sure not to clear the per_cpu() structures unless this we get past that call. If we do and arch_register_cpu() fails we need to clear these two IDs. Doing so means that acpi_processor_hotadd_init() is side effect free and hence we can return in acpi_processor_get_info() which avoids the need to clear pointers when we don't have a valid pr->id to do it with. So fully agree we need to bail out properly if this fails. Jonathan