[dpdk-dev,3/4] crypto: add sgl support for sw PMDs

Message ID 1480698466-17620-4-git-send-email-tomaszx.kulasek@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
checkpatch/checkpatch success coding style OK

Commit Message

Tomasz Kulasek Dec. 2, 2016, 5:07 p.m. UTC
  This patch introduces RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER feature flag
informing that selected crypto device supports segmented mbufs natively
and doesn't need to be coalesced before crypto operation.

While using segmented buffers in crypto devices may have unpredictable
results, for PMDs which doesn't support it natively, additional check is
made for debug compilation.


Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
---
 drivers/crypto/aesni_gcm/aesni_gcm_pmd.c   |   14 ++++++++++++++
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c |   19 ++++++++++++++++---
 drivers/crypto/kasumi/rte_kasumi_pmd.c     |   13 +++++++++++++
 drivers/crypto/null/null_crypto_pmd.c      |    3 ++-
 drivers/crypto/openssl/rte_openssl_pmd.c   |   11 +++++++++++
 drivers/crypto/snow3g/rte_snow3g_pmd.c     |   15 +++++++++++++++
 drivers/crypto/zuc/rte_zuc_pmd.c           |   13 +++++++++++++
 lib/librte_cryptodev/rte_cryptodev.c       |    4 ++--
 lib/librte_cryptodev/rte_cryptodev.h       |    3 ++-
 9 files changed, 88 insertions(+), 7 deletions(-)
  

Comments

Michał Mirosław Dec. 3, 2016, 8:28 a.m. UTC | #1
2016-12-02 18:07 GMT+01:00 Tomasz Kulasek <tomaszx.kulasek@intel.com>:
> This patch introduces RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER feature flag
> informing that selected crypto device supports segmented mbufs natively
> and doesn't need to be coalesced before crypto operation.
>
> While using segmented buffers in crypto devices may have unpredictable
> results, for PMDs which doesn't support it natively, additional check is
> made for debug compilation.
>
[...]
> +#ifdef RTE_LIBRTE_PMD_AESNI_GCM_DEBUG
> +               if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
> +                               (ops[i]->sym->m_dst != NULL &&
> +                               !rte_pktmbuf_is_contiguous(
> +                                               ops[i]->sym->m_dst))) {
> +                       ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
> +                       GCM_LOG_ERR("PMD supports only contiguous mbufs, "
> +                               "op (%p) provides noncontiguous mbuf as "
> +                               "source/destination buffer.\n", ops[i]);
> +                       qp->qp_stats.enqueue_err_count++;
> +                       break;
> +               }
> +#endif
[...]

Why are there so many copies of this code?

Best Regards,
Michał Mirosław
  
Tomasz Kulasek Dec. 12, 2016, 10:01 a.m. UTC | #2
Hi Michał,

> -----Original Message-----

> From: Michał Mirosław [mailto:mirqus@gmail.com]

> Sent: Saturday, December 3, 2016 09:28

> To: Kulasek, TomaszX <tomaszx.kulasek@intel.com>

> Cc: dev@dpdk.org

> Subject: Re: [dpdk-dev] [PATCH 3/4] crypto: add sgl support for sw PMDs

> 

> 2016-12-02 18:07 GMT+01:00 Tomasz Kulasek <tomaszx.kulasek@intel.com>:

> > This patch introduces RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER feature

> > flag informing that selected crypto device supports segmented mbufs

> > natively and doesn't need to be coalesced before crypto operation.

> >

> > While using segmented buffers in crypto devices may have unpredictable

> > results, for PMDs which doesn't support it natively, additional check

> > is made for debug compilation.

> >

> [...]

> > +#ifdef RTE_LIBRTE_PMD_AESNI_GCM_DEBUG

> > +               if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||

> > +                               (ops[i]->sym->m_dst != NULL &&

> > +                               !rte_pktmbuf_is_contiguous(

> > +                                               ops[i]->sym->m_dst))) {

> > +                       ops[i]->status =

> RTE_CRYPTO_OP_STATUS_INVALID_ARGS;

> > +                       GCM_LOG_ERR("PMD supports only contiguous mbufs,

> "

> > +                               "op (%p) provides noncontiguous mbuf as

> "

> > +                               "source/destination buffer.\n", ops[i]);

> > +                       qp->qp_stats.enqueue_err_count++;

> > +                       break;

> > +               }

> > +#endif

> [...]

> 

> Why are there so many copies of this code?

> 

> Best Regards,

> Michał Mirosław


This is one check per crypto PMD: aesni-gcm, aesni-mb, openssl and so on, enabled per PMD.

Tomasz
  

Patch

diff --git a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
index dba5e15..1a6120c 100644
--- a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
+++ b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
@@ -375,6 +375,20 @@ 
 			break;
 		}
 
+#ifdef RTE_LIBRTE_PMD_AESNI_GCM_DEBUG
+		if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
+				(ops[i]->sym->m_dst != NULL &&
+				!rte_pktmbuf_is_contiguous(
+						ops[i]->sym->m_dst))) {
+			ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+			GCM_LOG_ERR("PMD supports only contiguous mbufs, "
+				"op (%p) provides noncontiguous mbuf as "
+				"source/destination buffer.\n", ops[i]);
+			qp->qp_stats.enqueue_err_count++;
+			break;
+		}
+#endif
+
 		retval = process_gcm_crypto_op(qp, ops[i]->sym, sess);
 		if (retval < 0) {
 			ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
index f07cd07..b5e115e 100644
--- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
+++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
@@ -529,15 +529,28 @@ 
 	int i, processed_jobs = 0;
 
 	for (i = 0; i < nb_ops; i++) {
-#ifdef RTE_LIBRTE_AESNI_MB_DEBUG
-		if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
+#ifdef RTE_LIBRTE_PMD_AESNI_MB_DEBUG
+		if (unlikely(ops[i]->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
 			MB_LOG_ERR("PMD only supports symmetric crypto "
 				"operation requests, op (%p) is not a "
-				"symmetric operation.", op);
+				"symmetric operation.", ops[i]);
+			qp->stats.enqueue_err_count++;
+			goto flush_jobs;
+		}
+
+		if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
+				(ops[i]->sym->m_dst != NULL &&
+				!rte_pktmbuf_is_contiguous(
+						ops[i]->sym->m_dst))) {
+			MB_LOG_ERR("PMD supports only contiguous mbufs, "
+				"op (%p) provides noncontiguous mbuf as "
+				"source/destination buffer.\n", ops[i]);
+			ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
 			qp->stats.enqueue_err_count++;
 			goto flush_jobs;
 		}
 #endif
+
 		sess = get_session(qp, ops[i]);
 		if (unlikely(sess == NULL)) {
 			qp->stats.enqueue_err_count++;
diff --git a/drivers/crypto/kasumi/rte_kasumi_pmd.c b/drivers/crypto/kasumi/rte_kasumi_pmd.c
index b119da2..4bdd7bb 100644
--- a/drivers/crypto/kasumi/rte_kasumi_pmd.c
+++ b/drivers/crypto/kasumi/rte_kasumi_pmd.c
@@ -455,6 +455,19 @@ 
 	for (i = 0; i < nb_ops; i++) {
 		curr_c_op = ops[i];
 
+#ifdef RTE_LIBRTE_PMD_KASUMI_DEBUG
+		if (!rte_pktmbuf_is_contiguous(curr_c_op->sym->m_src) ||
+				(curr_c_op->sym->m_dst != NULL &&
+				!rte_pktmbuf_is_contiguous(
+						curr_c_op->sym->m_dst))) {
+			KASUMI_LOG_ERR("PMD supports only contiguous mbufs, "
+				"op (%p) provides noncontiguous mbuf as "
+				"source/destination buffer.\n", curr_c_op);
+			curr_c_op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+			break;
+		}
+#endif
+
 		/* Set status as enqueued (not processed yet) by default. */
 		curr_c_op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 
diff --git a/drivers/crypto/null/null_crypto_pmd.c b/drivers/crypto/null/null_crypto_pmd.c
index c69606b..c37d3d6 100644
--- a/drivers/crypto/null/null_crypto_pmd.c
+++ b/drivers/crypto/null/null_crypto_pmd.c
@@ -216,7 +216,8 @@ 
 	dev->enqueue_burst = null_crypto_pmd_enqueue_burst;
 
 	dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
-			RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
+			RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
+			RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
 
 	internals = dev->data->dev_private;
 
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 5f8fa33..b57588e 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -868,6 +868,17 @@ 
 	msrc = op->sym->m_src;
 	mdst = op->sym->m_dst ? op->sym->m_dst : op->sym->m_src;
 
+#ifdef RTE_LIBRTE_PMD_OPENSSL_DEBUG
+	if (!rte_pktmbuf_is_contiguous(msrc) ||
+			!rte_pktmbuf_is_contiguous(mdst)) {
+		OPENSSL_LOG_ERR("PMD supports only contiguous mbufs, "
+			"op (%p) provides noncontiguous mbuf as "
+			"source/destination buffer.\n", op);
+		op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+		return -1;
+	}
+#endif
+
 	op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
 
 	switch (sess->chain_order) {
diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c b/drivers/crypto/snow3g/rte_snow3g_pmd.c
index 3b4292a..9a6f16d 100644
--- a/drivers/crypto/snow3g/rte_snow3g_pmd.c
+++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c
@@ -330,6 +330,21 @@ 
 	unsigned i;
 	unsigned enqueued_ops, processed_ops;
 
+#ifdef RTE_LIBRTE_PMD_SNOW3G_DEBUG
+	for (i = 0; i < num_ops; i++) {
+		if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
+				(ops[i]->sym->m_dst != NULL &&
+				!rte_pktmbuf_is_contiguous(
+						ops[i]->sym->m_dst))) {
+			SNOW3G_LOG_ERR("PMD supports only contiguous mbufs, "
+				"op (%p) provides noncontiguous mbuf as "
+				"source/destination buffer.\n", ops[i]);
+			ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+			return 0;
+		}
+	}
+#endif
+
 	switch (session->op) {
 	case SNOW3G_OP_ONLY_CIPHER:
 		processed_ops = process_snow3g_cipher_op(ops,
diff --git a/drivers/crypto/zuc/rte_zuc_pmd.c b/drivers/crypto/zuc/rte_zuc_pmd.c
index 3849119..bf53f76 100644
--- a/drivers/crypto/zuc/rte_zuc_pmd.c
+++ b/drivers/crypto/zuc/rte_zuc_pmd.c
@@ -211,6 +211,19 @@ 
 			break;
 		}
 
+#ifdef RTE_LIBRTE_PMD_ZUC_DEBUG
+		if (!rte_pktmbuf_is_contiguous(ops[i]->sym->m_src) ||
+				(ops[i]->sym->m_dst != NULL &&
+				!rte_pktmbuf_is_contiguous(
+						ops[i]->sym->m_dst))) {
+			ZUC_LOG_ERR("PMD supports only contiguous mbufs, "
+				"op (%p) provides noncontiguous mbuf as "
+				"source/destination buffer.\n", ops[i]);
+			ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
+			break;
+		}
+#endif
+
 		src[i] = rte_pktmbuf_mtod(ops[i]->sym->m_src, uint8_t *) +
 				(ops[i]->sym->cipher.data.offset >> 3);
 		dst[i] = ops[i]->sym->m_dst ?
diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index 127e8d0..ebbb822 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -211,13 +211,13 @@  struct rte_cryptodev_callback {
 		return "CPU_AESNI";
 	case RTE_CRYPTODEV_FF_HW_ACCELERATED:
 		return "HW_ACCELERATED";
-
+	case RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER:
+		return "MBUF_SCATTER_GATHER";
 	default:
 		return NULL;
 	}
 }
 
-
 int
 rte_cryptodev_create_vdev(const char *name, const char *args)
 {
diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h
index 8f63e8f..70ff7fc 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -225,7 +225,8 @@  struct rte_cryptodev_capabilities {
 /**< Utilises CPU AES-NI instructions */
 #define	RTE_CRYPTODEV_FF_HW_ACCELERATED		(1ULL << 7)
 /**< Operations are off-loaded to an external hardware accelerator */
-
+#define	RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER	(1ULL << 8)
+/**< Scatter-gather mbufs are supported */
 
 /**
  * Get the name of a crypto device feature flag