From patchwork Fri Aug 23 18:47:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 1976213 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=191V++RG; 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=DPhlVrFx; 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 4Wr8GL6jzRz1yNm for ; Sat, 24 Aug 2024 04:48:10 +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=2hn6ndFAbm2uxyH13AlREvzqZ+2qYibOTn41MCvBmwI=; b=191V++RGtbOkTO xGgRbOaPqcOXBy9eONP3F31/oHybXzrkBNsJZ0ZyH0Pfkdq7kJbNRlggKJ8IvHHTsILVjcquJa2nJ b5kR09tuRya+FF/E2HO6M/ZMAh0KUMoo8sgMR45B52vBeb4vaULzx9je3RVM6KcV35Dy2BqW+iANC w/VFApwXFLdV7ZZONJWqrCr0vo+uXMMJ3+SeRyjTqjD6EaUH531QmFGH1hOh5DL6aIm7VC2T22O5x MoLl50gqdsSfybGRv5LXJ4F92qw20LY59fD6rA0g3AgC7a++eVx5HFnufxqs3stATgN9BXL1EIgpB /+3RvVCze92YvZ5nt6uA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1shZKO-00000000KkF-32p4; Fri, 23 Aug 2024 18:48:04 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1shZK3-00000000KfH-0Csv for opensbi@lists.infradead.org; Fri, 23 Aug 2024 18:48:02 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-20230059241so20330365ad.3 for ; Fri, 23 Aug 2024 11:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1724438861; x=1725043661; 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=MMIzMFPGihrKRBQQA+JEpfSbKP7EvOq7p8gSba3fcbU=; b=DPhlVrFxbkmKpEI8RDKc+DVl2A2HkBOFeLzPjDsal2bcINCTy4YvOrJRr4hsw6F1ta 4xR63KGhWX0ISZmJKisZ7+jKiXKNpyVIpSu6U/upk+AQleMmgajFS9L4Ux6qMK4Yzs9f kV/63aihG4AwZvnM5c7h43jKj0DX5EQn4GlhEDUZ94nswojPq4pdszmUQSt1roB1GkkL 20qZceh8id+66VGFyvZ1XqId2BDiUGjQkbS1FpGayCt/Yv9/9Kz7nejOBTJeZItRWChl 1yblY9VlJkTLvDYOAUrnvvxDRLtMddPXbc9/ry4VyxfjId2dN+Qh/NbMAMUyGnoESS5t wWXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724438861; x=1725043661; 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=MMIzMFPGihrKRBQQA+JEpfSbKP7EvOq7p8gSba3fcbU=; b=kWkqqdx5NbHlo0dsNNzrwLviXqPXKx2KCzkmg3iG4xFhqRooG01wrfkfvuJI0eD57x zmmVG+gC5n0s9qIApYX7NyIKyQOMCYYuDAbIuq7hu+F7Ua3SbjkSqoVhBfD/DkSYQa+B czXoxSL9zy4BbKOEScC2VI68Trb4C9Si+S01GJx4VXPAVwLTxw51LKDQjlPoT3ynig/Z 2TbHSpcsQwLnT/jtN7oCbJTb5LoxhBPLQV3naOWs5jmJEt8xbHpVgzEDaN+6qNgLQpJ0 m/NnJbcgSl4heid5it66RfEIm2YY0ovYlhyyWAVMkQgGP67IcCrKVQ/LZpnGLBF6m5I4 d6EQ== X-Gm-Message-State: AOJu0YzgAoCswXXr/gqAorJlDyQQuXWdw8ySSXuh4a5mRqYyX1CHdaCz 3QLUo76uPDSnif1RS3RyXeRvrXy1p9nsZ0PfMg2+Tn4A51shDLbuJkhBUwTXAyBL5rFtCwFJ6Pg J X-Google-Smtp-Source: AGHT+IEr0zwXESMshT3obc+3cANR7RuXduf0/bTKOXMTYN3yBcc6FNeI8mmLMYe4dWmFeA+p2m7wzg== X-Received: by 2002:a17:902:ecca:b0:1fa:7e0:d69a with SMTP id d9443c01a7336-2039e4ef0d7mr34434595ad.46.1724438861125; Fri, 23 Aug 2024 11:47:41 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20385fcf6b3sm31507705ad.302.2024.08.23.11.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 11:47:40 -0700 (PDT) From: Deepak Gupta To: opensbi@lists.infradead.org Subject: [PATCH v4 2/4] lib: sbi: Zicfilp/Zicfiss detection and elp cfi state reflect back in status Date: Fri, 23 Aug 2024 11:47:33 -0700 Message-ID: <20240823184735.4154272-3-debug@rivosinc.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240823184735.4154272-1-debug@rivosinc.com> References: <20240823184735.4154272-1-debug@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240823_114743_110919_014ACB9C X-CRM114-Status: GOOD ( 12.55 ) 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. 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. 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:62b 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] -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, anup@brainfault.org, atishp@rivosinc.com, cleger@rivosinc.com, Deepak Gupta Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch adds support for zicfilp / zicfiss detection. 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;