From 6e7dd435a2692b9a80a2a47215cbfb7a973ba908 Mon Sep 17 00:00:00 2001 From: Jia He Date: Sun, 28 Jun 2020 20:48:48 -0700 Subject: [PATCH] qemu: arm64: Set defaultGICVersion to 3 to limit the max vCPU number [ port from runtime commit ee985a608015d81772901c1d9999190495fc9a0a ] After removing dectect of host gic version, we need to limit the max vCPU in different cases. Given that in most cases, Kata is running on gicv3 host, set it as default value. If the user really want to run Kata on gicv2 host, he/she need to set default_maxvcpus in toml file to 8 instead of 0. In summary, If the user uses host gicv3 gicv4, everything is fine If the user uses host gicv2, set default_maxvcpus=8 Signed-off-by: Jia He Signed-off-by: Peng Tao --- .../cli/config/configuration-fc.toml.in | 1 + .../configuration-qemu-virtiofs.toml.in | 1 + .../cli/config/configuration-qemu.toml.in | 1 + src/runtime/virtcontainers/qemu_arm64.go | 5 +- src/runtime/virtcontainers/qemu_arm64_test.go | 48 +------------------ 5 files changed, 8 insertions(+), 48 deletions(-) diff --git a/src/runtime/cli/config/configuration-fc.toml.in b/src/runtime/cli/config/configuration-fc.toml.in index 054950d2a9..4e5158f5b2 100644 --- a/src/runtime/cli/config/configuration-fc.toml.in +++ b/src/runtime/cli/config/configuration-fc.toml.in @@ -55,6 +55,7 @@ default_vcpus = 1 # `default_maxvcpus = 8` the memory footprint will be small, but 8 will be the maximum number of # vCPUs supported by the SB/VM. In general, we recommend that you do not edit this variable, # unless you know what are you doing. +# NOTICE: on arm platform with gicv2 interrupt controller, set it to 8. default_maxvcpus = @DEFMAXVCPUS@ # Bridges can be used to hot plug devices. diff --git a/src/runtime/cli/config/configuration-qemu-virtiofs.toml.in b/src/runtime/cli/config/configuration-qemu-virtiofs.toml.in index 129dc9963d..8a220feaae 100644 --- a/src/runtime/cli/config/configuration-qemu-virtiofs.toml.in +++ b/src/runtime/cli/config/configuration-qemu-virtiofs.toml.in @@ -58,6 +58,7 @@ default_vcpus = 1 # `default_maxvcpus = 8` the memory footprint will be small, but 8 will be the maximum number of # vCPUs supported by the SB/VM. In general, we recommend that you do not edit this variable, # unless you know what are you doing. +# NOTICE: on arm platform with gicv2 interrupt controller, set it to 8. default_maxvcpus = @DEFMAXVCPUS@ # Bridges can be used to hot plug devices. diff --git a/src/runtime/cli/config/configuration-qemu.toml.in b/src/runtime/cli/config/configuration-qemu.toml.in index bca733e2ad..7ac6d90988 100644 --- a/src/runtime/cli/config/configuration-qemu.toml.in +++ b/src/runtime/cli/config/configuration-qemu.toml.in @@ -59,6 +59,7 @@ default_vcpus = 1 # `default_maxvcpus = 8` the memory footprint will be small, but 8 will be the maximum number of # vCPUs supported by the SB/VM. In general, we recommend that you do not edit this variable, # unless you know what are you doing. +# NOTICE: on arm platform with gicv2 interrupt controller, set it to 8. default_maxvcpus = @DEFMAXVCPUS@ # Bridges can be used to hot plug devices. diff --git a/src/runtime/virtcontainers/qemu_arm64.go b/src/runtime/virtcontainers/qemu_arm64.go index ed38457711..5b1ca82ce2 100644 --- a/src/runtime/virtcontainers/qemu_arm64.go +++ b/src/runtime/virtcontainers/qemu_arm64.go @@ -8,7 +8,6 @@ package virtcontainers import ( "context" "fmt" - "runtime" "time" govmmQemu "github.com/intel/govmm/qemu" @@ -27,6 +26,8 @@ const qmpMigrationWaitTimeout = 10 * time.Second const defaultQemuMachineOptions = "usb=off,accel=kvm,gic-version=host" +var defaultGICVersion = uint32(3) + var kernelParams = []Param{ {"console", "hvc0"}, {"console", "hvc1"}, @@ -51,7 +52,7 @@ var gicList = map[uint32]uint32{ // MaxQemuVCPUs returns the maximum number of vCPUs supported func MaxQemuVCPUs() uint32 { - return uint32(runtime.NumCPU()) + return gicList[defaultGICVersion] } func newQemuArch(config HypervisorConfig) (qemuArch, error) { diff --git a/src/runtime/virtcontainers/qemu_arm64_test.go b/src/runtime/virtcontainers/qemu_arm64_test.go index eeb6c2ed67..95bffacc26 100644 --- a/src/runtime/virtcontainers/qemu_arm64_test.go +++ b/src/runtime/virtcontainers/qemu_arm64_test.go @@ -9,8 +9,6 @@ import ( "fmt" "io/ioutil" "os" - "path/filepath" - "runtime" "testing" govmmQemu "github.com/intel/govmm/qemu" @@ -59,50 +57,8 @@ func TestQemuArm64MemoryTopology(t *testing.T) { func TestMaxQemuVCPUs(t *testing.T) { assert := assert.New(t) - type testData struct { - contents string - expectedResult uint32 - } - - data := []testData{ - {"", uint32(runtime.NumCPU())}, - {" 1: 0 0 GICv2 25 Level vgic \n", uint32(8)}, - {" 1: 0 0 GICv3 25 Level vgic \n", uint32(123)}, - {" 1: 0 0 GICv4 25 Level vgic \n", uint32(123)}, - } - - tmpdir, err := ioutil.TempDir("", "") - if err != nil { - panic(err) - } - defer os.RemoveAll(tmpdir) - - savedGicProfile := gicProfile - - testGicProfile := filepath.Join(tmpdir, "interrupts") - - // override - gicProfile = testGicProfile - - defer func() { - gicProfile = savedGicProfile - }() - - savedHostGICVersion := hostGICVersion - - defer func() { - hostGICVersion = savedHostGICVersion - }() - - for _, d := range data { - err := ioutil.WriteFile(gicProfile, []byte(d.contents), os.FileMode(0640)) - assert.NoError(err) - - hostGICVersion = getHostGICVersion() - vCPUs := MaxQemuVCPUs() - - assert.Equal(d.expectedResult, vCPUs) - } + vCPUs := MaxQemuVCPUs() + assert.Equal(uint32(123), vCPUs) } func TestQemuArm64AppendBridges(t *testing.T) {