From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from netronome.com (host-79-78-33-110.static.as9105.net [79.78.33.110]) by dpdk.org (Postfix) with ESMTP id 9C16328F3 for ; Wed, 23 May 2018 14:30:11 +0200 (CEST) Received: from netronome.com (localhost [127.0.0.1]) by netronome.com (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id w4NCSu6E001483 for ; Wed, 23 May 2018 13:28:56 +0100 Received: (from alucero@localhost) by netronome.com (8.14.4/8.14.4/Submit) id w4NCSuAd001482 for dev@dpdk.org; Wed, 23 May 2018 13:28:56 +0100 From: Alejandro Lucero To: dev@dpdk.org Date: Wed, 23 May 2018 13:28:56 +0100 Message-Id: <1527078536-1443-1-git-send-email-alejandro.lucero@netronome.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] net/nfp: fix lock file usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 May 2018 12:30:12 -0000 DPDK apps can be executed as non-root users but current NFP lock file for avoiding concurrent accesses to CPP interface is precluding this option or requires to modify system file permissions. When the NFP device is bound to VFIO, this driver does not allow this concurrent access, so the lock file is not required at all. OVS-DPDK as executed in RedHat distributions is the main NFP user needing this fix. Fixes: c7e9729da6b5 ("net/nfp: support CPP") Signed-off-by: Alejandro Lucero --- drivers/net/nfp/nfp_net.c | 13 ++++++++++++- drivers/net/nfp/nfpcore/nfp_cpp.h | 5 ++++- drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 11 +++++++---- drivers/net/nfp/nfpcore/nfp_cppcore.c | 7 ++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c index 34a8cad..faad1ee 100644 --- a/drivers/net/nfp/nfp_net.c +++ b/drivers/net/nfp/nfp_net.c @@ -3118,7 +3118,18 @@ static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, if (!dev) return ret; - cpp = nfp_cpp_from_device_name(dev->device.name); + /* + * When device bound to UIO, the device could be used, by mistake, + * by two DPDK apps, and the UIO driver does not avoid it. This + * could lead to a serious problem when configuring the NFP CPP + * interface. Here we avoid this telling to the CPP init code to + * use a lock file if UIO is being used. + */ + if (dev->kdrv == RTE_KDRV_VFIO) + cpp = nfp_cpp_from_device_name(dev->device.name, 0); + else + cpp = nfp_cpp_from_device_name(dev->device.name, 1); + if (!cpp) { PMD_DRV_LOG(ERR, "A CPP handle can not be obtained"); ret = -EIO; diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h index 7e86214..de2ff84 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp.h +++ b/drivers/net/nfp/nfpcore/nfp_cpp.h @@ -31,6 +31,8 @@ struct nfp_cpp { * island XPB CSRs. */ uint32_t imb_cat_table[16]; + + int driver_lock_needed; }; /* @@ -179,7 +181,8 @@ int nfp_cpp_serial_set(struct nfp_cpp *cpp, const uint8_t *serial, * * @return NFP CPP handle, or NULL on failure (and set errno accordingly). */ -struct nfp_cpp *nfp_cpp_from_device_name(const char *devname); +struct nfp_cpp *nfp_cpp_from_device_name(const char *devname, + int driver_lock_needed); /* * Free a NFP CPP handle diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c index 52b2948..2f5e7f6 100644 --- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c +++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c @@ -850,9 +850,11 @@ struct nfp6000_area_priv { memset(desc->busdev, 0, BUSDEV_SZ); strlcpy(desc->busdev, devname, sizeof(desc->busdev)); - ret = nfp_acquire_process_lock(desc); - if (ret) - return -1; + if (cpp->driver_lock_needed) { + ret = nfp_acquire_process_lock(desc); + if (ret) + return -1; + } snprintf(tmp_str, sizeof(tmp_str), "%s/%s/driver", PCI_DEVICES, desc->busdev); @@ -912,7 +914,8 @@ struct nfp6000_area_priv { if (desc->bar[x - 1].iomem) munmap(desc->bar[x - 1].iomem, 1 << (desc->barsz - 3)); } - close(desc->lock); + if (cpp->driver_lock_needed) + close(desc->lock); close(desc->device); free(desc); } diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c index 94d4a0b..f61143f 100644 --- a/drivers/net/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c @@ -542,7 +542,7 @@ struct nfp_cpp_area * } static struct nfp_cpp * -nfp_cpp_alloc(const char *devname) +nfp_cpp_alloc(const char *devname, int driver_lock_needed) { const struct nfp_cpp_operations *ops; struct nfp_cpp *cpp; @@ -558,6 +558,7 @@ struct nfp_cpp_area * return NULL; cpp->op = ops; + cpp->driver_lock_needed = driver_lock_needed; if (cpp->op->init) { err = cpp->op->init(cpp, devname); @@ -603,9 +604,9 @@ struct nfp_cpp_area * } struct nfp_cpp * -nfp_cpp_from_device_name(const char *devname) +nfp_cpp_from_device_name(const char *devname, int driver_lock_needed) { - return nfp_cpp_alloc(devname); + return nfp_cpp_alloc(devname, driver_lock_needed); } /* -- 1.9.1