Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-crypto@vger.kernel.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	James Hsiao <jhsiao@amcc.com>, Rosen Penev <rosenp@gmail.com>,
	Christian Lamparter <chunkeey@gmail.com>
Subject: [PATCH 4/8] crypto: amcc - set up the TRNG before registering the algorithms
Date: Thu, 26 Nov 2026 20:04:19 -0800	[thread overview]
Message-ID: <20261127040423.1023233-5-rosenp@gmail.com> (raw)
In-Reply-To: <20261127040423.1023233-1-rosenp@gmail.com>

crypto4xx_probe() registers the algorithms and then probes the TRNG. If
ppc4xx_trng_probe() fails, the error path unregisters the algorithms
again. With self-tests enabled, a test that started on registration may
still hold the algorithm and have requests on the engine at that
point. crypto_unregister_alg() then warns that the algorithm is busy,
the driver frees it under the running test, and the IRQ and descriptor
rings are torn down with test requests still in flight. With a TRNG
failure injected on an APM82181, each algorithm hits:

  WARNING: CPU: 0 PID: 2547 at crypto_unregister_alg+0xfc/0x158

and the module is left with references it never drops.

Probe the TRNG first and register the algorithms as the last step, so
nothing can fail after registration. crypto4xx_register_alg() only
fails before registering anything, so its error path just tears down
the TRNG again.

Fixes: f033e862a32c ("crypto: crypto4xx - use int for ppc4xx_trng_probe()")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/crypto/amcc/crypto4xx_core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 6131fd6c0607..0dc23d29845e 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1347,19 +1347,23 @@ static int crypto4xx_probe(struct platform_device *ofdev)
 	/* need to setup pdr, rdr, gdr and sdr before this */
 	crypto4xx_hw_init(core_dev->dev);
 
-	/* Register security algorithms with Linux CryptoAPI */
-	rc = crypto4xx_register_alg(core_dev->dev, crypto4xx_alg,
-			       ARRAY_SIZE(crypto4xx_alg));
+	rc = ppc4xx_trng_probe(core_dev);
 	if (rc)
 		goto err_irq;
 
-	rc = ppc4xx_trng_probe(core_dev);
+	/*
+	 * Register security algorithms with Linux CryptoAPI. This must be
+	 * the last step: their self-tests may start running on the engine
+	 * right away, so nothing after this point may fail and unwind.
+	 */
+	rc = crypto4xx_register_alg(core_dev->dev, crypto4xx_alg,
+			       ARRAY_SIZE(crypto4xx_alg));
 	if (rc)
-		goto err_crypto;
+		goto err_trng;
 	return 0;
 
-err_crypto:
-	crypto4xx_unregister_alg(core_dev->dev);
+err_trng:
+	ppc4xx_trng_remove(core_dev);
 err_irq:
 	free_irq(core_dev->irq, core_dev);
 err_tasklet:
-- 
2.56.1


  parent reply	other threads:[~2026-11-27  4:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  4:04 [PATCH 0/8] crypto: amcc - fixes for the crypto4xx driver Rosen Penev
2026-11-27  4:04 ` [PATCH 1/8] crypto: amcc - fix scatter ring full check Rosen Penev
2026-11-27  4:04 ` [PATCH 2/8] crypto: amcc - fix missing DMA memory barriers in descriptor handling Rosen Penev
2026-11-27  4:04 ` [PATCH 3/8] crypto: amcc - allocate all algorithm wrappers before registering Rosen Penev
2026-11-27  4:04 ` Rosen Penev [this message]
2026-11-27  4:04 ` [PATCH 5/8] crypto: amcc - don't use memcpy() on the coherent SA and state record Rosen Penev
2026-11-27  4:04 ` [PATCH 6/8] crypto: amcc - fix the DMA mappings of the source and destination Rosen Penev
2026-11-27  4:04 ` [PATCH 7/8] crypto: amcc - fix the inverted AEAD error ratelimit Rosen Penev
2026-11-27  4:04 ` [PATCH 8/8] crypto: amcc - wipe the SA key material when freeing it Rosen Penev

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=20261127040423.1023233-5-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=chunkeey@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=jhsiao@amcc.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox