qat: detect noiommu mode with VFIO

If the kernel has CONFIG_VFIO_NOIOMMU enabled and the node admin
has explicitly set enable_unsafe_noiommu_mode VFIO parameter,
VFIO taints the kernel and writes "vfio-noiommu" to the IOMMU
group name. If these conditions are true, the /dev/vfio/ devices
are prefixed with "noiommu-".

This use-case is documented for DPDK so we don't want to break
it (as it was before because we added DeviceMounts to
/dev/vfio/<iommugroup> files that did not exist).

See DPDK documentation for further information and warnings.

Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
This commit is contained in:
Mikko Ylinen 2022-01-04 16:48:47 +02:00
parent 08d0bcf503
commit c306f5ef68
2 changed files with 41 additions and 1 deletions

View File

@ -169,6 +169,15 @@ func (dp *DevicePlugin) getDpdkDevice(vfBdf string) (string, error) {
s := filepath.Base(group)
// If the kernel has CONFIG_VFIO_NOIOMMU enabled and the node admin
// has explicitly set enable_unsafe_noiommu_mode VFIO parameter,
// VFIO taints the kernel and writes "vfio-noiommu" to the IOMMU
// group name. If these conditions are true, the /dev/vfio/ devices
// are prefixed with "noiommu-".
if isVfioNoIOMMU(vfioDirPath) {
s = fmt.Sprintf("noiommu-%s", s)
}
return s, nil
default:
@ -176,6 +185,16 @@ func (dp *DevicePlugin) getDpdkDevice(vfBdf string) (string, error) {
}
}
func isVfioNoIOMMU(iommuGroupPath string) bool {
if fileData, err := os.ReadFile(filepath.Join(iommuGroupPath, "name")); err == nil {
if strings.TrimSpace(string(fileData)) == "vfio-noiommu" {
return true
}
}
return false
}
func (dp *DevicePlugin) getDpdkDeviceSpecs(dpdkDeviceName string) []pluginapi.DeviceSpec {
switch dp.dpdkDriver {
case igbUio:

View File

@ -348,7 +348,7 @@ func TestScan(t *testing.T) {
expectedErr: true,
},
{
name: "vfio-pci DPDKdriver with one kernel bound device (QAT device) where vfdevID is equal to qatDevId (37c9), running in a VM",
name: "vfio-pci DPDKdriver with one kernel bound device (QAT device) where vfdevID is equal to qatDevId (37c9), running in a VM with vIOMMU",
dpdkDriver: "vfio-pci",
kernelVfDrivers: []string{"c6xxvf"},
dirs: []string{
@ -366,6 +366,27 @@ func TestScan(t *testing.T) {
maxDevNum: 1,
expectedDevNum: 1,
},
{
name: "vfio-pci DPDKdriver in unsafe NOIOMMU mode with one kernel bound device (QAT device) where vfdevID is equal to qatDevId (37c9), running in a VM without IOMMU",
dpdkDriver: "vfio-pci",
kernelVfDrivers: []string{"c6xxvf"},
dirs: []string{
"sys/bus/pci/drivers/c6xxvf",
"sys/bus/pci/drivers/vfio-pci",
"sys/bus/pci/devices/0000:02:01.0",
"sys/kernel/iommu_groups/vfiotestfile",
},
files: map[string][]byte{
"sys/bus/pci/devices/0000:02:01.0/device": []byte("0x37c9"),
"sys/kernel/iommu_groups/vfiotestfile/name": []byte("vfio-noiommu"),
},
symlinks: map[string]string{
"sys/bus/pci/devices/0000:02:01.0/iommu_group": "sys/kernel/iommu_groups/vfiotestfile",
"sys/bus/pci/devices/0000:02:01.0/driver": "sys/bus/pci/drivers/c6xxvf",
},
maxDevNum: 1,
expectedDevNum: 1,
},
}
for _, tt := range tcases {
t.Run(tt.name, func(t *testing.T) {