Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2649791iob; Mon, 16 May 2022 03:07:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ6wBKw3F8b/1z0jE7vV2tnHB9IDNpiBsDMF2iwftLB09uRddbjKfWLbywNW+lOtacwqRl X-Received: by 2002:a17:906:19c6:b0:6ce:98a4:5ee6 with SMTP id h6-20020a17090619c600b006ce98a45ee6mr14583124ejd.567.1652695656877; Mon, 16 May 2022 03:07:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652695656; cv=none; d=google.com; s=arc-20160816; b=DRZCQg81SevyJ/QG6/4u78dn4jr11wdmr2yKeWqrXfT/yRSUe6FIAYbbFGnp8M9YLH fAxU0ryeJ2vqzZkDBRFUmGYsjt2+v9GoVkzRBc0HVX24PR7yOlHNmr1G6cpyfdU68K06 pKZiecSRFg+lhDUXUds9kRKh0G6tAFivAQ0FJPPUzF/VSU+gMaHkIaeXcnkNRNlFkPlJ +I9VK6rU7XskKQFNMEqxzP9v/3ipD3DG8NINQJ3CFk73PTGQtw/lP60sqyQKSOqOEKno Xc/fRA2xqRSAYk/dvP5YgQDp9isJwRrt7/4x8L8O4kazYkA7oEbdQLpfIOn2b/Z6rq7V yUOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=zVVOCTvJRX3Olou6oLL+JZw4cMsITWwHrp/zHjilPa0=; b=DtbusT38Pbh9evCEdgSrpq5AwBIz4B+Ek7C/m/wlfhMnYS+y3/GI+gOEoPPUMOFD+/ 8yNOlQhTSswH1TLGGXGbjAyxmA7fG90RO8VLUWRzYHYQKVb+uo6f0ZHIXtdEbZUw1IhC 2FaljuauGgPYS+h6+rLQLa+rmDLnudhmw242YnRGKw/e7q0Ec2YYJDRCJHRnqG1DX9nB dvZMN+NKXV1NAsYdG3y30W0BGlAzyzbbp8H/NhFUlBM8vl/cLW/N1XH1wpNv++a6vY/9 j3RpAJh27zAJjacOt657eq0CFN6zDwEtlugGGkPQbnCBqT/uL0c6Da4ap7wVt6tydmkZ 8x5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=C+eq1A7H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020a1709063ad000b006f35fd3ab4fsi8681468ejd.324.2022.05.16.03.07.11; Mon, 16 May 2022 03:07:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=C+eq1A7H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237266AbiEOOuG (ORCPT + 99 others); Sun, 15 May 2022 10:50:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237252AbiEOOt5 (ORCPT ); Sun, 15 May 2022 10:49:57 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E2A8186F9 for ; Sun, 15 May 2022 07:49:51 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id a5so13617099wrp.7 for ; Sun, 15 May 2022 07:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zVVOCTvJRX3Olou6oLL+JZw4cMsITWwHrp/zHjilPa0=; b=C+eq1A7HiHDaSo0p27ThkLSdQenQd4sfQWLvzP0ajbo/oIGxBN5Dqaz1SVvL3dcQg5 t1uahCp1gCZeu50g/nzqoHTK9vjJ/C0ZgQkiYK91Gz+8A77RE5kE24SdXAZBKZ8YfWmE GhtKVZoYXFFfnhdpOr3Q4FiqiiEJ+Hgxcjwv7iEiGvRwPr3Asj16nr+DD/v7VBgmWDJU FUekiYTa1EJCHbTByoXJh84MoSbXSRqwb8GZFr1qOFJXXbB7DWbuVIlt/EPOK2Qxmu2c IkMnzinehd0xbC62K3YmNbctekwEuM7AfuCWVF0c0bXJwPSwDbL+YliNlRdn/M0H/ggv 6GgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zVVOCTvJRX3Olou6oLL+JZw4cMsITWwHrp/zHjilPa0=; b=VZQEtdo9l7iLu91W6qjLEERJGjjdnaEVGwaoA9zhDDXDqRdafjFUQ3Gget9PJmnozG ScoMq9wRUbkVOJwxcXTeB1oTn2vQJlUU23ZNB3r1o0NNa53sHMCYtq3CHs0lgscyFHKT qSpinETDYXyUwFqurcdBzyWf7YrEBcl+09F2T+Dphs8yS9NvfzjAJjmc1X0JN2GNY85J KcQk8frzlRBfc9wjew7d7wV2D9OfqO+xZzrCIVSc5iw0hOqzUJfbFFWY1KU1GCLQIx88 cGN2xp9WUSzOsVjdln1iEUXbv4p69OANokih2xDmD+jCW7yiFMyALzkYXO4MhlYnGX9T WuYA== X-Gm-Message-State: AOAM5302nd8pOjssW09HvDpcER6RXi+xCPvZuKv2fJ9UghgQp8jOWPsR 9XQLfzk6wozf5Cx/nobpCaFPrMTs79xH/8wKL6HJYafrWSKS8w== X-Received: by 2002:adf:f001:0:b0:20d:22b:183c with SMTP id j1-20020adff001000000b0020d022b183cmr4176252wro.313.1652626190014; Sun, 15 May 2022 07:49:50 -0700 (PDT) MIME-Version: 1.0 References: <20220508160749.984-1-jszhang@kernel.org> <20220508160749.984-3-jszhang@kernel.org> In-Reply-To: From: Anup Patel Date: Sun, 15 May 2022 20:19:37 +0530 Message-ID: Subject: Re: [PATCH v2 2/4] riscv: introduce unified static key mechanism for CPU features To: Jisheng Zhang Cc: Atish Patra , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Alexandre Ghiti , linux-riscv , "linux-kernel@vger.kernel.org List" , kasan-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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 On Sun, May 15, 2022 at 12:54 PM Jisheng Zhang wrote: > > On Wed, May 11, 2022 at 11:29:32PM -0700, Atish Patra wrote: > > On Mon, May 9, 2022 at 7:50 AM Jisheng Zhang wrote: > > > > > > On Mon, May 09, 2022 at 09:17:10AM +0530, Anup Patel wrote: > > > > On Sun, May 8, 2022 at 9:47 PM Jisheng Zhang wrote: > > > > > > > > > > Currently, riscv has several features why may not be supported on all > > > > > riscv platforms, for example, FPU, SV48 and so on. To support unified > > > > > kernel Image style, we need to check whether the feature is suportted > > > > > or not. If the check sits at hot code path, then performance will be > > > > > impacted a lot. static key can be used to solve the issue. In the past > > > > > FPU support has been converted to use static key mechanism. I believe > > > > > we will have similar cases in the future. > > > > > > > > It's not just FPU and Sv48. There are several others such as Svinval, > > > > Vector, Svnapot, Svpbmt, and many many others. > > > > > > > > Overall, I agree with the approach of using static key array but I > > > > disagree with the semantics and the duplicate stuff being added. > > > > > > > > Please see more comments below .. > > > > > > > > > > > > > > Similar as arm64 does(in fact, some code is borrowed from arm64), this > > > > > patch tries to add an unified mechanism to use static keys for all > > > > > the cpu features by implementing an array of default-false static keys > > > > > and enabling them when detected. The cpus_have_*_cap() check uses the > > > > > static keys if riscv_const_caps_ready is finalized, otherwise the > > > > > compiler generates the bitmap test. > > > > > > > > First of all, we should stop calling this a feature (like ARM does). Rather, > > > > we should call these as isa extensions ("isaext") to align with the RISC-V > > > > priv spec and RISC-V profiles spec. For all the ISA optionalities which do > > > > not have distinct extension name, the RISC-V profiles spec is assigning > > > > names to all such optionalities. > > > > > > Same as the reply a few minutes ago, the key problem here is do all > > > CPU features belong to *ISA* extensions? For example, SV48, SV57 etc. > > > I agree with Atish's comments here: > > > > > > "I think the cpu feature is a superset of the ISA extension. > > > cpu feature != ISA extension" > > > > > > > It seems to be accurate at that point in time. However, the latest > > profile spec seems to > > define everything as an extension including sv48. > > > > https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#623-rva22s64-supported-optional-extensions > > > > It may be a redundant effort and confusing to create two sets i.e. > > feature and extension in this case. > > But this specification is not frozen yet and may change in the future. > > We at least know that that is the current intention. > > > > Array of static keys is definitely useful and should be used for all > > well defined ISA extensions by the ratified priv spec. > > This will simplify this patch as well. For any feature/extensions > > (i.e. sv48/sv57) which was never defined as an extension > > in the priv spec but profile seems to define it now, I would leave it > > alone for the time being. Converting the existing code > > to static key probably has value but please do not include it in the > > static key array setup. > > > > Once the profile spec is frozen, we can decide which direction the > > Linux kernel should go. > > > > Hi Atish, Anup, > > I see your points and thanks for the information of the profile > spec. Now, I have other two points about isa VS features: > > 1. Not all isa extenstions need static key mechanism, so if we > make a static key array with 1:1 riscv_isa <-> static key relationship > there may be waste. > > For example, the 'a', 'c', 'i', 'm' and so on don't have static > key usage. Not all isa extensions but a large number of them will need a static key. It's better to always have one static key per ISA extension defined in cpufeatures.c For example, F, D, V, Sstc, Svinval, Ssofpmt, Zb*, AIA, etc. > > 2.We may need riscv architecture static keys for non-isa, this is > usually related with the linux os itself, for example > a static key for "unmap kernelspace at userspace". > static keys for "spectre CVE mitigations" > etc. These things look more like errata or workarounds so better to use that framework instead of ISA extensions (or features). Some of these things might even use ALTERNATIVEs instead of static keys. > > In summary, I can see riscv_isa doesn't cover features which need static > keys, and vice vesa. > > Could you please comment? > > Thanks in advance, > Jisheng Regards, Anup