From patchwork Thu Aug 22 06:50:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 1975275 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=NkRgyHLW; 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=IdQpWgbL; 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 4WqDPT3rFgz1yf6 for ; Thu, 22 Aug 2024 16:51:09 +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: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=6L3KzbQDjf+oW3miAe5cXYp5lp4MHGEs3pmE85Cf4eM=; b=NkRgyHLWtV77pP lHsOP9RBy433tIFHn6tVCuioPrB0GH4xD4JI0RffCJaI1vVKTNjlo9l2itDvM+x+KnB7JXxNrR2H8 87uTcYIJ9PsUmR42qQiA3dLpVTTX39Ab8bp4f7rxpFDi2O0eUSerWYf/ULeWx+SeujbBaEgtk6K9N Y21H2GCc4oYF0WPDyhaDvjnvksGaQFMBp+fKghrNFspX+W7+ehPVJu1k4dTX5dgkKY0A4QRvIYCd+ PzARcEjtw/2M10oeLWR3WEYKtte5E0pkQWaXzHwUehuYi3pM+5GWvK9GFWuAbQ66qVjM1v8f30zsA uZGHltnRXilzKKQyPFUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh1ew-0000000BhGw-2lqK; Thu, 22 Aug 2024 06:51:02 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh1et-0000000BhF9-1IsM for opensbi@lists.infradead.org; Thu, 22 Aug 2024 06:51:00 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-7106cf5771bso440628b3a.2 for ; Wed, 21 Aug 2024 23:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724309458; x=1724914258; 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=Y/bAouQ4zWbKAQrkMsea4v+cNEqIfi2tMLGNEyViZvE=; b=IdQpWgbLfTZSPMgROFGPTdMkDbCEWsY22uYupqGRnqS4G/rqAmcyzeuRQgAwHjoul6 b7Q3NWIwX5asLeF6k6IN1HCttcWn5EK5d9O5IcVLPs+9/T+6b0b8XOm7JBjahm+seC6b bFpYxQzbYMWOi455pQwU5R7Fr42quNGKLjcwiAHXi1JD+LihcdVbuhhMGJ+jlOxlq4J+ O5H2vraLG0XHrHSafYGBqnnMgfs8Bx96/UxDiDgzvwpgi749Gt6yBLQ3tKtKdPQ1VA7Q QkviOYEPRFGV02Q82Sn0lOpvjo68F228gVJshuJBYyknGqKuVCRBjYeUyAvdB6xP4E3y EliQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724309458; x=1724914258; 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=Y/bAouQ4zWbKAQrkMsea4v+cNEqIfi2tMLGNEyViZvE=; b=LGfXaFVVhnAE+YcMWVkHUuPlTM9gBAznykseX1xYiTIFZsVmffvn93uEfrme6PwCMm W3gkBiZ4QgOWvQg2vkzAtAoLcoBKFzc+cC9Vsmkrk6qZmG+KuJNmay4XCge+2TE/drSL vg0W2pFg2qWCI3mrhuWmrPWyfrpuYYz5X8YptF49vU2wqnz6XX95oPIyKBaZr6ekcyE+ Oe2PblDrLIo0oWnIH/bGRWP5Vm6NBc1earHXAM7JDvfR+cMrf1MqR/P72/RZP9dsSGQu 0Cm3NEn2XFunj+yZSrbOm3ZvePvTcvoGU35yS0IvJgz/1sv5ZEgzD5VAm2xS8/4piY8Q wl/A== X-Gm-Message-State: AOJu0YzMH/rWB9XCqbJfAaCjBnoHcGSUPVuoMXRYMu1hHoGOdSrJZMty /SsndU9FO+uTPzXhiKzNbD5tIohJ3XTSelB/pDK1GSremBzCrhnlKNppijP3ldf5HVu/Patcamx 1 X-Google-Smtp-Source: AGHT+IGFJ++S9hgpdjm6aEnNykvKnI++mVt217r1kkrAYPiToaSAgjxzj14Wxoe5OS78/3FyAWMO6A== X-Received: by 2002:a05:6a00:3d0c:b0:70d:2725:ebe4 with SMTP id d2e1a72fcca58-7142349a6fdmr5778145b3a.13.1724309458074; Wed, 21 Aug 2024 23:50:58 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-714342e02basm699769b3a.125.2024.08.21.23.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 23:50:57 -0700 (PDT) From: Deepak Gupta To: opensbi@lists.infradead.org Subject: [PATCH v2 2/3] lib: sbi: Zicfilp/Zicfiss detection and elp cfi state reflect back in status Date: Wed, 21 Aug 2024 23:50:48 -0700 Message-ID: <20240822065049.3923308-3-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240822065049.3923308-1-debug@rivosinc.com> References: <20240822065049.3923308-1-debug@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240821_235059_398075_BAEB6A88 X-CRM114-Status: GOOD ( 13.28 ) 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: This patch adds support for zicfilp / zicfiss detection in sbi_hart.c Zicfilp records status of hart's ELP state in *status csr. Missing landing pad sets MPELP in mstatus. When SBI is redirecting back [...] 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:431 listed in] [list.dnswl.org] -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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: apatel@ventanamicro.com, Deepak Gupta , atishp@rivosinc.com Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch adds support for zicfilp / zicfiss detection in sbi_hart.c Zicfilp records status of hart's ELP state in *status csr. Missing landing pad sets MPELP in mstatus. When SBI is redirecting back to S/VS/HS, SPELP is set in sstatus/vsstatus. Signed-off-by: Deepak Gupta --- include/sbi/sbi_hart.h | 3 +++ lib/sbi/sbi_hart.c | 18 ++++++++++++++++++ lib/sbi/sbi_trap.c | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 81ec061..2aa6867 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -67,6 +67,9 @@ enum sbi_hart_extensions { SBI_HART_EXT_SVADE, /** Hart has Svadu extension */ SBI_HART_EXT_SVADU, + /** HART has zicfiss & zicfilp extension */ + SBI_HART_EXT_ZICFILP, + SBI_HART_EXT_ZICFISS, /** Maximum index of Hart extension */ SBI_HART_EXT_MAX, diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index c366701..0636021 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -680,6 +680,8 @@ 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(zicfilp, SBI_HART_EXT_ZICFILP), + __SBI_HART_EXT_DATA(zicfiss, SBI_HART_EXT_ZICFISS), }; _Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext), @@ -776,6 +778,7 @@ static int hart_detect_features(struct sbi_scratch *scratch) unsigned long val, oldval; bool has_zicntr = false; int rc; + bool ssp_exist, elp_exist; /* If hart features already detected then do nothing */ if (hfeatures->detected) @@ -933,6 +936,21 @@ __pmp_skip: /* Save trap based detection of Zicntr */ has_zicntr = sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR); + if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { + val = csr_read_allowed(CSR_SSP, (unsigned long)&trap); + ssp_exist = trap.cause == 0; + if (ssp_exist) + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_ZICFISS, true); + + csr_set(CSR_MSTATUS, MSTATUS_MPELP); + val = csr_read_clear(CSR_MSTATUS, MSTATUS_MPELP); + elp_exist = val & MSTATUS_MPELP; + if (elp_exist) + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_ZICFILP, true); + } + /* Let platform populate extensions */ rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(), hfeatures); diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index b4f3a17..e2502f2 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -103,6 +103,7 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, const struct sbi_trap_info *trap) { ulong hstatus, vsstatus, prev_mode; + bool elp = false; #if __riscv_xlen == 32 bool prev_virt = (regs->mstatusH & MSTATUSH_MPV) ? true : false; #else @@ -116,6 +117,17 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, if (prev_mode != PRV_S && prev_mode != PRV_U) return SBI_ENOTSUPP; + /* If extension has support for CFI, clear MPELP because redirecting to VS or (H)S */ + if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(), SBI_HART_EXT_ZICFILP)) { +#if __riscv_xlen == 32 + elp = regs->mstatusH & MSTATUSH_MPELP; + regs->mstatusH &= ~MSTATUSH_MPELP; +#else + elp = regs->mstatus & MSTATUS_MPELP; + regs->mstatus &= ~MSTATUS_MPELP; +#endif + } + /* If exceptions came from VS/VU-mode, redirect to VS-mode if * delegated in hedeleg */ @@ -169,6 +181,10 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, /* Get VS-mode SSTATUS CSR */ vsstatus = csr_read(CSR_VSSTATUS); + /*if elp was set, set it back in vsstatus */ + if (elp) + vsstatus |= MSTATUS_SPELP; + /* Set SPP for VS-mode */ vsstatus &= ~SSTATUS_SPP; if (prev_mode == PRV_S) @@ -209,6 +225,10 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, /* Clear SIE for S-mode */ regs->mstatus &= ~MSTATUS_SIE; + + /* if elp was set, set it back in mstatus */ + if (elp) + regs->mstatus |= MSTATUS_SPELP; } return 0;