diff --git a/Gopkg.lock b/Gopkg.lock index 57b06eced..fad325a75 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -115,11 +115,11 @@ revision = "3520598351bb3500a49ae9563f5539666ae0a27c" [[projects]] - digest = "1:a801632523299b53fbd954449f36020cf751e4bd6fe2d923e3416e8f0603b4af" + digest = "1:e35245b8aac4b53c6dd7b161c8c19f038e2ad29a54a03d276a88f3fc2a656c29" name = "github.com/intel/govmm" packages = ["qemu"] pruneopts = "NUT" - revision = "eda239928bfa12b214e9c93192d548cccf4e7f1e" + revision = "d8f80cafe3ee3bba440a9ff8d234817b64a30b07" [[projects]] digest = "1:55460fbdfca464360cec902b0805126451908aa1a058fe4072b01650ebe768b3" diff --git a/Gopkg.toml b/Gopkg.toml index 36d68e26f..a3914ffd3 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -52,7 +52,7 @@ [[constraint]] name = "github.com/intel/govmm" - revision = "eda239928bfa12b214e9c93192d548cccf4e7f1e" + revision = "d8f80cafe3ee3bba440a9ff8d234817b64a30b07" [[constraint]] name = "github.com/kata-containers/agent" diff --git a/vendor/github.com/intel/govmm/qemu/qemu.go b/vendor/github.com/intel/govmm/qemu/qemu.go index 31254231d..d2f27f51d 100644 --- a/vendor/github.com/intel/govmm/qemu/qemu.go +++ b/vendor/github.com/intel/govmm/qemu/qemu.go @@ -1064,16 +1064,12 @@ type RTC struct { // Valid returns true if the RTC structure is valid and complete. func (rtc RTC) Valid() bool { - if rtc.Clock != "" { - if rtc.Clock != Host && rtc.Clock != VM { - return false - } + if rtc.Clock != Host && rtc.Clock != VM { + return false } - if rtc.DriftFix != "" { - if rtc.DriftFix != Slew && rtc.DriftFix != NoDriftFix { - return false - } + if rtc.DriftFix != Slew && rtc.DriftFix != NoDriftFix { + return false } return true @@ -1239,7 +1235,7 @@ type Config struct { // Path is the qemu binary path. Path string - // Ctx is not used at the moment. + // Ctx is the context used when launching qemu. Ctx context.Context // Name is the qemu guest name @@ -1636,7 +1632,12 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) { return "", err } - return LaunchCustomQemu(config.Ctx, config.Path, config.qemuParams, + ctx := config.Ctx + if ctx == nil { + ctx = context.Background() + } + + return LaunchCustomQemu(ctx, config.Path, config.qemuParams, config.fds, nil, logger) } @@ -1644,10 +1645,6 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) { // // The path parameter is used to pass the qemu executable path. // -// The ctx parameter is not currently used but has been added so that the -// signature of this function will not need to change when launch cancellation -// is implemented. -// // params is a slice of options to pass to qemu-system-x86_64 and fds is a // list of open file descriptors that are to be passed to the spawned qemu // process. The attrs parameter can be used to control aspects of the @@ -1672,7 +1669,7 @@ func LaunchCustomQemu(ctx context.Context, path string, params []string, fds []* } /* #nosec */ - cmd := exec.Command(path, params...) + cmd := exec.CommandContext(ctx, path, params...) if len(fds) > 0 { logger.Infof("Adding extra file %v", fds) cmd.ExtraFiles = fds diff --git a/vendor/github.com/intel/govmm/qemu/qmp.go b/vendor/github.com/intel/govmm/qemu/qmp.go index ea6cb6454..92000fe03 100644 --- a/vendor/github.com/intel/govmm/qemu/qmp.go +++ b/vendor/github.com/intel/govmm/qemu/qmp.go @@ -671,7 +671,8 @@ func (q *QMP) ExecuteBlockdevAdd(ctx context.Context, device, blockdevID string) // to a previous call to ExecuteBlockdevAdd. devID is the id of the device to // add. Both strings must be valid QMP identifiers. driver is the name of the // driver,e.g., virtio-blk-pci, and bus is the name of the bus. bus is optional. -func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string) error { +// shared denotes if the drive can be shared allowing it to be passed more than once. +func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string, shared bool) error { args := map[string]interface{}{ "id": devID, "driver": driver, @@ -680,6 +681,9 @@ func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, b if bus != "" { args["bus"] = bus } + if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) { + args["share-rw"] = "on" + } return q.executeCommand(ctx, "device_add", args, nil) } @@ -689,8 +693,9 @@ func (q *QMP) ExecuteDeviceAdd(ctx context.Context, blockdevID, devID, driver, b // the device to add. Both strings must be valid QMP identifiers. driver is the name of the // scsi driver,e.g., scsi-hd, and bus is the name of a SCSI controller bus. // scsiID is the SCSI id, lun is logical unit number. scsiID and lun are optional, a negative value -// for scsiID and lun is ignored. -func (q *QMP) ExecuteSCSIDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string, scsiID, lun int) error { +// for scsiID and lun is ignored. shared denotes if the drive can be shared allowing it +// to be passed more than once. +func (q *QMP) ExecuteSCSIDeviceAdd(ctx context.Context, blockdevID, devID, driver, bus string, scsiID, lun int, shared bool) error { // TBD: Add drivers for scsi passthrough like scsi-generic and scsi-block drivers := []string{"scsi-hd", "scsi-cd", "scsi-disk"} @@ -718,6 +723,9 @@ func (q *QMP) ExecuteSCSIDeviceAdd(ctx context.Context, blockdevID, devID, drive if lun >= 0 { args["lun"] = lun } + if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) { + args["share-rw"] = "on" + } return q.executeCommand(ctx, "device_add", args, nil) } @@ -820,8 +828,9 @@ func (q *QMP) ExecuteDeviceDel(ctx context.Context, devID string) error { // ExecutePCIDeviceAdd is the PCI version of ExecuteDeviceAdd. This function can be used // to hot plug PCI devices on PCI(E) bridges, unlike ExecuteDeviceAdd this function receive the -// device address on its parent bus. bus is optional. -func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver, addr, bus string) error { +// device address on its parent bus. bus is optional. shared denotes if the drive can be shared +// allowing it to be passed more than once. +func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver, addr, bus string, shared bool) error { args := map[string]interface{}{ "id": devID, "driver": driver, @@ -831,6 +840,10 @@ func (q *QMP) ExecutePCIDeviceAdd(ctx context.Context, blockdevID, devID, driver if bus != "" { args["bus"] = bus } + if shared && (q.version.Major > 2 || (q.version.Major == 2 && q.version.Minor >= 10)) { + args["share-rw"] = "on" + } + return q.executeCommand(ctx, "device_add", args, nil) } @@ -865,6 +878,24 @@ func (q *QMP) ExecutePCIVFIODeviceAdd(ctx context.Context, devID, bdf, addr, bus return q.executeCommand(ctx, "device_add", args, nil) } +// ExecutePCIVFIOMediatedDeviceAdd adds a VFIO mediated device to a QEMU instance using the device_add command. +// This function can be used to hot plug VFIO mediated devices on PCI(E) bridges, unlike +// ExecuteVFIODeviceAdd this function receives the bus and the device address on its parent bus. +// bus is optional. devID is the id of the device to add. Must be valid QMP identifier. sysfsdev is the VFIO +// mediated device. +func (q *QMP) ExecutePCIVFIOMediatedDeviceAdd(ctx context.Context, devID, sysfsdev, addr, bus string) error { + args := map[string]interface{}{ + "id": devID, + "driver": "vfio-pci", + "sysfsdev": sysfsdev, + "addr": addr, + } + if bus != "" { + args["bus"] = bus + } + return q.executeCommand(ctx, "device_add", args, nil) +} + // ExecuteCPUDeviceAdd adds a CPU to a QEMU instance using the device_add command. // driver is the CPU model, cpuID must be a unique ID to identify the CPU, socketID is the socket number within // node/board the CPU belongs to, coreID is the core number within socket the CPU belongs to, threadID is the @@ -956,12 +987,17 @@ func (q *QMP) ExecHotplugMemory(ctx context.Context, qomtype, id, mempath string } // ExecutePCIVSockAdd adds a vhost-vsock-pci bus -func (q *QMP) ExecutePCIVSockAdd(ctx context.Context, id, guestCID, vhostfd string, disableModern bool) error { +func (q *QMP) ExecutePCIVSockAdd(ctx context.Context, id, guestCID, vhostfd, addr, bus string, disableModern bool) error { args := map[string]interface{}{ "driver": VHostVSockPCI, "id": id, "guest-cid": guestCID, "vhostfd": vhostfd, + "addr": addr, + } + + if bus != "" { + args["bus"] = bus } if disableModern { diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index 151222de5..750785b71 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -733,7 +733,7 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error // PCI address is in the format bridge-addr/device-addr eg. "03/02" drive.PCIAddr = fmt.Sprintf("%02x", bridge.Addr) + "/" + addr - if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID); err != nil { + if err = q.qmpMonitorCh.qmp.ExecutePCIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, addr, bridge.ID, true); err != nil { return err } } else { @@ -748,7 +748,7 @@ func (q *qemu) hotplugBlockDevice(drive *config.BlockDrive, op operation) error return err } - if err = q.qmpMonitorCh.qmp.ExecuteSCSIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, bus, scsiID, lun); err != nil { + if err = q.qmpMonitorCh.qmp.ExecuteSCSIDeviceAdd(q.qmpMonitorCh.ctx, drive.ID, devID, driver, bus, scsiID, lun, true); err != nil { return err } }