Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Timur Kussainov <kusainov.timur@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
	Corentin Labbe <clabbe@baylibre.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Heiko Stuebner <heiko@sntech.de>,
	linux-crypto@vger.kernel.org, linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Timur Kussainov <kusainov.timur@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/2] crypto: rockchip - fix inverted hash completion poll
Date: Sat, 28 Nov 2026 15:47:44 -0500	[thread overview]
Message-ID: <20261128204745.1044083-2-kusainov.timur@gmail.com> (raw)
In-Reply-To: <20261128204745.1044083-1-kusainov.timur@gmail.com>

Before commit 37bc22159c45 ("crypto: rockchip - use read_poll_timeout"),
rk_hash_run() waited for the hash engine with

	while (!CRYPTO_READ(tctx->dev, RK_CRYPTO_HASH_STS))
		udelay(10);

i.e. it spun until RK_CRYPTO_HASH_STS became non-zero (HASH_DONE set).
The conversion to readl_poll_timeout() inverted the condition to
"v == 0", so the poll now waits for the opposite state. The return value
was ignored at the time, so the bug went unnoticed: the digest was read
after the 1 ms timeout and happened to be correct.

Now that the timeout is reported as an error, every hash request fails
with "HASH idle timeout" and the rk-sha1/rk-sha256/rk-md5 self-tests
fail.

Poll for the HASH_DONE bit, as the original code did.

Tested on an ASUS Tinker Board (RK3288): the md5/sha1/sha256 self-tests
pass, and 300 digests of random buffers (4 bytes to 1 MiB) computed via
AF_ALG match the generic implementation.

Fixes: 37bc22159c45 ("crypto: rockchip - use read_poll_timeout")
Cc: stable@vger.kernel.org
Signed-off-by: Timur Kussainov <kusainov.timur@gmail.com>
---
 drivers/crypto/rockchip/rk3288_crypto_ahash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto_ahash.c b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
index d3482619a..922980b66 100644
--- a/drivers/crypto/rockchip/rk3288_crypto_ahash.c
+++ b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
@@ -325,7 +325,7 @@ static int rk_hash_run(struct crypto_engine *engine, void *breq)
 	 * complete.
 	 */
 	err = readl_poll_timeout(rkc->reg + RK_CRYPTO_HASH_STS, v,
-				 v == 0, 10, 1000);
+				 v & RK_CRYPTO_HASH_DONE, 10, 1000);
 	if (err) {
 		dev_err(rkc->dev, "HASH idle timeout\n");
 		goto theend;
-- 
2.47.3


  reply	other threads:[~2026-11-28 20:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 20:47 [PATCH 0/2] crypto: rockchip - fix hash timeouts and debugfs leak Timur Kussainov
2026-11-28 20:47 ` Timur Kussainov [this message]
2026-11-28 20:47 ` [PATCH 2/2] crypto: rockchip - fix debugfs leak when stats are disabled Timur Kussainov

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=20261128204745.1044083-2-kusainov.timur@gmail.com \
    --to=kusainov.timur@gmail.com \
    --cc=clabbe@baylibre.com \
    --cc=davem@davemloft.net \
    --cc=heiko@sntech.de \
    --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=linux-rockchip@lists.infradead.org \
    --cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox