Commit b3db2a65 authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Jim Harris
Browse files

vfio: don't use VFIO when IOMMU is disabled



Previously we used VFIO if only the vfio-pci kernel module
was loaded, which is different from what our setup.sh script
did. On a fairly usual system configuration, setup.sh could
have bound devices to UIO, but SPDK would still try to map
memory to an (empty) DPDK VFIO container just because its fd
was available. That would fail obviously.

setup.sh checks for IOMMU presence in order to use vfio-pci
and SPDK should probably do the same. We could check the
kernel driver of each attached PCI device, but there's no
chance right now of supporting both UIO and VFIO devices
at the same time with IOMMU passthrough. That's not
a reasonable configuration anyway. To keep things simple,
we just add a single check on vtophys initialization.

Fixes #462

Change-Id: Ica653f117743be322291a1b7e37ed00e34ef5035
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/432518


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatar <wuzhouhui@kingsoft.com>
parent cfc372c2
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -445,6 +445,27 @@ spdk_vfio_enabled(void)
#endif
}

/* Check if IOMMU is enabled on the system */
static bool
has_iommu_groups(void)
{
	struct dirent *d;
	int count = 0;
	DIR *dir = opendir("/sys/kernel/iommu_groups");

	if (dir == NULL) {
		return false;
	}

	while (count < 3 && (d = readdir(dir)) != NULL) {
		count++;
	}

	closedir(dir);
	/* there will always be ./ and ../ entries */
	return count > 2;
}

static void
spdk_vtophys_iommu_init(void)
{
@@ -454,7 +475,7 @@ spdk_vtophys_iommu_init(void)
	DIR *dir;
	struct dirent *d;

	if (!spdk_vfio_enabled()) {
	if (!spdk_vfio_enabled() || !has_iommu_groups()) {
		return;
	}