Skip to content

Commit eba4675

Browse files
jic23ctmarinas
authored andcommitted
arm64: arch_register_cpu() variant to check if an ACPI handle is now available.
The ARM64 architecture does not support physical CPU HP today. To avoid any possibility of a bug against such an architecture if defined in future, check for the physical CPU HP case (not present) and return an error on any such attempt. On ARM64 virtual CPU Hotplug relies on the status value that can be queried via the AML method _STA for the CPU object. There are two conditions in which the CPU can be registered. 1) ACPI disabled. 2) ACPI enabled and the acpi_handle is available. _STA evaluates to the CPU is both enabled and present. (Note that in absence of the _STA method they are always in this state). If neither of these conditions is met the CPU is not 'yet' ready to be used and -EPROBE_DEFER is returned. Success occurs in the early attempt to register the CPUs if we are booting with DT (no concept yet of vCPU HP) if not it succeeds for already enabled CPUs when the ACPI Processor driver attaches to them. Finally it may succeed via the CPU Hotplug code indicating that the CPU is now enabled. For ACPI if CONFIG_ACPI_PROCESSOR the only path to get to arch_register_cpu() with that handle set is via acpi_processor_hot_add_init() which is only called from an ACPI bus scan in which _STA has already been queried there is no need to repeat it here. Add a comment to remind us of this in the future. Suggested-by: Rafael J. Wysocki <[email protected]> Tested-by: Miguel Luis <[email protected]> Reviewed-by: Gavin Shan <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 643e12d commit eba4675

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

arch/arm64/kernel/smp.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,59 @@ static int __init smp_cpu_setup(int cpu)
511511
static bool bootcpu_valid __initdata;
512512
static unsigned int cpu_count = 1;
513513

514+
int arch_register_cpu(int cpu)
515+
{
516+
acpi_handle acpi_handle = acpi_get_processor_handle(cpu);
517+
struct cpu *c = &per_cpu(cpu_devices, cpu);
518+
519+
if (!acpi_disabled && !acpi_handle &&
520+
IS_ENABLED(CONFIG_ACPI_HOTPLUG_CPU))
521+
return -EPROBE_DEFER;
522+
523+
#ifdef CONFIG_ACPI_HOTPLUG_CPU
524+
/* For now block anything that looks like physical CPU Hotplug */
525+
if (invalid_logical_cpuid(cpu) || !cpu_present(cpu)) {
526+
pr_err_once("Changing CPU present bit is not supported\n");
527+
return -ENODEV;
528+
}
529+
#endif
530+
531+
/*
532+
* Availability of the acpi handle is sufficient to establish
533+
* that _STA has aleady been checked. No need to recheck here.
534+
*/
535+
c->hotpluggable = arch_cpu_is_hotpluggable(cpu);
536+
537+
return register_cpu(c, cpu);
538+
}
539+
540+
#ifdef CONFIG_ACPI_HOTPLUG_CPU
541+
void arch_unregister_cpu(int cpu)
542+
{
543+
acpi_handle acpi_handle = acpi_get_processor_handle(cpu);
544+
struct cpu *c = &per_cpu(cpu_devices, cpu);
545+
acpi_status status;
546+
unsigned long long sta;
547+
548+
if (!acpi_handle) {
549+
pr_err_once("Removing a CPU without associated ACPI handle\n");
550+
return;
551+
}
552+
553+
status = acpi_evaluate_integer(acpi_handle, "_STA", NULL, &sta);
554+
if (ACPI_FAILURE(status))
555+
return;
556+
557+
/* For now do not allow anything that looks like physical CPU HP */
558+
if (cpu_present(cpu) && !(sta & ACPI_STA_DEVICE_PRESENT)) {
559+
pr_err_once("Changing CPU present bit is not supported\n");
560+
return;
561+
}
562+
563+
unregister_cpu(c);
564+
}
565+
#endif /* CONFIG_ACPI_HOTPLUG_CPU */
566+
514567
#ifdef CONFIG_ACPI
515568
static struct acpi_madt_generic_interrupt cpu_madt_gicc[NR_CPUS];
516569

0 commit comments

Comments
 (0)