qemu: support vfio pass x-pci-vendor-id and x-pci-device-id pass

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 <aceapril@126.com>
This commit is contained in:
Ace-Tang 2019-07-19 15:15:11 +08:00
parent 2cf4189244
commit 50e263d943
5 changed files with 41 additions and 3 deletions

View File

@ -167,6 +167,12 @@ type VFIODev struct {
// sysfsdev of VFIO mediated device // sysfsdev of VFIO mediated device
SysfsDev string SysfsDev string
// VendorID specifies vendor id
VendorID string
// DeviceID specifies device id
DeviceID string
} }
// RNGDev represents a random number generator device // RNGDev represents a random number generator device

View File

@ -79,8 +79,16 @@ func (endpoint *PhysicalEndpoint) Attach(h hypervisor) error {
} }
// TODO: use device manager as general device management entrance // 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{ d := config.VFIODev{
BDF: endpoint.BDF, BDF: endpoint.BDF,
VendorID: vendorID,
DeviceID: deviceID,
} }
return h.addDevice(d, vfioDev) return h.addDevice(d, vfioDev)

View File

@ -1172,7 +1172,7 @@ func (q *qemu) hotplugNetDevice(endpoint Endpoint, op operation) error {
return err return err
} }
if machine.Type == QemuCCWVirtio { 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) return q.qmpMonitorCh.qmp.ExecuteNetPCIDeviceAdd(q.qmpMonitorCh.ctx, tap.Name, devID, endpoint.HardwareAddr(), addr, bridge.ID, romFile, int(q.config.NumVCPUs), defaultDisableModern)
} }

View File

@ -551,7 +551,9 @@ func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDev conf
devices = append(devices, devices = append(devices,
govmmQemu.VFIODevice{ govmmQemu.VFIODevice{
BDF: vfioDev.BDF, BDF: vfioDev.BDF,
VendorID: vfioDev.VendorID,
DeviceID: vfioDev.DeviceID,
}, },
) )

View File

@ -419,6 +419,28 @@ func TestQemuArchBaseAppendVFIODevice(t *testing.T) {
testQemuArchBaseAppend(t, vfDevice, expectedOut) 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) { func TestQemuArchBaseAppendSCSIController(t *testing.T) {
var devices []govmmQemu.Device var devices []govmmQemu.Device
assert := assert.New(t) assert := assert.New(t)