Message ID | 20231017131456.2053396-6-cleger@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4126726vqb; Tue, 17 Oct 2023 06:16:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJoOghYcvTY1/HhsKyAaGapq05aimSwFU5X0r8gugpJ0DPucKFYtJC7ujMFsugv8DVEHd0 X-Received: by 2002:a05:6a00:2a41:b0:6bc:67ca:671d with SMTP id cf1-20020a056a002a4100b006bc67ca671dmr2116432pfb.1.1697548590139; Tue, 17 Oct 2023 06:16:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697548590; cv=none; d=google.com; s=arc-20160816; b=joqAeRWZFXvzM9ZvDxymOoPWe4ai9ZE/28lv/KDaC04QmOs5vEF/qKzHZsNzUNtoUU N7JmQx/wuN43ZP3ns6YeRE5K3TN7vUyc82rzggfDrQds1yi0LHT3sAyWTJawoOYjC0ux J1MyJAixNd8UDLQxgyOcUHjRPevEbJa3Vdv2cp/A7Qabk8XQSfdcARcC3FwC6YXBEacW a8r9P1ue3wcUl2iTWyQdQceIAf3jKI0Fufkb0f3FURBDGF6up6GTIHxUJKLNw8ZHbyXy ld6DGrh9MRHXWm+MgovsZlEyXqbBb2iR4y1WludTmnLdvSlRlmY+hLfMyUT8WiDMrlJC xIQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kAwzEIcm8h808xpQc++6VSntDVwJ3qhe3e6hBMESJ6w=; fh=lvGFqwUxN+Dx1jonz8cRGrvjuKDcjMXylffmtrJGOYA=; b=dDE5mIuJcd5tc2zdcf+xGeR9SJ50Nc0CylfABJ9quua2AQOlBmT6b8L5rFkQ9DN/Pw ZjYyoUCFM57olsgL/aZTHOUMn+U9JmXwAto29Q1/zKPQPbkuKPx3fTw97jIkS2Q19A8z CoWU2wVmSU4eAuvgOeaoH3zZWV/hl9TbnJoigpMFhOdxwUt1cqLe+1pcf0T3fWEeWzTn lGEqwLB3cu+Oha5murn8Vk7isdwOtWiis4G3Ota1AqE+dyMkCY4VhWfg3SGug3NX+NLe oIk6iXtWyQcPH/Awn5WMKVg0PDCxK3TwTxrT1PfQ53z6wINy9uaaUsAqbCHtGlP+k1SU rvIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=3OAPtVaP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id x13-20020aa79a4d000000b006bd92721f4esi1596517pfj.293.2023.10.17.06.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 06:16:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=3OAPtVaP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 653B68033DEA; Tue, 17 Oct 2023 06:16:26 -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 S234970AbjJQNPx (ORCPT <rfc822;hjfbswb@gmail.com> + 19 others); Tue, 17 Oct 2023 09:15:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343611AbjJQNPf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 17 Oct 2023 09:15:35 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0588ED for <linux-kernel@vger.kernel.org>; Tue, 17 Oct 2023 06:15:33 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2c519eab81fso3998031fa.1 for <linux-kernel@vger.kernel.org>; Tue, 17 Oct 2023 06:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697548532; x=1698153332; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kAwzEIcm8h808xpQc++6VSntDVwJ3qhe3e6hBMESJ6w=; b=3OAPtVaPDwxeYj2/Vaywhdl5nKRxznfJRIMCbal1tcUXD3yvxyYlj/8HrBcuwQuPMs K5/kVwRimwnr2xeEAeaz0d4P1p6FfwQFxEB1CzyytWhk63vAJtT/PErQPEXeLNV3c7tk RR604JV1bZ3AfuG/nqlLEgxqrks6ZqnKmoL4h4BFWiLc2vkL4bFBZUXR6CZ834OhTFrh OQt6FsHTiPujAxsxgDv1SiPHth60PUP0QKRVjUi2RLL6rkIJDHtqBPX4Yd9IXff2slaI OlUu37Bpkayp0cu33WtEt6DSK0aydC+gH3lcKaeGnWRCb8Aen07wIMQVMfAeUFQcldcz RakA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697548532; x=1698153332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kAwzEIcm8h808xpQc++6VSntDVwJ3qhe3e6hBMESJ6w=; b=MkVG8OgowPk07BCVJvNNR/WHG+rqkAzofcFqSNceIe29OEdPEzdVLEPDezgef4FYY0 p7AUZb7oWSWL0Mpo2vPpABkCFcvc0RqKLPHFk2n11+EbEAGZHiIhrX3qMOdPBVuN1/jY 1aqiuZTOvnv63UTvg+eRtvsww2i2nVerlisFTqBeCsr+/N4kAA19tdUPiGz1FlFRGw18 r6pWII9OkOyedt3Zrzv5YB00ODErqOtwvxKn4fiPseSrlBP3w2yYxm3r7sVe6FBL/M5h OclgDZoHYydSX5aTbqU9KkxinUakzFX8/PJcNCBlIFeMmG0mZDfUC9of8ZuZEbBoyYlL YVYw== X-Gm-Message-State: AOJu0YxevR+iibNhAgfB1zg0V5CczpnlO436lvnHuMWvM7oIrB0fYEUC SGdnv14Hel+P734laBgpvuaZAw== X-Received: by 2002:a2e:b5ad:0:b0:2c5:36e:31bf with SMTP id f13-20020a2eb5ad000000b002c5036e31bfmr1328347ljn.5.1697548531317; Tue, 17 Oct 2023 06:15:31 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:96:820c:ecf7:a817]) by smtp.gmail.com with ESMTPSA id fj7-20020a05600c0c8700b0040772138bb7sm9873393wmb.2.2023.10.17.06.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 06:15:30 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= <cleger@rivosinc.com> To: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= <cleger@rivosinc.com>, Palmer Dabbelt <palmer@rivosinc.com>, Paul Walmsley <paul.walmsley@sifive.com>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Albert Ou <aou@eecs.berkeley.edu>, Jonathan Corbet <corbet@lwn.net>, Andrew Jones <ajones@ventanamicro.com>, Evan Green <evan@rivosinc.com>, Conor Dooley <conor@kernel.org>, Samuel Ortiz <sameo@rivosinc.com> Subject: [PATCH v2 05/19] riscv: add ISA extension parsing for vector crypto extensions Date: Tue, 17 Oct 2023 15:14:42 +0200 Message-ID: <20231017131456.2053396-6-cleger@rivosinc.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017131456.2053396-1-cleger@rivosinc.com> References: <20231017131456.2053396-1-cleger@rivosinc.com> MIME-Version: 1.0 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: <linux-kernel.vger.kernel.org> 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]); Tue, 17 Oct 2023 06:16:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780008710662242818 X-GMAIL-MSGID: 1780008710662242818 |
Series |
riscv: report more ISA extensions through hwprobe
|
|
Commit Message
Clément Léger
Oct. 17, 2023, 1:14 p.m. UTC
Add parsing of some Zv* vector crypto ISA extensions that are mentioned
in "RISC-V Cryptography Extensions Volume II" [1]. These ISA extensions
are the following:
- Zvbb: Vector Basic Bit-manipulation
- Zvbc: Vector Carryless Multiplication
- Zvkb: Vector Cryptography Bit-manipulation
- Zvkg: Vector GCM/GMAC.
- Zvkned: NIST Suite: Vector AES Block Cipher
- Zvknh[ab]: NIST Suite: Vector SHA-2 Secure Hash
- Zvksed: ShangMi Suite: SM4 Block Cipher
- Zvksh: ShangMi Suite: SM3 Secure Hash
- Zvkn: NIST Algorithm Suite
- Zvknc: NIST Algorithm Suite with carryless multiply
- Zvkng: NIST Algorithm Suite with GCM.
- Zvks: ShangMi Algorithm Suite
- Zvksc: ShangMi Algorithm Suite with carryless multiplication
- Zvksg: ShangMi Algorithm Suite with GCM.
- Zvkt: Vector Data-Independent Execution Latency.
Link: https://drive.google.com/file/d/1gb9OLH-DhbCgWp7VwpPOVrrY6f3oSJLL/view [1]
Signed-off-by: Clément Léger <cleger@rivosinc.com>
---
arch/riscv/include/asm/hwcap.h | 10 ++++++
arch/riscv/kernel/cpufeature.c | 56 ++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
Comments
On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: > @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { > __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), > __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), > __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), > + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), > + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), > + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVKB), + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), or + __RISCV_ISA_EXT_BUNDLE(zvbb, riscv_zvbb_bundled_exts), + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), [1] https://github.com/riscv/riscv-crypto/blob/main/doc/vector/riscv-crypto-vector-zvkb.adoc -Jerry
On 18/10/2023 03:45, Jerry Shih wrote: > On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: >> @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { >> __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), >> __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), >> __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), >> + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), >> + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), >> + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), > > The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. Hi Jerry, Thanks for catching this, I think some other extensions will fall in this category as well then (Zvknha/Zvknhb). I will verify that. Clément > > + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), > + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVKB), > + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), > > or > > + __RISCV_ISA_EXT_BUNDLE(zvbb, riscv_zvbb_bundled_exts), > + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), > > [1] > https://github.com/riscv/riscv-crypto/blob/main/doc/vector/riscv-crypto-vector-zvkb.adoc > > -Jerry
On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: > > > > On 18/10/2023 03:45, Jerry Shih wrote: > > On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: > >> @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { > >> __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), > >> __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), > >> __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), > >> + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), > >> + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), > >> + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), > > > > The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. > > Hi Jerry, > > Thanks for catching this, I think some other extensions will fall in > this category as well then (Zvknha/Zvknhb). I will verify that. The bundling mechanism works well when an extension is a pure lasso around other extensions. We'd have to tweak that code if we wanted to support cases like this, where the extension is a superset of others, but also contains loose change not present anywhere else (and therefore also needs to stand as a separate bit). IMO, decomposing "pure" bundles makes sense since otherwise usermode would have to query multiple distinct bitmaps that meant the same thing (eg check the Zk bit, or maybe check the Zkn/Zkr/Zkt bits, or maybe check the Zbkb/Zbkc... bits, and they're all equivalent). But when an extension is a superset that also contains loose change, there really aren't two equivalent bitmasks, each bit adds something new. There's an argument to be made for still turning on the containing extensions to cover for silly ISA strings (eg ISA strings that advertise the superset but fail to advertise the containing extensions). We can decide if we want to work that hard to cover hypothetical broken ISA strings now, or wait until they show up. Personally I would wait until something broken shows up. But others may feel differently. -Evan
On 18/10/2023 19:26, Evan Green wrote: > On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: >> >> >> >> On 18/10/2023 03:45, Jerry Shih wrote: >>> On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: >>>> @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { >>>> __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), >>>> __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), >>>> __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), >>>> + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), >>>> + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), >>>> + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), >>> >>> The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. >> >> Hi Jerry, >> >> Thanks for catching this, I think some other extensions will fall in >> this category as well then (Zvknha/Zvknhb). I will verify that. > > The bundling mechanism works well when an extension is a pure lasso > around other extensions. We'd have to tweak that code if we wanted to > support cases like this, where the extension is a superset of others, > but also contains loose change not present anywhere else (and > therefore also needs to stand as a separate bit). For Zvbb and Zvknhb, I used the following code: static const unsigned int riscv_zvbb_bundled_exts[] = { RISCV_ISA_EXT_ZVKB, RISCV_ISA_EXT_ZVBB }; static const unsigned int riscv_zvknhb_bundled_exts[] = { RISCV_ISA_EXT_ZVKNHA, RISCV_ISA_EXT_ZVKNHB }; Which correctly results in both extension (superset + base set) being enabled when only one is set. Is there something that I'm missing ? > > IMO, decomposing "pure" bundles makes sense since otherwise usermode > would have to query multiple distinct bitmaps that meant the same > thing (eg check the Zk bit, or maybe check the Zkn/Zkr/Zkt bits, or > maybe check the Zbkb/Zbkc... bits, and they're all equivalent). But > when an extension is a superset that also contains loose change, there > really aren't two equivalent bitmasks, each bit adds something new. Agreed but if a system only report ZVBB for instance and the user wants ZVKB, then it is clear that ZVKB should be reported as well I guess. So in the end, it works much like "bundle" extension, just that the bundle is actually a "real" ISA extension by itself. Clément > > There's an argument to be made for still turning on the containing > extensions to cover for silly ISA strings (eg ISA strings that > advertise the superset but fail to advertise the containing > extensions). We can decide if we want to work that hard to cover > hypothetical broken ISA strings now, or wait until they show up. > Personally I would wait until something broken shows up. But others > may feel differently. > > -Evan
On Thu, Oct 19, 2023 at 11:35:59AM +0200, Clément Léger wrote: > > > On 18/10/2023 19:26, Evan Green wrote: > > On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: > >> > >> > >> > >> On 18/10/2023 03:45, Jerry Shih wrote: > >>> On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: > >>>> @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { > >>>> __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), > >>>> __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), > >>>> __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), > >>>> + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), > >>>> + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), > >>>> + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), > >>> > >>> The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. > >> > >> Hi Jerry, > >> > >> Thanks for catching this, I think some other extensions will fall in > >> this category as well then (Zvknha/Zvknhb). I will verify that. > > > > The bundling mechanism works well when an extension is a pure lasso > > around other extensions. We'd have to tweak that code if we wanted to > > support cases like this, where the extension is a superset of others, > > but also contains loose change not present anywhere else (and > > therefore also needs to stand as a separate bit). > > For Zvbb and Zvknhb, I used the following code: > > static const unsigned int riscv_zvbb_bundled_exts[] = { > RISCV_ISA_EXT_ZVKB, > RISCV_ISA_EXT_ZVBB > }; > > static const unsigned int riscv_zvknhb_bundled_exts[] = { > RISCV_ISA_EXT_ZVKNHA, > RISCV_ISA_EXT_ZVKNHB > }; > > Which correctly results in both extension (superset + base set) being > enabled when only one is set. Is there something that I'm missing ? > > > > > IMO, decomposing "pure" bundles makes sense since otherwise usermode > > would have to query multiple distinct bitmaps that meant the same > > thing (eg check the Zk bit, or maybe check the Zkn/Zkr/Zkt bits, or > > maybe check the Zbkb/Zbkc... bits, and they're all equivalent). But > > when an extension is a superset that also contains loose change, there > > really aren't two equivalent bitmasks, each bit adds something new. > > Agreed but if a system only report ZVBB for instance and the user wants > ZVKB, then it is clear that ZVKB should be reported as well I guess. So > in the end, it works much like "bundle" extension, just that the bundle > is actually a "real" ISA extension by itself. > > Clément > > > > > There's an argument to be made for still turning on the containing > > extensions to cover for silly ISA strings (eg ISA strings that > > advertise the superset but fail to advertise the containing > > extensions). We can decide if we want to work that hard to cover > > hypothetical broken ISA strings now, or wait until they show up. > > Personally I would wait until something broken shows up. But others > > may feel differently. I'm not really sure that those are "silly" ISA strings. People are going to do it that way because it is much easier than spelling out 5 dozen sub-components, and it is pretty inevitable that subsets will be introduced in the future for extensions we currently have. IMO, it's perfectly valid to say you have the supersets and not spell out all the subcomponents.
On Thu, Oct 19, 2023 at 8:33 AM Conor Dooley <conor@kernel.org> wrote: > > On Thu, Oct 19, 2023 at 11:35:59AM +0200, Clément Léger wrote: > > > > > > On 18/10/2023 19:26, Evan Green wrote: > > > On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: > > >> > > >> > > >> > > >> On 18/10/2023 03:45, Jerry Shih wrote: > > >>> On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: > > >>>> @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { > > >>>> __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), > > >>>> __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), > > >>>> __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), > > >>>> + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), > > >>>> + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), > > >>>> + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), > > >>> > > >>> The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. > > >> > > >> Hi Jerry, > > >> > > >> Thanks for catching this, I think some other extensions will fall in > > >> this category as well then (Zvknha/Zvknhb). I will verify that. > > > > > > The bundling mechanism works well when an extension is a pure lasso > > > around other extensions. We'd have to tweak that code if we wanted to > > > support cases like this, where the extension is a superset of others, > > > but also contains loose change not present anywhere else (and > > > therefore also needs to stand as a separate bit). > > > > For Zvbb and Zvknhb, I used the following code: > > > > static const unsigned int riscv_zvbb_bundled_exts[] = { > > RISCV_ISA_EXT_ZVKB, > > RISCV_ISA_EXT_ZVBB > > }; > > > > static const unsigned int riscv_zvknhb_bundled_exts[] = { > > RISCV_ISA_EXT_ZVKNHA, > > RISCV_ISA_EXT_ZVKNHB > > }; > > > > Which correctly results in both extension (superset + base set) being > > enabled when only one is set. Is there something that I'm missing ? > > > > > > > > IMO, decomposing "pure" bundles makes sense since otherwise usermode > > > would have to query multiple distinct bitmaps that meant the same > > > thing (eg check the Zk bit, or maybe check the Zkn/Zkr/Zkt bits, or > > > maybe check the Zbkb/Zbkc... bits, and they're all equivalent). But > > > when an extension is a superset that also contains loose change, there > > > really aren't two equivalent bitmasks, each bit adds something new. > > > > Agreed but if a system only report ZVBB for instance and the user wants > > ZVKB, then it is clear that ZVKB should be reported as well I guess. So > > in the end, it works much like "bundle" extension, just that the bundle > > is actually a "real" ISA extension by itself. > > > > Clément > > > > > > > > There's an argument to be made for still turning on the containing > > > extensions to cover for silly ISA strings (eg ISA strings that > > > advertise the superset but fail to advertise the containing > > > extensions). We can decide if we want to work that hard to cover > > > hypothetical broken ISA strings now, or wait until they show up. > > > Personally I would wait until something broken shows up. But others > > > may feel differently. > > I'm not really sure that those are "silly" ISA strings. People are going > to do it that way because it is much easier than spelling out 5 dozen > sub-components, and it is pretty inevitable that subsets will be > introduced in the future for extensions we currently have. > > IMO, it's perfectly valid to say you have the supersets and not spell > out all the subcomponents. Hm, ok. If ISA strings are likely to be written that way, then I agree having the kernel flip on all the contained extensions is a good idea. We can tweak patch 2 to support the parsing of struct riscv_isa_ext_data with both .id and .bundle_size set (instead of only one or the other as it is now). Looking back at that patch, it looks quite doable. Alright! -Evan
On Oct 19, 2023, at 17:35, Clément Léger <cleger@rivosinc.com> wrote: > On 18/10/2023 19:26, Evan Green wrote: >> On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: >>> >>> On 18/10/2023 03:45, Jerry Shih wrote: >>>> >>>> The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. >>> >>> Hi Jerry, >>> >>> Thanks for catching this, I think some other extensions will fall in >>> this category as well then (Zvknha/Zvknhb). I will verify that. >> >> The bundling mechanism works well when an extension is a pure lasso >> around other extensions. We'd have to tweak that code if we wanted to >> support cases like this, where the extension is a superset of others, >> but also contains loose change not present anywhere else (and >> therefore also needs to stand as a separate bit). > > For Zvbb and Zvknhb, I used the following code: > > static const unsigned int riscv_zvbb_bundled_exts[] = { > RISCV_ISA_EXT_ZVKB, > RISCV_ISA_EXT_ZVBB > }; > > static const unsigned int riscv_zvknhb_bundled_exts[] = { > RISCV_ISA_EXT_ZVKNHA, > RISCV_ISA_EXT_ZVKNHB > }; > > Which correctly results in both extension (superset + base set) being > enabled when only one is set. Is there something that I'm missing ? We should not bundle zvknha and zvknhb together. They are exclusive. Please check: https://github.com/riscv/riscv-crypto/issues/364#issuecomment-1726782096 -Jerry
On 20/10/2023 04:43, Jerry Shih wrote: > On Oct 19, 2023, at 17:35, Clément Léger <cleger@rivosinc.com> wrote: >> On 18/10/2023 19:26, Evan Green wrote: >>> On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: >>>> >>>> On 18/10/2023 03:45, Jerry Shih wrote: >>>>> >>>>> The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. >>>> >>>> Hi Jerry, >>>> >>>> Thanks for catching this, I think some other extensions will fall in >>>> this category as well then (Zvknha/Zvknhb). I will verify that. >>> >>> The bundling mechanism works well when an extension is a pure lasso >>> around other extensions. We'd have to tweak that code if we wanted to >>> support cases like this, where the extension is a superset of others, >>> but also contains loose change not present anywhere else (and >>> therefore also needs to stand as a separate bit). >> >> For Zvbb and Zvknhb, I used the following code: >> >> static const unsigned int riscv_zvbb_bundled_exts[] = { >> RISCV_ISA_EXT_ZVKB, >> RISCV_ISA_EXT_ZVBB >> }; >> >> static const unsigned int riscv_zvknhb_bundled_exts[] = { >> RISCV_ISA_EXT_ZVKNHA, >> RISCV_ISA_EXT_ZVKNHB >> }; >> >> Which correctly results in both extension (superset + base set) being >> enabled when only one is set. Is there something that I'm missing ? > > We should not bundle zvknha and zvknhb together. They are exclusive. Yes, but for instance, what happens if the user query the zvknha (if it only needs SHA256) but zvknhb is present. If we don't declare zvknha, then it will fail but the support would actually be present due to zvknhb being there. Clément > Please check: > https://github.com/riscv/riscv-crypto/issues/364#issuecomment-1726782096 > > -Jerry >
On 19/10/2023 18:19, Evan Green wrote: > On Thu, Oct 19, 2023 at 8:33 AM Conor Dooley <conor@kernel.org> wrote: >> >> On Thu, Oct 19, 2023 at 11:35:59AM +0200, Clément Léger wrote: >>> >>> >>> On 18/10/2023 19:26, Evan Green wrote: >>>> On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: >>>>> >>>>> >>>>> >>>>> On 18/10/2023 03:45, Jerry Shih wrote: >>>>>> On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: >>>>>>> @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { >>>>>>> __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), >>>>>>> __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), >>>>>>> __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), >>>>>>> + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), >>>>>>> + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), >>>>>>> + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), >>>>>> >>>>>> The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. >>>>> >>>>> Hi Jerry, >>>>> >>>>> Thanks for catching this, I think some other extensions will fall in >>>>> this category as well then (Zvknha/Zvknhb). I will verify that. >>>> >>>> The bundling mechanism works well when an extension is a pure lasso >>>> around other extensions. We'd have to tweak that code if we wanted to >>>> support cases like this, where the extension is a superset of others, >>>> but also contains loose change not present anywhere else (and >>>> therefore also needs to stand as a separate bit). >>> >>> For Zvbb and Zvknhb, I used the following code: >>> >>> static const unsigned int riscv_zvbb_bundled_exts[] = { >>> RISCV_ISA_EXT_ZVKB, >>> RISCV_ISA_EXT_ZVBB >>> }; >>> >>> static const unsigned int riscv_zvknhb_bundled_exts[] = { >>> RISCV_ISA_EXT_ZVKNHA, >>> RISCV_ISA_EXT_ZVKNHB >>> }; >>> >>> Which correctly results in both extension (superset + base set) being >>> enabled when only one is set. Is there something that I'm missing ? >>> >>>> >>>> IMO, decomposing "pure" bundles makes sense since otherwise usermode >>>> would have to query multiple distinct bitmaps that meant the same >>>> thing (eg check the Zk bit, or maybe check the Zkn/Zkr/Zkt bits, or >>>> maybe check the Zbkb/Zbkc... bits, and they're all equivalent). But >>>> when an extension is a superset that also contains loose change, there >>>> really aren't two equivalent bitmasks, each bit adds something new. >>> >>> Agreed but if a system only report ZVBB for instance and the user wants >>> ZVKB, then it is clear that ZVKB should be reported as well I guess. So >>> in the end, it works much like "bundle" extension, just that the bundle >>> is actually a "real" ISA extension by itself. >>> >>> Clément >>> >>>> >>>> There's an argument to be made for still turning on the containing >>>> extensions to cover for silly ISA strings (eg ISA strings that >>>> advertise the superset but fail to advertise the containing >>>> extensions). We can decide if we want to work that hard to cover >>>> hypothetical broken ISA strings now, or wait until they show up. >>>> Personally I would wait until something broken shows up. But others >>>> may feel differently. >> >> I'm not really sure that those are "silly" ISA strings. People are going >> to do it that way because it is much easier than spelling out 5 dozen >> sub-components, and it is pretty inevitable that subsets will be >> introduced in the future for extensions we currently have. >> >> IMO, it's perfectly valid to say you have the supersets and not spell >> out all the subcomponents. > > Hm, ok. If ISA strings are likely to be written that way, then I agree > having the kernel flip on all the contained extensions is a good idea. > We can tweak patch 2 to support the parsing of struct > riscv_isa_ext_data with both .id and .bundle_size set (instead of only > one or the other as it is now). Looking back at that patch, it looks > quite doable. Alright! Hey Evan, do you have anything against using this code: static const unsigned int riscv_zvbb_bundled_exts[] = { RISCV_ISA_EXT_ZVKB, RISCV_ISA_EXT_ZVBB }; ... Then declaring zvbb like that: __RISCV_ISA_EXT_BUNDLE(zvbb, riscv_zvbb_bundled_exts), I agree that it is *not* a bundled extension but it actually already works with Conor's code. Not sure that adding more code is needed to handle that case. Clément > > -Evan
On Mon, Oct 23, 2023 at 12:24 AM Clément Léger <cleger@rivosinc.com> wrote: > > > > On 19/10/2023 18:19, Evan Green wrote: > > On Thu, Oct 19, 2023 at 8:33 AM Conor Dooley <conor@kernel.org> wrote: > >> > >> On Thu, Oct 19, 2023 at 11:35:59AM +0200, Clément Léger wrote: > >>> > >>> > >>> On 18/10/2023 19:26, Evan Green wrote: > >>>> On Wed, Oct 18, 2023 at 5:53 AM Clément Léger <cleger@rivosinc.com> wrote: > >>>>> > >>>>> > >>>>> > >>>>> On 18/10/2023 03:45, Jerry Shih wrote: > >>>>>> On Oct 17, 2023, at 21:14, Clément Léger <cleger@rivosinc.com> wrote: > >>>>>>> @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { > >>>>>>> __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), > >>>>>>> __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), > >>>>>>> __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), > >>>>>>> + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), > >>>>>>> + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), > >>>>>>> + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), > >>>>>> > >>>>>> The `Zvkb` is the subset of `Zvbb`[1]. So, the `Zvkb` should be bundled with `Zvbb`. > >>>>> > >>>>> Hi Jerry, > >>>>> > >>>>> Thanks for catching this, I think some other extensions will fall in > >>>>> this category as well then (Zvknha/Zvknhb). I will verify that. > >>>> > >>>> The bundling mechanism works well when an extension is a pure lasso > >>>> around other extensions. We'd have to tweak that code if we wanted to > >>>> support cases like this, where the extension is a superset of others, > >>>> but also contains loose change not present anywhere else (and > >>>> therefore also needs to stand as a separate bit). > >>> > >>> For Zvbb and Zvknhb, I used the following code: > >>> > >>> static const unsigned int riscv_zvbb_bundled_exts[] = { > >>> RISCV_ISA_EXT_ZVKB, > >>> RISCV_ISA_EXT_ZVBB > >>> }; > >>> > >>> static const unsigned int riscv_zvknhb_bundled_exts[] = { > >>> RISCV_ISA_EXT_ZVKNHA, > >>> RISCV_ISA_EXT_ZVKNHB > >>> }; > >>> > >>> Which correctly results in both extension (superset + base set) being > >>> enabled when only one is set. Is there something that I'm missing ? > >>> > >>>> > >>>> IMO, decomposing "pure" bundles makes sense since otherwise usermode > >>>> would have to query multiple distinct bitmaps that meant the same > >>>> thing (eg check the Zk bit, or maybe check the Zkn/Zkr/Zkt bits, or > >>>> maybe check the Zbkb/Zbkc... bits, and they're all equivalent). But > >>>> when an extension is a superset that also contains loose change, there > >>>> really aren't two equivalent bitmasks, each bit adds something new. > >>> > >>> Agreed but if a system only report ZVBB for instance and the user wants > >>> ZVKB, then it is clear that ZVKB should be reported as well I guess. So > >>> in the end, it works much like "bundle" extension, just that the bundle > >>> is actually a "real" ISA extension by itself. > >>> > >>> Clément > >>> > >>>> > >>>> There's an argument to be made for still turning on the containing > >>>> extensions to cover for silly ISA strings (eg ISA strings that > >>>> advertise the superset but fail to advertise the containing > >>>> extensions). We can decide if we want to work that hard to cover > >>>> hypothetical broken ISA strings now, or wait until they show up. > >>>> Personally I would wait until something broken shows up. But others > >>>> may feel differently. > >> > >> I'm not really sure that those are "silly" ISA strings. People are going > >> to do it that way because it is much easier than spelling out 5 dozen > >> sub-components, and it is pretty inevitable that subsets will be > >> introduced in the future for extensions we currently have. > >> > >> IMO, it's perfectly valid to say you have the supersets and not spell > >> out all the subcomponents. > > > > Hm, ok. If ISA strings are likely to be written that way, then I agree > > having the kernel flip on all the contained extensions is a good idea. > > We can tweak patch 2 to support the parsing of struct > > riscv_isa_ext_data with both .id and .bundle_size set (instead of only > > one or the other as it is now). Looking back at that patch, it looks > > quite doable. Alright! > > Hey Evan, > > do you have anything against using this code: > > static const unsigned int riscv_zvbb_bundled_exts[] = { > RISCV_ISA_EXT_ZVKB, > RISCV_ISA_EXT_ZVBB > }; > > ... > > Then declaring zvbb like that: > > __RISCV_ISA_EXT_BUNDLE(zvbb, riscv_zvbb_bundled_exts), > > I agree that it is *not* a bundled extension but it actually already > works with Conor's code. Not sure that adding more code is needed to > handle that case. Ah, I had missed that Zvbb was in Zvbb's own bundle. I see now that it works, but it also feels a bit like we're working around our own code. An alternate way, which you can decide if you like better, would be a new macro (something like __RISCV_ISA_EXT_DATA_BUNDLE(), but better names welcome) that allows setting both .id and .bundle_size. Then the else-if in match_isa_ext() could just turn into two independent ifs. You'd have to define an "invalid" value for .id, since 0 is 'a', but that should be straightforward. Or maybe jiggle things around a bit so 0 is invalid and 'a' is 1. -Evan
diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index ab80d822c847..a2fac23b0cc0 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -69,6 +69,16 @@ #define RISCV_ISA_EXT_ZKSED 51 #define RISCV_ISA_EXT_ZKSH 52 #define RISCV_ISA_EXT_ZKT 53 +#define RISCV_ISA_EXT_ZVBB 54 +#define RISCV_ISA_EXT_ZVBC 55 +#define RISCV_ISA_EXT_ZVKB 56 +#define RISCV_ISA_EXT_ZVKG 57 +#define RISCV_ISA_EXT_ZVKNED 58 +#define RISCV_ISA_EXT_ZVKNHA 59 +#define RISCV_ISA_EXT_ZVKNHB 60 +#define RISCV_ISA_EXT_ZVKSED 61 +#define RISCV_ISA_EXT_ZVKSH 62 +#define RISCV_ISA_EXT_ZVKT 63 #define RISCV_ISA_EXT_MAX 64 diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index d3682fdfd9f1..8cf0b8b442ae 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -144,6 +144,46 @@ static const unsigned int riscv_zks_bundled_exts[] = { RISCV_ISA_EXT_ZKSH }; +#define RISCV_ISA_EXT_ZVKN \ + RISCV_ISA_EXT_ZVKNED, \ + RISCV_ISA_EXT_ZVKNHB, \ + RISCV_ISA_EXT_ZVKB, \ + RISCV_ISA_EXT_ZVKT + +static const unsigned int riscv_zvkn_bundled_exts[] = { + RISCV_ISA_EXT_ZVKN +}; + +static const unsigned int riscv_zvknc_bundled_exts[] = { + RISCV_ISA_EXT_ZVKN, + RISCV_ISA_EXT_ZVBC, +}; + +static const unsigned int riscv_zvkng_bundled_exts[] = { + RISCV_ISA_EXT_ZVKN, + RISCV_ISA_EXT_ZVKG, +}; + +#define RISCV_ISA_EXT_ZVKS \ + RISCV_ISA_EXT_ZVKSED, \ + RISCV_ISA_EXT_ZVKSH, \ + RISCV_ISA_EXT_ZVKB, \ + RISCV_ISA_EXT_ZVKT + +static const unsigned int riscv_zvks_bundled_exts[] = { + RISCV_ISA_EXT_ZVKS +}; + +static const unsigned int riscv_zvksc_bundled_exts[] = { + RISCV_ISA_EXT_ZVKS, + RISCV_ISA_EXT_ZVBC, +}; + +static const unsigned int riscv_zvksg_bundled_exts[] = { + RISCV_ISA_EXT_ZVKS, + RISCV_ISA_EXT_ZVKG, +}; + /* * The canonical order of ISA extension names in the ISA string is defined in * chapter 27 of the unprivileged specification. @@ -221,6 +261,22 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), + __RISCV_ISA_EXT_DATA(zvbb, RISCV_ISA_EXT_ZVBB), + __RISCV_ISA_EXT_DATA(zvbc, RISCV_ISA_EXT_ZVBC), + __RISCV_ISA_EXT_DATA(zvkb, RISCV_ISA_EXT_ZVKB), + __RISCV_ISA_EXT_DATA(zvkg, RISCV_ISA_EXT_ZVKG), + __RISCV_ISA_EXT_BUNDLE(zvkn, riscv_zvkn_bundled_exts), + __RISCV_ISA_EXT_BUNDLE(zvknc, riscv_zvknc_bundled_exts), + __RISCV_ISA_EXT_DATA(zvkned, RISCV_ISA_EXT_ZVKNED), + __RISCV_ISA_EXT_BUNDLE(zvkng, riscv_zvkng_bundled_exts), + __RISCV_ISA_EXT_DATA(zvknha, RISCV_ISA_EXT_ZVKNHA), + __RISCV_ISA_EXT_DATA(zvknhb, RISCV_ISA_EXT_ZVKNHB), + __RISCV_ISA_EXT_BUNDLE(zvks, riscv_zvks_bundled_exts), + __RISCV_ISA_EXT_BUNDLE(zvksc, riscv_zvksc_bundled_exts), + __RISCV_ISA_EXT_DATA(zvksed, RISCV_ISA_EXT_ZVKSED), + __RISCV_ISA_EXT_DATA(zvksh, RISCV_ISA_EXT_ZVKSH), + __RISCV_ISA_EXT_BUNDLE(zvksg, riscv_zvksg_bundled_exts), + __RISCV_ISA_EXT_DATA(zvkt, RISCV_ISA_EXT_ZVKT), __RISCV_ISA_EXT_DATA(smaia, RISCV_ISA_EXT_SMAIA), __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF),