Skip to content

Commit

Permalink
unbinding boot vga
Browse files Browse the repository at this point in the history
  • Loading branch information
muhamadazmy committed Jun 14, 2023
1 parent 3d2a841 commit bf9a221
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/capacity/pci.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func (p PCI) String() string {
return fmt.Sprintf("%s %04x: [%04x:%04x]", p.Slot, p.Class, p.Vendor, p.Device)
}

// Flag read a custom flag on PCI device as uint64
func (p *PCI) Flag(name string) (uint64, error) {
return readUint64(filepath.Join(pciDir, p.Slot, name), 64)
}

func pciDeviceFromSlot(slot string) (PCI, error) {
const (
classFile = "class"
Expand Down
19 changes: 18 additions & 1 deletion pkg/primitives/vm/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
)

func (m *Manager) initGPUVfioModules() error {

for _, mod := range modules {
if err := exec.Command("modprobe", mod).Run(); err != nil {
return errors.Wrapf(err, "failed to probe module: %s", mod)
Expand All @@ -34,6 +33,11 @@ func (m *Manager) initGPUVfioModules() error {
return errors.Wrapf(err, "failed to set allow_unsafe_interrupts for vfio")
}

return nil
}

// unbindBootVga is a helper method to disconnect the boot vga if needed
func (m *Manager) unbindBootVga() error {
const vtConsole = "/sys/class/vtconsole"
vts, err := os.ReadDir(vtConsole)
if err != nil && !os.IsNotExist(err) {
Expand Down Expand Up @@ -64,7 +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
}

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

if disconnectVT {
return m.unbindBootVga()
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/vm/ch.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (m *Machine) Run(ctx context.Context, socket, logs string) (pkg.MachineInfo

var devices []string
for _, dev := range m.Devices {
devices = append(devices, fmt.Sprintf("path=/sys/bus/pci/devices/%s/,iommu=on", dev))
devices = append(devices, fmt.Sprintf("path=/sys/bus/pci/devices/%s/", dev))
}

if len(devices) > 0 {
Expand Down

0 comments on commit bf9a221

Please sign in to comment.