From patchwork Wed Aug 14 08:40:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 1972299 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=r9lpAkwK; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=kLA22h0/; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=UhD+q0ha; 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 4WkNfl64Czz1yYl for ; Wed, 14 Aug 2024 19:45:51 +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:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=HBfc1n0KnCOFMdhFrXWiXypDWZi5haVw9IVHVph8DSo=; b=r9lpAkwKDFPOyB sU2Z1R4oefx4i8pQiARJlXoFCv99TYtQ1I4IYEUldOQd8Z13LKKqWqgRx4ccVTGrlFqmButc9kDtI ex+UJXT2OErRdD4q5C1CaYGF7QLjrNX22zWX0IlMMtQyVqfSedTRmjQDy87WqnJ4Q358zScwGdjIP KREqbiYivvDn+BDWB7gCrYifxuk06NBCPLVS+w3XtD+JHLWI/i6u2nZLyNaOwwdPijTTc8e+VIVAK r5+gBx9gfxBXvNlvqJPh1Kau4PHp3ROKHyWePxFZzkXXYqw7ruRnlgHucX09YySkYUoXUYgKNnjyj g7CCta2KzGGK3Z9dSVkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1seAZa-00000006RyA-3XeS; Wed, 14 Aug 2024 09:45:42 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se9Yk-00000006G9N-02da for opensbi@bombadil.infradead.org; Wed, 14 Aug 2024 08:40:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=LmJkO3eV1SYuuOFVPKjOLVCrI+aThFjOc3Nrw5NmsXs=; b=kLA22h0/bpSIA/bfUmFDVJ8n7r iYYtV22HgWgjLiMDr9/AWxJftWSxZEpabVPtVxDh5/Bc8wW3Rb25ok0TZ0ZReukdIbmIhRxbPKDsr BbC6IXdbJzO8UB7jqowuqW7ocvSeOD6GFWoBcPnixP/4B+JuY0Qog2P10L7FtdrdolCixfye+mqWR DQfxyD2J6SCJUmnpaPCPQM4cOoJefuCUUQEv5ntWdrtrgaNU9VKsQeUSYK0lYNeWjiSGJDDkkYtqT V1XmOzkUsgqZyPUaPrAE6+HzqcZpDFLH+n7ln6eoKgsW6fxgiMd4tVknknLPjpcuY8PRMevGuEgSY eZOWFrLQ==; Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1se9Yg-00000007yGU-0NDi for opensbi@lists.infradead.org; Wed, 14 Aug 2024 08:40:44 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1ff4fa918afso37407395ad.1 for ; Wed, 14 Aug 2024 01:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1723624839; x=1724229639; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LmJkO3eV1SYuuOFVPKjOLVCrI+aThFjOc3Nrw5NmsXs=; b=UhD+q0habmRkvrv6H2QPP7apJEs16dVc1thrKMFeaGVyOohdwyKJRsj+3gMfKvcnTh CxJL1Z/Y6C0Iuw+v7onM5gz7WXuLY00hwnvo5UTHFjHavbIgNPVQ6Hf+QRXS9mKGkRWf h2jC5swbbl+yFpg2TopUxIynZCBNLU5NRB3WFyXthuyk/41jaxEMspbF33IOvmoypBuV GeQwW084Yw/j4QUdAF19U0CNIlrWk3OtsFWouLtgfloz8DDFTBHOlehhXlPxNYSk9YY/ 50QCDXaui9fgCHoCSEOA10ihsS7ODN9lQOFASn2Z0+bMI01ch4TsGHbfUCXbKd4OksW+ cYFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723624839; x=1724229639; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LmJkO3eV1SYuuOFVPKjOLVCrI+aThFjOc3Nrw5NmsXs=; b=l6X/rHK62EEuoLxNXslf39CH7APud9Y7b9xxYn5DoqZLignvJeJwtFDHb9/Kuo3FzT OAlhLXQsYwjgpFvaCWUojSATx9iymvr2aOjotEJbx1vVEEmj6ZHr7k6TizK9SVwq1tTa pB+mwd9D/Qxg5Mbk45WuD4wvgL7f82WjC/2oTM1FjAeH4rXtWxSiTC5oc1zlm5hMYlvl 0W/q1oxdU/8Hx+JC8EP//qVBOQz0xlthLPowLo8ddzb8KCtBG7fHOdJjFoa/oWzv9yXa VqBcyEK/gWxNikMqMKTfYYsesFRJAWnvxKG6EkNeAltBQhQLNGc4plTacWTCISLjNOS3 MimQ== X-Gm-Message-State: AOJu0YxKxX11jZMm+PBfLo5jZ60h6YwJ8THAe8F5BCIYyhNHxW4x/fYK BRM5T6andcr3NVW9TQrcagC2seWY/d38/b8xsfkXihoS3F5Qj3G+EfoPIMNd1ETXuIS6ykfnMoW d7f+Vbr2X0xOSJnv7s4Dy2I6wyUndnjIUuLDyfC/ysewof4NtHi9JOUvqQYc/d3NazR/J+Op/g/ A5D9Hk2kcgmJwjhjP2RdZQoxriMdhzBax0xrURNQzacoUX5AMj3hU= X-Google-Smtp-Source: AGHT+IELoMRVZsO7p1qgXmum5tQ939xZ6PTloNEVyvQCW2EzEeSGjWlA/L51URJ8SABow6wsSAllJg== X-Received: by 2002:a17:902:db0b:b0:1ff:5135:1317 with SMTP id d9443c01a7336-201d64b0767mr26236095ad.51.1723624838939; Wed, 14 Aug 2024 01:40:38 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201cd1a9eb6sm25119885ad.155.2024.08.14.01.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 01:40:38 -0700 (PDT) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH] lib: sbi: fwft: add support for SBI_FWFT_POINTER_MASKING_PMLEN Date: Wed, 14 Aug 2024 01:40:30 -0700 Message-ID: <20240814084037.967027-1-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240814_094042_583094_7932B9E3 X-CRM114-Status: GOOD ( 17.06 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.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 controlling the pointer masking mode on harts which support the Smnpm extension. This extension can only exist on harts where XLEN >= 64 bits. This implementation selects the mode with [...] 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_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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add support for controlling the pointer masking mode on harts which support the Smnpm extension. This extension can only exist on harts where XLEN >= 64 bits. This implementation selects the mode with the smallest PMLEN that satisfies the caller's requested lower bound. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- This patch implements the API I originally suggested while the FWFT extension was a draft and also submitted here: https://github.com/riscv-non-isa/riscv-sbi-doc/pull/161 include/sbi/riscv_encoding.h | 4 ++ include/sbi/sbi_ecall_interface.h | 3 +- include/sbi/sbi_hart.h | 2 + lib/sbi/sbi_fwft.c | 67 +++++++++++++++++++++++++++++++ lib/sbi/sbi_hart.c | 1 + 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 2ed05f24..beb874af 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -213,6 +213,10 @@ #define ENVCFG_PBMTE (_ULL(1) << 62) #define ENVCFG_ADUE (_ULL(1) << 61) #define ENVCFG_CDE (_ULL(1) << 60) +#define ENVCFG_PMM (_ULL(0x3) << 32) +#define ENVCFG_PMM_PMLEN_0 (_ULL(0x0) << 32) +#define ENVCFG_PMM_PMLEN_7 (_ULL(0x2) << 32) +#define ENVCFG_PMM_PMLEN_16 (_ULL(0x3) << 32) #define ENVCFG_CBZE (_UL(1) << 7) #define ENVCFG_CBCFE (_UL(1) << 6) #define ENVCFG_CBIE_SHIFT 4 diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index e9a81677..2958b418 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -128,7 +128,8 @@ enum sbi_fwft_feature_t { SBI_FWFT_SHADOW_STACK = 0x2, SBI_FWFT_DOUBLE_TRAP = 0x3, SBI_FWFT_PTE_AD_HW_UPDATING = 0x4, - SBI_FWFT_LOCAL_RESERVED_START = 0x5, + SBI_FWFT_POINTER_MASKING_PMLEN = 0x5, + SBI_FWFT_LOCAL_RESERVED_START = 0x6, SBI_FWFT_LOCAL_RESERVED_END = 0x3fffffff, SBI_FWFT_LOCAL_PLATFORM_START = 0x40000000, SBI_FWFT_LOCAL_PLATFORM_END = 0x7fffffff, diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 81ec061d..32545f41 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -67,6 +67,8 @@ enum sbi_hart_extensions { SBI_HART_EXT_SVADE, /** Hart has Svadu extension */ SBI_HART_EXT_SVADU, + /** Hart has Smnpm extension */ + SBI_HART_EXT_SMNPM, /** Maximum index of Hart extension */ SBI_HART_EXT_MAX, diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c index ef881ef5..c5803300 100644 --- a/lib/sbi/sbi_fwft.c +++ b/lib/sbi/sbi_fwft.c @@ -59,6 +59,7 @@ static const unsigned long fwft_defined_features[] = { SBI_FWFT_SHADOW_STACK, SBI_FWFT_DOUBLE_TRAP, SBI_FWFT_PTE_AD_HW_UPDATING, + SBI_FWFT_POINTER_MASKING_PMLEN, }; static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature) @@ -145,6 +146,64 @@ static int fwft_get_adue(struct fwft_config *conf, unsigned long *value) return SBI_OK; } +#if __riscv_xlen > 32 +static int fwft_pmlen_supported(struct fwft_config *conf) +{ + if (!sbi_hart_has_extension(sbi_scratch_thishart_ptr(), + SBI_HART_EXT_SMNPM)) + return SBI_ENOTSUPP; + + return SBI_OK; +} + +static bool fwft_try_to_set_pmm(unsigned long pmm) +{ + csr_set(CSR_MENVCFG, pmm); + return (csr_read(CSR_MENVCFG) & ENVCFG_PMM) == pmm; +} + +static int fwft_set_pmlen(struct fwft_config *conf, unsigned long value) +{ + unsigned long prev; + + if (value > 16) + return SBI_EINVAL; + + prev = csr_read_clear(CSR_MENVCFG, ENVCFG_PMM); + if (value == 0) + return SBI_OK; + if (value <= 7) { + if (fwft_try_to_set_pmm(ENVCFG_PMM_PMLEN_7)) + return SBI_OK; + csr_clear(CSR_MENVCFG, ENVCFG_PMM); + } + if (fwft_try_to_set_pmm(ENVCFG_PMM_PMLEN_16)) + return SBI_OK; + csr_write(CSR_MENVCFG, prev); + + return SBI_EINVAL; +} + +static int fwft_get_pmlen(struct fwft_config *conf, unsigned long *value) +{ + switch (csr_read(CSR_MENVCFG) & ENVCFG_PMM) { + case ENVCFG_PMM_PMLEN_0: + *value = 0; + break; + case ENVCFG_PMM_PMLEN_7: + *value = 7; + break; + case ENVCFG_PMM_PMLEN_16: + *value = 16; + break; + default: + return SBI_EFAIL; + } + + return SBI_OK; +} +#endif + static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) { int i; @@ -236,6 +295,14 @@ static const struct fwft_feature features[] = .set = fwft_set_adue, .get = fwft_get_adue, }, +#if __riscv_xlen > 32 + { + .id = SBI_FWFT_POINTER_MASKING_PMLEN, + .supported = fwft_pmlen_supported, + .set = fwft_set_pmlen, + .get = fwft_get_pmlen, + }, +#endif }; int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index c3667019..8c5bcf85 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -680,6 +680,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(smnpm, SBI_HART_EXT_SMNPM), }; _Static_assert(SBI_HART_EXT_MAX == array_size(sbi_hart_ext),