From 3ec56eaf9fd8e5cec0486a820d4c982da37dfa97 Mon Sep 17 00:00:00 2001 From: Penny Zheng Date: Wed, 13 Feb 2019 12:37:07 +0800 Subject: [PATCH] runtime: add appendBridges for arm64 since generic func genericAppendBridges and genericBridges is also applied for machine type QemuVirt, we use it as implementation for appendBridges and bridges on aarch64. since const defaultPCBridgeBus is used in generic func genericAppendBridges for pc machine, we should define it once in generic file, instead of redefining it in different arch-specific files. Fixes: #1200 Signed-off-by: Penny Zheng --- virtcontainers/qemu_amd64.go | 2 -- virtcontainers/qemu_arch_base.go | 13 +++++++------ virtcontainers/qemu_arm64.go | 13 ++++++++++--- virtcontainers/qemu_arm64_test.go | 27 +++++++++++++++++++++++++++ virtcontainers/qemu_ppc64le.go | 2 -- virtcontainers/qemu_s390x.go | 2 -- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/virtcontainers/qemu_amd64.go b/virtcontainers/qemu_amd64.go index 65d9838e44..7a34270876 100644 --- a/virtcontainers/qemu_amd64.go +++ b/virtcontainers/qemu_amd64.go @@ -24,8 +24,6 @@ const defaultQemuMachineType = QemuPC const defaultQemuMachineOptions = "accel=kvm,kernel_irqchip,nvdimm" -const defaultPCBridgeBus = "pci.0" - var qemuPaths = map[string]string{ QemuPCLite: "/usr/bin/qemu-lite-system-x86_64", QemuPC: defaultQemuPath, diff --git a/virtcontainers/qemu_arch_base.go b/virtcontainers/qemu_arch_base.go index 5e68bfd292..7b6bdc05bc 100644 --- a/virtcontainers/qemu_arch_base.go +++ b/virtcontainers/qemu_arch_base.go @@ -116,12 +116,13 @@ type qemuArchBase struct { } const ( - defaultCores uint32 = 1 - defaultThreads uint32 = 1 - defaultCPUModel = "host" - defaultBridgeBus = "pcie.0" - maxDevIDSize = 31 - defaultMsize9p = 8192 + defaultCores uint32 = 1 + defaultThreads uint32 = 1 + defaultCPUModel = "host" + defaultBridgeBus = "pcie.0" + defaultPCBridgeBus = "pci.0" + maxDevIDSize = 31 + defaultMsize9p = 8192 ) // This is the PCI start address assigned to the first bridge that diff --git a/virtcontainers/qemu_arm64.go b/virtcontainers/qemu_arm64.go index bc72b0fa79..49c0923090 100644 --- a/virtcontainers/qemu_arm64.go +++ b/virtcontainers/qemu_arm64.go @@ -11,6 +11,7 @@ import ( "strings" govmmQemu "github.com/intel/govmm/qemu" + "github.com/kata-containers/runtime/virtcontainers/types" "github.com/sirupsen/logrus" ) @@ -25,9 +26,6 @@ const defaultQemuMachineType = QemuVirt var defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=" + getGuestGICVersion() -// Not used -const defaultPCBridgeBus = "" - var qemuPaths = map[string]string{ QemuVirt: defaultQemuPath, } @@ -153,3 +151,12 @@ func newQemuArch(config HypervisorConfig) qemuArch { return q } + +func (q *qemuArm64) bridges(number uint32) []types.PCIBridge { + return genericBridges(number, q.machineType) +} + +// appendBridges appends to devices the given bridges +func (q *qemuArm64) appendBridges(devices []govmmQemu.Device, bridges []types.PCIBridge) []govmmQemu.Device { + return genericAppendBridges(devices, bridges, q.machineType) +} diff --git a/virtcontainers/qemu_arm64_test.go b/virtcontainers/qemu_arm64_test.go index ceb0699ad7..a9add75a63 100644 --- a/virtcontainers/qemu_arm64_test.go +++ b/virtcontainers/qemu_arm64_test.go @@ -98,3 +98,30 @@ func TestMaxQemuVCPUs(t *testing.T) { assert.Equal(d.expectedResult, vCPUs) } } + +func TestQemuArm64AppendBridges(t *testing.T) { + var devices []govmmQemu.Device + assert := assert.New(t) + + arm64 := newTestQemu(QemuVirt) + + bridges := arm64.bridges(1) + assert.Len(bridges, 1) + + devices = []govmmQemu.Device{} + devices = arm64.appendBridges(devices, bridges) + assert.Len(devices, 1) + + expectedOut := []govmmQemu.Device{ + govmmQemu.BridgeDevice{ + Type: govmmQemu.PCIEBridge, + Bus: defaultBridgeBus, + ID: bridges[0].ID, + Chassis: 1, + SHPC: true, + Addr: "2", + }, + } + + assert.Equal(expectedOut, devices) +} diff --git a/virtcontainers/qemu_ppc64le.go b/virtcontainers/qemu_ppc64le.go index d986e87963..cc77f683b2 100644 --- a/virtcontainers/qemu_ppc64le.go +++ b/virtcontainers/qemu_ppc64le.go @@ -27,8 +27,6 @@ const defaultQemuMachineType = QemuPseries const defaultQemuMachineOptions = "accel=kvm,usb=off" -const defaultPCBridgeBus = "pci.0" - const defaultMemMaxPPC64le = 32256 // Restrict MemMax to 32Gb on PPC64le var qemuPaths = map[string]string{ diff --git a/virtcontainers/qemu_s390x.go b/virtcontainers/qemu_s390x.go index 1ac865cbfa..e3dc14b573 100644 --- a/virtcontainers/qemu_s390x.go +++ b/virtcontainers/qemu_s390x.go @@ -23,8 +23,6 @@ const defaultQemuMachineType = QemuCCWVirtio const defaultQemuMachineOptions = "accel=kvm" -const defaultPCBridgeBus = "pci.0" - const VirtioSerialCCW = "virtio-serial-ccw" var qemuPaths = map[string]string{