|
|
c7ffa4 |
From 552ff0a9afc2d41685ed0295e6080df0c05382b4 Mon Sep 17 00:00:00 2001
|
|
|
c7ffa4 |
From: Alejandro Lucero <alejandro.lucero@netronome.com>
|
|
|
c7ffa4 |
Date: Wed, 23 May 2018 13:28:56 +0100
|
|
|
c7ffa4 |
Subject: [PATCH] net/nfp: fix lock file usage
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
DPDK apps can be executed as non-root users but current NFP lock
|
|
|
c7ffa4 |
file for avoiding concurrent accesses to CPP interface is precluding
|
|
|
c7ffa4 |
this option or requires to modify system file permissions.
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
When the NFP device is bound to VFIO, this driver does not allow this
|
|
|
c7ffa4 |
concurrent access, so the lock file is not required at all.
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
OVS-DPDK as executed in RedHat distributions is the main NFP user
|
|
|
c7ffa4 |
needing this fix.
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
Fixes: c7e9729da6b5 ("net/nfp: support CPP")
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
|
|
|
c7ffa4 |
(cherry picked from commit 5f6ed2f4e0cb79580c0bedba2bd764a39923d7ec)
|
|
|
c7ffa4 |
---
|
|
|
c7ffa4 |
drivers/net/nfp/nfp_net.c | 13 ++++++++++++-
|
|
|
c7ffa4 |
drivers/net/nfp/nfpcore/nfp_cpp.h | 5 ++++-
|
|
|
c7ffa4 |
drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c | 11 +++++++----
|
|
|
c7ffa4 |
drivers/net/nfp/nfpcore/nfp_cppcore.c | 7 ++++---
|
|
|
c7ffa4 |
4 files changed, 27 insertions(+), 9 deletions(-)
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
|
|
|
c7ffa4 |
index 559230ab6..71249572d 100644
|
|
|
c7ffa4 |
--- a/drivers/net/nfp/nfp_net.c
|
|
|
c7ffa4 |
+++ b/drivers/net/nfp/nfp_net.c
|
|
|
c7ffa4 |
@@ -3146,7 +3146,18 @@ static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
|
|
|
c7ffa4 |
if (!dev)
|
|
|
c7ffa4 |
return ret;
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
- cpp = nfp_cpp_from_device_name(dev->device.name);
|
|
|
c7ffa4 |
+ /*
|
|
|
c7ffa4 |
+ * When device bound to UIO, the device could be used, by mistake,
|
|
|
c7ffa4 |
+ * by two DPDK apps, and the UIO driver does not avoid it. This
|
|
|
c7ffa4 |
+ * could lead to a serious problem when configuring the NFP CPP
|
|
|
c7ffa4 |
+ * interface. Here we avoid this telling to the CPP init code to
|
|
|
c7ffa4 |
+ * use a lock file if UIO is being used.
|
|
|
c7ffa4 |
+ */
|
|
|
c7ffa4 |
+ if (dev->kdrv == RTE_KDRV_VFIO)
|
|
|
c7ffa4 |
+ cpp = nfp_cpp_from_device_name(dev->device.name, 0);
|
|
|
c7ffa4 |
+ else
|
|
|
c7ffa4 |
+ cpp = nfp_cpp_from_device_name(dev->device.name, 1);
|
|
|
c7ffa4 |
+
|
|
|
c7ffa4 |
if (!cpp) {
|
|
|
c7ffa4 |
RTE_LOG(ERR, PMD, "A CPP handle can not be obtained");
|
|
|
c7ffa4 |
ret = -EIO;
|
|
|
c7ffa4 |
diff --git a/drivers/net/nfp/nfpcore/nfp_cpp.h b/drivers/net/nfp/nfpcore/nfp_cpp.h
|
|
|
c7ffa4 |
index 7e862145c..de2ff84e9 100644
|
|
|
c7ffa4 |
--- a/drivers/net/nfp/nfpcore/nfp_cpp.h
|
|
|
c7ffa4 |
+++ b/drivers/net/nfp/nfpcore/nfp_cpp.h
|
|
|
c7ffa4 |
@@ -31,6 +31,8 @@ struct nfp_cpp {
|
|
|
c7ffa4 |
* island XPB CSRs.
|
|
|
c7ffa4 |
*/
|
|
|
c7ffa4 |
uint32_t imb_cat_table[16];
|
|
|
c7ffa4 |
+
|
|
|
c7ffa4 |
+ int driver_lock_needed;
|
|
|
c7ffa4 |
};
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
/*
|
|
|
c7ffa4 |
@@ -179,7 +181,8 @@ uint32_t __nfp_cpp_model_autodetect(struct nfp_cpp *cpp);
|
|
|
c7ffa4 |
*
|
|
|
c7ffa4 |
* @return NFP CPP handle, or NULL on failure (and set errno accordingly).
|
|
|
c7ffa4 |
*/
|
|
|
c7ffa4 |
-struct nfp_cpp *nfp_cpp_from_device_name(const char *devname);
|
|
|
c7ffa4 |
+struct nfp_cpp *nfp_cpp_from_device_name(const char *devname,
|
|
|
c7ffa4 |
+ int driver_lock_needed);
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
/*
|
|
|
c7ffa4 |
* Free a NFP CPP handle
|
|
|
c7ffa4 |
diff --git a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c
|
|
|
c7ffa4 |
index ad6ce72fe..e46dbc7d7 100644
|
|
|
c7ffa4 |
--- a/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c
|
|
|
c7ffa4 |
+++ b/drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c
|
|
|
c7ffa4 |
@@ -848,9 +848,11 @@ nfp6000_init(struct nfp_cpp *cpp, const char *devname)
|
|
|
c7ffa4 |
memset(desc->busdev, 0, BUSDEV_SZ);
|
|
|
c7ffa4 |
strncpy(desc->busdev, devname, strlen(devname));
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
- ret = nfp_acquire_process_lock(desc);
|
|
|
c7ffa4 |
- if (ret)
|
|
|
c7ffa4 |
- return -1;
|
|
|
c7ffa4 |
+ if (cpp->driver_lock_needed) {
|
|
|
c7ffa4 |
+ ret = nfp_acquire_process_lock(desc);
|
|
|
c7ffa4 |
+ if (ret)
|
|
|
c7ffa4 |
+ return -1;
|
|
|
c7ffa4 |
+ }
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
snprintf(tmp_str, sizeof(tmp_str), "%s/%s/driver", PCI_DEVICES,
|
|
|
c7ffa4 |
desc->busdev);
|
|
|
c7ffa4 |
@@ -910,7 +912,8 @@ nfp6000_free(struct nfp_cpp *cpp)
|
|
|
c7ffa4 |
if (desc->bar[x - 1].iomem)
|
|
|
c7ffa4 |
munmap(desc->bar[x - 1].iomem, 1 << (desc->barsz - 3));
|
|
|
c7ffa4 |
}
|
|
|
c7ffa4 |
- close(desc->lock);
|
|
|
c7ffa4 |
+ if (cpp->driver_lock_needed)
|
|
|
c7ffa4 |
+ close(desc->lock);
|
|
|
c7ffa4 |
close(desc->device);
|
|
|
c7ffa4 |
free(desc);
|
|
|
c7ffa4 |
}
|
|
|
c7ffa4 |
diff --git a/drivers/net/nfp/nfpcore/nfp_cppcore.c b/drivers/net/nfp/nfpcore/nfp_cppcore.c
|
|
|
c7ffa4 |
index 94d4a0b6b..f61143f7e 100644
|
|
|
c7ffa4 |
--- a/drivers/net/nfp/nfpcore/nfp_cppcore.c
|
|
|
c7ffa4 |
+++ b/drivers/net/nfp/nfpcore/nfp_cppcore.c
|
|
|
c7ffa4 |
@@ -542,7 +542,7 @@ nfp_xpb_readl(struct nfp_cpp *cpp, uint32_t xpb_addr, uint32_t *value)
|
|
|
c7ffa4 |
}
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
static struct nfp_cpp *
|
|
|
c7ffa4 |
-nfp_cpp_alloc(const char *devname)
|
|
|
c7ffa4 |
+nfp_cpp_alloc(const char *devname, int driver_lock_needed)
|
|
|
c7ffa4 |
{
|
|
|
c7ffa4 |
const struct nfp_cpp_operations *ops;
|
|
|
c7ffa4 |
struct nfp_cpp *cpp;
|
|
|
c7ffa4 |
@@ -558,6 +558,7 @@ nfp_cpp_alloc(const char *devname)
|
|
|
c7ffa4 |
return NULL;
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
cpp->op = ops;
|
|
|
c7ffa4 |
+ cpp->driver_lock_needed = driver_lock_needed;
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
if (cpp->op->init) {
|
|
|
c7ffa4 |
err = cpp->op->init(cpp, devname);
|
|
|
c7ffa4 |
@@ -603,9 +604,9 @@ nfp_cpp_free(struct nfp_cpp *cpp)
|
|
|
c7ffa4 |
}
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
struct nfp_cpp *
|
|
|
c7ffa4 |
-nfp_cpp_from_device_name(const char *devname)
|
|
|
c7ffa4 |
+nfp_cpp_from_device_name(const char *devname, int driver_lock_needed)
|
|
|
c7ffa4 |
{
|
|
|
c7ffa4 |
- return nfp_cpp_alloc(devname);
|
|
|
c7ffa4 |
+ return nfp_cpp_alloc(devname, driver_lock_needed);
|
|
|
c7ffa4 |
}
|
|
|
c7ffa4 |
|
|
|
c7ffa4 |
/*
|
|
|
c7ffa4 |
--
|
|
|
c7ffa4 |
2.17.0
|
|
|
c7ffa4 |
|