Skip to content

Commit

Permalink
iommu skip bridge devices
Browse files Browse the repository at this point in the history
  • Loading branch information
muhamadazmy committed Jun 15, 2023
1 parent bf9a221 commit a780526
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
20 changes: 19 additions & 1 deletion pkg/capacity/pci.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,20 @@ func GPU(p *PCI) bool {
return p.Class == 0x030000
}

func PCIBridge(p *PCI) bool {
// this will include 0x060000 and 0x060400
// or any other pci bridge device
return p.Class>>16 == 0x06
}

func Not(f Filter) Filter {
return func(pci *PCI) bool {
return !f(pci)
}
}

// given a pci device, return all devices in the same iommu group
func IoMMUGroup(pci PCI) ([]PCI, error) {
func IoMMUGroup(pci PCI, filter ...Filter) ([]PCI, error) {
path := filepath.Join(pciDir, pci.Slot, "iommu_group", "devices")
entries, err := os.ReadDir(path)
if os.IsNotExist(err) {
Expand All @@ -226,11 +238,17 @@ func IoMMUGroup(pci PCI) ([]PCI, error) {
}

var devices []PCI
next:
for _, entry := range entries {
pci, err := pciDeviceFromSlot(entry.Name())
if err != nil {
return nil, err
}
for _, f := range filter {
if !f(&pci) {
continue next
}
}

devices = append(devices, pci)
}
Expand Down
11 changes: 3 additions & 8 deletions pkg/primitives/vm/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@ func (m *Manager) initGPUs() error {
return errors.Wrap(err, "failed to list system GPUs")
}

disconnectVT := false
for _, gpu := range gpus {
bootVga, err := gpu.Flag("boot_vga")
if err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "failed to read GPU '%s' boot_vga flag", gpu.Slot)
}
if bootVga > 0 {
disconnectVT = true
m.unbindBootVga()
}

devices, err := capacity.IoMMUGroup(gpu)
devices, err := capacity.IoMMUGroup(gpu, capacity.Not(capacity.PCIBridge))
if err != nil {
return errors.Wrapf(err, "failed to list devices in iommu group for '%s'", gpu.Slot)
}
Expand Down Expand Up @@ -117,10 +116,6 @@ func (m *Manager) initGPUs() error {
}
}

if disconnectVT {
return m.unbindBootVga()
}

return nil
}

Expand All @@ -143,7 +138,7 @@ func (m *Manager) expandGPUs(gpus []zos.GPU) ([]capacity.PCI, error) {
return nil, fmt.Errorf("unknown GPU id '%s'", gpu)
}

sub, err := capacity.IoMMUGroup(device)
sub, err := capacity.IoMMUGroup(device, capacity.Not(capacity.PCIBridge))
if err != nil {
return nil, errors.Wrapf(err, "failed to list all devices belonging to '%s'", device.Slot)
}
Expand Down

0 comments on commit a780526

Please sign in to comment.