Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp961400lqo; Wed, 8 May 2024 23:56:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWJLPUHHr9v8Ux89A0egeknw8vI2t+2JyytYkNojSfMTDaPIbmZVh4h0g4m/7kAiZHL5Ne9rIUEkgY1Mu6a7TBlcxgIs5X/GIFnqakXoA== X-Google-Smtp-Source: AGHT+IE5FoZj7Pl/gn2YLRoF4YhgiMVBBumPn9NwXas4UPiRvUyv97VWUJThJ13srQAnjg+HReCG X-Received: by 2002:a50:d796:0:b0:572:3483:8a27 with SMTP id 4fb4d7f45d1cf-5731da5b6aamr4269349a12.33.1715237817801; Wed, 08 May 2024 23:56:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715237817; cv=pass; d=google.com; s=arc-20160816; b=ISiYA8NJ6nMEEUmeItQ+2+3t19dGudAORLLemHXruxpwcA5wO/kquHEWdNEsH+o4k8 gst7fQOPtaKrtoYhyoEp1ASDL3ZxOZcRsRXyf3ol/oKn8leQEVptHo4RK1muTiQQJ+qN 81MkMXMtDhqyaSX1tFlV2SbvoKZ295aTBQGwjwc2PfHUTuBT8fF0oBBp3i6U+gd1AaZ/ lpetSq7tCQwsyfi6uLb8dF2LaC2N7JLFGjFN3n/OKu+uQg7uk8L+1kLdpzmfXYN5wNvD QSo+C5o9L9NjYu19jPfIxbFgPDZK23mtW4K3LyFx3RoOps29dxJLJDI1Ghk0baFijOJT 74QQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=VaF65Mth8rDaiy1Bx7eDA2aD8YWaoQ7AgHRL/QGNHIg=; fh=l2nUA4e6pPKuJxSuYDoavIIqHXTvuHmZXgyciTPoWSc=; b=GJcHgNU8UzykTLS39IxH1fAD0W8jS6qtzmGe/fug+NGVVSlRZ2ub8X0mxDY/ooAXoB 0Tyd/4/kKNVF5rn5nFOnVTX7cHozkdS+eGyph6wpS3PVfysdpcqTLjVAqbtQdfv8M/Kf pkQhsiQW9q9T4BUnFu0zLaRsmX0eMFStmZNe27b5C0oG/4TSzQ8nM6TAafD726QBvGxs jyFw3fE4drqZAQl/N8zXzbbNigymL7BD23P7VnS0lmw8gQdbEXrbqh14KCCbYlPBIRsd ONt9t2otHcybI6Gkj5b3mcIagXMbN0YENYqFAHfaHFlwg7Bk4CdGRJv0YR4U7HOcQEcy YNWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=TtbtRhxC; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-174219-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c32c3f8si467205a12.427.2024.05.08.23.56.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 23:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174219-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=TtbtRhxC; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-174219-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3049D1F213BB for ; Thu, 9 May 2024 06:56:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 608B213C830; Thu, 9 May 2024 06:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="TtbtRhxC" Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFAE6624 for ; Thu, 9 May 2024 06:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715237804; cv=none; b=Kh4wkUVWGR0qZOFPB1lEpK5fM+5aBfOdst3/5yPwtIEdq15Xm3/NZSevouPmhQCNfGB4f4wp1eiRuiVB6oAA1Dhe+enMaaSy3UFSUjeu00jfT193p/7sN1WxIFlb8LngL+z2e+LFZH5Wa5PcOoncBKb6uoYDNltoK3Ln2WhCw7o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715237804; c=relaxed/simple; bh=qMk1PdT+iPPJAba1vs0taTftishgYTmWVXA0TThaZfo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=W6U0AvZNlh+2g4Fw7HaIJmKnk9PT7fXm4nOh7QL8Z9N6F9aLKi6WozZx25TtVa8AzCfujLr0DUx2LWd1THV4SSLUi/+f4XpD7j/df8FOb+zHaTIJ/wq27yeXHoZr5ElJca1PonR6P1meCS5nKqS3DazI5emwq/IAkS8BOAfWjH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=TtbtRhxC; arc=none smtp.client-ip=209.85.128.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-620314aa1d7so5676207b3.2 for ; Wed, 08 May 2024 23:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1715237802; x=1715842602; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VaF65Mth8rDaiy1Bx7eDA2aD8YWaoQ7AgHRL/QGNHIg=; b=TtbtRhxCHBFjy6bHolE3ZrCu96bdCOh13MQ+kXrhp9dMfcPglz3SLoc4BrSbvlL4dX 7MUoNBKH27UCtkjgWfVjl3thZFWqBpJqy5wZ3eNZDKn1+G/KxH7Ug+gdPDNO4Px/+HA+ E93FUMS3jI6aXzlseFgT0y++0ck0Ewp72md4v0qvvfAB8/cD4M/oWU8zfJq8u+ILhxNR iPa+oWYEp6x8Zmvo7H+j1Y8tzsDTt+yqJAEFOVRNiuIclcXl7xLpDXXY/OWTmgTs8ogk mLISZcKSBgoFxKJJDp4uYddqwOfZ8u+jMfgZ5W7/K6FObwwwegBsWc7GGzhz1aQYQQOM bNvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715237802; x=1715842602; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VaF65Mth8rDaiy1Bx7eDA2aD8YWaoQ7AgHRL/QGNHIg=; b=eY8O+FePajKGpr5qM7pK8QySzYTKf4G4dwHYgN3vwPYWyly0oRAunJL/gd5XzhnJVt 1dtg2KAsKVp7vqDleXBD2q2jh4SoiHnXVasfNsnYtJp5gH+EqfavU7dZWbYjPxwSCEHb nvfAzsyoNapQyi+pihbfojfMkq1OW2Wk+Z7xDaeXzVBBhdaQQJkGP6DnVdNWWgI+hvYX 5nrLR5fm2nZL9towJAftme4BeO5agoPBEzti1qJIIZxcHqpONQvo2Muyhms2m/wIDmMY xGPP07Y6/JSfzDeKRtoDhNDw45klVo+c9LJ5A3MJRCLeq9OaTpgWl6pADlgJxELUTQ5j SOkw== X-Forwarded-Encrypted: i=1; AJvYcCVz9fNWkUQV+1Oan1f8G/OrE524KLY6Hz9XOCEhO5sErch/0nuLPkOvN1Hvxv4fT8sGs/qHEW3/r1LNkMHoGcmTXZSKLQaLjwuAmkfv X-Gm-Message-State: AOJu0Yx/+w79/MznCC23hbAloOMWjCdLXwCsplQxCz1V5+HyZPAm1NDh eaCOrpnC03LLAvDwj6X++52hCMzy0i6iqOQ19S6qPLmzEYg6vT8LE89f29azyu5I5fqB/BZ29sM rL7txxOzPM7am6kp618AjXlQBjMK5f/48qkd8Xg== X-Received: by 2002:a81:928c:0:b0:61b:3304:cdc7 with SMTP id 00721157ae682-62085a747b9mr50296887b3.29.1715237801602; Wed, 08 May 2024 23:56:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240412-zve-detection-v4-0-e0c45bb6b253@sifive.com> <20240412-zve-detection-v4-7-e0c45bb6b253@sifive.com> <20240418-brook-chili-4d3e61d1a55c@wendy> <20240418155256.GA2410@sol.localdomain> <20240418-ultimatum-yam-11de4b063b83@spud> <20240418173203.GA1081@sol.localdomain> <20240418173946.GB1081@sol.localdomain> <20240418-sterling-sanding-d59c3b0a2aaa@spud> In-Reply-To: <20240418-sterling-sanding-d59c3b0a2aaa@spud> From: Andy Chiu Date: Thu, 9 May 2024 14:56:30 +0800 Message-ID: Subject: Re: [PATCH v4 7/9] riscv: vector: adjust minimum Vector requirement to ZVE32X To: Conor Dooley Cc: Eric Biggers , Conor Dooley , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Stuebner , Guo Ren , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Evan Green , =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Shuah Khan , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , Vincent Chen , Greentime Hu , devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Joel Granados , Jerry Shih Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Conor, On Fri, Apr 19, 2024 at 2:26=E2=80=AFAM Conor Dooley wro= te: > > On Thu, Apr 18, 2024 at 10:39:46AM -0700, Eric Biggers wrote: > > On Thu, Apr 18, 2024 at 10:32:03AM -0700, Eric Biggers wrote: > > > On Thu, Apr 18, 2024 at 05:53:55PM +0100, Conor Dooley wrote: > > > > > If it would be useful to do so, we should be able to enable some = of the code > > > > > with a smaller VLEN and/or EEW once it has been tested in those c= onfigurations. > > > > > Some of it should work, but some of it won't be able to work. (F= or example, the > > > > > SHA512 instructions require EEW=3D=3D64.) > > > > > > > > > > Also note that currently all the RISC-V vector crypto code only s= upports riscv64 > > > > > (XLEN=3D64). Similarly, that could be relaxed in the future if p= eople really need > > > > > the vector crypto acceleration on 32-bit CPUs... But similarly, = the code would > > > > > need to be revised and tested in that configuration. > > > > > > > > > > > Eric/Jerry (although read the previous paragraph too): > > > > > > I noticed that the sha256 glue code calls crypto_simd_usable(),= and in > > > > > > turn may_use_simd() before kernel_vector_begin(). The chacha20 = glue code > > > > > > does not call either, which seems to violate the edict in > > > > > > kernel_vector_begin()'s kerneldoc: > > > > > > "Must not be called unless may_use_simd() returns true." > > > > > > > > > > skcipher algorithms can only be invoked in process and softirq co= ntext. This > > > > > differs from shash algorithms which can be invoked in any context= . > > > > > > > > > > My understanding is that, like arm64, RISC-V always allows non-ne= sted > > > > > kernel-mode vector to be used in process and softirq context -- a= nd in fact, > > > > > this was intentionally done in order to support use cases like th= is. So that's > > > > > why the RISC-V skcipher algorithms don't check for may_use_simd()= before calling > > > > > kernel_vector_begin(). > > > > > > > > I see, thanks for explaining that. I think you should probably chec= k > > > > somewhere if has_vector() returns true in that driver though before > > > > using vector instructions. Only checking vlen seems to me like rely= ing on > > > > an implementation detail and if we set vlen for the T-Head/0.7.1 ve= ctor > > > > it'd be fooled. That said, I don't think that any of the 0.7.1 vect= or > > > > systems actually support Zvkb, but I hope you get my drift. > > > > > > All the algorithms check for at least one of the vector crypto extens= ions being > > > supported, for example Zvkb. 'if (riscv_isa_extension_available(NULL= , ZVKB))' > > > should return whether the ratified version of Zvkb is supported, and = likewise > > > for the other vector crypto extensions. The ratified version of the = vector > > > crypto extensions depends on the ratified version of the vector exten= sion. > > That's great if it does require that the version of the vector extension > must be standard. Higher quality spec than most if it does. But > "supported" in the context of riscv_isa_extension_available() means that > the hardware supports it (or set of harts), not that the currently > running kernel does. The Kconfig deps that must be met for the code to be > built at least mean the kernel is built with vector support, leaving only > "the kernel was built with vector support and the hardware supports vecto= r > but for $reason the kernel refused to enable it". > > I'm not sure if that final condition is actually possible with the system > ending up in a broken state, however - I'm not sure that we ever do turn > off access to the VPU at present (after we mark it usable), and if we do > it doesn't get reflected in has_vector() so the kernel and userspace woul= d > both break, with what a crypto driver does probably being the least of > your worries. > > > > So > > > there should be no issue. If there is, the RISC-V core architecture = code needs > > > to be fixed to not declare that extensions are supported when they ar= e actually > > > incompatible non-standard versions of those extensions. Incompatible > > > non-standard extensions should be represented as separate extensions. > > > > > > > It probably makes sense to check has_vector() to exclude Zve* for now, = though. > > I think you might actually be better served at present, given the code ca= n > only be built if the core vector code is, by using > riscv_isa_extension_available(NULL, v). That way you know for sure that > you're getting the ratified extension and nothing else. > > Prior to this conversation I thought that has_vector() should return true > if there's a standard compliant vector unit available - given all users > Andy added only need Zve32x. > > > I am just concerned about how you're suggesting that non-standard exten= sions > > might be pretending to be standard ones and individual users of kernel-= mode > > vector would need to work around that. > > I am absolutely not suggesting that non-standard extensions should > masquerade as standard ones, I don't know where you got that from. What > I said was that a non-standard vector extension could reuse riscv_v_vlen > (and should IMO for simplicity reasons), not that any of the APIs we have > for checking extension availability would lie and say it was standard. > riscv_v_vlen having a value greater than 128 is not one of those APIs ;) > > > I think that neither has_vector() nor > > 'if (riscv_isa_extension_available(NULL, ZVKB))' should return true if = the CPU's > > vector extension is non-standard. > > riscv_isa_extension_available(NULL, ZVKB) only checks whether the extensi= on > was present in DT or ACPI for all harts. It doesn't check whether or not > the required config option for vector has been set or anything related > to dependencies. has_vector() at least checks that the vector core has > been enabled (and uses the alternative-patched version of the check > given it is used in some hotter paths). That's kinda moot for code > that's only built if the vector core stuff is enabled as I said above > though. > > We could of course make riscv_isa_extension_available() check > extension dependencies, but I'd rather leave dt validation to the dt > tooling (apparently ACPI tables are never wrong...). Either would allow > you to rely on the crypto extensions present only when the standard vecto= r > extensions unless someone's DT/ACPI stuff is shite, but then they keep th= e > pieces IMO :) Should we check if "v" presents for vector crypto extensions in riscv_isa_extension_check()? We are not checking this for now. So a kernel compiled with RISCV_ISA_V still has a problem if its isa-string includes any of vector crypto ("zvbb, zvkg, etc") but not "v". > > Hope that makes sense? > Conor. Cheers, Andy