All of lore.kernel.org
 help / color / mirror / Atom feed
From: clement.leger@linux.dev
To: Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>
Cc: "Clément Léger" <clement.leger@linux.dev>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] riscv: kgdb: Fix potential missing local_irq_restore() call
Date: Thu, 29 Oct 2026 21:31:42 +0100	[thread overview]
Message-ID: <20261029203144.190422-1-clement.leger@linux.dev> (raw)

From: Clément Léger <clement.leger@linux.dev>

If kgdb_handle_exception() returns an error, local irqs are not
reenabled. Fix this by factoring out the kgdb exception handling to a
function and call it between local_irq_save()/local_irq_restore() so
that the error handling flow is simple.

Signed-off-by: Clément Léger <clement.leger@linux.dev>

---
 arch/riscv/kernel/kgdb.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/arch/riscv/kernel/kgdb.c b/arch/riscv/kernel/kgdb.c
index 0bf629204c76..b833408494f9 100644
--- a/arch/riscv/kernel/kgdb.c
+++ b/arch/riscv/kernel/kgdb.c
@@ -319,13 +319,28 @@ static int kgdb_riscv_kgdbbreak(unsigned long addr)
 	return kgdb_has_hit_break(addr);
 }
 
+static int kgdb_riscv_handle(struct die_args *args, unsigned long cmd,
+			     int type)
+{
+	struct pt_regs *regs = args->regs;
+
+	if (kgdb_handle_exception(type == KGDB_SW_SINGLE_STEP ? 0 : 1,
+				  args->signr, cmd, regs))
+		return NOTIFY_DONE;
+
+	if (type == KGDB_COMPILED_BREAK)
+		regs->epc += 4;
+
+	return NOTIFY_STOP;
+}
+
 static int kgdb_riscv_notify(struct notifier_block *self, unsigned long cmd,
 			     void *ptr)
 {
 	struct die_args *args = (struct die_args *)ptr;
 	struct pt_regs *regs = args->regs;
 	unsigned long flags;
-	int type;
+	int type, ret;
 
 	if (user_mode(regs))
 		return NOTIFY_DONE;
@@ -335,17 +350,10 @@ static int kgdb_riscv_notify(struct notifier_block *self, unsigned long cmd,
 		return NOTIFY_DONE;
 
 	local_irq_save(flags);
-
-	if (kgdb_handle_exception(type == KGDB_SW_SINGLE_STEP ? 0 : 1,
-				  args->signr, cmd, regs))
-		return NOTIFY_DONE;
-
-	if (type == KGDB_COMPILED_BREAK)
-		regs->epc += 4;
-
+	ret = kgdb_riscv_handle(args, cmd, type);
 	local_irq_restore(flags);
 
-	return NOTIFY_STOP;
+	return ret;
 }
 
 static struct notifier_block kgdb_notifier = {
-- 
2.55.0


                 reply	other threads:[~2026-10-29 20:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261029203144.190422-1-clement.leger@linux.dev \
    --to=clement.leger@linux.dev \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.