Skip to content

Commit bf89c6a

Browse files
authored
Merge pull request #19228 from spowelljr/amd64QemuOnArm64
Support running x86 QEMU on arm64
2 parents 4c7fcd0 + 250786e commit bf89c6a

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

pkg/drivers/qemu/qemu.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242

4343
"k8s.io/klog/v2"
4444
pkgdrivers "k8s.io/minikube/pkg/drivers"
45+
"k8s.io/minikube/pkg/minikube/detect"
4546
"k8s.io/minikube/pkg/minikube/exit"
4647
"k8s.io/minikube/pkg/minikube/firewall"
4748
"k8s.io/minikube/pkg/minikube/out"
@@ -412,14 +413,11 @@ func (d *Driver) Start() error {
412413
}
413414

414415
// hardware acceleration is important, it increases performance by 10x
415-
if runtime.GOOS == "darwin" {
416-
// On macOS, enable the Hypervisor framework accelerator.
417-
startCmd = append(startCmd,
418-
"-accel", "hvf")
419-
} else if _, err := os.Stat("/dev/kvm"); err == nil && runtime.GOOS == "linux" {
420-
// On Linux, enable the Kernel Virtual Machine accelerator.
416+
accel := hardwareAcceleration()
417+
if accel != "" {
418+
klog.Infof("Using %s for hardware acceleration", accel)
421419
startCmd = append(startCmd,
422-
"-accel", "kvm")
420+
"-accel", accel)
423421
}
424422

425423
startCmd = append(startCmd,
@@ -546,6 +544,21 @@ func (d *Driver) Start() error {
546544
return WaitForTCPWithDelay(fmt.Sprintf("%s:%d", d.IPAddress, d.SSHPort), time.Second)
547545
}
548546

547+
func hardwareAcceleration() string {
548+
if detect.IsAmd64M1Emulation() {
549+
return "tcg"
550+
}
551+
if runtime.GOOS == "darwin" {
552+
// On macOS, enable the Hypervisor framework accelerator.
553+
return "hvf"
554+
}
555+
if _, err := os.Stat("/dev/kvm"); err == nil && runtime.GOOS == "linux" {
556+
// On Linux, enable the Kernel Virtual Machine accelerator.
557+
return "kvm"
558+
}
559+
return ""
560+
}
561+
549562
func isBootpdError(err error) bool {
550563
if runtime.GOOS != "darwin" {
551564
return false

pkg/minikube/registry/drvs/qemu2/qemu2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"k8s.io/minikube/pkg/drivers/qemu"
3232

3333
"k8s.io/minikube/pkg/minikube/config"
34+
"k8s.io/minikube/pkg/minikube/detect"
3435
"k8s.io/minikube/pkg/minikube/download"
3536
"k8s.io/minikube/pkg/minikube/driver"
3637
"k8s.io/minikube/pkg/minikube/localpath"
@@ -76,6 +77,9 @@ func qemuFirmwarePath(customPath string) (string, error) {
7677
if runtime.GOOS == "windows" {
7778
return "C:\\Program Files\\qemu\\share\\edk2-x86_64-code.fd", nil
7879
}
80+
if detect.IsAmd64M1Emulation() {
81+
return "/opt/homebrew/opt/qemu/share/qemu/edk2-x86_64-code.fd", nil
82+
}
7983
arch := runtime.GOARCH
8084
// For macOS, find the correct brew installation path for qemu firmware
8185
if runtime.GOOS == "darwin" {

0 commit comments

Comments
 (0)