]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/smp.h
bpf: Prevent memory disambiguation attack
[mirror_ubuntu-artful-kernel.git] / include / linux / smp.h
CommitLineData
1da177e4
LT
1#ifndef __LINUX_SMP_H
2#define __LINUX_SMP_H
3
4/*
5 * Generic SMP support
6 * Alan Cox. <alan@redhat.com>
7 */
8
79974a0e 9#include <linux/errno.h>
54514a70 10#include <linux/types.h>
3d442233 11#include <linux/list.h>
3d442233 12#include <linux/cpumask.h>
04948c7f 13#include <linux/init.h>
6897fc22 14#include <linux/llist.h>
1da177e4 15
3a5f65df 16typedef void (*smp_call_func_t)(void *info);
3d442233 17struct call_single_data {
0ebeb79c 18 struct llist_node llist;
3a5f65df 19 smp_call_func_t func;
3d442233 20 void *info;
f4d03bd1 21 unsigned int flags;
3d442233
JA
22};
23
e057d7ae
MT
24/* total number of cpus in this system (may exceed NR_CPUS) */
25extern unsigned int total_cpus;
26
3a5f65df
DH
27int smp_call_function_single(int cpuid, smp_call_func_t func, void *info,
28 int wait);
53ce3d95 29
bff2dc42
DD
30/*
31 * Call a function on all processors
32 */
33int on_each_cpu(smp_call_func_t func, void *info, int wait);
34
fa688207
DD
35/*
36 * Call a function on processors specified by mask, which might include
37 * the local one.
38 */
39void on_each_cpu_mask(const struct cpumask *mask, smp_call_func_t func,
40 void *info, bool wait);
41
42/*
43 * Call a function on each processor for which the supplied function
44 * cond_func returns a positive value. This may include the local
45 * processor.
46 */
47void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
48 smp_call_func_t func, void *info, bool wait,
49 gfp_t gfp_flags);
50
c46fff2a 51int smp_call_function_single_async(int cpu, struct call_single_data *csd);
7cf64f86 52
357b57d7
TC
53#ifdef CONFIG_X86
54/* indicate usage of IBRS to control execution speculation */
55extern int use_ibrs;
56extern u32 sysctl_ibrs_enabled;
57extern struct mutex spec_ctrl_mutex;
58#define ibrs_supported (use_ibrs & 0x2)
59#define ibrs_disabled (use_ibrs & 0x4)
60static inline void set_ibrs_inuse(void)
61{
62 if (ibrs_supported)
63 use_ibrs |= 0x1;
64}
65static inline void clear_ibrs_inuse(void)
66{
67 use_ibrs &= ~0x1;
68}
69static inline int check_ibrs_inuse(void)
70{
71 if (use_ibrs & 0x1)
72 return 1;
73 else
74 /* rmb to prevent wrong speculation for security */
75 rmb();
76 return 0;
77}
78static inline void set_ibrs_supported(void)
79{
80 use_ibrs |= 0x2;
81 if (!ibrs_disabled)
82 set_ibrs_inuse();
83}
84static inline void set_ibrs_disabled(void)
85{
86 use_ibrs |= 0x4;
87 if (check_ibrs_inuse())
88 clear_ibrs_inuse();
89}
90static inline void clear_ibrs_disabled(void)
91{
92 use_ibrs &= ~0x4;
93 set_ibrs_inuse();
94}
95#define ibrs_inuse (check_ibrs_inuse())
96
97/* indicate usage of IBPB to control execution speculation */
98extern int use_ibpb;
99extern u32 sysctl_ibpb_enabled;
100#define ibpb_supported (use_ibpb & 0x2)
101#define ibpb_disabled (use_ibpb & 0x4)
210a3e08 102static inline void set_ibpb_inuse(void)
357b57d7 103{
210a3e08
AW
104 if (ibpb_supported)
105 use_ibpb |= 0x1;
106}
107static inline void clear_ibpb_inuse(void)
108{
109 use_ibpb &= ~0x1;
357b57d7
TC
110}
111static inline int check_ibpb_inuse(void)
112{
210a3e08 113 if (use_ibpb & 0x1)
357b57d7
TC
114 return 1;
115 else
116 /* rmb to prevent wrong speculation for security */
117 rmb();
118 return 0;
119}
120static inline void set_ibpb_supported(void)
121{
122 use_ibpb |= 0x2;
210a3e08
AW
123 if (!ibpb_disabled)
124 set_ibpb_inuse();
357b57d7
TC
125}
126static inline void set_ibpb_disabled(void)
127{
128 use_ibpb |= 0x4;
210a3e08
AW
129 if (check_ibpb_inuse())
130 clear_ibpb_inuse();
357b57d7
TC
131}
132static inline void clear_ibpb_disabled(void)
133{
134 use_ibpb &= ~0x4;
210a3e08 135 set_ibpb_inuse();
357b57d7
TC
136}
137#define ibpb_inuse (check_ibpb_inuse())
138#endif
139
1da177e4
LT
140#ifdef CONFIG_SMP
141
142#include <linux/preempt.h>
143#include <linux/kernel.h>
144#include <linux/compiler.h>
145#include <linux/thread_info.h>
146#include <asm/smp.h>
1da177e4
LT
147
148/*
149 * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
150 * (defined in asm header):
d1dedb52 151 */
1da177e4
LT
152
153/*
154 * stops all CPUs but the current one:
155 */
156extern void smp_send_stop(void);
157
158/*
159 * sends a 'reschedule' event to another CPU:
160 */
161extern void smp_send_reschedule(int cpu);
162
163
164/*
165 * Prepare machine for booting other CPUs.
166 */
167extern void smp_prepare_cpus(unsigned int max_cpus);
168
169/*
170 * Bring a CPU up
171 */
8239c25f 172extern int __cpu_up(unsigned int cpunum, struct task_struct *tidle);
1da177e4
LT
173
174/*
175 * Final polishing of CPUs
176 */
177extern void smp_cpus_done(unsigned int max_cpus);
178
179/*
180 * Call a function on all other processors
181 */
3a5f65df 182int smp_call_function(smp_call_func_t func, void *info, int wait);
54b11e6d 183void smp_call_function_many(const struct cpumask *mask,
3a5f65df 184 smp_call_func_t func, void *info, bool wait);
2d3854a3 185
2ea6dec4 186int smp_call_function_any(const struct cpumask *mask,
3a5f65df 187 smp_call_func_t func, void *info, int wait);
2ea6dec4 188
f37f435f 189void kick_all_cpus_sync(void);
c6f4459f 190void wake_up_all_idle_cpus(void);
f37f435f 191
3d442233
JA
192/*
193 * Generic and arch helpers
194 */
d8ad7d11 195void __init call_function_init(void);
3d442233 196void generic_smp_call_function_single_interrupt(void);
9a46ad6d
SL
197#define generic_smp_call_function_interrupt \
198 generic_smp_call_function_single_interrupt
a3bc0dbc 199
1da177e4
LT
200/*
201 * Mark the boot cpu "online" so that it can call console drivers in
202 * printk() and can access its per-cpu storage.
203 */
204void smp_prepare_boot_cpu(void);
205
ca74a6f8 206extern unsigned int setup_max_cpus;
34db18a0
AW
207extern void __init setup_nr_cpu_ids(void);
208extern void __init smp_init(void);
ca74a6f8 209
8ce371f9
PZ
210extern int __boot_cpu_id;
211
212static inline int get_boot_cpu_id(void)
213{
214 return __boot_cpu_id;
215}
216
1da177e4
LT
217#else /* !SMP */
218
d1dedb52
IM
219static inline void smp_send_stop(void) { }
220
1da177e4
LT
221/*
222 * These macros fold the SMP functionality into a single CPU system
223 */
39c715b7 224#define raw_smp_processor_id() 0
3a5f65df 225static inline int up_smp_call_function(smp_call_func_t func, void *info)
3c30b06d
CK
226{
227 return 0;
228}
8691e5a8 229#define smp_call_function(func, info, wait) \
a5fbb6d1 230 (up_smp_call_function(func, info))
3b8967d7 231
79a88102 232static inline void smp_send_reschedule(int cpu) { }
2ac6608c 233#define smp_prepare_boot_cpu() do {} while (0)
d2ff9118
RR
234#define smp_call_function_many(mask, func, info, wait) \
235 (up_smp_call_function(func, info))
d8ad7d11 236static inline void call_function_init(void) { }
2ea6dec4
RR
237
238static inline int
3a5f65df 239smp_call_function_any(const struct cpumask *mask, smp_call_func_t func,
2ea6dec4 240 void *info, int wait)
3d442233 241{
2ea6dec4 242 return smp_call_function_single(0, func, info, wait);
3d442233 243}
2ea6dec4 244
f37f435f 245static inline void kick_all_cpus_sync(void) { }
c6f4459f 246static inline void wake_up_all_idle_cpus(void) { }
f37f435f 247
30b8b006
TG
248#ifdef CONFIG_UP_LATE_INIT
249extern void __init up_late_init(void);
250static inline void smp_init(void) { up_late_init(); }
251#else
252static inline void smp_init(void) { }
253#endif
254
8ce371f9
PZ
255static inline int get_boot_cpu_id(void)
256{
257 return 0;
258}
259
1da177e4
LT
260#endif /* !SMP */
261
262/*
39c715b7 263 * smp_processor_id(): get the current CPU ID.
1da177e4 264 *
cfd8d6c0 265 * if DEBUG_PREEMPT is enabled then we check whether it is
39c715b7
IM
266 * used in a preemption-safe way. (smp_processor_id() is safe
267 * if it's used in a preemption-off critical section, or in
268 * a thread that is bound to the current CPU.)
1da177e4 269 *
39c715b7
IM
270 * NOTE: raw_smp_processor_id() is for internal use only
271 * (smp_processor_id() is the preferred variant), but in rare
272 * instances it might also be used to turn off false positives
273 * (i.e. smp_processor_id() use that the debugging code reports but
274 * which use for some reason is legal). Don't use this to hack around
275 * the warning message, as your code might not work under PREEMPT.
1da177e4 276 */
39c715b7
IM
277#ifdef CONFIG_DEBUG_PREEMPT
278 extern unsigned int debug_smp_processor_id(void);
279# define smp_processor_id() debug_smp_processor_id()
1da177e4 280#else
39c715b7 281# define smp_processor_id() raw_smp_processor_id()
1da177e4
LT
282#endif
283
284#define get_cpu() ({ preempt_disable(); smp_processor_id(); })
285#define put_cpu() preempt_enable()
1da177e4 286
a146649b
IM
287/*
288 * Callback to arch code if there's nosmp or maxcpus=0 on the
289 * boot command line:
290 */
291extern void arch_disable_smp_support(void);
292
fb37bb04
PG
293extern void arch_enable_nonboot_cpus_begin(void);
294extern void arch_enable_nonboot_cpus_end(void);
295
033ab7f8
AM
296void smp_setup_processor_id(void);
297
df8ce9d7
JG
298int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par,
299 bool phys);
300
31487f83
RW
301/* SMP core functions */
302int smpcfd_prepare_cpu(unsigned int cpu);
303int smpcfd_dead_cpu(unsigned int cpu);
304int smpcfd_dying_cpu(unsigned int cpu);
305
1da177e4 306#endif /* __LINUX_SMP_H */