Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4848978rdh; Wed, 29 Nov 2023 12:26:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGa8AGy74LFHWsaPsqStN9rWFxB0REJ5b9ohzzXbBi3lrE7BeQNMtc+tuKHZVJJ5PGb+XKW X-Received: by 2002:a17:902:8309:b0:1d0:68a:4a45 with SMTP id bd9-20020a170902830900b001d0068a4a45mr4917357plb.35.1701289579855; Wed, 29 Nov 2023 12:26:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701289579; cv=none; d=google.com; s=arc-20160816; b=cnQ4ffukVmU4ON0/bjIJrGQjBf2zhz+x0CJpwWwJdhhkbM3mAc3A8wRpzERoRkNePq 7M8dcSATgxZMqmYl1uFv7D7ZI1/V2NBDlqSEw8VRW1bsOwufYZ0NfvnEZPbWeB0LRh90 JWBg34Rk2YbYff7JzHe766kwHXFx94qgrb5eaJvkFtPiGUc7T1FAfCNxQzybafWpt3EP 7Dqzy/L7EckUsZtrZuFhsyrFtc6Lp9F6HFlDpFOiLwQ/CdK+B5/Nilj2425RrXKvG1v/ BCZq5zBPxvNIjvieETdgPKK811bTotkMF9EFQnoXDhBtWXyYFnHPaw64vI5jiXHc6WFj zPzw== 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=SK6bj/XhvsOzQf1+CYa15D5WO52e/PLb5H3EAiK6TAk=; fh=6NSYfrN97yPa57mDk4JOMoTZYv57PdZL175x+vySAiw=; b=Px8LRPeY+WBlc8gXHBJ9ZDjya+TMN7hwHPK+LC4Wn3HVa2r8Bue+oLB7HFmWVfjPl3 kOhctqz6eUD0eA3ga6nrTWsB2cIZjLqdno8C1YLuLf1OLehoKky/NtOn4kUrytHk6W45 OyJ58EA9/X+W0wqFNT9pSYlodOn+HOD/IYP2/BgXvuDzzxYd427lyPxbkO6s8tQuQVWN RRm+Nm1Sr5qrD+mVcqjal4IZRsuyoNX9XNUVNyumQEmMU4qG1Qd+JoQC/+nFGccNurO0 i9PeThDNXJ2fkWCtCJAJ/0d0CCQQm0Xdw1TSX88lzlPMWz4Lxr950JFVCuKK8Psw0z/6 NTqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SXjh5gO0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e2-20020a170902744200b001b894687ec9si14042584plt.462.2023.11.29.12.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 12:26:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SXjh5gO0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id B466380ACC6C; Wed, 29 Nov 2023 12:26:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233879AbjK2U0A (ORCPT + 99 others); Wed, 29 Nov 2023 15:26:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbjK2UZ7 (ORCPT ); Wed, 29 Nov 2023 15:25:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09780D67 for ; Wed, 29 Nov 2023 12:26:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33903C433C8; Wed, 29 Nov 2023 20:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701289565; bh=PN5ubgLpDPuW9rHykLBRI+s3FZh6xjxWlF9+Ry84t80=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SXjh5gO079La4jU98h/gu37YvIoFwnrjoraInTxvddDeytta4VebZNQV2H+kSoxiN 3P939JvVZhSvqOjLYzrv5cJDl+zd5o13jLXxReDmxH0jo3ydVQlnR1skJnl+4OqPuE Hh38EVOHi9+DI11WDHEtPhu2f95exDmdlCyoXg2I1Nwr3meJ5BQ40qPOAJzd1HRfO6 HP9okeS8J9iVDUeb1o18O3kLuYJYkJL3m76mOJBPUGxxuCRH0hgOvWysuLnJrLfAfK Exa6Y9enh+emk9SzsSK2bSobP/7mJNXRsChuKM78adeE2l5ZXwdgsCn0ZbdpKPfXNC II+VZoyJLkvUg== Date: Wed, 29 Nov 2023 12:26:03 -0800 From: Eric Biggers To: Conor Dooley Cc: Jerry Shih , Andy Chiu , Paul Walmsley , palmer@dabbelt.com, aou@eecs.berkeley.edu, herbert@gondor.apana.org.au, davem@davemloft.net, conor.dooley@microchip.com, ardb@kernel.org, heiko@sntech.de, phoebe.chen@sifive.com, hongrong.hsu@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Subject: Re: [PATCH v2 04/13] RISC-V: crypto: add Zvkned accelerated AES implementation Message-ID: <20231129202603.GB1174@sol.localdomain> References: <20231127070703.1697-1-jerry.shih@sifive.com> <20231127070703.1697-5-jerry.shih@sifive.com> <20231128-await-tipper-2094715466f2@spud> <20231128201228.GE1148@sol.localdomain> <20231129-subtitle-unlinked-c0871a28ac88@spud> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231129-subtitle-unlinked-c0871a28ac88@spud> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 29 Nov 2023 12:26:16 -0800 (PST) On Wed, Nov 29, 2023 at 11:12:16AM +0000, Conor Dooley wrote: > On Wed, Nov 29, 2023 at 10:39:56AM +0800, Jerry Shih wrote: > > On Nov 29, 2023, at 04:12, Eric Biggers wrote: > > > On Tue, Nov 28, 2023 at 05:54:49PM +0000, Conor Dooley wrote: > > >>> +static inline bool check_aes_ext(void) > > >>> +{ > > >>> + return riscv_isa_extension_available(NULL, ZVKNED) && > > >>> + riscv_vector_vlen() >= 128; > > >>> +} > > >> > > >> I'm not keen on this construct, where you are checking vlen greater than > > >> 128 and the presence of Zvkned without checking for the presence of V > > >> itself. Can you use "has_vector()" in any places where you depend on the > > >> presence of vector please? > > > > > > Shouldn't both of those things imply vector support already? > > > > The vector crypto extensions imply `V` extension. Should we still need to check > > the `V` explicitly? > > https://github.com/riscv/riscv-crypto/blob/main/doc/vector/riscv-crypto-spec-vector.adoc#1-extensions-overview > > The check for Zkvned is only for whether or not Zvkned has been provided > in the DT or ACPI tables, it doesn't mean that the kernel supports the V > extension. I could see something like a hypervisor that does not support > vector parsing the "v" out of the DT or ACPI tables but not eliminating > every single extension that may depend on vector support. > > The latter check is, IMO, an implementation detail and also should not > be used to imply that vector is supported. First, the RISC-V crypto files are only compiled when CONFIG_RISCV_ISA_V=y. So in those files, we know that the kernel supports V if the hardware does. If the hardware can indeed declare extensions like Zvkned without declaring V, that sounds problematic. Would /proc/cpuinfo end up with the same misleading information in that case, in which case userspace would have the same problem too? I think that such misconfigurations are best handled centrally by having the low-level architecture code in the kernel clear all extensions that depend on missing extensions. IIRC there have been issues like this on x86, and that was the fix that was implemented. See arch/x86/kernel/cpu/cpuid-deps.c - Eric