Re: [PATCH v8 0/7] Optimize dm-verity and fsverity using multibuffer hashing
From: Eric Biggers
Date: Fri Feb 14 2025 - 01:14:11 EST
On Fri, Feb 14, 2025 at 12:56:10PM +0800, Herbert Xu wrote:
> On Thu, Feb 13, 2025 at 08:29:51PM -0800, Eric Biggers wrote:
> >
> > 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
>
> Well thanks for pointing out that deficiency. It would be good
> to be able to set the tfm in the macro, something like:
>
> #define SYNC_AHASH_REQUEST_ON_STACK(name, _tfm) \
> char __##name##_desc[sizeof(struct ahash_request) + \
> MAX_SYNC_AHASH_REQSIZE \
> ] CRYPTO_MINALIGN_ATTR; \
> struct ahash_request *name = (((struct ahash_request *)__##name##_desc)->base.tfm = crypto_sync_ahash_tfm((_tfm)), (void *)__##name##_desc)
I'm not sure what you intended with the second line, which looks like it won't
compile. The first line also shows that ahash_request has a large alignment for
DMA, which is irrelevant for CPU based crypto. And I'm not sure
__attribute__((aligned)) with that alignment on the stack even works reliably
all architectures; we've had issues with that in the past. So again you're
still proposing APIs with weird quirks caused by bolting CPU-based crypto
support onto an API designed for an obsolete style of hardware offload.
> > 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.
>
> I'm more than happy to rename ahash to hash. The only reason
> it was called ahash is to distinguish it from shash, which will
> no longer be necessary.
>
> > 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.
>
> I think you're again conflating two different concepts. Yes
> zswap/iaa are sleepable, but they're not synchronous.
Here's the compression in zswap:
comp_ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait);
And here's the decompression:
BUG_ON(crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait));
It waits synchronously for each request to complete.
It doesn't want an asynchronous API.
> iaa is also useable by IPsec, which is most certainly not sleepable.
The IAA driver doesn't actually support encryption, so that's a very bad start.
But even assuming it was added, the premise of IAA being helpful for IPsec seems
questionable. AES-GCM is already accelerated via the VAES and VPCLMULQDQ
instructions, performing at 10-30 GB/s per thread on recent processors. It's
hard to see how legacy-style offload can beat that in practice, when accounting
for all the driver overhead and the fact that memory often ends up as the
bottleneck these days. But of course for optimal IPsec performance you actually
need adapter-level offload (inline crypto) which does not use the crypto API at
all, so again the legacy-style offload support in the crypto API is irrelevant.
But, this is tangential to this discussion, since we can still keep the legacy
style hardware offload APIs around for the few users that think they want them.
The point is that we shouldn't let them drag down everyone else.
- Eric