From 21792c4432056711bfac7f08500eb50100c9122c Mon Sep 17 00:00:00 2001 From: Arek Kusztal Date: Tue, 7 Jul 2020 17:02:38 +0200 Subject: [PATCH] crypto/qat: add multi-process handling of driver ID 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 Acked-by: Fiona Trahe --- drivers/common/qat/qat_device.h | 6 ++++++ drivers/crypto/qat/qat_asym.c | 4 ++-- drivers/crypto/qat/qat_asym_pmd.c | 21 +++++++++++++++++---- drivers/crypto/qat/qat_asym_pmd.h | 2 +- drivers/crypto/qat/qat_sym.c | 2 +- drivers/crypto/qat/qat_sym.h | 2 +- drivers/crypto/qat/qat_sym_pmd.c | 27 +++++++++++++++++++++++---- drivers/crypto/qat/qat_sym_pmd.h | 2 +- 8 files changed, 52 insertions(+), 14 deletions(-) diff --git a/drivers/common/qat/qat_device.h b/drivers/common/qat/qat_device.h index b5fe3946ec..e6337c688d 100644 --- a/drivers/common/qat/qat_device.h +++ b/drivers/common/qat/qat_device.h @@ -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 */ diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c index ae0dd79562..85973812a8 100644 --- a/drivers/crypto/qat/qat_asym.c +++ b/drivers/crypto/qat/qat_asym.c @@ -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); diff --git a/drivers/crypto/qat/qat_asym_pmd.c b/drivers/crypto/qat/qat_asym_pmd.c index cc448cd91b..d584ac79ad 100644 --- a/drivers/crypto/qat/qat_asym_pmd.c +++ b/drivers/crypto/qat/qat_asym_pmd.c @@ -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); diff --git a/drivers/crypto/qat/qat_asym_pmd.h b/drivers/crypto/qat/qat_asym_pmd.h index 0535bc66b8..ddf413fb72 100644 --- a/drivers/crypto/qat/qat_asym_pmd.h +++ b/drivers/crypto/qat/qat_asym_pmd.h @@ -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, diff --git a/drivers/crypto/qat/qat_sym.c b/drivers/crypto/qat/qat_sym.c index 55251d1716..6d568ab8fa 100644 --- a/drivers/crypto/qat/qat_sym.c +++ b/drivers/crypto/qat/qat_sym.c @@ -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( diff --git a/drivers/crypto/qat/qat_sym.h b/drivers/crypto/qat/qat_sym.h index 02e72391dc..dbca74efba 100644 --- a/drivers/crypto/qat/qat_sym.h +++ b/drivers/crypto/qat/qat_sym.h @@ -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; diff --git a/drivers/crypto/qat/qat_sym_pmd.c b/drivers/crypto/qat/qat_sym_pmd.c index bdcb42e9db..6ef9a345b4 100644 --- a/drivers/crypto/qat/qat_sym_pmd.c +++ b/drivers/crypto/qat/qat_sym_pmd.c @@ -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); diff --git a/drivers/crypto/qat/qat_sym_pmd.h b/drivers/crypto/qat/qat_sym_pmd.h index c625fef4a1..cf4e1a0000 100644 --- a/drivers/crypto/qat/qat_sym_pmd.h +++ b/drivers/crypto/qat/qat_sym_pmd.h @@ -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, -- 2.20.1