diff --git a/virtcontainers/device/config/config.go b/virtcontainers/device/config/config.go index 2b5d5518e..93fedc187 100644 --- a/virtcontainers/device/config/config.go +++ b/virtcontainers/device/config/config.go @@ -167,6 +167,12 @@ type VFIODev struct { // sysfsdev of VFIO mediated device SysfsDev string + + // VendorID specifies vendor id + VendorID string + + // DeviceID specifies device id + DeviceID string } // RNGDev represents a random number generator device diff --git a/virtcontainers/physical_endpoint.go b/virtcontainers/physical_endpoint.go index 989233f15..77d5c996a 100644 --- a/virtcontainers/physical_endpoint.go +++ b/virtcontainers/physical_endpoint.go @@ -79,8 +79,16 @@ func (endpoint *PhysicalEndpoint) Attach(h hypervisor) error { } // TODO: use device manager as general device management entrance + var vendorID, deviceID string + if splits := strings.Split(endpoint.VendorDeviceID, " "); len(splits) == 2 { + vendorID = splits[0] + deviceID = splits[1] + } + d := config.VFIODev{ - BDF: endpoint.BDF, + BDF: endpoint.BDF, + VendorID: vendorID, + DeviceID: deviceID, } return h.addDevice(d, vfioDev) diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 8743902f2..db66eaf6e 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -1172,7 +1172,7 @@ func (q *qemu) hotplugNetDevice(endpoint Endpoint, op operation) error { return err } if machine.Type == QemuCCWVirtio { - return q.qmpMonitorCh.qmp.ExecuteNetCCWDeviceAdd(q.qmpMonitorCh.ctx, tap.Name, devID, endpoint.HardwareAddr(), addr, bridge.ID, int(q.config.NumVCPUs)) + return q.qmpMonitorCh.qmp.ExecuteNetCCWDeviceAdd(q.qmpMonitorCh.ctx, tap.Name, devID, endpoint.HardwareAddr(), bridge.ID, int(q.config.NumVCPUs)) } return q.qmpMonitorCh.qmp.ExecuteNetPCIDeviceAdd(q.qmpMonitorCh.ctx, tap.Name, devID, endpoint.HardwareAddr(), addr, bridge.ID, romFile, int(q.config.NumVCPUs), defaultDisableModern) } diff --git a/virtcontainers/qemu_arch_base.go b/virtcontainers/qemu_arch_base.go index 4e4ce492c..d8abcf506 100644 --- a/virtcontainers/qemu_arch_base.go +++ b/virtcontainers/qemu_arch_base.go @@ -551,7 +551,9 @@ func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDev conf devices = append(devices, govmmQemu.VFIODevice{ - BDF: vfioDev.BDF, + BDF: vfioDev.BDF, + VendorID: vfioDev.VendorID, + DeviceID: vfioDev.DeviceID, }, ) diff --git a/virtcontainers/qemu_arch_base_test.go b/virtcontainers/qemu_arch_base_test.go index 986592134..07eb7cf61 100644 --- a/virtcontainers/qemu_arch_base_test.go +++ b/virtcontainers/qemu_arch_base_test.go @@ -419,6 +419,28 @@ func TestQemuArchBaseAppendVFIODevice(t *testing.T) { testQemuArchBaseAppend(t, vfDevice, expectedOut) } +func TestQemuArchBaseAppendVFIODeviceWithVendorDeviceID(t *testing.T) { + bdf := "02:10.1" + vendorID := "0x1234" + deviceID := "0x5678" + + expectedOut := []govmmQemu.Device{ + govmmQemu.VFIODevice{ + BDF: bdf, + VendorID: vendorID, + DeviceID: deviceID, + }, + } + + vfDevice := config.VFIODev{ + BDF: bdf, + VendorID: vendorID, + DeviceID: deviceID, + } + + testQemuArchBaseAppend(t, vfDevice, expectedOut) +} + func TestQemuArchBaseAppendSCSIController(t *testing.T) { var devices []govmmQemu.Device assert := assert.New(t)