From: Andrew Cooper <Andrew.Cooper3@citrix.com>
To: Oleksii Kurochko <oleksii.kurochko@gmail.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Gianluca Guida <gianluca@rivosinc.com>,
Bob Eshleman <bobbyeshleman@gmail.com>,
Alistair Francis <alistair.francis@wdc.com>,
Connor Davis <connojdavis@gmail.com>
Subject: Re: [PATCH v1 08/14] xen/riscv: introduce decode_cause() stuff
Date: Mon, 23 Jan 2023 12:09:40 +0000 [thread overview]
Message-ID: <00af9dc0-1a3c-ef37-3d4d-b0a307349bf3@citrix.com> (raw)
In-Reply-To: <c798832ec19cb94c0a27e8cff8f5bd6d1aa6ae7e.1674226563.git.oleksii.kurochko@gmail.com>
On 20/01/2023 2:59 pm, Oleksii Kurochko wrote:
> diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c
> index 3201b851ef..dd64f053a5 100644
> --- a/xen/arch/riscv/traps.c
> +++ b/xen/arch/riscv/traps.c
> @@ -4,8 +4,96 @@
> *
> * RISC-V Trap handlers
> */
> +#include <asm/csr.h>
> +#include <asm/early_printk.h>
> #include <asm/processor.h>
> #include <asm/traps.h>
> +#include <xen/errno.h>
> +
> +const char *decode_trap_cause(unsigned long cause)
These should be static as you've not put a declaration in a header
file. But as it stands, you'll then get a compiler warning on
decode_cause() as it's not used.
I would merge this patch with the following patch, as the following
patch is very related to this, and then you can get everything nicely
static without unused warnings.
> +{
> + switch ( cause )
> + {
> + case CAUSE_MISALIGNED_FETCH:
> + return "Instruction Address Misaligned";
> + case CAUSE_FETCH_ACCESS:
> + return "Instruction Access Fault";
> + case CAUSE_ILLEGAL_INSTRUCTION:
> + return "Illegal Instruction";
> + case CAUSE_BREAKPOINT:
> + return "Breakpoint";
> + case CAUSE_MISALIGNED_LOAD:
> + return "Load Address Misaligned";
> + case CAUSE_LOAD_ACCESS:
> + return "Load Access Fault";
> + case CAUSE_MISALIGNED_STORE:
> + return "Store/AMO Address Misaligned";
> + case CAUSE_STORE_ACCESS:
> + return "Store/AMO Access Fault";
> + case CAUSE_USER_ECALL:
> + return "Environment Call from U-Mode";
> + case CAUSE_SUPERVISOR_ECALL:
> + return "Environment Call from S-Mode";
> + case CAUSE_MACHINE_ECALL:
> + return "Environment Call from M-Mode";
> + case CAUSE_FETCH_PAGE_FAULT:
> + return "Instruction Page Fault";
> + case CAUSE_LOAD_PAGE_FAULT:
> + return "Load Page Fault";
> + case CAUSE_STORE_PAGE_FAULT:
> + return "Store/AMO Page Fault";
> + case CAUSE_FETCH_GUEST_PAGE_FAULT:
> + return "Instruction Guest Page Fault";
> + case CAUSE_LOAD_GUEST_PAGE_FAULT:
> + return "Load Guest Page Fault";
> + case CAUSE_VIRTUAL_INST_FAULT:
> + return "Virtualized Instruction Fault";
> + case CAUSE_STORE_GUEST_PAGE_FAULT:
> + return "Guest Store/AMO Page Fault";
> + default:
> + return "UNKNOWN";
This style tends to lead to poor code generation. You probably want:
const char *decode_trap_cause(unsigned long cause)
{
static const char *const trap_causes[] = {
[CAUSE_MISALIGNED_FETCH] = "Instruction Address Misaligned",
...
[CAUSE_STORE_GUEST_PAGE_FAULT] = "Guest Store/AMO Page Fault",
};
if ( cause < ARRAY_SIZE(trap_causes) && trap_causes[cause] )
return trap_causes[cause];
return "UNKNOWN";
}
(note the trailing comma on the final entry, which is there to simply
future diffs)
However, given the hope to get snprintf() wired up, you actually want to
to adjust this to:
if ( cause < ARRAY_SIZE(trap_causes) )
return trap_causes[cause];
return NULL;
And render the raw cause number for the unknown case, because that is
far more useful for whomever is debugging.
~Andrew
next prev parent reply other threads:[~2023-01-23 12:10 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 14:59 [PATCH v1 00/14] RISCV basic exception handling implementation Oleksii Kurochko
2023-01-20 14:59 ` [PATCH v1 01/14] xen/riscv: add _zicsr to CFLAGS Oleksii Kurochko
2023-01-20 15:29 ` Andrew Cooper
2023-01-23 10:43 ` Oleksii
2023-01-31 11:49 ` Alistair Francis
2023-01-31 12:30 ` Oleksii
2023-01-20 14:59 ` [PATCH v1 02/14] xen/riscv: add <asm/asm.h> header Oleksii Kurochko
2023-01-20 15:31 ` Andrew Cooper
2023-01-23 11:00 ` Jan Beulich
2023-01-23 11:10 ` Andrew Cooper
2023-01-22 22:58 ` Alistair Francis
2023-01-20 14:59 ` [PATCH v1 03/14] xen/riscv: add <asm/riscv_encoding.h header Oleksii Kurochko
2023-01-22 23:24 ` Alistair Francis
2023-01-23 13:52 ` Jan Beulich
2023-01-23 14:04 ` Oleksii
2023-01-23 14:06 ` Jan Beulich
2023-01-20 14:59 ` [PATCH v1 04/14] xen/riscv: add <asm/csr.h> header Oleksii Kurochko
2023-01-22 23:25 ` Alistair Francis
2023-01-23 13:57 ` Jan Beulich
2023-01-23 14:23 ` Oleksii
2023-01-23 14:31 ` Jan Beulich
2023-01-20 14:59 ` [PATCH v1 05/14] xen/riscv: add early_printk_hnum() function Oleksii Kurochko
2023-01-20 15:39 ` Andrew Cooper
2023-01-23 12:05 ` Oleksii
2023-01-23 11:10 ` Jan Beulich
2023-01-20 14:59 ` [PATCH v1 06/14] xen/riscv: introduce exception context Oleksii Kurochko
2023-01-20 15:54 ` Andrew Cooper
2023-01-23 12:03 ` Oleksii
2023-01-23 12:25 ` Andrew Cooper
2023-01-23 11:13 ` Jan Beulich
2023-01-20 14:59 ` [PATCH v1 07/14] xen/riscv: introduce exception handlers implementation Oleksii Kurochko
2023-01-22 23:29 ` Alistair Francis
2023-01-23 11:17 ` Jan Beulich
2023-01-23 15:04 ` Oleksii
2023-01-23 11:50 ` Andrew Cooper
2023-01-23 12:41 ` Jan Beulich
2023-01-23 15:17 ` Oleksii
2023-01-23 20:09 ` Andrew Cooper
2023-01-25 14:44 ` Oleksii
2023-01-20 14:59 ` [PATCH v1 08/14] xen/riscv: introduce decode_cause() stuff Oleksii Kurochko
2023-01-22 23:38 ` Alistair Francis
2023-01-23 12:09 ` Andrew Cooper [this message]
2023-01-20 14:59 ` [PATCH v1 09/14] xen/riscv: introduce do_unexpected_trap() Oleksii Kurochko
2023-01-22 23:39 ` Alistair Francis
2023-01-25 17:01 ` Oleksii
2023-01-25 17:11 ` Julien Grall
2023-01-25 17:15 ` Andrew Cooper
2023-01-26 8:40 ` Oleksii
2023-01-20 14:59 ` [PATCH v1 10/14] xen/riscv: mask all interrupts Oleksii Kurochko
2023-01-22 23:40 ` Alistair Francis
2023-01-20 14:59 ` [PATCH v1 11/14] xen/riscv: introduce setup_trap_handler() Oleksii Kurochko
2023-01-22 23:41 ` Alistair Francis
2023-01-23 23:21 ` Andrew Cooper
2023-01-20 14:59 ` [PATCH v1 12/14] xen/riscv: introduce an implementation of macros from <asm/bug.h> Oleksii Kurochko
2023-01-23 11:37 ` Jan Beulich
2023-01-20 14:59 ` [PATCH v1 13/14] xen/riscv: test basic handling stuff Oleksii Kurochko
2023-01-20 14:59 ` [PATCH v1 14/14] automation: add smoke test to verify macros from bug.h Oleksii Kurochko
2023-01-24 23:53 ` Stefano Stabellini
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=00af9dc0-1a3c-ef37-3d4d-b0a307349bf3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=alistair.francis@wdc.com \
--cc=bobbyeshleman@gmail.com \
--cc=connojdavis@gmail.com \
--cc=gianluca@rivosinc.com \
--cc=oleksii.kurochko@gmail.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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.