Commit 5557c59c authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Jim Harris
Browse files

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: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/434407


Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 0e7ca669
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -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 */