FRV: Fix the section attribute on UP DECLARE_PER_CPU()
Subsystems (6)
PATCH 1/2 FRV: Fix the section attribute on UP DECLARE_PER_CPU()
In non-SMP mode, the variable section attribute specified by DECLARE_PER_CPU() does not agree with that specified by DEFINE_PER_CPU(). This means that architectures that have a small data section references relative to a base register may throw up linkage errors due to too great a displacement between where the base register points and the per-CPU variable.
On FRV, the .h declaration says that the variable is in the .sdata section, but the .c definition says it's actually in the .data section. The linker throws up the following errors:
kernel/built-in.o: In function `release_task':kernel/exit.c:78: relocation truncated to fit: R_FRV_GPREL12 against symbol per_cpu__process_counts' defined in .data section in kernel/built-in.o kernel/exit.c:78: relocation truncated to fit: R_FRV_GPREL12 against symbol per_cpu__process_counts' defined in .data section in kernel/built-in.o
To fix this, DECLARE_PER_CPU() should simply apply the same section attribute as does DEFINE_PER_CPU(). However, this is made slightly more complex by virtue of the fact that there are several variants on DEFINE, so these need to be matched by variants on DECLARE.
---
arch/alpha/include/asm/percpu.h | 2 +- arch/ia64/include/asm/smp.h | 2 +- arch/x86/include/asm/desc.h | 2 +- arch/x86/include/asm/hardirq.h | 2 +- arch/x86/include/asm/processor.h | 6 +++-- arch/x86/include/asm/tlbflush.h | 2 +- include/asm-generic/percpu.h | 43 ++++++++++++++++++++++++++++++++++++-- include/linux/percpu.h | 24 --------------------- net/rds/rds.h | 2 +- 9 files changed, 50 insertions(+), 35 deletions(-)
arch/alpha/include/asm/percpu.h +1 -1
@@ -73,6 +73,6 @@ extern unsigned long __per_cpu_offset[NR_CPUS];#endif /* SMP */ -#define DECLARE_PER_CPU (type, name) extern __typeof__(type) per_cpu_var(name) +#include <asm-generic/percpu.h> #endif /* __ALPHA_PERCPU_H */
arch/ia64/include/asm/smp.h +1 -1
@@ -58,7 +58,7 @@ extern struct smp_boot_data {extern char no_int_routing__devinitdata ;extern cpumask_t cpu_core_map[NR_CPUS ]; -DECLARE_PER_CPU (cpumask_t, cpu_sibling_map); +DECLARE_PER_CPU_SHARED_ALIGNED (cpumask_t, cpu_sibling_map);extern int smp_num_siblings;extern void __iomem *ipi_base_addr;extern unsigned char smp_int_redirect;
arch/x86/include/asm/desc.h +1 -1
@@ -37,7 +37,7 @@ extern gate_desc idt_table[];struct gdt_page {struct desc_struct gdt[GDT_ENTRIES ]; } __attribute__((aligned (PAGE_SIZE ))); -DECLARE_PER_CPU(struct gdt_page, gdt_page); +DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);static inline struct desc_struct *get_cpu_gdt_table (unsigned int cpu) {
arch/x86/include/asm/hardirq.h +1 -1
@@ -26,7 +26,7 @@ typedef struct {#endif }____cacheline_aligned irq_cpustat_t; -DECLARE_PER_CPU (irq_cpustat_t, irq_stat); +DECLARE_PER_CPU_SHARED_ALIGNED (irq_cpustat_t, irq_stat);/* We can have at most NR_VECTORS irqs routed to a cpu at a time */ #define MAX_HARDIRQS_PER_CPU NR_VECTORS
arch/x86/include/asm/processor.h +3 -3
@@ -138,7 +138,7 @@ extern struct tss_struct doublefault_tss;extern __u32 cleared_cpu_caps[NCAPINTS ];#ifdef CONFIG_SMP -DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info); +DECLARE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);#define cpu_data (cpu) per_cpu(cpu_info, cpu)#define current_cpu_data __get_cpu_var(cpu_info)#else
@@ -270,7 +270,7 @@ struct tss_struct { }____cacheline_aligned ; -DECLARE_PER_CPU(struct tss_struct, init_tss); +DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);/* * Save the original ist values for checking stack pointers during debugging
@@ -393,7 +393,7 @@ union irq_stack_union { }; }; -DECLARE_PER_CPU(union irq_stack_union, irq_stack_union); +DECLARE_PER_CPU_FIRST(union irq_stack_union, irq_stack_union);DECLARE_INIT_PER_CPU (irq_stack_union); DECLARE_PER_CPU(char *, irq_stack_ptr);
arch/x86/include/asm/tlbflush.h +1 -1
@@ -152,7 +152,7 @@ struct tlb_state {struct mm_struct *active_mm;int state; }; -DECLARE_PER_CPU(struct tlb_state, cpu_tlbstate); +DECLARE_PER_CPU_SHARED_ALIGNED(struct tlb_state, cpu_tlbstate);static inline void reset_lazy_tlbstate (void ) {
include/asm-generic/percpu.h +41 -2
52 lines not on this page · raw message
include/linux/percpu.h +0 -24
@@ -9,30 +9,6 @@#include <asm/percpu.h> -#ifndef PER_CPU_BASE_SECTION -#ifdef CONFIG_SMP -#define PER_CPU_BASE_SECTION ".data.percpu" -#else -#define PER_CPU_BASE_SECTION ".data" -#endif -#endif - -#ifdef CONFIG_SMP - -#ifdef MODULE -#define PER_CPU_SHARED_ALIGNED_SECTION "" -#else -#define PER_CPU_SHARED_ALIGNED_SECTION ".shared_aligned" -#endif -#define PER_CPU_FIRST_SECTION ".first" - -#else - -#define PER_CPU_SHARED_ALIGNED_SECTION "" -#define PER_CPU_FIRST_SECTION "" - -#endif -#define DEFINE_PER_CPU_SECTION (type, name, section) \ __attribute__((__section__(PER_CPU_BASE_SECTION section))) \ PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name
net/rds/rds.h +1 -1
@@ -638,7 +638,7 @@ struct rds_message *rds_send_get_message(struct rds_connection *,void rds_rdma_unuse (struct rds_sock *rs,u32 r_key,int force);/* stats.c */ -DECLARE_PER_CPU(struct rds_statistics, rds_stats); +DECLARE_PER_CPU_SHARED_ALIGNED(struct rds_statistics, rds_stats);#define rds_stats_inc_which (which, member) do { \ per_cpu(which, get_cpu()).member++; \ put_cpu(); \
PATCH 2/2 PERCPU: Collect the DECLARE/DEFINE declarations together
Collect the DECLARE/DEFINE declarations together in linux/percpu-defs.h so that they're in one place, and give them descriptive comments, particularly the SHARED_ALIGNED variant.
It would be nice to collect these in linux/percpu.h, but that's not possible without sorting out the severe #include recursion between the x86 arch headers and the general headers (and possibly other arches too).
---
include/asm-generic/percpu.h | 26 +------------ include/linux/percpu-defs.h | 84 ++++++++++++++++++++++++++++++++++++++++++ include/linux/percpu.h | 20 ---------- 3 files changed, 86 insertions(+), 44 deletions(-) create mode 100644 include/linux/percpu-defs.h
include/asm-generic/percpu.h +2 -24
@@ -1,13 +1,9 @@#ifndef _ASM_GENERIC_PERCPU_H_#define _ASM_GENERIC_PERCPU_H_ +#include <linux/compiler.h> #include <linux/threads.h> - -/* -* Determine the real variable name from the name visible in the -* kernel sources. -*/ -#define per_cpu_var (var) per_cpu__##var +#include <linux/percpu-defs.h> #ifdef CONFIG_SMP
@@ -101,22 +97,4 @@ extern void setup_per_cpu_areas(void);#define PER_CPU_ATTRIBUTES #endif -#define DECLARE_PER_CPU_SECTION (type, name, section) \ - extern \ - __attribute__((__section__(PER_CPU_BASE_SECTION section))) \ - PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name - -#define DECLARE_PER_CPU (type, name) \ - DECLARE_PER_CPU_SECTION(type, name, "") - -#define DECLARE_PER_CPU_SHARED_ALIGNED (type, name) \ - DECLARE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ - ____cacheline_aligned_in_smp - -#define DECLARE_PER_CPU_PAGE_ALIGNED (type, name) \ - DECLARE_PER_CPU_SECTION(type, name, ".page_aligned") - -#define DECLARE_PER_CPU_FIRST (type, name) \ - DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) -#endif /* _ASM_GENERIC_PERCPU_H_ */
include/linux/percpu-defs.h new file +84 -0
84 lines not on this page · raw message
include/linux/percpu.h +0 -20
@@ -9,26 +9,6 @@#include <asm/percpu.h> -#define DEFINE_PER_CPU_SECTION (type, name, section) \ - __attribute__((__section__(PER_CPU_BASE_SECTION section))) \ - PER_CPU_ATTRIBUTES __typeof__(type) per_cpu__##name - -#define DEFINE_PER_CPU (type, name) \ - DEFINE_PER_CPU_SECTION(type, name, "") - -#define DEFINE_PER_CPU_SHARED_ALIGNED (type, name) \ - DEFINE_PER_CPU_SECTION(type, name, PER_CPU_SHARED_ALIGNED_SECTION) \ - ____cacheline_aligned_in_smp - -#define DEFINE_PER_CPU_PAGE_ALIGNED (type, name) \ - DEFINE_PER_CPU_SECTION(type, name, ".page_aligned") - -#define DEFINE_PER_CPU_FIRST (type, name) \ - DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) - -#define EXPORT_PER_CPU_SYMBOL (var) EXPORT_SYMBOL(per_cpu__##var) -#define EXPORT_PER_CPU_SYMBOL_GPL (var) EXPORT_SYMBOL_GPL(per_cpu__##var) -/* enough to cover all DEFINE_PER_CPUs in modules */ #ifdef CONFIG_MODULES #define PERCPU_MODULE_RESERVE (8 << 10)