@@ -1104,6 +1104,45 @@ def check_iommu() -> CheckFuncReturn:
1104
1104
f"Unable to check if IOMMU is enabled by listing { iommu_dev_filepath } .\n "
1105
1105
+ recommendation ,
1106
1106
)
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
+
1107
1146
# List the network PCI devices
1108
1147
try :
1109
1148
cmd = "lshw -businfo -c network"
@@ -1112,8 +1151,6 @@ def check_iommu() -> CheckFuncReturn:
1112
1151
r"pci@([\da-f]{4}:[\da-f]{2}:[\da-f]{2}\.[\da-f])\s+(\S+)" , output
1113
1152
)
1114
1153
if not matches :
1115
- # This should always be a warning - we need PCI devices whether
1116
- # we're using igb_uio or vfio-pci.
1117
1154
return CheckState .WARNING , "no PCI network devices found"
1118
1155
network_devices = set ()
1119
1156
net_devices_dict = {}
@@ -1126,31 +1163,32 @@ def check_iommu() -> CheckFuncReturn:
1126
1163
return (
1127
1164
CheckState .ERROR ,
1128
1165
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." ,
1141
1167
)
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 + ")" )
1142
1181
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 ):
1145
1184
dev_output = dev_output + f"{ dev } "
1146
1185
elif count % 3 != 0 :
1147
1186
dev_output = dev_output + f"{ dev } , "
1148
1187
else :
1149
1188
dev_output = dev_output + f"{ dev } ,\n "
1150
1189
return (
1151
1190
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 ,
1154
1192
)
1155
1193
1156
1194
@@ -1505,6 +1543,7 @@ VROUTER_CHECKS = [
1505
1543
Check ("Hugepages" , check_hugepages , []),
1506
1544
Check ("Interface kernel driver" , check_interface_kernel_driver , []),
1507
1545
Check ("IOMMU" , check_iommu , ["Interface kernel driver" ]),
1546
+ Check ("PCI devices" , check_pci_devices , ["Interface kernel driver" ]),
1508
1547
Check ("Shared memory pages max size" , check_shmem_pages_max_size , []),
1509
1548
Check ("Real-time Group Scheduling" , check_realtime_group_sched , []),
1510
1549
]
0 commit comments