Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions pkg/driver/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"slices"
"strconv"
"strings"
"sync"
"time"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -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"
}
}
Expand Down Expand Up @@ -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
}
51 changes: 0 additions & 51 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"slices"
"strconv"
"strings"
"sync"
"text/template"

"github.com/docker/go-units"
Expand Down Expand Up @@ -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"
Expand Down
Loading