@@ -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"
@@ -480,6 +481,67 @@ func audioDevice() string {
480
481
return "oss"
481
482
}
482
483
484
+ func defaultCPUType () limayaml.CPUType {
485
+ // x86_64 + TCG + max was previously unstable until 2021.
486
+ // https://bugzilla.redhat.com/show_bug.cgi?id=1999700
487
+ // https://bugs.launchpad.net/qemu/+bug/1748296
488
+ defaultX8664 := "max"
489
+ if runtime .GOOS == "windows" && runtime .GOARCH == "amd64" {
490
+ // https://github.com/lima-vm/lima/pull/3487#issuecomment-2846253560
491
+ // > #931 intentionally prevented the code from setting it to max when running on Windows,
492
+ // > and kept it at qemu64.
493
+ //
494
+ // TODO: remove this if "max" works with the latest qemu
495
+ defaultX8664 = "qemu64"
496
+ }
497
+ cpuType := map [limayaml.Arch ]string {
498
+ limayaml .AARCH64 : "max" ,
499
+ limayaml .ARMV7L : "max" ,
500
+ limayaml .X8664 : defaultX8664 ,
501
+ limayaml .PPC64LE : "max" ,
502
+ limayaml .RISCV64 : "max" ,
503
+ limayaml .S390X : "max" ,
504
+ }
505
+ for arch := range cpuType {
506
+ if limayaml .IsNativeArch (arch ) && limayaml .IsAccelOS () {
507
+ if limayaml .HasHostCPU () {
508
+ cpuType [arch ] = "host"
509
+ }
510
+ }
511
+ if arch == limayaml .X8664 && runtime .GOOS == "darwin" {
512
+ // disable AVX-512, since it requires trapping instruction faults in guest
513
+ // Enterprise Linux requires either v2 (SSE4) or v3 (AVX2), but not yet v4.
514
+ cpuType [arch ] += ",-avx512vl"
515
+
516
+ // Disable pdpe1gb on Intel Mac
517
+ // https://github.com/lima-vm/lima/issues/1485
518
+ // https://stackoverflow.com/a/72863744/5167443
519
+ cpuType [arch ] += ",-pdpe1gb"
520
+ }
521
+ }
522
+ return cpuType
523
+ }
524
+
525
+ func resolveCPUType (y * limayaml.LimaYAML ) string {
526
+ cpuType := defaultCPUType ()
527
+ var overrideCPUType bool
528
+ for k , v := range y .VMOpts .QEMU .CPUType {
529
+ if ! slices .Contains (limayaml .ArchTypes , * y .Arch ) {
530
+ logrus .Warnf ("field `vmOpts.qemu.cpuType` uses unsupported arch %q" , k )
531
+ continue
532
+ }
533
+ if v != "" {
534
+ overrideCPUType = true
535
+ cpuType [k ] = v
536
+ }
537
+ }
538
+ if overrideCPUType {
539
+ y .VMOpts .QEMU .CPUType = cpuType
540
+ }
541
+
542
+ return cpuType [* y .Arch ]
543
+ }
544
+
483
545
func Cmdline (ctx context.Context , cfg Config ) (exe string , args []string , err error ) {
484
546
y := cfg .LimaYAML
485
547
exe , args , err = Exe (* y .Arch )
@@ -531,7 +593,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
531
593
}
532
594
533
595
// CPU
534
- cpu := y . CPUType [ * y . Arch ]
596
+ cpu := resolveCPUType ( y )
535
597
if runtime .GOOS == "darwin" && runtime .GOARCH == "amd64" {
536
598
switch {
537
599
case strings .HasPrefix (cpu , "host" ), strings .HasPrefix (cpu , "max" ):
0 commit comments