vfio: open container at startup rather than during init

Currently, VFIO only checks for being able to access the /dev/vfio
directory when initializing VFIO, deferring actual VFIO container
initialization to VFIO binding code. This doesn't bode well for when
VFIO container cannot be initialized for whatever reason, because
it results in unrecoverable error even if the user didn't set up
VFIO and didn't even want to use it in the first place.

This patch fixes this by moving container initialization into the
code that checks if VFIO is available at runtime. Therefore, any
issues with the container will be known at initialization stage and
VFIO will simply be turned off if container could not be set up.

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
This commit is contained in:
Anatoly Burakov 2014-06-18 16:07:16 +01:00 committed by Thomas Monjalon
parent 3056abfb27
commit b841b88346

View File

@ -523,17 +523,6 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
rte_snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
loc->domain, loc->bus, loc->devid, loc->function);
/* get container fd (needs to be done only once per initialization) */
if (vfio_cfg.vfio_container_fd == -1) {
int vfio_container_fd = pci_vfio_get_container_fd();
if (vfio_container_fd < 0) {
RTE_LOG(ERR, EAL, " %s cannot open VFIO container!\n", pci_addr);
return -1;
}
vfio_cfg.vfio_container_fd = vfio_container_fd;
}
/* get group number */
iommu_group_no = pci_vfio_get_group_no(pci_addr);
@ -770,10 +759,10 @@ pci_vfio_enable(void)
vfio_cfg.vfio_groups[i].fd = -1;
vfio_cfg.vfio_groups[i].group_no = -1;
}
vfio_cfg.vfio_container_fd = -1;
vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();
/* check if we have VFIO driver enabled */
if (access(VFIO_DIR, F_OK) == 0)
if (vfio_cfg.vfio_container_fd != -1)
vfio_cfg.vfio_enabled = 1;
else
RTE_LOG(INFO, EAL, "VFIO driver not loaded or wrong permissions\n");