From: Eric Biggers <ebiggers@kernel.org>
To: Laveesh Bansal <laveeshb@laveeshbansal.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org
Subject: Re: [PATCH] crypto: adiantum - Eliminate slab memory allocation in setkey
Date: Fri, 27 Nov 2026 10:44:07 -0800 [thread overview]
Message-ID: <20261127184407.GB1974@quark> (raw)
In-Reply-To: <20261127015345.33904-1-laveeshb@laveeshbansal.com>
On Thu, Nov 26, 2026 at 05:53:45PM -0800, Laveesh Bansal wrote:
> I tested this on x86_64, arm64 and s390x (big-endian, emulated in QEMU) --
> all on top of mainline c44104f3642d.
>
> On Tue, Nov 24, 2026 at 05:35:53PM -0800, Eric Biggers wrote:
> > + memmove(tctx->nh_key,
> > + &tctx->derived_keys[BLOCKCIPHER_KEY_SIZE +
> > + 2 * POLY1305_BLOCK_SIZE],
> > + NH_KEY_BYTES);
>
> I checked that this gives the same ciphertext as before. On each machine
> I compared it with and without the patch using 400 seeded random keys,
> tweaks and plaintexts for each of adiantum(xchacha12,aes) and
> adiantum(xchacha20,aes), including re-keying one tfm against a fresh one.
> The digests were identical with and without the patch, and the same on
> all three machines. I saw no round trip or re-key mismatches.
>
> > + SYNC_SKCIPHER_REQUEST_ON_STACK(
> > + req, (struct crypto_sync_skcipher *)tctx->streamcipher);
>
> I measured the stack cost. With -fstack-usage, the frame of
> adiantum_setkey() grows from 64 to 640 bytes on arm64 (gcc 13.3.0; 96 to
> 896 with KASAN) and from 72 to 872 bytes on x86_64 with KASAN (gcc
> 15.2.0), under the 2048 byte frame warning limit.
>
> I also ran the stack tracer on arm64 (KASAN, 32 KiB stacks,
> with v3 of my blk-crypto patch also applied:
> https://lore.kernel.org/all/20261125081417.77674-1-laveeshb@laveeshbansal.com/)
> under the f2fs/adiantum workload with memory pressure.
> The deepest stack at any adiantum, chacha or blk-crypto function was
> 7784 bytes, going through adiantum_setkey() via inode eviction in
> reclaim. That was one run and I did not run the tracer on x86_64.
>
> I think this is an acceptable trade. The old kzalloc() could enter direct
> reclaim from setkey, and an allocation in the same fallback I/O path (the
> bio encryption) used about 4 KiB of stack in reclaim in the same
> workload. The new frame adds 576 to 800 bytes, mostly the on-stack
> request (a fixed 384 bytes plus header).
>
> A couple of other results:
>
> - The lockdep cycle from the blk-crypto report is gone with this patch.
> In my f2fs/adiantum workload under memory pressure the base kernel hit
> it in all 3 runs on arm64, and lockdep recorded the &profile->lock to
> fs_reclaim dependency. With only this patch I got none and lockdep no
> longer recorded that dependency. I also got none with
> CRYPTO_SELFTESTS_FULL.
> On x86_64 the base hit the cycle in all runs - 6 across 2 hosts.
> With only this patch I got none,
> and also none with v3 of my patch on top. I saw no hung task or
> KASAN reports in any of the runs with the patch.
>
> - CRYPTO_SELFTESTS: I did not get any failures, with and without
> CRYPTO_SELFTESTS_FULL. The WARN_ON in
> adiantum_init_tfm() did not fire in any of my runs.
>
> Tested-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
Thanks. Later we should shrink the required stack space by switching
from crypto_skcipher to the ChaCha library.
(SYNC_SKCIPHER_REQUEST_ON_STACK() uses way more stack space than
needed.) But that would be a separate cleanup, and the stack usage from
SYNC_SKCIPHER_REQUEST_ON_STACK() is tolerable for now.
- Eric
prev parent reply other threads:[~2026-11-27 18:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 1:35 [PATCH] crypto: adiantum - Eliminate slab memory allocation in setkey Eric Biggers
2026-11-27 1:53 ` Laveesh Bansal
2026-11-27 18:44 ` Eric Biggers [this message]
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=20261127184407.GB1974@quark \
--to=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=laveeshb@laveeshbansal.com \
--cc=linux-crypto@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.