From patchwork Thu Sep 12 12:10:46 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: 1984644 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=CEh6kL2F; 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=xZS2Ia3O; 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 4X4GWj6Wy6z1y25 for ; Thu, 12 Sep 2024 22:11:45 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qcmaTMgn6yy0upNGFa4WydEjqk+8pdUunWGMR16oslo=; b=CEh6kL2F+PYMUo ncTWy4tYAXIPh4sgYS3wAkQJNyHW+/C7GDrfHudTmPLtjBMD+5bxHd8KP6OvMlkWIgXAa+skbTvbN a53oJBafPIJkY37VqwXxEnKmCeNe9dTEK4aJZlQ6BeXwiwbo003V1Xon5TD8aXRpJ+Huzy5Olqk9d R+KvvmxbQxtoFmRrhBCwfJCk76KcEt4qAEsWP6co0QgxWtgN8E0Pu5TkCyl0eTmomIeZq9UhVVHSF BENmSGHGpHxdVGScqTLwyIrtGJk+C0F9yx/fPDOSR6o5PcykZqbreVgLqSwPVH73crzL4Gi+FVmNj sV3fI/MMrmk1P9WFriww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soifg-0000000Cxs2-170k; Thu, 12 Sep 2024 12:11:36 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soif6-0000000CxgV-1iLG for opensbi@lists.infradead.org; Thu, 12 Sep 2024 12:11:03 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-42bb7298bdeso9828785e9.1 for ; Thu, 12 Sep 2024 05:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726143059; x=1726747859; 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=l7n+UEOLwhogsZduK1qEJTmC05Qepg0IVulrNQje07I=; b=xZS2Ia3O+6Vjc9cOXGuYMikS6TwXgCfe196gTufY+lDfbee7l9RJ7rybpoPZoJaEv4 at/SxFToCijSWY40bhKCnLT+6gb6NiK7YInblKAqFD1JODU6DOsGfQzIAtC4fNLOOfra G+OJ33EKFWYxQK4MwxLYFowOgGnqLfW+9xBiTUF7HagK/svx4/FwweXxBecWJ6C5ak43 rSAfu1yIqCRWr/pJkFuLeB4Z7/RTtAPn7OVBqWDUxHrOY5JaFPYx+Fd+nD/JtYHL+2UZ /q5cF6IqT4dltLKyRbVPzfI14WMj8WkPf84q5vqh7uC3h04PFfAFUzju0wZuEJrmziwf GKsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726143059; x=1726747859; 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=l7n+UEOLwhogsZduK1qEJTmC05Qepg0IVulrNQje07I=; b=lZTv1Lp5ZXl3UkrDmLP1tJROW0D4ZntspL44KN6oUN8hoSAk4rZlP26hoaMrMzwXt5 WiSesp4xK62GPFJB9ZfIr0LUgzkZ9oxA3zv5MJoaF+alk+pNEUQ8UNHBtijU94rPfZ21 Q6VUU10gtN2CU5P68KOdF13ylidh1ywW5Sfe8Zpl9bhh5DV5VrbQlsZCJ5cq/fnl9FNp KJlVG+bMeBFFzQUs0OOas+ERZHkTz+i+W/2kdt5GtTay/mCANQ+HEuRRXDVEtZ6U+APb 9pCIuWMtT0qIwzbzzWQwnrrgc5+IUebABs5hn+O39kIPGVmfH2Qdjcm5MOyhVBQYPMj3 prQA== X-Gm-Message-State: AOJu0Yxr648q+dqVVTLuMfxzseZnheP7lJmFZT1+bDyNfcJwWvvAB+Sq CloY+7lMflHvzhH9oOAYjDrR26CkqeHF8AiJ3JETg44BcWlR/lOFTKLdHadcm4GOP1KkQtNROuC z11A= X-Google-Smtp-Source: AGHT+IFIyahifxFYl7QPNG3zo8HB91A0RJGk0VSAKPNnuSiSoJu696GRqjHAfGbzJG2+c54p/yjXrA== X-Received: by 2002:a05:600c:3b08:b0:42c:bae0:f05f with SMTP id 5b1f17b1804b1-42cdb53a998mr25279825e9.13.1726143058632; Thu, 12 Sep 2024 05:10:58 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb5ba4532sm146884895e9.38.2024.09.12.05.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 05:10:57 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Anup Patel , Ved Shanbhogue Subject: [PATCH 2/5] lib: sbi: add Ssdbltrp ISA extension support Date: Thu, 12 Sep 2024 14:10:46 +0200 Message-ID: <20240912121052.2959596-3-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240912121052.2959596-1-cleger@rivosinc.com> References: <20240912121052.2959596-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_051100_481447_B2D8981E X-CRM114-Status: GOOD ( 17.94 ) 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 a double trap SSE e [...] 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 [2a00:1450:4864:20:0:0:0:32f 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: , 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 a double trap SSE event is delivered. Signed-off-by: Clément Léger Reviewed-by: Samuel Holland --- include/sbi/riscv_encoding.h | 2 ++ include/sbi/sbi_ecall_interface.h | 2 ++ include/sbi/sbi_hart.h | 3 ++- include/sbi/sbi_trap_ldst.h | 2 ++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_double_trap.c | 26 ++++++++++++++++++++++++++ lib/sbi/sbi_hart.c | 4 ++++ lib/sbi/sbi_sse.c | 1 + lib/sbi/sbi_trap.c | 4 ++++ 9 files changed, 44 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 2e4391f..4728c63 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -213,6 +213,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_CBZE (_UL(1) << 7) #define ENVCFG_CBCFE (_UL(1) << 6) #define ENVCFG_CBIE_SHIFT 4 @@ -763,6 +764,7 @@ #define CAUSE_FETCH_PAGE_FAULT 0xc #define CAUSE_LOAD_PAGE_FAULT 0xd #define CAUSE_STORE_PAGE_FAULT 0xf +#define CAUSE_DOUBLE_TRAP 0x10 #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_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index e9a8167..d8077a7 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -379,7 +379,9 @@ 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_START 0x00004000 #define SBI_SSE_EVENT_LOCAL_PLAT_0_END 0x00007fff #define SBI_SSE_EVENT_GLOBAL_RAS 0x00008000 #define SBI_SSE_EVENT_GLOBAL_PLAT_0_START 0x00004000 diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 81ec061..8aef2a1 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -67,7 +67,8 @@ enum sbi_hart_extensions { SBI_HART_EXT_SVADE, /** Hart has Svadu extension */ SBI_HART_EXT_SVADU, - + /** 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..af3c991 --- /dev/null +++ b/lib/sbi/sbi_double_trap.c @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Rivos Inc. + * + * Authors: + * Clément Léger + */ + +#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); + + /* Exception was taken in VS-mode, redirect it to S-mode */ + if (prev_virt) + return sbi_trap_redirect(regs, trap); + + return sbi_sse_inject_event(SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP); +} diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index cc364fa..d6b9a0a 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; @@ -680,6 +683,7 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = { __SBI_HART_EXT_DATA(ssccfg, SBI_HART_EXT_SSCCFG), __SBI_HART_EXT_DATA(svade, SBI_HART_EXT_SVADE), __SBI_HART_EXT_DATA(svadu, SBI_HART_EXT_SVADU), + __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_sse.c b/lib/sbi/sbi_sse.c index 52172fc..b5f076a 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, diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 8bd2183..188f2a5 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -330,6 +330,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";