From patchwork Tue Apr 5 10:45:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1613366 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=J9KLWfGN; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=nT/85hb6; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KXkpV745Wz9sCD for ; Tue, 5 Apr 2022 20:46:25 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=yyfDUtf6Qyp7QPe6aSgI/4qDLkz6xfoU59znk1tFtYE=; b=J9KLWfGN6EdVaa D1ilMj3jkigqvPqkIeRlkDkkhmFxuroLGn9MWCLqKUeVfHBFwTBxWlgg+SzDg5AtPiM1xjReDeZVf PDOEjDglHy5TK73w6/p4EAUaPef036Pd/OQs5jeT+Q764/yeb70sPqcVfs1MoPiStYQZyATxEvEcZ F8g0H7DEqEAqrtRg17gbnw2soBwT0+/SdQ+IcDE/TNpJHlXso3844+/waDXM5vUF/kkGxMF51W+VG MNviJ989PreB71oivSZTFaW8LWjlNu/l9BmowsN7shut0LdpOmlwwPyJEUSqeeDeGTwWsXC7J6TE5 Fq2SOUKEI8QwqQt4Ahgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbghK-000gri-Hj; Tue, 05 Apr 2022 10:46:06 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbghH-000gqr-CE for opensbi@lists.infradead.org; Tue, 05 Apr 2022 10:46:04 +0000 Received: by mail-pl1-x629.google.com with SMTP id j8so10536042pll.11 for ; Tue, 05 Apr 2022 03:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CETyVP7dWpHIUj9vLVPtnhGqa7rtF1g8ylsSDVRYCs8=; b=nT/85hb6QcTlbGBCWagUSrqwy6idXFFS4BidC9CYlVibNSBQRwqOypbn3b56gTWIQK cyqaMXHHuJIXMteIYzWShP+h4HQ3JZsQxN4eYYBMjyKevrQP+8EVixfTI1RnxTrZrOTk mN1NOJ53sGUs0u7b3EUBsHogAkxWraWB0Ox9WD/V4b3459cOUrfr+pzWNKknMFhJ7Kss ugh09UlfsvvtMXZxpMMgAKWe3C1gaUJ4kCgfbp2kGCzMEZCc3iB2YjbcjgAD4XvDHNVB sDj/zp3ZrkGXcHtbX33GTwyzie284/3TLTBV1x1nQEuneRxS/7tQ5xhZl89QmkQwdzY3 ks9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CETyVP7dWpHIUj9vLVPtnhGqa7rtF1g8ylsSDVRYCs8=; b=MVq7/oLD0wrXUrb/yLrLlftZMG1ZDQbtpWWFyEzVOBppEj81wB5BCm45NhFFoBVwz/ FLrnK+jw0CjaCdADMmhmAFFZARX0KMDoHW0iwZAcKsZxayBa6hwNogjMKlYj0cnyOwl/ XzlaYrZ+4q0u5qyESRGx21/e7h9qL8kumbxobqLTFnKC8xrGhYbAZ+HQo0aezwm8lT3o 5FgkMf6CDMol0O0pA0w94s9cjR6ZYAxqkkYxAOfV+3bfj0Qp8KBUbacn0tFTffndhzFF QnuEzLnBsUZqLQxS6BfpOgArftDUxXeDutj+letW/pVhz2/lN4AgIEMXd7YbRNO+mGBI hZbQ== X-Gm-Message-State: AOAM5326Vy1ZQ9rA4RezPi6Jh+0PnkwT26NSQ3Z6Kx0exnyxX7IgkFyC W1teyFa57SVzw5dU04+xL27oaY71f4QuXp9fbck= X-Google-Smtp-Source: ABdhPJxs0JZS0E1FZm27YZ/zD+0bxzmq+7sspD3L8WccrutmBugxmPVWC1Rw3zJ0YnYTPAF+7MNtlw== X-Received: by 2002:a17:902:e403:b0:156:ab93:2094 with SMTP id m3-20020a170902e40300b00156ab932094mr2751791ple.104.1649155560131; Tue, 05 Apr 2022 03:46:00 -0700 (PDT) Received: from ThinkPad-T490.dc1.ventanamicro.com ([182.70.13.238]) by smtp.googlemail.com with ESMTPSA id 21-20020a630115000000b00382a0895661sm12964147pgb.11.2022.04.05.03.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 03:45:59 -0700 (PDT) From: Mayuresh Chitale To: opensbi@lists.infradead.org Cc: Mayuresh Chitale Subject: [PATCH v2 1/3] lib: sbi: Add Smstateen extension defines Date: Tue, 5 Apr 2022 16:15:39 +0530 Message-Id: <20220405104541.13185-2-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220405104541.13185-1-mchitale@ventanamicro.com> References: <20220405104541.13185-1-mchitale@ventanamicro.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220405_034603_450658_B86F924E X-CRM114-Status: UNSURE ( 8.79 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Smstateen extension provides a mechanism to plug potential covert channels which are opened by extensions that add to processor state that may not get context-switched. Signed-off-by: Mayuresh Chitale --- include/sbi/riscv_encoding.h | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) Content analysis details: (-0.2 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:629 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_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Smstateen extension provides a mechanism to plug potential covert channels which are opened by extensions that add to processor state that may not get context-switched. Signed-off-by: Mayuresh Chitale --- include/sbi/riscv_encoding.h | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index c02aa8f..04d5621 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -345,6 +345,12 @@ #define CSR_SIEH 0x114 #define CSR_SIPH 0x154 +/* Supervisor stateen CSRs */ +#define CSR_SSTATEEN0 0x10C +#define CSR_SSTATEEN1 0x10D +#define CSR_SSTATEEN2 0x10E +#define CSR_SSTATEEN3 0x10F + /* ===== Hypervisor-level CSRs ===== */ /* Hypervisor Trap Setup (H-extension) */ @@ -413,6 +419,16 @@ #define CSR_VSIEH 0x214 #define CSR_VSIPH 0x254 +/* Hypervisor stateen CSRs */ +#define CSR_HSTATEEN0 0x60C +#define CSR_HSTATEEN0H 0x61C +#define CSR_HSTATEEN1 0x60D +#define CSR_HSTATEEN1H 0x61D +#define CSR_HSTATEEN2 0x60E +#define CSR_HSTATEEN2H 0x61E +#define CSR_HSTATEEN3 0x60F +#define CSR_HSTATEEN3H 0x61F + /* ===== Machine-level CSRs ===== */ /* Machine Information Registers */ @@ -686,6 +702,17 @@ #define CSR_MVIEN 0x308 #define CSR_MVIP 0x309 +/* Smstateen extension registers */ +/* Machine stateen CSRs */ +#define CSR_MSTATEEN0 0x30C +#define CSR_MSTATEEN0H 0x31C +#define CSR_MSTATEEN1 0x30D +#define CSR_MSTATEEN1H 0x31D +#define CSR_MSTATEEN2 0x30E +#define CSR_MSTATEEN2H 0x31E +#define CSR_MSTATEEN3 0x30F +#define CSR_MSTATEEN3H 0x31F + /* Machine-Level High-Half CSRs (AIA) */ #define CSR_MIDELEGH 0x313 #define CSR_MIEH 0x314 @@ -715,6 +742,23 @@ #define CAUSE_VIRTUAL_INST_FAULT 0x16 #define CAUSE_STORE_GUEST_PAGE_FAULT 0x17 +/* Common defines for all smstateen */ +#define SMSTATEEN_MAX_COUNT 4 +#define SMSTATEEN0_CS_SHIFT 0 +#define SMSTATEEN0_CS (_ULL(1) << SMSTATEEN0_CS_SHIFT) +#define SMSTATEEN0_FCSR_SHIFT 1 +#define SMSTATEEN0_FCSR (_ULL(1) << SMSTATEEN0_FCSR_SHIFT) +#define SMSTATEEN0_IMSIC_SHIFT 58 +#define SMSTATEEN0_IMSIC (_ULL(1) << SMSTATEEN0_IMSIC_SHIFT) +#define SMSTATEEN0_AIA_SHIFT 59 +#define SMSTATEEN0_AIA (_ULL(1) << SMSTATEEN0_AIA_SHIFT) +#define SMSTATEEN0_SVSLCT_SHIFT 60 +#define SMSTATEEN0_SVSLCT (_ULL(1) << SMSTATEEN0_SVSLCT_SHIFT) +#define SMSTATEEN0_HSENVCFG_SHIFT 62 +#define SMSTATEEN0_HSENVCFG (_ULL(1) << SMSTATEEN0_HSENVCFG_SHIFT) +#define SMSTATEEN_STATEN_SHIFT 63 +#define SMSTATEEN_STATEN (_ULL(1) << SMSTATEEN_STATEN_SHIFT) + /* ===== Instruction Encodings ===== */ #define INSN_MATCH_LB 0x3 From patchwork Tue Apr 5 10:45:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1613369 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=maZCTmMT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=Zp9+hFxR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KXkpY27Cpz9sCD for ; Tue, 5 Apr 2022 20:46:29 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=zvIiu1JC7/KxFbjPHn2YRlyOVYSM+M5qc8GELVD666k=; b=maZCTmMTZ7O01p +jhsbU2R3bSg2WyhtyBcTruqK0Sw8oCRyVpmfMLIIwBmNDyU0GvjZRCN8fLA/1ih05O+0jBKUOMao 9D9p+3B5NaWylfdDtrutekXMaWY4KkOsLb4WP4wQz/Klsa77hKEnyFZiKIpnbdKacxj5uwi+W4MDA JKHlUwMTFrunhGP+oi2rLIWEXLWS++L2R5Npm/hbFvWMPvTejWrKL1kwxmopHgoYP0igKwFIwsXGD meoLHfwEpvjiCcEtKnyJyiLkNf+fqkXbvf8a6ch1QOHpZikekjWbRYEyBXyss3wAFidCFLr0on3M3 VblGspauXlthlYDiSl/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbghO-000gtn-3s; Tue, 05 Apr 2022 10:46:10 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbghK-000gr9-T9 for opensbi@lists.infradead.org; Tue, 05 Apr 2022 10:46:08 +0000 Received: by mail-pl1-x636.google.com with SMTP id n8so3576102plh.1 for ; Tue, 05 Apr 2022 03:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gJAHBga5oWGpAAjbDEr5vy3Au2l0VUDXjOxkh38FELU=; b=Zp9+hFxR/R9M2WrBENm98gDw6Hx5CT23o3Pe2iqcByCViOfiM6s65x5CO9OL0x+vj5 1WmzbDorJQYdw5irG4JvmxuFcwyuWnqP8k0j0+APBQ3kFWiAouIQt+Dw+KI8lMeav74l QSgzupb+c2x01gRDa5DjACZBjxZYL2xlzlhQt5nzIsnnuDhuN2ig2tyXW1dr7JMd2HC+ 5TdvtGe1FAj/ZywsVZhg/cUVnNpWa2x2fn3sWNtD1JCJpzJO8j0TuGacEE3VICff+98m JcOwBLz15LYaMIv4m6vmm4DPeejJZEcdwZXQUdxmQNLHYYvFqXz+zqUbmegLexB6wB/s cg3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gJAHBga5oWGpAAjbDEr5vy3Au2l0VUDXjOxkh38FELU=; b=O2K5sK0AvTAq3va8k/07LcWzUGq8Ln7gq14hmdVdNDeOCvTYr2GRNZP0UGjm7X39h+ BFLRAKFwDrx2yZtQkgif+wH3ug9Gnt1ecm7mMBgXvkco9mlcDlsTXB54NnuNVIEjAv6v ZTDi55YO8XWVYzgZh1tTA6qWDjWqxueb4CEpQuEwJp7eksEIr//NHPwh/AX6cHL94IVM sK37AQw887kOwyyt8VkHzOEG9qbGkYX0xxEtA5JRwq1uCE0jvlzDyXCKY/YXTBiJHc4G uyKCppVDM9pF0Fcnz40shPl0ePi3z7EVG6102Y6C8xEn023VH3BaQeDvq1VCz4GuMZqL xQsw== X-Gm-Message-State: AOAM5326FQZm3VLCwPV2QrYUrXYtrDRKq7EWQMyX13zafgFk5CwiNwiF wwsI14zOge/56h8cQRb5iHUKvU4Q9xxfVqDpqhM= X-Google-Smtp-Source: ABdhPJySjnBuhGdzc/Zibj6rRtcFqmP7+fB4rpoXN0C8jqMXIe/SU5L3s5WyM8/49BzsiCldZscJwg== X-Received: by 2002:a17:903:22d1:b0:154:4cfa:2b12 with SMTP id y17-20020a17090322d100b001544cfa2b12mr2673926plg.47.1649155562698; Tue, 05 Apr 2022 03:46:02 -0700 (PDT) Received: from ThinkPad-T490.dc1.ventanamicro.com ([182.70.13.238]) by smtp.googlemail.com with ESMTPSA id 21-20020a630115000000b00382a0895661sm12964147pgb.11.2022.04.05.03.46.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 03:46:02 -0700 (PDT) From: Mayuresh Chitale To: opensbi@lists.infradead.org Cc: Mayuresh Chitale Subject: [PATCH v2 2/3] lib: sbi: Detect Smstateen CSRs at boot-time Date: Tue, 5 Apr 2022 16:15:40 +0530 Message-Id: <20220405104541.13185-3-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220405104541.13185-1-mchitale@ventanamicro.com> References: <20220405104541.13185-1-mchitale@ventanamicro.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220405_034606_962108_179A9400 X-CRM114-Status: GOOD ( 13.63 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Extend HART feature detection to discover Smstateen CSRs at boot-time and configure mstateen envcfg bit depending on availability of menvcfg CSR. Signed-off-by: Mayuresh Chitale --- include/sbi/sbi_hart.h | 4 +++- lib/sbi/sbi_hart.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) Content analysis details: (-0.2 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:636 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_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Extend HART feature detection to discover Smstateen CSRs at boot-time and configure mstateen envcfg bit depending on availability of menvcfg CSR. Signed-off-by: Mayuresh Chitale --- include/sbi/sbi_hart.h | 4 +++- lib/sbi/sbi_hart.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 57f80bc..be3ad9f 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -28,9 +28,11 @@ enum sbi_hart_features { SBI_HART_HAS_AIA = (1 << 5), /** HART has menvcfg CSR */ SBI_HART_HAS_MENVCFG = (1 << 6), + /** HART has mstateen CSR **/ + SBI_HART_HAS_SMSTATEEN = (1 << 7), /** Last index of Hart features*/ - SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_MENVCFG, + SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SMSTATEEN, }; struct sbi_scratch; diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 6be9286..db08eaf 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -43,6 +43,7 @@ static void mstatus_init(struct sbi_scratch *scratch) int cidx; unsigned int num_mhpm = sbi_hart_mhpm_count(scratch); uint64_t mhpmevent_init_val = 0; + unsigned long mstateen_val; /* Enable FPU */ if (misa_extension('D') || misa_extension('F')) @@ -87,6 +88,22 @@ static void mstatus_init(struct sbi_scratch *scratch) #endif } + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SMSTATEEN)) { + mstateen_val = csr_read(CSR_MSTATEEN0); +#if __riscv_xlen == 32 + mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32; +#endif + mstateen_val |= SMSTATEEN_STATEN; + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MENVCFG)) + mstateen_val |= SMSTATEEN0_HSENVCFG; + else + mstateen_val &= ~SMSTATEEN0_HSENVCFG; + csr_write(CSR_MSTATEEN0, mstateen_val); +#if __riscv_xlen == 32 + csr_write(CSR_MSTATEEN0H, mstateen_val >> 32); +#endif + } + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MENVCFG)) { menvcfg_val = csr_read(CSR_MENVCFG); @@ -348,6 +365,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) case SBI_HART_HAS_MENVCFG: fstr = "menvcfg"; break; + case SBI_HART_HAS_SMSTATEEN: + fstr = "smstateen"; + break; default: break; } @@ -584,6 +604,11 @@ __aia_skip: if (!trap.cause) hfeatures->features |= SBI_HART_HAS_MENVCFG; + /* Detect if hart supports mstateen CSRs */ + val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap); + if (!trap.cause) + hfeatures->features |= SBI_HART_HAS_SMSTATEEN; + return; } From patchwork Tue Apr 5 10:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 1613368 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=UW2xUWXJ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=Urlme0En; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KXkpW5zN5z9sFq for ; Tue, 5 Apr 2022 20:46:26 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=/EJlZiYFgEEb02VaA/NJE+4DKZ+jAHLmVyz2n29P0Ns=; b=UW2xUWXJUspImo lrZlSGRwMDSO7r3JVpCn4DXrGDiBSZJ0whS5nzuYJ6eQvJ2mos+1lyp780vhWmNwt/sh7oUFVoQqu 5dVDgGD6KC1g+XIiqrKPecjpqUzoGdIUPbkdYNhXXQm4bjD/zmqUyRZaUla89lENDQhskke2GRJiM U6i3E+ThRB+UUaJcF3Awn1vDIp/d2lZ+wNP1fvp8GAXDUh69j3EDPUdNmBoiDEvs3axi/z9Z/pFj8 aPY45DwY/Ac0pFS44n17KxarIRB2jFEhjPYYnmpnR1QtRYoIji1iyFieH+dFAAZQfVblxcUT0Vxcd BK9NCS/ixJO+IGR+QABg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbghQ-000guy-0W; Tue, 05 Apr 2022 10:46:12 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbghM-000grc-PV for opensbi@lists.infradead.org; Tue, 05 Apr 2022 10:46:10 +0000 Received: by mail-pj1-x102a.google.com with SMTP id i10-20020a17090a2aca00b001ca56c9ab16so1621522pjg.1 for ; Tue, 05 Apr 2022 03:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FOBa/XQYkgAK/091/kgpPSZZbVfJ/fWWSwqwI4hTJHs=; b=Urlme0EnGIzcbjyfpaC5iaZ03FGzJPRDGrNyS3r7J9SHYOrjmZqoVYybXxTucMXBjb w7APczn1EhSOOUKSYU96KWADC5Zjg6L8BxxHM3gn9yglR68iSM6PtxCFvRkrbRXYRRUi 61OETKUCaDt+yhugN43dkC55DtnSVcuHfgFVp7dSrK6aqK90zmXEMURgP8UGrohUaISG wXE/+aGNe71bZJh7kKyM2ttOUZDIHrv3ma/kuM8jGPScbX8IEJuYDP7REXeFGP4oj1ZI pU/IH7Pz0MhyPphNanFjHKb9GcWKkIc+uUtHHzy0w5cWLJTYKT+E8ddhm0T8EhePJiOM dxgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FOBa/XQYkgAK/091/kgpPSZZbVfJ/fWWSwqwI4hTJHs=; b=caEN5B9kb1Yincsb+FiAJ2HJe9OISaW347jXAxGIEfLk+jnL2e3sdL5IS/fzj98WEr AKfCG7SZB+3ewgAI9OCIPG0Wb08u8bJMx1/KtpSq6OClBCZ2aRc/M+jjqYu/jS4YTFDr LniF3jgkJX1dYU1d1VqVcYQwQeIcA14dCq1oEnBuKuzXPffiKo13L1PBIJ9omVYCORLw mWe39T4XZH+3LYJPImunR6R+pIPBfo4+bQf7icf3CcEgUguhMcl92L/n+8witjwbsOcU dTLCSBC/DKit5EmE6ty5Jmn5k4BGRlEGAWHfna+QkXo7EB1h2xnZ6tc1eZnYxHdUNdka L/Nw== X-Gm-Message-State: AOAM530mEnnrhl0vgPMchUwh+s34VSyAFnSiU+/P3HQhEhYVrAliKrlY jWG/8d96GFRySTBFsIiOGewA356SGb7aiQC0t9g= X-Google-Smtp-Source: ABdhPJykO/4kFNDT6iGWTvz5jxQSZl8/AT0KcSGAsi9pwzC5wFG9BuCexXJa5FTpHqB9LJDEM7GKtg== X-Received: by 2002:a17:902:b704:b0:156:624:934b with SMTP id d4-20020a170902b70400b001560624934bmr2958429pls.116.1649155565363; Tue, 05 Apr 2022 03:46:05 -0700 (PDT) Received: from ThinkPad-T490.dc1.ventanamicro.com ([182.70.13.238]) by smtp.googlemail.com with ESMTPSA id 21-20020a630115000000b00382a0895661sm12964147pgb.11.2022.04.05.03.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 03:46:04 -0700 (PDT) From: Mayuresh Chitale To: opensbi@lists.infradead.org Cc: Mayuresh Chitale Subject: [PATCH v2 3/3] lib: irqchip/imsic: configure mstateen Date: Tue, 5 Apr 2022 16:15:41 +0530 Message-Id: <20220405104541.13185-4-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220405104541.13185-1-mchitale@ventanamicro.com> References: <20220405104541.13185-1-mchitale@ventanamicro.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220405_034608_863333_1BBB31A0 X-CRM114-Status: UNSURE ( 8.94 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: When mstateen registers are implemented, the AIA related configurations need to be done in mstateen for the IMSIC initialization to succeed. Signed-off-by: Mayuresh Chitale --- lib/sbi/sbi_hart.c | 6 ++++++ 1 file changed, 6 insertions(+) Content analysis details: (-0.2 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:102a 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_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When mstateen registers are implemented, the AIA related configurations need to be done in mstateen for the IMSIC initialization to succeed. Signed-off-by: Mayuresh Chitale --- lib/sbi/sbi_hart.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index db08eaf..604e0b4 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -98,6 +98,12 @@ static void mstatus_init(struct sbi_scratch *scratch) mstateen_val |= SMSTATEEN0_HSENVCFG; else mstateen_val &= ~SMSTATEEN0_HSENVCFG; + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_AIA)) + mstateen_val |= (SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT | + SMSTATEEN0_IMSIC); + else + mstateen_val &= ~(SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT | + SMSTATEEN0_IMSIC); csr_write(CSR_MSTATEEN0, mstateen_val); #if __riscv_xlen == 32 csr_write(CSR_MSTATEEN0H, mstateen_val >> 32);