All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: tcrypt - restore request length in multi-update ahash speed tests
@ 2026-12-05 14:54 ` Rani Hod via B4 Relay
  0 siblings, 0 replies; 3+ messages in thread
From: Rani Hod @ 2026-12-05 14:54 UTC (permalink / raw)
  To: David S. Miller, Herbert Xu; +Cc: linux-crypto

Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in
API"), crypto_ahash_final() is an inline wrapper that sets req->nbytes
to zero and calls crypto_ahash_finup().

test_ahash_speed_common() sets the request length once with
ahash_request_set_crypt(), and test_ahash_jiffies() and
test_ahash_cycles() then run several init/update/final rounds on that
request. The final() at the end of the first round clears req->nbytes,
so every update() in later rounds hashes zero bytes. The results are
still reported as if blen bytes had been hashed in each round, which
inflates the multi-update figures (plen < blen) by up to two orders of
magnitude. The single-update cases (plen == blen) go through
crypto_ahash_digest() and are not affected.

For example, sha256-lib under QEMU (x86_64, TCG), "tcrypt.mode=404
tcrypt.sec=1", in bytes/sec:

  test  block  per update      before       after
    15   4096        1024  1652248576    46739456
    16   4096        4096    49266688    52375552
    20   8192        4096  3241795584    52166656
    21   8192        8192    45522944    54394880

Tests 16 and 21 are single-update cases and serve as a baseline.

The cycles mode (tcrypt.sec=0) shows the same: test 15 went from
1 cycle/byte to 92 cycles/byte, against 106 cycles/byte for test 16.

Restore the request length at the start of every round. In
test_ahash_cycles() this is done before get_cycles(), so it is not
counted in the measurement.

The problem was found while testing an out-of-tree hash driver. A
counter in the driver showed that a whole tcrypt run issued only as
many update requests to the hardware as the first round needs. The
analysis, the fix and this changelog were prepared with the help of an
AI coding assistant (Claude Opus 5.5) and reviewed by the submitter.

Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Rani Hod <rani.hod@gmail.com>
---
Testing: x86_64 defconfig with CONFIG_CRYPTO_BENCHMARK=y, booted under
QEMU (TCG), "tcrypt.mode=404" with sec=1 and sec=0, with and without
this patch (the numbers above). crypto/tcrypt.o builds without warnings
with W=1.

A backport to v6.18.64 was also run on a Banana Pi BPI-RV2 (Siflower
SF21H8898, riscv64) with an out-of-tree driver for the SoC's hash
engine, "mode=400 alg=siflower-ce-sha1 sec=1". For each block size, the
multi-update tests now report lower throughput than the single-update
test, as expected, since they hash the same data in more calls; before
this patch they reported higher throughput. The driver's count of update
requests sent to the hardware (418263) matches exactly the number
expected from the reported opers/sec of each test.

Not tested with any in-tree hardware ahash driver.

The bug only affects benchmark output, so I have not added a Cc to
stable; v6.16 and later are affected if you want it backported.
---
 crypto/tcrypt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e6834bdde9b99232134c82e04e0270ccf8e1df10..2a137d63476f3bededd62eee048f63cd7bd746f1 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -763,6 +763,8 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
 
 	for (start = jiffies, end = start + secs * HZ, bcount = 0;
 	     time_before(jiffies, end); bcount++) {
+		/* crypto_ahash_final() clears req->nbytes, so restore it */
+		ahash_request_set_crypt(req, req->src, out, plen);
 		ret = do_one_ahash_op(treq, crypto_ahash_init(req));
 		if (ret)
 			return ret;
@@ -834,6 +836,7 @@ static int test_ahash_cycles(struct tcrypt_ahash_request *treq, int blen,
 
 	/* Warm-up run. */
 	for (i = 0; i < 4; i++) {
+		ahash_request_set_crypt(req, req->src, out, plen);
 		ret = do_one_ahash_op(treq, crypto_ahash_init(req));
 		if (ret)
 			goto out;
@@ -851,6 +854,8 @@ static int test_ahash_cycles(struct tcrypt_ahash_request *treq, int blen,
 	for (i = 0; i < 8; i++) {
 		cycles_t start, end;
 
+		ahash_request_set_crypt(req, req->src, out, plen);
+
 		start = get_cycles();
 
 		ret = do_one_ahash_op(treq, crypto_ahash_init(req));

---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261205-tcrypt-ahash-nbytes-d8b9248222d6

Best regards,
-- 
Rani Hod <rani.hod@gmail.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] crypto: tcrypt - restore request length in multi-update ahash speed tests
@ 2026-12-05 14:54 ` Rani Hod via B4 Relay
  0 siblings, 0 replies; 3+ messages in thread
From: Rani Hod via B4 Relay @ 2026-12-05 14:54 UTC (permalink / raw)
  To: David S. Miller, Herbert Xu; +Cc: linux-crypto

From: Rani Hod <rani.hod@gmail.com>

Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in
API"), crypto_ahash_final() is an inline wrapper that sets req->nbytes
to zero and calls crypto_ahash_finup().

test_ahash_speed_common() sets the request length once with
ahash_request_set_crypt(), and test_ahash_jiffies() and
test_ahash_cycles() then run several init/update/final rounds on that
request. The final() at the end of the first round clears req->nbytes,
so every update() in later rounds hashes zero bytes. The results are
still reported as if blen bytes had been hashed in each round, which
inflates the multi-update figures (plen < blen) by up to two orders of
magnitude. The single-update cases (plen == blen) go through
crypto_ahash_digest() and are not affected.

For example, sha256-lib under QEMU (x86_64, TCG), "tcrypt.mode=404
tcrypt.sec=1", in bytes/sec:

  test  block  per update      before       after
    15   4096        1024  1652248576    46739456
    16   4096        4096    49266688    52375552
    20   8192        4096  3241795584    52166656
    21   8192        8192    45522944    54394880

Tests 16 and 21 are single-update cases and serve as a baseline.

The cycles mode (tcrypt.sec=0) shows the same: test 15 went from
1 cycle/byte to 92 cycles/byte, against 106 cycles/byte for test 16.

Restore the request length at the start of every round. In
test_ahash_cycles() this is done before get_cycles(), so it is not
counted in the measurement.

The problem was found while testing an out-of-tree hash driver. A
counter in the driver showed that a whole tcrypt run issued only as
many update requests to the hardware as the first round needs. The
analysis, the fix and this changelog were prepared with the help of an
AI coding assistant (Claude Opus 5.5) and reviewed by the submitter.

Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Rani Hod <rani.hod@gmail.com>
---
Testing: x86_64 defconfig with CONFIG_CRYPTO_BENCHMARK=y, booted under
QEMU (TCG), "tcrypt.mode=404" with sec=1 and sec=0, with and without
this patch (the numbers above). crypto/tcrypt.o builds without warnings
with W=1.

A backport to v6.18.64 was also run on a Banana Pi BPI-RV2 (Siflower
SF21H8898, riscv64) with an out-of-tree driver for the SoC's hash
engine, "mode=400 alg=siflower-ce-sha1 sec=1". For each block size, the
multi-update tests now report lower throughput than the single-update
test, as expected, since they hash the same data in more calls; before
this patch they reported higher throughput. The driver's count of update
requests sent to the hardware (418263) matches exactly the number
expected from the reported opers/sec of each test.

Not tested with any in-tree hardware ahash driver.

The bug only affects benchmark output, so I have not added a Cc to
stable; v6.16 and later are affected if you want it backported.
---
 crypto/tcrypt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e6834bdde9b99232134c82e04e0270ccf8e1df10..2a137d63476f3bededd62eee048f63cd7bd746f1 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -763,6 +763,8 @@ static int test_ahash_jiffies(struct tcrypt_ahash_request *treq, int blen,
 
 	for (start = jiffies, end = start + secs * HZ, bcount = 0;
 	     time_before(jiffies, end); bcount++) {
+		/* crypto_ahash_final() clears req->nbytes, so restore it */
+		ahash_request_set_crypt(req, req->src, out, plen);
 		ret = do_one_ahash_op(treq, crypto_ahash_init(req));
 		if (ret)
 			return ret;
@@ -834,6 +836,7 @@ static int test_ahash_cycles(struct tcrypt_ahash_request *treq, int blen,
 
 	/* Warm-up run. */
 	for (i = 0; i < 4; i++) {
+		ahash_request_set_crypt(req, req->src, out, plen);
 		ret = do_one_ahash_op(treq, crypto_ahash_init(req));
 		if (ret)
 			goto out;
@@ -851,6 +854,8 @@ static int test_ahash_cycles(struct tcrypt_ahash_request *treq, int blen,
 	for (i = 0; i < 8; i++) {
 		cycles_t start, end;
 
+		ahash_request_set_crypt(req, req->src, out, plen);
+
 		start = get_cycles();
 
 		ret = do_one_ahash_op(treq, crypto_ahash_init(req));

---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261205-tcrypt-ahash-nbytes-d8b9248222d6

Best regards,
-- 
Rani Hod <rani.hod@gmail.com>



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] crypto: tcrypt - restore request length in multi-update ahash speed tests
  2026-12-05 14:54 ` Rani Hod via B4 Relay
  (?)
@ 2026-12-05 15:08 ` sashiko-bot
  -1 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-05 15:08 UTC (permalink / raw)
  To: Rani Hod, David S. Miller, Herbert Xu; +Cc: linux-crypto

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: tcrypt: non-standard Co-authored-by trailer in commit
  message
--

commit 6e380fecad3b52fc13d296cb479c4a08d5ee0df9
Author: Rani Hod <rani.hod@gmail.com>

> crypto: tcrypt - restore request length in multi-update ahash speed tests
>
> Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in
> API"), crypto_ahash_final() is an inline wrapper that sets req->nbytes
> to zero and calls crypto_ahash_finup().
>
> test_ahash_speed_common() sets the request length once with
> ahash_request_set_crypt(), and test_ahash_jiffies() and
> test_ahash_cycles() then run several init/update/final rounds on that
> request. The final() at the end of the first round clears req->nbytes,
> so every update() in later rounds hashes zero bytes. The results are
> still reported as if blen bytes had been hashed in each round, which
> inflates the multi-update figures (plen < blen) by up to two orders of
> magnitude. The single-update cases (plen == blen) go through
> crypto_ahash_digest() and are not affected.
>
> For example, sha256-lib under QEMU (x86_64, TCG), "tcrypt.mode=404
> tcrypt.sec=1", in bytes/sec:
>
>   test  block  per update      before       after
>     15   4096        1024  1652248576    46739456
>     16   4096        4096    49266688    52375552
>     20   8192        4096  3241795584    52166656
>     21   8192        8192    45522944    54394880
>
> Tests 16 and 21 are single-update cases and serve as a baseline.
>
> The cycles mode (tcrypt.sec=0) shows the same: test 15 went from
> 1 cycle/byte to 92 cycles/byte, against 106 cycles/byte for test 16.
>
> Restore the request length at the start of every round. In
> test_ahash_cycles() this is done before get_cycles(), so it is not
> counted in the measurement.
>
> The problem was found while testing an out-of-tree hash driver. A
> counter in the driver showed that a whole tcrypt run issued only as
> many update requests to the hardware as the first round needs. The
> analysis, the fix and this changelog were prepared with the help of an
> AI coding assistant (Claude Opus 5.5) and reviewed by the submitter.
>
> Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
> Signed-off-by: Rani Hod <rani.hod@gmail.com>

[Severity: Low]
Should the Co-authored-by: trailer be dropped?

scripts/checkpatch.pl warns that Co-authored-by: is a non-standard signature.
Kernel co-authorship uses Co-developed-by:, which requires a matching
Signed-off-by: to certify the Developer Certificate of Origin, and per
Documentation/process/coding-assistants.rst AI agents must not add one.

Since AI assistance is already disclosed in the changelog body, removing this
trailer avoids the checkpatch warning.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-tcrypt-ahash-nbytes-v1-1-6ab5355c2ba0@gmail.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-05 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 14:54 [PATCH] crypto: tcrypt - restore request length in multi-update ahash speed tests Rani Hod
2026-12-05 14:54 ` Rani Hod via B4 Relay
2026-12-05 15:08 ` sashiko-bot

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.