From patchwork Fri Oct 18 08:40:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1998992 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=1cgdZhkq; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=FJlPjQ6t; 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 4XVJNt5pLRz1xth for ; Fri, 18 Oct 2024 19:52:13 +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:References:In-Reply-To: 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: List-Owner; bh=PSBqRmSE+2ks/eT9ocC+1oQrUnv01INDQ/KMtDQGNjY=; b=1cgdZhkq+pjkNY p+4gVJrLkv1iv3MsswacP9Dom8EKQ0E4gBNEoPuLCmADN8mzdPXvwtnynlyyPFM/han4H0O+LriI/ reonYLnZWTIIZNkpKgV6026DJ1F809hZOpCq7a/tAaSCxlr79FqWQFg7ckt+Pl2WNobdBimumVpeo GWfsBj7ze4sL36Uv0GxKgw487evPDFEWxnYeRtOB2MrRpT7w5DfgF13GTRIIxqmpiCPqIOq3VfQ6z BhFT1ufd0KMAT1UEu1JYCXkPBe2KP2RvGuRIMVGAZFrA4BROaqa15pXVYFPWGc192RMGUEZiGNEQT GtVv1K9BLA5+7ZhlW5ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1iiI-000000003Dg-1dV1; Fri, 18 Oct 2024 08:52:02 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1iXD-0000000Hb7t-24TN for opensbi@lists.infradead.org; Fri, 18 Oct 2024 08:40:37 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2e56df894d4so188386a91.3 for ; Fri, 18 Oct 2024 01:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729240834; x=1729845634; darn=lists.infradead.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=3eFgisiOn+ah7w63zcDEzmNY1uMHu1fAZJ9jjRjKwm0=; b=FJlPjQ6t6Ehh+bK16f5L6NyZRYjj+ZK/yGRGKcxizRYnfG9nafnkvTYhdqx7wk6noC YCaALXsyvNLhNpQGD4pif3RgSTt+osgc9TIEJv+otLTwlzqg/Owq5iCTuxPNLOpFXlSR FKfQFn5XKtoTAkjtwp7wB2p2S3oLEbLu8JncT0ngeVxad1O9V7sSF1sSAkPDd+D/TtXQ 8DzJggV/7YixxqIvc5nwriV+6xTpvItFJb7dpWGG0K+QjICthUVUG2NqpJ/ZpeaqLEfi Y53xIP6npgXkiL1KiNw3uf3ZxCHDayUmzxtcBqlN2hdpQagbJlnVNU0gTkx8MMIJJm7f gtbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729240834; x=1729845634; 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=3eFgisiOn+ah7w63zcDEzmNY1uMHu1fAZJ9jjRjKwm0=; b=ouWnH8WuQDbTyyIBw0XRdpB4Cmn/5cDLgUJJ8QRzaA6DvTTvVE3RfevWESqzEwN6BO ++LbwcQHQvgp8gABs95EztQBDVjLeqm7ExXIvAchA83JEH6OypouYgYUgrm4IGqPauD6 dlqiAuNa7a+yoLZTLsNCl37myRMKz+Vjk+wzJDgQAw/SlBGa81qdnWtRrpwTSRTl5sTC RVOvw34cQUfTfLwWzj/F+99KuqXQALJZlfnUErLnyzGWGwPyorsTHFlhm8OxZKMnu81X 9Lor7MH76jcMqyVYvN3msvzmdDW9tQK26hrXvkS5SrHKoJ7cUxgxMGcSG8cuQBhacPAb +HRw== X-Gm-Message-State: AOJu0Ywej3IeB2s07cVev3KYBLRZX9oJ0dT1vla6CL7I7MeAjB0YJp0y OPbJnGA44TS7lMXNDJq4cYVbpNJb31nELw9tljVV1gBJKuGSG/nQmn3Cf8Ayiyl84RFwylsJpEh dKxE= X-Google-Smtp-Source: AGHT+IGEacJ6lXuRIYMUePKdAOQin76zv/FCjrgOwLuLcW2z5DQ4Tw0+hQBB/XCPZlY8ryAm/ZnPgQ== X-Received: by 2002:a17:90b:4b03:b0:2dd:6969:2096 with SMTP id 98e67ed59e1d1-2e561a230ddmr1781121a91.38.1729240833957; Fri, 18 Oct 2024 01:40:33 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e55d8051a9sm1364094a91.27.2024.10.18.01.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 01:40:33 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH v4 1/7] lib: sbi: factorize previous virtualization mode read from regs Date: Fri, 18 Oct 2024 10:40:02 +0200 Message-ID: <20241018084010.406285-2-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018084010.406285-1-cleger@rivosinc.com> References: <20241018084010.406285-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_014035_613956_0C5B55BB X-CRM114-Status: UNSURE ( 9.94 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__The_same_pattern_is_used_at_multiple_p?= =?unknown-8bit?q?laces_to_verify_in_which?= =?unknown-8bit?q?_mode_the_exception_was_actually_taken=2E_Factorize_it=2E_S?= =?unknown-8bit?q?igned-off-by=3A_Cl=C3=A9ment?= =?unknown-8bit?q?_L=C3=A9ger_=3Ccleger=40rivosinc=2Ecom=3E_Reviewed-by=3A_Sa?= =?unknown-8bit?q?muel_Holland_=3Csamuel=2Eholland=40sifive=2Ecom=3E?= =?unknown-8bit?q?_---_include/sbi/sbi=5Ftrap=2Eh_=7C_9_+++++++++_lib/sbi/sbi?= =?unknown-8bit?q?=5Femulate=5Fcsr=2Ec_=7C_12_++?= =?unknown-8bit?b?IGxpYi9zYiBbLi4uXSA=?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-1=2E9_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyNjA3OmY4YjA6NDg2NDoyMDowOjA6MDoxMDJkIGxpc3RlZCBpbl0=?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-1=2E9_BAYES=5F00_______________BODY=3A_Bayes_spam_probabi?= =?unknown-8bit?q?lity_is_0_to_1=25?= =?unknown-8bit?q?_=5Bscore=3A_0=2E0000=5D?= 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Ved Shanbhogue Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The same pattern is used at multiple places to verify in which mode the exception was actually taken. Factorize it. Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- include/sbi/sbi_trap.h | 9 +++++++++ lib/sbi/sbi_emulate_csr.c | 12 ++---------- lib/sbi/sbi_trap.c | 6 +----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index f7c170e..b0c47ce 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -236,6 +236,15 @@ static inline unsigned long sbi_regs_gva(const struct sbi_trap_regs *regs) #endif } +static inline bool sbi_regs_from_virt(const struct sbi_trap_regs *regs) +{ +#if __riscv_xlen == 32 + return (regs->mstatusH & MSTATUSH_MPV) ? true : false; +#else + return (regs->mstatus & MSTATUS_MPV) ? true : false; +#endif +} + int sbi_trap_redirect(struct sbi_trap_regs *regs, const struct sbi_trap_info *trap); diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c index 3adec78..a5a04cd 100644 --- a/lib/sbi/sbi_emulate_csr.c +++ b/lib/sbi/sbi_emulate_csr.c @@ -47,11 +47,7 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs, int ret = 0; struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; -#if __riscv_xlen == 32 - bool virt = (regs->mstatusH & MSTATUSH_MPV) ? true : false; -#else - bool virt = (regs->mstatus & MSTATUS_MPV) ? true : false; -#endif + bool virt = sbi_regs_from_virt(regs); switch (csr_num) { case CSR_HTIMEDELTA: @@ -157,11 +153,7 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs, { int ret = 0; ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; -#if __riscv_xlen == 32 - bool virt = (regs->mstatusH & MSTATUSH_MPV) ? true : false; -#else - bool virt = (regs->mstatus & MSTATUS_MPV) ? true : false; -#endif + bool virt = sbi_regs_from_virt(regs); switch (csr_num) { case CSR_HTIMEDELTA: diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 176e174..ff0668e 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -104,11 +104,7 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, { ulong hstatus, vsstatus, prev_mode; bool elp = false; -#if __riscv_xlen == 32 - bool prev_virt = (regs->mstatusH & MSTATUSH_MPV) ? true : false; -#else - bool prev_virt = (regs->mstatus & MSTATUS_MPV) ? true : false; -#endif + bool prev_virt = sbi_regs_from_virt(regs); /* By default, we redirect to HS-mode */ bool next_virt = false; From patchwork Fri Oct 18 08:40:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1998991 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=WPqdtVNW; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=f1baXKev; 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 4XVJNv0hWQz1xwN for ; Fri, 18 Oct 2024 19:52:13 +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:References:In-Reply-To: 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: List-Owner; bh=shrIHSSH5Yi4UzAPMfHjSZ862f3mDLg3gM+qMAE87iQ=; b=WPqdtVNWN6Hjm4 3J7Y6WZlL31/abGICEq/hINGGs3je+yfXG/05G9rQB515Dbs2oseOm9tYnS6/A2+fH2/Nh217mfif bg3+FFTjZZzjh1EMRFJRgoHakmrLeoT1UuzcP6LN+lFssNzg3lfS4QMK+2yXTtPsoqi2Wqwr7Mf+f fdnN86dHyDgoD9i9GKg350ruwBQWUhi+QY8bRpiyexcJPKfM+iIYbMSqtoUQE9pxGOIH9FiaccLBB eb/bdQlZMOddWn6q1K0CHtAFPvV0+ZhM9k+3lro2pa1aO+vGImxNEhrl1D/9OiYqAMx02COEYP+W4 KjFd7n7MYuqOWj2CqxnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1iiJ-000000003Dq-0atr; Fri, 18 Oct 2024 08:52:03 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1iXI-0000000007w-1U40 for opensbi@lists.infradead.org; Fri, 18 Oct 2024 08:40:42 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2e2a97c2681so1411380a91.2 for ; Fri, 18 Oct 2024 01:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729240839; x=1729845639; darn=lists.infradead.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=vKrUKfYevSD8FUi1WjPzf8Ksz4oTp1nQVCubvo8NqWQ=; b=f1baXKev3VhhYhh3b+Qb+s6ZWyOzgKho+Nl4j7WxtD/DBlh9lJfi2D1cfyXK+/ZmH1 jIbqtbO6jeMsZCvflxBZ29rcCXO54/IFC/psKHiPl/152JkRB9fUhKn2bl/9Up2O/+Cs bT6loe6oSgzmYmvzaYx15S9+48ezVGsfeNnUuZLcf8VcGXzBM6dQNhAHrv24vwQdC3iI nqsm1lPYyEpFvIKJUsizsuJKyNgsyD3MvriF8LiwkhJMM1b9yKj8miwGLGFLtn0OKiWR fcKA0PjSM6fAck7N2CI8DQS8dKFdvDq01e4nBRUwWY0XwKONjS27NpS3QjqqjXaAQT0b R/uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729240839; x=1729845639; 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=vKrUKfYevSD8FUi1WjPzf8Ksz4oTp1nQVCubvo8NqWQ=; b=pkxY1qwP7yfE+9KVkxIrhD3eterGRQIcBqyWN6xluD8qb+9b99Yb6pvUXU2ijfzE5k cMsBR9aytGLOEzrn7TRXol1WoEsHAwdZ/DuaokB1krwzmPDlx4fp3Eq2ZwMb+QqMfZo7 VpA1QOo03LnwUNQRmYSbOeT39JxFX8Kwm6c9you1aGa4dMwiGO6tiZZwfB6czLWT8Ir3 JJzK+Ptuo7PArAgFg0VngwKUnBwpRzkh2hr7za8ssbS9+WBYa8hy/qYJmbVNZ4qFkRNy LFXnFl5ptE8tXoFk4d4KeqXXaOmdpaDyQiwwOWYu8vgANRN5fs9X6lo4WcxT/0mAGQ7x EzYg== X-Gm-Message-State: AOJu0YyrkQNFwsCtwrNgIdP3whOBG1UxnEGUdCZEKoVHkr4oaF9NS2Ky r1i592wQEWXF/KsnWpVhiwjNVR93whSzpupMrSgxx3N8PZ6sjE4TUroYI6i+2JwdAjyS7BqJEUQ 4bbE= X-Google-Smtp-Source: AGHT+IGu2E8Y8fofLiJYGzkwJvZdyd99p5KGZDINGbRb+kffXr0si7QUa68S38gygavH52Qcs3lS+Q== X-Received: by 2002:a17:90b:3906:b0:2d1:bf48:e767 with SMTP id 98e67ed59e1d1-2e561900e42mr1796644a91.29.1729240839389; Fri, 18 Oct 2024 01:40:39 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e55d8051a9sm1364094a91.27.2024.10.18.01.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 01:40:38 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH v4 2/7] lib: sbi: factorize previous mode computation Date: Fri, 18 Oct 2024 10:40:03 +0200 Message-ID: <20241018084010.406285-3-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018084010.406285-1-cleger@rivosinc.com> References: <20241018084010.406285-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_014040_459895_3E2DE9C4 X-CRM114-Status: GOOD ( 13.19 ) X-Spam-Score: -1.9 (-) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__Previous_privilege_mode_retrieval_from?= =?unknown-8bit?q?_mstatus_is_done_at?= =?unknown-8bit?q?_different_places=2C_factorize_it_rather_than_copy/pasting_?= =?unknown-8bit?q?it_again=2E_Signed-off-by=3A?= =?unknown-8bit?q?_Cl=C3=A9ment_L=C3=A9ger_=3Ccleger=40rivosinc=2Ecom=3E_---_?= =?unknown-8bit?q?include/sbi/sbi=5Ftrap=2Eh_=7C_5_+++++?= =?unknown-8bit?q?_lib/sbi/sbi=5Femulate=5Fcsr=2Ec_=7C_4_++--_lib/sbi/sbi=5Fi?= =?unknown-8bit?q?llegal=5Finsn=2Ec_=7C_2_+-_lib/sbi/sbi=5Fsystem=2Ec?= =?unknown-8bit?b?IHwgMiArLSBsaWIvc2JpL3NiaV90IFsuLi5dIA==?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-1=2E9_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyNjA3OmY4YjA6NDg2NDoyMDowOjA6MDoxMDJkIGxpc3RlZCBpbl0=?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-1=2E9_BAYES=5F00_______________BODY=3A_Bayes_spam_probabi?= =?unknown-8bit?q?lity_is_0_to_1=25?= =?unknown-8bit?q?_=5Bscore=3A_0=2E0000=5D?= 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Ved Shanbhogue Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Previous privilege mode retrieval from mstatus is done at different places, factorize it rather than copy/pasting it again. Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- include/sbi/sbi_trap.h | 5 +++++ lib/sbi/sbi_emulate_csr.c | 4 ++-- lib/sbi/sbi_illegal_insn.c | 2 +- lib/sbi/sbi_system.c | 2 +- lib/sbi/sbi_trap.c | 4 ++-- lib/sbi/sbi_trap_ldst.c | 4 ++-- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index b0c47ce..d5182bf 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -245,6 +245,11 @@ static inline bool sbi_regs_from_virt(const struct sbi_trap_regs *regs) #endif } +static inline int sbi_mstatus_prev_mode(unsigned long mstatus) +{ + return (mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; +} + int sbi_trap_redirect(struct sbi_trap_regs *regs, const struct sbi_trap_info *trap); diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c index a5a04cd..c2253c8 100644 --- a/lib/sbi/sbi_emulate_csr.c +++ b/lib/sbi/sbi_emulate_csr.c @@ -46,7 +46,7 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs, { int ret = 0; struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); - ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); bool virt = sbi_regs_from_virt(regs); switch (csr_num) { @@ -152,7 +152,7 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs, ulong csr_val) { int ret = 0; - ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); bool virt = sbi_regs_from_virt(regs); switch (csr_num) { diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index e1d2cd3..784bc4c 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -52,7 +52,7 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) int rs1_num = GET_RS1_NUM(insn); ulong rs1_val = GET_RS1(insn, regs); int csr_num = GET_CSR_NUM((u32)insn); - ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + ulong prev_mode = sbi_mstatus_prev_mode(regs->mstatus); ulong csr_val, new_csr_val; if (prev_mode == PRV_M) { diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index 8e624fd..cd0f4ba 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -158,7 +158,7 @@ int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque) if (ret != SBI_OK) return ret; - prev_mode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + prev_mode = sbi_mstatus_prev_mode(csr_read(CSR_MSTATUS)); if (prev_mode != PRV_S && prev_mode != PRV_U) return SBI_EFAIL; diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index ff0668e..fd70e67 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -109,7 +109,7 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, bool next_virt = false; /* Sanity check on previous mode */ - prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + prev_mode = sbi_mstatus_prev_mode(regs->mstatus); if (prev_mode != PRV_S && prev_mode != PRV_U) return SBI_ENOTSUPP; @@ -361,7 +361,7 @@ trap_done: if (rc) sbi_trap_error(msg, rc, tcntx); - if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) != PRV_M) + if (sbi_mstatus_prev_mode(regs->mstatus) != PRV_M) sbi_sse_process_pending_events(regs); sbi_trap_set_context(scratch, tcntx->prev_context); diff --git a/lib/sbi/sbi_trap_ldst.c b/lib/sbi/sbi_trap_ldst.c index f9c0241..ebc4a92 100644 --- a/lib/sbi/sbi_trap_ldst.c +++ b/lib/sbi/sbi_trap_ldst.c @@ -318,7 +318,7 @@ static int sbi_ld_access_emulator(int rlen, union sbi_ldst_data *out_val, struct sbi_trap_regs *regs = &tcntx->regs; /* If fault came from M mode, just fail */ - if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M) + if (sbi_mstatus_prev_mode(regs->mstatus) == PRV_M) return SBI_EINVAL; /* If platform emulator failed, we redirect instead of fail */ @@ -341,7 +341,7 @@ static int sbi_st_access_emulator(int wlen, union sbi_ldst_data in_val, struct sbi_trap_regs *regs = &tcntx->regs; /* If fault came from M mode, just fail */ - if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M) + if (sbi_mstatus_prev_mode(regs->mstatus) == PRV_M) return SBI_EINVAL; /* If platform emulator failed, we redirect instead of fail */ From patchwork Fri Oct 18 08:40:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1998998 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=lWFrPpbZ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=UwjHHAOs; 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 4XVJNt6ScBz1xwD for ; Fri, 18 Oct 2024 19:52:13 +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:References:In-Reply-To: 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: List-Owner; bh=Bl5C1/+5SL1MgSCG3NxX6RH39Tp7oS9MtAn79k7YIr8=; b=lWFrPpbZQoI89A lcYA8/Uc4NobhcrLA26fhQEW42Fnp9iM+8+XTxQTUoQLSqPvpSbAMMh/EBqtIlDD6wr58/JTpJozZ LOeEpVA+fEN0BbtXpTDDgJ/sc51QWF8gmQa7gjZGsVqCIkefo3mrmKTHGynr/uhLoLqr1mFwUPeUM UfHuUoWCblYtCvQfetsHbAR+aww753OFDIukEMXDb4IjuAZcRm1kmYmAtcuT8kqXnXrLjJ1TOE4EK SEVv38GCTOgUaGvu092mBwmLobBSzumulW87+7LVZ7CVBjAY6bUmrRpWe6z97OkiarvnIH2Uz/zYf wHLIEwTlqhRq17klA8hQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1iiJ-000000003Dz-2ea4; Fri, 18 Oct 2024 08:52:03 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1iXO-000000000AU-3yXr for opensbi@lists.infradead.org; Fri, 18 Oct 2024 08:40:49 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2e2e2d09decso2181838a91.1 for ; Fri, 18 Oct 2024 01:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729240845; x=1729845645; darn=lists.infradead.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=natMRjL6k6/6h8cI9t10OenRfk8ZBO0KqInZGq71DRE=; b=UwjHHAOs1DBhxJmUl6hIq8YgtzJw/pkpTHi8rwZ8KowP3XNodwJowwYROSsrFS+VpI z1bsiB9mRjQzKfJg8v2h8cyo9cctU2vvklaEGJ8St321oQttlLNWZcz3vF04wpE3p23G uq3eUKBNN/C+MK88bs0wtdnChbxWSC0TSndvSuCPaTmJ0A/hVb66qWCyH5lR2ZR2JPbt +lwCMaAaNAcew9kQaq2P2JI1gWAN5bzRkoDsKQdvrXDxcjtQLMn+cL4N2jo8ZPCqGWY7 BvCKaVM6RMXLz4JVw3ie2CIM+YX7VMEcJZSWgl545CXwizS77IiwmzVhRyntPo0W/eEM b9bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729240845; x=1729845645; 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=natMRjL6k6/6h8cI9t10OenRfk8ZBO0KqInZGq71DRE=; b=Km/vD6L2+7cHyKDUyHg6mrQY5SIENIq4oJ6i5/Jd+m1TEtE+O7FRcWxrvNr9hLXixs OeW/6TjiylIzEwBnly63ub+kzNkXDnwWVSyAVfVLIHi/djUCj1N5PYVdbj4HW6zIn8xy WWZtNlxjU5s989ZGa6Z+xQiPAe0O5QgZqkvgbouTvVLRe+PBtq21CcvCnb4IXQv9ztq7 G3d9jCooZBofh2hKSttY5mHBt4N+Xqn82vkjp876hEWyQXnJ8ScgWCAIei8LX7yiGbTe Onu7xKUgug26La3gUjcgNQ1/N9p2hQPWihW1qp5IR9qBO3OMh0qQpqHEYxDfDOkM+9cw O+FQ== X-Gm-Message-State: AOJu0YwcMfuzveH+pMdqhqO1gIyfzVOn2o2yXeu7HxxNaIv4wnEll4iK onj0U/jB0LFELt+7Tvysf5oqnhxkHEoOIw0XGClJYNwETx67DNraSH0H+S/u/nX5vbWf04iF1DN W8Nk= X-Google-Smtp-Source: AGHT+IEZx8jKKb+61s79qrsQzKOpbYxyRoatB7Y0WNXBIm2MX6HXLtZFYANzjByoWUKErr/ga0ddug== X-Received: by 2002:a17:90b:4c12:b0:2e3:bc3e:feef with SMTP id 98e67ed59e1d1-2e5644991c9mr2365097a91.3.1729240844809; Fri, 18 Oct 2024 01:40:44 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e55d8051a9sm1364094a91.27.2024.10.18.01.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 01:40:43 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH v4 3/7] lib: sbi: add Ssdbltrp ISA extension support Date: Fri, 18 Oct 2024 10:40:04 +0200 Message-ID: <20241018084010.406285-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018084010.406285-1-cleger@rivosinc.com> References: <20241018084010.406285-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_014047_334094_175CE29E X-CRM114-Status: GOOD ( 17.49 ) X-Spam-Score: -1.9 (-) 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: Add Ssdbltrp trap handler support for S-mode double trap handling. If the trap is received while in VS-mode, then the trap is redirected to S-mode. If caught while in HS-mode, then an error is returne [...] Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1029 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Ved Shanbhogue Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add Ssdbltrp trap handler support for S-mode double trap handling. If the trap is received while in VS-mode, then the trap is redirected to S-mode. If caught while in HS-mode, then an error is returned to the top trap handler which will panic. Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- include/sbi/riscv_encoding.h | 4 +++- include/sbi/sbi_hart.h | 2 ++ include/sbi/sbi_trap_ldst.h | 2 ++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_double_trap.c | 30 ++++++++++++++++++++++++++++++ lib/sbi/sbi_hart.c | 4 ++++ lib/sbi/sbi_trap.c | 4 ++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 lib/sbi/sbi_double_trap.c diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 980abdb..2264427 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -216,6 +216,7 @@ #define ENVCFG_PBMTE (_ULL(1) << 62) #define ENVCFG_ADUE (_ULL(1) << 61) #define ENVCFG_CDE (_ULL(1) << 60) +#define ENVCFG_DTE (_ULL(1) << 59) #define ENVCFG_PMM (_ULL(0x3) << 32) #define ENVCFG_PMM_PMLEN_0 (_ULL(0x0) << 32) #define ENVCFG_PMM_PMLEN_7 (_ULL(0x2) << 32) @@ -773,7 +774,8 @@ #define CAUSE_FETCH_PAGE_FAULT 0xc #define CAUSE_LOAD_PAGE_FAULT 0xd #define CAUSE_STORE_PAGE_FAULT 0xf -#define CAUSE_SW_CHECK_EXCP 0x12 +#define CAUSE_DOUBLE_TRAP 0x10 +#define CAUSE_SW_CHECK_EXCP 0x12 #define CAUSE_FETCH_GUEST_PAGE_FAULT 0x14 #define CAUSE_LOAD_GUEST_PAGE_FAULT 0x15 #define CAUSE_VIRTUAL_INST_FAULT 0x16 diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 22d8327..4c36c77 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -73,6 +73,8 @@ enum sbi_hart_extensions { SBI_HART_EXT_ZICFILP, /** HART has zicfiss extension */ SBI_HART_EXT_ZICFISS, + /** Hart has Ssdbltrp extension */ + SBI_HART_EXT_SSDBLTRP, /** Maximum index of Hart extension */ SBI_HART_EXT_MAX, diff --git a/include/sbi/sbi_trap_ldst.h b/include/sbi/sbi_trap_ldst.h index 8aee316..4c5cc37 100644 --- a/include/sbi/sbi_trap_ldst.h +++ b/include/sbi/sbi_trap_ldst.h @@ -28,4 +28,6 @@ int sbi_load_access_handler(struct sbi_trap_context *tcntx); int sbi_store_access_handler(struct sbi_trap_context *tcntx); +int sbi_double_trap_handler(struct sbi_trap_context *tcntx); + #endif diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 535aa70..7be943f 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -66,6 +66,7 @@ libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_domain_context.o libsbi-objs-y += sbi_domain.o +libsbi-objs-y += sbi_double_trap.o libsbi-objs-y += sbi_emulate_csr.o libsbi-objs-y += sbi_fifo.o libsbi-objs-y += sbi_fwft.o diff --git a/lib/sbi/sbi_double_trap.c b/lib/sbi/sbi_double_trap.c new file mode 100644 index 0000000..96f2fa5 --- /dev/null +++ b/lib/sbi/sbi_double_trap.c @@ -0,0 +1,30 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Rivos Inc. + * + * Authors: + * Clément Léger + */ + +#include +#include +#include +#include +#include + +int sbi_double_trap_handler(struct sbi_trap_context *tcntx) +{ + struct sbi_trap_regs *regs = &tcntx->regs; + const struct sbi_trap_info *trap = &tcntx->trap; + bool prev_virt = sbi_regs_from_virt(regs); + + if (sbi_mstatus_prev_mode(regs->mstatus) != PRV_S) + return SBI_ERR_INVALID_PARAM; + + /* Exception was taken in VS-mode, redirect it to S-mode */ + if (prev_virt) + return sbi_trap_redirect(regs, trap); + + return SBI_ENOTSUPP; +} diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index d9aef31..dc0863a 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -117,6 +117,9 @@ static void mstatus_init(struct sbi_scratch *scratch) menvcfg_val |= ((uint64_t)csr_read(CSR_MENVCFGH)) << 32; #endif + /* Disable double trap by default */ + menvcfg_val &= ~ENVCFG_DTE; + #define __set_menvcfg_ext(__ext, __bits) \ if (sbi_hart_has_extension(scratch, __ext)) \ menvcfg_val |= __bits; @@ -684,6 +687,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = { __SBI_HART_EXT_DATA(smnpm, SBI_HART_EXT_SMNPM), __SBI_HART_EXT_DATA(zicfilp, SBI_HART_EXT_ZICFILP), __SBI_HART_EXT_DATA(zicfiss, SBI_HART_EXT_ZICFISS), + __SBI_HART_EXT_DATA(ssdbltrp, SBI_HART_EXT_SSDBLTRP), }; _Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext), diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index fd70e67..d2de0c8 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -350,6 +350,10 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx) rc = sbi_store_access_handler(tcntx); msg = "store fault handler failed"; break; + case CAUSE_DOUBLE_TRAP: + rc = sbi_double_trap_handler(tcntx); + msg = "double trap handler failed"; + break; default: /* If the trap came from S or U mode, redirect it there */ msg = "trap redirect failed"; From patchwork Fri Oct 18 08:40:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1998993 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=DhuJWxqz; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=dY7i/eHX; 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 4XVJNv0ZCjz1xwL for ; Fri, 18 Oct 2024 19:52:13 +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:References:In-Reply-To: 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: List-Owner; bh=iVBsNFvEnPWE5kHCbJNJynFMVtFarym4RWEOvG+Y0yU=; b=DhuJWxqz1Kg3aZ QeeE4QBsRJPe2697hpUR3RojCkBeYv/bFWkAcaWfrVj5oWt71MCQduQXbzG+Es7G74QWnOT0Tk1sf QLJ4n85i99jOyC0UJZyBHUHhiUCLmmH71NlJGwFZAjtDbwOotVBrsh5e0mc7UuOOjN8BT7Gt/oVAF OwMlcHQ4u8NyavcQLKZRDKV9lMd3/CBI6aKxWmkYhpWG9bPqJkVeRCf7HHOMwrpRql0072fIr9EEx NylQJpLj5anyoACSLTkxeRngN06cNYzMj7F7iNLxt6A5VRUTGFam1zzs+fX2KoXX6GjrlabqPOX1M 1g2iY2pXYfgbJtnAYltw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1iiK-000000003EQ-0RUa; Fri, 18 Oct 2024 08:52:04 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1iXT-000000000DN-2xmq for opensbi@lists.infradead.org; Fri, 18 Oct 2024 08:40:57 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2e2ed59a35eso1596400a91.0 for ; Fri, 18 Oct 2024 01:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729240850; x=1729845650; darn=lists.infradead.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=ri3ednP+/OU+na0yR7dCtkiymSA7EMlKWA4IskARjgI=; b=dY7i/eHXxrUXWxiUA5aak2pT0Q/3E8FM/x6msGn/1jE7ryMxtoekmAI7ufjFrp/g50 3ibXE0xXNQnxCYaY2SrR9ZIF824rzDgA4YxgEu8ByVM5TTJjeauK/7VSqZnMjhd7MtKR 1ixcxs0kdI9yTPjGEfMmdrKesXbqOrRN2UuTZDiRSWgYzOaZgafX9jFyekiIwzVhGmrO tNv9CKM7Ddd8gSVYvyupjz36Hk6wsFRSeg87VDAB0D3NDQg3kKLuWTTXYdmtJNK7NJRw X1Bfawe0UMB5IPDqZE9+7t1QT+dQVtCHNAXHOxdGB71Z5wm2HtFdK4AIcZQ6aBPTWHB2 dFtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729240850; x=1729845650; 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=ri3ednP+/OU+na0yR7dCtkiymSA7EMlKWA4IskARjgI=; b=GRCOTK5nbrc+69VCwgMxRUaWeRG/w/xpNP7ega4wneJMp4BY6mWYVWffohHymYtj+L 46E5iUQ57R6TEUFiMqP6zbxNWGSCZbqd+BXGB5DVOFtSdwD3JZTorFg+G7AvoQkLTdbB sTshpXPFqvIrAl2eyagMyxypUTIK9FXOUdIdlOslgcjR5QWorwboxuqAvaiiKAiOWz/z KNZBi8dgZJZyNsuSWdegZp/Qmu2Wb/th/u1DJJwyNFCcWuBQ1ByvGbp5ODgyvwnkYFfd X7oqkN1zSTx3e8AtGmzUoZIEbhWf/kuSvmeZahAMxtaPKZfEAEAZg02k0jtFoGPg69ec yTAA== X-Gm-Message-State: AOJu0Yzi8Oa/0MkFK7CcXtcNXKG014K7TfRA5kuQnQI4goUc2f2y7/df 2lf1Sg+X4rlIHEFIAy1H+nVSVeCFaEm6FLXwjaW1FL9o5WyUB59dmLJaLB2rJ8fRyt0knjaUWS9 vUqU= X-Google-Smtp-Source: AGHT+IEmqzOq2vNgpKTRT1Yhz7ayLFtWZfj0LKgykO76Bjq+08CFhPmJQ07qmAwsXVCjBz9c3EDZHg== X-Received: by 2002:a17:90a:e649:b0:2e2:b8d7:4bd1 with SMTP id 98e67ed59e1d1-2e561a00d2bmr2088002a91.30.1729240850226; Fri, 18 Oct 2024 01:40:50 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e55d8051a9sm1364094a91.27.2024.10.18.01.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 01:40:49 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH v4 4/7] lib: sbi: send a double trap SSE event to supervisor Date: Fri, 18 Oct 2024 10:40:05 +0200 Message-ID: <20241018084010.406285-5-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018084010.406285-1-cleger@rivosinc.com> References: <20241018084010.406285-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_014051_825914_624B3BB2 X-CRM114-Status: GOOD ( 11.24 ) X-Spam-Score: -1.9 (-) 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: In case the double trap handler is called and the double trap happened in supervisor mode, send a double trap SSE event. NOTE: this commit depends on the ratification of the new SSE event id for double trap [1]. Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:102d listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Ved Shanbhogue Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org In case the double trap handler is called and the double trap happened in supervisor mode, send a double trap SSE event. NOTE: this commit depends on the ratification of the new SSE event id for double trap [1]. Link: https://lists.riscv.org/g/tech-prs/message/985 [1] Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- include/sbi/sbi_ecall_interface.h | 1 + lib/sbi/sbi_double_trap.c | 2 +- lib/sbi/sbi_sse.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index 2958b41..e4275b7 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -380,6 +380,7 @@ enum sbi_sse_state { /* SBI SSE Event IDs. */ #define SBI_SSE_EVENT_LOCAL_RAS 0x00000000 +#define SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP 0x00000001 #define SBI_SSE_EVENT_LOCAL_PLAT_0_START 0x00004000 #define SBI_SSE_EVENT_LOCAL_PLAT_0_END 0x00007fff #define SBI_SSE_EVENT_GLOBAL_RAS 0x00008000 diff --git a/lib/sbi/sbi_double_trap.c b/lib/sbi/sbi_double_trap.c index 96f2fa5..bab96fb 100644 --- a/lib/sbi/sbi_double_trap.c +++ b/lib/sbi/sbi_double_trap.c @@ -26,5 +26,5 @@ int sbi_double_trap_handler(struct sbi_trap_context *tcntx) if (prev_virt) return sbi_trap_redirect(regs, trap); - return SBI_ENOTSUPP; + return sbi_sse_inject_event(SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP); } diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c index ab03b9c..a2352a1 100644 --- a/lib/sbi/sbi_sse.c +++ b/lib/sbi/sbi_sse.c @@ -41,6 +41,7 @@ static const uint32_t supported_events[] = { SBI_SSE_EVENT_LOCAL_RAS, + SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP, SBI_SSE_EVENT_GLOBAL_RAS, SBI_SSE_EVENT_LOCAL_PMU, SBI_SSE_EVENT_LOCAL_SOFTWARE, From patchwork Fri Oct 18 08:40:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1998997 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=XSosV6IH; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=n0zXN3GU; 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 4XVJNt6z85z1xwG for ; Fri, 18 Oct 2024 19:52:14 +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:References:In-Reply-To: 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: List-Owner; bh=eBULlOi+jKhg9vKr36hkDpVhMXGl/vUMVBr+SLiXM04=; b=XSosV6IH4F0RGo x025OHyRKWulCngHixUH0IF1aDzGXN9lphGJxotqzNdGT9iu9YVb82T5tO7xeTHUwLWigflVItWdO 2pG/4TmtJYdRzraTjXIT5628IkxzKZueB8ocfiKqQS7xs6EF2G+C4mB8olaJr07m8too9zoXlwgn2 hvHOJSmpXqhhhDy6VmJ0u7N7+M0X/E9f45dzKkNmpWJGx0DCiAz6H6rGgenf/5/xZnOyJPKBtxTMX TbHjgY9lPJhuvKi872n/Hhyk4xMtQVdzkAq8IIilBEEfzCWCDxlG4f04FvQOQ15Ia6tyxrj6EgWIr dijWtoHX37ZUKw6bIKlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1iiK-000000003Ez-3TCA; Fri, 18 Oct 2024 08:52:04 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1iXY-000000000Fb-3oeR for opensbi@lists.infradead.org; Fri, 18 Oct 2024 08:41:02 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2e56750bb0dso251685a91.0 for ; Fri, 18 Oct 2024 01:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729240855; x=1729845655; darn=lists.infradead.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=i1xS0NLtskYPm/GkhtUU9wcU09R4tQiQNsXDSxe27UM=; b=n0zXN3GUXZsT3Y9Edh5FF2EHYcK9qqZ3+iZBSp1xxAEHN/Vlg+4yPsplNx8i1zyZ3t +K7fzjahj4RLtl3SxJwHPBA3Cln+pnWgdN5ByEewfoWeuad2vgI7cOUCeL+t1gvtJrtR 69iimKxDJEFuRqr4GT2sSdUbo9SjQM/ZA97AB7g+gKgg1WrU41lSDZ3IqqWLR8BxjnJd 582cscOsRUjTAPWFUJNpIPgja9hIXnNrhbK2NpKYItUT8UPKF4ZtV31+rl2Bj6+1iXvH K7owKRH4J1rxtMJtFKVYS6yi1PnKBAxcFa5BWKIR8CI/7sPFHU34tod+OSG/rC38Lau8 FwNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729240855; x=1729845655; 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=i1xS0NLtskYPm/GkhtUU9wcU09R4tQiQNsXDSxe27UM=; b=C5s1/XddpXl3oukW0APAUZ7SUzCou9XuosleF/8WKHNpkJz9BDRLFTKCdXG/iet8+e yF7JJBGLuxepbzCem0+6cOB5hP9lrPec7h3bN1kbQM88zgNqNvYWwkMBNN0YP+GDgIPH m+UcICqKH1FUqFUP8ZpBSHkYeIeyFXr5KNW449NwthtxGFUQc8K988wCVRuh0gUu5cMs 8cQlWawhAfHorxU2A4DrgHtMDx97aBtwkW9TeJdF3iHV+xzVCDBP4WoFRgLa93dfJJts KFfIExKHjr/8aWLjeiwzFVtA2XvESVNZ29sIurTEOwO1nAwHB2dVKXccABCA1RqmZRk4 4Vhw== X-Gm-Message-State: AOJu0Yx4Me27TIafgkI9lB9rHdkgc96lj8wfnLOeL0pxX14GuX08o29n LzutmDaMILsWu1sQt4BRNVhHt5S6oQ1xmJqDUDI8WI4DvrquLB5SivhvViNswEBs7TnD5pauckU dcQw= X-Google-Smtp-Source: AGHT+IHozqzWF55IkNAf/5OFIzJOTt/LAwBM5JUw7UwgO4annB+XUN8MF4WXqTX0ygNUkstQcfxPZA== X-Received: by 2002:a17:90a:17ef:b0:2e2:991c:d7a6 with SMTP id 98e67ed59e1d1-2e56172abc7mr1879387a91.19.1729240855474; Fri, 18 Oct 2024 01:40:55 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e55d8051a9sm1364094a91.27.2024.10.18.01.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 01:40:54 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH v4 5/7] lib: sbi: fwft: factorize menvcfg read/write Date: Fri, 18 Oct 2024 10:40:06 +0200 Message-ID: <20241018084010.406285-6-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018084010.406285-1-cleger@rivosinc.com> References: <20241018084010.406285-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_014057_373382_C67E48BD X-CRM114-Status: GOOD ( 12.22 ) X-Spam-Score: -1.9 (-) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__MENVCFG_access_will_be_used_as_well_fo?= =?unknown-8bit?q?r_double_trap=2C_landing?= =?unknown-8bit?q?_pad_and_shadow_stack_fwft_support=2E_Factorize_that_in_a_c?= =?unknown-8bit?q?ommon_function=2E_Signed-off-by=3A?= =?unknown-8bit?q?_Cl=C3=A9ment_L=C3=A9ger_=3Ccleger=40rivosinc=2Ecom=3E_Revi?= =?unknown-8bit?q?ewed-by=3A_Samuel_Holland_=3Csamuel=2Eholland=40sifive=2Ec?= =?unknown-8bit?q?om=3E?= =?unknown-8bit?q?_---_include/sbi/riscv=5Fencoding=2Eh_=7C_9_++--_lib/sbi/sb?= =?unknown-8bit?q?i=5Ffwft=2Ec_=7C_94_+++++++++++++++?= =?unknown-8bit?b?IFsuLi5dIA==?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-1=2E9_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyNjA3OmY4YjA6NDg2NDoyMDowOjA6MDoxMDI5IGxpc3RlZCBpbl0=?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-1=2E9_BAYES=5F00_______________BODY=3A_Bayes_spam_probabi?= =?unknown-8bit?q?lity_is_0_to_1=25?= =?unknown-8bit?q?_=5Bscore=3A_0=2E0000=5D?= 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Ved Shanbhogue Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org MENVCFG access will be used as well for double trap, landing pad and shadow stack fwft support. Factorize that in a common function. Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- include/sbi/riscv_encoding.h | 9 ++-- lib/sbi/sbi_fwft.c | 94 +++++++++++++++--------------------- 2 files changed, 46 insertions(+), 57 deletions(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 2264427..fd34ba7 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -214,7 +214,8 @@ #define ENVCFG_STCE (_ULL(1) << 63) #define ENVCFG_PBMTE (_ULL(1) << 62) -#define ENVCFG_ADUE (_ULL(1) << 61) +#define ENVCFG_ADUE_SHIFT 61 +#define ENVCFG_ADUE (_ULL(1) << ENVCFG_ADUE_SHIFT) #define ENVCFG_CDE (_ULL(1) << 60) #define ENVCFG_DTE (_ULL(1) << 59) #define ENVCFG_PMM (_ULL(0x3) << 32) @@ -228,8 +229,10 @@ #define ENVCFG_CBIE_ILL _UL(0x0) #define ENVCFG_CBIE_FLUSH _UL(0x1) #define ENVCFG_CBIE_INV _UL(0x3) -#define ENVCFG_SSE (_UL(1) << 3) -#define ENVCFG_LPE (_UL(1) << 2) +#define ENVCFG_SSE_SHIFT 3 +#define ENVCFG_SSE (_UL(1) << ENVCFG_SSE_SHIFT) +#define ENVCFG_LPE_SHIFT 2 +#define ENVCFG_LPE (_UL(1) << ENVCFG_LPE_SHIFT) #define ENVCFG_FIOM _UL(0x1) /* ===== User-level CSRs ===== */ diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c index 124a043..9ee0d07 100644 --- a/lib/sbi/sbi_fwft.c +++ b/lib/sbi/sbi_fwft.c @@ -74,6 +74,40 @@ static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature) return false; } +static int fwft_menvcfg_set_bit(unsigned long value, unsigned long bit) +{ + if (value == 1) { + if (bit >= 32 && __riscv_xlen == 32) + csr_set(CSR_MENVCFGH, _ULL(1) << (bit - 32)); + else + csr_set(CSR_MENVCFG, _ULL(1) << bit); + + } else if (value == 0) { + if (bit >= 32 && __riscv_xlen == 32) + csr_clear(CSR_MENVCFGH, _ULL(1) << (bit - 32)); + else + csr_clear(CSR_MENVCFG, _ULL(1) << bit); + } else { + return SBI_EINVAL; + } + + return SBI_OK; +} + +static int fwft_menvcfg_read_bit(unsigned long *value, unsigned long bit) +{ + unsigned long cfg; + + if (bit >= 32 && __riscv_xlen == 32) + cfg = csr_read(CSR_MENVCFGH) & (_ULL(1) << (bit - 32)); + else + cfg = csr_read(CSR_MENVCFG) & (_ULL(1) << bit); + + *value = cfg != 0; + + return SBI_OK; +} + static int fwft_misaligned_delegation_supported(struct fwft_config *conf) { if (!misa_extension('S')) @@ -114,36 +148,12 @@ static int fwft_adue_supported(struct fwft_config *conf) static int fwft_set_adue(struct fwft_config *conf, unsigned long value) { - if (value == 1) -#if __riscv_xlen == 32 - csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32); -#else - csr_set(CSR_MENVCFG, ENVCFG_ADUE); -#endif - else if (value == 0) -#if __riscv_xlen == 32 - csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32); -#else - csr_clear(CSR_MENVCFG, ENVCFG_ADUE); -#endif - else - return SBI_EINVAL; - - return SBI_OK; + return fwft_menvcfg_set_bit(value, ENVCFG_ADUE_SHIFT); } static int fwft_get_adue(struct fwft_config *conf, unsigned long *value) { - unsigned long cfg; - -#if __riscv_xlen == 32 - cfg = csr_read(CSR_MENVCFGH) & (ENVCFG_ADUE >> 32); -#else - cfg = csr_read(CSR_MENVCFG) & ENVCFG_ADUE; -#endif - *value = cfg != 0; - - return SBI_OK; + return fwft_menvcfg_read_bit(value, ENVCFG_ADUE_SHIFT); } static int fwft_lpad_supported(struct fwft_config *conf) @@ -157,24 +167,12 @@ static int fwft_lpad_supported(struct fwft_config *conf) static int fwft_enable_lpad(struct fwft_config *conf, unsigned long value) { - if (value == 1) - csr_set(CSR_MENVCFG, ENVCFG_LPE); - else if (value == 0) - csr_clear(CSR_MENVCFG, ENVCFG_LPE); - else - return SBI_EINVAL; - - return SBI_OK; + return fwft_menvcfg_set_bit(value, ENVCFG_LPE_SHIFT); } static int fwft_get_lpad(struct fwft_config *conf, unsigned long *value) { - unsigned long cfg; - - cfg = csr_read(CSR_MENVCFG) & ENVCFG_LPE; - *value = cfg != 0; - - return SBI_OK; + return fwft_menvcfg_read_bit(value, ENVCFG_LPE_SHIFT); } static int fwft_sstack_supported(struct fwft_config *conf) @@ -188,24 +186,12 @@ static int fwft_sstack_supported(struct fwft_config *conf) static int fwft_enable_sstack(struct fwft_config *conf, unsigned long value) { - if (value == 1) - csr_set(CSR_MENVCFG, ENVCFG_SSE); - else if (value == 0) - csr_clear(CSR_MENVCFG, ENVCFG_SSE); - else - return SBI_EINVAL; - - return SBI_OK; + return fwft_menvcfg_set_bit(value, ENVCFG_SSE_SHIFT); } static int fwft_get_sstack(struct fwft_config *conf, unsigned long *value) { - unsigned long cfg; - - cfg = csr_read(CSR_MENVCFG) & ENVCFG_SSE; - *value = cfg != 0; - - return SBI_OK; + return fwft_menvcfg_read_bit(value, ENVCFG_SSE_SHIFT); } #if __riscv_xlen > 32 From patchwork Fri Oct 18 08:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1998996 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=AU6uvVvj; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=V7ZYOKqa; 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 4XVJNv0PX7z1xwK for ; Fri, 18 Oct 2024 19:52:14 +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:References:In-Reply-To: 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: List-Owner; bh=g9gwPep9pmuLYnJ9URFbnyO9692o3sVQQxNf5Lk1FnI=; b=AU6uvVvjYo4OXU vqFwvMGGuzaEboh66A9LyrUbb1QGxD7Ek3ExX/Qa1m/xjnQkGb7WagSyIXyIP2suXTgvrFOLBeik4 Ay6akfXa5fgoXGTJOjkAM8V8Ivh87iRVPy1P/IbqrZ/zFWWmLmg2n58ID/Yy7x001rxPl54dMd6Bl zwQpNqLhYHzsaWopa/inG8+FxC6jqWVxzvyRSqFzADOomTzER5glzJ3ETMnxJHlURcilNPzgL9JAE 1nU6S0xBahaDTFJuZ+KoFJ2y6wigoy5wnc3W7BPymz4ueGbjHo+T857sc0NR4DmTCtXTdkeuDsriq 4TeaQGONtlU5QQVRvtlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1iiL-000000003FN-1WSC; Fri, 18 Oct 2024 08:52:05 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1iXf-000000000Ks-0bpD for opensbi@lists.infradead.org; Fri, 18 Oct 2024 08:41:05 +0000 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2e3d523a24dso1360676a91.0 for ; Fri, 18 Oct 2024 01:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729240861; x=1729845661; darn=lists.infradead.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=kVzdpwW8Ta8tgRIO88EppH71xSJN9dVsdpFI56oNC6g=; b=V7ZYOKqaMa5Te91HgU2wznxfw1mR40GHUOzUM7FhXDHYL1e2fk+9c9Phho5slSBV50 SXv5rFi9WrzVfZnjUzNndurUE5G8jnTqjc+sJrv2L2muVDMHsk7e8GLDh8KBy3AY/u2h a9KMxc9z+rlsDdxZ92EYeKhqVYR2rJkcHMTCcmqlWa5cR1nMh+8NP9FNYSf5xnFOcBYk rJOg/GyLrl9LvWuVjJgB2Ckp2X+pa8UDL621EVbRoMF62BAUFvpr97YFMIT0TaYfiZPu RcxYu20dW6Djp5bnWXs4JVTLih35QiQqTFSk7JE9GdwpNCJIJ6lnHxx1P/N89oFJ6E2K 7tIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729240861; x=1729845661; 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=kVzdpwW8Ta8tgRIO88EppH71xSJN9dVsdpFI56oNC6g=; b=S7AL/Voc35FnJ7eAZTSDFGCtZckI6SCc1AamQ8F8Gfkl9zB9O1DPv6jw+sMwAIA9TX JkV8a6PAupEo4ABMNowrDihhYrQuzMQ/TH1xI/dpixccBtAxysN5G88qAvVkVLkKcQ8D bDtBUHnVyvNSX0PSKmm76XglQTQUbZJ8Ld7ZDyU0qgRByF3LSXR8Cffde6pYV+oZ/jGk eiOJy7IjmNMBbTaeoYLs346jp1CB+bKV7OeWOARBGkP9c1IQvC9mUw+7dc+PI6xWbmON 64WzkhsKjV9BBgv9yrTuCAZbEBpy3xd8kFD27iDgw2xhNsK/4SclQNNjjWhYAtsuQAYw zlcA== X-Gm-Message-State: AOJu0YyLVJKCpFaa8tCiG7Dmj/jtFVJuyrCbzSLH+8/MF5HnBNsRAWuG PVIhHPeC5ftqMVGzkiZNyS7OoH7axL8IGlbjDS157bvxeN/JA8oiJZWQPsWLnxVxvlFYRzfihoG 7f3A= X-Google-Smtp-Source: AGHT+IGDbOla4tjGjX0ecSzLLK/ph3dnAMJjbS24Q8tpQAGSVMdhgVxKdmZ6SwDPrhSnjMZm/WBWDA== X-Received: by 2002:a17:90a:a796:b0:2e2:c835:bc31 with SMTP id 98e67ed59e1d1-2e5615c45e3mr2159516a91.7.1729240860816; Fri, 18 Oct 2024 01:41:00 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e55d8051a9sm1364094a91.27.2024.10.18.01.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 01:41:00 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH v4 6/7] lib: sbi: implement firmware feature SBI_FWFT_DOUBLE_TRAP Date: Fri, 18 Oct 2024 10:40:07 +0200 Message-ID: <20241018084010.406285-7-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018084010.406285-1-cleger@rivosinc.com> References: <20241018084010.406285-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_014103_242000_589584D5 X-CRM114-Status: GOOD ( 11.57 ) X-Spam-Score: -1.9 (-) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__Add_support_for_double_trap_firmware_f?= =?unknown-8bit?q?eature=2E_Link=3A_https=3A//lists=2Eriscv=2Eorg/g/tech-prs?= =?unknown-8bit?q?/message/985?= =?unknown-8bit?q?_=5B1=5D_Signed-off-by=3A_Cl=C3=A9ment_L=C3=A9ger_=3Ccleger?= =?unknown-8bit?q?=40rivosinc=2Ecom=3E_Reviewed-by=3A_Samuel?= =?unknown-8bit?q?_Holland_=3Csamuel=2Eholland=40sifive=2Ecom=3E_---_include/?= =?unknown-8bit?q?sbi/riscv=5Fencoding=2Eh_=7C_=5B=2E=2E=2E=5D?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-1=2E9_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyNjA3OmY4YjA6NDg2NDoyMDowOjA6MDoxMDMyIGxpc3RlZCBpbl0=?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-1=2E9_BAYES=5F00_______________BODY=3A_Bayes_spam_probabi?= =?unknown-8bit?q?lity_is_0_to_1=25?= =?unknown-8bit?q?_=5Bscore=3A_0=2E0000=5D?= 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Ved Shanbhogue Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add support for double trap firmware feature. Link: https://lists.riscv.org/g/tech-prs/message/985 [1] Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- include/sbi/riscv_encoding.h | 3 ++- lib/sbi/sbi_fwft.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index fd34ba7..174cc9c 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -217,7 +217,8 @@ #define ENVCFG_ADUE_SHIFT 61 #define ENVCFG_ADUE (_ULL(1) << ENVCFG_ADUE_SHIFT) #define ENVCFG_CDE (_ULL(1) << 60) -#define ENVCFG_DTE (_ULL(1) << 59) +#define ENVCFG_DTE_SHIFT 59 +#define ENVCFG_DTE (_ULL(1) << ENVCFG_DTE_SHIFT) #define ENVCFG_PMM (_ULL(0x3) << 32) #define ENVCFG_PMM_PMLEN_0 (_ULL(0x0) << 32) #define ENVCFG_PMM_PMLEN_7 (_ULL(0x2) << 32) diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c index 9ee0d07..9cf14c1 100644 --- a/lib/sbi/sbi_fwft.c +++ b/lib/sbi/sbi_fwft.c @@ -137,6 +137,25 @@ static int fwft_get_misaligned_delegation(struct fwft_config *conf, return SBI_OK; } +static int fwft_double_trap_supported(struct fwft_config *conf) +{ + if (!sbi_hart_has_extension(sbi_scratch_thishart_ptr(), + SBI_HART_EXT_SSDBLTRP)) + return SBI_ENOTSUPP; + + return SBI_OK; +} + +static int fwft_set_double_trap(struct fwft_config *conf, unsigned long value) +{ + return fwft_menvcfg_set_bit(value, ENVCFG_DTE_SHIFT); +} + +static int fwft_get_double_trap(struct fwft_config *conf, unsigned long *value) +{ + return fwft_menvcfg_read_bit(value, ENVCFG_DTE_SHIFT); +} + static int fwft_adue_supported(struct fwft_config *conf) { if (!sbi_hart_has_extension(sbi_scratch_thishart_ptr(), @@ -349,6 +368,12 @@ static const struct fwft_feature features[] = .set = fwft_enable_sstack, .get = fwft_get_sstack, }, + { + .id = SBI_FWFT_DOUBLE_TRAP, + .supported = fwft_double_trap_supported, + .set = fwft_set_double_trap, + .get = fwft_get_double_trap, + }, { .id = SBI_FWFT_PTE_AD_HW_UPDATING, .supported = fwft_adue_supported, From patchwork Fri Oct 18 08:40:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 1998995 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=jorafPcM; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=OHL3b4yF; 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 4XVJNt74d9z1xwH for ; Fri, 18 Oct 2024 19:52:14 +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:References:In-Reply-To: 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: List-Owner; bh=U3GB4wWogXMImtJ6ZOo7L6zYZEnY9R8kfvnc/gZ4tiQ=; b=jorafPcMSOltrz wXQLMe66TyiN9Qo4R3lJBBpSLxNTjfWdopUnInzXyQGyAJ0K17qPbNvipO1Pj4oLln2eoS53Zl/X8 kCF+s+HZ6a9Ft9TiAKdctgJKG0XBO2AYwxBA2hyUn3odSTXdSOjAgpmD89dr6wzC7K6usrmsxEC+U 83O63zK7smKjeKNG/l/thJ3oAPQ0MuxfXudamU00mhK2BihtTk7VgeKQ042I93VQ9mIhZVWX9aUr7 oDQtQVUs+JUixmm0ORMW9vVZbLsLJTIqjNHe3b4upx7qDFFn7t2arGafvfDpudidoWkkO5YQVFOf3 wl2vKyjiqFVingv66+aQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1iiM-000000003Fi-0HnP; Fri, 18 Oct 2024 08:52:06 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t1iXl-000000000NL-48GX for opensbi@lists.infradead.org; Fri, 18 Oct 2024 08:41:14 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-71e8c0bd2c3so1227328b3a.2 for ; Fri, 18 Oct 2024 01:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1729240866; x=1729845666; darn=lists.infradead.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=k+gDK0N+mfBq6JPQeeaUd8K23zkGzZ88cNoqQsQC+6U=; b=OHL3b4yFVesUzW3ExVkg1UNbcybuW4u+ayis1K0PC3a3zR92k3YwhRfUr5HpCwst0m DdgNF4+T2+izW26HlQl4VbShidnTRew12G6voSAdJrDyIMRdfIV4UnH5kssOAYI4Gve+ MKR5DSFb+ggYmvM9FCEFgt1BdM0CWer+b5NDEFTO8v8vgxuvEx7HVyyCGqneKy0u9tpX GaitJSkUqpfpyTJp1UYjGoGcY6fAan3DNQ296dOP84u3Gcle1tflu9zVyrgPRCHQe0DW 4C6hUjDvCQROzZoW6LODsNU1jr0Inb30ynN3yUQeIUvR0cUN3LZxuX0+wm/QYMZsj6LK ik1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729240866; x=1729845666; 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=k+gDK0N+mfBq6JPQeeaUd8K23zkGzZ88cNoqQsQC+6U=; b=mxZxPDyAhf4IqwBghmLjCLk9G3+Ph5RrChm7DH94OZFv2xDMEiy+ZEII3pjYx5LrsJ rlu/Zsgr63oetLp1UIM3ruXp1f7vjdrHLpfuLZrfLhy3w556Z7SGUY1oBmVlwzLz+MEh ueihYIyThbjdt+C4eZYb2yO8HhWsmeFITNlWgNTXkOeE4y/Oh7YbIX1npGCrqsg5ynM/ hrqoZNHs0tnM7Pud4NN5qDtdb9sRG7D9LLEIAJMXWC8jZJjdHCtwCj/xQWFtRSeieMYR jLn52nsL0cB8bWp9MiQMzNOQ7ELMbLDbBgRfzomNemwCKCuerNh4UjI0apXyYI82tybf WaCw== X-Gm-Message-State: AOJu0Yxm/7PMt9RTGvNtCpECxHzBRJFpc29P6ufB6GHqRIEWDTm6rWqP ZTINMc3fRH0Yxem4PVSSaU5m2+EC3L7cXdYOmd7PnFaDi+ub5mCFCBT9EfWc7OXkiFLbjz+bH8K tyLY= X-Google-Smtp-Source: AGHT+IE56SP1BWNMQpu+S9NAMxo9ZBDwl+GGiqqZpyjZrE3pqI0SwfKrlwOX4zHGHl2ZQEfP/H/4dQ== X-Received: by 2002:a05:6a20:4499:b0:1d9:29c8:2d3b with SMTP id adf61e73a8af0-1d92c590b3emr2144798637.50.1729240866236; Fri, 18 Oct 2024 01:41:06 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e55d8051a9sm1364094a91.27.2024.10.18.01.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 01:41:05 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH v4 7/7] lib: sbi: add Smdbltrp ISA extension support Date: Fri, 18 Oct 2024 10:40:08 +0200 Message-ID: <20241018084010.406285-8-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018084010.406285-1-cleger@rivosinc.com> References: <20241018084010.406285-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241018_014110_102813_BCB99DD5 X-CRM114-Status: GOOD ( 13.99 ) X-Spam-Score: -1.9 (-) 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: Add support for the Smdbltrp[1] ISA extension. First thing to do is clearing MDT on entry after setting the first MTVEC (since MDT is reset to 1). Additionally, during trap handling, clear MDT once al [...] Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42f listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Ved Shanbhogue Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add support for the Smdbltrp[1] ISA extension. First thing to do is clearing MDT on entry after setting the first MTVEC (since MDT is reset to 1). Additionally, during trap handling, clear MDT once all critical CSRs have been saved and in return path, restore MSTATUS/H before restoring MEPC to avoid taking another trap which would clobber it. Link: https://github.com/riscv/riscv-double-trap/releases/download/v0.56/riscv-double-trap.pdf [1] Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- firmware/fw_base.S | 37 +++++++++++++++++++++++++++++++----- include/sbi/riscv_encoding.h | 4 +++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index 4a2652e..d027e5e 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -31,6 +31,16 @@ add \__d4, \__s4, zero .endm +.macro CLEAR_MDT tmp +#if __riscv_xlen == 32 + li \tmp, MSTATUSH_MDT + csrc CSR_MSTATUSH, \tmp +#else + li \tmp, MSTATUS_MDT + csrc CSR_MSTATUS, \tmp +#endif +.endm + .section .entry, "ax", %progbits .align 3 .globl _start @@ -91,6 +101,14 @@ _bss_zero: lla s4, _start_hang csrw CSR_MTVEC, s4 + /* + * While at this point, trap handling is rudimentary, if a trap happens, + * it will end up in _start_hang which is enough to hook up a GDB. Clear + * MDT to avoid generating a double trap and thus entering a + * critical-error state. + */ + CLEAR_MDT t0 + /* Setup temporary stack */ lla s4, _fw_end li s5, (SBI_SCRATCH_SIZE * 2) @@ -348,6 +366,9 @@ _start_warm: _skip_trap_handler_hyp: csrw CSR_MTVEC, a4 + /* Clear MDT here again for all harts */ + CLEAR_MDT t0 + /* Initialize SBI runtime */ csrr a0, CSR_MSCRATCH call sbi_init @@ -545,6 +566,9 @@ memcmp: li t0, 0 .endif REG_S t0, (SBI_TRAP_REGS_SIZE + SBI_TRAP_INFO_OFFSET(gva))(sp) + + /* We are ready to take another trap, clear MDT */ + CLEAR_MDT t0 .endm .macro TRAP_CALL_C_ROUTINE @@ -587,15 +611,18 @@ memcmp: .endm .macro TRAP_RESTORE_MEPC_MSTATUS have_mstatush - /* Restore MEPC and MSTATUS CSRs */ - REG_L t0, SBI_TRAP_REGS_OFFSET(mepc)(a0) - csrw CSR_MEPC, t0 - REG_L t0, SBI_TRAP_REGS_OFFSET(mstatus)(a0) - csrw CSR_MSTATUS, t0 + /* + * Restore MSTATUS and MEPC CSRs starting with MSTATUS/H to set MDT + * flags since we can not take a trap now or MEPC would be cloberred + */ .if \have_mstatush REG_L t0, SBI_TRAP_REGS_OFFSET(mstatusH)(a0) csrw CSR_MSTATUSH, t0 .endif + REG_L t0, SBI_TRAP_REGS_OFFSET(mstatus)(a0) + csrw CSR_MSTATUS, t0 + REG_L t0, SBI_TRAP_REGS_OFFSET(mepc)(a0) + csrw CSR_MEPC, t0 .endm .macro TRAP_RESTORE_A0_T0 diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 174cc9c..38997ef 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -42,7 +42,8 @@ #define MSTATUS_GVA _ULL(0x0000004000000000) #define MSTATUS_GVA_SHIFT 38 #define MSTATUS_MPV _ULL(0x0000008000000000) -#define MSTATUS_MPELP _ULL(0x0000020000000000) +#define MSTATUS_MPELP _ULL(0x0000020000000000) +#define MSTATUS_MDT _ULL(0x0000040000000000) #else #define MSTATUSH_SBE _UL(0x00000010) #define MSTATUSH_MBE _UL(0x00000020) @@ -50,6 +51,7 @@ #define MSTATUSH_GVA_SHIFT 6 #define MSTATUSH_MPV _UL(0x00000080) #define MSTATUSH_MPELP _UL(0x00000200) +#define MSTATUSH_MDT _UL(0x00000400) #endif #define MSTATUS32_SD _UL(0x80000000) #define MSTATUS64_SD _ULL(0x8000000000000000)