From dbecab8da09279d1805c69fe97291b79467885b6 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Mon, 11 Jul 2022 09:32:27 +0800 Subject: [PATCH] nvme/pcie: make `nvme_pcie_ctrlr_delete_io_qpair` call trace multi-process safe When a secondary process exit without deleting allocated IO queue pair, then a new secondary process will do cleanup for previous allocated queue pair, then segment fault will happen due to `stat` inside IO queue pair data strucutre can't be accessed in this cleanup process. Fix issue #2565. Change-Id: I01a037642683901941b5268ac20d17b78b6c6350 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13537 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk --- lib/nvme/nvme_pcie_common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/nvme/nvme_pcie_common.c b/lib/nvme/nvme_pcie_common.c index 2e0f82456..a531ee020 100644 --- a/lib/nvme/nvme_pcie_common.c +++ b/lib/nvme/nvme_pcie_common.c @@ -1018,7 +1018,7 @@ nvme_pcie_qpair_destroy(struct spdk_nvme_qpair *qpair) nvme_qpair_deinit(qpair); - if (!pqpair->shared_stats) { + if (!pqpair->shared_stats && (qpair->active_proc == nvme_ctrlr_get_current_process(qpair->ctrlr))) { if (qpair->id) { free(pqpair->stat); } else { @@ -1125,7 +1125,9 @@ nvme_pcie_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ /* Now that the submission queue is deleted, the device is supposed to have * completed any outstanding I/O. Try to complete them. If they don't complete, * they'll be marked as aborted and completed below. */ - nvme_pcie_qpair_process_completions(qpair, 0); + if (qpair->active_proc == nvme_ctrlr_get_current_process(ctrlr)) { + nvme_pcie_qpair_process_completions(qpair, 0); + } memset(status, 0, sizeof(*status)); /* Delete the completion queue */