Skip to content

Commit 4760df7

Browse files
committed
Clean up codes for QEMU < 7.0
- QEMU 7.0 is documented as the minimum requirement since 9eb1396 (Dec 2022) - Also clean up the hint for QEMU 8.2.0, as QEMU 8.2.0 users should have already updated QEMU to 8.2.1+ Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
1 parent d7ece61 commit 4760df7

File tree

1 file changed

+11
-80
lines changed

1 file changed

+11
-80
lines changed

pkg/qemu/qemu.go

Lines changed: 11 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Config struct {
4949

5050
// MinimumQemuVersion is the minimum supported QEMU version.
5151
const (
52-
MinimumQemuVersion = "4.0.0"
52+
MinimumQemuVersion = "7.0.0"
5353
)
5454

5555
// EnsureDisk also ensures the kernel and the initrd.
@@ -313,9 +313,6 @@ type features struct {
313313
// e.g. "Available CPUs:\n...\nx86 base...\nx86 host...\n...\n"
314314
// Not machine-readable, but checking strings.Contains() should be fine.
315315
CPUHelp []byte
316-
317-
// VersionGEQ7 is true when the QEMU version seems v7.0.0 or later
318-
VersionGEQ7 bool
319316
}
320317

321318
func inspectFeatures(exe, machine string) (*features, error) {
@@ -359,7 +356,6 @@ func inspectFeatures(exe, machine string) (*features, error) {
359356
f.MachineHelp = stderr.Bytes()
360357
}
361358
}
362-
f.VersionGEQ7 = strings.Contains(string(f.MachineHelp), "-7.0")
363359

364360
// Avoid error: "No machine specified, and there is no default"
365361
cmd = exec.Command(exe, "-cpu", "help", "-machine", machine)
@@ -377,56 +373,15 @@ func inspectFeatures(exe, machine string) (*features, error) {
377373
return &f, nil
378374
}
379375

380-
// showDarwinARM64HVFQEMU620Warning shows a warning on M1 macOS when QEMU is older than 6.2.0_1.
381-
//
382-
// See:
383-
// - https://gitlab.com/qemu-project/qemu/-/issues/899
384-
// - https://github.com/Homebrew/homebrew-core/pull/96743
385-
// - https://github.com/lima-vm/lima/issues/712
386-
func showDarwinARM64HVFQEMU620Warning(exe, accel string, features *features) {
387-
if runtime.GOOS != "darwin" {
388-
return
389-
}
390-
if runtime.GOARCH != "arm64" {
391-
return
392-
}
393-
if accel != "hvf" {
394-
return
395-
}
396-
if features.VersionGEQ7 {
397-
return
398-
}
399-
if exeFull, err := exec.LookPath(exe); err == nil {
400-
if exeResolved, err2 := filepath.EvalSymlinks(exeFull); err2 == nil {
401-
if strings.Contains(exeResolved, "Cellar/qemu/6.2.0_") {
402-
// Homebrew's QEMU 6.2.0_1 or later
403-
return
404-
}
405-
}
406-
}
407-
w := "This version of QEMU might not be able to boot recent Linux guests on M1 macOS hosts."
408-
if _, err := exec.LookPath("brew"); err == nil {
409-
w += "Run `brew upgrade` and make sure your QEMU version is 6.2.0_1 or later."
410-
} else {
411-
w += `Reinstall QEMU with the following commits (included in QEMU 7.0.0):
412-
- https://github.com/qemu/qemu/commit/ad99f64f "hvf: arm: Use macros for sysreg shift/masking"
413-
- https://github.com/qemu/qemu/commit/7f6c295c "hvf: arm: Handle unknown ID registers as RES0"
414-
`
415-
w += "See https://github.com/Homebrew/homebrew-core/pull/96743 for the further information."
416-
}
417-
logrus.Warn(w)
418-
}
419-
420376
// adjustMemBytesDarwinARM64HVF adjusts the memory to be <= 3 GiB, only when the following conditions are met:
421377
//
422378
// - Host OS < macOS 12.4
423379
// - Host Arch == arm64
424380
// - Accel == hvf
425-
// - QEMU >= 7.0
426381
//
427382
// This adjustment is required for avoiding host kernel panic. The issue was fixed in macOS 12.4 Beta 1.
428383
// See https://github.com/lima-vm/lima/issues/795 https://gitlab.com/qemu-project/qemu/-/issues/903#note_911000975
429-
func adjustMemBytesDarwinARM64HVF(memBytes int64, accel string, features *features) int64 {
384+
func adjustMemBytesDarwinARM64HVF(memBytes int64, accel string) int64 {
430385
const safeSize = 3 * 1024 * 1024 * 1024 // 3 GiB
431386
if memBytes <= safeSize {
432387
return memBytes
@@ -440,9 +395,6 @@ func adjustMemBytesDarwinARM64HVF(memBytes int64, accel string, features *featur
440395
if accel != "hvf" {
441396
return memBytes
442397
}
443-
if !features.VersionGEQ7 {
444-
return memBytes
445-
}
446398
macOSProductVersion, err := osutil.ProductVersion()
447399
if err != nil {
448400
logrus.Warn(err)
@@ -451,8 +403,8 @@ func adjustMemBytesDarwinARM64HVF(memBytes int64, accel string, features *featur
451403
if !macOSProductVersion.LessThan(*semver.New("12.4.0")) {
452404
return memBytes
453405
}
454-
logrus.Warnf("Reducing the guest memory from %s to %s, to avoid host kernel panic on macOS <= 12.3 with QEMU >= 7.0; "+
455-
"Please update macOS to 12.4 or later, or downgrade QEMU to 6.2; "+
406+
logrus.Warnf("Reducing the guest memory from %s to %s, to avoid host kernel panic on macOS <= 12.3; "+
407+
"Please update macOS to 12.4 or later; "+
456408
"See https://github.com/lima-vm/lima/issues/795 for the further background.",
457409
units.BytesSize(float64(memBytes)), units.BytesSize(float64(safeSize)))
458410
memBytes = safeSize
@@ -503,25 +455,20 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
503455
if y.VMOpts.QEMU.MinimumVersion != nil && version.LessThan(*semver.New(*y.VMOpts.QEMU.MinimumVersion)) {
504456
logrus.Fatalf("QEMU %v is too old, template requires %q or later", version, *y.VMOpts.QEMU.MinimumVersion)
505457
}
506-
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" && version.Equal(*semver.New("8.2.0")) {
507-
logrus.Fatal("QEMU 8.2.0 is no longer supported on ARM Mac due to <https://gitlab.com/qemu-project/qemu/-/issues/1990>. " +
508-
"Please upgrade QEMU to v8.2.1 (or downgrade to v8.1.x).")
509-
}
510458
}
511459

512460
// Architecture
513461
accel := Accel(*y.Arch)
514462
if !strings.Contains(string(features.AccelHelp), accel) {
515463
return "", nil, fmt.Errorf("accelerator %q is not supported by %s", accel, exe)
516464
}
517-
showDarwinARM64HVFQEMU620Warning(exe, accel, features)
518465

519466
// Memory
520467
memBytes, err := units.RAMInBytes(*y.Memory)
521468
if err != nil {
522469
return "", nil, err
523470
}
524-
memBytes = adjustMemBytesDarwinARM64HVF(memBytes, accel, features)
471+
memBytes = adjustMemBytesDarwinARM64HVF(memBytes, accel)
525472
args = appendArgsIfNoConflict(args, "-m", strconv.Itoa(int(memBytes>>20)))
526473

527474
if *y.MountType == limayaml.VIRTIOFS {
@@ -569,14 +516,6 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
569516
}
570517
case limayaml.AARCH64:
571518
machine := "virt,accel=" + accel
572-
// QEMU >= 7.0 requires highmem=off NOT to be set, otherwise fails with "Addressing limited to 32 bits, but memory exceeds it by 1073741824 bytes"
573-
// QEMU < 7.0 requires highmem=off to be set, otherwise fails with "VCPU supports less PA bits (36) than requested by the memory map (40)"
574-
// https://github.com/lima-vm/lima/issues/680
575-
// https://github.com/lima-vm/lima/pull/24
576-
// But when the memory size is <= 3 GiB, we can always set highmem=off.
577-
if !features.VersionGEQ7 || memBytes <= 3*1024*1024*1024 {
578-
machine += ",highmem=off"
579-
}
580519
args = appendArgsIfNoConflict(args, "-machine", machine)
581520
case limayaml.RISCV64:
582521
// https://github.com/tianocore/edk2/blob/edk2-stable202408/OvmfPkg/RiscVVirt/README.md#test
@@ -876,23 +815,15 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
876815
}
877816

878817
switch *y.Arch {
818+
// FIXME: use virtio-gpu on all the architectures
879819
case limayaml.X8664, limayaml.RISCV64:
880820
args = append(args, "-device", "virtio-vga")
881-
args = append(args, "-device", "virtio-keyboard-pci")
882-
args = append(args, "-device", "virtio-"+input+"-pci")
883-
args = append(args, "-device", "qemu-xhci,id=usb-bus")
884-
case limayaml.AARCH64, limayaml.ARMV7L, limayaml.PPC64LE, limayaml.S390X:
885-
if features.VersionGEQ7 {
886-
args = append(args, "-device", "virtio-gpu")
887-
args = append(args, "-device", "virtio-keyboard-pci")
888-
args = append(args, "-device", "virtio-"+input+"-pci")
889-
} else { // kernel panic with virtio and old versions of QEMU
890-
args = append(args, "-vga", "none", "-device", "ramfb")
891-
args = append(args, "-device", "usb-kbd,bus=usb-bus")
892-
args = append(args, "-device", "usb-"+input+",bus=usb-bus")
893-
}
894-
args = append(args, "-device", "qemu-xhci,id=usb-bus")
821+
default:
822+
args = append(args, "-device", "virtio-gpu")
895823
}
824+
args = append(args, "-device", "virtio-keyboard-pci")
825+
args = append(args, "-device", "virtio-"+input+"-pci")
826+
args = append(args, "-device", "qemu-xhci,id=usb-bus")
896827

897828
// Parallel
898829
args = append(args, "-parallel", "none")

0 commit comments

Comments
 (0)