From 367fc07bbb32fb38eae99c832734b1ec4b779c55 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 15 Oct 2025 16:57:18 +0900 Subject: [PATCH] limayaml: remove implementation details of QEMU Signed-off-by: Akihiro Suda --- pkg/driver/qemu/qemu.go | 45 +++++++++++++++++++++++++++++++++-- pkg/limayaml/defaults.go | 51 ---------------------------------------- 2 files changed, 43 insertions(+), 53 deletions(-) diff --git a/pkg/driver/qemu/qemu.go b/pkg/driver/qemu/qemu.go index 529b37471c8..30c15a4aaa8 100644 --- a/pkg/driver/qemu/qemu.go +++ b/pkg/driver/qemu/qemu.go @@ -19,6 +19,7 @@ import ( "slices" "strconv" "strings" + "sync" "time" "github.com/coreos/go-semver/semver" @@ -427,8 +428,8 @@ func defaultCPUType() limatype.CPUType { limatype.S390X: "max", } for arch := range cpuType { - if limayaml.IsNativeArch(arch) && limayaml.IsAccelOS() { - if limayaml.HasHostCPU() { + if limayaml.IsNativeArch(arch) && Accel(arch) != "tcg" { + if hasHostCPU() { cpuType[arch] = "host" } } @@ -1272,3 +1273,43 @@ func getFirmwareVars(qemuExe string, arch limatype.Arch) (string, error) { return "", fmt.Errorf("could not find firmware vars for %q", arch) } + +var hasSMEDarwin = sync.OnceValue(func() bool { + if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" { + return false + } + // golang.org/x/sys/cpu does not support inspecting the availability of SME yet + s, err := osutil.Sysctl(context.Background(), "hw.optional.arm.FEAT_SME") + if err != nil { + logrus.WithError(err).Debug("failed to check hw.optional.arm.FEAT_SME") + } + return s == "1" +}) + +func hasHostCPU() bool { + switch runtime.GOOS { + case "darwin": + if hasSMEDarwin() { + // [2025-02-05] + // SME is available since Apple M4 running macOS 15.2, but it was broken on macOS 15.2. + // It has been fixed in 15.3. + // + // https://github.com/lima-vm/lima/issues/3032 + // https://gitlab.com/qemu-project/qemu/-/issues/2665 + // https://gitlab.com/qemu-project/qemu/-/issues/2721 + + // [2025-02-12] + // SME got broken again after upgrading QEMU from 9.2.0 to 9.2.1 (Homebrew bottle). + // Possibly this regression happened in some build process rather than in QEMU itself? + // https://github.com/lima-vm/lima/issues/3226 + return false + } + return true + case "linux": + return true + case "netbsd", "windows": + return false + } + // Not reached + return false +} diff --git a/pkg/limayaml/defaults.go b/pkg/limayaml/defaults.go index 9e546d72e02..49be6d0fa8f 100644 --- a/pkg/limayaml/defaults.go +++ b/pkg/limayaml/defaults.go @@ -19,7 +19,6 @@ import ( "slices" "strconv" "strings" - "sync" "text/template" "github.com/docker/go-units" @@ -974,56 +973,6 @@ func ResolveArch(s *string) limatype.Arch { return *s } -func IsAccelOS() bool { - switch runtime.GOOS { - case "darwin", "linux", "netbsd", "windows", "dragonfly": - // Accelerator - return true - } - // Using TCG - return false -} - -var hasSMEDarwin = sync.OnceValue(func() bool { - if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" { - return false - } - // golang.org/x/sys/cpu does not support inspecting the availability of SME yet - s, err := osutil.Sysctl(context.Background(), "hw.optional.arm.FEAT_SME") - if err != nil { - logrus.WithError(err).Debug("failed to check hw.optional.arm.FEAT_SME") - } - return s == "1" -}) - -func HasHostCPU() bool { - switch runtime.GOOS { - case "darwin": - if hasSMEDarwin() { - // [2025-02-05] - // SME is available since Apple M4 running macOS 15.2, but it was broken on macOS 15.2. - // It has been fixed in 15.3. - // - // https://github.com/lima-vm/lima/issues/3032 - // https://gitlab.com/qemu-project/qemu/-/issues/2665 - // https://gitlab.com/qemu-project/qemu/-/issues/2721 - - // [2025-02-12] - // SME got broken again after upgrading QEMU from 9.2.0 to 9.2.1 (Homebrew bottle). - // Possibly this regression happened in some build process rather than in QEMU itself? - // https://github.com/lima-vm/lima/issues/3226 - return false - } - return true - case "linux": - return true - case "netbsd", "windows": - return false - } - // Not reached - return false -} - func IsNativeArch(arch limatype.Arch) bool { nativeX8664 := arch == limatype.X8664 && runtime.GOARCH == "amd64" nativeAARCH64 := arch == limatype.AARCH64 && runtime.GOARCH == "arm64"