Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
qemu: support appending a vIOMMU device
Browse files Browse the repository at this point in the history
Add a new function appendIOMMU() to the qemuArch interface
and provide an implementation on amd64 architecture.

Signed-off-by: Adrian Moreno <[email protected]>
  • Loading branch information
amorenoz committed Jun 9, 2020
1 parent 401ad67 commit 66b54f8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ type qemuArch interface {

// appendPCIeRootPortDevice appends a pcie-root-port device to pcie.0 bus
appendPCIeRootPortDevice(devices []govmmQemu.Device, number uint32) []govmmQemu.Device

// append vIOMMU device
appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error)
}

type qemuArchBase struct {
Expand Down Expand Up @@ -768,4 +771,22 @@ func (q *qemuArchBase) addBridge(b types.Bridge) {
// appendPCIeRootPortDevice appends to devices the given pcie-root-port
func (q *qemuArchBase) appendPCIeRootPortDevice(devices []govmmQemu.Device, number uint32) []govmmQemu.Device {
return genericAppendPCIeRootPort(devices, number, q.machineType)

}

// appendIOMMU appends a virtual IOMMU device
func (q *qemuArchBase) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
switch q.machineType {
case QemuQ35:
iommu := govmmQemu.IommuDev{
Intremap: true,
DeviceIotlb: true,
CachingMode: true,
}

devices = append(devices, iommu)
return devices, nil
default:
return devices, fmt.Errorf("Machine Type %s does not support vIOMMU", q.machineType)
}
}
24 changes: 24 additions & 0 deletions virtcontainers/qemu_arch_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,27 @@ func TestQemuArchBaseAppendNetwork(t *testing.T) {
assert.NoError(err)
assert.Equal(expectedOut, devices)
}

func TestQemuArchBaseAppendIOMMU(t *testing.T) {
var devices []govmmQemu.Device
var err error
assert := assert.New(t)
qemuArchBase := newQemuArchBase()

expectedOut := []govmmQemu.Device{
govmmQemu.IommuDev{
Intremap: true,
DeviceIotlb: true,
CachingMode: true,
},
}
// Test IOMMU is not appended to PC machine type
qemuArchBase.machineType = QemuPC
devices, err = qemuArchBase.appendIOMMU(devices)
assert.Error(err)

qemuArchBase.machineType = QemuQ35
devices, err = qemuArchBase.appendIOMMU(devices)
assert.NoError(err)
assert.Equal(expectedOut, devices)
}
4 changes: 4 additions & 0 deletions virtcontainers/qemu_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ func (q *qemuArm64) setIgnoreSharedMemoryMigrationCaps(_ context.Context, _ *gov
// x-ignore-shared not support in arm64 for now
return nil
}

func (q *qemuArm64) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
return devices, fmt.Errorf("Arm64 architecture does not support vIOMMU")
}
4 changes: 4 additions & 0 deletions virtcontainers/qemu_ppc64le.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ func (q *qemuPPC64le) memoryTopology(memoryMb, hostMemoryMb uint64, slots uint8)
func (q *qemuPPC64le) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
return genericAppendBridges(devices, q.Bridges, q.machineType)
}

func (q *qemuPPC64le) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
return devices, fmt.Errorf("PPC64le does not support appending a vIOMMU")
}
4 changes: 4 additions & 0 deletions virtcontainers/qemu_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,7 @@ func (q *qemuS390x) appendVSock(devices []govmmQemu.Device, vsock types.VSock) (
return devices, nil

}

func (q *qemuS390x) appendIOMMU(devices []govmmQemu.Device) ([]govmmQemu.Device, error) {
return devices, fmt.Errorf("S390x does not support appending a vIOMMU")
}

0 comments on commit 66b54f8

Please sign in to comment.