Skip to content

Commit 8b622fd

Browse files
committed
qemu: use -cpu host by default
`-cpu host` seemed to cause kernel panic with QEMU 5.2 on Intel Mac, but seems to work well with QEMU 6.1 now. The behavior can be rolled back by specifying an env var like `QEMU_SYSTEM_X86_64=qemu-system-x86_64 -cpu Haswell-v4` or `QEMU_SYSTEM_AARCH64=qemu-system-aarch64 -cpu cortex-a72` . Signed-off-by: Akihiro Suda <[email protected]>
1 parent df25c45 commit 8b622fd

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ See [`./pkg/limayaml/default.yaml`](./pkg/limayaml/default.yaml).
149149

150150
The current default spec:
151151
- OS: Ubuntu 21.04 (Hirsute Hippo)
152-
- CPU (x86\_64): Haswell v4, 4 cores
153-
- CPU (aarch64): Cortex A72, 4 cores
152+
- CPU: 4 cores
154153
- Memory: 4 GiB
155154
- Disk: 100 GiB
156155
- Mounts: `~` (read-only), `/tmp/lima` (writable)

pkg/qemu/qemu.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,18 @@ func Cmdline(cfg Config) (string, []string, error) {
198198
}
199199
switch y.Arch {
200200
case limayaml.X8664:
201-
// NOTE: "-cpu host" seems to cause kernel panic
202-
// (MacBookPro 2020, Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz, macOS 11.3, Ubuntu 21.04)
203-
args = appendArgsIfNoConflict(args, "-cpu", "Haswell-v4")
201+
cpu := "Haswell-v4"
202+
if isNativeArch(y.Arch) {
203+
cpu = "host"
204+
}
205+
args = appendArgsIfNoConflict(args, "-cpu", cpu)
204206
args = appendArgsIfNoConflict(args, "-machine", "q35,accel="+accel)
205207
case limayaml.AARCH64:
206-
args = appendArgsIfNoConflict(args, "-cpu", "cortex-a72")
208+
cpu := "cortex-a72"
209+
if isNativeArch(y.Arch) {
210+
cpu = "host"
211+
}
212+
args = appendArgsIfNoConflict(args, "-cpu", cpu)
207213
args = appendArgsIfNoConflict(args, "-machine", "virt,accel="+accel+",highmem=off")
208214
}
209215

@@ -355,11 +361,14 @@ func getExe(arch limayaml.Arch) (string, []string, error) {
355361
return exe, args, nil
356362
}
357363

358-
func getAccel(arch limayaml.Arch) string {
364+
func isNativeArch(arch limayaml.Arch) bool {
359365
nativeX8664 := arch == limayaml.X8664 && runtime.GOARCH == "amd64"
360366
nativeAARCH64 := arch == limayaml.AARCH64 && runtime.GOARCH == "arm64"
361-
native := nativeX8664 || nativeAARCH64
362-
if native {
367+
return nativeX8664 || nativeAARCH64
368+
}
369+
370+
func getAccel(arch limayaml.Arch) string {
371+
if isNativeArch(arch) {
363372
switch runtime.GOOS {
364373
case "darwin":
365374
return "hvf"

0 commit comments

Comments
 (0)