All of lore.kernel.org
 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 5/8] crypto: amcc - don't use memcpy() on the coherent SA and state record
Date: Thu, 26 Nov 2026 20:04:20 -0800	[thread overview]
Message-ID: <20261127040423.1023233-6-rosenp@gmail.com> (raw)
In-Reply-To: <20261127040423.1023233-1-rosenp@gmail.com>

crypto4xx_build_pd() copies the SA and the IV into the shadow SA and
state record pools with memcpy(). Those pools come from
dma_alloc_coherent(), which is cache-inhibited on the non-coherent 4xx
cores. The 32-bit powerpc memcpy() zeroes each whole destination cache
line with dcbz before filling it, and dcbz on cache-inhibited memory
raises an alignment exception. The kernel emulates it, so the copy
still works, but each such copy takes a trap, and the first one
warns:

  WARNING: CPU: 0 PID: 2434 at fix_alignment+0x184/0x1ac
  ...
  ---- interrupt: 600 at memcpy+0x88/0x10c
  LR [e4f9b88c] crypto4xx_build_pd+0x1c8/0x854 [crypto4xx]

Copy both with word stores instead. Every caller passes word-aligned
buffers whose lengths are multiples of 4.

Fixes: 049359d65527 ("crypto: amcc - Add crypt4xx driver")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/crypto/amcc/crypto4xx_core.c |  5 +++--
 drivers/crypto/amcc/crypto4xx_core.h | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 0dc23d29845e..cb9b36d6f4fc 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -782,10 +782,11 @@ int crypto4xx_build_pd(struct crypto_async_request *req,
 	pd_uinfo->async_req = req;
 
 	if (iv_len)
-		memcpy(pd_uinfo->sr_va->save_iv, iv, iv_len);
+		crypto4xx_memcpy_to_coherent(pd_uinfo->sr_va->save_iv, iv,
+					     iv_len);
 
 	sa = pd_uinfo->sa_va;
-	memcpy(sa, req_sa, sa_len * 4);
+	crypto4xx_memcpy_to_coherent(sa, req_sa, sa_len * 4);
 
 	sa->sa_command_1.bf.hash_crypto_offset = (assoclen >> 2);
 	offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(sa);
diff --git a/drivers/crypto/amcc/crypto4xx_core.h b/drivers/crypto/amcc/crypto4xx_core.h
index 66a95733c86d..294a57b77733 100644
--- a/drivers/crypto/amcc/crypto4xx_core.h
+++ b/drivers/crypto/amcc/crypto4xx_core.h
@@ -209,6 +209,24 @@ static inline void crypto4xx_memcpy_swab32(u32 *dst, const void *buf,
 	}
 }
 
+/*
+ * The shadow SA and state record pools come from dma_alloc_coherent(),
+ * which is cache-inhibited on the non-coherent 4xx cores. memcpy() zeroes
+ * whole destination cache lines with dcbz, and dcbz on cache-inhibited
+ * memory takes an alignment exception, so copy word by word instead.
+ * WRITE_ONCE() keeps the compiler from turning the loop back into memcpy().
+ * Both pointers must be word aligned and len a multiple of 4.
+ */
+static inline void crypto4xx_memcpy_to_coherent(void *dst, const void *src,
+						size_t len)
+{
+	u32 *d = dst;
+	const u32 *s = src;
+
+	for (; len >= sizeof(u32); len -= sizeof(u32))
+		WRITE_ONCE(*d++, *s++);
+}
+
 static inline void crypto4xx_memcpy_from_le32(u32 *dst, const void *buf,
 					      size_t len)
 {
-- 
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 ` [PATCH 4/8] crypto: amcc - set up the TRNG before registering the algorithms Rosen Penev
2026-11-27  4:04 ` Rosen Penev [this message]
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-6-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 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.