mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-25 11:13:15 +00:00
Merge pull request #1895 from Ace-Tang/pass-vendor-to-qmp
qemu: support vfio pass x-pci-vendor-id and x-pci-device-id pass
This commit is contained in:
commit
4bd3ea848d
4
Gopkg.lock
generated
4
Gopkg.lock
generated
@ -391,11 +391,11 @@
|
||||
revision = "2f1d1f20f75d5404f53b9edf6b53ed5505508675"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8e8b93094815f3bbc3792eaf78ce5cf45e0376b8ba0c92f3d58714d7a34f5d0b"
|
||||
digest = "1:6b643bd5e349019c33430301a3e5c38324c3014c423fe5e7cf857a8dd341efe2"
|
||||
name = "github.com/intel/govmm"
|
||||
packages = ["qemu"]
|
||||
pruneopts = "NUT"
|
||||
revision = "9f389cb319af066f210b28dc8846d679878fe9f2"
|
||||
revision = "52b2309a558fe89b3e81b85440144b535288ce4f"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:36dfd4701e98a9d8371dd3053e32d4f29e82b07bcc9e655db82138f9273bcb0f"
|
||||
|
@ -48,7 +48,7 @@
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/intel/govmm"
|
||||
revision = "9f389cb319af066f210b28dc8846d679878fe9f2"
|
||||
revision = "52b2309a558fe89b3e81b85440144b535288ce4f"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/kata-containers/agent"
|
||||
|
84
vendor/github.com/intel/govmm/qemu/qemu.go
generated
vendored
84
vendor/github.com/intel/govmm/qemu/qemu.go
generated
vendored
@ -103,6 +103,9 @@ const (
|
||||
|
||||
// PCIePCIBridgeDriver represents a PCIe to PCI bridge device type.
|
||||
PCIePCIBridgeDriver DeviceDriver = "pcie-pci-bridge"
|
||||
|
||||
// VirtioBlockCCW is the CCW block device driver
|
||||
VirtioBlockCCW DeviceDriver = "virtio-blk-ccw"
|
||||
)
|
||||
|
||||
// disableModern returns the parameters with the disable-modern option.
|
||||
@ -249,6 +252,9 @@ type FSDevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// Valid returns true if the FSDevice structure is valid and complete.
|
||||
@ -275,6 +281,9 @@ func (fsdev FSDevice) QemuParams(config *Config) []string {
|
||||
if isVirtioPCI[fsdev.Driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", fsdev.ROMFile))
|
||||
}
|
||||
if isVirtioCCW[fsdev.Driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",devno=%s", fsdev.DevNo))
|
||||
}
|
||||
|
||||
fsParams = append(fsParams, string(fsdev.FSDriver))
|
||||
fsParams = append(fsParams, fmt.Sprintf(",id=%s", fsdev.ID))
|
||||
@ -335,6 +344,9 @@ type CharDevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// Valid returns true if the CharDevice structure is valid and complete.
|
||||
@ -368,6 +380,10 @@ func (cdev CharDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", cdev.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[cdev.Driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",devno=%s", cdev.DevNo))
|
||||
}
|
||||
|
||||
cdevParams = append(cdevParams, string(cdev.Backend))
|
||||
cdevParams = append(cdevParams, fmt.Sprintf(",id=%s", cdev.ID))
|
||||
if cdev.Backend == Socket {
|
||||
@ -450,6 +466,9 @@ type NetDevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// Valid returns true if the NetDevice structure is valid and complete.
|
||||
@ -488,6 +507,7 @@ func (netdev NetDevice) mqParameter() string {
|
||||
vectors := len(netdev.FDs)*2 + 2
|
||||
p = append(p, fmt.Sprintf(",vectors=%d", vectors))
|
||||
}
|
||||
|
||||
return strings.Join(p, "")
|
||||
}
|
||||
|
||||
@ -526,6 +546,10 @@ func (netdev NetDevice) QemuDeviceParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", netdev.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[netdev.Driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",devno=%s", netdev.DevNo))
|
||||
}
|
||||
|
||||
return deviceParams
|
||||
}
|
||||
|
||||
@ -617,6 +641,9 @@ type SerialDevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// Valid returns true if the SerialDevice structure is valid and complete.
|
||||
@ -642,6 +669,10 @@ func (dev SerialDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", dev.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[dev.Driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",devno=%s", dev.DevNo))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(deviceParams, ""))
|
||||
|
||||
@ -694,6 +725,9 @@ type BlockDevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// Valid returns true if the BlockDevice structure is valid and complete.
|
||||
@ -728,6 +762,10 @@ func (blkdev BlockDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", blkdev.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[blkdev.Driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",devno=%s", blkdev.DevNo))
|
||||
}
|
||||
|
||||
blkParams = append(blkParams, fmt.Sprintf("id=%s", blkdev.ID))
|
||||
blkParams = append(blkParams, fmt.Sprintf(",file=%s", blkdev.File))
|
||||
blkParams = append(blkParams, fmt.Sprintf(",aio=%s", blkdev.AIO))
|
||||
@ -860,6 +898,15 @@ type VFIODevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
|
||||
// VendorID specifies vendor id
|
||||
VendorID string
|
||||
|
||||
// DeviceID specifies device id
|
||||
DeviceID string
|
||||
}
|
||||
|
||||
// Valid returns true if the VFIODevice structure is valid and complete.
|
||||
@ -876,9 +923,19 @@ func (vfioDev VFIODevice) QemuParams(config *Config) []string {
|
||||
|
||||
deviceParams = append(deviceParams, fmt.Sprintf("%s,host=%s", driver, vfioDev.BDF))
|
||||
if isVirtioPCI[driver] {
|
||||
if vfioDev.VendorID != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",x-pci-vendor-id=%s", vfioDev.VendorID))
|
||||
}
|
||||
if vfioDev.DeviceID != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",x-pci-device-id=%s", vfioDev.DeviceID))
|
||||
}
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", vfioDev.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",devno=%s", vfioDev.DevNo))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(deviceParams, ""))
|
||||
|
||||
@ -903,6 +960,9 @@ type SCSIController struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// Valid returns true if the SCSIController structure is valid and complete.
|
||||
@ -933,6 +993,10 @@ func (scsiCon SCSIController) QemuParams(config *Config) []string {
|
||||
devParams = append(devParams, fmt.Sprintf("romfile=%s", scsiCon.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[driver] {
|
||||
devParams = append(devParams, fmt.Sprintf("devno=%s", scsiCon.DevNo))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(devParams, ","))
|
||||
|
||||
@ -1041,6 +1105,9 @@ type VSOCKDevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
const (
|
||||
@ -1086,6 +1153,10 @@ func (vsock VSOCKDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", vsock.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",devno=%s", vsock.DevNo))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(deviceParams, ""))
|
||||
|
||||
@ -1104,6 +1175,8 @@ type RngDevice struct {
|
||||
Period uint
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// Valid returns true if the RngDevice structure is valid and complete.
|
||||
@ -1131,6 +1204,10 @@ func (v RngDevice) QemuParams(_ *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf("romfile=%s", v.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf("devno=%s", v.DevNo))
|
||||
}
|
||||
|
||||
if v.Filename != "" {
|
||||
objectParams = append(objectParams, "filename="+v.Filename)
|
||||
}
|
||||
@ -1160,6 +1237,9 @@ type BalloonDevice struct {
|
||||
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the ccw devices for s390x architecture
|
||||
DevNo string
|
||||
}
|
||||
|
||||
// QemuParams returns the qemu parameters built out of the BalloonDevice.
|
||||
@ -1178,6 +1258,10 @@ func (b BalloonDevice) QemuParams(_ *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf("romfile=%s", b.ROMFile))
|
||||
}
|
||||
|
||||
if isVirtioCCW[driver] {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf("devno=%s", b.DevNo))
|
||||
}
|
||||
|
||||
if b.DeflateOnOOM {
|
||||
deviceParams = append(deviceParams, "deflate-on-oom=on")
|
||||
} else {
|
||||
|
3
vendor/github.com/intel/govmm/qemu/qemu_arch_base.go
generated
vendored
3
vendor/github.com/intel/govmm/qemu/qemu_arch_base.go
generated
vendored
@ -61,6 +61,9 @@ var isVirtioPCI = map[DeviceDriver]bool{
|
||||
PCIePCIBridgeDriver: true,
|
||||
}
|
||||
|
||||
// isVirtioCCW is a dummy map to return always false on no-s390x arch
|
||||
var isVirtioCCW = map[DeviceDriver]bool{}
|
||||
|
||||
// QemuNetdevParam converts to the QEMU -netdev parameter notation
|
||||
func (n NetDeviceType) QemuNetdevParam() string {
|
||||
switch n {
|
||||
|
21
vendor/github.com/intel/govmm/qemu/qemus390x.go
generated
vendored
21
vendor/github.com/intel/govmm/qemu/qemus390x.go
generated
vendored
@ -63,6 +63,27 @@ var isVirtioPCI = map[DeviceDriver]bool{
|
||||
PCIePCIBridgeDriver: false,
|
||||
}
|
||||
|
||||
// isVirtioCCW returns if the device is a ccw device
|
||||
var isVirtioCCW = map[DeviceDriver]bool{
|
||||
NVDIMM: false,
|
||||
Virtio9P: true,
|
||||
VirtioNetCCW: true,
|
||||
VirtioSerial: true,
|
||||
VirtioBlock: true,
|
||||
VirtioBlockCCW: true,
|
||||
Console: false,
|
||||
VirtioSerialPort: false,
|
||||
VHostVSock: true,
|
||||
VirtioRng: true,
|
||||
VirtioBalloon: true,
|
||||
VhostUserSCSI: false,
|
||||
VhostUserBlk: false,
|
||||
Vfio: true,
|
||||
VirtioScsi: true,
|
||||
PCIBridgeDriver: false,
|
||||
PCIePCIBridgeDriver: false,
|
||||
}
|
||||
|
||||
// QemuDeviceParam converts to the QEMU -device parameter notation
|
||||
// This function has been reimplemented for the s390x architecture to deal
|
||||
// with the VHOSTUSER case. Vhost user devices are not implemented on s390x
|
||||
|
18
vendor/github.com/intel/govmm/qemu/qmp.go
generated
vendored
18
vendor/github.com/intel/govmm/qemu/qmp.go
generated
vendored
@ -822,9 +822,13 @@ func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, b
|
||||
"driver": driver,
|
||||
"drive": blockdevID,
|
||||
}
|
||||
if bus != "" {
|
||||
|
||||
if isVirtioCCW[DeviceDriver(driver)] {
|
||||
args["devno"] = bus
|
||||
} else if bus != "" {
|
||||
args["bus"] = bus
|
||||
}
|
||||
|
||||
if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) {
|
||||
args["share-rw"] = "on"
|
||||
}
|
||||
@ -870,8 +874,14 @@ func (q *QMP) ExecuteSCSIDeviceAdd(ctx context.Context, blockdevID, devID, drive
|
||||
"id": devID,
|
||||
"driver": driver,
|
||||
"drive": blockdevID,
|
||||
"bus": bus,
|
||||
}
|
||||
|
||||
if isVirtioCCW[DeviceDriver(driver)] {
|
||||
args["devno"] = bus
|
||||
} else {
|
||||
args["bus"] = bus
|
||||
}
|
||||
|
||||
if scsiID >= 0 {
|
||||
args["scsi-id"] = scsiID
|
||||
}
|
||||
@ -1023,13 +1033,13 @@ func (q *QMP) ExecuteNetPCIDeviceAdd(ctx context.Context, netdevID, devID, macAd
|
||||
// using the device_add command. devID is the id of the device to add.
|
||||
// Must be valid QMP identifier. netdevID is the id of nic added by previous netdev_add.
|
||||
// queues is the number of queues of a nic.
|
||||
func (q *QMP) ExecuteNetCCWDeviceAdd(ctx context.Context, netdevID, devID, macAddr, addr, bus string, queues int) error {
|
||||
func (q *QMP) ExecuteNetCCWDeviceAdd(ctx context.Context, netdevID, devID, macAddr, bus string, queues int) error {
|
||||
args := map[string]interface{}{
|
||||
"id": devID,
|
||||
"driver": VirtioNetCCW,
|
||||
"netdev": netdevID,
|
||||
"mac": macAddr,
|
||||
"addr": addr,
|
||||
"devno": bus,
|
||||
}
|
||||
|
||||
if queues > 0 {
|
||||
|
@ -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
|
||||
|
@ -80,8 +80,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)
|
||||
|
@ -1184,7 +1184,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)
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user