From 03d9c67139aa768f2b84775a0695b94505e194ff Mon Sep 17 00:00:00 2001 From: Yuriy Umanets Date: Thu, 20 Jan 2022 11:32:21 +0200 Subject: [PATCH] bdev/crypto: Error handling in create_vbdev_dev() - Properly rte_cryptodev_stop() and rte_cryptodev_close() device on errors in create_vbdev_dev(). - Check for device id before removing its qp from the qp list. - Maintain correct g_qat_total_qp counter if qat qp is removed on errors. Signed-off-by: Yuriy Umanets Change-Id: I088d7057eebff89ff0d995adcc2a05c724c3323b Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11622 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Reviewed-by: Paul Luse Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- module/bdev/crypto/vbdev_crypto.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/module/bdev/crypto/vbdev_crypto.c b/module/bdev/crypto/vbdev_crypto.c index d0276440a..77c542380 100644 --- a/module/bdev/crypto/vbdev_crypto.c +++ b/module/bdev/crypto/vbdev_crypto.c @@ -309,7 +309,7 @@ create_vbdev_dev(uint8_t index, uint16_t num_lcores) SPDK_ERRLOG("Failed to setup queue pair %u on " "cryptodev %u\n", j, cdev_id); rc = -EINVAL; - goto err; + goto err_qp_setup; } } @@ -318,7 +318,7 @@ create_vbdev_dev(uint8_t index, uint16_t num_lcores) SPDK_ERRLOG("Failed to start device %u: error %d\n", cdev_id, rc); rc = -EINVAL; - goto err; + goto err_dev_start; } /* Select the right device/qp list based on driver name @@ -329,8 +329,10 @@ create_vbdev_dev(uint8_t index, uint16_t num_lcores) } else if (strcmp(device->cdev_info.driver_name, AESNI_MB) == 0) { dev_qp_head = (struct device_qps *)&g_device_qp_aesni_mb; } else { + SPDK_ERRLOG("Failed to start device %u. Invalid driver name \"%s\"\n", + cdev_id, device->cdev_info.driver_name); rc = -EINVAL; - goto err; + goto err_invalid_drv_name; } /* Build up lists of device/qp combinations per PMD */ @@ -355,9 +357,20 @@ create_vbdev_dev(uint8_t index, uint16_t num_lcores) return 0; err_qp_alloc: TAILQ_FOREACH_SAFE(dev_qp, dev_qp_head, link, tmp_qp) { + if (dev_qp->device->cdev_id != device->cdev_id) { + continue; + } TAILQ_REMOVE(dev_qp_head, dev_qp, link); + if (dev_qp_head == (struct device_qps *)&g_device_qp_qat) { + g_qat_total_qp--; + } free(dev_qp); } +err_invalid_drv_name: + rte_cryptodev_stop(cdev_id); +err_dev_start: +err_qp_setup: + rte_cryptodev_close(cdev_id); err: free(device);