From e64728f092db1fb93f1fc8f54ff03fe47004c86b Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Fri, 13 Jan 2023 11:53:54 +0100 Subject: [PATCH] bdev/crypto: make sure that vbdev_crypto_destruct() returns 1 Make vbdev_crypto_destruct() return 1 to signal that program execution should wait for spdk_bdev_destruct_done() function, which is added inside _device_unregister_cb(). This change is related to _vdev_dev_get() not being able to find the devices, when called from _cryptodev_sym_session_free(), as it uses device driver name, which might already be freed. This occurs only during bdev module finish, when crypto bdevs are being unregistered and vbdev_crypto_finish() proceeds to call bdev name deletion without waiting for the unregister callbacks to complete, which ultimately results in reading freed pointers. This only happens when code execution takes path for DPDK 22.11+. Change-Id: Id9a43d07c90aef7a82867383fd77354ac521a3e7 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16290 Reviewed-by: Tomasz Zawadzki Reviewed-by: Konrad Sztyber Tested-by: SPDK CI Jenkins --- module/bdev/crypto/vbdev_crypto.c | 4 +++- test/unit/lib/bdev/crypto.c/crypto_ut.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/module/bdev/crypto/vbdev_crypto.c b/module/bdev/crypto/vbdev_crypto.c index 7ffbd1cf5..7dbe5d032 100644 --- a/module/bdev/crypto/vbdev_crypto.c +++ b/module/bdev/crypto/vbdev_crypto.c @@ -1438,6 +1438,8 @@ _device_unregister_cb(void *io_device) _cryptodev_sym_session_free(crypto_bdev, crypto_bdev->session_decrypt); _cryptodev_sym_session_free(crypto_bdev, crypto_bdev->session_encrypt); crypto_bdev->opts = NULL; + + spdk_bdev_destruct_done(&crypto_bdev->crypto_bdev, 0); free(crypto_bdev->crypto_bdev.name); free(crypto_bdev); } @@ -1477,7 +1479,7 @@ vbdev_crypto_destruct(void *ctx) g_number_of_claimed_volumes--; - return 0; + return 1; } /* We supplied this as an entry point for upper layers who want to communicate to this diff --git a/test/unit/lib/bdev/crypto.c/crypto_ut.c b/test/unit/lib/bdev/crypto.c/crypto_ut.c index aca77e64e..c999b6c65 100644 --- a/test/unit/lib/bdev/crypto.c/crypto_ut.c +++ b/test/unit/lib/bdev/crypto.c/crypto_ut.c @@ -246,6 +246,7 @@ DEFINE_STUB(spdk_bdev_module_claim_bdev, int, (struct spdk_bdev *bdev, struct sp struct spdk_bdev_module *module), 0); DEFINE_STUB_V(spdk_bdev_module_examine_done, (struct spdk_bdev_module *module)); DEFINE_STUB(spdk_bdev_register, int, (struct spdk_bdev *vbdev), 0); +DEFINE_STUB_V(spdk_bdev_destruct_done, (struct spdk_bdev *bdev, int bdeverrno)); /* DPDK stubs */ #define DPDK_DYNFIELD_OFFSET offsetof(struct rte_mbuf, dynfield1[1])