From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v3 10/10] lib: sbi: Extend sbi_trap_error() to dump state in a nested trap
Date: Sun, 17 Mar 2024 18:32:31 +0530 [thread overview]
Message-ID: <20240317130231.1705888-11-apatel@ventanamicro.com> (raw)
In-Reply-To: <20240317130231.1705888-1-apatel@ventanamicro.com>
The sbi_trap_error() should dump state of all in-flight traps upon
failure in a nested trap so extend it accordingly.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Tested-by: Samuel Holland <samuel.holland@sifive.com>
---
lib/sbi/sbi_trap.c | 105 ++++++++++++++++++++++++++-------------------
1 file changed, 60 insertions(+), 45 deletions(-)
diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c
index 060cec6..175560f 100644
--- a/lib/sbi/sbi_trap.c
+++ b/lib/sbi/sbi_trap.c
@@ -23,54 +23,69 @@
#include <sbi/sbi_timer.h>
#include <sbi/sbi_trap.h>
-static void __noreturn sbi_trap_error(const char *msg, int rc,
- const struct sbi_trap_info *trap,
- const struct sbi_trap_regs *regs)
+static void sbi_trap_error_one(const struct sbi_trap_context *tcntx,
+ const char *prefix, u32 hartid, u32 depth)
{
- u32 hartid = current_hartid();
+ const struct sbi_trap_info *trap = &tcntx->trap;
+ const struct sbi_trap_regs *regs = &tcntx->regs;
- sbi_printf("%s: hart%d: %s (error %d)\n", __func__, hartid, msg, rc);
- sbi_printf("%s: hart%d: mcause=0x%" PRILX " mtval=0x%" PRILX "\n",
- __func__, hartid, trap->cause, trap->tval);
+ sbi_printf("\n");
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "mcause", trap->cause, "mtval", trap->tval);
if (misa_extension('H')) {
- sbi_printf("%s: hart%d: mtval2=0x%" PRILX
- " mtinst=0x%" PRILX "\n",
- __func__, hartid, trap->tval2, trap->tinst);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "mtval2", trap->tval2, "mtinst", trap->tinst);
}
- sbi_printf("%s: hart%d: mepc=0x%" PRILX " mstatus=0x%" PRILX "\n",
- __func__, hartid, regs->mepc, regs->mstatus);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "ra", regs->ra, "sp", regs->sp);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "gp", regs->gp, "tp", regs->tp);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "s0", regs->s0, "s1", regs->s1);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "a0", regs->a0, "a1", regs->a1);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "a2", regs->a2, "a3", regs->a3);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "a4", regs->a4, "a5", regs->a5);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "a6", regs->a6, "a7", regs->a7);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "s2", regs->s2, "s3", regs->s3);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "s4", regs->s4, "s5", regs->s5);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "s6", regs->s6, "s7", regs->s7);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "s8", regs->s8, "s9", regs->s9);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "s10", regs->s10, "s11", regs->s11);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "t0", regs->t0, "t1", regs->t1);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "t2", regs->t2, "t3", regs->t3);
- sbi_printf("%s: hart%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", __func__,
- hartid, "t4", regs->t4, "t5", regs->t5);
- sbi_printf("%s: hart%d: %s=0x%" PRILX "\n", __func__, hartid, "t6",
- regs->t6);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "mepc", regs->mepc, "mstatus", regs->mstatus);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "ra", regs->ra, "sp", regs->sp);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "gp", regs->gp, "tp", regs->tp);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "s0", regs->s0, "s1", regs->s1);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "a0", regs->a0, "a1", regs->a1);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "a2", regs->a2, "a3", regs->a3);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "a4", regs->a4, "a5", regs->a5);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "a6", regs->a6, "a7", regs->a7);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "s2", regs->s2, "s3", regs->s3);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "s4", regs->s4, "s5", regs->s5);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "s6", regs->s6, "s7", regs->s7);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "s8", regs->s8, "s9", regs->s9);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "s10", regs->s10, "s11", regs->s11);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "t0", regs->t0, "t1", regs->t1);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "t2", regs->t2, "t3", regs->t3);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX " %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "t4", regs->t4, "t5", regs->t5);
+ sbi_printf("%s: hart%d: trap%d: %s=0x%" PRILX "\n", prefix,
+ hartid, depth, "t6", regs->t6);
+}
+
+static void __noreturn sbi_trap_error(const char *msg, int rc,
+ const struct sbi_trap_context *tcntx)
+{
+ u32 depth = 0, hartid = current_hartid();
+ const struct sbi_trap_context *tc;
+
+ for (tc = tcntx; tc; tc = tc->prev_context)
+ depth++;
+
+ sbi_printf("\n");
+ sbi_printf("%s: hart%d: trap%d: %s (error %d)\n", __func__,
+ hartid, depth - 1, msg, rc);
+ for (tc = tcntx; tc; tc = tc->prev_context)
+ sbi_trap_error_one(tc, __func__, hartid, --depth);
sbi_hart_hang();
}
@@ -321,7 +336,7 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx)
trap_done:
if (rc)
- sbi_trap_error(msg, rc, trap, regs);
+ sbi_trap_error(msg, rc, tcntx);
sbi_trap_set_context(scratch, tcntx->prev_context);
return tcntx;
}
--
2.34.1
next prev parent reply other threads:[~2024-03-17 13:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-17 13:02 [PATCH v3 00/10] Improve trap handling for nested traps Anup Patel
2024-03-17 13:02 ` [PATCH v3 01/10] lib: sbi: Remove epc from struct sbi_trap_info Anup Patel
2024-03-17 13:02 ` [PATCH v3 02/10] lib: sbi: Remove sbi_trap_exit() and related code Anup Patel
2024-03-17 13:02 ` [PATCH v3 03/10] include: sbi: Add trap_context pointer in struct sbi_scratch Anup Patel
2024-03-17 13:02 ` [PATCH v3 04/10] lib: sbi: Introduce trap context Anup Patel
2024-03-17 13:02 ` [PATCH v3 05/10] lib: sbi: Simplify parameters of misaligned and access fault handlers Anup Patel
2024-03-17 13:02 ` [PATCH v3 06/10] lib: sbi: Simplify parameters of sbi_illegal_insn_handler() Anup Patel
2024-03-17 13:02 ` [PATCH v3 07/10] lib: sbi: Remove regs paramter of sbi_irqchip_process() Anup Patel
2024-03-17 13:02 ` [PATCH v3 08/10] lib: sbi: Remove regs parameter from trap irq handling functions Anup Patel
2024-03-17 13:02 ` [PATCH v3 09/10] lib: sbi: Pass trap context pointer to sbi_ecall_handler() Anup Patel
2024-03-17 13:02 ` Anup Patel [this message]
2024-03-19 6:06 ` [PATCH v3 00/10] Improve trap handling for nested traps Anup Patel
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=20240317130231.1705888-11-apatel@ventanamicro.com \
--to=apatel@ventanamicro.com \
--cc=opensbi@lists.infradead.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