x86: apic: Cleanup and simplify setup_local_APIC()

setup_local_APIC() is used to setup local APIC early during CPU
initialization and already assumes that preemption is disabled on
entry. However, The function unnecessarily disables and enables
preemption and uses smp_processor_id() multiple times in and out of
the nested preemption disabled section. This gives the wrong
impression that the function might be able to handle being called with
preemption enabled and/or migrated to another processor in the middle.

Make it clear that the function is always called with preemption
disabled, drop the confusing preemption disable block and call
smp_processor_id() once at the beginning of the function.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: brgerst@gmail.com
LKML-Reference: <4D00B3B9.7060702@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by Tejun Heo and committed by Thomas Gleixner 0aa002fe 0e3fa13f

+9 -12
+9 -12
arch/x86/kernel/apic/apic.c
··· 1195 oldvalue, value); 1196 } 1197 1198 - 1199 /** 1200 * setup_local_APIC - setup the local APIC 1201 */ 1202 void __cpuinit setup_local_APIC(void) 1203 { 1204 unsigned int value, queued; 1205 int i, j, acked = 0; 1206 unsigned long long tsc = 0, ntsc; ··· 1227 } 1228 #endif 1229 perf_events_lapic_init(); 1230 - 1231 - preempt_disable(); 1232 1233 /* 1234 * Double-check whether this APIC is really registered. ··· 1343 * TODO: set up through-local-APIC from through-I/O-APIC? --macro 1344 */ 1345 value = apic_read(APIC_LVT0) & APIC_LVT_MASKED; 1346 - if (!smp_processor_id() && (pic_mode || !value)) { 1347 value = APIC_DM_EXTINT; 1348 - apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", 1349 - smp_processor_id()); 1350 } else { 1351 value = APIC_DM_EXTINT | APIC_LVT_MASKED; 1352 - apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", 1353 - smp_processor_id()); 1354 } 1355 apic_write(APIC_LVT0, value); 1356 1357 /* 1358 * only the BP should see the LINT1 NMI signal, obviously. 1359 */ 1360 - if (!smp_processor_id()) 1361 value = APIC_DM_NMI; 1362 else 1363 value = APIC_DM_NMI | APIC_LVT_MASKED; ··· 1363 value |= APIC_LVT_LEVEL_TRIGGER; 1364 apic_write(APIC_LVT1, value); 1365 1366 - preempt_enable(); 1367 - 1368 #ifdef CONFIG_X86_MCE_INTEL 1369 /* Recheck CMCI information after local APIC is up on CPU #0 */ 1370 - if (smp_processor_id() == 0) 1371 cmci_recheck(); 1372 #endif 1373 }
··· 1195 oldvalue, value); 1196 } 1197 1198 /** 1199 * setup_local_APIC - setup the local APIC 1200 + * 1201 + * Used to setup local APIC while initializing BSP or bringin up APs. 1202 + * Always called with preemption disabled. 1203 */ 1204 void __cpuinit setup_local_APIC(void) 1205 { 1206 + int cpu = smp_processor_id(); 1207 unsigned int value, queued; 1208 int i, j, acked = 0; 1209 unsigned long long tsc = 0, ntsc; ··· 1224 } 1225 #endif 1226 perf_events_lapic_init(); 1227 1228 /* 1229 * Double-check whether this APIC is really registered. ··· 1342 * TODO: set up through-local-APIC from through-I/O-APIC? --macro 1343 */ 1344 value = apic_read(APIC_LVT0) & APIC_LVT_MASKED; 1345 + if (!cpu && (pic_mode || !value)) { 1346 value = APIC_DM_EXTINT; 1347 + apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", cpu); 1348 } else { 1349 value = APIC_DM_EXTINT | APIC_LVT_MASKED; 1350 + apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", cpu); 1351 } 1352 apic_write(APIC_LVT0, value); 1353 1354 /* 1355 * only the BP should see the LINT1 NMI signal, obviously. 1356 */ 1357 + if (!cpu) 1358 value = APIC_DM_NMI; 1359 else 1360 value = APIC_DM_NMI | APIC_LVT_MASKED; ··· 1364 value |= APIC_LVT_LEVEL_TRIGGER; 1365 apic_write(APIC_LVT1, value); 1366 1367 #ifdef CONFIG_X86_MCE_INTEL 1368 /* Recheck CMCI information after local APIC is up on CPU #0 */ 1369 + if (!cpu) 1370 cmci_recheck(); 1371 #endif 1372 }