@@ -290,12 +290,16 @@ type features struct {
290
290
// e.g. "Supported machines are:\nakita...\n...virt-6.2...\n...virt-7.0...\n...\n"
291
291
// Not machine-readable, but checking strings.Contains() should be fine.
292
292
MachineHelp []byte
293
+ // CPUHelp is the output of `qemu-system-x86_64 -cpu help`
294
+ // e.g. "Available CPUs:\n...\nx86 base...\nx86 host...\n...\n"
295
+ // Not machine-readable, but checking strings.Contains() should be fine.
296
+ CPUHelp []byte
293
297
294
298
// VersionGEQ7 is true when the QEMU version seems v7.0.0 or later
295
299
VersionGEQ7 bool
296
300
}
297
301
298
- func inspectFeatures (exe string ) (* features , error ) {
302
+ func inspectFeatures (exe string , machine string ) (* features , error ) {
299
303
var (
300
304
f features
301
305
stdout bytes.Buffer
@@ -338,6 +342,19 @@ func inspectFeatures(exe string) (*features, error) {
338
342
}
339
343
f .VersionGEQ7 = strings .Contains (string (f .MachineHelp ), "-7.0" )
340
344
345
+ // Avoid error: "No machine specified, and there is no default"
346
+ cmd = exec .Command (exe , "-cpu" , "help" , "-machine" , machine )
347
+ cmd .Stdout = & stdout
348
+ cmd .Stderr = & stderr
349
+ if err := cmd .Run (); err != nil {
350
+ logrus .Warnf ("failed to run %v: stdout=%q, stderr=%q" , cmd .Args , stdout .String (), stderr .String ())
351
+ } else {
352
+ f .CPUHelp = stdout .Bytes ()
353
+ if len (f .CPUHelp ) == 0 {
354
+ f .CPUHelp = stderr .Bytes ()
355
+ }
356
+ }
357
+
341
358
return & f , nil
342
359
}
343
360
@@ -442,14 +459,22 @@ func adjustMemBytesDarwinARM64HVF(memBytes int64, accel string, features *featur
442
459
return memBytes
443
460
}
444
461
462
+ // qemuMachine returns string to use for -machine
463
+ func qemuMachine (arch limayaml.Arch ) string {
464
+ if arch == limayaml .X8664 {
465
+ return "q35"
466
+ }
467
+ return "virt"
468
+ }
469
+
445
470
func Cmdline (cfg Config ) (string , []string , error ) {
446
471
y := cfg .LimaYAML
447
472
exe , args , err := getExe (* y .Arch )
448
473
if err != nil {
449
474
return "" , nil , err
450
475
}
451
476
452
- features , err := inspectFeatures (exe )
477
+ features , err := inspectFeatures (exe , qemuMachine ( * y . Arch ) )
453
478
if err != nil {
454
479
return "" , nil , err
455
480
}
@@ -495,6 +520,9 @@ func Cmdline(cfg Config) (string, []string, error) {
495
520
}
496
521
}
497
522
}
523
+ if ! strings .Contains (string (features .CPUHelp ), strings .Split (cpu , "," )[0 ]) {
524
+ return "" , nil , fmt .Errorf ("cpu %q is not supported by %s" , cpu , exe )
525
+ }
498
526
args = appendArgsIfNoConflict (args , "-cpu" , cpu )
499
527
500
528
// Machine
0 commit comments