Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp245501rdb; Thu, 19 Oct 2023 03:22:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKU5eMqH+OqRFgYKe8anjiQiP4tmb4+bnG2D3Ii911MO3NRZZ++HPB1yEhdlrajSMk2f3Y X-Received: by 2002:a17:90a:ca88:b0:27d:29f6:79e0 with SMTP id y8-20020a17090aca8800b0027d29f679e0mr1814849pjt.17.1697710968257; Thu, 19 Oct 2023 03:22:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697710968; cv=none; d=google.com; s=arc-20160816; b=LdiDf80LfeJDLyz/zVtmso3+gz2MBysm6J2VX9ps0uRmmVkKHhYoAElLm4FA+ZFyU1 YaV4x2ENbtH42o2aynrxLtcSOCFSxLHTMrgQLZZ+Uog4M1U57vQzK/iSOoxmKTrD0vLP LJ+LD6vXZo1FhVYt24oq/roj/BHR5CS+YUoOUM346NciQudJXVt/mo+Tl/zqUeZuGz81 887df0/3n5D9JTC0a+EgMFXM1IDgmb0G+eGo5OPTve7u81/69BUPWtrbAWBJvNQz2jRS zY9l2ivrb/Zve5lQBW0DC17tcyWVfLqtr35mclzFN4vg9DBIUY7kLHwLy81AJNYPN60q KzsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4uKY7SyBzCEHa/mCAAfoJnMtprpuvvdQNa+DDXCzvc0=; fh=HCMEMw2FL2V0bCNFcx/PoCA1BnbQ6avTXd1wakvTuwI=; b=zmKykQUpSLRRwYm9JRNATBNz45Wxi6h0GcBLPtg27OJJSkBuZv1jLUf1NcP7Imwjma LGM/M08nTIXGgz4JdoYidzHjf6pzJnyi3tdNwpfXaYlajXHWfhtbgUPZKajD5eIykJxt qTP+7wURKsHYUujDArv9fce23Eg/N9l+JkQpMtjyg4r0+SYA5WPt/ZL+KCfgtV1CpvQc NP1KmVaWn/if8xZSOXJhDgokiKB00hqXeYuX+6rDAHiRWjFH3CsXwl/UgGM7oZfxnHvD hAfQBO/hz5PEW3z3+q2JZjA+kNDQkj9HunniqC7zB1z3b3/Qh29Zuu+MilVj0m7kqq1V vgMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ViHqvtAL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e9-20020a17090a804900b0027d1a77c766si1776257pjw.118.2023.10.19.03.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 03:22:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ViHqvtAL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 55EF8822CC5C; Thu, 19 Oct 2023 03:22:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345249AbjJSKWm (ORCPT + 99 others); Thu, 19 Oct 2023 06:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345289AbjJSKWi (ORCPT ); Thu, 19 Oct 2023 06:22:38 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D121B6 for ; Thu, 19 Oct 2023 03:22:31 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57D37C433C8; Thu, 19 Oct 2023 10:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697710951; bh=PKYzCBBNs1O32oIawGxF3uIbDChRrVw3IJL0BEhOvoE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ViHqvtALFFnpctn8RsIfJYCIj7DwvYkiiPvlN/uF+gglBElEflYqwEqQ3X7tAExDP QKLfxK4bPnzDT+0CSgjrlzzfdvDACHwVd11/qVqK1NiuLziWaFeHRyVLe/5/GPgb5Y 8fupB0UMPif5QUQQ8ay7buIf26O0y3qg/8R94FOpufo9ONGnz292TuRcEdYDedjNIJ FJaFHwvMYb0aDWD5sVfqMZ55nXtcPdnCEgiSerN8h9RNNAahmACit6zfpS3Yaj0zE4 6UDZ3f90tPRKeDKoVmTj4Rit7xOezNsysbxkEw+fiMRL+ujI5kiz8EpKHv4I5YFT2K ivDxq4QT0oK4g== Date: Thu, 19 Oct 2023 11:22:26 +0100 From: Conor Dooley To: =?iso-8859-1?Q?Cl=E9ment_L=E9ger?= Cc: Evan Green , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Palmer Dabbelt , Paul Walmsley , Rob Herring , Krzysztof Kozlowski , Albert Ou , Jonathan Corbet , Andrew Jones , Samuel Ortiz Subject: Re: [PATCH v2 01/19] riscv: hwprobe: factorize hwprobe ISA extension reporting Message-ID: <20231019-flatten-showbiz-127b2e917a7a@spud> References: <20231017131456.2053396-1-cleger@rivosinc.com> <20231017131456.2053396-2-cleger@rivosinc.com> <20231018-scrap-bankable-a0f321d97a46@spud> <20231018-flagpole-footpad-07a6228485f3@spud> <844f6f35-3125-4014-852c-9ad7aee19ddc@rivosinc.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0kZSCNOwIdjxb8Tb" Content-Disposition: inline In-Reply-To: <844f6f35-3125-4014-852c-9ad7aee19ddc@rivosinc.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 19 Oct 2023 03:22:47 -0700 (PDT) --0kZSCNOwIdjxb8Tb Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 19, 2023 at 09:26:31AM +0200, Cl=C3=A9ment L=C3=A9ger wrote: >=20 >=20 > On 18/10/2023 19:36, Conor Dooley wrote: > > On Wed, Oct 18, 2023 at 06:33:34PM +0100, Conor Dooley wrote: > >> On Wed, Oct 18, 2023 at 10:24:15AM -0700, Evan Green wrote: > >>> On Tue, Oct 17, 2023 at 6:15=E2=80=AFAM Cl=C3=A9ment L=C3=A9ger wrote: > >>>> > >>>> Factorize ISA extension reporting by using a macro rather than > >>>> copy/pasting extension names. This will allow adding new extensions = more > >>>> easily. > >>>> > >>>> Signed-off-by: Cl=C3=A9ment L=C3=A9ger > >>>> --- > >>>> arch/riscv/kernel/sys_riscv.c | 32 ++++++++++++++++++-------------- > >>>> 1 file changed, 18 insertions(+), 14 deletions(-) > >>>> > >>>> diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_r= iscv.c > >>>> index 473159b5f303..e207874e686e 100644 > >>>> --- a/arch/riscv/kernel/sys_riscv.c > >>>> +++ b/arch/riscv/kernel/sys_riscv.c > >>>> @@ -145,20 +145,24 @@ static void hwprobe_isa_ext0(struct riscv_hwpr= obe *pair, > >>>> for_each_cpu(cpu, cpus) { > >>>> struct riscv_isainfo *isainfo =3D &hart_isa[cpu]; > >>>> > >>>> - if (riscv_isa_extension_available(isainfo->isa, ZBA)) > >>>> - pair->value |=3D RISCV_HWPROBE_EXT_ZBA; > >>>> - else > >>>> - missing |=3D RISCV_HWPROBE_EXT_ZBA; > >>>> - > >>>> - if (riscv_isa_extension_available(isainfo->isa, ZBB)) > >>>> - pair->value |=3D RISCV_HWPROBE_EXT_ZBB; > >>>> - else > >>>> - missing |=3D RISCV_HWPROBE_EXT_ZBB; > >>>> - > >>>> - if (riscv_isa_extension_available(isainfo->isa, ZBS)) > >>>> - pair->value |=3D RISCV_HWPROBE_EXT_ZBS; > >>>> - else > >>>> - missing |=3D RISCV_HWPROBE_EXT_ZBS; > >>>> +#define CHECK_ISA_EXT(__ext) = \ > >>>> + do { = \ > >>>> + if (riscv_isa_extension_available(isainfo->i= sa, __ext)) \ > >>>> + pair->value |=3D RISCV_HWPROBE_EXT_#= #__ext; \ > >>>> + else = \ > >>>> + missing |=3D RISCV_HWPROBE_EXT_##__e= xt; \ > >>>> + } while (false) > >>>> + > >>>> + /* > >>>> + * Only use CHECK_ISA_EXT() for extensions which can= be exposed > >>>> + * to userspace, regardless of the kernel's configur= ation, as no > >>>> + * other checks, besides presence in the hart_isa bi= tmap, are > >>>> + * made. > >>> > >>> This comment alludes to a dangerous trap, but I'm having trouble > >>> understanding what it is. > >> > >> You cannot, for example, use this for communicating the presence of F = or > >> D, since they require a config option to be set before their use is > >> safe. > >=20 > > Funnily enough, this comment is immediately contradicted by the vector > > subset extensions, where these CHECK_ISA_EXT() macros are used wrapped > > in has_vector(). The code looks valid to me, since has_vector() contains > > the Kconfig check, but does fly in the face of this comment. > Yes, the KConfig checks are already done by the headers, adding #ifdef > would be redundant even if more coherent with the comment I don't really understand what the first part of this means, or why using avoidable ifdeffery here would be desirable. > BTW, wouldn't > it make more sense to get rid out of the unsupported extensions directly > at ISA string parsing ? ie, if kernel is compiled without V support, > then do not set the bits corresponding to these in the riscv_isa_ext[] > array ? But the initial intent was probably to be able to report the > full string through cpuinfo. Yeah, hysterical raisins I guess, it's always been that way. I don't think anyone originally thought about such configurations and that is how the cpuinfo stuff behaves. I strongly dislike the riscv_isa_extension_available() interface, but one of Drew's patches does at least improve things a bit. Kinda waiting for some of the patches in flight to settle down before deciding if I want to refactor stuff to be less of a potential for shooting oneself in the foot. --0kZSCNOwIdjxb8Tb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZTEDYQAKCRB4tDGHoIJi 0hxoAP0Q/QwVBDGTktqXbnElnvW6qMUNCJQnZu8Yc7rQ7OMNJAEAkJ4ESLvJaOki BU3KxXVZ+61ZCescByygZiFqNKepPgM= =2KUA -----END PGP SIGNATURE----- --0kZSCNOwIdjxb8Tb--