From patchwork Wed Mar 12 13:11:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Conor Dooley X-Patchwork-Id: 14013578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98918C28B2F for ; Wed, 12 Mar 2025 13:41:10 +0000 (UTC) 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=2hMBkylFGIS2V7Dr0feSw/JKJZ6Ba8+pLNA2w+zHcIM=; b=I9Se05AAIMbA5t jg6hdN7TGQIVjJR8KWWRYRN/3UDl6WeEjLh1jnsywh+oIm70atIsQ3emhXPQNfWP/TA8Bo58s42yc AE9LSKeN0kjTmH2JJn1S25n1DpytKAzSk2sxq+3aZBeztvdVoxgWpKIzwYcFx/XWyaGihZXmZVzXT +1o4BUCY+dSAa9DzKX/W/QPFSgNPWQsluRRcmC9GNIIoN0hgWLX8WSZon1wGsmYfUMNUUuSfbefid j5qVGLY/6wBXDFyXS+7q+kq4VgnT5wCD9FkoBG7hiS2V/Qx2W3CjlqY4NWrHXcsYJC1GU+56HoKu+ VzzyMAGDgQiiG7Ar6SIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tsMKX-00000008bBY-0F54; Wed, 12 Mar 2025 13:41:05 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tsLt3-00000008X4f-3Q3K for linux-riscv@lists.infradead.org; Wed, 12 Mar 2025 13:12:42 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 8380D5C5AE0; Wed, 12 Mar 2025 13:10:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD8A3C4CEE3; Wed, 12 Mar 2025 13:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741785161; bh=HIf+aPICbUrXbjs2m8V10w71t0JwLVu4gn/Zh9Vui6w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f/7U7xrO8SKIhGKp0vrJKwgKaMM3jhDpRWOoJb1UhpNTgsMm0yB0GXpvskk6IyaOZ UFeBgwll87+nxaeu0tuVnGgdujgT/eMsEX4BBOlAAl1/uWRTCQiBMxa7+jC2tLmscs muqY5FWrg5z6JUVmdS1FdgODyPaKISB0hIAYlKoqvUNdwPUU3PWm9t2qtOYah8YCXM vBb0DEB60YbY5B8htZ123AarHOyEr1EaedPrLu3NzJm+q/FXtiNT99mOHJhKzihidD thQM/KuY4Xv3G+n8DPlPJy3NMSz2wK1qa6qgC/lzpeapnuaZFxYfsUxv31velrDxWM yx9pEyJ8MNe3g== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Eric Biggers , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Andy Chiu , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/6] RISC-V: add f & d extension validation checks Date: Wed, 12 Mar 2025 13:11:46 +0000 Message-ID: <20250312-reptile-platinum-62ee0f444a32@spud> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250312-abide-pancreas-3576b8c44d2c@spud> References: <20250312-abide-pancreas-3576b8c44d2c@spud> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2687; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=4ovnGd2xVakirrIacf77VjQZZtTzzTmY7fwuG+fgLn8=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDOkXO4T1d0x6HKlXwPm9tnz55sVHd1vWVrFVXY16r2m1N jxjU/D0jlIWBjEOBlkxRZbE230tUuv/uOxw7nkLM4eVCWQIAxenAEyk9TQjw+baa+aeUyYq7pix Kf7J9t9Ts2cU5n78dlzzWZbx19h3O9YxMjwwEGKflxHXdFFlxaEpYuf/a7W8daj7VCwb8LLPRya 3jxkA X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250312_061241_941994_115917CF X-CRM114-Status: GOOD ( 12.83 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Conor Dooley Using Clement's new validation callbacks, support checking that dependencies have been satisfied for the floating point extensions. The check for "d" might be slightly confusingly shorter than that of "f", despite "d" depending on "f". This is because the requirement that a hart supporting double precision must also support single precision, should be validated by dt-bindings etc, not the kernel but lack of support for single precision only is a limitation of the kernel. Since vector will now be disabled proactively, there's no need to clear the bit in elf_hwcap in riscv_fill_hwcap() any longer. Tested-by: Clément Léger Reviewed-by: Clément Léger Signed-off-by: Conor Dooley --- arch/riscv/kernel/cpufeature.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 4fa951e9f1cf..21d3cf361e0a 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -109,6 +109,33 @@ static int riscv_ext_zicboz_validate(const struct riscv_isa_ext_data *data, return 0; } +static int riscv_ext_f_validate(const struct riscv_isa_ext_data *data, + const unsigned long *isa_bitmap) +{ + if (!IS_ENABLED(CONFIG_FPU)) + return -EINVAL; + + /* + * Due to extension ordering, d is checked before f, so no deferral + * is required. + */ + if (!__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_d)) { + pr_warn_once("This kernel does not support systems with F but not D\n"); + return -EINVAL; + } + + return 0; +} + +static int riscv_ext_d_validate(const struct riscv_isa_ext_data *data, + const unsigned long *isa_bitmap) +{ + if (!IS_ENABLED(CONFIG_FPU)) + return -EINVAL; + + return 0; +} + static int riscv_ext_vector_x_validate(const struct riscv_isa_ext_data *data, const unsigned long *isa_bitmap) { @@ -371,8 +398,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(i, RISCV_ISA_EXT_i), __RISCV_ISA_EXT_DATA(m, RISCV_ISA_EXT_m), __RISCV_ISA_EXT_DATA(a, RISCV_ISA_EXT_a), - __RISCV_ISA_EXT_DATA(f, RISCV_ISA_EXT_f), - __RISCV_ISA_EXT_DATA(d, RISCV_ISA_EXT_d), + __RISCV_ISA_EXT_DATA_VALIDATE(f, RISCV_ISA_EXT_f, riscv_ext_f_validate), + __RISCV_ISA_EXT_DATA_VALIDATE(d, RISCV_ISA_EXT_d, riscv_ext_d_validate), __RISCV_ISA_EXT_DATA(q, RISCV_ISA_EXT_q), __RISCV_ISA_EXT_SUPERSET(c, RISCV_ISA_EXT_c, riscv_c_exts), __RISCV_ISA_EXT_SUPERSET_VALIDATE(v, RISCV_ISA_EXT_v, riscv_v_exts, riscv_ext_vector_float_validate),