[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v1 08/14] xen/riscv: introduce decode_cause() stuff
- To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
- Date: Mon, 23 Jan 2023 12:09:40 +0000
- Accept-language: en-GB, en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ou5sAyXk6SHDdw+3MAn2dDSblhTDS4EeWN8QGUyPqV8=; b=iaLRMrxE3WRsXMUrC2RG0YFzmgC1nGrW0jd4B4anYJMTNuksJaEInSeNAIUS7sVOv34QmXWBiX7IlLy8XY0DCc9VkhQjnzU1PmQOSMTjmsX4qIA47zBSEFxX5TzI0t8LusHpxWvCwkINIFY8YX366hT0msXMaO9rDQ0bW5FQ6OJyMCibGU5A2bV49o6o5e1VRVapEeprDHe+/0pCACJQDzUKJ1okmMpUnWItgQUvu90KaXfqyq4VBCfn3SspjxuXhgKVV4BlPZflZ6LSxw3AuxnaWUTR8E4dak8fN8RbmbcqAmLBuy2lwksf7ZfM1rS8HVXDABA0fGxJo3wR3KoLkw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GJs/jer36UfZuJUqyOS9tHW5/z0H6Ld0rdntlYNsMncOh+Xq6V4A8tPg25yuiRwRkmB+pBFoea2tgh96TpnT+ypmJmHMOO8akweAJlhjS+D+/T9+WKrz+IywSTcPrSYVzt3o+YqO83Jo3IY87yFwdQc8ky4K8BP7UN7WxWeM+V76b1wgRSP6WN2+njJ2QGtg/KG/Q1KFfzbCZ18u4myYu0vj09a8nL6/voL60cTynj+RahOl7O071pfEdX2myyZz7hV7C1NpD3mhWcW2VQreLvtrrjZL+Y/cXX0Vo0o1obQtLcDu4Sc554B+JFeo5iBgIGHidOxB/u1iqsLuz1kHVQ==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
- Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Gianluca Guida <gianluca@xxxxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>
- Delivery-date: Mon, 23 Jan 2023 12:10:11 +0000
- Ironport-data: A9a23:/McqKKnzpr+SNr6XK+zO3/Lo5gwaJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xIeD2DTM//eNmDxKtsgOdnkoU1U6JaHzdcwTlZr+SFhFiMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icf3grHmeIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7auaVA8w5ARkPqgS5gSGzhH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 dxbIismRDOuu7uznO3nabBxjesZa8a+aevzulk4pd3YJdAPZMmaBo/stZpf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVw3iea9WDbWUoXiqcF9t0CUv G/ZuU/+BQkXLoe3wjuZ6HO8wOTImEsXXapDT+Lmq6Yw3zV/wEQiUBA3TnaSpMWSpXaiHIl/D Xc/whgh+P1aGEuDC4OVsweDiHmAsx0HWtsWEPAg7wqNya387AOQB2xCRTlEAPQ2uclzSTE02 1uhm9LyGScpoLCTUWia9LqfsXW1Iyd9BXQZeSYOQA8B4t/iiII+lBTCSpBkCqHdptL0EDf03 juDhDI/mbIIjMgAka68+DjviTWmrInEVQ4x6wDeWEqq6wp4YMiuYInAwVHf7O1cJYeDCFebt X4PmtO28+wFS5qKkUSlS+ILGrar6/+bMSb0jltmHp1n/DOok0NPZqhV6TB6YU1vYsANfGawZ FeJ4F0BophOIHGtcKl7JZqrDNgnxrThEtKjUe3Iat1JYd56cwrvEDxSWHN8FlvFyCAE+ZzT8 7/BL65A0V5y5Xxb8QeL
- Ironport-hdrordr: A9a23:wQnc5qNKfN/IeMBcTuCjsMiBIKoaSvp037BL7TELdfUxSKalfq +V7ZAmPHPP+VMssRIb6LO90cu7MBXhHPdOiOF7XNeftSbdyQmVxepZnPLfKlPbalXDHy1muZ uIsZISNPTASXZ9i8j+7E2DH9EszMLC2Ly0hI7lvhBQpM1RBJ2IJj0WNjqm
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Thread-index: AQHZLN///evNj7qtDEG2WE9mE7PhWK6r7WMA
- Thread-topic: [PATCH v1 08/14] xen/riscv: introduce decode_cause() stuff
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
|