Skip to content

Commit 0cb9389

Browse files
authored
Merge pull request #4205 from AkihiroSuda/limayaml-qemu
limayaml: remove implementation details of QEMU
2 parents 39c5246 + 367fc07 commit 0cb9389

File tree

2 files changed

+43
-53
lines changed

2 files changed

+43
-53
lines changed

pkg/driver/qemu/qemu.go

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"slices"
2020
"strconv"
2121
"strings"
22+
"sync"
2223
"time"
2324

2425
"github.com/coreos/go-semver/semver"
@@ -427,8 +428,8 @@ func defaultCPUType() limatype.CPUType {
427428
limatype.S390X: "max",
428429
}
429430
for arch := range cpuType {
430-
if limayaml.IsNativeArch(arch) && limayaml.IsAccelOS() {
431-
if limayaml.HasHostCPU() {
431+
if limayaml.IsNativeArch(arch) && Accel(arch) != "tcg" {
432+
if hasHostCPU() {
432433
cpuType[arch] = "host"
433434
}
434435
}
@@ -1272,3 +1273,43 @@ func getFirmwareVars(qemuExe string, arch limatype.Arch) (string, error) {
12721273

12731274
return "", fmt.Errorf("could not find firmware vars for %q", arch)
12741275
}
1276+
1277+
var hasSMEDarwin = sync.OnceValue(func() bool {
1278+
if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
1279+
return false
1280+
}
1281+
// golang.org/x/sys/cpu does not support inspecting the availability of SME yet
1282+
s, err := osutil.Sysctl(context.Background(), "hw.optional.arm.FEAT_SME")
1283+
if err != nil {
1284+
logrus.WithError(err).Debug("failed to check hw.optional.arm.FEAT_SME")
1285+
}
1286+
return s == "1"
1287+
})
1288+
1289+
func hasHostCPU() bool {
1290+
switch runtime.GOOS {
1291+
case "darwin":
1292+
if hasSMEDarwin() {
1293+
// [2025-02-05]
1294+
// SME is available since Apple M4 running macOS 15.2, but it was broken on macOS 15.2.
1295+
// It has been fixed in 15.3.
1296+
//
1297+
// https://github.com/lima-vm/lima/issues/3032
1298+
// https://gitlab.com/qemu-project/qemu/-/issues/2665
1299+
// https://gitlab.com/qemu-project/qemu/-/issues/2721
1300+
1301+
// [2025-02-12]
1302+
// SME got broken again after upgrading QEMU from 9.2.0 to 9.2.1 (Homebrew bottle).
1303+
// Possibly this regression happened in some build process rather than in QEMU itself?
1304+
// https://github.com/lima-vm/lima/issues/3226
1305+
return false
1306+
}
1307+
return true
1308+
case "linux":
1309+
return true
1310+
case "netbsd", "windows":
1311+
return false
1312+
}
1313+
// Not reached
1314+
return false
1315+
}

pkg/limayaml/defaults.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"slices"
2020
"strconv"
2121
"strings"
22-
"sync"
2322
"text/template"
2423

2524
"github.com/docker/go-units"
@@ -974,56 +973,6 @@ func ResolveArch(s *string) limatype.Arch {
974973
return *s
975974
}
976975

977-
func IsAccelOS() bool {
978-
switch runtime.GOOS {
979-
case "darwin", "linux", "netbsd", "windows", "dragonfly":
980-
// Accelerator
981-
return true
982-
}
983-
// Using TCG
984-
return false
985-
}
986-
987-
var hasSMEDarwin = sync.OnceValue(func() bool {
988-
if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
989-
return false
990-
}
991-
// golang.org/x/sys/cpu does not support inspecting the availability of SME yet
992-
s, err := osutil.Sysctl(context.Background(), "hw.optional.arm.FEAT_SME")
993-
if err != nil {
994-
logrus.WithError(err).Debug("failed to check hw.optional.arm.FEAT_SME")
995-
}
996-
return s == "1"
997-
})
998-
999-
func HasHostCPU() bool {
1000-
switch runtime.GOOS {
1001-
case "darwin":
1002-
if hasSMEDarwin() {
1003-
// [2025-02-05]
1004-
// SME is available since Apple M4 running macOS 15.2, but it was broken on macOS 15.2.
1005-
// It has been fixed in 15.3.
1006-
//
1007-
// https://github.com/lima-vm/lima/issues/3032
1008-
// https://gitlab.com/qemu-project/qemu/-/issues/2665
1009-
// https://gitlab.com/qemu-project/qemu/-/issues/2721
1010-
1011-
// [2025-02-12]
1012-
// SME got broken again after upgrading QEMU from 9.2.0 to 9.2.1 (Homebrew bottle).
1013-
// Possibly this regression happened in some build process rather than in QEMU itself?
1014-
// https://github.com/lima-vm/lima/issues/3226
1015-
return false
1016-
}
1017-
return true
1018-
case "linux":
1019-
return true
1020-
case "netbsd", "windows":
1021-
return false
1022-
}
1023-
// Not reached
1024-
return false
1025-
}
1026-
1027976
func IsNativeArch(arch limatype.Arch) bool {
1028977
nativeX8664 := arch == limatype.X8664 && runtime.GOARCH == "amd64"
1029978
nativeAARCH64 := arch == limatype.AARCH64 && runtime.GOARCH == "arm64"

0 commit comments

Comments
 (0)