From patchwork Wed Mar 13 01:48:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1911475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=uv6WKnWA; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=LHEI4pwK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvYSk2wZpz1yWt for ; Wed, 13 Mar 2024 12:53:24 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=wsPGidmZ70vttioicmtKNbh8Epf06ttA9YJp0RamByw=; b=uv6WKnWApi209/ 2aMhbeoeEidU5zMAaZkyjYoaFxdx9pr22l8BM2Vr10Mu/9uJRMlyJFciEunq7bXv5f4hQ68zbs5KU 2puguhKCfhQjTOovR0u7B3FRkxKIDjJuXZG1Hs//OSu3U4OQTR6sy60AVeMW2MsQBTpQFmN4+0xrO IkZFhTP37IIKMtMbjzE9vnW8A2YcbjnpsNV1p6kMbTQ0SrmTJQsv1bXntxTAarP2LdTmDqbLGr8uS yDjhn8Z9FxGwn4aXbS1BBLtMgxe0XhGqCjeiVTn3hd+0aMGwqtQzZsDfhv0bu9UgMHQe0pIYDHa8L EfgHsGiLxgY4l4j1RC0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkDnq-00000008Tmc-2Ewe; Wed, 13 Mar 2024 01:53:10 +0000 Received: from m16.mail.126.com ([117.135.210.8]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkDnl-00000008Tla-3wfX for opensbi@lists.infradead.org; Wed, 13 Mar 2024 01:53:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=zTw+h AIy3vi1untdqKH7/fiz1yJuM9vV2mrwWg9MqUc=; b=LHEI4pwK897QpxCT4AH7k 0JXGDHVxoz/pWDhNOC/qT91zowJ/+kB/IfRhkwAv558J9fqhcIJp0WMSfWkp7Mdi v9OUnXQka3rHOAaWTD8gre3xOZJ+c5s8fbTWwstcEjuukHYPfRC3ouMmUQWD8Uv4 D6WFPrkRFQ7MKwLYcMFFiM= Received: from T490.lan (unknown [112.83.183.140]) by gzga-smtp-mta-g1-3 (Coremail) with SMTP id _____wD3X9_yBvFlTOjXAA--.1419S2; Wed, 13 Mar 2024 09:52:51 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Subject: [PATCH] lib: sbi: Remove gva from struct sbi_trap_info Date: Wed, 13 Mar 2024 09:48:52 +0800 Message-ID: <20240313015237.761227-1-wxjstz@126.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CM-TRANSID: _____wD3X9_yBvFlTOjXAA--.1419S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3Gw1kGw47Ww1fKw4kXF1fWFg_yoW7XFW5pr 98Ga17Ga18t3W8KrZ7X3ykursYqrs7W3y3Cw42kF1SyF18CFyS9a47tFn8tF93Gr13AFZ5 XF1rCry8CF47Ww7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zNsj1wUUUUU= X-Originating-IP: [112.83.183.140] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcxWgOmSQAoB-AwAAs2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240312_185306_583128_9476C6CA X-CRM114-Status: GOOD ( 10.42 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: gva is only used in sbi_trap_redirect and can be calculated from sbi_trap_regs through sbi_regs_gva. Signed-off-by: Xiang W --- This patch base on "[PATCH v2 00/10] Improve trap handling for nested traps" Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz(at)126.com] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Xiang W , anup@brainfault.org Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org gva is only used in sbi_trap_redirect and can be calculated from sbi_trap_regs through sbi_regs_gva. Signed-off-by: Xiang W --- This patch base on "[PATCH v2 00/10] Improve trap handling for nested traps" firmware/fw_base.S | 19 +++---------------- include/sbi/sbi_trap.h | 6 +----- lib/sbi/sbi_expected_trap.S | 17 ++--------------- lib/sbi/sbi_illegal_insn.c | 1 - lib/sbi/sbi_trap.c | 2 +- 5 files changed, 7 insertions(+), 38 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 967cca5..7e172ad 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -625,7 +625,7 @@ memcmp: REG_S t6, SBI_TRAP_REGS_OFFSET(t6)(sp) .endm -.macro TRAP_SAVE_INFO have_mstatush have_h_extension +.macro TRAP_SAVE_INFO have_h_extension csrr t0, CSR_MCAUSE REG_S t0, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(cause))(sp) csrr t0, CSR_MTVAL @@ -635,20 +635,11 @@ memcmp: REG_S t0, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(tval2))(sp) csrr t0, CSR_MTINST REG_S t0, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(tinst))(sp) - .if \have_mstatush - csrr t0, CSR_MSTATUSH - srli t0, t0, MSTATUSH_GVA_SHIFT - .else - csrr t0, CSR_MSTATUS - srli t0, t0, MSTATUS_GVA_SHIFT - .endif - and t0, t0, 0x1 .else REG_S zero, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(tval2))(sp) REG_S zero, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(tinst))(sp) add t0, zero, zero .endif - REG_S t0, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(gva))(sp) .endm .macro TRAP_CALL_C_ROUTINE @@ -720,7 +711,7 @@ _trap_handler: TRAP_SAVE_GENERAL_REGS_EXCEPT_SP_T0 - TRAP_SAVE_INFO 0 0 + TRAP_SAVE_INFO 0 TRAP_CALL_C_ROUTINE @@ -746,11 +737,7 @@ _trap_handler_hyp: TRAP_SAVE_GENERAL_REGS_EXCEPT_SP_T0 -#if __riscv_xlen == 32 - TRAP_SAVE_INFO 1 1 -#else - TRAP_SAVE_INFO 0 1 -#endif + TRAP_SAVE_INFO 1 TRAP_CALL_C_ROUTINE diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index f7c170e..ff475ca 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -95,10 +95,8 @@ #define SBI_TRAP_INFO_tval2 2 /** Index of tinst member in sbi_trap_info */ #define SBI_TRAP_INFO_tinst 3 -/** Index of gva member in sbi_trap_info */ -#define SBI_TRAP_INFO_gva 4 /** Last member index in sbi_trap_info */ -#define SBI_TRAP_INFO_last 5 +#define SBI_TRAP_INFO_last 4 /* clang-format on */ @@ -206,8 +204,6 @@ struct sbi_trap_info { unsigned long tval2; /** tinst Trap instruction */ unsigned long tinst; - /** gva Guest virtual address in tval flag */ - unsigned long gva; }; /** Representation of trap context saved on stack */ diff --git a/lib/sbi/sbi_expected_trap.S b/lib/sbi/sbi_expected_trap.S index 99dede5..6823c46 100644 --- a/lib/sbi/sbi_expected_trap.S +++ b/lib/sbi/sbi_expected_trap.S @@ -22,14 +22,13 @@ .align 3 .global __sbi_expected_trap __sbi_expected_trap: - /* Without H-extension so, MTVAL2 and MTINST CSRs and GVA not available */ + /* Without H-extension so, MTVAL2 and MTINST CSRs not available */ csrr a4, CSR_MCAUSE REG_S a4, SBI_TRAP_INFO_OFFSET(cause)(a3) csrr a4, CSR_MTVAL REG_S a4, SBI_TRAP_INFO_OFFSET(tval)(a3) REG_S zero, SBI_TRAP_INFO_OFFSET(tval2)(a3) REG_S zero, SBI_TRAP_INFO_OFFSET(tinst)(a3) - REG_S zero, SBI_TRAP_INFO_OFFSET(gva)(a3) csrr a4, CSR_MEPC addi a4, a4, 4 csrw CSR_MEPC, a4 @@ -38,7 +37,7 @@ __sbi_expected_trap: .align 3 .global __sbi_expected_trap_hext __sbi_expected_trap_hext: - /* With H-extension so, MTVAL2 and MTINST CSRs and GVA available */ + /* With H-extension so, MTVAL2 and MTINST CSRs available */ csrr a4, CSR_MCAUSE REG_S a4, SBI_TRAP_INFO_OFFSET(cause)(a3) csrr a4, CSR_MTVAL @@ -47,18 +46,6 @@ __sbi_expected_trap_hext: REG_S a4, SBI_TRAP_INFO_OFFSET(tval2)(a3) csrr a4, CSR_MTINST REG_S a4, SBI_TRAP_INFO_OFFSET(tinst)(a3) - - /* Extract GVA bit from MSTATUS or MSTATUSH */ -#if __riscv_xlen == 32 - csrr a4, CSR_MSTATUSH - srli a4, a4, MSTATUSH_GVA_SHIFT -#else - csrr a4, CSR_MSTATUS - srli a4, a4, MSTATUS_GVA_SHIFT -#endif - andi a4, a4, 1 - REG_S a4, SBI_TRAP_INFO_OFFSET(gva)(a3) - csrr a4, CSR_MEPC addi a4, a4, 4 csrw CSR_MEPC, a4 diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index 29c5d74..e912234 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -29,7 +29,6 @@ static int truly_illegal_insn(ulong insn, struct sbi_trap_regs *regs) trap.tval = insn; trap.tval2 = 0; trap.tinst = 0; - trap.gva = 0; return sbi_trap_redirect(regs, &trap); } diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 83598a4..01077f2 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -146,7 +146,7 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, hstatus &= ~HSTATUS_SPV; hstatus |= (prev_virt) ? HSTATUS_SPV : 0; hstatus &= ~HSTATUS_GVA; - hstatus |= (trap->gva) ? HSTATUS_GVA : 0; + hstatus |= sbi_regs_gva(regs) ? HSTATUS_GVA : 0; csr_write(CSR_HSTATUS, hstatus); csr_write(CSR_HTVAL, trap->tval2); csr_write(CSR_HTINST, trap->tinst);