From 78ff96bb7317a1a1e0fe84557d8f35a25b2e706c Mon Sep 17 00:00:00 2001 From: Krishna Kanth Reddy Date: Mon, 26 Sep 2022 22:36:16 +0530 Subject: [PATCH] bdev_xnvme: free bdev_xnvme structure after device is fully unregistered Fix for the issue 2702. spdk_bdev plugin crashes while handling xnvme devices. xnvme_queue_term gets invoked after the bdev_xnvme_free executes and frees the xnvme structures. xnvme_queue_term references the xnvme->dev structure, after it is freed, resulting in a segmentation fault. Implemented a bdev_xnvme_destruct_cb, that frees the xnvme structures after the xnvme_queue_term invokes and the device is fully unregistered. Signed-off-by: Krishna Kanth Reddy Change-Id: I9338c84baf4b61ec2e0d324e67bfefcb96485156 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14680 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Konrad Sztyber --- module/bdev/xnvme/bdev_xnvme.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/module/bdev/xnvme/bdev_xnvme.c b/module/bdev/xnvme/bdev_xnvme.c index 645ff0779..9edc63084 100644 --- a/module/bdev/xnvme/bdev_xnvme.c +++ b/module/bdev/xnvme/bdev_xnvme.c @@ -105,14 +105,21 @@ bdev_xnvme_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type) } } +static void +bdev_xnvme_destruct_cb(void *io_device) +{ + struct bdev_xnvme *xnvme = io_device; + + TAILQ_REMOVE(&g_xnvme_bdev_head, xnvme, link); + bdev_xnvme_free(xnvme); +} + static int bdev_xnvme_destruct(void *ctx) { struct bdev_xnvme *xnvme = ctx; - TAILQ_REMOVE(&g_xnvme_bdev_head, xnvme, link); - spdk_io_device_unregister(xnvme, NULL); - bdev_xnvme_free(xnvme); + spdk_io_device_unregister(xnvme, bdev_xnvme_destruct_cb); return 0; }