Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
qemu: support vfio pass x-pci-vendor-id and x-pci-device-id pass
Browse files Browse the repository at this point in the history
since some vendor id like 1ded can not be identified by virtio-pci
driver, so need to pass a specified vendor id to qemu.

Fixes: #1894

Signed-off-by: Ace-Tang <[email protected]>
  • Loading branch information
Ace-Tang committed Jul 19, 2019
1 parent 2cf4189 commit 50e263d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions virtcontainers/device/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion virtcontainers/physical_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
)

Expand Down
22 changes: 22 additions & 0 deletions virtcontainers/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 50e263d

Please sign in to comment.