From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1134-178.mail.aliyun.com (out1134-178.mail.aliyun.com [42.120.134.178]) by dpdk.org (Postfix) with ESMTP id CB81B7F30 for ; Fri, 7 Nov 2014 15:48:39 +0100 (CET) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.02695761|-1; FP=0|0|0|0|0|-1|-1|-1; HT=r41g08146; MF=liang.xu@cinfotech.cn; PH=DS; RN=4; RT=4; SR=0; Received: from localhost.localdomain(mailfrom:liang.xu@cinfotech.cn ip:222.65.239.251) by smtp.aliyun-inc.com(10.147.34.66); Fri, 07 Nov 2014 22:58:07 +0800 From: lxu To: dev@dpdk.org Date: Fri, 7 Nov 2014 22:57:49 +0800 Message-Id: <1415372269-8723-1-git-send-email-liang.xu@cinfotech.cn> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415193919-17361-1-git-send-email-liang.xu@cinfotech.cn> References: <1415193919-17361-1-git-send-email-liang.xu@cinfotech.cn> Subject: [dpdk-dev] [PATCH v7] eal: map uio resources after hugepages. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Nov 2014 14:48:40 -0000 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 --- 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(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 5fe3961..aef6f5e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -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; iaddr == 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; } diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index 7e62266..e92124e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -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) { diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index c776ddc..2102adf 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -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; diff --git a/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h index d758bee..e14fa36 100644 --- a/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/include/eal_pci_init.h @@ -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); -- 1.9.1