Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp217668lqh; Mon, 6 May 2024 17:25:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeyMC5uMA+evxLf8DvYXoKsTg+jrkTg9XsJmkOJPio6Nqnpi0aXRBUMA+jl/dasCKrRu08nSBxjTs6yTiBoZhpaKdmer1wvpSEESPhFA== X-Google-Smtp-Source: AGHT+IHxOtb7eebOvQbKH+6ZXlGbXUEZslSYWxKTx8o/QkJLJR7HX1sDHGLyqITMkRa4BohYwwi4 X-Received: by 2002:a17:906:718:b0:a59:bd78:34c5 with SMTP id y24-20020a170906071800b00a59bd7834c5mr3270805ejb.41.1715041522470; Mon, 06 May 2024 17:25:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715041522; cv=pass; d=google.com; s=arc-20160816; b=umO0g0ikhj8ierLpNUtfYrywBPlRJQnP6jPb4K4RIZBR6w7Thqc+f0r7mNGyl1iZtG meSLJbp2pola6sxyyWg+VGxVF2YRU1Vva56/wff99/GGqejp7lbwZXoXDYEFyDO4KFZ9 xZIRC6iT35z97T0eN726hAD8CIDGz57RLXWwWPmtA6sVyC8ZEzMw/LOQRCQVR589h+gx N2RUav55DUBur0Bx/uqCTUOf3oDP3oJL1TMrgvjCIPnRXbl0SfpRaHFQBwjxukxEMTHV zXABqqOkXJzoe2yBdzqSXlVB1VctxynZG/riKsiFSsCFzKsVByKPIRmCbkyNCviauK0q dw0g== 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=hZslMm3Ifc6gEA2cx0gVSmyKD+m2rS2OT2R6Q2hk8pA=; fh=Oc4UeL7Acx0XOi4VhIHpcDb9W4i3PZetSD9m7YBP3X4=; b=xZxewYMW3N6QfaWck/go+zMyaFbiid1+XZYPIc9ARBIQn4KJxi8TVtIGGt199Pfi6A q2oziy23VdcNEO8djA5rkLHE+36XAq+xuRFTQmAefEOCPhOVVD5IsejQK4PebWiy/MIu bRe4YB5MVHDVgzeI6/vhbNY4i12EiiL2EKK26rNMHfNybfuf5oogoYBVE+fUE/mecN0m ZALFAzdeLmADz7et6THBuPoVZSnP0sQowZeTaXLptMgnVURc0aHrH9MH2swqYNdbcfGQ pbjCWc2Jc7Zv3aG6ka67Fo0mjZfTOpAcuE9xdC/zzFm5xWhhmnIclnRQMF9D0AycBw5E 5U5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DKFHtSIz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4045-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4045-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. [147.75.80.249]) by mx.google.com with ESMTPS id a9-20020a170906468900b00a59ce1386d9si1484584ejr.842.2024.05.06.17.25.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 17:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4045-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DKFHtSIz; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4045-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4045-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 37AA11F23462 for ; Tue, 7 May 2024 00:25:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEF97653; Tue, 7 May 2024 00:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DKFHtSIz" 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 64929622; Tue, 7 May 2024 00:25:16 +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=1715041516; cv=none; b=I/VPT+fidbITC8gjaT1WbVjopR4RE2xBCDGXSdGNrAdnGTd02Nm/oVS7oh64wizqT+685s/S4iDB2cz9679F+rz2pw3rX2ujGXJ4KqhXra4zRU89apS23XJ+bzG24Yn7663MMziu5tfyqmjN8/9AA/1lEjqYu5HYk6jYqpuAJ+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715041516; c=relaxed/simple; bh=s7eBMIDMnKUPCUXSt92sBihifomPay5rghqvBJKTjqk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Ta5mrlH5WXhZmsjp/azLgZhWNN6mSPCKV6eDRTw6PXwn3sQ2A0p72b98kGq/odTK567Lo9FGB6BQ28/vak7EZCf1Fc1FwuNRSnI/Yc/Vlu5pQ02rRoz3ptMXnbLCaG7wORXtEG+5GE5L7kMk0a6zvIv9bX6CmC350FFnRFGAL+w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DKFHtSIz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A76A4C116B1; Tue, 7 May 2024 00:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715041515; bh=s7eBMIDMnKUPCUXSt92sBihifomPay5rghqvBJKTjqk=; h=From:To:Cc:Subject:Date:From; b=DKFHtSIzwCtggFmwgVNyvFpYLdhnLcCxCQPuHNK4a5PxuijN0Tf6AHz/0noYtG9zT Sep4DM7tMwaUOrbZ2Y0DXhUnEj9pEQrOiLsUgwYqbdqyy68jNRYkiXAUbEhA7xdlWK 87vSxjbRIGh8Dy4R9dJemz3OEvcFshe9IO1vvZhPdDFkLOA8ZLt1nETEcIU+4GR7vr Se2KmaAfUIuXOKDb++oC/wCPx95eOeedCLoVNxISpFpggzYzqd1hvRfFMuUN8W76MX uzr43qdjXmKCsMS0g9OvUD3bTNBsacI09UjVD+h8EbxupBl7M+NjbDEcXgYn5HP19C pdKq/AIJhz7PA== 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: [PATCH v3 0/8] Optimize dm-verity and fsverity using multibuffer hashing Date: Mon, 6 May 2024 17:23:35 -0700 Message-ID: <20240507002343.239552-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.45.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 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_finup_mb() and tests for it. - Patch 4-5 implement finup_mb on x86_64 and arm64, using an interleaving factor of 2. - Patch 6-8 update fsverity and dm-verity to use crypto_shash_finup_mb() 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 70-98%, and the throughput of cold-cache reads from dm-verity and fsverity increases by very roughly 35%. Changed in v3: - Change API from finup2x to finup_mb. It now takes arrays of data buffer and output buffers, avoiding hardcoding 2x in the API. Changed in v2: - Rebase onto cryptodev/master - Add more comments to assembly - Reorganize some of the assembly slightly - Fix the claimed throughput improvement on arm64 - Fix incorrect kunmap order in fs/verity/verify.c - Adjust testmgr generation logic slightly - Explicitly check for INT_MAX before casting unsigned int to int - Mention SHA3 based parallel hashes - Mention AVX512-based approach Eric Biggers (8): crypto: shash - add support for finup_mb crypto: testmgr - generate power-of-2 lengths more often crypto: testmgr - add tests for finup_mb crypto: x86/sha256-ni - add support for finup_mb crypto: arm64/sha256-ce - add support for finup_mb 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 | 281 +++++++++++++- arch/arm64/crypto/sha2-ce-glue.c | 40 ++ arch/x86/crypto/sha256_ni_asm.S | 368 ++++++++++++++++++ arch/x86/crypto/sha256_ssse3_glue.c | 39 ++ crypto/shash.c | 60 +++ crypto/testmgr.c | 91 ++++- drivers/md/dm-verity-fec.c | 31 +- drivers/md/dm-verity-fec.h | 7 +- drivers/md/dm-verity-target.c | 563 ++++++++++++++++++++-------- drivers/md/dm-verity.h | 43 +-- fs/verity/fsverity_private.h | 5 + fs/verity/hash_algs.c | 32 +- fs/verity/open.c | 6 + fs/verity/verify.c | 177 +++++++-- include/crypto/hash.h | 45 ++- 15 files changed, 1543 insertions(+), 245 deletions(-) base-commit: ed265f7fd9a635d77c8022fc6d9a1b735dd4dfd7 -- 2.45.0