fsverity: Use 2-way interleaved SHA-256 hashing when supported
authorEric Biggers <ebiggers@kernel.org>
Mon, 15 Sep 2025 16:08:19 +0000 (11:08 -0500)
committerEric Biggers <ebiggers@kernel.org>
Wed, 17 Sep 2025 18:10:04 +0000 (13:10 -0500)
commita1f692fd69ccdbe1e492d366788b63227d429753
tree470a18085c91c72d4f2873b5a05b81637c2ef532
parent4bd70b53bd7d554d402b2d8f5972a54e39a2e5ab
fsverity: Use 2-way interleaved SHA-256 hashing when supported

When the crypto library provides an optimized implementation of
sha256_finup_2x(), use it to interleave the hashing of pairs of data
blocks.  On some CPUs this nearly doubles hashing performance.  The
increase in overall throughput of cold-cache fsverity reads that I'm
seeing on arm64 and x86_64 is roughly 35% (though this metric is hard to
measure as it jumps around a lot).

For now this is only done on the verification path, and only for data
blocks, not Merkle tree blocks.  We could use sha256_finup_2x() on
Merkle tree blocks too, but that is less important as there aren't as
many Merkle tree blocks as data blocks, and that would require some
additional code restructuring.  We could also use sha256_finup_2x() to
accelerate building the Merkle tree, but verification performance is
more important.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250915160819.140019-7-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
fs/verity/verify.c