Skip to content

Commit 3cfe889

Browse files
fengchengwenrafaeljw
authored andcommitted
x86/acpi: Add acpi_get_cpu_uid() for unified ACPI CPU UID retrieval
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>
1 parent 0c82319 commit 3cfe889

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

arch/x86/include/asm/acpi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ static inline bool acpi_has_cpu_in_madt(void)
157157
return !!acpi_lapic;
158158
}
159159

160+
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid);
161+
160162
#define ACPI_HAVE_ARCH_SET_ROOT_POINTER
161163
static __always_inline void acpi_arch_set_root_pointer(u64 addr)
162164
{

arch/x86/include/asm/cpu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#ifndef CONFIG_SMP
1313
#define cpu_physical_id(cpu) boot_cpu_physical_apicid
14-
#define cpu_acpi_id(cpu) 0
1514
#endif /* CONFIG_SMP */
1615

1716
#ifdef CONFIG_HOTPLUG_CPU

arch/x86/include/asm/smp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ __visible void smp_call_function_interrupt(struct pt_regs *regs);
130130
__visible void smp_call_function_single_interrupt(struct pt_regs *r);
131131

132132
#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
133-
#define cpu_acpi_id(cpu) per_cpu(x86_cpu_to_acpiid, cpu)
134133

135134
/*
136135
* This function is needed by all SMP systems. It must _always_ be valid

arch/x86/kernel/acpi/boot.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,3 +1848,23 @@ void __iomem * (*acpi_os_ioremap)(acpi_physical_address phys, acpi_size size) =
18481848
x86_acpi_os_ioremap;
18491849
EXPORT_SYMBOL_GPL(acpi_os_ioremap);
18501850
#endif
1851+
1852+
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
1853+
{
1854+
u32 acpi_id;
1855+
1856+
if (cpu >= nr_cpu_ids)
1857+
return -EINVAL;
1858+
1859+
#ifdef CONFIG_SMP
1860+
acpi_id = per_cpu(x86_cpu_to_acpiid, cpu);
1861+
if (acpi_id == CPU_ACPIID_INVALID)
1862+
return -ENODEV;
1863+
#else
1864+
acpi_id = 0;
1865+
#endif
1866+
1867+
*uid = acpi_id;
1868+
return 0;
1869+
}
1870+
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);

arch/x86/xen/enlighten_hvm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static void xen_hvm_crash_shutdown(struct pt_regs *regs)
151151

152152
static int xen_cpu_up_prepare_hvm(unsigned int cpu)
153153
{
154+
u32 cpu_uid;
154155
int rc = 0;
155156

156157
/*
@@ -161,8 +162,8 @@ static int xen_cpu_up_prepare_hvm(unsigned int cpu)
161162
*/
162163
xen_uninit_lock_cpu(cpu);
163164

164-
if (cpu_acpi_id(cpu) != CPU_ACPIID_INVALID)
165-
per_cpu(xen_vcpu_id, cpu) = cpu_acpi_id(cpu);
165+
if (acpi_get_cpu_uid(cpu, &cpu_uid) == 0)
166+
per_cpu(xen_vcpu_id, cpu) = cpu_uid;
166167
else
167168
per_cpu(xen_vcpu_id, cpu) = cpu;
168169
xen_vcpu_setup(cpu);

0 commit comments

Comments
 (0)