Skip to content

Commit cd92396

Browse files
jic23ctmarinas
authored andcommitted
ACPI: processor: Move checks and availability of acpi_processor earlier
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). Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/20240529133446.28446-7-Jonathan.Cameron@huawei.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 47ec9b4 commit cd92396

1 file changed

Lines changed: 52 additions & 36 deletions

File tree

drivers/acpi/acpi_processor.c

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,38 @@ static void __init acpi_pcc_cpufreq_init(void) {}
183183
#endif /* CONFIG_X86 */
184184

185185
/* Initialization */
186+
static DEFINE_PER_CPU(void *, processor_device_array);
187+
188+
static int acpi_processor_set_per_cpu(struct acpi_processor *pr,
189+
struct acpi_device *device)
190+
{
191+
BUG_ON(pr->id >= nr_cpu_ids);
192+
193+
/*
194+
* Buggy BIOS check.
195+
* ACPI id of processors can be reported wrongly by the BIOS.
196+
* Don't trust it blindly
197+
*/
198+
if (per_cpu(processor_device_array, pr->id) != NULL &&
199+
per_cpu(processor_device_array, pr->id) != device) {
200+
dev_warn(&device->dev,
201+
"BIOS reported wrong ACPI id %d for the processor\n",
202+
pr->id);
203+
return -EINVAL;
204+
}
205+
/*
206+
* processor_device_array is not cleared on errors to allow buggy BIOS
207+
* checks.
208+
*/
209+
per_cpu(processor_device_array, pr->id) = device;
210+
per_cpu(processors, pr->id) = pr;
211+
212+
return 0;
213+
}
214+
186215
#ifdef CONFIG_ACPI_HOTPLUG_CPU
187-
static int acpi_processor_hotadd_init(struct acpi_processor *pr)
216+
static int acpi_processor_hotadd_init(struct acpi_processor *pr,
217+
struct acpi_device *device)
188218
{
189219
int ret;
190220

@@ -198,8 +228,16 @@ static int acpi_processor_hotadd_init(struct acpi_processor *pr)
198228
if (ret)
199229
goto out;
200230

231+
ret = acpi_processor_set_per_cpu(pr, device);
232+
if (ret) {
233+
acpi_unmap_cpu(pr->id);
234+
goto out;
235+
}
236+
201237
ret = arch_register_cpu(pr->id);
202238
if (ret) {
239+
/* Leave the processor device array in place to detect buggy bios */
240+
per_cpu(processors, pr->id) = NULL;
203241
acpi_unmap_cpu(pr->id);
204242
goto out;
205243
}
@@ -217,7 +255,8 @@ static int acpi_processor_hotadd_init(struct acpi_processor *pr)
217255
return ret;
218256
}
219257
#else
220-
static inline int acpi_processor_hotadd_init(struct acpi_processor *pr)
258+
static inline int acpi_processor_hotadd_init(struct acpi_processor *pr,
259+
struct acpi_device *device)
221260
{
222261
return -ENODEV;
223262
}
@@ -232,6 +271,7 @@ static int acpi_processor_get_info(struct acpi_device *device)
232271
acpi_status status = AE_OK;
233272
static int cpu0_initialized;
234273
unsigned long long value;
274+
int ret;
235275

236276
acpi_processor_errata();
237277

@@ -315,12 +355,12 @@ static int acpi_processor_get_info(struct acpi_device *device)
315355
* NOTE: Even if the processor has a cpuid, it may not be present
316356
* because cpuid <-> apicid mapping is persistent now.
317357
*/
318-
if (invalid_logical_cpuid(pr->id) || !cpu_present(pr->id)) {
319-
int ret = acpi_processor_hotadd_init(pr);
320-
321-
if (ret)
322-
return ret;
323-
}
358+
if (invalid_logical_cpuid(pr->id) || !cpu_present(pr->id))
359+
ret = acpi_processor_hotadd_init(pr, device);
360+
else
361+
ret = acpi_processor_set_per_cpu(pr, device);
362+
if (ret)
363+
return ret;
324364

325365
/*
326366
* On some boxes several processors use the same processor bus id.
@@ -365,8 +405,6 @@ static int acpi_processor_get_info(struct acpi_device *device)
365405
* (cpu_data(cpu)) values, like CPU feature flags, family, model, etc.
366406
* Such things have to be put in and set up by the processor driver's .probe().
367407
*/
368-
static DEFINE_PER_CPU(void *, processor_device_array);
369-
370408
static int acpi_processor_add(struct acpi_device *device,
371409
const struct acpi_device_id *id)
372410
{
@@ -395,28 +433,6 @@ static int acpi_processor_add(struct acpi_device *device,
395433
if (result) /* Processor is not physically present or unavailable */
396434
goto err_clear_driver_data;
397435

398-
BUG_ON(pr->id >= nr_cpu_ids);
399-
400-
/*
401-
* Buggy BIOS check.
402-
* ACPI id of processors can be reported wrongly by the BIOS.
403-
* Don't trust it blindly
404-
*/
405-
if (per_cpu(processor_device_array, pr->id) != NULL &&
406-
per_cpu(processor_device_array, pr->id) != device) {
407-
dev_warn(&device->dev,
408-
"BIOS reported wrong ACPI id %d for the processor\n",
409-
pr->id);
410-
/* Give up, but do not abort the namespace scan. */
411-
goto err_clear_driver_data;
412-
}
413-
/*
414-
* processor_device_array is not cleared on errors to allow buggy BIOS
415-
* checks.
416-
*/
417-
per_cpu(processor_device_array, pr->id) = device;
418-
per_cpu(processors, pr->id) = pr;
419-
420436
dev = get_cpu_device(pr->id);
421437
if (!dev) {
422438
result = -ENODEV;
@@ -470,17 +486,17 @@ static void acpi_processor_remove(struct acpi_device *device)
470486
device_release_driver(pr->dev);
471487
acpi_unbind_one(pr->dev);
472488

473-
/* Clean up. */
474-
per_cpu(processor_device_array, pr->id) = NULL;
475-
per_cpu(processors, pr->id) = NULL;
476-
477489
cpu_maps_update_begin();
478490
cpus_write_lock();
479491

480492
/* Remove the CPU. */
481493
arch_unregister_cpu(pr->id);
482494
acpi_unmap_cpu(pr->id);
483495

496+
/* Clean up. */
497+
per_cpu(processor_device_array, pr->id) = NULL;
498+
per_cpu(processors, pr->id) = NULL;
499+
484500
cpus_write_unlock();
485501
cpu_maps_update_done();
486502

0 commit comments

Comments
 (0)