Skip to content

Commit 4705243

Browse files
committed
x86/apic: Use u32 for APIC IDs in global data
APIC IDs are used with random data types u16, u32, int, unsigned int, unsigned long. Make it all consistently use u32 because that reflects the hardware register width and fixup the most obvious usage sites of that. The APIC callbacks will be addressed separately. Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Juergen Gross <[email protected]> Tested-by: Sohil Mehta <[email protected]> Tested-by: Michael Kelley <[email protected]> Tested-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Zhang Rui <[email protected]> Reviewed-by: Arjan van de Ven <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9ff4275 commit 4705243

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

arch/x86/include/asm/apic.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extern int local_apic_timer_c2_ok;
5454
extern bool apic_is_disabled;
5555
extern unsigned int lapic_timer_period;
5656

57-
extern int cpuid_to_apicid[];
57+
extern u32 cpuid_to_apicid[];
5858

5959
extern enum apic_intr_mode_id apic_intr_mode;
6060
enum apic_intr_mode_id {
@@ -517,9 +517,9 @@ extern void generic_bigsmp_probe(void);
517517

518518
extern struct apic apic_noop;
519519

520-
static inline unsigned int read_apic_id(void)
520+
static inline u32 read_apic_id(void)
521521
{
522-
unsigned int reg = apic_read(APIC_ID);
522+
u32 reg = apic_read(APIC_ID);
523523

524524
return apic->get_apic_id(reg);
525525
}
@@ -544,7 +544,7 @@ extern int default_cpu_present_to_apicid(int mps_cpu);
544544

545545
#else /* CONFIG_X86_LOCAL_APIC */
546546

547-
static inline unsigned int read_apic_id(void) { return 0; }
547+
static inline u32 read_apic_id(void) { return 0; }
548548

549549
#endif /* !CONFIG_X86_LOCAL_APIC */
550550

arch/x86/include/asm/mpspec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern int mp_bus_id_to_type[MAX_MP_BUSSES];
3737

3838
extern DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
3939

40-
extern unsigned int boot_cpu_physical_apicid;
40+
extern u32 boot_cpu_physical_apicid;
4141
extern u8 boot_cpu_apic_version;
4242

4343
#ifdef CONFIG_X86_LOCAL_APIC

arch/x86/include/asm/processor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ extern int set_tsc_mode(unsigned int val);
693693

694694
DECLARE_PER_CPU(u64, msr_misc_features_shadow);
695695

696-
static inline u16 per_cpu_llc_id(unsigned int cpu)
696+
static inline u32 per_cpu_llc_id(unsigned int cpu)
697697
{
698698
return per_cpu(cpu_info.topo.llc_id, cpu);
699699
}
700700

701-
static inline u16 per_cpu_l2c_id(unsigned int cpu)
701+
static inline u32 per_cpu_l2c_id(unsigned int cpu)
702702
{
703703
return per_cpu(cpu_info.topo.l2c_id, cpu);
704704
}

arch/x86/include/asm/smp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
1818
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
1919
DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map);
2020

21-
DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid);
21+
DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid);
2222
DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid);
2323

2424
struct task_struct;

arch/x86/kernel/apic/apic.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ unsigned int num_processors;
7272
unsigned disabled_cpus;
7373

7474
/* Processor that is doing the boot up */
75-
unsigned int boot_cpu_physical_apicid __ro_after_init = BAD_APICID;
75+
u32 boot_cpu_physical_apicid __ro_after_init = BAD_APICID;
7676
EXPORT_SYMBOL_GPL(boot_cpu_physical_apicid);
7777

7878
u8 boot_cpu_apic_version __ro_after_init;
@@ -87,7 +87,7 @@ physid_mask_t phys_cpu_present_map;
8787
* disable_cpu_apicid=<int>, mostly used for the kdump 2nd kernel to
8888
* avoid undefined behaviour caused by sending INIT from AP to BSP.
8989
*/
90-
static unsigned int disabled_cpu_apicid __ro_after_init = BAD_APICID;
90+
static u32 disabled_cpu_apicid __ro_after_init = BAD_APICID;
9191

9292
/*
9393
* This variable controls which CPUs receive external NMIs. By default,
@@ -111,7 +111,7 @@ static inline bool apic_accessible(void)
111111
/*
112112
* Map cpu index to physical APIC ID
113113
*/
114-
DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid, BAD_APICID);
114+
DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_apicid, BAD_APICID);
115115
DEFINE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid, U32_MAX);
116116
EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid);
117117
EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_acpiid);
@@ -1765,7 +1765,7 @@ static void __x2apic_enable(void)
17651765
static int __init setup_nox2apic(char *str)
17661766
{
17671767
if (x2apic_enabled()) {
1768-
int apicid = native_apic_msr_read(APIC_ID);
1768+
u32 apicid = native_apic_msr_read(APIC_ID);
17691769

17701770
if (apicid >= 255) {
17711771
pr_warn("Apicid: %08x, cannot enforce nox2apic\n",
@@ -2318,11 +2318,11 @@ static int nr_logical_cpuids = 1;
23182318
/*
23192319
* Used to store mapping between logical CPU IDs and APIC IDs.
23202320
*/
2321-
int cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, };
2321+
u32 cpuid_to_apicid[] = { [0 ... NR_CPUS - 1] = BAD_APICID, };
23222322

23232323
bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
23242324
{
2325-
return phys_id == cpuid_to_apicid[cpu];
2325+
return phys_id == (u64)cpuid_to_apicid[cpu];
23262326
}
23272327

23282328
#ifdef CONFIG_SMP
@@ -2391,7 +2391,7 @@ static int allocate_logical_cpuid(int apicid)
23912391
return nr_logical_cpuids++;
23922392
}
23932393

2394-
static void cpu_update_apic(int cpu, int apicid)
2394+
static void cpu_update_apic(int cpu, u32 apicid)
23952395
{
23962396
#if defined(CONFIG_SMP) || defined(CONFIG_X86_64)
23972397
early_per_cpu(x86_cpu_to_apicid, cpu) = apicid;
@@ -2544,7 +2544,7 @@ static struct {
25442544
*/
25452545
int active;
25462546
/* r/w apic fields */
2547-
unsigned int apic_id;
2547+
u32 apic_id;
25482548
unsigned int apic_taskpri;
25492549
unsigned int apic_ldr;
25502550
unsigned int apic_dfr;

arch/x86/kernel/apic/ipi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void default_send_IPI_mask_logical(const struct cpumask *cpumask, int vector)
281281
}
282282

283283
#ifdef CONFIG_SMP
284-
static int convert_apicid_to_cpu(int apic_id)
284+
static int convert_apicid_to_cpu(u32 apic_id)
285285
{
286286
int i;
287287

@@ -294,7 +294,8 @@ static int convert_apicid_to_cpu(int apic_id)
294294

295295
int safe_smp_processor_id(void)
296296
{
297-
int apicid, cpuid;
297+
u32 apicid;
298+
int cpuid;
298299

299300
if (!boot_cpu_has(X86_FEATURE_APIC))
300301
return 0;

arch/x86/kernel/kvm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,13 @@ static bool pv_sched_yield_supported(void)
500500
static void __send_ipi_mask(const struct cpumask *mask, int vector)
501501
{
502502
unsigned long flags;
503-
int cpu, apic_id, icr;
504-
int min = 0, max = 0;
503+
int cpu, min = 0, max = 0;
505504
#ifdef CONFIG_X86_64
506505
__uint128_t ipi_bitmap = 0;
507506
#else
508507
u64 ipi_bitmap = 0;
509508
#endif
509+
u32 apic_id, icr;
510510
long ret;
511511

512512
if (cpumask_empty(mask))
@@ -1028,8 +1028,8 @@ arch_initcall(activate_jump_labels);
10281028
/* Kick a cpu by its apicid. Used to wake up a halted vcpu */
10291029
static void kvm_kick_cpu(int cpu)
10301030
{
1031-
int apicid;
10321031
unsigned long flags = 0;
1032+
u32 apicid;
10331033

10341034
apicid = per_cpu(x86_cpu_to_apicid, cpu);
10351035
kvm_hypercall2(KVM_HC_KICK_CPU, flags, apicid);

arch/x86/mm/numa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ s16 __apicid_to_node[MAX_LOCAL_APIC] = {
5656

5757
int numa_cpu_node(int cpu)
5858
{
59-
int apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
59+
u32 apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
6060

6161
if (apicid != BAD_APICID)
6262
return __apicid_to_node[apicid];
@@ -786,7 +786,7 @@ void __init init_gi_nodes(void)
786786
void __init init_cpu_to_node(void)
787787
{
788788
int cpu;
789-
u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
789+
u32 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
790790

791791
BUG_ON(cpu_to_apicid == NULL);
792792

0 commit comments

Comments
 (0)