x86: remove hardcoding of hard_smp_processor_id on UP systems From: Fernando Luis Vazquez Cao With the advent of kdump, the assumption that the boot CPU when booting an UP kernel is always the CPU with a hardware ID of 0 (usually referred to as BSP on some architectures) is not valid anymore. We can use the APIC to determine the hardware processor id when APIC support has been selected, independently of whether CONFIG_SMP is set or not. Signed-off-by: Fernando Luis Vazquez Cao Signed-off-by: Andi Kleen Cc: Andi Kleen Cc: Vivek Goyal Cc: "Eric W. Biederman" Cc: Richard Henderson Cc: Ivan Kokshaysky Acked-by: Paul Mackerras Cc: Benjamin Herrenschmidt Cc: Hirokazu Takata Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: "David S. Miller" Cc: Jeff Dike Cc: "Luck, Tony" Acked-by: Simon Horman Signed-off-by: Andrew Morton --- include/asm-alpha/smp.h | 1 + include/asm-i386/smp.h | 37 ++++++++++++++++++++++--------------- include/asm-m32r/smp.h | 6 +++++- include/asm-powerpc/smp.h | 1 + include/asm-s390/smp.h | 1 + include/asm-sparc/smp.h | 1 + include/asm-sparc64/smp.h | 1 + include/asm-um/smp.h | 4 ++++ include/asm-x86_64/smp.h | 14 +++++++------- include/linux/smp.h | 1 - 10 files changed, 43 insertions(+), 24 deletions(-) Index: linux/include/asm-alpha/smp.h =================================================================== --- linux.orig/include/asm-alpha/smp.h +++ linux/include/asm-alpha/smp.h @@ -51,6 +51,7 @@ int smp_call_function_on_cpu(void (*func #else /* CONFIG_SMP */ +#define hard_smp_processor_id() 0 #define smp_call_function_on_cpu(func,info,retry,wait,cpu) ({ 0; }) #endif /* CONFIG_SMP */ Index: linux/include/asm-m32r/smp.h =================================================================== --- linux.orig/include/asm-m32r/smp.h +++ linux/include/asm-m32r/smp.h @@ -108,6 +108,10 @@ extern unsigned long send_IPI_mask_phys( #define IPI_SHIFT (0) #define NR_IPIS (8) -#endif /* CONFIG_SMP */ +#else /* CONFIG_SMP */ + +#define hard_smp_processor_id() 0 + +#endif /* CONFIG_SMP */ #endif /* _ASM_M32R_SMP_H */ Index: linux/include/asm-powerpc/smp.h =================================================================== --- linux.orig/include/asm-powerpc/smp.h +++ linux/include/asm-powerpc/smp.h @@ -83,6 +83,7 @@ extern void __cpu_die(unsigned int cpu); #else /* for UP */ +#define hard_smp_processor_id() 0 #define smp_setup_cpu_maps() #endif /* CONFIG_SMP */ Index: linux/include/asm-s390/smp.h =================================================================== --- linux.orig/include/asm-s390/smp.h +++ linux/include/asm-s390/smp.h @@ -113,6 +113,7 @@ static inline void smp_send_stop(void) __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK); } +#define hard_smp_processor_id() 0 #define smp_cpu_not_running(cpu) 1 #define smp_get_cpu(cpu) ({ 0; }) #define smp_put_cpu(cpu) ({ 0; }) Index: linux/include/asm-sparc/smp.h =================================================================== --- linux.orig/include/asm-sparc/smp.h +++ linux/include/asm-sparc/smp.h @@ -165,6 +165,7 @@ void smp_setup_cpu_possible_map(void); #else /* SMP */ +#define hard_smp_processor_id() 0 #define smp_setup_cpu_possible_map() do { } while (0) #endif /* !(SMP) */ Index: linux/include/asm-sparc64/smp.h =================================================================== --- linux.orig/include/asm-sparc64/smp.h +++ linux/include/asm-sparc64/smp.h @@ -47,6 +47,7 @@ extern void smp_setup_cpu_possible_map(v #else +#define hard_smp_processor_id() 0 #define smp_setup_cpu_possible_map() do { } while (0) #endif /* !(CONFIG_SMP) */ Index: linux/include/asm-um/smp.h =================================================================== --- linux.orig/include/asm-um/smp.h +++ linux/include/asm-um/smp.h @@ -24,6 +24,10 @@ extern inline void smp_cpus_done(unsigne extern struct task_struct *idle_threads[NR_CPUS]; +#else + +#define hard_smp_processor_id() 0 + #endif #endif Index: linux/include/linux/smp.h =================================================================== --- linux.orig/include/linux/smp.h +++ linux/include/linux/smp.h @@ -83,7 +83,6 @@ void smp_prepare_boot_cpu(void); * These macros fold the SMP functionality into a single CPU system */ #define raw_smp_processor_id() 0 -#define hard_smp_processor_id() 0 static inline int up_smp_call_function(void) { return 0; Index: linux/include/asm-i386/smp.h =================================================================== --- linux.orig/include/asm-i386/smp.h +++ linux/include/asm-i386/smp.h @@ -124,20 +124,6 @@ static inline int num_booting_cpus(void) return cpus_weight(cpu_callout_map); } -#ifdef CONFIG_X86_LOCAL_APIC - -#ifdef APIC_DEFINITION -extern int hard_smp_processor_id(void); -#else -#include -static inline int hard_smp_processor_id(void) -{ - /* we don't want to mark this access volatile - bad code generation */ - return GET_APIC_ID(*(unsigned long *)(APIC_BASE+APIC_ID)); -} -#endif -#endif - extern int safe_smp_processor_id(void); extern int __cpu_disable(void); extern void __cpu_die(unsigned int cpu); @@ -152,10 +138,31 @@ extern unsigned int num_processors; #define NO_PROC_ID 0xFF /* No processor magic marker */ -#endif +#endif /* CONFIG_SMP */ #ifndef __ASSEMBLY__ +#ifdef CONFIG_X86_LOCAL_APIC + +#ifdef APIC_DEFINITION +extern int hard_smp_processor_id(void); +#else +#include +static inline int hard_smp_processor_id(void) +{ + /* we don't want to mark this access volatile - bad code generation */ + return GET_APIC_ID(*(unsigned long *)(APIC_BASE+APIC_ID)); +} +#endif /* APIC_DEFINITION */ + +#else /* CONFIG_X86_LOCAL_APIC */ + +#ifndef CONFIG_SMP +#define hard_smp_processor_id() 0 +#endif + +#endif /* CONFIG_X86_LOCAL_APIC */ + extern u8 apicid_2_node[]; #ifdef CONFIG_X86_LOCAL_APIC Index: linux/include/asm-x86_64/smp.h =================================================================== --- linux.orig/include/asm-x86_64/smp.h +++ linux/include/asm-x86_64/smp.h @@ -57,12 +57,6 @@ static inline int num_booting_cpus(void) #define raw_smp_processor_id() read_pda(cpunumber) -static inline int hard_smp_processor_id(void) -{ - /* we don't want to mark this access volatile - bad code generation */ - return GET_APIC_ID(*(unsigned int *)(APIC_BASE+APIC_ID)); -} - extern int __cpu_disable(void); extern void __cpu_die(unsigned int cpu); extern void prefill_possible_map(void); @@ -71,7 +65,13 @@ extern unsigned __cpuinitdata disabled_c #define NO_PROC_ID 0xFF /* No processor magic marker */ -#endif +#endif /* CONFIG_SMP */ + +static inline int hard_smp_processor_id(void) +{ + /* we don't want to mark this access volatile - bad code generation */ + return GET_APIC_ID(*(unsigned int *)(APIC_BASE+APIC_ID)); +} /* * Some lowlevel functions might want to know about