[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / 3.2.27 / 0066-drop_monitor-dont-sleep-in-atomic-context.patch
1 From af61f8503b1c3a3d2e034a79abc0368ab3fd2aa4 Mon Sep 17 00:00:00 2001
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Mon, 4 Jun 2012 00:18:19 +0000
4 Subject: [PATCH 66/70] drop_monitor: dont sleep in atomic context
6 commit bec4596b4e6770c7037f21f6bd27567b152dc0d6 upstream.
8 drop_monitor calls several sleeping functions while in atomic context.
10 BUG: sleeping function called from invalid context at mm/slub.c:943
11 in_atomic(): 1, irqs_disabled(): 0, pid: 2103, name: kworker/0:2
12 Pid: 2103, comm: kworker/0:2 Not tainted 3.5.0-rc1+ #55
13 Call Trace:
14 [<ffffffff810697ca>] __might_sleep+0xca/0xf0
15 [<ffffffff811345a3>] kmem_cache_alloc_node+0x1b3/0x1c0
16 [<ffffffff8105578c>] ? queue_delayed_work_on+0x11c/0x130
17 [<ffffffff815343fb>] __alloc_skb+0x4b/0x230
18 [<ffffffffa00b0360>] ? reset_per_cpu_data+0x160/0x160 [drop_monitor]
19 [<ffffffffa00b022f>] reset_per_cpu_data+0x2f/0x160 [drop_monitor]
20 [<ffffffffa00b03ab>] send_dm_alert+0x4b/0xb0 [drop_monitor]
21 [<ffffffff810568e0>] process_one_work+0x130/0x4c0
22 [<ffffffff81058249>] worker_thread+0x159/0x360
23 [<ffffffff810580f0>] ? manage_workers.isra.27+0x240/0x240
24 [<ffffffff8105d403>] kthread+0x93/0xa0
25 [<ffffffff816be6d4>] kernel_thread_helper+0x4/0x10
26 [<ffffffff8105d370>] ? kthread_freezable_should_stop+0x80/0x80
27 [<ffffffff816be6d0>] ? gs_change+0xb/0xb
29 Rework the logic to call the sleeping functions in right context.
31 Use standard timer/workqueue api to let system chose any cpu to perform
32 the allocation and netlink send.
34 Also avoid a loop if reset_per_cpu_data() cannot allocate memory :
35 use mod_timer() to wait 1/10 second before next try.
37 Signed-off-by: Eric Dumazet <edumazet@google.com>
38 Cc: Neil Horman <nhorman@tuxdriver.com>
39 Reviewed-by: Neil Horman <nhorman@tuxdriver.com>
40 Signed-off-by: David S. Miller <davem@davemloft.net>
41 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
42 ---
43 net/core/drop_monitor.c | 101 +++++++++++++++-------------------------------
44 1 files changed, 33 insertions(+), 68 deletions(-)
46 diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
47 index e836592..b856f87 100644
48 --- a/net/core/drop_monitor.c
49 +++ b/net/core/drop_monitor.c
50 @@ -33,9 +33,6 @@
51 #define TRACE_ON 1
52 #define TRACE_OFF 0
54 -static void send_dm_alert(struct work_struct *unused);
55 -
56 -
57 /*
58 * Globals, our netlink socket pointer
59 * and the work handle that will send up
60 @@ -45,11 +42,10 @@ static int trace_state = TRACE_OFF;
61 static DEFINE_MUTEX(trace_state_mutex);
63 struct per_cpu_dm_data {
64 - struct work_struct dm_alert_work;
65 - struct sk_buff __rcu *skb;
66 - atomic_t dm_hit_count;
67 - struct timer_list send_timer;
68 - int cpu;
69 + spinlock_t lock;
70 + struct sk_buff *skb;
71 + struct work_struct dm_alert_work;
72 + struct timer_list send_timer;
73 };
75 struct dm_hw_stat_delta {
76 @@ -75,13 +71,13 @@ static int dm_delay = 1;
77 static unsigned long dm_hw_check_delta = 2*HZ;
78 static LIST_HEAD(hw_stats_list);
80 -static void reset_per_cpu_data(struct per_cpu_dm_data *data)
81 +static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
82 {
83 size_t al;
84 struct net_dm_alert_msg *msg;
85 struct nlattr *nla;
86 struct sk_buff *skb;
87 - struct sk_buff *oskb = rcu_dereference_protected(data->skb, 1);
88 + unsigned long flags;
90 al = sizeof(struct net_dm_alert_msg);
91 al += dm_hit_limit * sizeof(struct net_dm_drop_point);
92 @@ -96,65 +92,40 @@ static void reset_per_cpu_data(struct per_cpu_dm_data *data)
93 sizeof(struct net_dm_alert_msg));
94 msg = nla_data(nla);
95 memset(msg, 0, al);
96 - } else
97 - schedule_work_on(data->cpu, &data->dm_alert_work);
98 -
99 - /*
100 - * Don't need to lock this, since we are guaranteed to only
101 - * run this on a single cpu at a time.
102 - * Note also that we only update data->skb if the old and new skb
103 - * pointers don't match. This ensures that we don't continually call
104 - * synchornize_rcu if we repeatedly fail to alloc a new netlink message.
105 - */
106 - if (skb != oskb) {
107 - rcu_assign_pointer(data->skb, skb);
108 -
109 - synchronize_rcu();
110 -
111 - atomic_set(&data->dm_hit_count, dm_hit_limit);
112 + } else {
113 + mod_timer(&data->send_timer, jiffies + HZ / 10);
114 }
116 + spin_lock_irqsave(&data->lock, flags);
117 + swap(data->skb, skb);
118 + spin_unlock_irqrestore(&data->lock, flags);
119 +
120 + return skb;
121 }
123 -static void send_dm_alert(struct work_struct *unused)
124 +static void send_dm_alert(struct work_struct *work)
125 {
126 struct sk_buff *skb;
127 - struct per_cpu_dm_data *data = &get_cpu_var(dm_cpu_data);
128 + struct per_cpu_dm_data *data;
130 - WARN_ON_ONCE(data->cpu != smp_processor_id());
131 + data = container_of(work, struct per_cpu_dm_data, dm_alert_work);
133 - /*
134 - * Grab the skb we're about to send
135 - */
136 - skb = rcu_dereference_protected(data->skb, 1);
137 + skb = reset_per_cpu_data(data);
139 - /*
140 - * Replace it with a new one
141 - */
142 - reset_per_cpu_data(data);
143 -
144 - /*
145 - * Ship it!
146 - */
147 if (skb)
148 genlmsg_multicast(skb, 0, NET_DM_GRP_ALERT, GFP_KERNEL);
149 -
150 - put_cpu_var(dm_cpu_data);
151 }
153 /*
154 * This is the timer function to delay the sending of an alert
155 * in the event that more drops will arrive during the
156 - * hysteresis period. Note that it operates under the timer interrupt
157 - * so we don't need to disable preemption here
158 + * hysteresis period.
159 */
160 -static void sched_send_work(unsigned long unused)
161 +static void sched_send_work(unsigned long _data)
162 {
163 - struct per_cpu_dm_data *data = &get_cpu_var(dm_cpu_data);
164 + struct per_cpu_dm_data *data = (struct per_cpu_dm_data *)_data;
166 - schedule_work_on(smp_processor_id(), &data->dm_alert_work);
167 -
168 - put_cpu_var(dm_cpu_data);
169 + schedule_work(&data->dm_alert_work);
170 }
172 static void trace_drop_common(struct sk_buff *skb, void *location)
173 @@ -164,22 +135,17 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
174 struct nlattr *nla;
175 int i;
176 struct sk_buff *dskb;
177 - struct per_cpu_dm_data *data = &get_cpu_var(dm_cpu_data);
178 -
179 + struct per_cpu_dm_data *data;
180 + unsigned long flags;
182 - rcu_read_lock();
183 - dskb = rcu_dereference(data->skb);
184 + local_irq_save(flags);
185 + data = &__get_cpu_var(dm_cpu_data);
186 + spin_lock(&data->lock);
187 + dskb = data->skb;
189 if (!dskb)
190 goto out;
192 - if (!atomic_add_unless(&data->dm_hit_count, -1, 0)) {
193 - /*
194 - * we're already at zero, discard this hit
195 - */
196 - goto out;
197 - }
198 -
199 nlh = (struct nlmsghdr *)dskb->data;
200 nla = genlmsg_data(nlmsg_data(nlh));
201 msg = nla_data(nla);
202 @@ -189,7 +155,8 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
203 goto out;
204 }
205 }
206 -
207 + if (msg->entries == dm_hit_limit)
208 + goto out;
209 /*
210 * We need to create a new entry
211 */
212 @@ -201,13 +168,11 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
214 if (!timer_pending(&data->send_timer)) {
215 data->send_timer.expires = jiffies + dm_delay * HZ;
216 - add_timer_on(&data->send_timer, smp_processor_id());
217 + add_timer(&data->send_timer);
218 }
220 out:
221 - rcu_read_unlock();
222 - put_cpu_var(dm_cpu_data);
223 - return;
224 + spin_unlock_irqrestore(&data->lock, flags);
225 }
227 static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb, void *location)
228 @@ -405,11 +370,11 @@ static int __init init_net_drop_monitor(void)
230 for_each_present_cpu(cpu) {
231 data = &per_cpu(dm_cpu_data, cpu);
232 - data->cpu = cpu;
233 INIT_WORK(&data->dm_alert_work, send_dm_alert);
234 init_timer(&data->send_timer);
235 - data->send_timer.data = cpu;
236 + data->send_timer.data = (unsigned long)data;
237 data->send_timer.function = sched_send_work;
238 + spin_lock_init(&data->lock);
239 reset_per_cpu_data(data);
240 }
242 --
243 1.7.7.6