linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eugeniu Rosca <erosca@de.adit-jv.com>
To: <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>, Will Deacon <will@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Jiafei Pan <Jiafei.Pan@nxp.com>,
	Romain Perier <romain.perier@gmail.com>
Cc: Andrew Gabbasov <andrew_gabbasov@mentor.com>,
	Dirk Behme <dirk.behme@de.bosch.com>,
	Eugeniu Rosca <roscaeugeniu@gmail.com>,
	Eugeniu Rosca <erosca@de.adit-jv.com>
Subject: [PATCH v2] softirq: s/BUG/WARN_ONCE/ on tasklet SCHED state not set
Date: Wed, 17 Mar 2021 11:20:12 +0100	[thread overview]
Message-ID: <20210317102012.32399-1-erosca@de.adit-jv.com> (raw)

From: Dirk Behme <dirk.behme@de.bosch.com>

Replace BUG() with WARN_ONCE() on wrong tasklet state, in order to:
 * increase the verbosity / aid in debugging
 * avoid fatal/unrecoverable state

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
---

Changes since v1:
 * Factored out the change into a separate function
 * Replaced BUG with WARN_ONCE
 * Fixed 'checkpatch --strict' errors
 * v1: https://lore.kernel.org/lkml/20210315154421.11463-1-erosca@de.adit-jv.com/

 kernel/softirq.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/kernel/softirq.c b/kernel/softirq.c
index 9908ec4a9bfe..17a93d47b9a1 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -531,6 +531,18 @@ void __tasklet_hi_schedule(struct tasklet_struct *t)
 }
 EXPORT_SYMBOL(__tasklet_hi_schedule);
 
+static bool tasklet_should_run(struct tasklet_struct *t)
+{
+	if (test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
+		return true;
+
+	WARN_ONCE(1, "tasklet SCHED state not set: %s %pS\n",
+		  t->use_callback ? "callback" : "func",
+		  t->use_callback ? (void *)t->callback : (void *)t->func);
+
+	return false;
+}
+
 static void tasklet_action_common(struct softirq_action *a,
 				  struct tasklet_head *tl_head,
 				  unsigned int softirq_nr)
@@ -550,13 +562,12 @@ static void tasklet_action_common(struct softirq_action *a,
 
 		if (tasklet_trylock(t)) {
 			if (!atomic_read(&t->count)) {
-				if (!test_and_clear_bit(TASKLET_STATE_SCHED,
-							&t->state))
-					BUG();
-				if (t->use_callback)
-					t->callback(t);
-				else
-					t->func(t->data);
+				if (tasklet_should_run(t)) {
+					if (t->use_callback)
+						t->callback(t);
+					else
+						t->func(t->data);
+				}
 				tasklet_unlock(t);
 				continue;
 			}
-- 
2.29.0


             reply	other threads:[~2021-03-17 10:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 10:20 Eugeniu Rosca [this message]
2021-03-17 12:38 ` [tip: irq/core] softirq: s/BUG/WARN_ONCE/ on tasklet SCHED state not set tip-bot2 for Dirk Behme

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=20210317102012.32399-1-erosca@de.adit-jv.com \
    --to=erosca@de.adit-jv.com \
    --cc=Jiafei.Pan@nxp.com \
    --cc=andrew_gabbasov@mentor.com \
    --cc=dirk.behme@de.bosch.com \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=romain.perier@gmail.com \
    --cc=roscaeugeniu@gmail.com \
    --cc=tglx@linutronix.de \
    --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;
as well as URLs for NNTP newsgroup(s).