Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp312808rdb; Thu, 19 Oct 2023 05:31:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV5BPqcYQWmD2vQZiIQ3s1zNxyqo4gg9fcJMQkOVKV+msn5ZZ9NU3mMNxUBnEfcgjMHWPi X-Received: by 2002:a05:6a20:3951:b0:15d:8366:65be with SMTP id r17-20020a056a20395100b0015d836665bemr2625533pzg.9.1697718678400; Thu, 19 Oct 2023 05:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697718678; cv=none; d=google.com; s=arc-20160816; b=kVpzcL7E3Acup4X3aGYC5io4W5xu5JzaulxdYStFo0gOkgAoUSKFjppoWB2/LFCaLY IlJonDErrL3AZlBLEdB5iyjYm0t4lBruX2Fn1/+ZqZmioDDOEOgy8ipYql1Bmp5nK6Ev ZKAZiq8g264KxJyFq1BFb5rLv6chdiubwkXwvLKRwv6PDJY57sjm97Mu10bujVeYGkFB slKF0zLw3oFTXe7hjfCkqslnbvCggLVFpyOtGc8dHnXJ4nkJLnxnWYBrHxgEaQT/RKdV dkS0w9uMm72Ua8En52dNnrP4vem4ggbZQxcsSIVjP0uWdVFBn8KgGWsIR0g3MAItoTwh cpaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=nPQidXa+OYvo5Cuog4USzNI+/Xa6NAbmqLzTVYeaaGI=; fh=rTMv/gq7NVOhVsS/z+xrHArIxQoH/lEbzonRlwYCdko=; b=hlYwvueWizv8eLHHPpcvFcIZkVUgE/t1zQNMi0Bh92P5g+zXsmfOv0WDRBTxw12GZ3 aOn2keJgPJ5s5SvSb2GcvFgjXAC8Ot0cA28mKhlxkiKk7lO3DtfarKaD2LTEhr1LWXNH w8LY1wpT5WMR2wWJ0V5QY09Ya87GCX7XUlsZ9lD0cW9VqtFymLRTuP3q07C+k0zQTvEq nF8UIapbkgRw+zNpWNoJilQ+TRUa3jHwniF7uwO3JL77q76aNo16KzBLxeA5OeSIrZjp jQbsQtg8SqK0WXVPEno0kKEr0Aa+L+2VkBNDUU/xQUV7LaLvg7CyYjCOb7a9tkCjUF5q Ao4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hsm+NgS2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id c6-20020a633506000000b005ad8009e304si3460252pga.784.2023.10.19.05.31.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:31:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hsm+NgS2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 67AE180D5F80; Thu, 19 Oct 2023 05:31:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235364AbjJSMa3 (ORCPT + 99 others); Thu, 19 Oct 2023 08:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345691AbjJSMaE (ORCPT ); Thu, 19 Oct 2023 08:30:04 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08AF3189 for ; Thu, 19 Oct 2023 05:29:56 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-507a3af69d8so1894707e87.0 for ; Thu, 19 Oct 2023 05:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697718594; x=1698323394; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=nPQidXa+OYvo5Cuog4USzNI+/Xa6NAbmqLzTVYeaaGI=; b=hsm+NgS2yLAar//ppYO0VkxpBnkq8TSc6tnuRl7T6GUofmZPCnZjWTje/1bxR5XHlj ZkBHJJEDe8IPHMFhEugPVQPlBv3beRKtjpnU0qxTdGqAEPAN9zMTzOjzjbbCPqsTMDhr XbPwN1Z0S9n0DEG9ZWXdL6DMSn3a2bMQTNk6Md0tq/spBhcCe7DskF+L5z7HfgndNLEr VK0LmzRPemoIsd1FPPLE+xuIk2yGJ7ltS/5TGf7rJwqB3WEuzlRhD9QmbH7yg4WMiy8D aU29IQAbBEi7djprTVQAG4XOiJlgsYm3Nqh77kajAbHkA/xT2ujGrrIEsT6gQF6oDyvT PC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697718594; x=1698323394; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nPQidXa+OYvo5Cuog4USzNI+/Xa6NAbmqLzTVYeaaGI=; b=rFNLf7D1k2jLp5oLNhJ053Cc5lrl+3SheouODNMbZoBFJcib/mNz5E+Un1qg2M68xs EyqbmsdxF/0kIECWa1xNrTlt/+xDrEG1KlLu32vDX0cAnY62IdA1EDPj8wbCjEqsc7vo DwHFl2cozA43cyZcVOiL/Kr2Br4ZkL89IYJwv1ThxPq70MDx+fZ4m40zmzKlv/18EmZo H/4WxXkClhPaQJhmucFq84D8KssRogyVMmdWiYNmhAAXIMxKGS+8UG0BuWQB68VgvA13 coY8tOYlT4p0PnjX7JenWclgitMOtIc7qAcCh4wZ2cNjzbPP8parwvA8LSewKzFHg0oL rTSQ== X-Gm-Message-State: AOJu0YwE3vrhDAu+R9glOTr2LZ52lzPj8g1PmaBvIlqXzjLIWduos5T/ 90H4HkvVuaXy8KQm1Xz+pLapuw== X-Received: by 2002:a2e:870a:0:b0:2c5:6ab:b817 with SMTP id m10-20020a2e870a000000b002c506abb817mr1417727lji.5.1697718593993; Thu, 19 Oct 2023 05:29:53 -0700 (PDT) Received: from ?IPV6:2a01:e0a:999:a3a0:6933:1fe3:b858:3dde? ([2a01:e0a:999:a3a0:6933:1fe3:b858:3dde]) by smtp.gmail.com with ESMTPSA id l10-20020a1c790a000000b004063cced50bsm4266895wme.23.2023.10.19.05.29.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Oct 2023 05:29:53 -0700 (PDT) Message-ID: Date: Thu, 19 Oct 2023 14:29:52 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 01/19] riscv: hwprobe: factorize hwprobe ISA extension reporting To: Conor Dooley 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 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> <20231019-flatten-showbiz-127b2e917a7a@spud> Content-Language: en-US From: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= In-Reply-To: <20231019-flatten-showbiz-127b2e917a7a@spud> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:31:00 -0700 (PDT) On 19/10/2023 12:22, Conor Dooley wrote: > On Thu, Oct 19, 2023 at 09:26:31AM +0200, Clément Léger wrote: >> >> >> 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 AM Clément Léger 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ément Léger >>>>>> --- >>>>>> 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_riscv.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_hwprobe *pair, >>>>>> for_each_cpu(cpu, cpus) { >>>>>> struct riscv_isainfo *isainfo = &hart_isa[cpu]; >>>>>> >>>>>> - if (riscv_isa_extension_available(isainfo->isa, ZBA)) >>>>>> - pair->value |= RISCV_HWPROBE_EXT_ZBA; >>>>>> - else >>>>>> - missing |= RISCV_HWPROBE_EXT_ZBA; >>>>>> - >>>>>> - if (riscv_isa_extension_available(isainfo->isa, ZBB)) >>>>>> - pair->value |= RISCV_HWPROBE_EXT_ZBB; >>>>>> - else >>>>>> - missing |= RISCV_HWPROBE_EXT_ZBB; >>>>>> - >>>>>> - if (riscv_isa_extension_available(isainfo->isa, ZBS)) >>>>>> - pair->value |= RISCV_HWPROBE_EXT_ZBS; >>>>>> - else >>>>>> - missing |= RISCV_HWPROBE_EXT_ZBS; >>>>>> +#define CHECK_ISA_EXT(__ext) \ >>>>>> + do { \ >>>>>> + if (riscv_isa_extension_available(isainfo->isa, __ext)) \ >>>>>> + pair->value |= RISCV_HWPROBE_EXT_##__ext; \ >>>>>> + else \ >>>>>> + missing |= RISCV_HWPROBE_EXT_##__ext; \ >>>>>> + } while (false) >>>>>> + >>>>>> + /* >>>>>> + * Only use CHECK_ISA_EXT() for extensions which can be exposed >>>>>> + * to userspace, regardless of the kernel's configuration, as no >>>>>> + * other checks, besides presence in the hart_isa bitmap, 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. >>> >>> 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. Sorry, I was not clear enough. What I meant is that the has_fpu() and has_vector() functions are already ifdef'd in headers based on the KConfig options for their support (CONFIG_FPU/CONFIG_RISCV_ISA_V) So in the end, using ifdef here in hwprobe_isa_ext0() would be redundant. > >> 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. Make sense. Clément