public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <frederic@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Waiman Long <longman@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Hayes Wang <hayeswang@realtek.com>,
	linux-usb@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 1/2] net: Assert proper context while calling napi_schedule()
Date: Wed, 12 Feb 2025 18:43:28 +0100	[thread overview]
Message-ID: <20250212174329.53793-2-frederic@kernel.org> (raw)
In-Reply-To: <20250212174329.53793-1-frederic@kernel.org>

napi_schedule() is expected to be called either:

* From an interrupt, where raised softirqs are handled on IRQ exit

* From a softirq disabled section, where raised softirqs are handled on
  the next call to local_bh_enable().

* From a softirq handler, where raised softirqs are handled on the next
  round in do_softirq(), or further deferred to a dedicated kthread.

Other bare tasks context may end up ignoring the raised NET_RX vector
until the next random softirq handling opportunity, which may not
happen before a while if the CPU goes idle afterwards with the tick
stopped.

Report inappropriate calling contexts when neither of the three above
conditions are met.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 include/linux/lockdep.h | 12 ++++++++++++
 net/core/dev.c          |  1 +
 2 files changed, 13 insertions(+)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 67964dc4db95..1bd730b881f0 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -619,6 +619,17 @@ do {									\
 		     (!in_softirq() || in_irq() || in_nmi()));		\
 } while (0)
 
+/*
+ * Assert to be either in hardirq or in serving softirq or with
+ * softirqs disabled. Verifies a safe context to queue a softirq
+ * with __raise_softirq_irqoff().
+ */
+#define lockdep_assert_in_interrupt()				\
+do {								\
+	WARN_ON_ONCE(__lockdep_enabled && !in_interrupt());	\
+} while (0)
+
+
 extern void lockdep_assert_in_softirq_func(void);
 
 #else
@@ -634,6 +645,7 @@ extern void lockdep_assert_in_softirq_func(void);
 # define lockdep_assert_preemption_enabled() do { } while (0)
 # define lockdep_assert_preemption_disabled() do { } while (0)
 # define lockdep_assert_in_softirq() do { } while (0)
+# define lockdep_assert_in_interrupt() do { } while (0)
 # define lockdep_assert_in_softirq_func() do { } while (0)
 #endif
 
diff --git a/net/core/dev.c b/net/core/dev.c
index c0021cbd28fc..80e415ccf2c8 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4666,6 +4666,7 @@ static inline void ____napi_schedule(struct softnet_data *sd,
 	struct task_struct *thread;
 
 	lockdep_assert_irqs_disabled();
+	lockdep_assert_in_interrupt();
 
 	if (test_bit(NAPI_STATE_THREADED, &napi->state)) {
 		/* Paired with smp_mb__before_atomic() in
-- 
2.46.0


  reply	other threads:[~2025-02-12 17:43 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12 17:43 [PATCH 0/2] net: Fix/prevent napi_schedule() call from bare task context Frederic Weisbecker
2025-02-12 17:43 ` Frederic Weisbecker [this message]
2025-02-13  3:48   ` [PATCH 1/2] net: Assert proper context while calling napi_schedule() Jakub Kicinski
2025-02-13  9:58     ` Breno Leitao
2025-02-13 15:14       ` Jakub Kicinski
2025-02-13 18:14         ` Breno Leitao
2025-02-13 19:04           ` Jakub Kicinski
2025-02-13 20:38             ` Frederic Weisbecker
2025-02-14 22:00               ` Jakub Kicinski
2025-02-15 21:16                 ` Frederic Weisbecker
2025-02-14 13:05             ` Breno Leitao
2025-02-14 16:43         ` Breno Leitao
2025-02-14 22:10           ` Jakub Kicinski
2025-02-17 16:46             ` Breno Leitao
2025-02-17 17:37               ` Jakub Kicinski
2025-02-13 20:39     ` Frederic Weisbecker
2025-02-14 22:03       ` Jakub Kicinski
2025-02-12 17:43 ` [PATCH 2/2] r8152: Call napi_schedule() from proper context Frederic Weisbecker
2025-02-12 20:49   ` Francois Romieu
2025-02-12 20:58     ` Frederic Weisbecker
2025-02-18 20:12       ` Paul Menzel
2025-04-27 20:50         ` Tobias Jakobi
2025-04-28 17:49           ` Jakub Kicinski
2025-04-28 20:26             ` Tobias Jakobi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250212174329.53793-2-frederic@kernel.org \
    --to=frederic@kernel.org \
    --cc=boqun.feng@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hayeswang@realtek.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox