Revert "net: validate variable length ll headers"
[pandora-kernel.git] / include / linux / preempt.h
1 #ifndef __LINUX_PREEMPT_H
2 #define __LINUX_PREEMPT_H
3
4 /*
5  * include/linux/preempt.h - macros for accessing and manipulating
6  * preempt_count (used for kernel preemption, interrupt count, etc.)
7  */
8
9 #include <linux/thread_info.h>
10 #include <linux/linkage.h>
11 #include <linux/list.h>
12
13 #if defined(CONFIG_DEBUG_PREEMPT) || defined(CONFIG_PREEMPT_TRACER)
14   extern void add_preempt_count(int val);
15   extern void sub_preempt_count(int val);
16 #else
17 # define add_preempt_count(val) do { preempt_count() += (val); } while (0)
18 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
19 #endif
20
21 #define inc_preempt_count() add_preempt_count(1)
22 #define dec_preempt_count() sub_preempt_count(1)
23
24 #define preempt_count() (current_thread_info()->preempt_count)
25
26 #ifdef CONFIG_PREEMPT
27
28 asmlinkage void preempt_schedule(void);
29
30 #define preempt_check_resched() \
31 do { \
32         if (unlikely(test_thread_flag(TIF_NEED_RESCHED))) \
33                 preempt_schedule(); \
34 } while (0)
35
36 #else /* !CONFIG_PREEMPT */
37
38 #define preempt_check_resched()         do { } while (0)
39
40 #endif /* CONFIG_PREEMPT */
41
42
43 #ifdef CONFIG_PREEMPT_COUNT
44
45 #define preempt_disable() \
46 do { \
47         inc_preempt_count(); \
48         barrier(); \
49 } while (0)
50
51 #define preempt_enable_no_resched() \
52 do { \
53         barrier(); \
54         dec_preempt_count(); \
55 } while (0)
56
57 #define preempt_enable() \
58 do { \
59         preempt_enable_no_resched(); \
60         barrier(); \
61         preempt_check_resched(); \
62 } while (0)
63
64 /* For debugging and tracer internals only! */
65 #define add_preempt_count_notrace(val)                  \
66         do { preempt_count() += (val); } while (0)
67 #define sub_preempt_count_notrace(val)                  \
68         do { preempt_count() -= (val); } while (0)
69 #define inc_preempt_count_notrace() add_preempt_count_notrace(1)
70 #define dec_preempt_count_notrace() sub_preempt_count_notrace(1)
71
72 #define preempt_disable_notrace() \
73 do { \
74         inc_preempt_count_notrace(); \
75         barrier(); \
76 } while (0)
77
78 #define preempt_enable_no_resched_notrace() \
79 do { \
80         barrier(); \
81         dec_preempt_count_notrace(); \
82 } while (0)
83
84 /* preempt_check_resched is OK to trace */
85 #define preempt_enable_notrace() \
86 do { \
87         preempt_enable_no_resched_notrace(); \
88         barrier(); \
89         preempt_check_resched(); \
90 } while (0)
91
92 #else /* !CONFIG_PREEMPT_COUNT */
93
94 /*
95  * Even if we don't have any preemption, we need preempt disable/enable
96  * to be barriers, so that we don't have things like get_user/put_user
97  * that can cause faults and scheduling migrate into our preempt-protected
98  * region.
99  */
100 #define preempt_disable()               barrier()
101 #define preempt_enable_no_resched()     barrier()
102 #define preempt_enable()                barrier()
103
104 #define preempt_disable_notrace()               barrier()
105 #define preempt_enable_no_resched_notrace()     barrier()
106 #define preempt_enable_notrace()                barrier()
107
108 #endif /* CONFIG_PREEMPT_COUNT */
109
110 #ifdef CONFIG_PREEMPT_NOTIFIERS
111
112 struct preempt_notifier;
113
114 /**
115  * preempt_ops - notifiers called when a task is preempted and rescheduled
116  * @sched_in: we're about to be rescheduled:
117  *    notifier: struct preempt_notifier for the task being scheduled
118  *    cpu:  cpu we're scheduled on
119  * @sched_out: we've just been preempted
120  *    notifier: struct preempt_notifier for the task being preempted
121  *    next: the task that's kicking us out
122  *
123  * Please note that sched_in and out are called under different
124  * contexts.  sched_out is called with rq lock held and irq disabled
125  * while sched_in is called without rq lock and irq enabled.  This
126  * difference is intentional and depended upon by its users.
127  */
128 struct preempt_ops {
129         void (*sched_in)(struct preempt_notifier *notifier, int cpu);
130         void (*sched_out)(struct preempt_notifier *notifier,
131                           struct task_struct *next);
132 };
133
134 /**
135  * preempt_notifier - key for installing preemption notifiers
136  * @link: internal use
137  * @ops: defines the notifier functions to be called
138  *
139  * Usually used in conjunction with container_of().
140  */
141 struct preempt_notifier {
142         struct hlist_node link;
143         struct preempt_ops *ops;
144 };
145
146 void preempt_notifier_register(struct preempt_notifier *notifier);
147 void preempt_notifier_unregister(struct preempt_notifier *notifier);
148
149 static inline void preempt_notifier_init(struct preempt_notifier *notifier,
150                                      struct preempt_ops *ops)
151 {
152         INIT_HLIST_NODE(&notifier->link);
153         notifier->ops = ops;
154 }
155
156 #endif
157
158 #endif /* __LINUX_PREEMPT_H */