Closed
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 <zkaiser@nvidia.com>
Simple test for proper IOMMUFD parsing Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
cdesiniotis
approved these changes
Mar 12, 2025
elezar
reviewed
Mar 13, 2025
Comment on lines
+87
to
+92
| vfioDev := filepath.Join(deviceDir, "vfio-dev") | ||
| vfioFD := filepath.Join(vfioDev, "vfio8") | ||
| err = os.MkdirAll(vfioFD, 0755) | ||
| if err != nil { | ||
| return err | ||
| } |
Member
There was a problem hiding this comment.
nit: Is there a benefit in having two variables?
Suggested change
| 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 | |
| } |
elezar
reviewed
Mar 13, 2025
| _, err = nvpci.GetGPUByIndex(1) | ||
| require.Error(t, err, "No error returned when getting GPU at invalid index") | ||
| } | ||
| func TestNvpciIOMMUFD(t *testing.T) { |
Member
There was a problem hiding this comment.
Seems like we need a newline before this?
Suggested change
| func TestNvpciIOMMUFD(t *testing.T) { | |
| func TestNvpciIOMMUFD(t *testing.T) { |
elezar
reviewed
Mar 13, 2025
| return "", err | ||
| } | ||
|
|
||
| // /sys/bus/pci/devices/0000:df:00.0/vfio-dev/vfio0. |
Member
There was a problem hiding this comment.
Maybe add a more descriptive docstring.
elezar
reviewed
Mar 13, 2025
| // /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 |
Member
There was a problem hiding this comment.
We don't check for exactly one entry below. Should we?
elezar
reviewed
Mar 13, 2025
| case os.IsNotExist(err): | ||
| return -1, nil | ||
| case err == nil: | ||
| if len(entries) == 0 { |
Member
There was a problem hiding this comment.
Should we check for the vfio prefix in the entries? Does using filepath.Glob make sense here if we're expecting a particular pattern?
elezar
reviewed
Mar 13, 2025
| name := entries[0].Name() | ||
| // Strip the "vfio" prefix to get the numeric part | ||
| idxStr := strings.TrimPrefix(name, "vfio") | ||
| idx, err := strconv.Atoi(idxStr) |
Member
There was a problem hiding this comment.
Nit: Should we use ParseInt here and specify a 64 bit width as we do for the IOMMU Group?
elezar
reviewed
Mar 13, 2025
| 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") |
Member
There was a problem hiding this comment.
Suggested change
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.