From 9bdd0195fee4946c1dae0dcf8a141050ee115d8b Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Thu, 22 Nov 2018 17:19:47 +0100 Subject: [PATCH] nvme/pcie: don't allow constructing a controller from secondary process With various possibilities to leak the rte_pci_device in the primary process, we could technically construct the controller in secondary. The nvme stack is not prepared for this and will fail to initialize the device, but will still leak the device object memory. This patch adds an extra check to prevent any controller from being constructed in secondary process. Change-Id: I772f42b541c5db53310362b6595cebf9a30e8491 Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/434407 (master) Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/448365 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/nvme/nvme_pcie.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 8042380c3..16bb2a8ff 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -703,15 +703,14 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev) trid.trtype = SPDK_NVME_TRANSPORT_PCIE; spdk_pci_addr_fmt(trid.traddr, sizeof(trid.traddr), &pci_addr); - /* Verify that this controller is not already attached */ ctrlr = spdk_nvme_get_ctrlr_by_trid_unsafe(&trid); - if (ctrlr) { - if (spdk_process_is_primary()) { - /* Already attached */ - return 0; - } else { - return nvme_ctrlr_add_process(ctrlr, pci_dev); + if (!spdk_process_is_primary()) { + if (!ctrlr) { + SPDK_ERRLOG("Controller must be constructed in the primary process first.\n"); + return -1; } + + return nvme_ctrlr_add_process(ctrlr, pci_dev); } /* check whether user passes the pci_addr */