Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Add support for hot-plugging IBM VFIO-AP devices
Browse files Browse the repository at this point in the history
Add ExecuteAPVFIOMediatedDeviceAdd to qmp.go, which executes a hotplug
for an IBM Adjunct processor (AP) VFIO device (see also
https://www.kernel.org/doc/html/latest/s390/vfio-ap.html )
Also includes the respective unittest and adds the VfioAP DeviceDriver
constant to qemu.go.

Pushing again due to incidental CI failure

Fixes: #133

Signed-off-by: Jakob-Naucke <jakob.naucke@ibm.com>
Reviewed-by: alicefr <afrosi@redhat.com>
  • Loading branch information
Jakob-Naucke committed Aug 12, 2020
1 parent 547a851 commit 4d6f225
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions qemu/qemu.go
Expand Up @@ -123,6 +123,9 @@ const (
// VfioCCW is the vfio driver with CCW transport.
VfioCCW DeviceDriver = "vfio-ccw"

// VfioAP is the vfio driver with AP transport.
VfioAP DeviceDriver = "vfio-ap"

// VHostVSockPCI is a generic Vsock vhost device with PCI transport.
VHostVSockPCI DeviceDriver = "vhost-vsock-pci"

Expand Down
9 changes: 9 additions & 0 deletions qemu/qmp.go
Expand Up @@ -1217,6 +1217,15 @@ func (q *QMP) ExecutePCIVFIOMediatedDeviceAdd(ctx context.Context, devID, sysfsd
return q.executeCommand(ctx, "device_add", args, nil)
}

// ExecuteAPVFIOMediatedDeviceAdd adds a VFIO mediated AP device to a QEMU instance using the device_add command.
func (q *QMP) ExecuteAPVFIOMediatedDeviceAdd(ctx context.Context, sysfsdev string) error {
args := map[string]interface{}{
"driver": VfioAP,
"sysfsdev": sysfsdev,
}
return q.executeCommand(ctx, "device_add", args, nil)
}

// isSocketIDSupported returns if the cpu driver supports the socket id option
func isSocketIDSupported(driver string) bool {
if driver == "host-s390x-cpu" || driver == "host-powerpc64-cpu" {
Expand Down
17 changes: 17 additions & 0 deletions qemu/qmp_test.go
Expand Up @@ -1100,6 +1100,23 @@ func TestQMPPCIVFIOPCIeDeviceAdd(t *testing.T) {
<-disconnectedCh
}

func TestQMPAPVFIOMediatedDeviceAdd(t *testing.T) {
connectedCh := make(chan *QMPVersion)
disconnectedCh := make(chan struct{})
buf := newQMPTestCommandBuffer(t)
buf.AddCommand("device_add", nil, "return", nil)
cfg := QMPConfig{Logger: qmpTestLogger{}}
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
checkVersion(t, connectedCh)
sysfsDev := "/sys/devices/vfio_ap/matrix/a297db4a-f4c2-11e6-90f6-d3b88d6c9525"
err := q.ExecuteAPVFIOMediatedDeviceAdd(context.Background(), sysfsDev)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
q.Shutdown()
<-disconnectedCh
}

// Checks that CPU are correctly added using device_add
func TestQMPCPUDeviceAdd(t *testing.T) {
drivers := []string{"host-x86_64-cpu", "host-s390x-cpu", "host-powerpc64-cpu"}
Expand Down

0 comments on commit 4d6f225

Please sign in to comment.