From patchwork Fri Aug 2 13:54:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13751561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D6A3C52D6D for ; Fri, 2 Aug 2024 13:54:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.771218.1181791 (Exim 4.92) (envelope-from ) id 1sZsjZ-0003Ag-AS; Fri, 02 Aug 2024 13:54:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 771218.1181791; Fri, 02 Aug 2024 13:54:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZsjZ-000397-5u; Fri, 02 Aug 2024 13:54:17 +0000 Received: by outflank-mailman (input) for mailman id 771218; Fri, 02 Aug 2024 13:54:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZsjY-00036j-4z for xen-devel@lists.xenproject.org; Fri, 02 Aug 2024 13:54:16 +0000 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [2a00:1450:4864:20::229]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b42042f5-50d6-11ef-bc03-fd08da9f4363; Fri, 02 Aug 2024 15:54:14 +0200 (CEST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2ef27bfd15bso104951951fa.2 for ; Fri, 02 Aug 2024 06:54:14 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f15e1ae4easm1684271fa.43.2024.08.02.06.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 06:54:13 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b42042f5-50d6-11ef-bc03-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722606854; x=1723211654; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8vYENS4GOrzDyoLqzf6YJMTgRNv1aUaS9P/N7H1oUq4=; b=AU0nBErxAefkckDo35pM0PB6HRscd5GLz5hRg61lP6VYubOkKxdzyh7A5GDtJ4lK+z W8fogpy3HAN/+UR417JKUEhvW38TzChX/eBSDnjKWmktOg4vldp1XuCIqA9Brke0nwkw WIqqTZLBnzv1uGnzztRFP/RuhwZ0VUkWSw8HX+HEZfRm5r9Ta4D/KixjIqWTF1l+8ATC uZJfahBXmy5/Uq78SWSzBLdIdJ76XD5QNy6wWW1tEFk8Qn1SGskVO0kME0B/tCnEo/4S bOh1YkUi5lpC9YQOH9Of3Lnq/pCDW5lyl79gDflFx7vK8Bvu8NIt1snbIIe48uHK4PBm dFlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722606854; x=1723211654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8vYENS4GOrzDyoLqzf6YJMTgRNv1aUaS9P/N7H1oUq4=; b=pS0pPW8aPtnDYjyxQMwK9fNgf9Lgsk9BhkfuNC3pa3gQRX/LwQQvd9E5Tu5zGY5QqO 0TpMq7Y0itZhsbBB3cCBOnuBQbiNtRoR4wW+fVVppcadm+Cc/Y/xYQOac4ljWlUKl96P YbkuAO4iKmPohDal4sFjJZhTDSbXf1JdtNkPEAK3nZEd96dt13l+4pUjm1rPt1WXZtEH T4w3Xb1SLHx/ckgJUrGDUX6t8ojqAOB5PZZnKQsfcCvE3qFvvdDPt/TOjOxVCc1+wDw/ i2Vor5vDUdcvjP5EhSkHww1eEdicqP1tMBVrl149oiyufyYzNHdsWSeGmzIlrjBopotn E44g== X-Gm-Message-State: AOJu0YwxMd0GgovULa6XYbeM2u5avnfs38S67VCeDDVrTOCKE0GFXndm S7ERZmcSsRZ0p5loQbikYZixuWCkLjFuIjmz2NT3TRzCznHCZpFHL1DImg== X-Google-Smtp-Source: AGHT+IFqAyT4ng08KrkKSh6DAucBsCP0itGzNsRbWuHjWX1FPj1vH48eGKEHoyxLs8vKk0vc8tuTQA== X-Received: by 2002:a2e:9606:0:b0:2ef:23ec:9357 with SMTP id 38308e7fff4ca-2f15a9f988emr27541791fa.0.1722606853462; Fri, 02 Aug 2024 06:54:13 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v12 1/3] xen/riscv: enable GENERIC_BUG_FRAME Date: Fri, 2 Aug 2024 15:54:07 +0200 Message-ID: <3d507ce45606d22e9fa07dd6087870c16b5c4a4e.1722605952.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Enable GENERIC_BUG_FRAME to support BUG(), WARN(), ASSERT, and run_in_exception_handler(). The 0x0000 opcode is used for BUG_INSTR, which, when macros from are used, triggers an exception with the ILLEGAL_INSTRUCTION cause. This opcode is encoded as a 2-byte instruction and is invalid if CONFIG_RISCV_ISA_C is enabled or not. Using 'ebreak' as BUG_INSTR does not guarantee proper handling of macros from . If a debugger inserts a breakpoint (using the 'ebreak' instruction) at a location where Xen already uses 'ebreak', it creates ambiguity. Xen cannot distinguish whether the 'ebreak' instruction is inserted by the debugger or is part of Xen's own code. Remove BUG_INSN_32 and BUG_INSN_16 macros as they encode the ebreak instruction, which is no longer used for BUG_INSN. Update the commit above the definition of INS_LENGTH_MASK as ebreak isn't and 2-byte instruction is used to encode BUG_INSTR so it doesn't matter if CONFIG_RISCV_ISA_C is enabled or not. is included for the reason that panic() and printk() are used in common/bug.c and RISC-V fails if it is not included. Signed-off-by: Oleksii Kurochko --- Changes in V12: - Update the commit message - Use 0x0000 as BUG_INSTR instead of 'ebreak' to deal with cases when the debugger inserts 'ebreak' into the place where Xen has ebreak. - Remove BUG_INSN_32 and BUG_INSN_16 macros as they encode the ebreak instruction, which is no longer used for BUG_INSN. - Update the commit above the definition of INS_LENGTH_MASK. - Move break inside "if ( do_bug_frame(cpu_regs, pc) >= 0 )". --- Changes in V11: - update the commit message - change "%lx" to "%#x" for PC register printing. - drop +1 in argument of is_kernel_text(pc) and is_kernel_inittext(pc). - drop return for case CAUSE_BREAKPOINT. - add break to default and add a blank like above it. - add a comment CAUSE_BREAKPOINT is handled instead of illegal instruction. --- Changes in V10: - put 'select GENERIC_BUG_FRAME' in "Config RISCV". - rework do_trap() to not fetch an instruction in case when the cause of trap is BUG_insn. - drop read_instr() and is_valid_bug_insn(). - update the commit message. --- Changes in V9: - Rebase on the top of current staging. - use GENERIC_BUG_FRAME as now we have common code available. - add xen/lib.h to bug.c to fix a compilation error around printk. - update the commit message. - update the code of read_instr() in traps.c - fold two-s if into 1 in do_trap. --- Changes in V8: - remove Pointless initializer of id. - make bug_frames[] array constant. - remove cast_to_bug_frame(addr). - rename is_valig_bugaddr to is_valid_bug_insn(). - add check that read_instr is used only on xen code - update the commit message. --- Changes in V7: - move to this patch the definition of cast_to_bug_frame() from the previous patch. - update the comment in bug.h. - update the comment above do_bug_frame(). - fix code style. - add comment to read_instr func. - add space for bug_frames in lds.S. --- Changes in V6: - Avoid LINK_TO_LOAD() as bug.h functionality expected to be used after MMU is enabled. - Change early_printk() to printk() --- Changes in V5: - Remove "#include " from as there is no any need in it anymore - Update macros GET_INSN_LENGTH: remove UL and 'unsigned int len;' from it - Remove " include " from risc/setup.c. it is not needed in the current version of the patch - change an argument type from vaddr_t to uint32_t for is_valid_bugaddr and introduce read_instr() to read instruction properly as the length of qinstruction can be either 32 or 16 bits. - Code style fixes - update the comments before do_bug_frame() in riscv/trap.c - Refactor is_valid_bugaddr() function. - introduce macros cast_to_bug_frame(addr) to hide casts. - use LINK_TO_LOAD() for addresses which are linker time relative. --- Changes in V4: - Updates in RISC-V's : * Add explanatory comment about why there is only defined for 32-bits length instructions and 16/32-bits BUG_INSN_{16,32}. * Change 'unsigned long' to 'unsigned int' inside GET_INSN_LENGTH(). * Update declaration of is_valid_bugaddr(): switch return type from int to bool and the argument from 'unsigned int' to 'vaddr'. - Updates in RISC-V's traps.c: * replace /xen and /asm includes * update definition of is_valid_bugaddr():switch return type from int to bool and the argument from 'unsigned int' to 'vaddr'. Code style inside function was updated too. * do_bug_frame() refactoring: * local variables start and bug became 'const struct bug_frame' * bug_frames[] array became 'static const struct bug_frame[] = ...' * remove all casts * remove unneeded comments and add an explanatory comment that the do_bug_frame() will be switched to a generic one. * do_trap() refactoring: * read 16-bits value instead of 32-bits as compressed instruction can be used and it might happen than only 16-bits may be accessible. * code style updates * re-use instr variable instead of re-reading instruction. - Updates in setup.c: * add blank line between xen/ and asm/ includes. --- Changes in V3: - Rebase the patch "xen/riscv: introduce an implementation of macros from " on top of patch series [introduce generic implementation of macros from bug.h] --- Changes in V2: - Remove __ in define namings - Update run_in_exception_handler() with register void *fn_ asm(__stringify(BUG_FN_REG)) = (fn); - Remove bug_instr_t type and change it's usage to uint32_t --- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/include/asm/bug.h | 12 +++++------- xen/arch/riscv/traps.c | 25 ++++++++++++++++++++++++- xen/common/bug.c | 1 + 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index b4b354a778..f531e96657 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -1,6 +1,7 @@ config RISCV def_bool y select FUNCTION_ALIGNMENT_16B + select GENERIC_BUG_FRAME config RISCV_64 def_bool y diff --git a/xen/arch/riscv/include/asm/bug.h b/xen/arch/riscv/include/asm/bug.h index f5ff96140f..1fffef5037 100644 --- a/xen/arch/riscv/include/asm/bug.h +++ b/xen/arch/riscv/include/asm/bug.h @@ -9,7 +9,11 @@ #ifndef __ASSEMBLY__ -#define BUG_INSTR "ebreak" +#include + +#define BUG_OPCODE 0x0000 + +#define BUG_INSTR ".hword " __stringify(BUG_OPCODE) /* * The base instruction set has a fixed length of 32-bit naturally aligned @@ -17,16 +21,10 @@ * * There are extensions of variable length ( where each instruction can be * any number of 16-bit parcels in length ). - * - * Compressed ISA is used now where the instruction length is 16 bit and - * 'ebreak' instruction, in this case, can be either 16 or 32 bit ( - * depending on if compressed ISA is used or not ) */ #define INSN_LENGTH_MASK _UL(0x3) #define INSN_LENGTH_32 _UL(0x3) -#define BUG_INSN_32 _UL(0x00100073) /* ebreak */ -#define BUG_INSN_16 _UL(0x9002) /* c.ebreak */ #define COMPRESSED_INSN_MASK _UL(0xffff) #define GET_INSN_LENGTH(insn) \ diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index cb18b30ff2..72ffdcd79e 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -5,6 +5,7 @@ * RISC-V Trap handlers */ +#include #include #include @@ -103,7 +104,29 @@ static void do_unexpected_trap(const struct cpu_user_regs *regs) void do_trap(struct cpu_user_regs *cpu_regs) { - do_unexpected_trap(cpu_regs); + register_t pc = cpu_regs->sepc; + unsigned long cause = csr_read(CSR_SCAUSE); + + switch ( cause ) + { + case CAUSE_ILLEGAL_INSTRUCTION: + if ( do_bug_frame(cpu_regs, pc) >= 0 ) + { + if ( !(is_kernel_text(pc) || is_kernel_inittext(pc)) ) + { + printk("Something wrong with PC: %#lx\n", pc); + die(); + } + + cpu_regs->sepc += GET_INSN_LENGTH(*(uint16_t *)pc); + + break; + } + + default: + do_unexpected_trap(cpu_regs); + break; + } } void vcpu_show_execution_state(struct vcpu *v) diff --git a/xen/common/bug.c b/xen/common/bug.c index b7c5d8fd4d..75cb35fcfa 100644 --- a/xen/common/bug.c +++ b/xen/common/bug.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include From patchwork Fri Aug 2 13:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13751560 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D630EC52D6F for ; Fri, 2 Aug 2024 13:54:29 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.771220.1181806 (Exim 4.92) (envelope-from ) id 1sZsja-0003QE-3s; Fri, 02 Aug 2024 13:54:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 771220.1181806; Fri, 02 Aug 2024 13:54:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZsjZ-0003Pn-Ta; Fri, 02 Aug 2024 13:54:17 +0000 Received: by outflank-mailman (input) for mailman id 771220; Fri, 02 Aug 2024 13:54:17 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZsjZ-00036y-6F for xen-devel@lists.xenproject.org; Fri, 02 Aug 2024 13:54:17 +0000 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [2a00:1450:4864:20::22f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b473272c-50d6-11ef-8776-851b0ebba9a2; Fri, 02 Aug 2024 15:54:15 +0200 (CEST) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2ef2cce8be8so101593261fa.1 for ; Fri, 02 Aug 2024 06:54:15 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f15e1ae4easm1684271fa.43.2024.08.02.06.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 06:54:13 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b473272c-50d6-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722606854; x=1723211654; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wIOcN4PHeriEnZEntkfGwdQOvLPTgN17YwTpAAoCcJk=; b=Nv0ZTqmwLLUqoDpTMXFSV94/6g8FuGWi7+eOUz4aKaKCBdayDXWuk5X3sMRkRpymco +5ikDiWC8pCIAQR78nXK3uKrMrf6yV9vBd/wCpLS08+ogC0u+8HCpPf+KXVlD6XEiLLH 88mqYOMYOSTEiahbrBfJGVN2u6Ea+5IUbNnHH9RDBMKfgC2tG0y/uhkWvCbg2v2TC2nL kLPe3EtYpYgOoOg0HjAcx5fp8lIAAKiE+Rk9DOkLIzsQH3QsHyI4gUKYj0LoG4TxYSzB Y5DRyq+frqMCe83pT6pGT3asv5vijmt1MkyeQ8R/MiQp4wTc6DGCclC8iN8MiXVswK7E GCMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722606854; x=1723211654; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wIOcN4PHeriEnZEntkfGwdQOvLPTgN17YwTpAAoCcJk=; b=N6eIBHJLjX0Ne581M8NRttPAsxnoKR+ZaSgi56VhjbER5TJitdLl4D2cj42KlhVUdA S5p7hOA8e36T0yKCVe+ujeDJobMehQdCY6N8dYqY29n5Orwa/6jF/XN91R4KUxbY8RM8 Qpe1ozFBIvaw6RCzZGbL98I9skyVFULZSzmDLoCoEp5NyNEkZ+rG4aD23ucEDTbv33D2 dWK9TwnqbWUh0zoh7liuaU+JhWB1k4ZiNxPB+RBMj6Pf1DMkuOtFTAWwAgfuuy1IqXlG wznComm84b2DDf00hZQqaoUN/97INKJm+/FA4tIT6eZAdDAKqje7h8V7pCbipdexskqZ P9cg== X-Gm-Message-State: AOJu0YwgiOLn15QOuI9bfquPQa7Wbd2Npou6jKcYQIKVe/nYc8xpaCvj 9YyDq0fa0gUr2yWpHZkhS+ZdT7Xy8hfjHmMSUDLs71gY0l/fN3sGryB2Aw== X-Google-Smtp-Source: AGHT+IEANmQhPUVt4MoYximYaBpIi4QWwle/e/k966V3fREoWHOCp71fE3RGalCYB+bkOiMMtOb0uA== X-Received: by 2002:a2e:884e:0:b0:2ef:2580:c0c6 with SMTP id 38308e7fff4ca-2f15aa9a091mr27091761fa.14.1722606854199; Fri, 02 Aug 2024 06:54:14 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v12 2/3] xen/riscv: test basic exception handling stuff Date: Fri, 2 Aug 2024 15:54:08 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Introduces testing of some macros from . Also wraps this testing into SELF_TESTS config to not produce a noise in the log related to functionality testing ( in the current case, it is macros from xen/bug.h ) when CONFIG_SELF_TESTS is disabled. Signed-off-by: Oleksii Kurochko Acked-by: Alistair Francis --- Changes in V12: - Notrhing changed. Only rebase. --- Changes in V11: - update the commit message. --- Changes in V10: - wrap test_macros_from_bug_h() under "#ifdef CONFIG_SELF_TESTS" - update the commit title to: "xen/riscv: test basic exception handling stuff" --- Changes in V9: - s/early_printk/printk as common code is now available --- Changes in V5-V8: - Nothing changed. Only rebase. --- Changes in V4: - Add Acked-by: Alistair Francis --- Changes in V2-V3: - Nothing changed --- xen/arch/riscv/setup.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index a6a29a1508..4defad68f4 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -19,6 +19,22 @@ void arch_get_xen_caps(xen_capabilities_info_t *info) unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE); +#ifdef CONFIG_SELF_TESTS +static void test_run_in_exception(const struct cpu_user_regs *regs) +{ + printk("If you see this message, "); + printk("run_in_exception_handler is most likely working\n"); +} + +static void test_macros_from_bug_h(void) +{ + run_in_exception_handler(test_run_in_exception); + WARN(); + printk("If you see this message, "); + printk("WARN is most likely working\n"); +} +#endif + void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { @@ -26,6 +42,10 @@ void __init noreturn start_xen(unsigned long bootcpu_id, trap_init(); +#ifdef CONFIG_SELF_TESTS + test_macros_from_bug_h(); +#endif + printk("All set up\n"); for ( ;; ) From patchwork Fri Aug 2 13:54:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13751559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6CFBC3DA4A for ; Fri, 2 Aug 2024 13:54:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.771219.1181799 (Exim 4.92) (envelope-from ) id 1sZsjZ-0003Ks-Pn; Fri, 02 Aug 2024 13:54:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 771219.1181799; Fri, 02 Aug 2024 13:54:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZsjZ-0003Jw-Kv; Fri, 02 Aug 2024 13:54:17 +0000 Received: by outflank-mailman (input) for mailman id 771219; Fri, 02 Aug 2024 13:54:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sZsjY-00036j-OS for xen-devel@lists.xenproject.org; Fri, 02 Aug 2024 13:54:16 +0000 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [2a00:1450:4864:20::22a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b4e9a8b5-50d6-11ef-bc03-fd08da9f4363; Fri, 02 Aug 2024 15:54:16 +0200 (CEST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2ef2d582e31so96118121fa.2 for ; Fri, 02 Aug 2024 06:54:16 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2f15e1ae4easm1684271fa.43.2024.08.02.06.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 06:54:14 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b4e9a8b5-50d6-11ef-bc03-fd08da9f4363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722606855; x=1723211655; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9xMFnCQstUzRDpJ+Lt8V1NerdXhHxQ/jZPU/wjOAbGA=; b=axmmV1u+JFrGY4t8gaewl3rsax935QuHnNRN9uoKtfGgdrjXJcCXPhNxJa2MgI2SYF 1g7XyYMHaF912EFkK3iFXN0vrhVlgDziAwzNGC0uupYidVvk3PK8XiqC0Tf4N3mU1JMm IIV7h/zm4rDyzM7kB3HfM76eT6NigcVAr75iVrTvgmHYULEo1NSp6kkmrZiBQaalPqsi q/TpFTPvBMKr/le6t9xDtqDPx4dD4xoQ+zQjnbMzdwR77BN+/7f3sVm1NKsnBeZhv5t9 NLeTcd2wiIExuQ2ovhLGLsLcRBh24lMrvp6cNkfGp/CqNeu8lVQSfZMaJSZdKDqf4Uuo QvIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722606855; x=1723211655; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9xMFnCQstUzRDpJ+Lt8V1NerdXhHxQ/jZPU/wjOAbGA=; b=l1ndGbcZKO/5A1QJtSPntR9AQrDMU7ggqwM6VuMHbtUbxurSXBZw3wajO9P/PXz9Gx kovcSJemEIPms89lDKnIIDcFQSzO28vaNaws/EkW8eGY9NwMeIVP+Ek1o+hMQ1u4dLrL 0aYGrDo/98H+6KnkDDsvTFD+CWWnFXk0mFhgpee0J9s/53J892c+jIdvh7Xh3B3Mp1MZ g3WO7SkIeaGYmT9D+3a+NmcFguw3nQg9jyecwueY22VY9PUyc3vPa/SH5NAOyOmBFqfc IVFCEau5HRSbcmLyIt1wDSNDJ6dZRqiM1m4hpLYIAvTyW0lUMDdwURPSrrnhdE56N5mS 6yKQ== X-Gm-Message-State: AOJu0Yy4UmOAG0RzNmTC/YszXUOpaKwtYenJn8bhZNf4ztg1CG27mwbM FdxjV0P97sOW9bR8ZZzcaAoQMGrYG9z7siN3l3nr0GEHe4CPrBt4/8olTQ== X-Google-Smtp-Source: AGHT+IHxufmfzYuTB4oOeLssPmvuH/MFYbb7j6IzGfwer3jhklgSUL5HMxdQgEe6RvQlMF1MzkmnAg== X-Received: by 2002:a2e:2c11:0:b0:2ef:243b:6dce with SMTP id 38308e7fff4ca-2f15aa84ec7mr23882531fa.10.1722606855031; Fri, 02 Aug 2024 06:54:15 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Alistair Francis , Bob Eshleman , Connor Davis , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH v12 3/3] xen/riscv: refactor decode_trap_cause() Date: Fri, 2 Aug 2024 15:54:09 +0200 Message-ID: <88e15908d6ac363934b6da52091443af28bd7291.1722605952.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Use array_access_nospec() to prevent guest speculation. Avoid double access of trap_causes[cause]. Suggested-by: Jan Beulich Signed-off-by: Oleksii Kurochko Reviewed-by: Jan Beulich --- Changes in V12: - New patch. --- xen/arch/riscv/traps.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 72ffdcd79e..51f6e45ccc 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -48,9 +49,10 @@ static const char *decode_trap_cause(unsigned long cause) [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"; + const char *res = cause < ARRAY_SIZE(trap_causes) ? array_access_nospec(trap_causes, cause) + : NULL; + + return res ?: "UNKNOWN"; } static const char *decode_reserved_interrupt_cause(unsigned long irq_cause)