]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/acpi: Add acpi_get_cpu_uid() for unified ACPI CPU UID retrieval
authorChengwen Feng <fengchengwen@huawei.com>
Wed, 1 Apr 2026 08:16:36 +0000 (16:16 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 6 Apr 2026 14:55:15 +0000 (16:55 +0200)
As a step towards unifying the interface for retrieving ACPI CPU UID
across architectures, introduce a new function acpi_get_cpu_uid() for
x86. While at it, add input validation to make the code more robust.

Update Xen-related code to use acpi_get_cpu_uid() instead of the legacy
cpu_acpi_id() function, and remove the now-unused cpu_acpi_id() to clean
up redundant code.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Link: https://patch.msgid.link/20260401081640.26875-5-fengchengwen@huawei.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
arch/x86/include/asm/acpi.h
arch/x86/include/asm/cpu.h
arch/x86/include/asm/smp.h
arch/x86/kernel/acpi/boot.c
arch/x86/xen/enlighten_hvm.c

index a03aa6f999d1587a15273e871e5f9e72c2d7d8d4..92b5c27c4fea81b01d0eca2961d5f9bbca8fd2a7 100644 (file)
@@ -157,6 +157,8 @@ static inline bool acpi_has_cpu_in_madt(void)
        return !!acpi_lapic;
 }
 
+int acpi_get_cpu_uid(unsigned int cpu, u32 *uid);
+
 #define ACPI_HAVE_ARCH_SET_ROOT_POINTER
 static __always_inline void acpi_arch_set_root_pointer(u64 addr)
 {
index ad235dda1ded0f28099d71236c849d190ca33a06..57a0786dfd75dab2574c6fbf9a6dd503f5080f84 100644 (file)
@@ -11,7 +11,6 @@
 
 #ifndef CONFIG_SMP
 #define cpu_physical_id(cpu)                   boot_cpu_physical_apicid
-#define cpu_acpi_id(cpu)                       0
 #endif /* CONFIG_SMP */
 
 #ifdef CONFIG_HOTPLUG_CPU
index 84951572ab8170578ca5c4a3437c66e9809f34c2..05d1d479b4cf3dfbe10dc59e8c9e1857c91d09f0 100644 (file)
@@ -130,7 +130,6 @@ __visible void smp_call_function_interrupt(struct pt_regs *regs);
 __visible void smp_call_function_single_interrupt(struct pt_regs *r);
 
 #define cpu_physical_id(cpu)   per_cpu(x86_cpu_to_apicid, cpu)
-#define cpu_acpi_id(cpu)       per_cpu(x86_cpu_to_acpiid, cpu)
 
 /*
  * This function is needed by all SMP systems. It must _always_ be valid
index a3f2fb1fea1bc9b340fc4eef89d275345922a8b7..ceba24f65ae3a816f4d34e7dca391eef6f09cbee 100644 (file)
@@ -1848,3 +1848,23 @@ void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys, acpi_size size) =
        x86_acpi_os_ioremap;
 EXPORT_SYMBOL_GPL(acpi_os_ioremap);
 #endif
+
+int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
+{
+       u32 acpi_id;
+
+       if (cpu >= nr_cpu_ids)
+               return -EINVAL;
+
+#ifdef CONFIG_SMP
+       acpi_id = per_cpu(x86_cpu_to_acpiid, cpu);
+       if (acpi_id == CPU_ACPIID_INVALID)
+               return -ENODEV;
+#else
+       acpi_id = 0;
+#endif
+
+       *uid = acpi_id;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
index fe57ff85d004ba359677f66e0dc5c9337f5c015b..2f9fa27e5a3c230c65a7edbad075ad447318caea 100644 (file)
@@ -151,6 +151,7 @@ static void xen_hvm_crash_shutdown(struct pt_regs *regs)
 
 static int xen_cpu_up_prepare_hvm(unsigned int cpu)
 {
+       u32 cpu_uid;
        int rc = 0;
 
        /*
@@ -161,8 +162,8 @@ static int xen_cpu_up_prepare_hvm(unsigned int cpu)
         */
        xen_uninit_lock_cpu(cpu);
 
-       if (cpu_acpi_id(cpu) != CPU_ACPIID_INVALID)
-               per_cpu(xen_vcpu_id, cpu) = cpu_acpi_id(cpu);
+       if (acpi_get_cpu_uid(cpu, &cpu_uid) == 0)
+               per_cpu(xen_vcpu_id, cpu) = cpu_uid;
        else
                per_cpu(xen_vcpu_id, cpu) = cpu;
        xen_vcpu_setup(cpu);