From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
x86@kernel.org, Antonio Quartulli <antonio@mandelbit.com>,
Eric Biggers <ebiggers@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH 01/11] crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths
Date: Sun, 29 Nov 2026 12:02:35 -0800 [thread overview]
Message-ID: <20261129200245.146503-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20261129200245.146503-1-ebiggers@kernel.org>
The linear fast paths in crypto_aes_cbc_cts_{en,de}crypt() and
crypto_aes_xts_{en,de}crypt() write directly to sg_virt(req->dst)
without going through scatterwalk_done_dst(), so they fail to flush the
dcache on architectures where ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE is true.
Add a small __always_inline helper sg_flush_dcache() and call it from
those fast paths. When !ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE, the helper
compiles out completely.
Fixes: 20df21a482aa ("crypto: aes - Add CBC and CBC-CTS support using library")
Fixes: 94efa0c9fb36 ("crypto: aes - Add XTS support using library")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
crypto/aes.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/crypto/aes.c b/crypto/aes.c
index a2db6351feefa..c4541f5bc6e32 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -240,6 +240,19 @@ skcipher_request_is_linear_lowmem(const struct skcipher_request *req)
req->src->length >= req->cryptlen;
}
+/*
+ * Flush the dcache for a linear region [off, off + len) within a single
+ * scatterlist element @sg. This must be called after writing directly to
+ * sg_virt(sg) without going through scatterwalk_done_dst().
+ */
+static __always_inline void sg_flush_dcache(struct scatterlist *sg,
+ unsigned int off, unsigned int len)
+{
+ if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE)
+ __scatterwalk_flush_dcache_pages(sg_page(sg), sg->offset + off,
+ len);
+}
+
/*
* Call crypt_func() (a function that operates on simple virtual addresses) zero
* or more times to en/decrypt 'cryptlen' bytes of data from the source
@@ -462,6 +475,7 @@ crypto_aes_cbc_cts_encrypt(struct skcipher_request *req)
/* Fast path */
aes_cbc_cts_encrypt(sg_virt(req->dst), sg_virt(req->src),
req->cryptlen, req->iv, key);
+ sg_flush_dcache(req->dst, 0, req->cryptlen);
return 0;
}
return crypto_aes_cbc_cts_crypt_nonlinear(req, /* enc= */ true);
@@ -479,6 +493,7 @@ crypto_aes_cbc_cts_decrypt(struct skcipher_request *req)
/* Fast path */
aes_cbc_cts_decrypt(sg_virt(req->dst), sg_virt(req->src),
req->cryptlen, req->iv, key);
+ sg_flush_dcache(req->dst, 0, req->cryptlen);
return 0;
}
return crypto_aes_cbc_cts_crypt_nonlinear(req, /* enc= */ false);
@@ -584,6 +599,7 @@ static __maybe_unused int crypto_aes_xts_encrypt(struct skcipher_request *req)
/* Fast path */
aes_xts_encrypt(sg_virt(req->dst), sg_virt(req->src),
req->cryptlen, req->iv, key, /* cont= */ false);
+ sg_flush_dcache(req->dst, 0, req->cryptlen);
return 0;
}
return crypto_aes_xts_crypt_nonlinear(req, /* enc= */ true);
@@ -600,6 +616,7 @@ static __maybe_unused int crypto_aes_xts_decrypt(struct skcipher_request *req)
/* Fast path */
aes_xts_decrypt(sg_virt(req->dst), sg_virt(req->src),
req->cryptlen, req->iv, key, /* cont= */ false);
+ sg_flush_dcache(req->dst, 0, req->cryptlen);
return 0;
}
return crypto_aes_xts_crypt_nonlinear(req, /* enc= */ false);
--
2.56.1
next prev parent reply other threads:[~2026-11-29 20:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 20:02 [PATCH 00/11] Migrate x86_64 AES-GCM code into library Eric Biggers
2026-11-29 20:02 ` Eric Biggers [this message]
2026-11-29 20:02 ` [PATCH 02/11] lib/crypto: gf128hash: Link libgf128hash before libaes Eric Biggers
2026-11-29 20:02 ` [PATCH 03/11] lib/crypto: aes-gcm: Add one-shot AES-GCM arch hooks Eric Biggers
2026-11-29 20:02 ` [PATCH 04/11] crypto: aes - Add linear fast path for AES-GCM Eric Biggers
2026-11-29 20:02 ` [PATCH 05/11] lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with PCLMULQDQ and AVX Eric Biggers
2026-11-29 20:02 ` [PATCH 06/11] lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ and AVX2 Eric Biggers
2026-11-29 20:02 ` [PATCH 07/11] lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ and AVX512 Eric Biggers
2026-11-29 20:02 ` [PATCH 08/11] lib/crypto: x86/aes-gcm: Migrate AES-NI optimized code into library Eric Biggers
2026-11-29 20:02 ` [PATCH 09/11] lib/crypto: x86/aes-gcm: Migrate VAES+AVX2 " Eric Biggers
2026-11-29 20:02 ` [PATCH 10/11] lib/crypto: x86/aes-gcm: Migrate VAES+AVX512 " Eric Biggers
2026-11-29 20:02 ` [PATCH 11/11] crypto: x86/aesni-intel - Remove empty module Eric Biggers
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=20261129200245.146503-2-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=antonio@mandelbit.com \
--cc=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=x86@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