Skip to content

Commit f251cce

Browse files
walacgregkh
authored andcommitted
drop_monitor: replace spin_lock by raw_spin_lock
[ Upstream commit f1e197a ] trace_drop_common() is called with preemption disabled, and it acquires a spin_lock. This is problematic for RT kernels because spin_locks are sleeping locks in this configuration, which causes the following splat: BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 449, name: rcuc/47 preempt_count: 1, expected: 0 RCU nest depth: 2, expected: 2 5 locks held by rcuc/47/449: #0: ff1100086ec30a60 ((softirq_ctrl.lock)){+.+.}-{2:2}, at: __local_bh_disable_ip+0x105/0x210 khadas#1: ffffffffb394a280 (rcu_read_lock){....}-{1:2}, at: rt_spin_lock+0xbf/0x130 khadas#2: ffffffffb394a280 (rcu_read_lock){....}-{1:2}, at: __local_bh_disable_ip+0x11c/0x210 khadas#3: ffffffffb394a160 (rcu_callback){....}-{0:0}, at: rcu_do_batch+0x360/0xc70 khadas#4: ff1100086ee07520 (&data->lock){+.+.}-{2:2}, at: trace_drop_common.constprop.0+0xb5/0x290 irq event stamp: 139909 hardirqs last enabled at (139908): [<ffffffffb1df2b33>] _raw_spin_unlock_irqrestore+0x63/0x80 hardirqs last disabled at (139909): [<ffffffffb19bd03d>] trace_drop_common.constprop.0+0x26d/0x290 softirqs last enabled at (139892): [<ffffffffb07a1083>] __local_bh_enable_ip+0x103/0x170 softirqs last disabled at (139898): [<ffffffffb0909b33>] rcu_cpu_kthread+0x93/0x1f0 Preemption disabled at: [<ffffffffb1de786b>] rt_mutex_slowunlock+0xab/0x2e0 CPU: 47 PID: 449 Comm: rcuc/47 Not tainted 6.9.0-rc2-rt1+ khadas#7 Hardware name: Dell Inc. PowerEdge R650/0Y2G81, BIOS 1.6.5 04/15/2022 Call Trace: <TASK> dump_stack_lvl+0x8c/0xd0 dump_stack+0x14/0x20 __might_resched+0x21e/0x2f0 rt_spin_lock+0x5e/0x130 ? trace_drop_common.constprop.0+0xb5/0x290 ? skb_queue_purge_reason.part.0+0x1bf/0x230 trace_drop_common.constprop.0+0xb5/0x290 ? preempt_count_sub+0x1c/0xd0 ? _raw_spin_unlock_irqrestore+0x4a/0x80 ? __pfx_trace_drop_common.constprop.0+0x10/0x10 ? rt_mutex_slowunlock+0x26a/0x2e0 ? skb_queue_purge_reason.part.0+0x1bf/0x230 ? __pfx_rt_mutex_slowunlock+0x10/0x10 ? skb_queue_purge_reason.part.0+0x1bf/0x230 trace_kfree_skb_hit+0x15/0x20 trace_kfree_skb+0xe9/0x150 kfree_skb_reason+0x7b/0x110 skb_queue_purge_reason.part.0+0x1bf/0x230 ? __pfx_skb_queue_purge_reason.part.0+0x10/0x10 ? mark_lock.part.0+0x8a/0x520 ... trace_drop_common() also disables interrupts, but this is a minor issue because we could easily replace it with a local_lock. Replace the spin_lock with raw_spin_lock to avoid sleeping in atomic context. Signed-off-by: Wander Lairson Costa <[email protected]> Reported-by: Hu Chunyu <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 6331004 commit f251cce

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

net/core/drop_monitor.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct net_dm_hw_entries {
7272
};
7373

7474
struct per_cpu_dm_data {
75-
spinlock_t lock; /* Protects 'skb', 'hw_entries' and
75+
raw_spinlock_t lock; /* Protects 'skb', 'hw_entries' and
7676
* 'send_timer'
7777
*/
7878
union {
@@ -166,9 +166,9 @@ static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data)
166166
err:
167167
mod_timer(&data->send_timer, jiffies + HZ / 10);
168168
out:
169-
spin_lock_irqsave(&data->lock, flags);
169+
raw_spin_lock_irqsave(&data->lock, flags);
170170
swap(data->skb, skb);
171-
spin_unlock_irqrestore(&data->lock, flags);
171+
raw_spin_unlock_irqrestore(&data->lock, flags);
172172

173173
if (skb) {
174174
struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data;
@@ -223,7 +223,7 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
223223

224224
local_irq_save(flags);
225225
data = this_cpu_ptr(&dm_cpu_data);
226-
spin_lock(&data->lock);
226+
raw_spin_lock(&data->lock);
227227
dskb = data->skb;
228228

229229
if (!dskb)
@@ -257,7 +257,7 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
257257
}
258258

259259
out:
260-
spin_unlock_irqrestore(&data->lock, flags);
260+
raw_spin_unlock_irqrestore(&data->lock, flags);
261261
}
262262

263263
static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb,
@@ -312,9 +312,9 @@ net_dm_hw_reset_per_cpu_data(struct per_cpu_dm_data *hw_data)
312312
mod_timer(&hw_data->send_timer, jiffies + HZ / 10);
313313
}
314314

315-
spin_lock_irqsave(&hw_data->lock, flags);
315+
raw_spin_lock_irqsave(&hw_data->lock, flags);
316316
swap(hw_data->hw_entries, hw_entries);
317-
spin_unlock_irqrestore(&hw_data->lock, flags);
317+
raw_spin_unlock_irqrestore(&hw_data->lock, flags);
318318

319319
return hw_entries;
320320
}
@@ -446,7 +446,7 @@ net_dm_hw_trap_summary_probe(void *ignore, const struct devlink *devlink,
446446
return;
447447

448448
hw_data = this_cpu_ptr(&dm_hw_cpu_data);
449-
spin_lock_irqsave(&hw_data->lock, flags);
449+
raw_spin_lock_irqsave(&hw_data->lock, flags);
450450
hw_entries = hw_data->hw_entries;
451451

452452
if (!hw_entries)
@@ -475,7 +475,7 @@ net_dm_hw_trap_summary_probe(void *ignore, const struct devlink *devlink,
475475
}
476476

477477
out:
478-
spin_unlock_irqrestore(&hw_data->lock, flags);
478+
raw_spin_unlock_irqrestore(&hw_data->lock, flags);
479479
}
480480

481481
static const struct net_dm_alert_ops net_dm_alert_summary_ops = {
@@ -1658,7 +1658,7 @@ static struct notifier_block dropmon_net_notifier = {
16581658

16591659
static void __net_dm_cpu_data_init(struct per_cpu_dm_data *data)
16601660
{
1661-
spin_lock_init(&data->lock);
1661+
raw_spin_lock_init(&data->lock);
16621662
skb_queue_head_init(&data->drop_queue);
16631663
u64_stats_init(&data->stats.syncp);
16641664
}

0 commit comments

Comments
 (0)