Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3658324rdh; Mon, 27 Nov 2023 23:17:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqImhjGW/YTw2efuyhlaJLGGwdi+aEqOrO5fzVUUbiUS7AxhCHUr9A59KWpDXwnYIoD6L9 X-Received: by 2002:a17:902:ab47:b0:1cf:cbf4:6f7e with SMTP id ij7-20020a170902ab4700b001cfcbf46f7emr6452544plb.14.1701155838038; Mon, 27 Nov 2023 23:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701155838; cv=none; d=google.com; s=arc-20160816; b=mey9XwraPdzUguzxY76vbKUe/CeWbsVibL2qWERP4F5XpqCgK0ynIVx0ZTxzbEgEFg mGLYUzN4ILkLC0wjPOOubzH2so2Zcjk7rU5Gx9htg1zj3uwcVn9yHooWY4Cw98yOITVH otoHywUGWSPoXdRpisDuCGQKdRYyH56DN3lmhOcz26X74Uqg1ltl8T7PgtyW7ThP/Y1u d6FT4qLgRgBqfgwaQrZVU8vYwVDYXa6pZ+TjUwnUCltBFLYTY+Gmxdum/Lh29MmoAQT+ 5NZXui318RG2yQdy5uxfMuKhmF1RueE4hssTh05BjVbeOgbHjvVgoEjAVE7S3+SocSqu 7ulg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=1hGy46pUf93WoDJ7rnnE2nED/iyelB1yhgDX8ASNQ7E=; fh=l87gWiv0kDFUQGpmayR9Ge7fmCHWSTb/NudJtZx8QfU=; b=CbD6eFZHe1kL0oftqjd4zvXSoLXtatBdqG/TOOx/meTws6UdZA1U/KuW3RAathaMAQ cdTNZCMj9mAsiacqIx81vrnz/dMUaV3FKEd/vlDg3sDvrvPjst51WzaGmQf4yUM3xlvD rx+MeFYSJJKAzp1nNI2TxyKUGD+g/9J9avjHYh/S3zSo3939zkIUZFK/htNAN+yp6l19 REM0cIkh4ua4xnA7OUWdwInVt0qOovggp1X1FefXhiFanVr4nfBBFKuI5554Thi2igBt uwbTDzt+/x6C5NxoWRku7mTxqvFIz3WuTE8C85SWxsyAb2eUICCjygrSs87HPofhevNn 99Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=VnvqGzM1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u14-20020a170903124e00b001cdf9395a2asi11749081plh.420.2023.11.27.23.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 23:17:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=VnvqGzM1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BE4CD80A990F; Mon, 27 Nov 2023 23:17:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343788AbjK1HRG (ORCPT + 99 others); Tue, 28 Nov 2023 02:17:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343813AbjK1HRB (ORCPT ); Tue, 28 Nov 2023 02:17:01 -0500 Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46CB3D4D for ; Mon, 27 Nov 2023 23:17:00 -0800 (PST) Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-58d4e32ea2fso1846141eaf.3 for ; Mon, 27 Nov 2023 23:17:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1701155818; x=1701760618; darn=vger.kernel.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1hGy46pUf93WoDJ7rnnE2nED/iyelB1yhgDX8ASNQ7E=; b=VnvqGzM1DoJNEubPnROwF86hlxKEiEWVfnKtU35EpW3SwaDsQl00Vg4Q+3ei3FLYQL 0IxC9bwYlWUizFMOJLbamv7xSQHZsJId4jdCNCSBrS2+nmRZ6EmiQxMDtxNB2mZ4w0kG CGKK+qbBS2n6W5CN1sfXbfK1Zc2Ew/UrEw536CDfeVOY/C5SxTnYDfWGnv/BHju8hzBJ H7qzYo3ZaDvnjhksHFSyBTx3hljMmgvCCa6i8vTUxVcHu+soTp2u5GNI4QtMsPrz5/xe 0V194CeXMZ0ANSL2sAKQOOpdXK74z8Huy+zSLr04f7AAUyXZlQyOBuUYjsPDyj6HQOmo /0qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701155818; x=1701760618; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1hGy46pUf93WoDJ7rnnE2nED/iyelB1yhgDX8ASNQ7E=; b=fQqjeQLonL+Ncyszujkw/FXmTwws4068i51NBZnifu97b9bjSqrB5QT7B6/RExxnlQ pZMXS9VT/h4hMHHzQPODvT1R0eYx0lVA8nlfbceY4PotKSFGBEVvsArrHOmGuG94g4EJ 3BSbxp+dyXeBw/eEN3PzkmtMnBiJ8hoMBPA43XvpKAmif3wiXJiaVfE3TOqhmTPCRpUx UX8SWVMDGMqT+IWP7U537XHFanhf7ega9DP7RgPxl3rVAGpxFsEP/LA/PhcwXBaTyJLT F+VhO0Sg74w0qZ9HHb2AxXd+zTMMUFe7D2D8WXEz9YQmMxmHVCK17XVnDX9F3zvdR/6a mpfQ== X-Gm-Message-State: AOJu0YzatpUqtVvejRFb2xKm3fZLXriBpfxEJR5+N43hMJFaKJiaTeEK Q3r2Adl6yobFKqy3RQsVM1Fuag== X-Received: by 2002:a05:6358:52c6:b0:16b:c479:d6c1 with SMTP id z6-20020a05635852c600b0016bc479d6c1mr17221034rwz.9.1701155817816; Mon, 27 Nov 2023 23:16:57 -0800 (PST) Received: from ?IPv6:2402:7500:4ce:8338:14c0:b892:2482:e230? ([2402:7500:4ce:8338:14c0:b892:2482:e230]) by smtp.gmail.com with ESMTPSA id n7-20020a634007000000b005c2185be2basm8957980pga.54.2023.11.27.23.16.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Nov 2023 23:16:57 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.7\)) Subject: Re: [PATCH v2 09/13] RISC-V: crypto: add Zvknha/b accelerated SHA224/256 implementations From: Jerry Shih In-Reply-To: <20231128041235.GJ1463@sol.localdomain> Date: Tue, 28 Nov 2023 15:16:53 +0800 Cc: Paul Walmsley , palmer@dabbelt.com, Albert Ou , 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 Content-Transfer-Encoding: quoted-printable Message-Id: <51190E7A-25BD-4D9A-AADF-02FE2A280508@sifive.com> References: <20231127070703.1697-1-jerry.shih@sifive.com> <20231127070703.1697-10-jerry.shih@sifive.com> <20231128041235.GJ1463@sol.localdomain> To: Eric Biggers X-Mailer: Apple Mail (2.3445.9.7) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 23:17:16 -0800 (PST) On Nov 28, 2023, at 12:12, Eric Biggers wrote: > On Mon, Nov 27, 2023 at 03:06:59PM +0800, Jerry Shih wrote: >> +/* >> + * sha256 using zvkb and zvknha/b vector crypto extension >> + * >> + * This asm function will just take the first 256-bit as the sha256 = state from >> + * the pointer to `struct sha256_state`. >> + */ >> +asmlinkage void >> +sha256_block_data_order_zvkb_zvknha_or_zvknhb(struct sha256_state = *digest, >> + const u8 *data, int = num_blks); >=20 > The SHA-2 and SM3 assembly functions are potentially being called = using indirect > calls, depending on whether the compiler optimizes out the indirect = call that > exists in the code or not. These assembly functions also are not = defined using > SYM_TYPED_FUNC_START. This is not compatible with Control Flow = Integrity > (CONFIG_CFI_CLANG); these indirect calls might generate CFI failures. >=20 > I recommend using wrapper functions to avoid this issue, like what is = done in > arch/arm64/crypto/sha2-ce-glue.c. >=20 > - Eric Here is the previous review comment for the assembly function wrapper: > > +asmlinkage void sha256_block_data_order_zvbb_zvknha(u32 *digest, = const void *data, > > + unsigned int num_blks); > > + > > +static void __sha256_block_data_order(struct sha256_state *sst, u8 = const *src, > > + int blocks) > > +{ > > + sha256_block_data_order_zvbb_zvknha(sst->state, src, blocks); > > +} > Having a double-underscored function wrap around a non-underscored one = like this > isn't conventional for Linux kernel code. IIRC some of the other = crypto code > happens to do this, but it really is supposed to be the other way = around. >=20 > I think you should just declare the assembly function to take a = 'struct > sha256_state', with a comment mentioning that only the 'u32 state[8]' = at the > beginning is actually used. That's what = arch/x86/crypto/sha256_ssse3_glue.c > does, for example. Then, __sha256_block_data_order() would be = unneeded. Do you mean that we need the wrapper functions back for both SHA-* and = SM3? If yes, we also don't need to check the state offset like: BUILD_BUG_ON(offsetof(struct sha256_state, state) !=3D 0); Could we just use the `SYM_TYPED_FUNC_START` in asm directly without the wrappers? -Jerry=