Skip to content

Commit 1261545

Browse files
committed
qemu: avoid Property 'host-arm-cpu.sme' not found
Close issue 3032 SME is available since Apple M4 running macOS 15.2. However, QEMU is not ready to handle SME yet. - https://gitlab.com/qemu-project/qemu/-/issues/2665 - https://gitlab.com/qemu-project/qemu/-/issues/2721 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 5fb9353 commit 1261545

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

.codespellrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
skip = .git,go.mod,go.sum,*.pb.desc,*/node_modules/*,*/public/js/*,*/public/scss/*
77

88
# Comma separated list of words to be ignored. Words must be lowercased.
9-
ignore-words-list = ans,distroname,testof,hda,ststr,archtypes
9+
ignore-words-list = ans,distroname,testof,hda,ststr,archtypes,sme
1010

1111
# Check file names as well.
1212
check-filenames = true

pkg/limayaml/defaults.go

+39-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"slices"
1515
"strconv"
1616
"strings"
17+
"sync"
1718
"text/template"
1819

1920
"github.com/coreos/go-semver/semver"
@@ -1173,9 +1174,44 @@ func IsAccelOS() bool {
11731174
return false
11741175
}
11751176

1177+
var (
1178+
hasSMEDarwin bool
1179+
hasSMEDarwinOnce sync.Once
1180+
)
1181+
1182+
func init() {
1183+
hasSMEDarwinOnce.Do(func() {
1184+
hasSMEDarwin = hasSMEDarwinFn()
1185+
})
1186+
}
1187+
1188+
func hasSMEDarwinFn() bool {
1189+
if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
1190+
return false
1191+
}
1192+
// golang.org/x/sys/cpu does not support inspecting the availability of SME yet
1193+
s, err := osutil.Sysctl("hw.optional.arm.FEAT_SME")
1194+
if err != nil {
1195+
logrus.WithError(err).Debug("failed to check hw.optional.arm.FEAT_SME")
1196+
}
1197+
return s == "1"
1198+
}
1199+
11761200
func HasHostCPU() bool {
11771201
switch runtime.GOOS {
1178-
case "darwin", "linux":
1202+
case "darwin":
1203+
if hasSMEDarwin {
1204+
// SME is available since Apple M4 running macOS 15.2.
1205+
//
1206+
// However, QEMU is not ready to handle SME yet.
1207+
//
1208+
// https://github.com/lima-vm/lima/issues/3032
1209+
// https://gitlab.com/qemu-project/qemu/-/issues/2665
1210+
// https://gitlab.com/qemu-project/qemu/-/issues/2721
1211+
return false
1212+
}
1213+
return true
1214+
case "linux":
11791215
return true
11801216
case "netbsd", "windows":
11811217
return false
@@ -1185,8 +1221,8 @@ func HasHostCPU() bool {
11851221
}
11861222

11871223
func HasMaxCPU() bool {
1188-
// WHPX: Unexpected VP exit code 4
1189-
return runtime.GOOS != "windows"
1224+
// windows: WHPX: Unexpected VP exit code 4
1225+
return HasHostCPU()
11901226
}
11911227

11921228
func IsNativeArch(arch Arch) bool {

pkg/osutil/osutil_unix.go

+16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
package osutil
44

55
import (
6+
"bytes"
7+
"fmt"
68
"os"
9+
"os/exec"
10+
"strings"
711
"syscall"
812

913
"golang.org/x/sys/unix"
@@ -16,3 +20,15 @@ func Dup2(oldfd, newfd int) (err error) {
1620
func SignalName(sig os.Signal) string {
1721
return unix.SignalName(sig.(syscall.Signal))
1822
}
23+
24+
func Sysctl(name string) (string, error) {
25+
var stderrBuf bytes.Buffer
26+
cmd := exec.Command("sysctl", "-n", name)
27+
cmd.Stderr = &stderrBuf
28+
stdout, err := cmd.Output()
29+
if err != nil {
30+
return "", fmt.Errorf("failed to run %v: %w (stdout=%q, stderr=%q)", cmd.Args, err,
31+
string(stdout), stderrBuf.String())
32+
}
33+
return strings.TrimSuffix(string(stdout), "\n"), nil
34+
}

pkg/osutil/osutil_windows.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package osutil
22

33
import (
4+
"errors"
45
"fmt"
56
"io/fs"
67
"os"
@@ -48,3 +49,7 @@ func SignalName(sig os.Signal) string {
4849
return fmt.Sprintf("Signal(%d)", sig)
4950
}
5051
}
52+
53+
func Sysctl(name string) (string, error) {
54+
return "", errors.New("sysctl: unimplemented on Windows")
55+
}

0 commit comments

Comments
 (0)