[v2] drivers/crypto: cipher buffer alignment check

Message ID 20230905112125.5735-1-venkatx.sivaramakrishnan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series [v2] drivers/crypto: cipher buffer alignment check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Sivaramakrishnan Venkat Sept. 5, 2023, 11:21 a.m. UTC
  Cipher length alignment checked for 3DES-CBC and AES-CBC to avoid slice
hang error in QAT CPM1.8

Signed-off-by: Sivaramakrishnan VenkatX <venkatx.sivaramakrishnan@intel.com>
--
V2:
Set auth_length = 0 for NULL CIPHER NULL AUTH operation.
---
 drivers/crypto/qat/dev/qat_crypto_pmd_gens.h | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
  

Comments

Power, Ciara Sept. 19, 2023, 2:41 p.m. UTC | #1
Hi Venkat,

> -----Original Message-----
> From: Sivaramakrishnan VenkatX <venkatx.sivaramakrishnan@intel.com>
> Sent: Tuesday, September 5, 2023 12:21 PM
> To: Ji, Kai <kai.ji@intel.com>
> Cc: dev@dpdk.org; Sivaramakrishnan, VenkatX
> <venkatx.sivaramakrishnan@intel.com>
> Subject: [PATCH v2] drivers/crypto: cipher buffer alignment check
> 
> Cipher length alignment checked for 3DES-CBC and AES-CBC to avoid slice
> hang error in QAT CPM1.8
> 
> Signed-off-by: Sivaramakrishnan VenkatX
> <venkatx.sivaramakrishnan@intel.com>
> --
> V2:
> Set auth_length = 0 for NULL CIPHER NULL AUTH operation.

Acked-by: Ciara Power <ciara.power@intel.com>
  
Akhil Goyal Sept. 19, 2023, 7:46 p.m. UTC | #2
> Subject: [EXT] RE: [PATCH v2] drivers/crypto: cipher buffer alignment check
> 
Title should be " crypto/qat: check cipher buffer alignment "

> 
> > -----Original Message-----
> > From: Sivaramakrishnan VenkatX <venkatx.sivaramakrishnan@intel.com>
> > Sent: Tuesday, September 5, 2023 12:21 PM
> > To: Ji, Kai <kai.ji@intel.com>
> > Cc: dev@dpdk.org; Sivaramakrishnan, VenkatX
> > <venkatx.sivaramakrishnan@intel.com>
> > Subject: [PATCH v2] drivers/crypto: cipher buffer alignment check
> >
> > Cipher length alignment checked for 3DES-CBC and AES-CBC to avoid slice
> > hang error in QAT CPM1.8
> >
> > Signed-off-by: Sivaramakrishnan VenkatX
> > <venkatx.sivaramakrishnan@intel.com>

Also change your signoff to 
Signed-off-by: Sivaramakrishnan Venkat <venkatx.sivaramakrishnan@intel.com>

> > --
> > V2:
> > Set auth_length = 0 for NULL CIPHER NULL AUTH operation.
> 
> Acked-by: Ciara Power <ciara.power@intel.com>

With above changes,
Applied to dpdk-next-crypto
  

Patch

diff --git a/drivers/crypto/qat/dev/qat_crypto_pmd_gens.h b/drivers/crypto/qat/dev/qat_crypto_pmd_gens.h
index cab7e214c0..37647374d5 100644
--- a/drivers/crypto/qat/dev/qat_crypto_pmd_gens.h
+++ b/drivers/crypto/qat/dev/qat_crypto_pmd_gens.h
@@ -10,6 +10,13 @@ 
 #include "qat_sym_session.h"
 #include "qat_sym.h"
 
+#define AES_OR_3DES_MISALIGNED (ctx->qat_mode == ICP_QAT_HW_CIPHER_CBC_MODE && \
+			((((ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES128) || \
+			(ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES192) || \
+			(ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES256)) && \
+			(cipher_param->cipher_length % ICP_QAT_HW_AES_BLK_SZ)) || \
+			((ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES) && \
+			(cipher_param->cipher_length % ICP_QAT_HW_3DES_BLK_SZ))))
 #define QAT_SYM_DP_GET_MAX_ENQ(q, c, n) \
 	RTE_MIN((q->max_inflights - q->enqueued + q->dequeued - c), n)
 
@@ -704,6 +711,21 @@  enqueue_one_chain_job_gen1(struct qat_sym_session *ctx,
 	auth_param->auth_off = ofs.ofs.auth.head;
 	auth_param->auth_len = auth_len;
 	auth_param->auth_res_addr = digest->iova;
+	/* Input cipher length alignment requirement for 3DES-CBC and AES-CBC.
+	 * For 3DES-CBC cipher algo, ESP Payload size requires 8 Byte aligned.
+	 * For AES-CBC cipher algo, ESP Payload size requires 16 Byte aligned.
+	 * The alignment should be guaranteed by the ESP package padding field
+	 * according to the RFC4303. Under this condition, QAT will pass through
+	 * chain job as NULL cipher and NULL auth operation and report misalignment
+	 * error detected.
+	 */
+	if (AES_OR_3DES_MISALIGNED) {
+		QAT_LOG(ERR, "Input cipher length alignment error detected.\n");
+		ctx->qat_cipher_alg = ICP_QAT_HW_CIPHER_ALGO_NULL;
+		ctx->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_NULL;
+		cipher_param->cipher_length = 0;
+		auth_param->auth_len = 0;
+	}
 
 	switch (ctx->qat_hash_alg) {
 	case ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2: