-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IOMMUFD support #56
base: main
Are you sure you want to change the base?
Conversation
The new kernel interface exposes VFIO devices via IOMMUFD backend besides the old VFIO container backend aka IOMMU Groups. Add the proper parsing function to gather the correct information. Signed-off-by: Zvonko Kaiser <[email protected]>
Simple test for proper IOMMUFD parsing Signed-off-by: Zvonko Kaiser <[email protected]>
vfioDev := filepath.Join(deviceDir, "vfio-dev") | ||
vfioFD := filepath.Join(vfioDev, "vfio8") | ||
err = os.MkdirAll(vfioFD, 0755) | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Is there a benefit in having two variables?
vfioDev := filepath.Join(deviceDir, "vfio-dev") | |
vfioFD := filepath.Join(vfioDev, "vfio8") | |
err = os.MkdirAll(vfioFD, 0755) | |
if err != nil { | |
return err | |
} | |
vfioFD := filepath.Join(deviceDir, "vfio-dev", "vfio8) | |
err = os.MkdirAll(vfioFD, 0755) | |
if err != nil { | |
return err | |
} |
@@ -74,6 +74,33 @@ func TestNvpci(t *testing.T) { | |||
_, err = nvpci.GetGPUByIndex(1) | |||
require.Error(t, err, "No error returned when getting GPU at invalid index") | |||
} | |||
func TestNvpciIOMMUFD(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we need a newline before this?
func TestNvpciIOMMUFD(t *testing.T) { | |
func TestNvpciIOMMUFD(t *testing.T) { |
@@ -521,6 +528,31 @@ func getDriver(devicePath string) (string, error) { | |||
return "", err | |||
} | |||
|
|||
// /sys/bus/pci/devices/0000:df:00.0/vfio-dev/vfio0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a more descriptive docstring.
// /sys/bus/pci/devices/0000:df:00.0/vfio-dev/vfio0. | ||
func getIOMMUFD(devicePath string) (int, error) { | ||
vfioDevDir := filepath.Join(devicePath, "vfio-dev") | ||
// Read the directory; expect exactly one entry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't check for exactly one entry below. Should we?
case os.IsNotExist(err): | ||
return -1, nil | ||
case err == nil: | ||
if len(entries) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check for the vfio
prefix in the entries? Does using filepath.Glob
make sense here if we're expecting a particular pattern?
name := entries[0].Name() | ||
// Strip the "vfio" prefix to get the numeric part | ||
idxStr := strings.TrimPrefix(name, "vfio") | ||
idx, err := strconv.Atoi(idxStr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should we use ParseInt
here and specify a 64 bit width as we do for the IOMMU Group?
devices, err := nvpci.GetGPUs() | ||
require.Nil(t, err, "Error getting GPUs") | ||
require.Equal(t, 1, len(devices), "Wrong number of GPU devices") | ||
require.Equal(t, 8, devices[0].IommuFD, "Wrong IOMMUFD found for device") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.Equal(t, 8, devices[0].IommuFD, "Wrong IOMMUFD found for device") | |
require.Equal(t, tc.IOMMUFD, devices[0].IommuFD, "Wrong IOMMUFD found for device") |
Add IOMMUFD parsing to NVPCI device.
The new kernel interface exposes VFIO devices via IOMMUFD backend besides the old VFIO container backend aka IOMMU Groups.
Add the proper parsing function to gather the correct information.