mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: iaa - Only set cache control when the device supports it
@ 2026-11-30  7:13 Fei Yu
  0 siblings, 0 replies; only message in thread
From: Fei Yu @ 2026-11-30  7:13 UTC (permalink / raw)
  To: Herbert Xu, linux-crypto
  Cc: Kristen Accardi, Vinicius Costa Gomes, David S . Miller,
	Tom Zanussi, Giovanni Cabiddu, linux-kernel

iaa_crypto sets IDXD_OP_FLAG_CC in every compress, decompress and
verify descriptor. Cache control is optional: GENCAP bit 2 (Cache
Control Support (Memory), cache_control_mem) tells whether the device
accepts CC=1. The IAA on Nova Lake does not advertise it (GENCAP
0x671f00801f1411), and fails each descriptor with status 0x11 (invalid
flags) and invalid_flags 0x100, so no request is ever offloaded:

  total_comp_calls: 654612
  total_completion_einval_errors: 654612

zswap then stores every page uncompressed, which hides the failure
apart from the error counter and a "cmp-rec" dump per request.

Set IDXD_OP_FLAG_CC only when the device advertises Cache Control
Support (Memory). The capability is read once when the IAA device is
added, and stored in struct iaa_device. Devices that support it, such
as the Sapphire Rapids IAA (GENCAP 0x71f10901f0105), keep the current
behavior.

Fixes: 2ec6761df889 ("crypto: iaa - Add support for deflate-iaa compression algorithm")
Cc: stable@vger.kernel.org
Signed-off-by: Fei Yu <fei.yu@intel.com>
---
Tested on Nova Lake (v7.3.4 based kernel, iaa_crypto and idxd built
out of tree with this patch): 7 rounds of 512 MB swapped out and in
through zswap with deflate-iaa, data checked with SHA-256 each round:
915727 HW compressions, 858471 HW decompressions, 0 einval or timeout
errors, 0 software decompressions. Without the patch, all 654612
compressions of the same test failed as shown above.

Tested on Sapphire Rapids (Ubuntu 6.17.0-42 kernel, iaa_crypto of
v6.17.13 with and without this patch, built out of tree): GENCAP
0x71f10901f0105 on all 8 IAAs, so CC stays set. An fprobe on
idxd_submit_desc() shows the same descriptor flags with and without
the patch (compress 0x1010c, decompress 0x10c, CC included). zswap with
deflate-iaa, 3 rounds of 512 MB each, data checked with SHA-256: no
einval or timeout errors, the same as without the patch.

 drivers/crypto/intel/iaa/iaa_crypto.h      |  3 +++
 drivers/crypto/intel/iaa/iaa_crypto_main.c | 16 +++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/intel/iaa/iaa_crypto.h b/drivers/crypto/intel/iaa/iaa_crypto.h
index 56985e395263..172f28aeb279 100644
--- a/drivers/crypto/intel/iaa/iaa_crypto.h
+++ b/drivers/crypto/intel/iaa/iaa_crypto.h
@@ -68,6 +68,9 @@ struct iaa_device {
 	struct list_head		list;
 	struct idxd_device		*idxd;
 
+	/* IDXD_OP_FLAG_CC if the device supports cache control, else 0 */
+	u32				cache_control;
+
 	struct iaa_device_compression_mode	*compression_modes[IAA_COMP_MODES_MAX];
 
 	int				n_wq;
diff --git a/drivers/crypto/intel/iaa/iaa_crypto_main.c b/drivers/crypto/intel/iaa/iaa_crypto_main.c
index c9ab4b83ae02..3824b2240311 100644
--- a/drivers/crypto/intel/iaa/iaa_crypto_main.c
+++ b/drivers/crypto/intel/iaa/iaa_crypto_main.c
@@ -545,6 +545,14 @@ static struct iaa_device *add_iaa_device(struct idxd_device *idxd)
 		return NULL;
 
 	iaa_device->idxd = idxd;
+	/*
+	 * Cache control (CC=1) hints the device to allocate its writes in the
+	 * cache. It is optional: a device that does not advertise Cache Control
+	 * Support (Memory) in GENCAP fails each descriptor with CC=1 with an
+	 * invalid flags error.
+	 */
+	if (idxd->hw.gen_cap.cache_control_mem)
+		iaa_device->cache_control = IDXD_OP_FLAG_CC;
 
 	list_add_tail(&iaa_device->list, &iaa_devices);
 
@@ -1194,7 +1202,7 @@ static int iaa_compress(struct crypto_tfm *tfm,	struct acomp_req *req,
 	desc = idxd_desc->iax_hw;
 
 	desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR |
-		IDXD_OP_FLAG_RD_SRC2_AECS | IDXD_OP_FLAG_CC;
+		IDXD_OP_FLAG_RD_SRC2_AECS | iaa_device->cache_control;
 	desc->opcode = IAX_OPCODE_COMPRESS;
 	desc->compr_flags = IAA_COMP_FLAGS;
 	desc->priv = 0;
@@ -1347,7 +1355,8 @@ static int iaa_compress_verify(struct crypto_tfm *tfm, struct acomp_req *req,
 
 	/* Verify (optional) - decompress and check crc, suppress dest write */
 
-	desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_CC;
+	desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR |
+		      iaa_device->cache_control;
 	desc->opcode = IAX_OPCODE_DECOMPRESS;
 	desc->decompr_flags = IAA_DECOMP_FLAGS | IAA_DECOMP_SUPPRESS_OUTPUT;
 	desc->priv = 0;
@@ -1431,7 +1440,8 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req,
 	}
 	desc = idxd_desc->iax_hw;
 
-	desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR | IDXD_OP_FLAG_CC;
+	desc->flags = IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR |
+		      iaa_device->cache_control;
 	desc->opcode = IAX_OPCODE_DECOMPRESS;
 	desc->max_dst_size = PAGE_SIZE;
 	desc->decompr_flags = IAA_DECOMP_FLAGS;

base-commit: 9fb9278d13dca54ce7ecd3254c7df8839e59f03d
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30  7:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  7:13 [PATCH] crypto: iaa - Only set cache control when the device supports it Fei Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®