[v2,1/4] crypto/qat: make immutable parameters constant

Message ID 20221020150940.62465-2-arkadiuszx.kusztal@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series crypto/qat: extend asymmetric crypto pmd |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing warning apply patch failure

Commit Message

Arkadiusz Kusztal Oct. 20, 2022, 3:09 p.m. UTC
  All pointers passed to functions that are not supposed
to have its data changed should be marked as constant.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 drivers/common/qat/qat_adf/qat_pke.h | 16 +++----
 drivers/common/qat/qat_device.c      |  2 +-
 drivers/common/qat/qat_device.h      |  4 +-
 drivers/crypto/qat/qat_asym.c        | 90 +++++++++++++++++-------------------
 drivers/crypto/qat/qat_ec.h          |  2 +-
 5 files changed, 54 insertions(+), 60 deletions(-)
  

Comments

Ji, Kai Oct. 20, 2022, 9:55 p.m. UTC | #1
Acked-by: Kai Ji <kai.ji@intel.com>

> -----Original Message-----
> From: Kusztal, ArkadiuszX <arkadiuszx.kusztal@intel.com>
> Sent: Thursday, October 20, 2022 4:10 PM
> To: dev@dpdk.org
> Cc: gakhil@marvell.com; Ji, Kai <kai.ji@intel.com>; Kusztal, ArkadiuszX
> <arkadiuszx.kusztal@intel.com>
> Subject: [PATCH v2 1/4] crypto/qat: make immutable parameters constant
> 
> All pointers passed to functions that are not supposed to have its data
> changed should be marked as constant.
> 
> Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
> ---
  

Patch

diff --git a/drivers/common/qat/qat_adf/qat_pke.h b/drivers/common/qat/qat_adf/qat_pke.h
index 6c12bfd989..00e2b776dc 100644
--- a/drivers/common/qat/qat_adf/qat_pke.h
+++ b/drivers/common/qat/qat_adf/qat_pke.h
@@ -50,13 +50,13 @@  get_modexp_function2(uint32_t bytesize)
 }
 
 static struct qat_asym_function
-get_modexp_function(struct rte_crypto_asym_xform *xform)
+get_modexp_function(const struct rte_crypto_asym_xform *xform)
 {
 	return get_modexp_function2(xform->modex.modulus.length);
 }
 
 static struct qat_asym_function
-get_modinv_function(struct rte_crypto_asym_xform *xform)
+get_modinv_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function = { };
 
@@ -137,7 +137,7 @@  get_modinv_function(struct rte_crypto_asym_xform *xform)
 }
 
 static struct qat_asym_function
-get_rsa_enc_function(struct rte_crypto_asym_xform *xform)
+get_rsa_enc_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function = { };
 
@@ -164,7 +164,7 @@  get_rsa_enc_function(struct rte_crypto_asym_xform *xform)
 }
 
 static struct qat_asym_function
-get_rsa_dec_function(struct rte_crypto_asym_xform *xform)
+get_rsa_dec_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function = { };
 
@@ -191,7 +191,7 @@  get_rsa_dec_function(struct rte_crypto_asym_xform *xform)
 }
 
 static struct qat_asym_function
-get_rsa_crt_function(struct rte_crypto_asym_xform *xform)
+get_rsa_crt_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function = { };
 	int nlen = xform->rsa.qt.p.length * 2;
@@ -219,7 +219,7 @@  get_rsa_crt_function(struct rte_crypto_asym_xform *xform)
 }
 
 static struct qat_asym_function
-get_ecdsa_verify_function(struct rte_crypto_asym_xform *xform)
+get_ecdsa_verify_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 
@@ -243,7 +243,7 @@  get_ecdsa_verify_function(struct rte_crypto_asym_xform *xform)
 }
 
 static struct qat_asym_function
-get_ecdsa_function(struct rte_crypto_asym_xform *xform)
+get_ecdsa_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 
@@ -267,7 +267,7 @@  get_ecdsa_function(struct rte_crypto_asym_xform *xform)
 }
 
 static struct qat_asym_function
-get_ecpm_function(struct rte_crypto_asym_xform *xform)
+get_ecpm_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 
diff --git a/drivers/common/qat/qat_device.c b/drivers/common/qat/qat_device.c
index 30e5cdb573..fcf08a70c4 100644
--- a/drivers/common/qat/qat_device.c
+++ b/drivers/common/qat/qat_device.c
@@ -453,7 +453,7 @@  qat_sym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused,
 
 __rte_weak int
 qat_asym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused,
-		struct qat_dev_cmd_param *qat_dev_cmd_param __rte_unused)
+		const struct qat_dev_cmd_param *qat_dev_cmd_param __rte_unused)
 {
 	return 0;
 }
diff --git a/drivers/common/qat/qat_device.h b/drivers/common/qat/qat_device.h
index d1512f3b89..26055b875f 100644
--- a/drivers/common/qat/qat_device.h
+++ b/drivers/common/qat/qat_device.h
@@ -158,8 +158,8 @@  qat_sym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused,
 		struct qat_dev_cmd_param *qat_dev_cmd_param);
 
 int
-qat_asym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused,
-		struct qat_dev_cmd_param *qat_dev_cmd_param);
+qat_asym_dev_create(struct qat_pci_device *qat_pci_dev,
+		const struct qat_dev_cmd_param *qat_dev_cmd_param);
 
 int
 qat_sym_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused);
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 05ca95319b..6a079424b9 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -129,7 +129,7 @@  cleanup_crt(struct qat_asym_op_cookie *cookie,
 
 static void
 cleanup(struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_xform *xform)
 {
 	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX)
 		cleanup_arrays(cookie, QAT_ASYM_MODEXP_NUM_IN_PARAMS,
@@ -178,7 +178,7 @@  check_zero(rte_crypto_param n)
 }
 
 static struct qat_asym_function
-get_asym_function(struct rte_crypto_asym_xform *xform)
+get_asym_function(const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 
@@ -198,10 +198,10 @@  get_asym_function(struct rte_crypto_asym_xform *xform)
 }
 
 static int
-modexp_set_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+modexp_set_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 	uint32_t alg_bytesize, func_id, in_bytesize;
@@ -248,8 +248,8 @@  modexp_set_input(struct rte_crypto_asym_op *asym_op,
 
 static uint8_t
 modexp_collect(struct rte_crypto_asym_op *asym_op,
-		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct qat_asym_op_cookie *cookie,
+		const struct rte_crypto_asym_xform *xform)
 {
 	rte_crypto_param n = xform->modex.modulus;
 	uint32_t alg_bytesize = cookie->alg_bytesize;
@@ -268,10 +268,10 @@  modexp_collect(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-modinv_set_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+modinv_set_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 	uint32_t alg_bytesize, func_id;
@@ -308,8 +308,8 @@  modinv_set_input(struct rte_crypto_asym_op *asym_op,
 
 static uint8_t
 modinv_collect(struct rte_crypto_asym_op *asym_op,
-		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct qat_asym_op_cookie *cookie,
+		const struct rte_crypto_asym_xform *xform)
 {
 	rte_crypto_param n = xform->modinv.modulus;
 	uint8_t *modinv_result = asym_op->modinv.result.data;
@@ -329,10 +329,10 @@  modinv_collect(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-rsa_set_pub_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+rsa_set_pub_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 	uint32_t alg_bytesize, func_id;
@@ -385,10 +385,10 @@  rsa_set_pub_input(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-rsa_set_priv_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+rsa_set_priv_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 	uint32_t alg_bytesize, func_id;
@@ -478,10 +478,10 @@  rsa_set_priv_input(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-rsa_set_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+rsa_set_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	qat_req->input_param_count =
 			QAT_ASYM_RSA_NUM_IN_PARAMS;
@@ -491,15 +491,15 @@  rsa_set_input(struct rte_crypto_asym_op *asym_op,
 	if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT ||
 			asym_op->rsa.op_type ==
 				RTE_CRYPTO_ASYM_OP_VERIFY) {
-		return rsa_set_pub_input(asym_op, qat_req, cookie, xform);
+		return rsa_set_pub_input(qat_req, cookie, asym_op, xform);
 	} else {
-		return rsa_set_priv_input(asym_op, qat_req, cookie, xform);
+		return rsa_set_priv_input(qat_req, cookie, asym_op, xform);
 	}
 }
 
 static uint8_t
 rsa_collect(struct rte_crypto_asym_op *asym_op,
-		struct qat_asym_op_cookie *cookie)
+		const struct qat_asym_op_cookie *cookie)
 {
 	uint32_t alg_bytesize = cookie->alg_bytesize;
 
@@ -559,10 +559,10 @@  rsa_collect(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-ecdsa_set_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+ecdsa_set_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 	uint32_t qat_func_alignsize, func_id;
@@ -662,7 +662,7 @@  ecdsa_set_input(struct rte_crypto_asym_op *asym_op,
 
 static uint8_t
 ecdsa_collect(struct rte_crypto_asym_op *asym_op,
-		struct qat_asym_op_cookie *cookie)
+		const struct qat_asym_op_cookie *cookie)
 {
 	uint32_t alg_bytesize = cookie->alg_bytesize;
 	uint32_t qat_func_alignsize = cookie->qat_func_alignsize;
@@ -686,10 +686,10 @@  ecdsa_collect(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-ecpm_set_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+ecpm_set_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
 	uint32_t qat_func_alignsize, func_id;
@@ -738,7 +738,7 @@  ecpm_set_input(struct rte_crypto_asym_op *asym_op,
 
 static uint8_t
 ecpm_collect(struct rte_crypto_asym_op *asym_op,
-		struct qat_asym_op_cookie *cookie)
+		const struct qat_asym_op_cookie *cookie)
 {
 	uint8_t *x = asym_op->ecpm.r.x.data;
 	uint8_t *y = asym_op->ecpm.r.y.data;
@@ -759,27 +759,22 @@  ecpm_collect(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-asym_set_input(struct rte_crypto_asym_op *asym_op,
-		struct icp_qat_fw_pke_request *qat_req,
+asym_set_input(struct icp_qat_fw_pke_request *qat_req,
 		struct qat_asym_op_cookie *cookie,
-		struct rte_crypto_asym_xform *xform)
+		const struct rte_crypto_asym_op *asym_op,
+		const struct rte_crypto_asym_xform *xform)
 {
 	switch (xform->xform_type) {
 	case RTE_CRYPTO_ASYM_XFORM_MODEX:
-		return modexp_set_input(asym_op, qat_req,
-				cookie, xform);
+		return modexp_set_input(qat_req, cookie, asym_op, xform);
 	case RTE_CRYPTO_ASYM_XFORM_MODINV:
-		return modinv_set_input(asym_op, qat_req,
-				cookie, xform);
+		return modinv_set_input(qat_req, cookie, asym_op, xform);
 	case RTE_CRYPTO_ASYM_XFORM_RSA:
-		return rsa_set_input(asym_op, qat_req,
-				cookie, xform);
+		return rsa_set_input(qat_req, cookie, asym_op, xform);
 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
-		return ecdsa_set_input(asym_op, qat_req,
-				cookie, xform);
+		return ecdsa_set_input(qat_req, cookie, asym_op, xform);
 	case RTE_CRYPTO_ASYM_XFORM_ECPM:
-		return ecpm_set_input(asym_op, qat_req,
-				cookie, xform);
+		return ecpm_set_input(qat_req, cookie, asym_op, xform);
 	default:
 		QAT_LOG(ERR, "Invalid/unsupported asymmetric crypto xform");
 		return -EINVAL;
@@ -824,8 +819,7 @@  qat_asym_build_request(void *in_op, uint8_t *out_msg, void *op_cookie,
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
 		goto error;
 	}
-	err = asym_set_input(asym_op, qat_req, cookie,
-			xform);
+	err = asym_set_input(qat_req, cookie, asym_op, xform);
 	if (err) {
 		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 		goto error;
@@ -1265,7 +1259,7 @@  qat_asym_init_op_cookie(void *op_cookie)
 
 int
 qat_asym_dev_create(struct qat_pci_device *qat_pci_dev,
-		struct qat_dev_cmd_param *qat_dev_cmd_param)
+		const struct qat_dev_cmd_param *qat_dev_cmd_param)
 {
 	struct qat_cryptodev_private *internals;
 	struct rte_cryptodev *cryptodev;
diff --git a/drivers/crypto/qat/qat_ec.h b/drivers/crypto/qat/qat_ec.h
index bbd0b31949..0e02722c18 100644
--- a/drivers/crypto/qat/qat_ec.h
+++ b/drivers/crypto/qat/qat_ec.h
@@ -264,7 +264,7 @@  static struct elliptic_curve curve[] = {
 };
 
 static int
-pick_curve(struct rte_crypto_asym_xform *xform)
+pick_curve(const struct rte_crypto_asym_xform *xform)
 {
 	switch (xform->ec.curve_id) {
 	case RTE_CRYPTO_EC_GROUP_SECP256R1: