@@ -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"
@@ -403,6 +404,67 @@ func audioDevice() string {
403
404
return "oss"
404
405
}
405
406
407
+ func defaultCPUType () limayaml.CPUType {
408
+ // x86_64 + TCG + max was previously unstable until 2021.
409
+ // https://bugzilla.redhat.com/show_bug.cgi?id=1999700
410
+ // https://bugs.launchpad.net/qemu/+bug/1748296
411
+ defaultX8664 := "max"
412
+ if runtime .GOOS == "windows" && runtime .GOARCH == "amd64" {
413
+ // https://github.com/lima-vm/lima/pull/3487#issuecomment-2846253560
414
+ // > #931 intentionally prevented the code from setting it to max when running on Windows,
415
+ // > and kept it at qemu64.
416
+ //
417
+ // TODO: remove this if "max" works with the latest qemu
418
+ defaultX8664 = "qemu64"
419
+ }
420
+ cpuType := map [limayaml.Arch ]string {
421
+ limayaml .AARCH64 : "max" ,
422
+ limayaml .ARMV7L : "max" ,
423
+ limayaml .X8664 : defaultX8664 ,
424
+ limayaml .PPC64LE : "max" ,
425
+ limayaml .RISCV64 : "max" ,
426
+ limayaml .S390X : "max" ,
427
+ }
428
+ for arch := range cpuType {
429
+ if limayaml .IsNativeArch (arch ) && limayaml .IsAccelOS () {
430
+ if limayaml .HasHostCPU () {
431
+ cpuType [arch ] = "host"
432
+ }
433
+ }
434
+ if arch == limayaml .X8664 && runtime .GOOS == "darwin" {
435
+ // disable AVX-512, since it requires trapping instruction faults in guest
436
+ // Enterprise Linux requires either v2 (SSE4) or v3 (AVX2), but not yet v4.
437
+ cpuType [arch ] += ",-avx512vl"
438
+
439
+ // Disable pdpe1gb on Intel Mac
440
+ // https://github.com/lima-vm/lima/issues/1485
441
+ // https://stackoverflow.com/a/72863744/5167443
442
+ cpuType [arch ] += ",-pdpe1gb"
443
+ }
444
+ }
445
+ return cpuType
446
+ }
447
+
448
+ func resolveCPUType (y * limayaml.LimaYAML ) string {
449
+ cpuType := defaultCPUType ()
450
+ var overrideCPUType bool
451
+ for k , v := range y .VMOpts .QEMU .CPUType {
452
+ if ! slices .Contains (limayaml .ArchTypes , * y .Arch ) {
453
+ logrus .Warnf ("field `vmOpts.qemu.cpuType` uses unsupported arch %q" , k )
454
+ continue
455
+ }
456
+ if v != "" {
457
+ overrideCPUType = true
458
+ cpuType [k ] = v
459
+ }
460
+ }
461
+ if overrideCPUType {
462
+ y .VMOpts .QEMU .CPUType = cpuType
463
+ }
464
+
465
+ return cpuType [* y .Arch ]
466
+ }
467
+
406
468
func Cmdline (ctx context.Context , cfg Config ) (exe string , args []string , err error ) {
407
469
y := cfg .LimaYAML
408
470
exe , args , err = Exe (* y .Arch )
@@ -453,7 +515,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
453
515
}
454
516
455
517
// CPU
456
- cpu := y . CPUType [ * y . Arch ]
518
+ cpu := resolveCPUType ( y )
457
519
if runtime .GOOS == "darwin" && runtime .GOARCH == "amd64" {
458
520
switch {
459
521
case strings .HasPrefix (cpu , "host" ), strings .HasPrefix (cpu , "max" ):
0 commit comments