From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: fsverity@lists.linux.dev, linux-crypto@vger.kernel.org,
dm-devel@lists.linux.dev, x86@kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Mikulas Patocka <mpatocka@redhat.com>,
David Howells <dhowells@redhat.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH v8 0/7] Optimize dm-verity and fsverity using multibuffer hashing
Date: Thu, 13 Feb 2025 20:29:51 -0800 [thread overview]
Message-ID: <20250214042951.GB2771@sol.localdomain> (raw)
In-Reply-To: <Z669mxPsSpej6K6K@gondor.apana.org.au>
On Fri, Feb 14, 2025 at 11:50:51AM +0800, Herbert Xu wrote:
> On Thu, Feb 13, 2025 at 07:35:18PM -0800, Eric Biggers wrote:
> >
> > It absolutely is designed for an obsolete form of hardware offload. Have you
> > ever tried actually using it? Here's how to hash a buffer of data with shash:
> >
> > return crypto_shash_tfm_digest(tfm, data, size, out)
> >
> > ... and here's how to do it with the SHA-256 library, for what it's worth:
> >
> > sha256(data, size, out)
> >
> > and here's how to do it with ahash:
>
> Try the new virt ahash interface, and we could easily put the
> request object on the stack for sync algorithms:
>
> SYNC_AHASH_REQUEST_ON_STACK(req, alg);
>
> ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_SLEEP, NULL, NULL);
> ahash_request_set_virt(req, data, out, size);
>
> return crypto_ahash_digest(req);
That doesn't actually exist, and your code snippet is also buggy (undefined
behavior) because it never sets the tfm pointer in the ahash_request. So this
just shows that you still can't use your own proposed APIs correctly because
they're still too complex. Yes the virt address support would be an improvement
on current ahash, but it would still be bolted onto an interface that wasn't
designed for it. There would still be the weirdness of having to initialize so
many unnecessary fields in the request, and having "synchronous asynchronous
hashes" which is always a fun one to try to explain to people. The shash and
lib/crypto/ interfaces are much better as they do not have these problems.
> > What? GHASH is a polynomial hash function, so it is easily parallelizable. If
> > you precompute N powers of the hash key then you can process N blocks in
> > parallel. Check how the AES-GCM assembly code works; that's exactly what it
> > does. This is fundamentally different from message digests like SHA-* where the
> > blocks have to be processed serially.
>
> Fair enough.
>
> But there are plenty of other users who want batching, such as the
> zcomp with iaa, and I don't want everybody to invent their own API
> for the same thing.
Well, the IAA and zswap people want a batch_compress method that takes an array
of pages
(https://lore.kernel.org/linux-crypto/20250206072102.29045-3-kanchana.p.sridhar@intel.com/).
They do not seem to want the weird request chaining thing that you are trying to
make them use. batch_compress is actually quite similar to what I'm proposing,
just for compression instead of hashing. So there is no conflict with my
proposal, and in fact they complement each other as they arrived at a similar
conclusion. Hash and compression are different algorithm types, so they can
never use exactly the same API anyway, just similar ones. And FWIW, zswap is
synchronous, so yet again all the weird async stuff just gets in the way.
- Eric
next prev parent reply other threads:[~2025-02-14 4:31 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 15:47 [PATCH v8 0/7] Optimize dm-verity and fsverity using multibuffer hashing Eric Biggers
2025-02-12 15:47 ` [PATCH v8 1/7] crypto: shash - add support for finup_mb Eric Biggers
2025-02-12 15:47 ` [PATCH v8 2/7] crypto: testmgr - add tests " Eric Biggers
2025-02-12 15:47 ` [PATCH v8 3/7] crypto: x86/sha256-ni - add support " Eric Biggers
2025-02-12 15:47 ` [PATCH v8 4/7] crypto: arm64/sha256-ce " Eric Biggers
2025-02-12 15:47 ` [PATCH v8 5/7] fsverity: improve performance by using multibuffer hashing Eric Biggers
2025-02-12 15:47 ` [PATCH v8 6/7] dm-verity: reduce scope of real and wanted digests Eric Biggers
2025-02-12 15:47 ` [PATCH v8 7/7] dm-verity: improve performance by using multibuffer hashing Eric Biggers
2025-02-13 4:17 ` [PATCH v8 0/7] Optimize dm-verity and fsverity " Herbert Xu
2025-02-13 6:33 ` Eric Biggers
2025-02-14 2:44 ` Herbert Xu
2025-02-14 3:35 ` Eric Biggers
2025-02-14 3:50 ` Herbert Xu
2025-02-14 4:29 ` Eric Biggers [this message]
2025-02-14 4:56 ` Herbert Xu
2025-02-14 6:11 ` Eric Biggers
2025-02-14 10:50 ` Ard Biesheuvel
2025-02-15 17:04 ` Jakub Kicinski
2025-02-16 2:27 ` Herbert Xu
2025-02-16 3:26 ` Eric Biggers
2025-02-16 3:29 ` Herbert Xu
2025-02-17 17:40 ` Jakub Kicinski
2025-02-18 3:42 ` Herbert Xu
2025-02-18 7:41 ` Ard Biesheuvel
2025-02-18 8:02 ` Herbert Xu
2025-02-13 10:10 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250214042951.GB2771@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=agk@redhat.com \
--cc=ardb@kernel.org \
--cc=dhowells@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=fsverity@lists.linux.dev \
--cc=herbert@gondor.apana.org.au \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=samitolvanen@google.com \
--cc=snitzer@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox