Skip to content

Commit df13f30

Browse files
authored
Merge pull request #3487 from AkihiroSuda/fix-3063
qemu: tcg: use `max` by default
2 parents 9182f7d + 822d237 commit df13f30

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

pkg/limayaml/defaults.go

+24-23
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,40 @@ var (
6161
)
6262

6363
func defaultCPUType() CPUType {
64+
// x86_64 + TCG + max was previously unstable until 2021.
65+
// https://bugzilla.redhat.com/show_bug.cgi?id=1999700
66+
// https://bugs.launchpad.net/qemu/+bug/1748296
67+
defaultX8664 := "max"
68+
if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
69+
// https://github.com/lima-vm/lima/pull/3487#issuecomment-2846253560
70+
// > #931 intentionally prevented the code from setting it to max when running on Windows,
71+
// > and kept it at qemu64.
72+
//
73+
// TODO: remove this if "max" works with the latest qemu
74+
defaultX8664 = "qemu64"
75+
}
6476
cpuType := map[Arch]string{
65-
AARCH64: "cortex-a76", // available since QEMU 7.1 (Aug 2022)
66-
ARMV7L: "cortex-a7",
67-
// Since https://github.com/lima-vm/lima/pull/494, we use qemu64 cpu for better emulation of x86_64.
68-
X8664: "qemu64",
77+
AARCH64: "max",
78+
ARMV7L: "max",
79+
X8664: defaultX8664,
6980
RISCV64: "max",
70-
S390X: "qemu", // FIXME: what is the right choice for s390x?
81+
S390X: "max",
7182
}
7283
for arch := range cpuType {
7384
if IsNativeArch(arch) && IsAccelOS() {
7485
if HasHostCPU() {
7586
cpuType[arch] = "host"
76-
} else if HasMaxCPU() {
77-
cpuType[arch] = "max"
7887
}
7988
}
8089
if arch == X8664 && runtime.GOOS == "darwin" {
81-
switch cpuType[arch] {
82-
case "host", "max":
83-
// disable AVX-512, since it requires trapping instruction faults in guest
84-
// Enterprise Linux requires either v2 (SSE4) or v3 (AVX2), but not yet v4.
85-
cpuType[arch] += ",-avx512vl"
86-
87-
// Disable pdpe1gb on Intel Mac
88-
// https://github.com/lima-vm/lima/issues/1485
89-
// https://stackoverflow.com/a/72863744/5167443
90-
cpuType[arch] += ",-pdpe1gb"
91-
}
90+
// disable AVX-512, since it requires trapping instruction faults in guest
91+
// Enterprise Linux requires either v2 (SSE4) or v3 (AVX2), but not yet v4.
92+
cpuType[arch] += ",-avx512vl"
93+
94+
// Disable pdpe1gb on Intel Mac
95+
// https://github.com/lima-vm/lima/issues/1485
96+
// https://stackoverflow.com/a/72863744/5167443
97+
cpuType[arch] += ",-pdpe1gb"
9298
}
9399
}
94100
return cpuType
@@ -1273,11 +1279,6 @@ func HasHostCPU() bool {
12731279
return false
12741280
}
12751281

1276-
func HasMaxCPU() bool {
1277-
// windows: WHPX: Unexpected VP exit code 4
1278-
return HasHostCPU()
1279-
}
1280-
12811282
func IsNativeArch(arch Arch) bool {
12821283
nativeX8664 := arch == X8664 && runtime.GOARCH == "amd64"
12831284
nativeAARCH64 := arch == AARCH64 && runtime.GOARCH == "arm64"

pkg/qemu/qemu.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
548548
// Machine
549549
switch *y.Arch {
550550
case limayaml.X8664:
551-
if strings.HasPrefix(cpu, "qemu64") && runtime.GOOS != "windows" {
551+
switch accel {
552+
case "tcg":
552553
// use q35 machine with vmware io port disabled.
553554
args = appendArgsIfNoConflict(args, "-machine", "q35,vmport=off")
554555
// use tcg accelerator with multi threading with 512MB translation block size
@@ -559,10 +560,10 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
559560
// This will disable CPU S3/S4 state.
560561
args = append(args, "-global", "ICH9-LPC.disable_s3=1")
561562
args = append(args, "-global", "ICH9-LPC.disable_s4=1")
562-
} else if runtime.GOOS == "windows" && accel == "whpx" {
563+
case "whpx":
563564
// whpx: injection failed, MSI (0, 0) delivery: 0, dest_mode: 0, trigger mode: 0, vector: 0
564565
args = appendArgsIfNoConflict(args, "-machine", "q35,accel="+accel+",kernel-irqchip=off")
565-
} else {
566+
default:
566567
args = appendArgsIfNoConflict(args, "-machine", "q35,accel="+accel)
567568
}
568569
case limayaml.AARCH64:

templates/_images/centos-stream-10.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,3 @@ firmware:
2828
# CentOS Stream 10 still requires legacyBIOS
2929
# https://issues.redhat.com/browse/CS-2672
3030
legacyBIOS: true
31-
32-
cpuType:
33-
# When emulating Intel on ARM hosts, Lima uses the "qemu64" CPU by default (https://github.com/lima-vm/lima/pull/494).
34-
# However, CentOS Stream 10 kernel reboots indefinitely due to lack of the support for x86_64-v3 instructions.
35-
# This issue is tracked in <https://github.com/lima-vm/lima/issues/3063>.
36-
x86_64: "Haswell-v4"

templates/default.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ os: null
334334
# Setting of instructions is supported like this: "qemu64,+ssse3".
335335
# 🟢 Builtin default: hard-coded arch map with type (see the output of `limactl info | jq .defaultTemplate.cpuType`)
336336
cpuType:
337-
# aarch64: "cortex-a76" # (or "host" when running on aarch64 host)
338-
# armv7l: "cortex-a7" # (or "host" when running on armv7l host)
339-
# riscv64: "rv64" # (or "host" when running on riscv64 host)
340-
# x86_64: "qemu64" # (or "host,-pdpe1gb" when running on x86_64 host)
337+
# aarch64: "max" # (or "host" when running on aarch64 host)
338+
# armv7l: "max" # (or "host" when running on armv7l host)
339+
# riscv64: "max" # (or "host" when running on riscv64 host)
340+
# x86_64: "max" # (or "host" when running on x86_64 host; additional options are appended on Intel Mac)
341341

342342
rosetta:
343343
# Enable Rosetta inside the VM; needs `vmType: vz`

0 commit comments

Comments
 (0)