hw: provide a fallback default machine when the default is compiled out
cover hw: provide a fallback default machine when the default is compiled out
From: Rohitashv Kumar <[email protected]>
When QEMU is built with the machine type marked as the default compiled out, there is no default machine at all and starting QEMU without an explicit -machine fails with:
No machine specified, and there is no default
On x86 this happens with a custom --with-devices-x86_64 configuration that drops the i440fx/pc machine but keeps q35: i440fx carries is_default, so once it is gone nothing is the default even though q35 is available.
This series lets a machine advertise itself as a *fallback* default:
1/2 adds an is_default_fallback flag to MachineClass and makes
find_default_machine() use it only when no is_default machine is present.
2/2 marks the latest non-default PC-family machine (q35) as the fallback.
There is intentionally no behaviour change for a normal build: the is_default machine (i440fx) always wins when present. The fallback only takes effect when the default machine is not compiled in.
This is an alternative to simply flipping the default from i440fx to q35, which would change long-standing default behaviour for everyone. Only one machine may advertise itself as the fallback (find_default_machine() asserts this, mirroring the single is_default assertion); on x86 that is q35. A priority-based is_default was also considered but seemed like more churn for the same result.
Tested by building QEMU with and without the i440fx/pc machine: with it present i440fx remains the default; with CONFIG_I440FX=n q35 becomes the default instead of QEMU having no default machine.
Rohitashv Kumar (2):
hw/core/machine: add a fallback default machine
hw/i386: make the latest non-default PC machine the fallback default
include/hw/core/boards.h | 1 + include/hw/i386/pc.h | 2 ++ system/vl.c | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.3
PATCH 1/2 hw/core/machine: add a fallback default machine
From: Rohitashv Kumar <[email protected]>
find_default_machine() returns the single machine whose class sets is_default. When QEMU is built with that machine compiled out there is no default at all, and starting QEMU without -machine fails with "No machine specified, and there is no default".
Add an is_default_fallback flag to MachineClass. When no is_default machine is present, find_default_machine() returns the machine that advertises itself as the fallback default. This changes nothing when the primary default machine is built in: the is_default machine always wins.
--- include/hw/core/boards.h | 1 + system/vl.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
include/hw/core/boards.h +1 -0
@@ -294,6 +294,7 @@ struct MachineClass { pci_allow_0_address:1 ;bool auto_create_sdcard;bool is_default; +bool is_default_fallback;const char *default_machine_opts;const char *default_boot_order;const char *default_display;
system/vl.c +6 -1
@@ -862,6 +862,7 @@ static MachineClass *find_default_machine(GSList *machines) {GSList *el;MachineClass *default_machineclass =NULL ; +MachineClass *fallback_machineclass =NULL ;for (el = machines; el; el = el->next) {MachineClass *mc = el->data;
@@ -869,10 +870,14 @@ static MachineClass *find_default_machine(GSList *machines)if (mc->is_default) {assert (default_machineclass ==NULL &&"Multiple default machines" ); default_machineclass = mc; + }else if (mc->is_default_fallback) { +assert (fallback_machineclass ==NULL && +"Multiple fallback default machines" ); + fallback_machineclass = mc; } } -return default_machineclass; +return default_machineclass ? default_machineclass : fallback_machineclass; }static void version (void )
Signature · 1 line
2.47.3
PATCH 2/2 hw/i386: make the latest non-default PC machine the fallback default
In reply to Rohitashv KumarFrom: Rohitashv Kumar <[email protected]>
Mark the latest machine of an x86 family that is not itself the default (i.e. q35, while i440fx is the default) as the fallback default machine.
When QEMU is built without the i440fx/pc machine (e.g. via a custom --with-devices-x86_64 configuration), x86_64/i386 previously had no default machine and required an explicit -machine argument. With this change q35 becomes the default in that configuration, while normal builds that include i440fx are unaffected.
--- include/hw/i386/pc.h | 2 ++ 1 file changed, 2 insertions(+)
include/hw/i386/pc.h +2 -0
@@ -306,6 +306,8 @@ extern const size_t pc_compat_4_1_len; mc->init =MACHINE_VER_SYM (init, namesym, __VA_ARGS__); \MACHINE_VER_DEPRECATION (__VA_ARGS__); \ mc->is_default = isdefault; \ +/* latest non-default family machine (e.g. q35) is the fallback default */ \ + mc->is_default_fallback = (malias !=NULL ) && !isdefault; \ mc->alias = malias; \ } \ static const TypeInfo MACHINE_VER_SYM(info, namesym, __VA_ARGS__) = \
Signature · 1 line
2.47.3