Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Fei Yu <fei.yu@intel.com>
To: Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org
Cc: Kristen Accardi <kristen.c.accardi@intel.com>,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	"David S . Miller" <davem@davemloft.net>,
	Tom Zanussi <tom.zanussi@linux.intel.com>,
	Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] crypto: iaa - Only set cache control when the device supports it
Date: Mon, 30 Nov 2026 15:13:27 +0800	[thread overview]
Message-ID: <20261130071327.3120126-1-fei.yu@intel.com> (raw)

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


                 reply	other threads:[~2026-11-30  7:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261130071327.3120126-1-fei.yu@intel.com \
    --to=fei.yu@intel.com \
    --cc=davem@davemloft.net \
    --cc=giovanni.cabiddu@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=kristen.c.accardi@intel.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom.zanussi@linux.intel.com \
    --cc=vinicius.gomes@intel.com \
    /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