@@ -16,6 +16,7 @@ import (
16
16
"path/filepath"
17
17
"regexp"
18
18
"runtime"
19
+ "slices"
19
20
"strconv"
20
21
"strings"
21
22
"time"
@@ -438,6 +439,67 @@ func audioDevice() string {
438
439
return "oss"
439
440
}
440
441
442
+ func defaultCPUType () limayaml.CPUType {
443
+ // x86_64 + TCG + max was previously unstable until 2021.
444
+ // https://bugzilla.redhat.com/show_bug.cgi?id=1999700
445
+ // https://bugs.launchpad.net/qemu/+bug/1748296
446
+ defaultX8664 := "max"
447
+ if runtime .GOOS == "windows" && runtime .GOARCH == "amd64" {
448
+ // https://github.com/lima-vm/lima/pull/3487#issuecomment-2846253560
449
+ // > #931 intentionally prevented the code from setting it to max when running on Windows,
450
+ // > and kept it at qemu64.
451
+ //
452
+ // TODO: remove this if "max" works with the latest qemu
453
+ defaultX8664 = "qemu64"
454
+ }
455
+ cpuType := map [limayaml.Arch ]string {
456
+ limayaml .AARCH64 : "max" ,
457
+ limayaml .ARMV7L : "max" ,
458
+ limayaml .X8664 : defaultX8664 ,
459
+ limayaml .PPC64LE : "max" ,
460
+ limayaml .RISCV64 : "max" ,
461
+ limayaml .S390X : "max" ,
462
+ }
463
+ for arch := range cpuType {
464
+ if limayaml .IsNativeArch (arch ) && limayaml .IsAccelOS () {
465
+ if limayaml .HasHostCPU () {
466
+ cpuType [arch ] = "host"
467
+ }
468
+ }
469
+ if arch == limayaml .X8664 && runtime .GOOS == "darwin" {
470
+ // disable AVX-512, since it requires trapping instruction faults in guest
471
+ // Enterprise Linux requires either v2 (SSE4) or v3 (AVX2), but not yet v4.
472
+ cpuType [arch ] += ",-avx512vl"
473
+
474
+ // Disable pdpe1gb on Intel Mac
475
+ // https://github.com/lima-vm/lima/issues/1485
476
+ // https://stackoverflow.com/a/72863744/5167443
477
+ cpuType [arch ] += ",-pdpe1gb"
478
+ }
479
+ }
480
+ return cpuType
481
+ }
482
+
483
+ func resolveCPUType (y * limayaml.LimaYAML ) string {
484
+ cpuType := defaultCPUType ()
485
+ var overrideCPUType bool
486
+ for k , v := range y .VMOpts .QEMU .CPUType {
487
+ if ! slices .Contains (limayaml .ArchTypes , * y .Arch ) {
488
+ logrus .Warnf ("field `vmOpts.qemu.cpuType` uses unsupported arch %q" , k )
489
+ continue
490
+ }
491
+ if v != "" {
492
+ overrideCPUType = true
493
+ cpuType [k ] = v
494
+ }
495
+ }
496
+ if overrideCPUType {
497
+ y .VMOpts .QEMU .CPUType = cpuType
498
+ }
499
+
500
+ return cpuType [* y .Arch ]
501
+ }
502
+
441
503
func Cmdline (ctx context.Context , cfg Config ) (exe string , args []string , err error ) {
442
504
y := cfg .LimaYAML
443
505
exe , args , err = Exe (* y .Arch )
@@ -488,7 +550,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
488
550
}
489
551
490
552
// CPU
491
- cpu := y . CPUType [ * y . Arch ]
553
+ cpu := resolveCPUType ( y )
492
554
if runtime .GOOS == "darwin" && runtime .GOARCH == "amd64" {
493
555
switch {
494
556
case strings .HasPrefix (cpu , "host" ), strings .HasPrefix (cpu , "max" ):
0 commit comments