crypto/qat: add multi-process handling of driver ID
authorArek Kusztal <arkadiuszx.kusztal@intel.com>
Tue, 7 Jul 2020 15:02:38 +0000 (17:02 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 8 Jul 2020 16:16:27 +0000 (18:16 +0200)
As cryptodev driver_id is allocated per-process,
a corner case exists where binaries for primary and
secondary processes could have different driver_ids
if built differently. Add checking in qat PMD to catch and
handle the case where driver_ids are inconsistent.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
drivers/common/qat/qat_device.h
drivers/crypto/qat/qat_asym.c
drivers/crypto/qat/qat_asym_pmd.c
drivers/crypto/qat/qat_asym_pmd.h
drivers/crypto/qat/qat_sym.c
drivers/crypto/qat/qat_sym.h
drivers/crypto/qat/qat_sym_pmd.c
drivers/crypto/qat/qat_sym_pmd.h

index b5fe394..e6337c6 100644 (file)
@@ -92,10 +92,16 @@ struct qat_pci_device {
        struct qat_sym_dev_private *sym_dev;
        /**< link back to cryptodev private data */
 
+       int qat_sym_driver_id;
+       /**< Symmetric driver id used by this device */
+
        /* Data relating to asymmetric crypto service */
        struct qat_asym_dev_private *asym_dev;
        /**< link back to cryptodev private data */
 
+       int qat_asym_driver_id;
+       /**< Symmetric driver id used by this device */
+
        /* Data relating to compression service */
        struct qat_comp_dev_private *comp_dev;
        /**< link back to compressdev private data */
index ae0dd79..8597381 100644 (file)
@@ -475,7 +475,7 @@ qat_asym_build_request(void *in_op,
        if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
                ctx = (struct qat_asym_session *)
                        get_asym_session_private_data(
-                       op->asym->session, cryptodev_qat_asym_driver_id);
+                       op->asym->session, qat_asym_driver_id);
                if (unlikely(ctx == NULL)) {
                        QAT_LOG(ERR, "Session has not been created for this device");
                        goto error;
@@ -693,7 +693,7 @@ qat_asym_process_response(void **op, uint8_t *resp,
 
        if (rx_op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
                ctx = (struct qat_asym_session *)get_asym_session_private_data(
-                       rx_op->asym->session, cryptodev_qat_asym_driver_id);
+                       rx_op->asym->session, qat_asym_driver_id);
                qat_asym_collect_response(rx_op, cookie, ctx->xform);
        } else if (rx_op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
                qat_asym_collect_response(rx_op, cookie, rx_op->asym->xform);
index cc448cd..d584ac7 100644 (file)
@@ -11,7 +11,7 @@
 #include "qat_sym_capabilities.h"
 #include "qat_asym_capabilities.h"
 
-uint8_t cryptodev_qat_asym_driver_id;
+uint8_t qat_asym_driver_id;
 
 static const struct rte_cryptodev_capabilities qat_gen1_asym_capabilities[] = {
        QAT_BASE_GEN1_ASYM_CAPABILITIES,
@@ -63,7 +63,7 @@ static void qat_asym_dev_info_get(struct rte_cryptodev *dev,
                                                        QAT_SERVICE_ASYMMETRIC);
                info->feature_flags = dev->feature_flags;
                info->capabilities = internals->qat_dev_capabilities;
-               info->driver_id = cryptodev_qat_asym_driver_id;
+               info->driver_id = qat_asym_driver_id;
                /* No limit of number of sessions */
                info->sym.max_nb_sessions = 0;
        }
@@ -251,6 +251,19 @@ qat_asym_dev_create(struct qat_pci_device *qat_pci_dev,
        struct rte_cryptodev *cryptodev;
        struct qat_asym_dev_private *internals;
 
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+               qat_pci_dev->qat_asym_driver_id =
+                               qat_asym_driver_id;
+       } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
+               if (qat_pci_dev->qat_asym_driver_id !=
+                               qat_asym_driver_id) {
+                       QAT_LOG(ERR,
+                               "Device %s have different driver id than corresponding device in primary process",
+                               name);
+                       return -(EFAULT);
+               }
+       }
+
        snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN, "%s_%s",
                        qat_pci_dev->name, "asym");
        QAT_LOG(DEBUG, "Creating QAT ASYM device %s\n", name);
@@ -268,7 +281,7 @@ qat_asym_dev_create(struct qat_pci_device *qat_pci_dev,
                return -ENODEV;
 
        qat_dev_instance->asym_rte_dev.name = cryptodev->data->name;
-       cryptodev->driver_id = cryptodev_qat_asym_driver_id;
+       cryptodev->driver_id = qat_asym_driver_id;
        cryptodev->dev_ops = &crypto_qat_ops;
 
        cryptodev->enqueue_burst = qat_asym_pmd_enqueue_op_burst;
@@ -326,4 +339,4 @@ qat_asym_dev_destroy(struct qat_pci_device *qat_pci_dev)
 static struct cryptodev_driver qat_crypto_drv;
 RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv,
                cryptodev_qat_asym_driver,
-               cryptodev_qat_asym_driver_id);
+               qat_asym_driver_id);
index 0535bc6..ddf413f 100644 (file)
@@ -13,7 +13,7 @@
 #define CRYPTODEV_NAME_QAT_ASYM_PMD    crypto_qat_asym
 
 
-extern uint8_t cryptodev_qat_asym_driver_id;
+extern uint8_t qat_asym_driver_id;
 
 /** private data structure for a QAT device.
  * This QAT device is a device offering only asymmetric crypto service,
index 55251d1..6d568ab 100644 (file)
@@ -206,7 +206,7 @@ qat_sym_build_request(void *in_op, uint8_t *out_msg,
                return -EINVAL;
        } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
                ctx = (struct qat_sym_session *)get_sym_session_private_data(
-                               op->sym->session, cryptodev_qat_driver_id);
+                               op->sym->session, qat_sym_driver_id);
 #ifdef RTE_LIBRTE_SECURITY
        } else {
                ctx = (struct qat_sym_session *)get_sec_session_private_data(
index 02e7239..dbca74e 100644 (file)
@@ -197,7 +197,7 @@ qat_sym_process_response(void **op, uint8_t *resp)
                        sess = (struct qat_sym_session *)
                                        get_sym_session_private_data(
                                        rx_op->sym->session,
-                                       cryptodev_qat_driver_id);
+                                       qat_sym_driver_id);
                }
 
                rx_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
index bdcb42e..6ef9a34 100644 (file)
@@ -19,7 +19,7 @@
 
 #define MIXED_CRYPTO_MIN_FW_VER 0x04090000
 
-uint8_t cryptodev_qat_driver_id;
+uint8_t qat_sym_driver_id;
 
 static const struct rte_cryptodev_capabilities qat_gen1_sym_capabilities[] = {
        QAT_BASE_GEN1_SYM_CAPABILITIES,
@@ -92,7 +92,7 @@ static void qat_sym_dev_info_get(struct rte_cryptodev *dev,
                        qat_qps_per_service(sym_hw_qps, QAT_SERVICE_SYMMETRIC);
                info->feature_flags = dev->feature_flags;
                info->capabilities = internals->qat_dev_capabilities;
-               info->driver_id = cryptodev_qat_driver_id;
+               info->driver_id = qat_sym_driver_id;
                /* No limit of number of sessions */
                info->sym.max_nb_sessions = 0;
        }
@@ -317,6 +317,25 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev,
        struct rte_cryptodev *cryptodev;
        struct qat_sym_dev_private *internals;
 
+       /*
+        * All processes must use same driver id so they can share sessions.
+        * Store driver_id so we can validate that all processes have the same
+        * value, typically they have, but could differ if binaries built
+        * separately.
+        */
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+               qat_pci_dev->qat_sym_driver_id =
+                               qat_sym_driver_id;
+       } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
+               if (qat_pci_dev->qat_sym_driver_id !=
+                               qat_sym_driver_id) {
+                       QAT_LOG(ERR,
+                               "Device %s have different driver id than corresponding device in primary process",
+                               name);
+                       return -(EFAULT);
+               }
+       }
+
 #ifdef RTE_LIBRTE_SECURITY
        struct rte_security_ctx *security_instance;
 #endif
@@ -338,7 +357,7 @@ qat_sym_dev_create(struct qat_pci_device *qat_pci_dev,
                return -ENODEV;
 
        qat_dev_instance->sym_rte_dev.name = cryptodev->data->name;
-       cryptodev->driver_id = cryptodev_qat_driver_id;
+       cryptodev->driver_id = qat_sym_driver_id;
        cryptodev->dev_ops = &crypto_qat_ops;
 
        cryptodev->enqueue_burst = qat_sym_pmd_enqueue_op_burst;
@@ -434,4 +453,4 @@ qat_sym_dev_destroy(struct qat_pci_device *qat_pci_dev)
 static struct cryptodev_driver qat_crypto_drv;
 RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv,
                cryptodev_qat_sym_driver,
-               cryptodev_qat_driver_id);
+               qat_sym_driver_id);
index c625fef..cf4e1a0 100644 (file)
@@ -23,7 +23,7 @@
 #define QAT_SYM_CAP_MIXED_CRYPTO       (1 << 0)
 #define QAT_SYM_CAP_VALID              (1 << 31)
 
-extern uint8_t cryptodev_qat_driver_id;
+extern uint8_t qat_sym_driver_id;
 
 /** private data structure for a QAT device.
  * This QAT device is a device offering only symmetric crypto service,