X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=inline;f=lib%2Flibrte_eal%2Flinuxapp%2Feal%2Feal_pci_vfio.c;h=20e097727f803f0d52f58d14d7fe40391fbf8bef;hb=8bae1da2afe0;hp=bf765b5f45f3157f71bc2f8ce0e36fdcf06a270e;hpb=a7156fa28c1dfa36e2a4553d374774132f3d7d80;p=dpdk.git diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index bf765b5f45..20e097727f 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -37,12 +37,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include "eal_filesystem.h" #include "eal_pci_init.h" @@ -339,9 +341,11 @@ pci_vfio_get_container_fd(void) if (ret != 1) { if (ret < 0) RTE_LOG(ERR, EAL, " could not get IOMMU type, " - "error %i (%s)\n", errno, strerror(errno)); + "error %i (%s)\n", errno, + strerror(errno)); else - RTE_LOG(ERR, EAL, " unsupported IOMMU type!\n"); + RTE_LOG(ERR, EAL, " unsupported IOMMU type " + "detected in VFIO\n"); close(vfio_container_fd); return -1; } @@ -392,7 +396,7 @@ pci_vfio_get_group_fd(int iommu_group_no) /* if primary, try to open the group */ if (internal_config.process_type == RTE_PROC_PRIMARY) { - rte_snprintf(filename, sizeof(filename), + snprintf(filename, sizeof(filename), VFIO_GROUP_FMT, iommu_group_no); vfio_group_fd = open(filename, O_RDWR); if (vfio_group_fd < 0) { @@ -472,7 +476,7 @@ pci_vfio_get_group_no(const char *pci_addr) memset(filename, 0, sizeof(filename)); /* try to find out IOMMU group for this device */ - rte_snprintf(linkname, sizeof(linkname), + snprintf(linkname, sizeof(linkname), SYSFS_PCI_DEVICES "/%s/iommu_group", pci_addr); ret = readlink(linkname, filename, sizeof(filename)); @@ -533,7 +537,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev) dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; /* store PCI address string */ - rte_snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, + snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, loc->domain, loc->bus, loc->devid, loc->function); /* get group number */ @@ -720,10 +724,22 @@ pci_vfio_map_resource(struct rte_pci_device *dev) if (i == msix_bar) continue; - bar_addr = pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset, - reg.size); + if (internal_config.process_type == RTE_PROC_PRIMARY) { + /* try mapping somewhere close to the end of hugepages */ + if (pci_map_addr == NULL) + pci_map_addr = pci_find_max_end_va(); + + bar_addr = pci_map_resource(pci_map_addr, vfio_dev_fd, reg.offset, + reg.size); + pci_map_addr = RTE_PTR_ADD(bar_addr, (size_t) reg.size); + } else { + bar_addr = pci_map_resource(maps[i].addr, vfio_dev_fd, reg.offset, + reg.size); + } - if (bar_addr == NULL) { + if (bar_addr == MAP_FAILED || + (internal_config.process_type == RTE_PROC_SECONDARY && + bar_addr != maps[i].addr)) { RTE_LOG(ERR, EAL, " %s mapping BAR%i failed: %s\n", pci_addr, i, strerror(errno)); close(vfio_dev_fd); @@ -770,11 +786,28 @@ pci_vfio_enable(void) { /* initialize group list */ int i; + int module_vfio_type1; for (i = 0; i < VFIO_MAX_GROUPS; i++) { vfio_cfg.vfio_groups[i].fd = -1; vfio_cfg.vfio_groups[i].group_no = -1; } + + module_vfio_type1 = rte_eal_check_module("vfio_iommu_type1"); + + /* return error directly */ + if (module_vfio_type1 == -1) { + RTE_LOG(INFO, EAL, "Could not get loaded module details!\n"); + return -1; + } + + /* return 0 if VFIO modules not loaded */ + if (module_vfio_type1 == 0) { + RTE_LOG(INFO, EAL, "VFIO modules not all loaded, " + "skip VFIO support...\n"); + return 0; + } + vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd(); /* check if we have VFIO driver enabled */