@@ -1104,6 +1104,45 @@ def check_iommu() -> CheckFuncReturn:
11041104 f"Unable to check if IOMMU is enabled by listing { iommu_dev_filepath } .\n "
11051105 + recommendation ,
11061106 )
1107+ return (CheckState .SUCCESS , "IOMMU enabled for vfio-pci." )
1108+
1109+
1110+ def check_pci_devices () -> CheckFuncReturn :
1111+ """Check PCI devices are available."""
1112+ # If only vfio-pci is supported (and it is not in no-IOMMU mode), then
1113+ # check for PCI network devices in IOMMU group, otherwise check for any
1114+ # PCI network devices.
1115+ if (
1116+ PCIDriver ("vfio-pci" ).is_supported ()
1117+ and not PCIDriver ("igb_uio" ).is_supported ()
1118+ ):
1119+ require_iommu = True
1120+ # Overide require_iommu if no-IOMMU mode is enabled
1121+ noiommu_filepath = (
1122+ "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode"
1123+ )
1124+ try :
1125+ with open (noiommu_filepath , "r" , encoding = "utf-8" ) as f :
1126+ if f .read ().strip ().upper () in ("Y" , "1" ):
1127+ require_iommu = False
1128+ except OSError :
1129+ # If the no-IOMMU file does not exist, then no-IOMMU mode can't be
1130+ # enabled.
1131+ pass
1132+ else :
1133+ require_iommu = False
1134+
1135+ if require_iommu :
1136+ # Get IOMMU devices
1137+ iommu_dev_filepath = "/sys/class/iommu/*/devices/*"
1138+ try :
1139+ iommu_devices = [
1140+ os .path .basename (p ) for p in glob .glob (iommu_dev_filepath )
1141+ ]
1142+ except Exception :
1143+ # If getting the directory fails, then assume IOMMU is not enabled
1144+ iommu_devices = []
1145+
11071146 # List the network PCI devices
11081147 try :
11091148 cmd = "lshw -businfo -c network"
@@ -1112,8 +1151,6 @@ def check_iommu() -> CheckFuncReturn:
11121151 r"pci@([\da-f]{4}:[\da-f]{2}:[\da-f]{2}\.[\da-f])\s+(\S+)" , output
11131152 )
11141153 if not matches :
1115- # This should always be a warning - we need PCI devices whether
1116- # we're using igb_uio or vfio-pci.
11171154 return CheckState .WARNING , "no PCI network devices found"
11181155 network_devices = set ()
11191156 net_devices_dict = {}
@@ -1126,31 +1163,32 @@ def check_iommu() -> CheckFuncReturn:
11261163 return (
11271164 CheckState .ERROR ,
11281165 f"The cmd { cmd !r} failed - unable to\n "
1129- "determine the network devices on the host. IOMMU is enabled." ,
1130- )
1131- net_iommu_devices = network_devices & set (iommu_devices )
1132- if not net_iommu_devices :
1133- return (
1134- warning_state ,
1135- "IOMMU enabled for vfio-pci, but no network PCI devices found." ,
1136- )
1137- net_iommu_devs_list = []
1138- for device in sorted (net_iommu_devices ):
1139- net_iommu_devs_list .append (
1140- net_devices_dict [device ] + " (" + device + ")"
1166+ "determine the network devices on the host." ,
11411167 )
1168+
1169+ # If in IOMMU mode then check if the network devices are in the IOMMU group
1170+ if require_iommu :
1171+ network_devices &= set (iommu_devices )
1172+ if not network_devices :
1173+ return (
1174+ CheckState .WARNING ,
1175+ "No PCI network devices found with IOMMU enabled for vfio-pci." ,
1176+ )
1177+
1178+ net_devs_list = []
1179+ for device in sorted (network_devices ):
1180+ net_devs_list .append (net_devices_dict [device ] + " (" + device + ")" )
11421181 dev_output = ""
1143- for count , dev in enumerate (net_iommu_devs_list , start = 1 ):
1144- if count == len (net_iommu_devs_list ):
1182+ for count , dev in enumerate (net_devs_list , start = 1 ):
1183+ if count == len (net_devs_list ):
11451184 dev_output = dev_output + f"{ dev } "
11461185 elif count % 3 != 0 :
11471186 dev_output = dev_output + f"{ dev } , "
11481187 else :
11491188 dev_output = dev_output + f"{ dev } ,\n "
11501189 return (
11511190 CheckState .SUCCESS ,
1152- "IOMMU enabled for vfio-pci with the following PCI device(s):\n "
1153- + dev_output ,
1191+ "The following PCI device(s) are available:\n " + dev_output ,
11541192 )
11551193
11561194
@@ -1505,6 +1543,7 @@ VROUTER_CHECKS = [
15051543 Check ("Hugepages" , check_hugepages , []),
15061544 Check ("Interface kernel driver" , check_interface_kernel_driver , []),
15071545 Check ("IOMMU" , check_iommu , ["Interface kernel driver" ]),
1546+ Check ("PCI devices" , check_pci_devices , ["Interface kernel driver" ]),
15081547 Check ("Shared memory pages max size" , check_shmem_pages_max_size , []),
15091548 Check ("Real-time Group Scheduling" , check_realtime_group_sched , []),
15101549]
0 commit comments