Skip to content

Optimize dm-verity and fsverity using multibuffer hashing

Eric Biggers dm-devel fsverity linux-arm-kernel linux-crypto lkml netdev 8 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest7 patches 18 repliesIn review
  2. v77 patches 1 replySuperseded
  3. v615 patches 1 replySuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v515 patches10 repliesSuperseded
v48 patches26 repliesSuperseded
v38 patches8 repliesSuperseded
v28 patches3 repliesSuperseded
v1 RFC8 patches3 repliesSuperseded

Changes in v8 from the cover letter

- Rebased onto v6.14-rc2 and updated cover letter.

Patches in v8 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7crypto: shash - add support for finup_mbcrypto/shash.c include/crypto/hash.h+109 -10 replies
2/7crypto: testmgr - add tests for finup_mbcrypto/testmgr.c+66 -70 replies
3/7crypto: x86/sha256-ni - add support for finup_mbarch/x86/crypto/sha256_ni_asm.S arch/x86/crypto/sha256_ssse3_glue.c+407 -00 replies
4/7crypto: arm64/sha256-ce - add support for finup_mbarch/arm64/crypto/sha2-ce-core.S arch/arm64/crypto/sha2-ce-glue.c+315 -60 replies
5/7fsverity: improve performance by using multibuffer hashingfs/verity/fsverity_private.h fs/verity/hash_algs.c fs/verity/verify.c+153 -310 replies
6/7dm-verity: reduce scope of real and wanted digestsdrivers/md/dm-verity-fec.c drivers/md/dm-verity-fec.h drivers/md/dm-verity-target.c +1 more+32 -290 replies
7/7dm-verity: improve performance by using multibuffer hashingdrivers/md/dm-verity-target.c drivers/md/dm-verity.h+147 -520 replies

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchSami TolvanenArd Biesheuvel
1/7R-b A-b
2/7R-b A-b
3/7R-b A-b
4/7R-b R-b A-b
5/7R-b A-b
6/7R-b A-b
7/7R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v8 thread

Cover letter [PATCH v8 0/7] Optimize dm-verity and fsverity using multibuffer hashing

[ This patchset keeps getting rejected by Herbert, who prefers a
complex, buggy, and slow alternative that shoehorns CPU-based hashing into the asynchronous hash API which is designed for off-CPU offload:
https://lore.kernel.org/linux-crypto/[email protected]/
This patchset is a much better way to do it though, and I've already been maintaining it downstream as it would not be reasonable to go the asynchronous hash route instead. Let me know if there are any objections to me taking this patchset through the fsverity tree, or at least patches 1-5 as the dm-verity patches could go in separately. ]

[ This patchset applies to v6.14-rc2 ]

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, as does the alternative ahash-based approach proposed by Herbert (e.g. see my responses at
https://lore.kernel.org/linux-crypto/[email protected]/
and
https://lore.kernel.org/linux-crypto/[email protected]/,
and the other discussion on v4
https://lore.kernel.org/linux-crypto/[email protected]/T/#t)
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-2 add crypto_shash_finup_mb() and tests for it.
- Patch 3-4 implement finup_mb on x86_64 and arm64, using an interleaving factor of 2.
- Patch 5 adds multibuffer hashing support to fsverity.
- Patch 6-7 add multibuffer hashing support to dm-verity.

This patchset increases raw SHA-256 hashing throughput by up to 98%, depending on the CPU (see patches for per-CPU results). The throughput of cold-cache reads from dm-verity and fsverity increases by around 35%.

Changed in v8:
- Rebased onto v6.14-rc2 and updated cover letter.

Changed in v7:
- Rebased onto v6.12-rc1 and dropped patches that were upstreamed.
- Added performance results for more CPUs.

Changed in v6:
- All patches: added Reviewed-by and Acked-by tags
- "crypto: testmgr - add tests for finup_mb": Whitespace fix
- "crypto: testmgr - generate power-of-2 lengths more often":
Fixed undefined behavior
- "fsverity: improve performance by using multibuffer hashing":
Simplified a comment
- "dm-verity: reduce scope of real and wanted digests":
Fixed mention of nonexistent function in commit message
- "dm-verity: improve performance by using multibuffer hashing":
Two small optimizations, and simplified a comment

Changed in v5:
- Reworked the dm-verity patches again. Split the preparation work into separate patches, fixed two bugs, and added some new cleanups.
- Other small cleanups

Changed in v4:
- Reorganized the fsverity and dm-verity code to have a unified code path for single-block vs. multi-block processing. For data blocks they now use only crypto_shash_finup_mb().

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 (7):
crypto: shash - add support for finup_mb
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: reduce scope of real and wanted digests
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                      |  58 +++++
 crypto/testmgr.c                    |  73 +++++-
 drivers/md/dm-verity-fec.c          |  19 +-
 drivers/md/dm-verity-fec.h          |   5 +-
 drivers/md/dm-verity-target.c       | 192 +++++++++++----
 drivers/md/dm-verity.h              |  34 +--
 fs/verity/fsverity_private.h        |   7 +
 fs/verity/hash_algs.c               |   8 +-
 fs/verity/verify.c                  | 169 ++++++++++---
 include/crypto/hash.h               |  52 +++-
 14 files changed, 1224 insertions(+), 121 deletions(-)

base-commit: a64dcfb451e254085a7daee5fe51bf22959d52d3

Signature · 1 line
2.48.1