Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1703260lqp; Mon, 15 Apr 2024 14:38:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/k8ES0bjkMqhkVNiVTHclt5vme3ychsmFZUbMw+/OvZSfIrtaKmOQYZBD3xDevKATMAdUstY2H60W0a/o4mDvRGovKhNBPT//5Hb9hg== X-Google-Smtp-Source: AGHT+IF40I2/z4GwTQTrGBTsyLxTiRtxGfRnYkNEIaJj8G3xCataktlAnS42EzTNkKd81Ur0YT9X X-Received: by 2002:ac2:465e:0:b0:516:cd76:ee11 with SMTP id s30-20020ac2465e000000b00516cd76ee11mr6672621lfo.17.1713217134680; Mon, 15 Apr 2024 14:38:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713217134; cv=pass; d=google.com; s=arc-20160816; b=uOyDOwsoHN+GLVKCceqYxmwSV4NHbDN8CKn+39Xx7dg+BLXNuN1IuRDFHK0PmMWyxR bGk9lUwrP7WDsc4NiDtRSOVKskDtVebzob/3sKIW7YoUUjPfbgUcVYoWaDzgfQX8Wa+t CYUQTTIq5AEDCm3HYiPjJUITi074YsEyLLNG3MBEMxnxgm5Cyhp+1Cy348tPXyDozo+d 8ntqZ0Q9tbwC6uN013ZI86ioGLiAmIrg/a8yNAB0e4xZ1TdXlGV+idmEEIXhrcD8a0Qo j8dro0OA8uhZ6/HQURQeuVqYEd3h3i0G61tHYdkt4eQEcwpAUFV9toyspGQqWauKhNyP C00g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=qVN4Url+5d47n0dyvIAMlTUtdAMuwsbrOVMZFCrk3lE=; fh=Oc4UeL7Acx0XOi4VhIHpcDb9W4i3PZetSD9m7YBP3X4=; b=iHeqPSVTj7pJmbUv7rlujAYdyousAgQeeo0yOHMOiiN0P7WSzgUFo308WI9ULMbV7T bPe4adCA3y2biUa0KhSjicEz3IL03ojjGaU+31L+EUb8ffOEi9uHzknCz4TuPj4z8XXk 1+ckPea5TEEol835DzMg/z4fdEoY0Cfb1TI1OHLT44Z8k/NClgzFLaxx/LSXT7eQyBCG EV9rPSuURjnOs4bA9traMbg0YzZTPffU0sE2KEJRdDneYb9tnOrHYCsz1SZ79aCiDBT6 PA4PcI8V28Q9nZJN9e5g1/ymGQMiMAlrcK148TfqVyq9zqJ4yig4qLcLioR/rW8uKP0F raGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="EYIF4/rv"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3550-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3550-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hr16-20020a1709073f9000b00a4666ecd61bsi4948032ejc.217.2024.04.15.14.38.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 14:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-3550-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=@kernel.org header.s=k20201202 header.b="EYIF4/rv"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-3550-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-3550-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 5008E1F2148D for ; Mon, 15 Apr 2024 21:38:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FDFE157460; Mon, 15 Apr 2024 21:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EYIF4/rv" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED7BE1E89A; Mon, 15 Apr 2024 21:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713217129; cv=none; b=qhm83+h0NcBQIREmpvE40AikVJoIxKrmi1K+dXU4NEdA6To0z1GQvxFxrY0j57I9gT1ovNfLYStKlfiYrr/CR2Yep2otxJKwrL34q13QMCsCMvOwJluS4BVTktCVA+XjWUmjrZ40pN/qxLbmhfRiIO0nsPHmVvDANsBx5L7tCQY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713217129; c=relaxed/simple; bh=LdgSzKnyi2LWa7e/BgfjAMFoEXu5VqKaRa128bZAOp8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AL3UW5K4YxNtNkRr4Fpu1PXYn9rA0hL93Bsh4mruQhPtVBa1mBEJ1myQEEhmPwKO04cigYwtfwSW5tujLz+V0VFz5S5ySK/bnXAH64vRBiVsWLUFsAKg7PdWYjdhfEdcVdQ9b3z2GGjQhDTzCfio8DH68uTcl3naoCcSzpVkKS0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EYIF4/rv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44054C113CC; Mon, 15 Apr 2024 21:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713217128; bh=LdgSzKnyi2LWa7e/BgfjAMFoEXu5VqKaRa128bZAOp8=; h=From:To:Cc:Subject:Date:From; b=EYIF4/rvgnLfiMR2HZGkvI551MKvMeaAR/vQxBnQ5XW3GsGPKwIn3OsHIbDBZWPc2 cb1hR4kA8L1bkTeoI+UTGiD2P2yzHigmynE+mzEAoIwWaVeE0Y44Ke/A3xpGC/fHyz UfW5riqyKkwdCNsth7fWbWJx1UCFVa0MLS5YCInSFtBg7BqQpeI7SOxkUnlSGi/UOj Km8ka2Hu1+am5WCkwOPXmV069RNxnCtewxPkbBNpFqn3S4b//3GAxJJIfht6Infaef k/F5TcY1KCjH8QjO2ZUmYKOnI5yO6tGT1Sev2Orm4QEGXvJc1ME4s0Emiz7Q8U8VoU tGfUAVPd+NBIQ== From: Eric Biggers To: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Sami Tolvanen , Bart Van Assche Subject: [RFC PATCH 0/8] Optimize dm-verity and fsverity using multibuffer hashing Date: Mon, 15 Apr 2024 14:37:11 -0700 Message-ID: <20240415213719.120673-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On many modern CPUs, it is possible to compute the SHA-256 hash of two equal-length messages in about the same time as a single message, if all the instructions are interleaved. This is because each SHA-256 (and also most other cryptographic hash functions) is inherently serialized and therefore can't always take advantage of the CPU's full throughput. An earlier attempt to support multibuffer hashing in Linux was based around the ahash API. That approach had some major issues. This patchset instead takes a much simpler approach of just adding a synchronous API for hashing two equal-length messages. This works well for dm-verity and fsverity, which use Merkle trees and therefore hash large numbers of equal-length messages. This patchset is organized as follows: - Patch 1-3 add crypto_shash_finup2x() and tests for it. - Patch 4-5 implement finup2x on x86_64 and arm64. - Patch 6-8 update fsverity and dm-verity to use crypto_shash_finup2x() to hash pairs of data blocks when possible. Note: the patch "dm-verity: hash blocks with shash import+finup when possible" is revived from its original submission (https://lore.kernel.org/dm-devel/20231030023351.6041-1-ebiggers@kernel.org/) because this new work provides a new motivation for it. On CPUs that support multiple concurrent SHA-256's (all arm64 CPUs I tested, and AMD Zen CPUs), raw SHA-256 hashing throughput increases by 82-98%, and the throughput of cold-cache reads from dm-verity and fsverity increases by very roughly 35%. This is marked as RFC for now, as I'm soliciting feedback on the overall concept, and some parts may need a bit more work. The dm-verity and fsverity patches are a bit large and I may try to split those up. Eric Biggers (8): crypto: shash - add support for finup2x crypto: testmgr - generate power-of-2 lengths more often crypto: testmgr - add tests for finup2x crypto: x86/sha256-ni - add support for finup2x crypto: arm64/sha256-ce - add support for finup2x fsverity: improve performance by using multibuffer hashing dm-verity: hash blocks with shash import+finup when possible dm-verity: improve performance by using multibuffer hashing arch/arm64/crypto/sha2-ce-core.S | 261 ++++++++++++- arch/arm64/crypto/sha2-ce-glue.c | 40 ++ arch/x86/crypto/sha256_ni_asm.S | 352 +++++++++++++++++ arch/x86/crypto/sha256_ssse3_glue.c | 40 ++ crypto/testmgr.c | 59 ++- drivers/md/dm-verity-fec.c | 31 +- drivers/md/dm-verity-fec.h | 7 +- drivers/md/dm-verity-target.c | 560 ++++++++++++++++++++-------- drivers/md/dm-verity.h | 43 +-- fs/verity/fsverity_private.h | 5 + fs/verity/hash_algs.c | 31 +- fs/verity/open.c | 6 + fs/verity/verify.c | 177 +++++++-- include/crypto/hash.h | 34 ++ 14 files changed, 1403 insertions(+), 243 deletions(-) base-commit: 0bbac3facb5d6cc0171c45c9873a2dc96bea9680 -- 2.44.0