History

net: Add lockdep asserts to ____napi_schedule().

____napi_schedule() needs to be invoked with disabled interrupts due to __raise_softirq_irqoff (in order not to corrupt the per-CPU list). ____napi_schedule() needs also to be invoked from an interrupt context so that the raised-softirq is processed while the interrupt context is left. Add lockdep asserts for both conditions. While this is the second time the irq/softirq check is needed, provide a generic lockdep_assert_softirq_will_run() which is used by both caller.

Sebastian Andrzej Siewior committed 4 years ago

Commit fbd9a2c1 parent d96657d2 files · +11 −1Browse files

Unified · Split

2 files
  1. include/linux/lockdep.h +7 −0
  2. net/core/dev.c +4 −1
include/linux/lockdep.h+7−0
@@ -329,6 +329,12 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie); · 328 unmodified lines
329329
330330 #define lockdep_assert_none_held_once() \
331331 lockdep_assert_once(!current->lockdep_depth)
332+/*
333+ * Ensure that softirq is handled within the callchain and not delayed and
334+ * handled by chance.
335+ */
336+#define lockdep_assert_softirq_will_run() \
337+ lockdep_assert_once(hardirq_count() | softirq_count())
332338
333339 #define lockdep_recursing(tsk) ((tsk)->lockdep_recursion)
334340
@@ -414,6 +420,7 @@ extern int lockdep_is_held(const void *); · 79 unmodified lines
414420 #define lockdep_assert_held_read(l) do { (void)(l); } while (0)
415421 #define lockdep_assert_held_once(l) do { (void)(l); } while (0)
416422 #define lockdep_assert_none_held_once() do { } while (0)
423+#define lockdep_assert_softirq_will_run() do { } while (0)
417424
418425 #define lockdep_recursing(tsk) (0)
419426
net/core/dev.c+4−1
@@ -4265,6 +4265,9 @@ static inline void ____napi_schedule(struct softnet_data *sd, · 4264 unmodified lines
42654265 {
42664266 struct task_struct *thread;
42674267
4268+ lockdep_assert_softirq_will_run();
4269+ lockdep_assert_irqs_disabled();
4270+
42684271 if (test_bit(NAPI_STATE_THREADED, &napi->state)) {
42694272 /* Paired with smp_mb__before_atomic() in
42704273 * napi_enable()/dev_set_threaded().
@@ -4872,7 +4875,7 @@ int __netif_rx(struct sk_buff *skb) · 601 unmodified lines
48724875 {
48734876 int ret;
48744877
4875− lockdep_assert_once(hardirq_count() | softirq_count());
4878+ lockdep_assert_softirq_will_run();
48764879
48774880 trace_netif_rx_entry(skb);
48784881 ret = netif_rx_internal(skb);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t