Skip to content

Commit

Permalink
lockdep: Introduce in_softirq lockdep assert
Browse files Browse the repository at this point in the history
The current semantic for napi_consume_skb() is that caller need
to provide non-zero budget when calling from NAPI context, and
breaking this semantic will cause hard to debug problem, because
_kfree_skb_defer() need to run in atomic context in order to push
the skb to the particular cpu' napi_alloc_cache atomically.

So add the lockdep_assert_in_softirq() to assert when the running
context is not in_softirq, in_softirq means softirq is serving or
BH is disabled, which has a ambiguous semantics due to the BH
disabled confusion, so add a comment to emphasize that.

And the softirq context can be interrupted by hard IRQ or NMI
context, lockdep_assert_in_softirq() need to assert about hard
IRQ or NMI context too.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Yunsheng Lin authored and Jakub Kicinski committed Nov 25, 2020
1 parent b5094a3 commit 8b5536a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/linux/lockdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,16 @@ do { \
this_cpu_read(hardirqs_enabled))); \
} while (0)

/*
* Acceptable for protecting per-CPU resources accessed from BH.
* Much like in_softirq() - semantics are ambiguous, use carefully.
*/
#define lockdep_assert_in_softirq() \
do { \
WARN_ON_ONCE(__lockdep_enabled && \
(!in_softirq() || in_irq() || in_nmi())); \
} while (0)

#else
# define might_lock(lock) do { } while (0)
# define might_lock_read(lock) do { } while (0)
Expand All @@ -605,6 +615,7 @@ do { \

# define lockdep_assert_preemption_enabled() do { } while (0)
# define lockdep_assert_preemption_disabled() do { } while (0)
# define lockdep_assert_in_softirq() do { } while (0)
#endif

#ifdef CONFIG_PROVE_RAW_LOCK_NESTING
Expand Down

0 comments on commit 8b5536a

Please sign in to comment.