runtime: Re-vendor GoVMM

for vhost-user-fs-ccw devno support

shortlog:
f0e9a35 Merge pull request #171 from Jakob-Naucke/fix-virtiofs-s390x
abd3c7e qemu: VhostUserDevice CCW device numbers
3eaeda7 qemu: Refactor vhostuserDev.QemuParams
7183b12 Merge pull request #166 from kata-containers/egernst-patch-1
092293f Merge pull request #169 from QiuMike/master
511cf58 Fix qemu commandline issue with empty romfile
8ba62b0 Merge pull request #164 from devimc/2021-03-30/tdxSupport
b3eac95 qmp: remove frequent, chatty log
3141894 qemu: add support for tdx-guest object

Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
This commit is contained in:
Jakob Naucke 2021-04-26 18:05:10 +02:00
parent adba4532a4
commit 8385ff9554
No known key found for this signature in database
GPG Key ID: 45FA1C7D310C0EBE
5 changed files with 164 additions and 79 deletions

View File

@ -31,7 +31,7 @@ require (
github.com/gogo/googleapis v1.4.0 // indirect
github.com/gogo/protobuf v1.3.1
github.com/hashicorp/go-multierror v1.0.0
github.com/kata-containers/govmm v0.0.0-20210329205824-7fbc685865d2
github.com/kata-containers/govmm v0.0.0-20210428163604-f0e9a35308ee
github.com/mdlayher/vsock v0.0.0-20191108225356-d9c65923cb8f
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v1.0.0-rc9.0.20200102164712-2b52db75279c

View File

@ -278,6 +278,8 @@ github.com/kata-containers/govmm v0.0.0-20210112013750-7d320e8f5dca h1:UdXFthwas
github.com/kata-containers/govmm v0.0.0-20210112013750-7d320e8f5dca/go.mod h1:VmAHbsL5lLfzHW/MNL96NVLF840DNEV5i683kISgFKk=
github.com/kata-containers/govmm v0.0.0-20210329205824-7fbc685865d2 h1:oDJsQ5avmW8PFUkSJdsuaGL3SR4/YQRno51GNGl+IDU=
github.com/kata-containers/govmm v0.0.0-20210329205824-7fbc685865d2/go.mod h1:VmAHbsL5lLfzHW/MNL96NVLF840DNEV5i683kISgFKk=
github.com/kata-containers/govmm v0.0.0-20210428163604-f0e9a35308ee h1:M4N7AdSHgWz/ubV5AZQdeqmK+9Ztpea6oqeXgk8GCHk=
github.com/kata-containers/govmm v0.0.0-20210428163604-f0e9a35308ee/go.mod h1:VmAHbsL5lLfzHW/MNL96NVLF840DNEV5i683kISgFKk=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=

View File

@ -227,6 +227,9 @@ type ObjectType string
const (
// MemoryBackendFile represents a guest memory mapped file.
MemoryBackendFile ObjectType = "memory-backend-file"
// TDXGuest represents a TDX object
TDXGuest ObjectType = "tdx-guest"
)
// Object is a qemu object representation.
@ -249,6 +252,12 @@ type Object struct {
// Size is the object size in bytes
Size uint64
// Debug this is a debug object
Debug bool
// File is the device file
File string
}
// Valid returns true if the Object structure is valid and complete.
@ -259,6 +268,11 @@ func (object Object) Valid() bool {
return false
}
case TDXGuest:
if object.ID == "" || object.File == "" || object.DeviceID == "" {
return false
}
default:
return false
}
@ -283,6 +297,13 @@ func (object Object) QemuParams(config *Config) []string {
objectParams = append(objectParams, fmt.Sprintf(",size=%d", object.Size))
deviceParams = append(deviceParams, fmt.Sprintf(",memdev=%s", object.ID))
case TDXGuest:
objectParams = append(objectParams, string(object.Type))
objectParams = append(objectParams, fmt.Sprintf(",id=%s", object.ID))
if object.Debug {
objectParams = append(objectParams, ",debug=on")
}
deviceParams = append(deviceParams, fmt.Sprintf(",file=%s", object.File))
}
qemuParams = append(qemuParams, "-device")
@ -408,7 +429,7 @@ func (fsdev FSDevice) QemuParams(config *Config) []string {
}
deviceParams = append(deviceParams, fmt.Sprintf(",fsdev=%s", fsdev.ID))
deviceParams = append(deviceParams, fmt.Sprintf(",mount_tag=%s", fsdev.MountTag))
if fsdev.Transport.isVirtioPCI(config) {
if fsdev.Transport.isVirtioPCI(config) && fsdev.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", fsdev.ROMFile))
}
if fsdev.Transport.isVirtioCCW(config) {
@ -541,7 +562,7 @@ func (cdev CharDevice) QemuParams(config *Config) []string {
if cdev.Name != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",name=%s", cdev.Name))
}
if cdev.Driver == VirtioSerial && cdev.Transport.isVirtioPCI(config) {
if cdev.Driver == VirtioSerial && cdev.Transport.isVirtioPCI(config) && cdev.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", cdev.ROMFile))
}
@ -811,7 +832,7 @@ func (netdev NetDevice) QemuDeviceParams(config *Config) []string {
deviceParams = append(deviceParams, netdev.mqParameter(config))
}
if netdev.Transport.isVirtioPCI(config) {
if netdev.Transport.isVirtioPCI(config) && netdev.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", netdev.ROMFile))
}
@ -944,7 +965,7 @@ func (dev SerialDevice) QemuParams(config *Config) []string {
deviceParams = append(deviceParams, fmt.Sprintf(",%s", s))
}
deviceParams = append(deviceParams, fmt.Sprintf(",id=%s", dev.ID))
if dev.Transport.isVirtioPCI(config) {
if dev.Transport.isVirtioPCI(config) && dev.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", dev.ROMFile))
if dev.Driver == VirtioSerial && dev.MaxPorts != 0 {
deviceParams = append(deviceParams, fmt.Sprintf(",max_ports=%d", dev.MaxPorts))
@ -1075,7 +1096,7 @@ func (blkdev BlockDevice) QemuParams(config *Config) []string {
deviceParams = append(deviceParams, ",config-wce=off")
}
if blkdev.Transport.isVirtioPCI(config) {
if blkdev.Transport.isVirtioPCI(config) && blkdev.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", blkdev.ROMFile))
}
@ -1190,6 +1211,9 @@ type VhostUserDevice struct {
// ROMFile specifies the ROM file being used for this device.
ROMFile string
// DevNo identifies the CCW device for s390x.
DevNo string
// Transport is the virtio transport for this device.
Transport VirtioTransport
}
@ -1254,22 +1278,13 @@ func (vhostuserDev VhostUserDevice) Valid() bool {
return true
}
// QemuParams returns the qemu parameters built out of this vhostuser device.
func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
// QemuNetParams builds QEMU netdev and device parameters for a VhostUserNet device
func (vhostuserDev VhostUserDevice) QemuNetParams(config *Config) []string {
var qemuParams []string
var charParams []string
var netParams []string
var devParams []string
var driver string
charParams = append(charParams, "socket")
charParams = append(charParams, fmt.Sprintf("id=%s", vhostuserDev.CharDevID))
charParams = append(charParams, fmt.Sprintf("path=%s", vhostuserDev.SocketPath))
switch vhostuserDev.VhostUserType {
// if network based vhost device:
case VhostUserNet:
driver = vhostuserDev.deviceName(config)
driver := vhostuserDev.deviceName(config)
if driver == "" {
return nil
}
@ -1282,8 +1297,25 @@ func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
devParams = append(devParams, driver)
devParams = append(devParams, fmt.Sprintf("netdev=%s", vhostuserDev.TypeDevID))
devParams = append(devParams, fmt.Sprintf("mac=%s", vhostuserDev.Address))
case VhostUserSCSI:
driver = vhostuserDev.deviceName(config)
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
}
qemuParams = append(qemuParams, "-netdev")
qemuParams = append(qemuParams, strings.Join(netParams, ","))
qemuParams = append(qemuParams, "-device")
qemuParams = append(qemuParams, strings.Join(devParams, ","))
return qemuParams
}
// QemuSCSIParams builds QEMU device parameters for a VhostUserSCSI device
func (vhostuserDev VhostUserDevice) QemuSCSIParams(config *Config) []string {
var qemuParams []string
var devParams []string
driver := vhostuserDev.deviceName(config)
if driver == "" {
return nil
}
@ -1291,8 +1323,23 @@ func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
devParams = append(devParams, driver)
devParams = append(devParams, fmt.Sprintf("id=%s", vhostuserDev.TypeDevID))
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
case VhostUserBlk:
driver = vhostuserDev.deviceName(config)
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
}
qemuParams = append(qemuParams, "-device")
qemuParams = append(qemuParams, strings.Join(devParams, ","))
return qemuParams
}
// QemuBlkParams builds QEMU device parameters for a VhostUserBlk device
func (vhostuserDev VhostUserDevice) QemuBlkParams(config *Config) []string {
var qemuParams []string
var devParams []string
driver := vhostuserDev.deviceName(config)
if driver == "" {
return nil
}
@ -1301,8 +1348,23 @@ func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
devParams = append(devParams, "logical_block_size=4096")
devParams = append(devParams, "size=512M")
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
case VhostUserFS:
driver = vhostuserDev.deviceName(config)
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
}
qemuParams = append(qemuParams, "-device")
qemuParams = append(qemuParams, strings.Join(devParams, ","))
return qemuParams
}
// QemuFSParams builds QEMU device parameters for a VhostUserFS device
func (vhostuserDev VhostUserDevice) QemuFSParams(config *Config) []string {
var qemuParams []string
var devParams []string
driver := vhostuserDev.deviceName(config)
if driver == "" {
return nil
}
@ -1316,28 +1378,52 @@ func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
if vhostuserDev.SharedVersions {
devParams = append(devParams, "versiontable=/dev/shm/fuse_shared_versions")
}
default:
return nil
if vhostuserDev.Transport.isVirtioCCW(config) {
devParams = append(devParams, fmt.Sprintf("devno=%s", vhostuserDev.DevNo))
}
if vhostuserDev.Transport.isVirtioPCI(config) {
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
}
qemuParams = append(qemuParams, "-chardev")
qemuParams = append(qemuParams, strings.Join(charParams, ","))
// if network based vhost device:
if vhostuserDev.VhostUserType == VhostUserNet {
qemuParams = append(qemuParams, "-netdev")
qemuParams = append(qemuParams, strings.Join(netParams, ","))
}
qemuParams = append(qemuParams, "-device")
qemuParams = append(qemuParams, strings.Join(devParams, ","))
return qemuParams
}
// QemuParams returns the qemu parameters built out of this vhostuser device.
func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
var qemuParams []string
var charParams []string
var devParams []string
charParams = append(charParams, "socket")
charParams = append(charParams, fmt.Sprintf("id=%s", vhostuserDev.CharDevID))
charParams = append(charParams, fmt.Sprintf("path=%s", vhostuserDev.SocketPath))
qemuParams = append(qemuParams, "-chardev")
qemuParams = append(qemuParams, strings.Join(charParams, ","))
switch vhostuserDev.VhostUserType {
case VhostUserNet:
devParams = vhostuserDev.QemuNetParams(config)
case VhostUserSCSI:
devParams = vhostuserDev.QemuSCSIParams(config)
case VhostUserBlk:
devParams = vhostuserDev.QemuBlkParams(config)
case VhostUserFS:
devParams = vhostuserDev.QemuFSParams(config)
default:
return nil
}
if devParams != nil {
return append(qemuParams, devParams...)
}
return nil
}
// deviceName returns the QEMU device name for the current combination of
// driver and transport.
func (vhostuserDev VhostUserDevice) deviceName(config *Config) string {
@ -1510,8 +1596,10 @@ func (vfioDev VFIODevice) QemuParams(config *Config) []string {
if vfioDev.DeviceID != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",x-pci-device-id=%s", vfioDev.DeviceID))
}
if vfioDev.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", vfioDev.ROMFile))
}
}
if vfioDev.Bus != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",bus=%s", vfioDev.Bus))
@ -1595,7 +1683,7 @@ func (scsiCon SCSIController) QemuParams(config *Config) []string {
if scsiCon.IOThread != "" {
devParams = append(devParams, fmt.Sprintf("iothread=%s", scsiCon.IOThread))
}
if scsiCon.Transport.isVirtioPCI(config) {
if scsiCon.Transport.isVirtioPCI(config) && scsiCon.ROMFile != "" {
devParams = append(devParams, fmt.Sprintf("romfile=%s", scsiCon.ROMFile))
}
@ -1701,7 +1789,7 @@ func (bridgeDev BridgeDevice) QemuParams(config *Config) []string {
}
var transport VirtioTransport
if transport.isVirtioPCI(config) {
if transport.isVirtioPCI(config) && bridgeDev.ROMFile != "" {
deviceParam = append(deviceParam, fmt.Sprintf(",romfile=%s", bridgeDev.ROMFile))
}
@ -1780,7 +1868,7 @@ func (vsock VSOCKDevice) QemuParams(config *Config) []string {
deviceParams = append(deviceParams, fmt.Sprintf(",id=%s", vsock.ID))
deviceParams = append(deviceParams, fmt.Sprintf(",%s=%d", VSOCKGuestCID, vsock.ContextID))
if vsock.Transport.isVirtioPCI(config) {
if vsock.Transport.isVirtioPCI(config) && vsock.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", vsock.ROMFile))
}
@ -1853,7 +1941,7 @@ func (v RngDevice) QemuParams(config *Config) []string {
deviceParams = append(deviceParams, v.deviceName(config))
deviceParams = append(deviceParams, "rng="+v.ID)
if v.Transport.isVirtioPCI(config) {
if v.Transport.isVirtioPCI(config) && v.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf("romfile=%s", v.ROMFile))
}
@ -1930,7 +2018,7 @@ func (b BalloonDevice) QemuParams(config *Config) []string {
deviceParams = append(deviceParams, "id="+b.ID)
}
if b.Transport.isVirtioPCI(config) {
if b.Transport.isVirtioPCI(config) && b.ROMFile != "" {
deviceParams = append(deviceParams, fmt.Sprintf("romfile=%s", b.ROMFile))
}

View File

@ -267,10 +267,6 @@ func (q *QMP) readLoop(fromVMCh chan<- []byte) {
for scanner.Scan() {
line := scanner.Bytes()
if q.cfg.Logger.V(1) {
q.cfg.Logger.Infof("read from QMP: %s", string(line))
}
// Since []byte channel type transfer slice info(include slice underlying array pointer, len, cap)
// between channel sender and receiver. scanner.Bytes() returned slice's underlying array
// may point to data that will be overwritten by a subsequent call to Scan(reference from:
@ -442,7 +438,6 @@ func (q *QMP) writeNextQMPCommand(cmdQueue *list.List) {
}
cmdQueue.Remove(cmdEl)
}
q.cfg.Logger.Infof("%s", string(encodedCmd))
encodedCmd = append(encodedCmd, '\n')
if unixConn, ok := q.conn.(*net.UnixConn); ok && len(cmd.oob) > 0 {
_, _, err = unixConn.WriteMsgUnix(encodedCmd, cmd.oob, nil)

View File

@ -222,7 +222,7 @@ github.com/hashicorp/errwrap
# github.com/hashicorp/go-multierror v1.0.0
## explicit
github.com/hashicorp/go-multierror
# github.com/kata-containers/govmm v0.0.0-20210329205824-7fbc685865d2
# github.com/kata-containers/govmm v0.0.0-20210428163604-f0e9a35308ee
## explicit
github.com/kata-containers/govmm/qemu
# github.com/konsorten/go-windows-terminal-sequences v1.0.1