From 8c71c208a2c478dbd2a8dd5a4815c6591be5d670 Mon Sep 17 00:00:00 2001 From: Liang Yan Date: Mon, 28 May 2018 12:31:20 +0800 Subject: [PATCH] nvme: check ctrlr process while get ctrlr data in hotplug function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix issue #313. For multi-process test scenarios, the secondary process may access controller’s CSTS register in the shared ctrlr list. For this situation, all the controllers are already in the primary shared ctrlr list, but then each controller is added one by one in the secondary process, so the secondary process may access CSTS before it is remapped for the BAR space. In the rpc_config.sh test case, the spdk_nvme_ctrlr_get_regs_csts function will be called in _nvme_pcie_hotplug_monitor function before calling spdk_pci_nvme_device_attach. This step caused the secondary process iSCSI Target access CSTS before it is remapped for the BAR space. Change-Id: Ifd62c38adf8624f9877a9a2f965ca4db28839d99 Signed-off-by: Liang Yan Reviewed-on: https://review.gerrithub.io/412594 Tested-by: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: GangCao Reviewed-by: Ziye Yang Reviewed-by: Shuhei Matsumoto Reviewed-by: Daniel Verkamp --- lib/nvme/nvme_pcie.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index 83a67be6b..829c6c513 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -254,6 +254,7 @@ _nvme_pcie_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb, struct spdk_uevent event; struct spdk_pci_addr pci_addr; union spdk_nvme_csts_register csts; + struct spdk_nvme_ctrlr_process *proc; while (spdk_get_uevent(hotplug_fd, &event) > 0) { if (event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_UIO || @@ -294,13 +295,17 @@ _nvme_pcie_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb, /* This is a work around for vfio-attached device hot remove detection. */ TAILQ_FOREACH_SAFE(ctrlr, &g_spdk_nvme_driver->shared_attached_ctrlrs, tailq, tmp) { - csts = spdk_nvme_ctrlr_get_regs_csts(ctrlr); - if (csts.raw == 0xffffffffU) { - nvme_ctrlr_fail(ctrlr, true); - if (remove_cb) { - nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock); - remove_cb(cb_ctx, ctrlr); - nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock); + /* NVMe controller BAR must be mapped to secondary process space before any access. */ + proc = spdk_nvme_ctrlr_get_current_process(ctrlr); + if (proc) { + csts = spdk_nvme_ctrlr_get_regs_csts(ctrlr); + if (csts.raw == 0xffffffffU) { + nvme_ctrlr_fail(ctrlr, true); + if (remove_cb) { + nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock); + remove_cb(cb_ctx, ctrlr); + nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock); + } } } }