stackprotector: remove self-test
[linux-2.6.git] / include / asm-x86 / pda.h
1 #ifndef X86_64_PDA_H
2 #define X86_64_PDA_H
3
4 #ifndef __ASSEMBLY__
5 #include <linux/stddef.h>
6 #include <linux/types.h>
7 #include <linux/cache.h>
8 #include <asm/page.h>
9
10 /* Per processor datastructure. %gs points to it while the kernel runs */
11 struct x8664_pda {
12         struct task_struct *pcurrent;   /* 0  Current process */
13         unsigned long data_offset;      /* 8 Per cpu data offset from linker
14                                            address */
15         unsigned long kernelstack;      /* 16 top of kernel stack for current */
16         unsigned long oldrsp;           /* 24 user rsp for system call */
17         int irqcount;                   /* 32 Irq nesting counter. Starts -1 */
18         unsigned int cpunumber;         /* 36 Logical CPU number */
19         unsigned long stack_canary;     /* 40 stack canary value */
20                                         /* gcc-ABI: this canary MUST be at
21                                            offset 40!!! */
22         char *irqstackptr;
23         unsigned int __softirq_pending;
24         unsigned int __nmi_count;       /* number of NMI on this CPUs */
25         short mmu_state;
26         short isidle;
27         struct mm_struct *active_mm;
28         unsigned apic_timer_irqs;
29         unsigned irq0_irqs;
30         unsigned irq_resched_count;
31         unsigned irq_call_count;
32         unsigned irq_tlb_count;
33         unsigned irq_thermal_count;
34         unsigned irq_threshold_count;
35         unsigned irq_spurious_count;
36 } ____cacheline_aligned_in_smp;
37
38 extern struct x8664_pda *_cpu_pda[];
39 extern struct x8664_pda boot_cpu_pda[];
40 extern void pda_init(int);
41
42 #define cpu_pda(i) (_cpu_pda[i])
43
44 /*
45  * There is no fast way to get the base address of the PDA, all the accesses
46  * have to mention %fs/%gs.  So it needs to be done this Torvaldian way.
47  */
48 extern void __bad_pda_field(void) __attribute__((noreturn));
49
50 /*
51  * proxy_pda doesn't actually exist, but tell gcc it is accessed for
52  * all PDA accesses so it gets read/write dependencies right.
53  */
54 extern struct x8664_pda _proxy_pda;
55
56 #define pda_offset(field) offsetof(struct x8664_pda, field)
57
58 #define pda_to_op(op, field, val)                                       \
59 do {                                                                    \
60         typedef typeof(_proxy_pda.field) T__;                           \
61         if (0) { T__ tmp__; tmp__ = (val); }    /* type checking */     \
62         switch (sizeof(_proxy_pda.field)) {                             \
63         case 2:                                                         \
64                 asm(op "w %1,%%gs:%c2" :                                \
65                     "+m" (_proxy_pda.field) :                           \
66                     "ri" ((T__)val),                                    \
67                     "i"(pda_offset(field)));                            \
68                 break;                                                  \
69         case 4:                                                         \
70                 asm(op "l %1,%%gs:%c2" :                                \
71                     "+m" (_proxy_pda.field) :                           \
72                     "ri" ((T__)val),                                    \
73                     "i" (pda_offset(field)));                           \
74                 break;                                                  \
75         case 8:                                                         \
76                 asm(op "q %1,%%gs:%c2":                                 \
77                     "+m" (_proxy_pda.field) :                           \
78                     "ri" ((T__)val),                                    \
79                     "i"(pda_offset(field)));                            \
80                 break;                                                  \
81         default:                                                        \
82                 __bad_pda_field();                                      \
83         }                                                               \
84 } while (0)
85
86 #define pda_from_op(op, field)                  \
87 ({                                              \
88         typeof(_proxy_pda.field) ret__;         \
89         switch (sizeof(_proxy_pda.field)) {     \
90         case 2:                                 \
91                 asm(op "w %%gs:%c1,%0" :        \
92                     "=r" (ret__) :              \
93                     "i" (pda_offset(field)),    \
94                     "m" (_proxy_pda.field));    \
95                 break;                          \
96         case 4:                                 \
97                 asm(op "l %%gs:%c1,%0":         \
98                     "=r" (ret__):               \
99                     "i" (pda_offset(field)),    \
100                     "m" (_proxy_pda.field));    \
101                 break;                          \
102         case 8:                                 \
103                 asm(op "q %%gs:%c1,%0":         \
104                     "=r" (ret__) :              \
105                     "i" (pda_offset(field)),    \
106                     "m" (_proxy_pda.field));    \
107                 break;                          \
108         default:                                \
109                 __bad_pda_field();              \
110         }                                       \
111         ret__;                                  \
112 })
113
114 #define read_pda(field)         pda_from_op("mov", field)
115 #define write_pda(field, val)   pda_to_op("mov", field, val)
116 #define add_pda(field, val)     pda_to_op("add", field, val)
117 #define sub_pda(field, val)     pda_to_op("sub", field, val)
118 #define or_pda(field, val)      pda_to_op("or", field, val)
119
120 /* This is not atomic against other CPUs -- CPU preemption needs to be off */
121 #define test_and_clear_bit_pda(bit, field)                              \
122 ({                                                                      \
123         int old__;                                                      \
124         asm volatile("btr %2,%%gs:%c3\n\tsbbl %0,%0"                    \
125                      : "=r" (old__), "+m" (_proxy_pda.field)            \
126                      : "dIr" (bit), "i" (pda_offset(field)) : "memory");\
127         old__;                                                          \
128 })
129
130 #endif
131
132 #define PDA_STACKOFFSET (5*8)
133
134 #define refresh_stack_canary() write_pda(stack_canary, current->stack_canary)
135 #endif