[dpdk-dev,v7] eal: map uio resources after hugepages.
Commit Message
A multiple process DPDK application must mmap hugepages and pci resources into same virtual addresses. By default the virtual addresses chosen by the primary process automatically when calling the mmap. But sometime the chosen virtual addresses isn't usable at secondary process. Such as the secondary process linked with more libraries than primary process. The library has been mapped into this virtual address. The command line parameter 'base-virtaddr' has been added for this situation. If it's configured, the hugepages will be mapped into this base address. But the virtual address of uio resource mapped still does not refer to the parameter. In that case "EAL: pci_map_resource(): cannot mmap" will be got.
This patch try to map uio resources after hugepages. So the error can be resolved by set base-virtaddr into free virtual address space.
Signed-off-by: lxu <liang.xu@cinfotech.cn>
---
lib/librte_eal/linuxapp/eal/eal_pci.c | 25 ++++++++++++++++++++--
lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 6 ++++--
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 4 +++-
lib/librte_eal/linuxapp/eal/include/eal_pci_init.h | 4 ++--
4 files changed, 32 insertions(+), 7 deletions(-)
Comments
Hi Liang,
I see you are learning how to send a patch. It's a good thing.
I don't know if the idea of your patch will be accepted but here are more tips
about formatting:
- You should use checkpatch.pl from kernel.org and fix the most important issues
- The commit log should be wrapped to avoid long lines
- The title is important. You didn't update it for vfio.
And there should be no point at the end of the title.
- You should use your real name in Signed-off-by.
- You should annotate each new version to show the changes
See http://dpdk.org/dev#send and
https://www.kernel.org/doc/Documentation/SubmittingPatches
Looking at other submissions could be inspiring also.
Thanks
@@ -483,15 +483,36 @@ pci_config_space_set(struct rte_pci_device *dev)
}
#endif
+static void *
+pci_find_max_end_va(void)
+{
+ const struct rte_memseg * seg = rte_eal_get_physmem_layout();
+ const struct rte_memseg * last = seg;
+ unsigned i = 0;
+
+ for (i=0; i<RTE_MAX_MEMSEG; i++, seg++) {
+ if (seg->addr == NULL)
+ break;
+
+ if(seg->addr > last->addr)
+ last = seg;
+
+ }
+ return RTE_PTR_ADD(last->addr, last->len);
+}
+
static int
pci_map_device(struct rte_pci_device *dev)
{
int ret, mapped = 0;
+ static void * requested_addr;
+ if(NULL == requested_addr)
+ requested_addr = pci_find_max_end_va();
/* try mapping the NIC resources using VFIO if it exists */
#ifdef VFIO_PRESENT
if (pci_vfio_is_enabled()) {
- ret = pci_vfio_map_resource(dev);
+ ret = pci_vfio_map_resource(dev, &requested_addr);
if (ret == 0)
mapped = 1;
else if (ret < 0)
@@ -500,7 +521,7 @@ pci_map_device(struct rte_pci_device *dev)
#endif
/* map resources for devices that use igb_uio */
if (!mapped) {
- ret = pci_uio_map_resource(dev);
+ ret = pci_uio_map_resource(dev, &requested_addr);
if (ret != 0)
return ret;
}
@@ -275,7 +275,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
/* map the PCI resource of a PCI device in virtual memory */
int
-pci_uio_map_resource(struct rte_pci_device *dev)
+pci_uio_map_resource(struct rte_pci_device *dev, void **requested_addr)
{
int i, j;
char dirname[PATH_MAX];
@@ -371,10 +371,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
if (maps[j].addr != NULL)
fail = 1;
else {
- mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+ mapaddr = pci_map_resource(*requested_addr, fd, (off_t)offset,
(size_t)maps[j].size);
if (mapaddr == NULL)
fail = 1;
+ else
+ *requested_addr = RTE_PTR_ADD(mapaddr, maps[j].size);
}
if (fail) {
@@ -515,7 +515,7 @@ clear_current_group(void)
* primary and secondary processes follow almost exactly the same path
*/
int
-pci_vfio_map_resource(struct rte_pci_device *dev)
+pci_vfio_map_resource(struct rte_pci_device *dev, void **requested_addr)
{
struct vfio_group_status group_status = {
.argsz = sizeof(group_status)
@@ -720,6 +720,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
if (i == msix_bar)
continue;
+ maps[i].addr = *requested_addr;
bar_addr = pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset,
reg.size);
@@ -732,6 +733,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
return -1;
}
+ *requested_addr = bar_addr;
maps[i].addr = bar_addr;
maps[i].offset = reg.offset;
maps[i].size = reg.size;
@@ -63,7 +63,7 @@ void *pci_map_resource(void *requested_addr, int fd, off_t offset,
size_t size);
/* map IGB_UIO resource prototype */
-int pci_uio_map_resource(struct rte_pci_device *dev);
+int pci_uio_map_resource(struct rte_pci_device *dev, void **requested_addr);
#ifdef VFIO_PRESENT
@@ -74,7 +74,7 @@ int pci_vfio_is_enabled(void);
int pci_vfio_mp_sync_setup(void);
/* map VFIO resource prototype */
-int pci_vfio_map_resource(struct rte_pci_device *dev);
+int pci_vfio_map_resource(struct rte_pci_device *dev, void **requested_addr);
int pci_vfio_get_group_fd(int iommu_group_fd);
int pci_vfio_get_container_fd(void);