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); + } } } }