From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796523022; b=qpfAje4gS8Q3lOS/Q+0Fdk88FimqQFZ+bM3n2jLjL1mZq0X+y8qw2sfUi7DGJugWBsw5 hK1tMiO2AfJk9cf/k+Pwp3TfQt7rVyKEZtBc1j63KGXrl3/y3XHJHyJnvGwOQVNdmQ9Xs yE2RYrEj+8WkRZI8WP38J1o7mc92Hq1QTOou/J0bbARGgy2tEyEl8p3G+NZyh+5s0FcCV K1479Imy7Mo6pJrMb+vcclWNS0sMORGv5O4xHG7aWXoC25SoqPqPsDI27KVD49J692fOv cHZo6ibmVd3v3CbeZ3/yIkA/smXbqW7TwmTt+cviW9mIoj5LYHYL064oMpW3YeOm09w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796523022; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=e+QI9WLjwK5yW2o8CyEMNogmsgzvk7zmVV5J+Wc1zPY=; b=UNe3v97YNKHRmjarKVMUN69LmDqKxH5krm25bmFji1bWm2afmodN/TxtHMWL7wPPDmyk +zhALm0ebZvfLlbgj0OTxXbkBRohF6awLyk7iLSJkTPL9ZdPwHFs7l0nWSvz8A6uLZqLC dP30eNWaOh8xpD0y35giTAPUuhq0pVUexyE7+Cqz4H/1vSKILcNWp0d7DB2WZvov9zUPN TDVpDlv5vzeCohpfN2YTOQ3fJeP9gfISXwkptxA9V1fmoZLJNEiHtOsOyLJo0J4ob7O+a SZhO0gifsFvayO2tV0xgHfXou4OxUz2/JsG+7uZwKdWlTsDEr3TgRxlOMLTJzeMz3ZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T3XusUy4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE7BB606A31F for ; Sun, 6 Dec 2026 02:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T3XusUy4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DAAB1F0093B; Sun, 6 Dec 2026 02:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796523022; bh=e+QI9WLjwK5yW2o8CyEMNogmsgzvk7zmVV5J+Wc1zPY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=T3XusUy4dW40xiCFPG0egKlPxRmOfjTJHMCgk8i1xsDJoo638GNvDR5COdfIOukLz RlGyCsV7lpAYwKUlYbYyOAlKZqKJGPrJMI3EmgINyOXHhS2I5zCbUOpQKAqhB2V71F x7Z1ZewUhuL/0C7B8MP+M2OgPUbZ3xbE9tirqViqlqhj2aj9krvm6Gwd7o+PF88pG/ WOCZdjtbAiPI2GbSOaXA0wpvkJSTYM9nBGN9QK9YIU/7L+UloDFmUFYD58cPCp+Bzs x0EWMkVJl432SgCknnYgOuhfDaCn0MCc0fKVAN8Nmm3xdvqXMLr2Sqxa+bRfHqhMkj Qr+bY33ddJTSA== Date: Sat, 5 Dec 2026 18:10:20 -0800 From: Eric Biggers To: Etienne Cordonnier Cc: Jason@zx2c4.com, ardb@kernel.org, linux-crypto@vger.kernel.org Subject: Re: [PATCH v2] lib/crypto: mpi: use a 128-bit multiply for umul_ppmm() when available Message-ID: <20261206021020.GB362402@quark> References: <20261127221711.3585352-1-ecordonnier@snap.com> X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127221711.3585352-1-ecordonnier@snap.com> On Fri, Nov 27, 2026 at 11:17:11PM +0100, Etienne Cordonnier wrote: > longlong.h only has architecture-specific umul_ppmm() implementations > for a handful of CPUs. On every other 64-bit architecture, including > arm64 and x86_64, umul_ppmm() falls back to generic C that builds each > 64x64->128 product out of four 32x32 multiplications plus carry > handling. umul_ppmm() is in the inner loops of mpihelp_mul_1(), > mpihelp_addmul_1(), mpihelp_submul_1() and the division code, so this > slows down every mpi_powm(), e.g. each RSA signature verification > (module signatures, X.509). > > Add a variant of umul_ppmm() based on a u128 multiplication, for 64-bit > architectures that select CONFIG_ARCH_SUPPORTS_INT128. It sits just > before the generic fallback, so architectures that provide their own > umul_ppmm() are unaffected. The compiler turns it into a widening > multiply: mul + umulh on arm64, mul on x86_64. > > On an arm64 Cortex-A55 at 1.5 GHz, the time spent in mpi_powm() per > RSA-4096 module signature verification (measured with kprobes on a 6.1 > kernel with the arm64 version of this change backported) goes from > 1286 us to 1201 us (-6.6%). A userspace build of the same code shows > the same direction at other modulus sizes (2048/3072/4096 bits: > 0.42/0.85/1.44 ms before, 0.35/0.70/1.19 ms after). Other > architectures were not benchmarked. > > The new macro gives the same results as the generic C one on 200 million > random and edge-case inputs. It builds without warnings on arm64 and > x86_64. On arm64 (QEMU virt, cortex-a57), rsa-generic passes the > self-tests with CONFIG_CRYPTO_SELFTESTS_FULL. It was not run on x86_64 or > other architectures. > > AI assistance: this patch and its changelog were written by Claude > Sonnet 5.5 (Anthropic), used through Claude Code, and reviewed by the > submitter. > > Signed-off-by: Etienne Cordonnier > --- > Changes in v2 (suggested by Eric Biggers): > - Drop the __aarch64__ condition and put the u128 variant right before > the generic fallback, so it applies to every 64-bit architecture that > selects CONFIG_ARCH_SUPPORTS_INT128 and has no umul_ppmm() of its own. > - Retitle and reword the changelog accordingly. > - v1 was arm64-only. Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next - Eric