From 7c3f9690d5b1f64e6f408ef755460d20c3d45a1c Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Fri, 4 Aug 2017 13:27:36 +0100 Subject: [PATCH] cmd/qemu: Better handling of arch - When executing on aarch64, use it as the default arch - When selecting aarch64 on a non aarch64 system set the CPU flag to a default value (not 'host'). Signed-off-by: Rolf Neugebauer --- src/cmd/linuxkit/run_qemu.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index 26a08155d..0c4625570 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strconv" "strings" @@ -54,6 +55,19 @@ const ( qemuNetworkingDefault = qemuNetworkingUser ) +var ( + defaultArch string +) + +func init() { + switch runtime.GOARCH { + case "arm64": + defaultArch = "aarch64" + case "amd64": + defaultArch = "x86_64" + } +} + func haveKVM() bool { _, err := os.Stat("/dev/kvm") return !os.IsNotExist(err) @@ -123,7 +137,7 @@ func runQemu(args []string) { // VM configuration enableKVM := flags.Bool("kvm", haveKVM(), "Enable KVM acceleration") - arch := flags.String("arch", "x86_64", "Type of architecture to use, e.g. x86_64, aarch64") + arch := flags.String("arch", defaultArch, "Type of architecture to use, e.g. x86_64, aarch64") cpus := flags.String("cpus", "1", "Number of CPUs") mem := flags.String("mem", "1024", "Amount of memory in MB") @@ -459,7 +473,11 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) { // Need to specify the vcpu type when running qemu on arm64 platform, for security reason, // the vcpu should be "host" instead of other names such as "cortex-a53"... if config.Arch == "aarch64" { - qemuArgs = append(qemuArgs, "-cpu", "host") + if runtime.GOARCH == "arm64" { + qemuArgs = append(qemuArgs, "-cpu", "host") + } else { + qemuArgs = append(qemuArgs, "-cpu", "cortex-a57") + } } if config.KVM {