Finish cleaning up qemu_init
Subsystems (3)
cover Finish cleaning up qemu_init
These are the patches that needed another review, had some conflicts, or were not quite ready for the previous posting.
Highlights include:
- fixing the HMP prompt for -preconfig
- enabling the qtest server with -object instead of -qtest
- decoupling target machine code from QemuOpts
Based-on: <[email protected]>
Paolo Bonzini (15):
remove preconfig state
vl: remove separate preconfig main_loop
vl: allow -incoming defer with -preconfig
vl: extract softmmu/runstate.c
vl: extract softmmu/globals.c
vl: move all generic initialization out of vl.c
chardev: do not use machine_init_done
machine: introduce MachineInitPhase
machine: record whether nvdimm= was set
vl: make qemu_get_machine_opts static
qtest: add a QOM object for qtest
plugin: propagate errors
memory: allow creating MemoryRegions before accelerators
null-machine: do not create a default memdev
monitor: allow quitting while in preconfig state
accel/kvm/kvm-all.c | 11 +- chardev/char-mux.c | 38 +- chardev/chardev-sysemu.c | 69 --- chardev/meson.build | 2 +- hmp-commands.hx | 1 + hw/arm/boot.c | 2 +- hw/core/machine-qmp-cmds.c | 7 +- hw/core/machine.c | 56 +- hw/core/null-machine.c | 2 +- hw/core/qdev.c | 28 +- hw/microblaze/boot.c | 9 +- hw/nios2/boot.c | 9 +- hw/pci/pci.c | 2 +- hw/ppc/e500.c | 5 +- hw/ppc/spapr_nvdimm.c | 4 +- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/sifive_u.c | 6 +- hw/riscv/virt.c | 6 +- hw/usb/core.c | 2 +- hw/virtio/virtio-iommu.c | 2 +- hw/xtensa/xtfpga.c | 9 +- include/chardev/char.h | 6 +- include/exec/cpu-common.h | 3 + include/exec/exec-all.h | 3 - include/hw/mem/nvdimm.h | 2 +- include/hw/qdev-core.h | 33 +- include/qapi/qmp/dispatch.h | 1 + include/qemu/plugin.h | 4 +- include/sysemu/runstate.h | 1 - include/sysemu/sysemu.h | 7 +- linux-user/main.c | 4 +- monitor/hmp.c | 7 +- monitor/qmp-cmds.c | 10 - plugins/loader.c | 34 +- qapi/control.json | 3 +- qapi/qmp-dispatch.c | 5 +- qapi/run-state.json | 5 +- softmmu/device_tree.c | 2 +- softmmu/globals.c | 74 +++ softmmu/memory.c | 12 +- softmmu/meson.build | 2 + softmmu/qdev-monitor.c | 34 +- softmmu/qtest.c | 144 ++++- softmmu/runstate.c | 800 ++++++++++++++++++++++++++++ softmmu/vl.c | 958 ++-------------------------------- stubs/machine-init-done.c | 8 - stubs/meson.build | 2 +- stubs/qmp-command-available.c | 7 + tests/qtest/qmp-test.c | 2 +- ui/console.c | 2 +- 50 files changed, 1312 insertions(+), 1135 deletions(-) delete mode 100644 chardev/chardev-sysemu.c create mode 100644 softmmu/globals.c create mode 100644 softmmu/runstate.c delete mode 100644 stubs/machine-init-done.c create mode 100644 stubs/qmp-command-available.c
Signature · 1 line
2.26.2
PATCH 1/15 remove preconfig state
The preconfig state is only used if -incoming is not specified, which makes the RunState state machine more tricky than it need be. However there is already an equivalent condition which works even with -incoming, namely qdev_hotplug. Use it instead of a separate runstate.
--- hw/core/machine-qmp-cmds.c | 5 ++--- include/qapi/qmp/dispatch.h | 1 + monitor/hmp.c | 7 ++++--- monitor/qmp-cmds.c | 5 ++--- qapi/qmp-dispatch.c | 5 +---- qapi/run-state.json | 5 +---- softmmu/qdev-monitor.c | 12 ++++++++++++ softmmu/vl.c | 13 ++----------- stubs/meson.build | 1 + stubs/qmp-command-available.c | 7 +++++++ tests/qtest/qmp-test.c | 2 +- 11 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 stubs/qmp-command-available.c
hw/core/machine-qmp-cmds.c +2 -3
@@ -286,9 +286,8 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)void qmp_set_numa_node (NumaOptions *cmd,Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) { +error_setg (errp,"The command is permitted only before the machine has been created" );return ; }
include/qapi/qmp/dispatch.h +1 -0
@@ -48,6 +48,7 @@ void qmp_disable_command(QmpCommandList *cmds, const char *name);void qmp_enable_command (QmpCommandList *cmds,const char *name);bool qmp_command_is_enabled (const QmpCommand *cmd); +bool qmp_command_available (const QmpCommand *cmd,Error **errp);const char *qmp_command_name (const QmpCommand *cmd);bool qmp_has_success_response (const QmpCommand *cmd);QDict *qmp_error_response (Error *err);
monitor/hmp.c +4 -3
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include <dirent.h> +#include "hw/qdev-core.h" #include "monitor-internal.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h"
@@ -215,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)static bool cmd_available (const HMPCommand *cmd) { -return !runstate_check (RUN_STATE_PRECONFIG ) ||cmd_can_preconfig (cmd); +return qdev_hotplug ||cmd_can_preconfig (cmd); } static void help_cmd_dump_one(Monitor *mon,
@@ -658,8 +659,8 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,return NULL ; }if (!cmd_available (cmd)) { -monitor_printf (mon,"Command '%.*s' not available with -preconfig " -"until after exit_preconfig.\n" , +monitor_printf (mon,"Command '%.*s' not available " +"until machine initialization has completed.\n" , (int )(p - cmdp_start), cmdp_start);return NULL ; }
monitor/qmp-cmds.c +2 -3
@@ -104,9 +104,8 @@ void qmp_system_powerdown(Error **errp)void qmp_x_exit_preconfig (Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) { +error_setg (errp,"The command is permitted only before machine initialization" );return ; }qemu_exit_preconfig_request ();
qapi/qmp-dispatch.c +1 -4
@@ -167,10 +167,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request, goto out; } -if (runstate_check (RUN_STATE_PRECONFIG ) && - !(cmd->options &QCO_ALLOW_PRECONFIG )) { -error_setg (&err,"The command '%s' isn't permitted in '%s' state" , - cmd->name,RunState_str (RUN_STATE_PRECONFIG )); +if (!qmp_command_available (cmd, &err)) { goto out; }
qapi/run-state.json +1 -4
@@ -50,15 +50,12 @@ # @colo: guest is paused to save/restore VM state under colo checkpoint, # VM can not get into this state unless colo capability is enabled # for migration. (since 2.8) -# @preconfig: QEMU is paused before board specific init callback is executed. -# The state is reachable only if the --preconfig CLI option is used. -# (Since 3.0) ## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked', 'colo', 'preconfig' ] } + 'guest-panicked', 'colo' ] } ## # @ShutdownCause:
softmmu/qdev-monitor.c +12 -0
@@ -25,6 +25,7 @@#include "sysemu/arch_init.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" +#include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qemu/config-file.h"
@@ -997,3 +998,14 @@ int qemu_global_option(const char *str)return 0 ; } + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +if (!qdev_hotplug && + !(cmd->options &QCO_ALLOW_PRECONFIG )) { +error_setg (errp,"The command '%s' is permitted only after machine initialization has completed" , + cmd->name); +return false; + } +return true; +}
softmmu/vl.c +2 -11
@@ -557,7 +557,7 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)/***********************************************************/ /* QEMU state */ -static RunState current_run_state =RUN_STATE_PRECONFIG ; +static RunState current_run_state =RUN_STATE_PRELAUNCH ;/* We use RUN_STATE__MAX but any invalid value will do */ static RunState vmstop_requested =RUN_STATE__MAX ;
@@ -569,13 +569,7 @@ typedef struct { } RunStateTransition;static const RunStateTransition runstate_transitions_def[] = { -/* from -> to */ - {RUN_STATE_PRECONFIG ,RUN_STATE_PRELAUNCH }, -/* Early switch to inmigrate state to allow -incoming CLI option work -* as it used to. TODO: delay actual switching to inmigrate state to -* the point after machine is built and remove this hack. -*/ - {RUN_STATE_PRECONFIG ,RUN_STATE_INMIGRATE }, + {RUN_STATE_PRELAUNCH ,RUN_STATE_INMIGRATE }, {RUN_STATE_DEBUG ,RUN_STATE_RUNNING }, {RUN_STATE_DEBUG ,RUN_STATE_FINISH_MIGRATE },
@@ -1471,9 +1465,6 @@ static bool main_loop_should_exit(void)ShutdownCause request;if (preconfig_exit_requested) { -if (runstate_check (RUN_STATE_PRECONFIG )) { -runstate_set (RUN_STATE_PRELAUNCH ); - } preconfig_exit_requested = false;return true; }
stubs/meson.build +1 -0
@@ -29,6 +29,7 @@ stub_ss.add(files('pci-bus.c')) stub_ss.add(files('pci-host-piix.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('qmp_memory_device.c')) +stub_ss.add(files('qmp-command-available.c')) stub_ss.add(files('qtest.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('ramfb.c'))
stubs/qmp-command-available.c new file +7 -0
@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "qapi/qmp/dispatch.h" + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +return true; +}
tests/qtest/qmp-test.c +1 -1
@@ -295,7 +295,7 @@ static void test_qmp_preconfig(void) rsp =qtest_qmp (qs,"{ 'execute': 'query-status' }" ); ret =qdict_get_qdict (rsp,"return" );g_assert (ret); - g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "preconfig"); + g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "prelaunch");qobject_unref (rsp);/* exit preconfig state */
Signature · 1 line
2.26.2
Re: [PATCH 01/15] remove preconfig state
Quoted 26 lines · On Wed, 2 Dec 2020 03:18:40 -0500 Paolo Bonzini <[email protected]> wrote:
The preconfig state is only used if -incoming is not specified, which makes the RunState state machine more tricky than it need be. However there is already an equivalent condition which works even with -incoming, namely
qdev_hotplug. Use it instead of a separate runstate.Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine-qmp-cmds.c | 5 ++--- include/qapi/qmp/dispatch.h | 1 + monitor/hmp.c | 7 ++++--- monitor/qmp-cmds.c | 5 ++--- qapi/qmp-dispatch.c | 5 +---- qapi/run-state.json | 5 +---- softmmu/qdev-monitor.c | 12 ++++++++++++ softmmu/vl.c | 13 ++----------- stubs/meson.build | 1 + stubs/qmp-command-available.c | 7 +++++++ tests/qtest/qmp-test.c | 2 +- 11 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 stubs/qmp-command-available.chw/core/machine-qmp-cmds.c +0
-0
hw/core/machine-qmp-cmds.c HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp) · line 289
Quoted 7 lines
hw/core/machine-qmp-cmds.c +1
-3@@ -286,9 +286,8 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)void qmp_set_numa_node (NumaOptions *cmd,Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) {
it's too late for qmp_set_numa_node(), but given it's temporary and patch 8/15 changes it to correct state it should be fine. so
Quoted 204 lines
hw/core/machine-qmp-cmds.c +1
-0+error_setg (errp,"The command is permitted only before the machine has been created" );return ; }include/qapi/qmp/dispatch.h +1
-0@@ -48,6 +48,7 @@ void qmp_disable_command(QmpCommandList *cmds, const char *name);void qmp_enable_command (QmpCommandList *cmds,const char *name);bool qmp_command_is_enabled (const QmpCommand *cmd); +bool qmp_command_available (const QmpCommand *cmd,Error **errp);const char *qmp_command_name (const QmpCommand *cmd);bool qmp_has_success_response (const QmpCommand *cmd);QDict *qmp_error_response (Error *err);monitor/hmp.c +4
-3@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include <dirent.h> +#include "hw/qdev-core.h" #include "monitor-internal.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" @@ -215,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)static bool cmd_available (const HMPCommand *cmd) { -return !runstate_check (RUN_STATE_PRECONFIG ) ||cmd_can_preconfig (cmd); +return qdev_hotplug ||cmd_can_preconfig (cmd); } static void help_cmd_dump_one(Monitor *mon,@@ -658,8 +659,8 @@ static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,return NULL ; }if (!cmd_available (cmd)) { -monitor_printf (mon,"Command '%.*s' not available with -preconfig " -"until after exit_preconfig.\n" , +monitor_printf (mon,"Command '%.*s' not available " +"until machine initialization has completed.\n" , (int )(p - cmdp_start), cmdp_start);return NULL ; }monitor/qmp-cmds.c +2
-3@@ -104,9 +104,8 @@ void qmp_system_powerdown(Error **errp)void qmp_x_exit_preconfig (Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) { +error_setg (errp,"The command is permitted only before machine initialization" );return ; }qemu_exit_preconfig_request ();qapi/qmp-dispatch.c +1
-4@@ -167,10 +167,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request, goto out; } -if (runstate_check (RUN_STATE_PRECONFIG ) && - !(cmd->options &QCO_ALLOW_PRECONFIG )) { -error_setg (&err,"The command '%s' isn't permitted in '%s' state" , - cmd->name,RunState_str (RUN_STATE_PRECONFIG )); +if (!qmp_command_available (cmd, &err)) { goto out; }qapi/run-state.json +1
-4@@ -50,15 +50,12 @@ # @colo: guest is paused to save/restore VM state under colo checkpoint, # VM can not get into this state unless colo capability is enabled # for migration. (since 2.8) -# @preconfig: QEMU is paused before board specific init callback is executed. -# The state is reachable only if the --preconfig CLI option is used. -# (Since 3.0) ## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error', 'paused', 'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked', 'colo', 'preconfig' ] } + 'guest-panicked', 'colo' ] } ## # @ShutdownCause:softmmu/qdev-monitor.c +12
-0@@ -25,6 +25,7 @@#include "sysemu/arch_init.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" +#include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qemu/config-file.h" @@ -997,3 +998,14 @@ int qemu_global_option(const char *str)return 0 ; } + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +if (!qdev_hotplug && + !(cmd->options &QCO_ALLOW_PRECONFIG )) { +error_setg (errp,"The command '%s' is permitted only after machine initialization has completed" , + cmd->name); +return false; + } +return true; +}softmmu/vl.c +2
-11@@ -557,7 +557,7 @@ static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)/***********************************************************/ /* QEMU state */ -static RunState current_run_state =RUN_STATE_PRECONFIG ; +static RunState current_run_state =RUN_STATE_PRELAUNCH ;/* We use RUN_STATE__MAX but any invalid value will do */ static RunState vmstop_requested =RUN_STATE__MAX ;@@ -569,13 +569,7 @@ typedef struct { } RunStateTransition;static const RunStateTransition runstate_transitions_def[] = { -/* from -> to */ - {RUN_STATE_PRECONFIG ,RUN_STATE_PRELAUNCH }, -/* Early switch to inmigrate state to allow -incoming CLI option work -* as it used to. TODO: delay actual switching to inmigrate state to -* the point after machine is built and remove this hack. -*/ - {RUN_STATE_PRECONFIG ,RUN_STATE_INMIGRATE }, + {RUN_STATE_PRELAUNCH ,RUN_STATE_INMIGRATE }, {RUN_STATE_DEBUG ,RUN_STATE_RUNNING }, {RUN_STATE_DEBUG ,RUN_STATE_FINISH_MIGRATE },@@ -1471,9 +1465,6 @@ static bool main_loop_should_exit(void)ShutdownCause request;if (preconfig_exit_requested) { -if (runstate_check (RUN_STATE_PRECONFIG )) { -runstate_set (RUN_STATE_PRELAUNCH ); - } preconfig_exit_requested = false;return true; }stubs/meson.build +1
-0@@ -29,6 +29,7 @@ stub_ss.add(files('pci-bus.c')) stub_ss.add(files('pci-host-piix.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('qmp_memory_device.c')) +stub_ss.add(files('qmp-command-available.c')) stub_ss.add(files('qtest.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('ramfb.c'))stubs/qmp-command-available.c new file +7
-0@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "qapi/qmp/dispatch.h" + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +return true; +}tests/qtest/qmp-test.c +1
-1@@ -295,7 +295,7 @@ static void test_qmp_preconfig(void) rsp =qtest_qmp (qs,"{ 'execute': 'query-status' }" ); ret =qdict_get_qdict (rsp,"return" );g_assert (ret); - g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "preconfig"); + g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "prelaunch");qobject_unref (rsp);/* exit preconfig state */
Re: [PATCH 01/15] remove preconfig state
Il lun 7 dic 2020, 14:57 Igor Mammedov <[email protected]> ha scritto:
Quoted 37 lines
hw/core/machine-qmp-cmds.c HotpluggableCPUList
Quoted 26 lines · On Wed, 2 Dec 2020 03:18:40 -0500 Paolo Bonzini <[email protected]> wrote:
The preconfig state is only used if -incoming is not specified, which makes the RunState state machine more tricky than it need be. However there is already an equivalent condition which works even with -incoming, namely
qdev_hotplug. Use it instead of a separate runstate.Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine-qmp-cmds.c | 5 ++--- include/qapi/qmp/dispatch.h | 1 + monitor/hmp.c | 7 ++++--- monitor/qmp-cmds.c | 5 ++--- qapi/qmp-dispatch.c | 5 +---- qapi/run-state.json | 5 +---- softmmu/qdev-monitor.c | 12 ++++++++++++ softmmu/vl.c | 13 ++----------- stubs/meson.build | 1 + stubs/qmp-command-available.c | 7 +++++++ tests/qtest/qmp-test.c | 2 +- 11 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 stubs/qmp-command-available.chw/core/machine-qmp-cmds.c +0
-0@@ -286,9 +286,8 @@ HotpluggableCPUList*qmp_query_hotpluggable_cpus(Error **errp)
hw/core/machine-qmp-cmds.c HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp) · line 289
Quoted 7 lines
hw/core/machine-qmp-cmds.c +1
-3void qmp_set_numa_node (NumaOptions *cmd,Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) {
Quoted 6 lines
it's too late for
qmp_set_numa_node(), but given it's temporary and patch 8/15 changes it to correct state it should be fine. soReviewed-by Igor Mammedov <[email protected]>
It's too late according to the fine grained distinction of phases that will be introduced later. For the two phases that are possible with current QEMU (before or after preconfig) it should be indistinguishable, right?
Paolo
Quoted 225 lines
hw/core/machine-qmp-cmds.c HotpluggableCPUList · line 289
Quoted 2 lines
hw/core/machine-qmp-cmds.c +1
-0+ error_setg(errp, "The command is permitted only before themachine has been created");
include/qapi/qmp/dispatch.h void qmp_disable_command(QmpCommandList *cmds, const
Quoted 8 lines
hw/core/machine-qmp-cmds.c +0
-0return ; }include/qapi/qmp/dispatch.h +0
-0@@ -48,6 +48,7 @@ void qmp_disable_command(QmpCommandList *cmds, constchar *name);
Quoted 20 lines
include/qapi/qmp/dispatch.h +1
-0void qmp_enable_command (QmpCommandList *cmds,const char *name);bool qmp_command_is_enabled (const QmpCommand *cmd); +bool qmp_command_available (const QmpCommand *cmd,Error **errp);const char *qmp_command_name (const QmpCommand *cmd);bool qmp_has_success_response (const QmpCommand *cmd);QDict *qmp_error_response (Error *err);monitor/hmp.c +1
-0@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include <dirent.h> +#include "hw/qdev-core.h" #include "monitor-internal.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" monitor/hmp.c static bool cmd_can_preconfig(const HMPCommand *cmd) · line 218
Quoted 4 lines
monitor/hmp.c +0
-1@@ -215,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)static bool cmd_available (const HMPCommand *cmd) { - return !runstate_check(RUN_STATE_PRECONFIG) ||
cmd_can_preconfig(cmd);monitor/hmp.c static const HMPCommand
Quoted 5 lines
monitor/hmp.c +1
-0+return qdev_hotplug ||cmd_can_preconfig (cmd); } static void help_cmd_dump_one(Monitor *mon,@@ -658,8 +659,8 @@ static const HMPCommand*monitor_parse_command(MonitorHMP
*hmp_mon,monitor/hmp.c static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
Quoted 4 lines
monitor/hmp.c +0
-1return NULL ; }if (!cmd_available (cmd)) { - monitor_printf(mon, "Command '%.*s' not available with-preconfig "
monitor/hmp.c static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
Quoted 3 lines
monitor/hmp.c +2
-1- "until after exit_preconfig.\n", +monitor_printf (mon,"Command '%.*s' not available " + "until machine initialization hascompleted.\n",
Quoted 8 lines
monitor/hmp.c +0
-0(int)(p - cmdp_start), cmdp_start);return NULL ; }monitor/qmp-cmds.c +0
-0monitor/qmp-cmds.c void qmp_system_powerdown(Error **errp) · line 108
Quoted 8 lines
monitor/qmp-cmds.c +2
-3@@ -104,9 +104,8 @@ void qmp_system_powerdown(Error **errp)void qmp_x_exit_preconfig (Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) { + error_setg(errp, "The command is permitted only before machineinitialization");
qapi/qmp-dispatch.c QDict *qmp_dispatch(const QmpCommandList *cmds,
Quoted 8 lines
monitor/qmp-cmds.c +0
-0return ; }qemu_exit_preconfig_request ();qapi/qmp-dispatch.c +0
-0@@ -167,10 +167,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds,QObject *request,
qapi/qmp-dispatch.c QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,
Quoted 6 lines
qapi/qmp-dispatch.c +0
-3goto out; } -if (runstate_check (RUN_STATE_PRECONFIG ) && - !(cmd->options &QCO_ALLOW_PRECONFIG )) { - error_setg(&err, "The command '%s' isn't permitted in '%s'state",
qapi/run-state.json line 51
Quoted 12 lines
qapi/qmp-dispatch.c +1
-1- cmd->name, RunState_str(RUN_STATE_PRECONFIG)); +if (!qmp_command_available (cmd, &err)) { goto out; }qapi/run-state.json +0
-0@@ -50,15 +50,12 @@ # @colo: guest is paused to save/restore VM state under colo checkpoint, # VM can not get into this state unless colo capability isenabled
qapi/run-state.json line 53
Quoted 2 lines
qapi/run-state.json +0
-1# for migration. (since 2.8) -# @preconfig: QEMU is paused before board specific init callback isexecuted.
qapi/run-state.json line 54
Quoted 1 line
qapi/run-state.json +0
-1-# The state is reachable only if the --preconfig CLI optionis used.
qapi/run-state.json
Quoted 4 lines
qapi/run-state.json +0
-1-# (Since 3.0) ## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error','paused',
Quoted 20 lines
qapi/run-state.json +1
-1'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked', 'colo', 'preconfig' ] } + 'guest-panicked', 'colo' ] } ## # @ShutdownCause:softmmu/qdev-monitor.c +1
-0@@ -25,6 +25,7 @@#include "sysemu/arch_init.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" +#include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qemu/config-file.h" softmmu/qdev-monitor.c int qemu_global_option(const char *str) · line 1006
Quoted 9 lines
softmmu/qdev-monitor.c +6
-0@@ -997,3 +998,14 @@ int qemu_global_option(const char *str)return 0 ; } + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +if (!qdev_hotplug && + !(cmd->options &QCO_ALLOW_PRECONFIG )) { + error_setg(errp, "The command '%s' is permitted only aftermachine initialization has completed",
softmmu/vl.c static int default_driver_check(void *opaque,
Quoted 10 lines
softmmu/qdev-monitor.c +5
-0+ cmd->name); +return false; + } +return true; +}softmmu/vl.c +0
-0@@ -557,7 +557,7 @@ static int default_driver_check(void *opaque,QemuOpts *opts, Error **errp)
Quoted 9 lines
softmmu/vl.c +1
-1/***********************************************************/ /* QEMU state */ -static RunState current_run_state =RUN_STATE_PRECONFIG ; +static RunState current_run_state =RUN_STATE_PRELAUNCH ;/* We use RUN_STATE__MAX but any invalid value will do */ static RunState vmstop_requested =RUN_STATE__MAX ;softmmu/vl.c typedef struct { · line 574
Quoted 6 lines
softmmu/vl.c +0
-3@@ -569,13 +569,7 @@ typedef struct { } RunStateTransition;static const RunStateTransition runstate_transitions_def[] = { -/* from -> to */ - {RUN_STATE_PRECONFIG ,RUN_STATE_PRELAUNCH }, -/* Early switch to inmigrate state to allow -incoming CLI option work
softmmu/vl.c typedef struct { · line 575
Quoted 1 line
softmmu/vl.c +0
-1-* as it used to. TODO: delay actual switching to inmigrate state to
Review
Quoted 30 lines
softmmu/vl.c +1
-6-* the point after machine is built and remove this hack. -*/ - { RUN_STATE_PRECONFIG, RUN_STATE_INMIGRATE }, + { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },@@ -1471,9 +1465,6 @@ static bool main_loop_should_exit(void)ShutdownCause request;if (preconfig_exit_requested) { -if (runstate_check (RUN_STATE_PRECONFIG )) { -runstate_set (RUN_STATE_PRELAUNCH ); - } preconfig_exit_requested = false;return true; }stubs/meson.build +1
-0@@ -29,6 +29,7 @@ stub_ss.add(files('pci-bus.c')) stub_ss.add(files('pci-host-piix.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('qmp_memory_device.c')) +stub_ss.add(files('qmp-command-available.c')) stub_ss.add(files('qtest.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('ramfb.c'))(quoted diff) +0
-0
b/stubs/qmp-command-available.cQuoted 25 lines
new file mode 100644
index 0000000000..46540af7bfstubs/qmp-command-available.c new file +7
-0@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "qapi/qmp/dispatch.h" + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +return true; +}tests/qtest/qmp-test.c +1
-1@@ -295,7 +295,7 @@ static void test_qmp_preconfig(void) rsp =qtest_qmp (qs,"{ 'execute': 'query-status' }" ); ret =qdict_get_qdict (rsp,"return" );g_assert (ret); - g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "preconfig"); + g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "prelaunch");qobject_unref (rsp);/* exit preconfig state */
Re: [PATCH 01/15] remove preconfig state
Quoted 43 lines · On Mon, 7 Dec 2020 15:11:34 +0100 Paolo Bonzini <[email protected]> wrote:
Il lun 7 dic 2020, 14:57 Igor Mammedov <[email protected]> ha scritto:
Quoted 41 lines
hw/core/machine-qmp-cmds.c HotpluggableCPUList
Quoted 26 lines · On Wed, 2 Dec 2020 03:18:40 -0500 Paolo Bonzini <[email protected]> wrote:
The preconfig state is only used if -incoming is not specified, which makes the RunState state machine more tricky than it need be. However there is already an equivalent condition which works even with -incoming, namely
qdev_hotplug. Use it instead of a separate runstate.Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine-qmp-cmds.c | 5 ++--- include/qapi/qmp/dispatch.h | 1 + monitor/hmp.c | 7 ++++--- monitor/qmp-cmds.c | 5 ++--- qapi/qmp-dispatch.c | 5 +---- qapi/run-state.json | 5 +---- softmmu/qdev-monitor.c | 12 ++++++++++++ softmmu/vl.c | 13 ++----------- stubs/meson.build | 1 + stubs/qmp-command-available.c | 7 +++++++ tests/qtest/qmp-test.c | 2 +- 11 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 stubs/qmp-command-available.chw/core/machine-qmp-cmds.c +0
-0@@ -286,9 +286,8 @@ HotpluggableCPUList*qmp_query_hotpluggable_cpus(Error **errp)
hw/core/machine-qmp-cmds.c HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp) · line 289
Quoted 7 lines
hw/core/machine-qmp-cmds.c +1
-3void qmp_set_numa_node (NumaOptions *cmd,Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) {it's too late for
qmp_set_numa_node(), but given it's temporary and patch 8/15 changes it to correct state it should be fine. so
Quoted 6 lines
Quoted 2 lines
Reviewed-by Igor Mammedov <[email protected]>It's too late according to the fine grained distinction of phases that will be introduced later. For the two phases that are possible with current QEMU (before or after preconfig) it should be indistinguishable, right?
yep, it doesn't break anything and 8/15 makes sure that command ends up at correct phase.
Quoted 229 lines
Paolo
Quoted 225 lines
hw/core/machine-qmp-cmds.c HotpluggableCPUList · line 289
Quoted 2 lines
hw/core/machine-qmp-cmds.c +1
-0+ error_setg(errp, "The command is permitted only before themachine has been created");
include/qapi/qmp/dispatch.h void qmp_disable_command(QmpCommandList *cmds, const
Quoted 8 lines
hw/core/machine-qmp-cmds.c +0
-0return ; }include/qapi/qmp/dispatch.h +0
-0@@ -48,6 +48,7 @@ void qmp_disable_command(QmpCommandList *cmds, constchar *name);
Quoted 20 lines
include/qapi/qmp/dispatch.h +1
-0void qmp_enable_command (QmpCommandList *cmds,const char *name);bool qmp_command_is_enabled (const QmpCommand *cmd); +bool qmp_command_available (const QmpCommand *cmd,Error **errp);const char *qmp_command_name (const QmpCommand *cmd);bool qmp_has_success_response (const QmpCommand *cmd);QDict *qmp_error_response (Error *err);monitor/hmp.c +1
-0@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include <dirent.h> +#include "hw/qdev-core.h" #include "monitor-internal.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" monitor/hmp.c static bool cmd_can_preconfig(const HMPCommand *cmd) · line 218
Quoted 4 lines
monitor/hmp.c +0
-1@@ -215,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)static bool cmd_available (const HMPCommand *cmd) { - return !runstate_check(RUN_STATE_PRECONFIG) ||
cmd_can_preconfig(cmd);monitor/hmp.c static const HMPCommand
Quoted 5 lines
monitor/hmp.c +1
-0+return qdev_hotplug ||cmd_can_preconfig (cmd); } static void help_cmd_dump_one(Monitor *mon,@@ -658,8 +659,8 @@ static const HMPCommand*monitor_parse_command(MonitorHMP
*hmp_mon,monitor/hmp.c static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
Quoted 4 lines
monitor/hmp.c +0
-1return NULL ; }if (!cmd_available (cmd)) { - monitor_printf(mon, "Command '%.*s' not available with-preconfig "
monitor/hmp.c static const HMPCommand *monitor_parse_command(MonitorHMP *hmp_mon,
Quoted 3 lines
monitor/hmp.c +2
-1- "until after exit_preconfig.\n", +monitor_printf (mon,"Command '%.*s' not available " + "until machine initialization hascompleted.\n",
Quoted 8 lines
monitor/hmp.c +0
-0(int)(p - cmdp_start), cmdp_start);return NULL ; }monitor/qmp-cmds.c +0
-0monitor/qmp-cmds.c void qmp_system_powerdown(Error **errp) · line 108
Quoted 8 lines
monitor/qmp-cmds.c +2
-3@@ -104,9 +104,8 @@ void qmp_system_powerdown(Error **errp)void qmp_x_exit_preconfig (Error **errp) { -if (!runstate_check (RUN_STATE_PRECONFIG )) { -error_setg (errp,"The command is permitted only in '%s' state" , -RunState_str (RUN_STATE_PRECONFIG )); +if (qdev_hotplug) { + error_setg(errp, "The command is permitted only before machineinitialization");
qapi/qmp-dispatch.c QDict *qmp_dispatch(const QmpCommandList *cmds,
Quoted 8 lines
monitor/qmp-cmds.c +0
-0return ; }qemu_exit_preconfig_request ();qapi/qmp-dispatch.c +0
-0@@ -167,10 +167,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds,QObject *request,
qapi/qmp-dispatch.c QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,
Quoted 6 lines
qapi/qmp-dispatch.c +0
-3goto out; } -if (runstate_check (RUN_STATE_PRECONFIG ) && - !(cmd->options &QCO_ALLOW_PRECONFIG )) { - error_setg(&err, "The command '%s' isn't permitted in '%s'state",
qapi/run-state.json line 51
Quoted 12 lines
qapi/qmp-dispatch.c +1
-1- cmd->name, RunState_str(RUN_STATE_PRECONFIG)); +if (!qmp_command_available (cmd, &err)) { goto out; }qapi/run-state.json +0
-0@@ -50,15 +50,12 @@ # @colo: guest is paused to save/restore VM state under colo checkpoint, # VM can not get into this state unless colo capability isenabled
qapi/run-state.json line 53
Quoted 2 lines
qapi/run-state.json +0
-1# for migration. (since 2.8) -# @preconfig: QEMU is paused before board specific init callback isexecuted.
qapi/run-state.json line 54
Quoted 1 line
qapi/run-state.json +0
-1-# The state is reachable only if the --preconfig CLI optionis used.
qapi/run-state.json
Quoted 4 lines
qapi/run-state.json +0
-1-# (Since 3.0) ## { 'enum': 'RunState', 'data': [ 'debug', 'inmigrate', 'internal-error', 'io-error','paused',
Quoted 20 lines
qapi/run-state.json +1
-1'postmigrate', 'prelaunch', 'finish-migrate', 'restore-vm', 'running', 'save-vm', 'shutdown', 'suspended', 'watchdog', - 'guest-panicked', 'colo', 'preconfig' ] } + 'guest-panicked', 'colo' ] } ## # @ShutdownCause:softmmu/qdev-monitor.c +1
-0@@ -25,6 +25,7 @@#include "sysemu/arch_init.h" #include "qapi/error.h" #include "qapi/qapi-commands-qdev.h" +#include "qapi/qmp/dispatch.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qerror.h" #include "qemu/config-file.h" softmmu/qdev-monitor.c int qemu_global_option(const char *str) · line 1006
Quoted 9 lines
softmmu/qdev-monitor.c +6
-0@@ -997,3 +998,14 @@ int qemu_global_option(const char *str)return 0 ; } + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +if (!qdev_hotplug && + !(cmd->options &QCO_ALLOW_PRECONFIG )) { + error_setg(errp, "The command '%s' is permitted only aftermachine initialization has completed",
softmmu/vl.c static int default_driver_check(void *opaque,
Quoted 10 lines
softmmu/qdev-monitor.c +5
-0+ cmd->name); +return false; + } +return true; +}softmmu/vl.c +0
-0@@ -557,7 +557,7 @@ static int default_driver_check(void *opaque,QemuOpts *opts, Error **errp)
Quoted 9 lines
softmmu/vl.c +1
-1/***********************************************************/ /* QEMU state */ -static RunState current_run_state =RUN_STATE_PRECONFIG ; +static RunState current_run_state =RUN_STATE_PRELAUNCH ;/* We use RUN_STATE__MAX but any invalid value will do */ static RunState vmstop_requested =RUN_STATE__MAX ;softmmu/vl.c typedef struct { · line 574
Quoted 6 lines
softmmu/vl.c +0
-3@@ -569,13 +569,7 @@ typedef struct { } RunStateTransition;static const RunStateTransition runstate_transitions_def[] = { -/* from -> to */ - {RUN_STATE_PRECONFIG ,RUN_STATE_PRELAUNCH }, -/* Early switch to inmigrate state to allow -incoming CLI option work
softmmu/vl.c typedef struct { · line 575
Quoted 1 line
softmmu/vl.c +0
-1-* as it used to. TODO: delay actual switching to inmigrate state to
Review
Quoted 30 lines
softmmu/vl.c +1
-6-* the point after machine is built and remove this hack. -*/ - { RUN_STATE_PRECONFIG, RUN_STATE_INMIGRATE }, + { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE }, { RUN_STATE_DEBUG, RUN_STATE_RUNNING }, { RUN_STATE_DEBUG, RUN_STATE_FINISH_MIGRATE },@@ -1471,9 +1465,6 @@ static bool main_loop_should_exit(void)ShutdownCause request;if (preconfig_exit_requested) { -if (runstate_check (RUN_STATE_PRECONFIG )) { -runstate_set (RUN_STATE_PRELAUNCH ); - } preconfig_exit_requested = false;return true; }stubs/meson.build +1
-0@@ -29,6 +29,7 @@ stub_ss.add(files('pci-bus.c')) stub_ss.add(files('pci-host-piix.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('qmp_memory_device.c')) +stub_ss.add(files('qmp-command-available.c')) stub_ss.add(files('qtest.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('ramfb.c'))(quoted diff) +0
-0
b/stubs/qmp-command-available.cQuoted 25 lines
new file mode 100644
index 0000000000..46540af7bfstubs/qmp-command-available.c new file +7
-0@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "qapi/qmp/dispatch.h" + +bool qmp_command_available (const QmpCommand *cmd,Error **errp) +{ +return true; +}tests/qtest/qmp-test.c +1
-1@@ -295,7 +295,7 @@ static void test_qmp_preconfig(void) rsp =qtest_qmp (qs,"{ 'execute': 'query-status' }" ); ret =qdict_get_qdict (rsp,"return" );g_assert (ret); - g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "preconfig"); + g_assert_cmpstr(qdict_get_try_str(ret, "status"), ==, "prelaunch");qobject_unref (rsp);/* exit preconfig state */
PATCH 2/15 vl: remove separate preconfig main_loop
In reply to Paolo BonziniMove post-preconfig initialization to the x-exit-preconfig. If preconfig is not requested, just exit preconfig mode immediately with the QMP command.
As a result, the preconfig loop will run with accel_setup_post and os_setup_post restrictions (xen_restrict, chroot, etc.) already done.
--- include/sysemu/runstate.h | 1 - monitor/qmp-cmds.c | 9 ---- softmmu/vl.c | 95 +++++++++++++++++---------------------- 3 files changed, 41 insertions(+), 64 deletions(-)
include/sysemu/runstate.h +0 -1
@@ -41,7 +41,6 @@ typedef enum WakeupReason {QEMU_WAKEUP_REASON_OTHER , } WakeupReason; -void qemu_exit_preconfig_request (void );void qemu_system_reset_request (ShutdownCause reason);void qemu_system_suspend_request (void );void qemu_register_suspend_notifier (Notifier *notifier);
monitor/qmp-cmds.c +0 -9
@@ -102,15 +102,6 @@ void qmp_system_powerdown(Error **errp)qemu_system_powerdown_request (); } -void qmp_x_exit_preconfig (Error **errp) -{ -if (qdev_hotplug) { -error_setg (errp,"The command is permitted only before machine initialization" ); -return ; - } -qemu_exit_preconfig_request (); -} -void qmp_cont (Error **errp) {BlockBackend *blk;
softmmu/vl.c +41 -54
139 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH 02/15] vl: remove separate preconfig main_loop
Quoted 9 lines · On Wed, 2 Dec 2020 03:18:41 -0500 Paolo Bonzini <[email protected]> wrote:
Move post-preconfig initialization to the x-exit-preconfig. If preconfig is not requested, just exit preconfig mode immediately with the QMP command.
As a result, the preconfig loop will run with
accel_setup_postandos_setup_postrestrictions (xen_restrict, chroot, etc.) already done.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 187 lines
--- include/sysemu/runstate.h | 1 - monitor/qmp-cmds.c | 9 ---- softmmu/vl.c | 95 +++++++++++++++++---------------------- 3 files changed, 41 insertions(+), 64 deletions(-)include/sysemu/runstate.h +0
-1@@ -41,7 +41,6 @@ typedef enum WakeupReason {QEMU_WAKEUP_REASON_OTHER , } WakeupReason; -void qemu_exit_preconfig_request (void );void qemu_system_reset_request (ShutdownCause reason);void qemu_system_suspend_request (void );void qemu_register_suspend_notifier (Notifier *notifier);monitor/qmp-cmds.c +0
-9@@ -102,15 +102,6 @@ void qmp_system_powerdown(Error **errp)qemu_system_powerdown_request (); } -void qmp_x_exit_preconfig (Error **errp) -{ -if (qdev_hotplug) { -error_setg (errp,"The command is permitted only before machine initialization" ); -return ; - } -qemu_exit_preconfig_request (); -} -void qmp_cont (Error **errp) {BlockBackend *blk;softmmu/vl.c +41
-54@@ -1151,7 +1151,6 @@ static pid_t shutdown_pid;static int powerdown_requested;static int debug_requested;static int suspend_requested; -static bool preconfig_exit_requested = true;static WakeupReason wakeup_reason;static NotifierList powerdown_notifiers =NOTIFIER_LIST_INITIALIZER (powerdown_notifiers);@@ -1238,11 +1237,6 @@ static int qemu_debug_requested(void)return r; } -void qemu_exit_preconfig_request (void ) -{ - preconfig_exit_requested = true; -} -/* * Reset the VM. Issue an event unless @reason is SHUTDOWN_CAUSE_NONE. */ @@ -1464,10 +1458,6 @@ static bool main_loop_should_exit(void)RunState r;ShutdownCause request; -if (preconfig_exit_requested) { - preconfig_exit_requested = false; -return true; - }if (qemu_debug_requested ()) {vm_stop (RUN_STATE_DEBUG ); }@@ -3283,6 +3273,43 @@ static void qemu_machine_creation_done(void)register_global_state (); } +void qmp_x_exit_preconfig (Error **errp) +{ +if (qdev_hotplug) { +error_setg (errp,"The command is permitted only before machine initialization" ); +return ; + } + +qemu_init_board (); +qemu_create_cli_devices (); +qemu_machine_creation_done (); + +if (loadvm) { +Error *local_err =NULL ; +if (load_snapshot (loadvm, &local_err) <0 ) { +error_report_err (local_err); + autostart =0 ; +exit (1 ); + } + } +if (replay_mode !=REPLAY_MODE_NONE ) { +replay_vmstate_init (); + } + +if (incoming) { +Error *local_err =NULL ; +if (strcmp (incoming,"defer" ) !=0 ) { +qmp_migrate_incoming (incoming, &local_err); +if (local_err) { +error_reportf_err (local_err,"-incoming %s: " , incoming); +exit (1 ); + } + } + }else if (autostart) { +qmp_cont (NULL ); + } +} +void qemu_init (int argc,char **argv,char **envp) {QemuOpts *opts;@@ -3847,7 +3874,6 @@ void qemu_init(int argc, char **argv, char **envp) }break ;case QEMU_OPTION_preconfig: - preconfig_exit_requested = false; preconfig_requested = true;break ;case QEMU_OPTION_enable_kvm:@@ -4272,57 +4298,18 @@ void qemu_init(int argc, char **argv, char **envp)qemu_resolve_machine_memdev ();parse_numa_opts (current_machine); -if (preconfig_requested) { -qemu_init_displays (); - } - -/* do monitor/qmp handling at preconfig state if requested */ -qemu_main_loop (); - -qemu_init_board (); - -qemu_create_cli_devices (); - -/* initialize displays after all errors have been reported */ -if (!preconfig_requested) { -qemu_init_displays (); - } -qemu_machine_creation_done (); - -if (loadvm) { -Error *local_err =NULL ; -if (load_snapshot (loadvm, &local_err) <0 ) { -error_report_err (local_err); - autostart =0 ; -exit (1 ); - } - } -if (replay_mode !=REPLAY_MODE_NONE ) { -replay_vmstate_init (); - } -if (vmstate_dump_file) {/* dump and exit */ dump_vmstate_json_to_file (vmstate_dump_file);exit (0 ); } -if (incoming) { -Error *local_err =NULL ; -if (strcmp (incoming,"defer" ) !=0 ) { -qmp_migrate_incoming (incoming, &local_err); -if (local_err) { -error_reportf_err (local_err,"-incoming %s: " , incoming); -exit (1 ); - } - } - }else if (autostart) { -qmp_cont (NULL ); - } +qemu_init_displays (); +if (!preconfig_requested) { +qmp_x_exit_preconfig (&error_fatal); + }accel_setup_post (current_machine);os_setup_post (); - -return ; }void qemu_cleanup (void )
PATCH 3/15 vl: allow -incoming defer with -preconfig
In reply to Paolo BonziniNow that there is no RUN_STATE_PRECONFIG anymore that can conflict with RUN_STATE_INMIGRATE, we can allow -incoming defer with -preconfig.
--- softmmu/vl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
softmmu/vl.c +2 -3
@@ -2986,9 +2986,8 @@ static void qemu_validate_options(void) "mutually exclusive");exit (EXIT_FAILURE ); } -if (incoming && preconfig_requested) { -error_report ("'preconfig' and 'incoming' options are " -"mutually exclusive" ); +if (incoming && preconfig_requested &&strcmp (incoming,"defer" ) !=0 ) { +error_report ("'preconfig' supports '-incoming defer' only" );exit (EXIT_FAILURE ); }
Signature · 1 line
2.26.2
PATCH 4/15 vl: extract softmmu/runstate.c
In reply to Paolo Bonzini--- include/sysemu/sysemu.h | 3 + softmmu/meson.build | 1 + softmmu/runstate.c | 800 ++++++++++++++++++++++++++++++++++++++++ softmmu/vl.c | 752 +------------------------------------ 4 files changed, 805 insertions(+), 751 deletions(-) create mode 100644 softmmu/runstate.c
include/sysemu/sysemu.h +3 -0
@@ -24,6 +24,8 @@ void qemu_remove_machine_init_done_notifier(Notifier *notify);void configure_rtc (QemuOpts *opts); +void qemu_init_subsystems (void ); +extern int autostart; typedef enum {
@@ -44,6 +46,7 @@ extern int alt_grab;extern int ctrl_grab;extern int graphic_rotate;extern int no_shutdown; +extern int no_reboot;extern int old_param;extern int boot_menu;extern bool boot_strict;
softmmu/meson.build +1 -0
@@ -7,6 +7,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files( 'physmem.c', 'ioport.c', 'rtc.c', + 'runstate.c', 'memory.c', 'memory_mapping.c', 'qtest.c',
softmmu/runstate.c new file +800 -0
800 lines not on this page · raw message
softmmu/vl.c +1 -751
803 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 5/15 vl: extract softmmu/globals.c
In reply to Paolo Bonzini--- hw/core/machine.c | 2 ++ include/exec/cpu-common.h | 3 ++ include/exec/exec-all.h | 3 -- softmmu/globals.c | 74 +++++++++++++++++++++++++++++++++++++++ softmmu/meson.build | 1 + softmmu/vl.c | 45 ++---------------------- 6 files changed, 83 insertions(+), 45 deletions(-) create mode 100644 softmmu/globals.c
hw/core/machine.c +2 -0
@@ -213,6 +213,8 @@ GlobalProperty hw_compat_2_1[] = { };const size_t hw_compat_2_1_len =G_N_ELEMENTS (hw_compat_2_1); +MachineState *current_machine; +static char *machine_get_kernel (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);
include/exec/cpu-common.h +3 -0
@@ -105,4 +105,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length);#endif +/* vl.c */ +extern int singlestep; +#endif /* CPU_COMMON_H */
include/exec/exec-all.h +0 -3
@@ -676,7 +676,4 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, MemoryRegionSection *section);#endif -/* vl.c */ -extern int singlestep; -#endif
softmmu/globals.c new file +74 -0
74 lines not on this page · raw message
softmmu/meson.build +1 -0
@@ -4,6 +4,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files( 'cpus.c', 'cpu-throttle.c', 'datadir.c', + 'globals.c', 'physmem.c', 'ioport.c', 'rtc.c',
softmmu/vl.c +3 -42
81 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 6/15 vl: move all generic initialization out of vl.c
In reply to Paolo Bonziniqdev_machine_creation_done is only setting a flag now. Extend it to move more code out of vl.c. Leave only consistency checks and gdbserver processing in qemu_machine_creation_done.
gdbserver_start can be moved after qdev_machine_creation_done because it only does listen on the socket and creates some internal data structures; it does not send any data (e.g. guest state) over the socket.
--- hw/core/machine.c | 47 +++++++++++++++++++++++++++++++++++++++++- hw/core/qdev.c | 12 +++-------- include/hw/qdev-core.h | 1 + softmmu/vl.c | 37 +-------------------------------- 4 files changed, 51 insertions(+), 46 deletions(-)
hw/core/machine.c +46 -1
@@ -16,16 +16,21 @@#include "sysemu/replay.h" #include "qemu/units.h" #include "hw/boards.h" +#include "hw/loader.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" #include "qapi/visitor.h" #include "hw/sysbus.h" +#include "sysemu/cpus.h" #include "sysemu/sysemu.h" +#include "sysemu/reset.h" +#include "sysemu/runstate.h" #include "sysemu/numa.h" #include "qemu/error-report.h" #include "sysemu/qtest.h" #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" +#include "migration/global_state.h" #include "migration/vmstate.h" GlobalProperty hw_compat_5_1[] = {
@@ -1186,10 +1191,50 @@ void qemu_remove_machine_init_done_notifier(Notifier *notify)notifier_remove (notify); } -void qemu_run_machine_init_done_notifiers (void ) +void qdev_machine_creation_done (void ) { +cpu_synchronize_all_post_init (); + +if (current_machine->boot_once) { +qemu_boot_set (current_machine->boot_once, &error_fatal); +qemu_register_reset (restore_boot_order,g_strdup (current_machine->boot_order)); + } + +/* +* ok, initial machine setup is done, starting from now we can +* only create hotpluggable devices +*/ + qdev_hotplug = true; +qdev_assert_realized_properly (); + +/* TODO: once all bus devices are qdevified, this should be done +* when bus is created by qdev.c */ +/* +* TODO: If we had a main 'reset container' that the whole system +* lived in, we could reset that using the multi-phase reset +* APIs. For the moment, we just reset the sysbus, which will cause +* all devices hanging off it (and all their child buses, recursively) +* to be reset. Note that this will *not* reset any Device objects +* which are not attached to some part of the qbus tree! +*/ +qemu_register_reset (resettable_cold_reset_fn,sysbus_get_default ()); + machine_init_done = true;notifier_list_notify (&machine_init_done_notifiers,NULL ); + +if (rom_check_and_register_reset () !=0 ) { +error_report ("rom check and register reset failed" ); +exit (1 ); + } + +replay_start (); + +/* This checkpoint is required by replay to separate prior clock +reading from the other reads, because timer polling functions query +clock values from the log. */ +replay_checkpoint (CHECKPOINT_RESET ); +qemu_system_reset (SHUTDOWN_CAUSE_NONE ); +register_global_state (); }static const TypeInfo machine_info = {
hw/core/qdev.c +3 -9
@@ -413,7 +413,7 @@ void qdev_unrealize(DeviceState *dev)object_property_set_bool (OBJECT (dev),"realized" , false, &error_abort); } -static int qdev_assert_realized_properly (Object *obj,void *opaque) +static int qdev_assert_realized_properly_cb (Object *obj,void *opaque) {DeviceState *dev =DEVICE (object_dynamic_cast (obj,TYPE_DEVICE ));DeviceClass *dc;
@@ -426,16 +426,10 @@ static int qdev_assert_realized_properly(Object *obj, void *opaque)return 0 ; } -void qdev_machine_creation_done (void ) +void qdev_assert_realized_properly (void ) { -/* -* ok, initial machine setup is done, starting from now we can -* only create hotpluggable devices -*/ - qdev_hotplug = true; -object_child_foreach_recursive (object_get_root (), - qdev_assert_realized_properly,NULL ); + qdev_assert_realized_properly_cb,NULL ); }bool qdev_machine_modified (void )
include/hw/qdev-core.h +1 -0
@@ -815,6 +815,7 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev);const char *qdev_fw_name (DeviceState *dev); +void qdev_assert_realized_properly (void );Object *qdev_get_machine (void );/* FIXME: make this a link<> */
softmmu/vl.c +1 -36
@@ -72,7 +72,6 @@#include "hw/i386/pc.h" #include "migration/misc.h" #include "migration/snapshot.h" -#include "migration/global_state.h" #include "sysemu/tpm.h" #include "sysemu/dma.h" #include "hw/audio/soundhw.h"
@@ -2465,8 +2464,6 @@ static void qemu_create_cli_devices(void)static void qemu_machine_creation_done (void ) { -cpu_synchronize_all_post_init (); -/* Did we create any drives that we failed to create a device for? */ drive_check_orphaned ();
@@ -2484,43 +2481,11 @@ static void qemu_machine_creation_done(void)qdev_prop_check_globals (); -if (current_machine->boot_once) { -qemu_boot_set (current_machine->boot_once, &error_fatal); -qemu_register_reset (restore_boot_order,g_strdup (current_machine->boot_order)); - } - -if (foreach_device_config (DEV_GDB , gdbserver_start) <0 ) { -exit (1 ); - } -qdev_machine_creation_done (); -/* TODO: once all bus devices are qdevified, this should be done -* when bus is created by qdev.c */ -/* -* TODO: If we had a main 'reset container' that the whole system -* lived in, we could reset that using the multi-phase reset -* APIs. For the moment, we just reset the sysbus, which will cause -* all devices hanging off it (and all their child buses, recursively) -* to be reset. Note that this will *not* reset any Device objects -* which are not attached to some part of the qbus tree! -*/ -qemu_register_reset (resettable_cold_reset_fn,sysbus_get_default ()); -qemu_run_machine_init_done_notifiers (); - -if (rom_check_and_register_reset () !=0 ) { -error_report ("rom check and register reset failed" ); +if (foreach_device_config (DEV_GDB , gdbserver_start) <0 ) {exit (1 ); } - -replay_start (); - -/* This checkpoint is required by replay to separate prior clock -reading from the other reads, because timer polling functions query -clock values from the log. */ -replay_checkpoint (CHECKPOINT_RESET ); -qemu_system_reset (SHUTDOWN_CAUSE_NONE ); -register_global_state (); }void qmp_x_exit_preconfig (Error **errp)
Signature · 1 line
2.26.2
Re: [PATCH 06/15] vl: move all generic initialization out of vl.c
Quoted 9 lines · On Wed, 2 Dec 2020 03:18:45 -0500 Paolo Bonzini <[email protected]> wrote:
qdev_machine_creation_doneis only setting a flag now. Extend it to move more code out ofvl.c. Leave only consistency checks and gdbserver processing inqemu_machine_creation_done.
gdbserver_startcan be moved afterqdev_machine_creation_donebecause it only does listen on the socket and creates some internal data structures; it does not send any data (e.g. guest state) over the socket.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 195 lines
--- hw/core/machine.c | 47 +++++++++++++++++++++++++++++++++++++++++- hw/core/qdev.c | 12 +++-------- include/hw/qdev-core.h | 1 + softmmu/vl.c | 37 +-------------------------------- 4 files changed, 51 insertions(+), 46 deletions(-)hw/core/machine.c +46
-1@@ -16,16 +16,21 @@#include "sysemu/replay.h" #include "qemu/units.h" #include "hw/boards.h" +#include "hw/loader.h" #include "qapi/error.h" #include "qapi/qapi-visit-common.h" #include "qapi/visitor.h" #include "hw/sysbus.h" +#include "sysemu/cpus.h" #include "sysemu/sysemu.h" +#include "sysemu/reset.h" +#include "sysemu/runstate.h" #include "sysemu/numa.h" #include "qemu/error-report.h" #include "sysemu/qtest.h" #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" +#include "migration/global_state.h" #include "migration/vmstate.h" GlobalProperty hw_compat_5_1[] = {@@ -1186,10 +1191,50 @@ void qemu_remove_machine_init_done_notifier(Notifier *notify)notifier_remove (notify); } -void qemu_run_machine_init_done_notifiers (void ) +void qdev_machine_creation_done (void ) { +cpu_synchronize_all_post_init (); + +if (current_machine->boot_once) { +qemu_boot_set (current_machine->boot_once, &error_fatal); +qemu_register_reset (restore_boot_order,g_strdup (current_machine->boot_order)); + } + +/* +* ok, initial machine setup is done, starting from now we can +* only create hotpluggable devices +*/ + qdev_hotplug = true; +qdev_assert_realized_properly (); + +/* TODO: once all bus devices are qdevified, this should be done +* when bus is created by qdev.c */ +/* +* TODO: If we had a main 'reset container' that the whole system +* lived in, we could reset that using the multi-phase reset +* APIs. For the moment, we just reset the sysbus, which will cause +* all devices hanging off it (and all their child buses, recursively) +* to be reset. Note that this will *not* reset any Device objects +* which are not attached to some part of the qbus tree! +*/ +qemu_register_reset (resettable_cold_reset_fn,sysbus_get_default ()); + machine_init_done = true;notifier_list_notify (&machine_init_done_notifiers,NULL ); + +if (rom_check_and_register_reset () !=0 ) { +error_report ("rom check and register reset failed" ); +exit (1 ); + } + +replay_start (); + +/* This checkpoint is required by replay to separate prior clock +reading from the other reads, because timer polling functions query +clock values from the log. */ +replay_checkpoint (CHECKPOINT_RESET ); +qemu_system_reset (SHUTDOWN_CAUSE_NONE ); +register_global_state (); }static const TypeInfo machine_info = {hw/core/qdev.c +3
-9@@ -413,7 +413,7 @@ void qdev_unrealize(DeviceState *dev)object_property_set_bool (OBJECT (dev),"realized" , false, &error_abort); } -static int qdev_assert_realized_properly (Object *obj,void *opaque) +static int qdev_assert_realized_properly_cb (Object *obj,void *opaque) {DeviceState *dev =DEVICE (object_dynamic_cast (obj,TYPE_DEVICE ));DeviceClass *dc;@@ -426,16 +426,10 @@ static int qdev_assert_realized_properly(Object *obj, void *opaque)return 0 ; } -void qdev_machine_creation_done (void ) +void qdev_assert_realized_properly (void ) { -/* -* ok, initial machine setup is done, starting from now we can -* only create hotpluggable devices -*/ - qdev_hotplug = true; -object_child_foreach_recursive (object_get_root (), - qdev_assert_realized_properly,NULL ); + qdev_assert_realized_properly_cb,NULL ); }bool qdev_machine_modified (void )include/hw/qdev-core.h +1
-0@@ -815,6 +815,7 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev);const char *qdev_fw_name (DeviceState *dev); +void qdev_assert_realized_properly (void );Object *qdev_get_machine (void );/* FIXME: make this a link<> */ softmmu/vl.c +1
-36@@ -72,7 +72,6 @@#include "hw/i386/pc.h" #include "migration/misc.h" #include "migration/snapshot.h" -#include "migration/global_state.h" #include "sysemu/tpm.h" #include "sysemu/dma.h" #include "hw/audio/soundhw.h" @@ -2465,8 +2464,6 @@ static void qemu_create_cli_devices(void)static void qemu_machine_creation_done (void ) { -cpu_synchronize_all_post_init (); -/* Did we create any drives that we failed to create a device for? */ drive_check_orphaned ();@@ -2484,43 +2481,11 @@ static void qemu_machine_creation_done(void)qdev_prop_check_globals (); -if (current_machine->boot_once) { -qemu_boot_set (current_machine->boot_once, &error_fatal); -qemu_register_reset (restore_boot_order,g_strdup (current_machine->boot_order)); - } - -if (foreach_device_config (DEV_GDB , gdbserver_start) <0 ) { -exit (1 ); - } -qdev_machine_creation_done (); -/* TODO: once all bus devices are qdevified, this should be done -* when bus is created by qdev.c */ -/* -* TODO: If we had a main 'reset container' that the whole system -* lived in, we could reset that using the multi-phase reset -* APIs. For the moment, we just reset the sysbus, which will cause -* all devices hanging off it (and all their child buses, recursively) -* to be reset. Note that this will *not* reset any Device objects -* which are not attached to some part of the qbus tree! -*/ -qemu_register_reset (resettable_cold_reset_fn,sysbus_get_default ()); -qemu_run_machine_init_done_notifiers (); - -if (rom_check_and_register_reset () !=0 ) { -error_report ("rom check and register reset failed" ); +if (foreach_device_config (DEV_GDB , gdbserver_start) <0 ) {exit (1 ); } - -replay_start (); - -/* This checkpoint is required by replay to separate prior clock -reading from the other reads, because timer polling functions query -clock values from the log. */ -replay_checkpoint (CHECKPOINT_RESET ); -qemu_system_reset (SHUTDOWN_CAUSE_NONE ); -register_global_state (); }void qmp_x_exit_preconfig (Error **errp)
PATCH 7/15 chardev: do not use machine_init_done
In reply to Paolo Bonzinimachine_init_done is not the right flag to check when preconfig is taken into account; for example "./qemu-system-x86_64 -serial mon:stdio -preconfig" does not print the QEMU monitor header until after exit_preconfig. Add back a custom bool for mux character devices. This partially undoes commit c7278b4355 ("chardev: introduce chr_machine_done hook", 2018-03-12), cut keeps the cleaner logic using a function pointer in ChardevClass.
--- chardev/char-mux.c | 38 ++++++++++++++++++--- chardev/chardev-sysemu.c | 69 --------------------------------------- chardev/meson.build | 2 +- hw/core/machine.c | 2 +- include/chardev/char.h | 6 ++-- include/sysemu/sysemu.h | 2 -- softmmu/vl.c | 3 ++ stubs/machine-init-done.c | 8 ----- stubs/meson.build | 1 - 9 files changed, 43 insertions(+), 88 deletions(-) delete mode 100644 chardev/chardev-sysemu.c delete mode 100644 stubs/machine-init-done.c
chardev/char-mux.c +34 -4
@@ -33,6 +33,13 @@/* MUX driver for serial I/O splitting */ +/* +* Set to false by suspend_mux_open. Open events are delayed until +* resume_mux_open. Usually suspend_mux_open is called before +* command line processing and resume_mux_open afterwards. +*/ +static bool muxes_opened = true; +/* Called with chr_write_lock held. */ static int mux_chr_write (Chardev *chr,const uint8_t *buf,int len) {
@@ -237,7 +244,7 @@ void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event)MuxChardev *d =MUX_CHARDEV (chr);int i; -if (!machine_init_done) { +if (!muxes_opened) {return ; }
@@ -328,7 +335,7 @@ static void qemu_chr_open_mux(Chardev *chr,/* only default to opened state if we've realized the initial * set of muxes */ - *be_opened = machine_init_done; + *be_opened = muxes_opened;qemu_chr_fe_init (&d->chr, drv, errp); }
@@ -360,19 +367,42 @@ static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend,* mux will receive CHR_EVENT_OPENED notifications for the BE * immediately. */ -static int open_muxes (Chardev *chr) +static void open_muxes (Chardev *chr) {/* send OPENED to all already-attached FEs */ mux_chr_send_all_event (chr,CHR_EVENT_OPENED ); +/* * mark mux as OPENED so any new FEs will immediately receive * OPENED event */ chr->be_open =1 ; +} + +void suspend_mux_open (void ) +{ + muxes_opened = false; +} + +static int chardev_options_parsed_cb (Object *child,void *opaque) +{ +Chardev *chr = (Chardev *)child; +ChardevClass *class =CHARDEV_GET_CLASS (chr); + +if (!chr->be_open && class->chr_options_parsed) { + class->chr_options_parsed (chr); + }return 0 ; } +void resume_mux_open (void ) +{ + muxes_opened = true; +object_child_foreach (get_chardevs_root (), + chardev_options_parsed_cb,NULL ); +} +static void char_mux_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc);
@@ -383,7 +413,7 @@ static void char_mux_class_init(ObjectClass *oc, void *data) cc->chr_accept_input = mux_chr_accept_input; cc->chr_add_watch = mux_chr_add_watch; cc->chr_be_event = mux_chr_be_event; - cc->chr_machine_done = open_muxes; + cc->chr_options_parsed = open_muxes; cc->chr_update_read_handler = mux_chr_update_read_handlers; }
chardev/chardev-sysemu.c deleted +0 -69
69 lines not on this page · raw message
chardev/meson.build +1 -1
@@ -25,7 +25,7 @@ chardev_ss.add(when: 'CONFIG_WIN32', if_true: files( chardev_ss = chardev_ss.apply(config_host, strict: false) -softmmu_ss.add(files('chardev-sysemu.c', 'msmouse.c', 'wctablet.c', 'testdev.c')) +softmmu_ss.add(files('msmouse.c', 'wctablet.c', 'testdev.c')) chardev_modules = {}
hw/core/machine.c +1 -1
@@ -1176,7 +1176,7 @@ void machine_run_board_init(MachineState *machine)static NotifierList machine_init_done_notifiers =NOTIFIER_LIST_INITIALIZER (machine_init_done_notifiers); -bool machine_init_done; +static bool machine_init_done;void qemu_add_machine_init_done_notifier (Notifier *notify) {
include/chardev/char.h +4 -2
@@ -270,8 +270,7 @@ struct ChardevClass {void (*chr_set_echo)(Chardev *chr,bool echo);void (*chr_set_fe_open)(Chardev *chr,int fe_open);void (*chr_be_event)(Chardev *s,QEMUChrEvent event); -/* Return 0 if succeeded, 1 if failed */ -int (*chr_machine_done)(Chardev *chr); +void (*chr_options_parsed)(Chardev *chr); }; Chardev *qemu_chardev_new(const char *id, const char *typename,
@@ -283,6 +282,9 @@ extern int term_escape_char;GSource *qemu_chr_timeout_add_ms (Chardev *chr,guint ms,GSourceFunc func,void *private); +void suspend_mux_open (void ); +void resume_mux_open (void ); +/* console.c */ void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp);
include/sysemu/sysemu.h +0 -2
@@ -16,8 +16,6 @@ extern bool qemu_uuid_set;void qemu_add_exit_notifier (Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify); -extern bool machine_init_done; -void qemu_run_machine_init_done_notifiers (void );void qemu_add_machine_init_done_notifier (Notifier *notify);void qemu_remove_machine_init_done_notifier (Notifier *notify);
softmmu/vl.c +3 -0
@@ -3462,6 +3462,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_create_machine (select_machine ()); +suspend_mux_open (); +qemu_disable_default_devices ();qemu_create_default_devices ();qemu_create_early_backends ();
@@ -3525,4 +3527,5 @@ void qemu_init(int argc, char **argv, char **envp) }accel_setup_post (current_machine);os_setup_post (); +resume_mux_open (); }
stubs/machine-init-done.c deleted +0 -8
@@ -1,8 +0,0 @@ -#include "qemu/osdep.h" -#include "sysemu/sysemu.h" - -bool machine_init_done = true; - -void qemu_add_machine_init_done_notifier (Notifier *notify) -{ -}
stubs/meson.build +0 -1
@@ -21,7 +21,6 @@ stub_ss.add(files('iothread-lock.c')) stub_ss.add(files('isa-bus.c')) stub_ss.add(files('is-daemonized.c')) stub_ss.add(when: 'CONFIG_LINUX_AIO', if_true: files('linux-aio.c')) -stub_ss.add(files('machine-init-done.c')) stub_ss.add(files('migr-blocker.c')) stub_ss.add(files('monitor.c')) stub_ss.add(files('monitor-core.c'))
Signature · 1 line
2.26.2
Re: [PATCH 07/15] chardev: do not use machine_init_done
Quoted 6 lines · On Wed, 2 Dec 2020 03:18:46 -0500 Paolo Bonzini <[email protected]> wrote:
machine_init_doneis not the right flag to check when preconfig is taken into account; for example "./qemu-system-x86_64 -serial mon:stdio -preconfig" does not print the QEMU monitor header until afterexit_preconfig. Add back a custom bool for mux character devices. This partially undoes commitc7278b4355("chardev: introducechr_machine_donehook", 2018-03-12), cut keeps the cleaner logic using a function pointer
^^^
did you mean
s/cut/but/
Quoted 1 line
in ChardevClass.
Quoted 287 lines
Signed-off-by Paolo Bonzini <[email protected]>--- chardev/char-mux.c | 38 ++++++++++++++++++--- chardev/chardev-sysemu.c | 69 --------------------------------------- chardev/meson.build | 2 +- hw/core/machine.c | 2 +- include/chardev/char.h | 6 ++-- include/sysemu/sysemu.h | 2 -- softmmu/vl.c | 3 ++ stubs/machine-init-done.c | 8 ----- stubs/meson.build | 1 - 9 files changed, 43 insertions(+), 88 deletions(-) delete mode 100644 chardev/chardev-sysemu.c delete mode 100644 stubs/machine-init-done.cchardev/char-mux.c +34
-4@@ -33,6 +33,13 @@/* MUX driver for serial I/O splitting */ +/* +* Set to false by suspend_mux_open. Open events are delayed until +* resume_mux_open. Usually suspend_mux_open is called before +* command line processing and resume_mux_open afterwards. +*/ +static bool muxes_opened = true; +/* Called with chr_write_lock held. */ static int mux_chr_write (Chardev *chr,const uint8_t *buf,int len) {@@ -237,7 +244,7 @@ void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event)MuxChardev *d =MUX_CHARDEV (chr);int i; -if (!machine_init_done) { +if (!muxes_opened) {return ; }@@ -328,7 +335,7 @@ static void qemu_chr_open_mux(Chardev *chr,/* only default to opened state if we've realized the initial * set of muxes */ - *be_opened = machine_init_done; + *be_opened = muxes_opened;qemu_chr_fe_init (&d->chr, drv, errp); }@@ -360,19 +367,42 @@ static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend,* mux will receive CHR_EVENT_OPENED notifications for the BE * immediately. */ -static int open_muxes (Chardev *chr) +static void open_muxes (Chardev *chr) {/* send OPENED to all already-attached FEs */ mux_chr_send_all_event (chr,CHR_EVENT_OPENED ); +/* * mark mux as OPENED so any new FEs will immediately receive * OPENED event */ chr->be_open =1 ; +} + +void suspend_mux_open (void ) +{ + muxes_opened = false; +} + +static int chardev_options_parsed_cb (Object *child,void *opaque) +{ +Chardev *chr = (Chardev *)child; +ChardevClass *class =CHARDEV_GET_CLASS (chr); + +if (!chr->be_open && class->chr_options_parsed) { + class->chr_options_parsed (chr); + }return 0 ; } +void resume_mux_open (void ) +{ + muxes_opened = true; +object_child_foreach (get_chardevs_root (), + chardev_options_parsed_cb,NULL ); +} +static void char_mux_class_init (ObjectClass *oc,void *data) {ChardevClass *cc =CHARDEV_CLASS (oc);@@ -383,7 +413,7 @@ static void char_mux_class_init(ObjectClass *oc, void *data) cc->chr_accept_input = mux_chr_accept_input; cc->chr_add_watch = mux_chr_add_watch; cc->chr_be_event = mux_chr_be_event; - cc->chr_machine_done = open_muxes; + cc->chr_options_parsed = open_muxes; cc->chr_update_read_handler = mux_chr_update_read_handlers; }chardev/chardev-sysemu.c deleted +0
-69@@ -1,69 +0,0 @@ -/* -* QEMU System Emulator -* -* Copyright (c) 2003-2008 Fabrice Bellard -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include "qemu/osdep.h" -#include "sysemu/sysemu.h" -#include "chardev/char.h" -#include "qemu/error-report.h" -#include "chardev-internal.h" - -static int chardev_machine_done_notify_one (Object *child,void *opaque) -{ -Chardev *chr = (Chardev *)child; -ChardevClass *class =CHARDEV_GET_CLASS (chr); - -if (class->chr_machine_done) { -return class->chr_machine_done (chr); - } - -return 0 ; -} - -static void chardev_machine_done_hook (Notifier *notifier,void *unused) -{ -int ret =object_child_foreach (get_chardevs_root (), - chardev_machine_done_notify_one,NULL ); - -if (ret) { -error_report ("Failed to call chardev machine_done hooks" ); -exit (1 ); - } -} - - -static Notifier chardev_machine_done_notify = { - .notify = chardev_machine_done_hook, -}; - -static void register_types (void ) -{ -/* -* This must be done after machine init, since we register FEs with muxes -* as part of realize functions like serial_isa_realizefn when -nographic -* is specified. -*/ -qemu_add_machine_init_done_notifier (&chardev_machine_done_notify); -} - -type_init (register_types);chardev/meson.build +1
-1@@ -25,7 +25,7 @@ chardev_ss.add(when: 'CONFIG_WIN32', if_true: files( chardev_ss = chardev_ss.apply(config_host, strict: false) -softmmu_ss.add(files('chardev-sysemu.c', 'msmouse.c', 'wctablet.c', 'testdev.c')) +softmmu_ss.add(files('msmouse.c', 'wctablet.c', 'testdev.c')) chardev_modules = {}hw/core/machine.c +1
-1@@ -1176,7 +1176,7 @@ void machine_run_board_init(MachineState *machine)static NotifierList machine_init_done_notifiers =NOTIFIER_LIST_INITIALIZER (machine_init_done_notifiers); -bool machine_init_done; +static bool machine_init_done;void qemu_add_machine_init_done_notifier (Notifier *notify) {include/chardev/char.h +4
-2@@ -270,8 +270,7 @@ struct ChardevClass {void (*chr_set_echo)(Chardev *chr,bool echo);void (*chr_set_fe_open)(Chardev *chr,int fe_open);void (*chr_be_event)(Chardev *s,QEMUChrEvent event); -/* Return 0 if succeeded, 1 if failed */ -int (*chr_machine_done)(Chardev *chr); +void (*chr_options_parsed)(Chardev *chr); }; Chardev *qemu_chardev_new(const char *id, const char *typename,@@ -283,6 +282,9 @@ extern int term_escape_char;GSource *qemu_chr_timeout_add_ms (Chardev *chr,guint ms,GSourceFunc func,void *private); +void suspend_mux_open (void ); +void resume_mux_open (void ); +/* console.c */ void qemu_chr_parse_vc (QemuOpts *opts,ChardevBackend *backend,Error **errp);include/sysemu/sysemu.h +0
-2@@ -16,8 +16,6 @@ extern bool qemu_uuid_set;void qemu_add_exit_notifier (Notifier *notify);void qemu_remove_exit_notifier (Notifier *notify); -extern bool machine_init_done; -void qemu_run_machine_init_done_notifiers (void );void qemu_add_machine_init_done_notifier (Notifier *notify);void qemu_remove_machine_init_done_notifier (Notifier *notify);softmmu/vl.c +3
-0@@ -3462,6 +3462,8 @@ void qemu_init(int argc, char **argv, char **envp)qemu_create_machine (select_machine ()); +suspend_mux_open (); +qemu_disable_default_devices ();qemu_create_default_devices ();qemu_create_early_backends ();@@ -3525,4 +3527,5 @@ void qemu_init(int argc, char **argv, char **envp) }accel_setup_post (current_machine);os_setup_post (); +resume_mux_open (); }stubs/machine-init-done.c deleted +0
-8@@ -1,8 +0,0 @@ -#include "qemu/osdep.h" -#include "sysemu/sysemu.h" - -bool machine_init_done = true; - -void qemu_add_machine_init_done_notifier (Notifier *notify) -{ -}stubs/meson.build +0
-1@@ -21,7 +21,6 @@ stub_ss.add(files('iothread-lock.c')) stub_ss.add(files('isa-bus.c')) stub_ss.add(files('is-daemonized.c')) stub_ss.add(when: 'CONFIG_LINUX_AIO', if_true: files('linux-aio.c')) -stub_ss.add(files('machine-init-done.c')) stub_ss.add(files('migr-blocker.c')) stub_ss.add(files('monitor.c')) stub_ss.add(files('monitor-core.c'))
PATCH 8/15 machine: introduce MachineInitPhase
In reply to Paolo BonziniGeneralize the qdev_hotplug variable to the different phases of machine initialization. We would like to allow different monitor commands depending on the phase.
--- hw/core/machine-qmp-cmds.c | 6 +++--- hw/core/machine.c | 8 +++----- hw/core/qdev.c | 16 ++++++++++++++-- hw/pci/pci.c | 2 +- hw/usb/core.c | 2 +- hw/virtio/virtio-iommu.c | 2 +- include/hw/qdev-core.h | 32 +++++++++++++++++++++++++++++++- monitor/hmp.c | 2 +- softmmu/qdev-monitor.c | 24 +++++++++++++----------- softmmu/vl.c | 9 ++++----- ui/console.c | 2 +- 11 files changed, 73 insertions(+), 32 deletions(-)
hw/core/machine-qmp-cmds.c +3 -3
@@ -286,9 +286,9 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)void qmp_set_numa_node (NumaOptions *cmd,Error **errp) { -if (qdev_hotplug) { -error_setg (errp,"The command is permitted only before the machine has been created" ); -return ; +if (phase_check (PHASE_MACHINE_INITIALIZED )) { +error_setg (errp,"The command is permitted only before the machine has been created" ); +return ; }set_numa_options (MACHINE (qdev_get_machine ()), cmd, errp);
hw/core/machine.c +3 -5
@@ -1171,17 +1171,16 @@ void machine_run_board_init(MachineState *machine) } machine_class->init (machine); +phase_advance (PHASE_MACHINE_INITIALIZED ); }static NotifierList machine_init_done_notifiers =NOTIFIER_LIST_INITIALIZER (machine_init_done_notifiers); -static bool machine_init_done; -void qemu_add_machine_init_done_notifier (Notifier *notify) {notifier_list_add (&machine_init_done_notifiers, notify); -if (machine_init_done) { +if (phase_check (PHASE_MACHINE_READY )) { notify->notify (notify,NULL ); } }
@@ -1204,7 +1203,7 @@ void qdev_machine_creation_done(void)* ok, initial machine setup is done, starting from now we can * only create hotpluggable devices */ - qdev_hotplug = true; +phase_advance (PHASE_MACHINE_READY );qdev_assert_realized_properly ();/* TODO: once all bus devices are qdevified, this should be done
@@ -1219,7 +1218,6 @@ void qdev_machine_creation_done(void)*/ qemu_register_reset (resettable_cold_reset_fn,sysbus_get_default ()); - machine_init_done = true;notifier_list_notify (&machine_init_done_notifiers,NULL );if (rom_check_and_register_reset () !=0 ) {
hw/core/qdev.c +14 -2
@@ -41,7 +41,6 @@#include "migration/vmstate.h" #include "trace.h" -bool qdev_hotplug = false;static bool qdev_hot_added = false;bool qdev_hot_removed = false;
@@ -1023,7 +1022,7 @@ static void device_initfn(Object *obj) {DeviceState *dev =DEVICE (obj); -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_READY )) { dev->hotplugged =1 ; qdev_hot_added = true; }
@@ -1267,6 +1266,19 @@ Object *qdev_get_machine(void)return dev; } +static MachineInitPhase machine_phase; + +bool phase_check (MachineInitPhase phase) +{ +return machine_phase >= phase; +} + +void phase_advance (MachineInitPhase phase) +{ +assert (machine_phase == phase -1 ); + machine_phase = phase; +} +static const TypeInfo device_type_info = { .name =TYPE_DEVICE , .parent =TYPE_OBJECT ,
hw/pci/pci.c +1 -1
@@ -1062,7 +1062,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_container_region, pci_dev->name); -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_READY )) {pci_init_bus_master (pci_dev); } pci_dev->irq_state =0 ;
hw/usb/core.c +1 -1
@@ -97,7 +97,7 @@ void usb_wakeup(USBEndpoint *ep, unsigned int stream)USBDevice *dev = ep->dev;USBBus *bus =usb_bus_from_device (dev); -if (!qdev_hotplug) { +if (!phase_check (PHASE_MACHINE_READY )) {/* * This is machine init cold plug. No need to wakeup anyone, * all devices will be reset anyway. And trying to wakeup can
hw/virtio/virtio-iommu.c +1 -1
@@ -928,7 +928,7 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr,* accept it. Having a different masks is possible but the guest will use * sub-optimal block sizes, so warn about it. */ -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_READY )) {int new_granule =ctz64 (new_mask);int cur_granule =ctz64 (cur_mask);
include/hw/qdev-core.h +31 -1
@@ -821,7 +821,6 @@ Object *qdev_get_machine(void);/* FIXME: make this a link<> */ bool qdev_set_parent_bus (DeviceState *dev,BusState *bus,Error **errp); -extern bool qdev_hotplug;extern bool qdev_hot_removed;char *qdev_get_dev_path (DeviceState *dev);
@@ -847,4 +846,35 @@ void device_listener_unregister(DeviceListener *listener);*/ bool qdev_should_hide_device (QemuOpts *opts); +typedef enum MachineInitPhase { +/* current_machine is NULL. */ +PHASE_NO_MACHINE , + +/* current_machine is not NULL, but current_machine->accel is NULL. */ +PHASE_MACHINE_CREATED , + +/* +* current_machine->accel is not NULL, but the machine properties have +* not been validated and machine_class->init has not yet been called. +*/ +PHASE_ACCEL_CREATED , + +/* +* machine_class->init has been called, thus creating any embedded +* devices and validating machine properties. Devices created at +* this time are considered to be cold-plugged. +*/ +PHASE_MACHINE_INITIALIZED , + +/* +* QEMU is ready to start CPUs and devices created at this time +* are considered to be hot-plugged. The monitor is not restricted +* to "preconfig" commands. +*/ +PHASE_MACHINE_READY , +}MachineInitPhase ; + +extern bool phase_check (MachineInitPhase phase); +extern void phase_advance (MachineInitPhase phase); +#endif
monitor/hmp.c +1 -1
@@ -216,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)static bool cmd_available (const HMPCommand *cmd) { -return qdev_hotplug ||cmd_can_preconfig (cmd); +return phase_check (PHASE_MACHINE_READY ) ||cmd_can_preconfig (cmd); } static void help_cmd_dump_one(Monitor *mon,
softmmu/qdev-monitor.c +13 -11
@@ -244,7 +244,7 @@ static DeviceClass *qdev_get_device_class(const char **driver, Error **errp) dc =DEVICE_CLASS (oc);if (!dc->user_creatable || - (qdev_hotplug && !dc->hotpluggable)) { + (phase_check (PHASE_MACHINE_READY ) && !dc->hotpluggable)) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"driver" ,"pluggable device type" );return NULL ;
@@ -637,7 +637,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) } hide =should_hide_device (opts); -if ((hide || qdev_hotplug) && bus && !qbus_is_hotpluggable (bus)) { +if ((hide ||phase_check (PHASE_MACHINE_READY )) && bus && !qbus_is_hotpluggable (bus)) {error_setg (errp,QERR_BUS_NO_HOTPLUG , bus->name);return NULL ; }
@@ -655,15 +655,17 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) dev =qdev_new (driver);/* Check whether the hotplug is allowed by the machine */ -if (qdev_hotplug && !qdev_hotplug_allowed (dev, errp)) { - goto err_del_dev; - } +if (phase_check (PHASE_MACHINE_READY )) { +if (!qdev_hotplug_allowed (dev, errp)) { + goto err_del_dev; + } -if (!bus && qdev_hotplug && !qdev_get_machine_hotplug_handler (dev)) { -/* No bus, no machine hotplug handler --> device is not hotpluggable */ -error_setg (errp,"Device '%s' can not be hotplugged on this machine" , - driver); - goto err_del_dev; +if (!bus && !qdev_get_machine_hotplug_handler (dev)) { +/* No bus, no machine hotplug handler --> device is not hotpluggable */ +error_setg (errp,"Device '%s' can not be hotplugged on this machine" , + driver); + goto err_del_dev; + } }qdev_set_id (dev,qemu_opts_id (opts));
@@ -1001,7 +1003,7 @@ int qemu_global_option(const char *str)bool qmp_command_available (const QmpCommand *cmd,Error **errp) { -if (!qdev_hotplug && +if (!phase_check (PHASE_MACHINE_READY ) && !(cmd->options &QCO_ALLOW_PRECONFIG )) {error_setg (errp,"The command '%s' is permitted only after machine initialization has completed" , cmd->name);
softmmu/vl.c +4 -5
@@ -2406,10 +2406,6 @@ static void qemu_init_displays(void) } } -/* -* Called after leaving preconfig state. From here on runstate is -* RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE. -*/ static void qemu_init_board (void ) {MachineClass *machine_class =MACHINE_GET_CLASS (current_machine);
@@ -2424,6 +2420,7 @@ static void qemu_init_board(void)exit (1 ); } +/* From here on we enter MACHINE_PHASE_INITIALIZED. */ machine_run_board_init (current_machine);/*
@@ -2490,7 +2487,7 @@ static void qemu_machine_creation_done(void)void qmp_x_exit_preconfig (Error **errp) { -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_INITIALIZED )) {error_setg (errp,"The command is permitted only before machine initialization" );return ; }
@@ -3469,12 +3466,14 @@ void qemu_init(int argc, char **argv, char **envp)qemu_create_early_backends ();qemu_apply_machine_options (); +phase_advance (PHASE_MACHINE_CREATED );/* * Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ configure_accelerators (argv[0 ]); +phase_advance (PHASE_ACCEL_CREATED );/* * Beware, QOM objects created before this point miss global and
ui/console.c +1 -1
@@ -1345,7 +1345,7 @@ static QemuConsole *new_console(DisplayState *ds, console_type_t console_type,if (QTAILQ_EMPTY (&consoles)) { s->index =0 ;QTAILQ_INSERT_TAIL (&consoles, s, next); - }else if (console_type !=GRAPHIC_CONSOLE || qdev_hotplug) { + }else if (console_type !=GRAPHIC_CONSOLE ||phase_check (PHASE_MACHINE_READY )) {QemuConsole *last =QTAILQ_LAST (&consoles); s->index = last->index +1 ;QTAILQ_INSERT_TAIL (&consoles, s, next);
Signature · 1 line
2.26.2
Re: [PATCH 08/15] machine: introduce MachineInitPhase
Quoted 5 lines · On Wed, 2 Dec 2020 03:18:47 -0500 Paolo Bonzini <[email protected]> wrote:
Generalize the
qdev_hotplugvariable to the different phases of machine initialization. We would like to allow different monitor commands depending on the phase.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 330 lines
--- hw/core/machine-qmp-cmds.c | 6 +++--- hw/core/machine.c | 8 +++----- hw/core/qdev.c | 16 ++++++++++++++-- hw/pci/pci.c | 2 +- hw/usb/core.c | 2 +- hw/virtio/virtio-iommu.c | 2 +- include/hw/qdev-core.h | 32 +++++++++++++++++++++++++++++++- monitor/hmp.c | 2 +- softmmu/qdev-monitor.c | 24 +++++++++++++----------- softmmu/vl.c | 9 ++++----- ui/console.c | 2 +- 11 files changed, 73 insertions(+), 32 deletions(-)hw/core/machine-qmp-cmds.c +3
-3@@ -286,9 +286,9 @@ HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp)void qmp_set_numa_node (NumaOptions *cmd,Error **errp) { -if (qdev_hotplug) { -error_setg (errp,"The command is permitted only before the machine has been created" ); -return ; +if (phase_check (PHASE_MACHINE_INITIALIZED )) { +error_setg (errp,"The command is permitted only before the machine has been created" ); +return ; }set_numa_options (MACHINE (qdev_get_machine ()), cmd, errp);hw/core/machine.c +3
-5@@ -1171,17 +1171,16 @@ void machine_run_board_init(MachineState *machine) } machine_class->init (machine); +phase_advance (PHASE_MACHINE_INITIALIZED ); }static NotifierList machine_init_done_notifiers =NOTIFIER_LIST_INITIALIZER (machine_init_done_notifiers); -static bool machine_init_done; -void qemu_add_machine_init_done_notifier (Notifier *notify) {notifier_list_add (&machine_init_done_notifiers, notify); -if (machine_init_done) { +if (phase_check (PHASE_MACHINE_READY )) { notify->notify (notify,NULL ); } }@@ -1204,7 +1203,7 @@ void qdev_machine_creation_done(void)* ok, initial machine setup is done, starting from now we can * only create hotpluggable devices */ - qdev_hotplug = true; +phase_advance (PHASE_MACHINE_READY );qdev_assert_realized_properly ();/* TODO: once all bus devices are qdevified, this should be done @@ -1219,7 +1218,6 @@ void qdev_machine_creation_done(void)*/ qemu_register_reset (resettable_cold_reset_fn,sysbus_get_default ()); - machine_init_done = true;notifier_list_notify (&machine_init_done_notifiers,NULL );if (rom_check_and_register_reset () !=0 ) {hw/core/qdev.c +14
-2@@ -41,7 +41,6 @@#include "migration/vmstate.h" #include "trace.h" -bool qdev_hotplug = false;static bool qdev_hot_added = false;bool qdev_hot_removed = false;@@ -1023,7 +1022,7 @@ static void device_initfn(Object *obj) {DeviceState *dev =DEVICE (obj); -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_READY )) { dev->hotplugged =1 ; qdev_hot_added = true; }@@ -1267,6 +1266,19 @@ Object *qdev_get_machine(void)return dev; } +static MachineInitPhase machine_phase; + +bool phase_check (MachineInitPhase phase) +{ +return machine_phase >= phase; +} + +void phase_advance (MachineInitPhase phase) +{ +assert (machine_phase == phase -1 ); + machine_phase = phase; +} +static const TypeInfo device_type_info = { .name =TYPE_DEVICE , .parent =TYPE_OBJECT ,hw/pci/pci.c +1
-1@@ -1062,7 +1062,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev,address_space_init (&pci_dev->bus_master_as, &pci_dev->bus_master_container_region, pci_dev->name); -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_READY )) {pci_init_bus_master (pci_dev); } pci_dev->irq_state =0 ;hw/usb/core.c +1
-1@@ -97,7 +97,7 @@ void usb_wakeup(USBEndpoint *ep, unsigned int stream)USBDevice *dev = ep->dev;USBBus *bus =usb_bus_from_device (dev); -if (!qdev_hotplug) { +if (!phase_check (PHASE_MACHINE_READY )) {/* * This is machine init cold plug. No need to wakeup anyone, * all devices will be reset anyway. And trying to wakeup can hw/virtio/virtio-iommu.c +1
-1@@ -928,7 +928,7 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr,* accept it. Having a different masks is possible but the guest will use * sub-optimal block sizes, so warn about it. */ -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_READY )) {int new_granule =ctz64 (new_mask);int cur_granule =ctz64 (cur_mask);include/hw/qdev-core.h +31
-1@@ -821,7 +821,6 @@ Object *qdev_get_machine(void);/* FIXME: make this a link<> */ bool qdev_set_parent_bus (DeviceState *dev,BusState *bus,Error **errp); -extern bool qdev_hotplug;extern bool qdev_hot_removed;char *qdev_get_dev_path (DeviceState *dev);@@ -847,4 +846,35 @@ void device_listener_unregister(DeviceListener *listener);*/ bool qdev_should_hide_device (QemuOpts *opts); +typedef enum MachineInitPhase { +/* current_machine is NULL. */ +PHASE_NO_MACHINE , + +/* current_machine is not NULL, but current_machine->accel is NULL. */ +PHASE_MACHINE_CREATED , + +/* +* current_machine->accel is not NULL, but the machine properties have +* not been validated and machine_class->init has not yet been called. +*/ +PHASE_ACCEL_CREATED , + +/* +* machine_class->init has been called, thus creating any embedded +* devices and validating machine properties. Devices created at +* this time are considered to be cold-plugged. +*/ +PHASE_MACHINE_INITIALIZED , + +/* +* QEMU is ready to start CPUs and devices created at this time +* are considered to be hot-plugged. The monitor is not restricted +* to "preconfig" commands. +*/ +PHASE_MACHINE_READY , +}MachineInitPhase ; + +extern bool phase_check (MachineInitPhase phase); +extern void phase_advance (MachineInitPhase phase); +#endif monitor/hmp.c +1
-1@@ -216,7 +216,7 @@ static bool cmd_can_preconfig(const HMPCommand *cmd)static bool cmd_available (const HMPCommand *cmd) { -return qdev_hotplug ||cmd_can_preconfig (cmd); +return phase_check (PHASE_MACHINE_READY ) ||cmd_can_preconfig (cmd); } static void help_cmd_dump_one(Monitor *mon,softmmu/qdev-monitor.c +13
-11@@ -244,7 +244,7 @@ static DeviceClass *qdev_get_device_class(const char **driver, Error **errp) dc =DEVICE_CLASS (oc);if (!dc->user_creatable || - (qdev_hotplug && !dc->hotpluggable)) { + (phase_check (PHASE_MACHINE_READY ) && !dc->hotpluggable)) {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"driver" ,"pluggable device type" );return NULL ;@@ -637,7 +637,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) } hide =should_hide_device (opts); -if ((hide || qdev_hotplug) && bus && !qbus_is_hotpluggable (bus)) { +if ((hide ||phase_check (PHASE_MACHINE_READY )) && bus && !qbus_is_hotpluggable (bus)) {error_setg (errp,QERR_BUS_NO_HOTPLUG , bus->name);return NULL ; }@@ -655,15 +655,17 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) dev =qdev_new (driver);/* Check whether the hotplug is allowed by the machine */ -if (qdev_hotplug && !qdev_hotplug_allowed (dev, errp)) { - goto err_del_dev; - } +if (phase_check (PHASE_MACHINE_READY )) { +if (!qdev_hotplug_allowed (dev, errp)) { + goto err_del_dev; + } -if (!bus && qdev_hotplug && !qdev_get_machine_hotplug_handler (dev)) { -/* No bus, no machine hotplug handler --> device is not hotpluggable */ -error_setg (errp,"Device '%s' can not be hotplugged on this machine" , - driver); - goto err_del_dev; +if (!bus && !qdev_get_machine_hotplug_handler (dev)) { +/* No bus, no machine hotplug handler --> device is not hotpluggable */ +error_setg (errp,"Device '%s' can not be hotplugged on this machine" , + driver); + goto err_del_dev; + } }qdev_set_id (dev,qemu_opts_id (opts));@@ -1001,7 +1003,7 @@ int qemu_global_option(const char *str)bool qmp_command_available (const QmpCommand *cmd,Error **errp) { -if (!qdev_hotplug && +if (!phase_check (PHASE_MACHINE_READY ) && !(cmd->options &QCO_ALLOW_PRECONFIG )) {error_setg (errp,"The command '%s' is permitted only after machine initialization has completed" , cmd->name);softmmu/vl.c +4
-5@@ -2406,10 +2406,6 @@ static void qemu_init_displays(void) } } -/* -* Called after leaving preconfig state. From here on runstate is -* RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE. -*/ static void qemu_init_board (void ) {MachineClass *machine_class =MACHINE_GET_CLASS (current_machine);@@ -2424,6 +2420,7 @@ static void qemu_init_board(void)exit (1 ); } +/* From here on we enter MACHINE_PHASE_INITIALIZED. */ machine_run_board_init (current_machine);/* @@ -2490,7 +2487,7 @@ static void qemu_machine_creation_done(void)void qmp_x_exit_preconfig (Error **errp) { -if (qdev_hotplug) { +if (phase_check (PHASE_MACHINE_INITIALIZED )) {error_setg (errp,"The command is permitted only before machine initialization" );return ; }@@ -3469,12 +3466,14 @@ void qemu_init(int argc, char **argv, char **envp)qemu_create_early_backends ();qemu_apply_machine_options (); +phase_advance (PHASE_MACHINE_CREATED );/* * Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ configure_accelerators (argv[0 ]); +phase_advance (PHASE_ACCEL_CREATED );/* * Beware, QOM objects created before this point miss global and ui/console.c +1
-1@@ -1345,7 +1345,7 @@ static QemuConsole *new_console(DisplayState *ds, console_type_t console_type,if (QTAILQ_EMPTY (&consoles)) { s->index =0 ;QTAILQ_INSERT_TAIL (&consoles, s, next); - }else if (console_type !=GRAPHIC_CONSOLE || qdev_hotplug) { + }else if (console_type !=GRAPHIC_CONSOLE ||phase_check (PHASE_MACHINE_READY )) {QemuConsole *last =QTAILQ_LAST (&consoles); s->index = last->index +1 ;QTAILQ_INSERT_TAIL (&consoles, s, next);
PATCH 9/15 machine: record whether nvdimm= was set
In reply to Paolo BonziniThis is needed for SPAPR which has different defaults than everyone else. Right now it looks at the -machine QemuOpts, but those will go away.
--- hw/core/machine.c | 1 + include/hw/mem/nvdimm.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
hw/core/machine.c +1 -0
@@ -455,6 +455,7 @@ static void machine_set_nvdimm(Object *obj, bool value, Error **errp) {MachineState *ms =MACHINE (obj); + ms->nvdimms_state->has_is_enabled = true; ms->nvdimms_state->is_enabled = value; }
include/hw/mem/nvdimm.h +1 -1
@@ -129,7 +129,7 @@ typedef struct NvdimmFitBuffer NvdimmFitBuffer;struct NVDIMMState {/* detect if NVDIMM support is enabled. */ -bool is_enabled; +bool has_is_enabled, is_enabled;/* the data of the fw_cfg file NVDIMM_DSM_MEM_FILE. */ GArray *dsm_mem;
Signature · 1 line
2.26.2
Re: [PATCH 09/15] machine: record whether nvdimm= was set
Quoted 14 lines · On Wed, 2 Dec 2020 03:18:48 -0500 Paolo Bonzini <[email protected]> wrote:
This is needed for SPAPR which has different defaults than everyone else. Right now it looks at the -machine QemuOpts, but those will go away.
Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/machine.c | 1 + include/hw/mem/nvdimm.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)hw/core/machine.c +0
-0
hw/core/machine.c static void machine_set_nvdimm(Object *obj, bool value, Error **errp) · line 458
Quoted 4 lines
hw/core/machine.c +1
-0@@ -455,6 +455,7 @@ static void machine_set_nvdimm(Object *obj, bool value, Error **errp) {MachineState *ms =MACHINE (obj); + ms->nvdimms_state->has_is_enabled = true;
naming looks like QAPI style we use for optional fields, it might be confusing.
maybe something like "user_set_is_enabled" would be better?
(sometimes I wish for QOM properties to have 'set' flag, so we can distinguish if value is a default one or were set later on)
Quoted 16 lines
hw/core/machine.c +0
-0ms->nvdimms_state->is_enabled = value; }include/hw/mem/nvdimm.h +1
-1@@ -129,7 +129,7 @@ typedef struct NvdimmFitBuffer NvdimmFitBuffer;struct NVDIMMState {/* detect if NVDIMM support is enabled. */ -bool is_enabled; +bool has_is_enabled, is_enabled;/* the data of the fw_cfg file NVDIMM_DSM_MEM_FILE. */ GArray *dsm_mem;
PATCH 10/15 vl: make qemu_get_machine_opts static
In reply to Paolo BonziniMachine options can be retrieved as properties of the machine object. Encourage that by removing the "easy" accessor to machine options.
--- accel/kvm/kvm-all.c | 11 ++++------- hw/arm/boot.c | 2 +- hw/microblaze/boot.c | 9 ++++----- hw/nios2/boot.c | 9 ++++----- hw/ppc/e500.c | 5 ++--- hw/ppc/spapr_nvdimm.c | 4 ++-- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/sifive_u.c | 6 ++---- hw/riscv/virt.c | 6 ++---- hw/xtensa/xtfpga.c | 9 ++++----- include/sysemu/sysemu.h | 2 -- softmmu/device_tree.c | 2 +- softmmu/vl.c | 2 +- 13 files changed, 28 insertions(+), 41 deletions(-)
accel/kvm/kvm-all.c +4 -7
@@ -2013,7 +2013,6 @@ static int kvm_init(MachineState *ms)const KVMCapabilityInfo *missing_cap;int ret;int type =0 ; -const char *kvm_type;uint64_t dirty_log_manual_caps; s =KVM_STATE (ms->accelerator);
@@ -2069,13 +2068,11 @@ static int kvm_init(MachineState *ms) } s->as = g_new0(struct KVMAs, s->nr_as); - kvm_type =qemu_opt_get (qemu_get_machine_opts (),"kvm-type" ); -if (mc->kvm_type) { +if (object_property_find (OBJECT (current_machine),"kvm-type" )) { + g_autofree char *kvm_type = object_property_get_str(OBJECT(current_machine), +"kvm-type" , + &error_abort); type = mc->kvm_type (ms, kvm_type); - }else if (kvm_type) { - ret = -EINVAL ; -fprintf (stderr,"Invalid argument kvm-type=%s\n" , kvm_type); - goto err; } do {
hw/arm/boot.c +1 -1
@@ -1299,7 +1299,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) info->kernel_filename = ms->kernel_filename; info->kernel_cmdline = ms->kernel_cmdline; info->initrd_filename = ms->initrd_filename; - info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); + info->dtb_filename = ms->dtb; info->dtb_limit =0 ;/* Load the kernel. */
hw/microblaze/boot.c +4 -5
@@ -34,6 +34,7 @@#include "sysemu/device_tree.h" #include "sysemu/reset.h" #include "sysemu/sysemu.h" +#include "hw/boards.h" #include "hw/loader.h" #include "elf.h" #include "qemu/cutils.h"
@@ -116,16 +117,14 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,const char *dtb_filename, void (*machine_cpu_reset)(MicroBlazeCPU *)) { - QemuOpts *machine_opts; const char *kernel_filename;const char *kernel_cmdline;const char *dtb_arg;char *filename =NULL ; - machine_opts =qemu_get_machine_opts (); - kernel_filename =qemu_opt_get (machine_opts,"kernel" ); - kernel_cmdline =qemu_opt_get (machine_opts,"append" ); - dtb_arg =qemu_opt_get (machine_opts,"dtb" ); + kernel_filename = current_machine->kernel_filename; + kernel_cmdline = current_machine->kernel_cmdline; + dtb_arg = current_machine->dtb;/* default to pcbios dtb as passed by machine_init */ if (!dtb_arg && dtb_filename) { filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , dtb_filename);
hw/nios2/boot.c +4 -5
@@ -39,6 +39,7 @@#include "sysemu/device_tree.h" #include "sysemu/reset.h" #include "sysemu/sysemu.h" +#include "hw/boards.h" #include "hw/loader.h" #include "elf.h"
@@ -120,16 +121,14 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,const char *dtb_filename, void (*machine_cpu_reset)(Nios2CPU *)) { - QemuOpts *machine_opts; const char *kernel_filename;const char *kernel_cmdline;const char *dtb_arg;char *filename =NULL ; - machine_opts =qemu_get_machine_opts (); - kernel_filename =qemu_opt_get (machine_opts,"kernel" ); - kernel_cmdline =qemu_opt_get (machine_opts,"append" ); - dtb_arg =qemu_opt_get (machine_opts,"dtb" ); + kernel_filename = current_machine->kernel_filename; + kernel_cmdline = current_machine->kernel_cmdline; + dtb_arg = current_machine->dtb;/* default to pcbios dtb as passed by machine_init */ if (!dtb_arg) { filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , dtb_filename);
hw/ppc/e500.c +2 -3
@@ -343,9 +343,8 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms, pmc->pci_pio_base >>32 , pmc->pci_pio_base, 0x0, 0x10000, }; - QemuOpts *machine_opts =qemu_get_machine_opts (); -const char *dtb_file =qemu_opt_get (machine_opts,"dtb" ); -const char *toplevel_compat =qemu_opt_get (machine_opts,"dt_compatible" ); +const char *dtb_file = machine->dtb; +const char *toplevel_compat = machine->dt_compatible;if (dtb_file) {char *filename;
hw/ppc/spapr_nvdimm.c +2 -2
@@ -38,7 +38,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;
@@ -57,10 +56,11 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled && ms->nvdimms_state->has_is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; } + ms->nvdimms_state->is_enabled = true;if (object_property_get_int (OBJECT (nvdimm),NVDIMM_LABEL_SIZE_PROP , &error_abort) ==0 ) {
hw/ppc/virtex_ml507.c +1 -1
@@ -152,7 +152,7 @@ static int xilinx_load_device_tree(hwaddr addr,int r;const char *dtb_filename; - dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); + dtb_filename = current_machine->dtb;if (dtb_filename) { fdt =load_device_tree (dtb_filename, &fdt_size);if (!fdt) {
hw/riscv/sifive_u.c +2 -4
@@ -100,14 +100,12 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,int cpu;uint32_t *cells;char *nodename; -const char *dtb_filename;char ethclk_names[] ="pclk\0hclk" ;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle; - dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); -if (dtb_filename) { - fdt = s->fdt =load_device_tree (dtb_filename, &s->fdt_size); +if (ms->dtb) { + fdt = s->fdt =load_device_tree (ms->dtb, &s->fdt_size);if (!fdt) {error_report ("load_device_tree() failed" );exit (1 );
hw/riscv/virt.c +2 -4
@@ -181,7 +181,6 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, {void *fdt;int i, cpu, socket; -const char *dtb_filename;MachineState *mc =MACHINE (s);uint64_t addr, size;uint32_t *clint_cells, *plic_cells;
@@ -195,9 +194,8 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,hwaddr flashsize = virt_memmap[VIRT_FLASH ].size /2 ;hwaddr flashbase = virt_memmap[VIRT_FLASH ].base; - dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); -if (dtb_filename) { - fdt = s->fdt =load_device_tree (dtb_filename, &s->fdt_size); +if (mc->dtb) { + fdt = s->fdt =load_device_tree (mc->dtb, &s->fdt_size);if (!fdt) {error_report ("load_device_tree() failed" );exit (1 );
hw/xtensa/xtfpga.c +4 -5
@@ -233,11 +233,10 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)qemu_irq *extints;DriveInfo *dinfo;PFlashCFI01 *flash =NULL ; -QemuOpts *machine_opts =qemu_get_machine_opts (); -const char *kernel_filename =qemu_opt_get (machine_opts,"kernel" ); -const char *kernel_cmdline =qemu_opt_get (machine_opts,"append" ); -const char *dtb_filename =qemu_opt_get (machine_opts,"dtb" ); -const char *initrd_filename =qemu_opt_get (machine_opts,"initrd" ); +const char *kernel_filename = machine->kernel_filename; +const char *kernel_cmdline = machine->kernel_cmdline; +const char *dtb_filename = machine->dtb; +const char *initrd_filename = machine->initrd_filename;const unsigned system_io_size =224 * MiB;uint32_t freq =10000000 ;int n;
include/sysemu/sysemu.h +0 -2
@@ -104,8 +104,6 @@ typedef void QEMUBootSetHandler(void *opaque, const char *boot_order,void qemu_register_boot_set (QEMUBootSetHandler *func,void *opaque);void qemu_boot_set (const char *boot_order,Error **errp); -QemuOpts *qemu_get_machine_opts (void ); -bool defaults_enabled (void );void qemu_init (int argc,char **argv,char **envp);
softmmu/device_tree.c +1 -1
@@ -526,7 +526,7 @@ int qemu_fdt_add_subnode(void *fdt, const char *name)void qemu_fdt_dumpdtb (void *fdt,int size) { -const char *dumpdtb =qemu_opt_get (qemu_get_machine_opts (),"dumpdtb" ); +const char *dumpdtb = current_machine->dumpdtb;if (dumpdtb) {/* Dump the dtb to a file and quit */
softmmu/vl.c +1 -1
@@ -481,7 +481,7 @@ static QemuOptsList qemu_fw_cfg_opts = {* * Returns: machine options (never null). */ -QemuOpts *qemu_get_machine_opts (void ) +static QemuOpts *qemu_get_machine_opts (void ) {return qemu_find_opts_singleton ("machine" ); }
Signature · 1 line
2.26.2
Re: [PATCH 10/15] vl: make qemu_get_machine_opts static
Quoted 20 lines · On Wed, 2 Dec 2020 03:18:49 -0500 Paolo Bonzini <[email protected]> wrote:
Machine options can be retrieved as properties of the machine object. Encourage that by removing the "easy" accessor to machine options.
Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 11 ++++------- hw/arm/boot.c | 2 +- hw/microblaze/boot.c | 9 ++++----- hw/nios2/boot.c | 9 ++++----- hw/ppc/e500.c | 5 ++--- hw/ppc/spapr_nvdimm.c | 4 ++-- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/sifive_u.c | 6 ++---- hw/riscv/virt.c | 6 ++---- hw/xtensa/xtfpga.c | 9 ++++----- include/sysemu/sysemu.h | 2 -- softmmu/device_tree.c | 2 +- softmmu/vl.c | 2 +- 13 files changed, 28 insertions(+), 41 deletions(-)
[...]
Quoted 13 lines
hw/ppc/spapr_nvdimm.c +0
-1@@ -38,7 +38,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;
hw/ppc/spapr_nvdimm.c bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, · line 63
Quoted 9 lines
hw/ppc/spapr_nvdimm.c +2
-1@@ -57,10 +56,11 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled && ms->nvdimms_state->has_is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; } + ms->nvdimms_state->is_enabled = true;
it looks like nvdimm is always enabled since 5.0 and there is no way to disable it how about dropping 9/15 and just error out is it's not enabled, something like:
hw/ppc/spapr.c +3 -0
@@ -2668,6 +2668,7 @@ static void spapr_machine_init(MachineState *machine)char *filename;Error *resize_hpt_err =NULL ; +if (mc->nvdimm_supported) {// by default it is always enabled + ms->nvdimms_state->is_enabled = true; + } msi_nonbroken = true;
QLIST_INIT(&spapr->phbs);
hw/ppc/spapr_nvdimm.c +1 -1
@@ -57,7 +57,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
if I didn't miss something, that way we do not abuse nvdimm_opt and still have nvdimm enabled by default and error out if it turns to disabled for whatever reason.
Quoted 2 lines
hw/ppc/spapr_nvdimm.c +0
-0if (object_property_get_int (OBJECT (nvdimm),NVDIMM_LABEL_SIZE_PROP , &error_abort) ==0 ) {
[...]
Re: [PATCH 10/15] vl: make qemu_get_machine_opts static
Quoted 77 lines · Igor Mammedov
Quoted 20 lines · On Wed, 2 Dec 2020 03:18:49 -0500 Paolo Bonzini <[email protected]> wrote:
Machine options can be retrieved as properties of the machine object. Encourage that by removing the "easy" accessor to machine options.
Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 11 ++++------- hw/arm/boot.c | 2 +- hw/microblaze/boot.c | 9 ++++----- hw/nios2/boot.c | 9 ++++----- hw/ppc/e500.c | 5 ++--- hw/ppc/spapr_nvdimm.c | 4 ++-- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/sifive_u.c | 6 ++---- hw/riscv/virt.c | 6 ++---- hw/xtensa/xtfpga.c | 9 ++++----- include/sysemu/sysemu.h | 2 -- softmmu/device_tree.c | 2 +- softmmu/vl.c | 2 +- 13 files changed, 28 insertions(+), 41 deletions(-)[...]
Quoted 13 lines
hw/ppc/spapr_nvdimm.c +0
-1@@ -38,7 +38,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;hw/ppc/spapr_nvdimm.c bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, · line 63
Quoted 9 lines
hw/ppc/spapr_nvdimm.c +2
-1@@ -57,10 +56,11 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled && ms->nvdimms_state->has_is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; } + ms->nvdimms_state->is_enabled = true;it looks like nvdimm is always enabled since 5.0 and there is no way to disable it how about dropping 9/15 and just error out is it's not enabled, something like:
hw/ppc/spapr.c +3
-0@@ -2668,6 +2668,7 @@ static void spapr_machine_init(MachineState *machine)char *filename;Error *resize_hpt_err =NULL ; +if (mc->nvdimm_supported) {// by default it is always enabled + ms->nvdimms_state->is_enabled = true; + } msi_nonbroken = true;QLIST_INIT (&spapr->phbs);hw/ppc/spapr_nvdimm.c +1
-1@@ -57,7 +57,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
Quoted 2 lines
if I didn't miss something, that way we do not abuse
nvdimm_optand still have nvdimm enabled by default and error out if it turns to disabled for whatever reason.
Yes, this looks correct. I see you have already CCed Daniel and David.
Paolo
Re: [PATCH 10/15] vl: make qemu_get_machine_opts static
In reply to Igor MammedovQuoted 40 lines · Igor Mammedov
Quoted 20 lines · On Wed, 2 Dec 2020 03:18:49 -0500 Paolo Bonzini <[email protected]> wrote:
Machine options can be retrieved as properties of the machine object. Encourage that by removing the "easy" accessor to machine options.
Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 11 ++++------- hw/arm/boot.c | 2 +- hw/microblaze/boot.c | 9 ++++----- hw/nios2/boot.c | 9 ++++----- hw/ppc/e500.c | 5 ++--- hw/ppc/spapr_nvdimm.c | 4 ++-- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/sifive_u.c | 6 ++---- hw/riscv/virt.c | 6 ++---- hw/xtensa/xtfpga.c | 9 ++++----- include/sysemu/sysemu.h | 2 -- softmmu/device_tree.c | 2 +- softmmu/vl.c | 2 +- 13 files changed, 28 insertions(+), 41 deletions(-)[...]
Quoted 16 lines
hw/ppc/spapr_nvdimm.c +0
-1@@ -38,7 +38,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;@@ -57,10 +56,11 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */
Quoted 8 lines
hw/ppc/spapr_nvdimm.c bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,
Quoted 6 lines
hw/ppc/spapr_nvdimm.c +2
-1-if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled && ms->nvdimms_state->has_is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; } + ms->nvdimms_state->is_enabled = true;it looks like nvdimm is always enabled since 5.0 and there is no way to disable it
I'm not sure I'm following this statement. Testing here with all patches up to this one applied, in a x86 machine:
$ sudo ./x86_64-softmmu/qemu-system-x86_64 -M pc,nvdimm=off -object memory-backend-file,id=mem0,size=1G,mem-path=/tmp/aa -device nvdimm,id=dimm0,memdev=mem0 qemu-system-x86_64: -device nvdimm,id=dimm0,memdev=mem0: nvdimm is not enabled: missing 'nvdimm' in '-M' $ $ sudo ./x86_64-softmmu/qemu-system-x86_64 -M pc -object memory-backend-file,id=mem0,size=1G,mem-path=/tmp/aa -device nvdimm,id=dimm0,memdev=mem0 qemu-system-x86_64: -device nvdimm,id=dimm0,memdev=mem0: nvdimm is not enabled: missing 'nvdimm' in '-M' $
This is the x86 NVDIMM behavior I considered when patching pseries NVDIMM support. As Paolo mentioned in patch 09, pseries has different default values. We screwed it up when pushing the first version of pseries NVDIMM support and we ended up enabling it by default, as opposed to disabling it by default like x86. One release later people complained that we weren't honoring 'nvdimm=off' to disable NVDIMM support. The path of less pain that I chose was to at the very least disable the support when "nvdimm=off" was specified by the user.
Quoted 29 lines
how about dropping 9/15 and just error out is it's not enabled, something like:
hw/ppc/spapr.c +3
-0@@ -2668,6 +2668,7 @@ static void spapr_machine_init(MachineState *machine)char *filename;Error *resize_hpt_err =NULL ; +if (mc->nvdimm_supported) {// by default it is always enabled + ms->nvdimms_state->is_enabled = true; + } msi_nonbroken = true;QLIST_INIT (&spapr->phbs);hw/ppc/spapr_nvdimm.c +1
-1@@ -57,7 +57,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
Quoted 2 lines
if I didn't miss something, that way we do not abuse
nvdimm_optand still have nvdimm enabled by default and error out if it turns to disabled for whatever reason.
Just tried this out. This doesn't disable the NVDIMM support when passing 'nvdimm=off' machine option.
As far pseries NVDIMM support goes, we'll need patch 09 and to consider nvdimm_opt to keep the same behavior we already have today, like Paolo is already doing in this patch.
Thanks,
DHB
Quoted 8 lines
Quoted 4 lines
hw/ppc/spapr_nvdimm.c +0
-0if (object_property_get_int (OBJECT (nvdimm),NVDIMM_LABEL_SIZE_PROP , &error_abort) ==0 ) {[...]
Re: [PATCH 10/15] vl: make qemu_get_machine_opts static
Quoted 103 lines · On Mon, 7 Dec 2020 23:32:55 -0300 Daniel Henrique Barboza…
Quoted 40 lines · Igor Mammedov
Quoted 20 lines · On Wed, 2 Dec 2020 03:18:49 -0500 Paolo Bonzini <[email protected]> wrote:
Machine options can be retrieved as properties of the machine object. Encourage that by removing the "easy" accessor to machine options.
Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 11 ++++------- hw/arm/boot.c | 2 +- hw/microblaze/boot.c | 9 ++++----- hw/nios2/boot.c | 9 ++++----- hw/ppc/e500.c | 5 ++--- hw/ppc/spapr_nvdimm.c | 4 ++-- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/sifive_u.c | 6 ++---- hw/riscv/virt.c | 6 ++---- hw/xtensa/xtfpga.c | 9 ++++----- include/sysemu/sysemu.h | 2 -- softmmu/device_tree.c | 2 +- softmmu/vl.c | 2 +- 13 files changed, 28 insertions(+), 41 deletions(-)[...]
Quoted 16 lines
hw/ppc/spapr_nvdimm.c +0
-1@@ -38,7 +38,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;@@ -57,10 +56,11 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ Quoted 8 lines
hw/ppc/spapr_nvdimm.c bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,
Quoted 6 lines
hw/ppc/spapr_nvdimm.c +2
-1-if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled && ms->nvdimms_state->has_is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; } + ms->nvdimms_state->is_enabled = true;it looks like nvdimm is always enabled since 5.0 and there is no way to disable it
I'm not sure I'm following this statement. Testing here with all patches up to this one applied, in a x86 machine:
$ sudo ./x86_64-softmmu/qemu-system-x86_64 -M pc,nvdimm=off -object memory-backend-file,id=mem0,size=1G,mem-path=/tmp/aa -device nvdimm,id=dimm0,memdev=mem0 qemu-system-x86_64: -device nvdimm,id=dimm0,memdev=mem0: nvdimm is not enabled: missing 'nvdimm' in '-M' $ $ sudo ./x86_64-softmmu/qemu-system-x86_64 -M pc -object memory-backend-file,id=mem0,size=1G,mem-path=/tmp/aa -device nvdimm,id=dimm0,memdev=mem0 qemu-system-x86_64: -device nvdimm,id=dimm0,memdev=mem0: nvdimm is not enabled: missing 'nvdimm' in '-M' $This is the x86 NVDIMM behavior I considered when patching pseries NVDIMM support. As Paolo mentioned in patch 09, pseries has different default values. We screwed it up when pushing the first version of pseries NVDIMM support and we ended up enabling it by default, as opposed to disabling it by default like x86. One release later people complained that we weren't honoring 'nvdimm=off' to disable NVDIMM support. The path of less pain that I chose was to at the very least disable the support when "nvdimm=off" was specified by the user.
Quoted 29 lines
how about dropping 9/15 and just error out is it's not enabled, something like:
hw/ppc/spapr.c +3
-0@@ -2668,6 +2668,7 @@ static void spapr_machine_init(MachineState *machine)char *filename;Error *resize_hpt_err =NULL ; +if (mc->nvdimm_supported) {// by default it is always enabled + ms->nvdimms_state->is_enabled = true; + } msi_nonbroken = true;QLIST_INIT (&spapr->phbs);hw/ppc/spapr_nvdimm.c +1
-1@@ -57,7 +57,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
Quoted 6 lines
Quoted 2 lines
if I didn't miss something, that way we do not abuse
nvdimm_optand still have nvdimm enabled by default and error out if it turns to disabled for whatever reason.Just tried this out. This doesn't disable the NVDIMM support when passing 'nvdimm=off' machine option.
that's not really working, but rather idea (spapr_machine_init is too late for the task). I'll post a path that should do the job in a minute.
Quoted 21 lines
As far pseries NVDIMM support goes, we'll need patch 09 and to consider
nvdimm_optto keep the same behavior we already have today, like Paolo is already doing in this patch.Thanks,
DHB
Quoted 8 lines
Quoted 4 lines
hw/ppc/spapr_nvdimm.c +0
-0if (object_property_get_int (OBJECT (nvdimm),NVDIMM_LABEL_SIZE_PROP , &error_abort) ==0 ) {[...]
PATCH 1/1 ppc/spapr: cleanup -machine pseries,nvdimm=X handling
In reply to Daniel Henrique BarbozaSince NVDIMM support was introduced on pseries machine,
it ignored machine's nvdimm=on|off option and effectively
was always enabled on machines that support NVDIMM.
Later on commit
(28f5a716212 ppc/spapr_nvdimm: do not enable support with 'nvdimm=off')
makes QEMU error out in case user explicitly set 'nvdimm=off' on CLI by peeking at machine_opts.
However that's a bit hacking and going away (in world where machine configured over QMP) and it also leaves
nvdimms_state->is_enabled
in inconsistent state (false) even when it should be set true by default.
Instead of using on machine_opts, implement per machine "nvdimm enabled" default handling and set default enabled value at machine class init time (which is set to true for pseries) and properly handle it generic machine code.
That way pseries will have, nvdimm enabled by default and will honor user provided 'nvdimm=on|off'.
---
PS:
Patch should be applied on top of:
[PATCH 08/15] machine: introduce MachineInitPhase
--- include/hw/boards.h | 1 + hw/core/machine.c | 1 + hw/ppc/spapr.c | 8 ++++++++ hw/ppc/spapr_nvdimm.c | 14 +------------- 4 files changed, 11 insertions(+), 13 deletions(-)
include/hw/boards.h +1 -0
@@ -206,6 +206,7 @@ struct MachineClass {bool ignore_boot_device_suffixes;bool smbus_no_migration_support;bool nvdimm_supported; +bool nvdimm_enabled_default;bool numa_mem_supported;bool auto_enable_numa;const char *default_ram_id;
hw/core/machine.c +1 -0
@@ -893,6 +893,7 @@ static void machine_initfn(Object *obj)Object *obj =OBJECT (ms); ms->nvdimms_state =g_new0 (NVDIMMState,1 ); + ms->nvdimms_state->is_enabled = mc->nvdimm_enabled_default;object_property_add_bool (obj,"nvdimm" , machine_get_nvdimm, machine_set_nvdimm); object_property_set_description(obj, "nvdimm",
hw/ppc/spapr.c +8 -0
@@ -4413,6 +4413,14 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("power9_v2.0" ); mc->has_hotpluggable_cpus = true; mc->nvdimm_supported = true; +/* +* NVDIMM support went live in 5.1 without considering that, in +* other archs, the user needs to enable NVDIMM support with the +* 'nvdimm' machine option and the default behavior is NVDIMM +* support disabled. It is too late to roll back to the standard +* behavior without breaking 5.1 guests. +*/ + mc->nvdimm_enabled_default = true; smc->resize_hpt_default =SPAPR_RESIZE_HPT_ENABLED ; fwc->get_dev_path = spapr_get_fw_dev_path; nc->nmi_monitor_handler = spapr_nmi;
hw/ppc/spapr_nvdimm.c +1 -13
@@ -27,10 +27,8 @@#include "hw/ppc/spapr_nvdimm.h" #include "hw/mem/nvdimm.h" #include "qemu/nvdimm-utils.h" -#include "qemu/option.h" #include "hw/ppc/fdt.h" #include "qemu/range.h" -#include "sysemu/sysemu.h" #include "hw/ppc/spapr_numa.h" bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,
@@ -38,7 +36,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;
@@ -48,16 +45,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,return false; } -/* -* NVDIMM support went live in 5.1 without considering that, in -* other archs, the user needs to enable NVDIMM support with the -* 'nvdimm' machine option and the default behavior is NVDIMM -* support disabled. It is too late to roll back to the standard -* behavior without breaking 5.1 guests. What we can do is to -* ensure that, if the user sets nvdimm=off, we error out -* regardless of being 5.1 or newer. -*/ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
Signature · 1 line
2.27.0
PATCH v2 1/1 ppc/spapr: cleanup -machine pseries,nvdimm=X handling
Since NVDIMM support was introduced on pseries machine,
it ignored machine's nvdimm=on|off option and effectively
was always enabled on machines that support NVDIMM.
Later on commit
(28f5a716212 ppc/spapr_nvdimm: do not enable support with 'nvdimm=off')
makes QEMU error out in case user explicitly set 'nvdimm=off' on CLI by peeking at machine_opts.
However that's a workaround and leaves 'nvdimms_state->is_enabled' in inconsistent state (false) when it should be set true by default.
Instead of using on machine_opts, set default to true for pseries machine in initfn time. If user sets manually 'nvdimm=off' it will overwrite default value to false and QEMU will error as expected without need to peek into machine_opts.
That way pseries will have, nvdimm enabled by default and will honor user provided 'nvdimm=on|off'.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
v2:
- simplify a bit more by using spapr_instance_init() to set default value instead of doing it in generic machine code
PS:
Patch should be applied on top of:
[PATCH 08/15] machine: introduce MachineInitPhase
--- hw/ppc/spapr.c | 13 +++++++++++++ hw/ppc/spapr_nvdimm.c | 14 +------------- 2 files changed, 14 insertions(+), 13 deletions(-)
hw/ppc/spapr.c +13 -0
@@ -3267,6 +3267,19 @@ static void spapr_instance_init(Object *obj) {SpaprMachineState *spapr =SPAPR_MACHINE (obj);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); +MachineState *ms =MACHINE (spapr); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +/* +* NVDIMM support went live in 5.1 without considering that, in +* other archs, the user needs to enable NVDIMM support with the +* 'nvdimm' machine option and the default behavior is NVDIMM +* support disabled. It is too late to roll back to the standard +* behavior without breaking 5.1 guests. +*/ +if (mc->nvdimm_supported) { + ms->nvdimms_state->is_enabled = true; + } spapr->htab_fd =-1 ; spapr->use_hotplug_event_source = true;
hw/ppc/spapr_nvdimm.c +1 -13
@@ -27,10 +27,8 @@#include "hw/ppc/spapr_nvdimm.h" #include "hw/mem/nvdimm.h" #include "qemu/nvdimm-utils.h" -#include "qemu/option.h" #include "hw/ppc/fdt.h" #include "qemu/range.h" -#include "sysemu/sysemu.h" #include "hw/ppc/spapr_numa.h" bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,
@@ -38,7 +36,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;
@@ -48,16 +45,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,return false; } -/* -* NVDIMM support went live in 5.1 without considering that, in -* other archs, the user needs to enable NVDIMM support with the -* 'nvdimm' machine option and the default behavior is NVDIMM -* support disabled. It is too late to roll back to the standard -* behavior without breaking 5.1 guests. What we can do is to -* ensure that, if the user sets nvdimm=off, we error out -* regardless of being 5.1 or newer. -*/ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
Signature · 1 line
2.27.0
Re: [PATCH v2] ppc/spapr: cleanup -machine pseries,nvdimm=X handling
Quoted 12 lines · Igor Mammedov
Since NVDIMM support was introduced on pseries machine,
it ignored machine's nvdimm=on|off option and effectively
was always enabled on machines that support NVDIMM.
Later on commit
(28f5a716212ppc/spapr_nvdimm: do not enable support with 'nvdimm=off')
makes QEMU error out in case user explicitly set 'nvdimm=off' on CLI by peeking atmachine_opts.However that's a workaround and leaves '
nvdimms_state->is_enabled' in inconsistent state (false) when it should be set true by default.
Quoted 6 lines
Instead of using on
machine_opts, set default to true for pseries machine in initfn time. If user sets manually 'nvdimm=off' it will overwrite default value to false and QEMU will error as expected without need to peek intomachine_opts.That way pseries will have, nvdimm enabled by default and
nit: extra ',' here
Quoted 1 line
will honor user provided 'nvdimm=on|off'.
I believe it's plausible to add a:
To indicate that this is amending my commit you mentioned up there.
Quoted 3 lines
Signed-off-by Igor Mammedov <[email protected]>---
Thanks for taking the time patching this up. Tested on top of Patch 08 in a Power 9 host and it works as intended.
ps: I'm assuming that that this is deprecating Paolo's patch:
"[PATCH 09/15] machine: record whether nvdimm= was set"
and also the chunks of Patch 10/15 that are changing spapr_nvdimm.c. If that's not the case, let me know and I'll re-test.
Thanks,
DHB
Quoted 82 lines
v2:
- simplify a bit more by usingspapr_instance_init()to set default value instead of doing it in generic machine codePS:
Patch should be applied on top of:
[PATCH 08/15] machine: introduce MachineInitPhase--- hw/ppc/spapr.c | 13 +++++++++++++ hw/ppc/spapr_nvdimm.c | 14 +------------- 2 files changed, 14 insertions(+), 13 deletions(-)hw/ppc/spapr.c +13
-0@@ -3267,6 +3267,19 @@ static void spapr_instance_init(Object *obj) {SpaprMachineState *spapr =SPAPR_MACHINE (obj);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); +MachineState *ms =MACHINE (spapr); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +/* +* NVDIMM support went live in 5.1 without considering that, in +* other archs, the user needs to enable NVDIMM support with the +* 'nvdimm' machine option and the default behavior is NVDIMM +* support disabled. It is too late to roll back to the standard +* behavior without breaking 5.1 guests. +*/ +if (mc->nvdimm_supported) { + ms->nvdimms_state->is_enabled = true; + } spapr->htab_fd =-1 ; spapr->use_hotplug_event_source = true;hw/ppc/spapr_nvdimm.c +1
-13@@ -27,10 +27,8 @@#include "hw/ppc/spapr_nvdimm.h" #include "hw/mem/nvdimm.h" #include "qemu/nvdimm-utils.h" -#include "qemu/option.h" #include "hw/ppc/fdt.h" #include "qemu/range.h" -#include "sysemu/sysemu.h" #include "hw/ppc/spapr_numa.h" bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,@@ -38,7 +36,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;@@ -48,16 +45,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,return false; } -/* -* NVDIMM support went live in 5.1 without considering that, in -* other archs, the user needs to enable NVDIMM support with the -* 'nvdimm' machine option and the default behavior is NVDIMM -* support disabled. It is too late to roll back to the standard -* behavior without breaking 5.1 guests. What we can do is to -* ensure that, if the user sets nvdimm=off, we error out -* regardless of being 5.1 or newer. -*/ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
Re: [PATCH v2] ppc/spapr: cleanup -machine pseries,nvdimm=X handling
Quoted 42 lines · On Tue, 8 Dec 2020 14:24:22 -0300 Daniel Henrique Barboza…
Quoted 12 lines · Igor Mammedov
Since NVDIMM support was introduced on pseries machine,
it ignored machine's nvdimm=on|off option and effectively
was always enabled on machines that support NVDIMM.
Later on commit
(28f5a716212ppc/spapr_nvdimm: do not enable support with 'nvdimm=off')
makes QEMU error out in case user explicitly set 'nvdimm=off' on CLI by peeking atmachine_opts.However that's a workaround and leaves '
nvdimms_state->is_enabled' in inconsistent state (false) when it should be set true by default.Quoted 6 lines
Instead of using on
machine_opts, set default to true for pseries machine in initfn time. If user sets manually 'nvdimm=off' it will overwrite default value to false and QEMU will error as expected without need to peek intomachine_opts.That way pseries will have, nvdimm enabled by default and
nit: extra ',' here
Quoted 1 line
will honor user provided 'nvdimm=on|off'.
I believe it's plausible to add a:
Fixes 28f5a716212 ("ppc/spapr_nvdimm: do not enable support with 'nvdimm=off'")To indicate that this is amending my commit you mentioned up there.
Quoted 3 lines
Signed-off-by Igor Mammedov <[email protected]>---
Thanks for taking the time patching this up. Tested on top of Patch 08 in a Power 9 host and it works as intended.
Reviewed-by Daniel Henrique Barboza <[email protected]>
Quoted 6 lines
ps: I'm assuming that that this is deprecating Paolo's patch:
"[PATCH 09/15] machine: record whether nvdimm= was set"
and also the chunks of Patch 10/15 that are changing
spapr_nvdimm.c. If that's not the case, let me know and I'll re-test.
yes, it does deprecate those.
And it is based on this series, so I'd expect Paolo to incorporate it, to avoid churn/conflicts.
Quoted 93 lines
Thanks,
DHB
Quoted 82 lines
v2:
- simplify a bit more by usingspapr_instance_init()to set default value instead of doing it in generic machine codePS:
Patch should be applied on top of:
[PATCH 08/15] machine: introduce MachineInitPhase--- hw/ppc/spapr.c | 13 +++++++++++++ hw/ppc/spapr_nvdimm.c | 14 +------------- 2 files changed, 14 insertions(+), 13 deletions(-)hw/ppc/spapr.c +13
-0@@ -3267,6 +3267,19 @@ static void spapr_instance_init(Object *obj) {SpaprMachineState *spapr =SPAPR_MACHINE (obj);SpaprMachineClass *smc =SPAPR_MACHINE_GET_CLASS (spapr); +MachineState *ms =MACHINE (spapr); +MachineClass *mc =MACHINE_GET_CLASS (ms); + +/* +* NVDIMM support went live in 5.1 without considering that, in +* other archs, the user needs to enable NVDIMM support with the +* 'nvdimm' machine option and the default behavior is NVDIMM +* support disabled. It is too late to roll back to the standard +* behavior without breaking 5.1 guests. +*/ +if (mc->nvdimm_supported) { + ms->nvdimms_state->is_enabled = true; + } spapr->htab_fd =-1 ; spapr->use_hotplug_event_source = true;hw/ppc/spapr_nvdimm.c +1
-13@@ -27,10 +27,8 @@#include "hw/ppc/spapr_nvdimm.h" #include "hw/mem/nvdimm.h" #include "qemu/nvdimm-utils.h" -#include "qemu/option.h" #include "hw/ppc/fdt.h" #include "qemu/range.h" -#include "sysemu/sysemu.h" #include "hw/ppc/spapr_numa.h" bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,@@ -38,7 +36,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;@@ -48,16 +45,7 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,return false; } -/* -* NVDIMM support went live in 5.1 without considering that, in -* other archs, the user needs to enable NVDIMM support with the -* 'nvdimm' machine option and the default behavior is NVDIMM -* support disabled. It is too late to roll back to the standard -* behavior without breaking 5.1 guests. What we can do is to -* ensure that, if the user sets nvdimm=off, we error out -* regardless of being 5.1 or newer. -*/ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; }
Re: [PATCH 10/15] vl: make qemu_get_machine_opts static
In reply to Paolo BonziniQuoted 33 lines · Paolo Bonzini
Machine options can be retrieved as properties of the machine object. Encourage that by removing the "easy" accessor to machine options.
Signed-off-by Paolo Bonzini <[email protected]>--- accel/kvm/kvm-all.c | 11 ++++------- hw/arm/boot.c | 2 +- hw/microblaze/boot.c | 9 ++++----- hw/nios2/boot.c | 9 ++++----- hw/ppc/e500.c | 5 ++--- hw/ppc/spapr_nvdimm.c | 4 ++-- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/sifive_u.c | 6 ++---- hw/riscv/virt.c | 6 ++---- hw/xtensa/xtfpga.c | 9 ++++----- include/sysemu/sysemu.h | 2 -- softmmu/device_tree.c | 2 +- softmmu/vl.c | 2 +- 13 files changed, 28 insertions(+), 41 deletions(-)accel/kvm/kvm-all.c +0
-1@@ -2013,7 +2013,6 @@ static int kvm_init(MachineState *ms)const KVMCapabilityInfo *missing_cap;int ret;int type =0 ; -const char *kvm_type;uint64_t dirty_log_manual_caps; s =KVM_STATE (ms->accelerator);
accel/kvm/kvm-all.c static int kvm_init(MachineState *ms) · line 2075
Quoted 10 lines
accel/kvm/kvm-all.c +4
-2@@ -2069,13 +2068,11 @@ static int kvm_init(MachineState *ms) } s->as = g_new0(struct KVMAs, s->nr_as); - kvm_type =qemu_opt_get (qemu_get_machine_opts (),"kvm-type" ); -if (mc->kvm_type) { +if (object_property_find (OBJECT (current_machine),"kvm-type" )) { + g_autofree char *kvm_type = object_property_get_str(OBJECT(current_machine), +"kvm-type" , + &error_abort); type = mc->kvm_type (ms, kvm_type);
I'm afraid that this code has unintended consequences for pseries. When starting the VM with '--enable-kvm' in a Power host I'm getting an error:
$ sudo ./ppc64-softmmu/qemu-system-ppc64 -nographic -nodefaults -machine pseries --enable-kvm qemu-system-ppc64: Unknown kvm-type specified ''
The reason is that spapr_kvm_type() expects kvm-type to be either NULL (i.e. no option set, in the previous semantic), "HV" or "PR". This was the case for the previous qemu_opt_get(), but with object_property_get_str() the absence of the option is returning kvm_type = ''.
This means that, as far as pseries goes, inserting "kvm-type=" (blank string) has the same effect:
$ sudo ./ppc64-softmmu/qemu-system-ppc64 -nographic -nodefaults -machine pseries,accel=kvm,kvm-type= qemu-system-ppc64: Unknown kvm-type specified ''
I investigated object_property_get_str() inner workings a bit and I wasn't able to find a way for it to return NULL if kvm_type isn't specified.
I see three possible solutions for it:
1) interpret kvm_type='' as if kvm_type=NULL inside spapr_kvm_type():
static int spapr_kvm_type(MachineState *machine, const char *vm_type)
{
if (!vm_type || strcmp(vm_type, "")) {
return 0;
}(...)
This is kind of ugly because we're validating a "kvm_type=" scenario with it, but it works.
2) find a way to make object_property_get_str() to return kvm_type = NULL if the 'kvm_type' option is absent and keep spapr code untouched. I don't have the knowledge to assess how hard this would be.
3) I can change the pseries logic to add an explicit default value for kvm_type=NULL or kvm_type='' (i.e. no user input is given). We're already doing that in a sense, but it's not exposed to the user. I would call it 'auto' and expose it to the user as default value if no kvm_type is explictly set. This would enhance user experience a bit and avoid having to deal with a scenario where kvm_type=(blank) is a valid input.
David, if you think (3) is tolerable let me know and I can send a patch. IMO this change adds a bit of value regardless of Paolo's change.
Thanks,
DHB
Quoted 243 lines
accel/kvm/kvm-all.c +0
-4- }else if (kvm_type) { - ret = -EINVAL ; -fprintf (stderr,"Invalid argument kvm-type=%s\n" , kvm_type); - goto err; } do {hw/arm/boot.c +1
-1@@ -1299,7 +1299,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) info->kernel_filename = ms->kernel_filename; info->kernel_cmdline = ms->kernel_cmdline; info->initrd_filename = ms->initrd_filename; - info->dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); + info->dtb_filename = ms->dtb; info->dtb_limit =0 ;/* Load the kernel. */ hw/microblaze/boot.c +4
-5@@ -34,6 +34,7 @@#include "sysemu/device_tree.h" #include "sysemu/reset.h" #include "sysemu/sysemu.h" +#include "hw/boards.h" #include "hw/loader.h" #include "elf.h" #include "qemu/cutils.h" @@ -116,16 +117,14 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,const char *dtb_filename, void (*machine_cpu_reset)(MicroBlazeCPU *)) { - QemuOpts *machine_opts; const char *kernel_filename;const char *kernel_cmdline;const char *dtb_arg;char *filename =NULL ; - machine_opts =qemu_get_machine_opts (); - kernel_filename =qemu_opt_get (machine_opts,"kernel" ); - kernel_cmdline =qemu_opt_get (machine_opts,"append" ); - dtb_arg =qemu_opt_get (machine_opts,"dtb" ); + kernel_filename = current_machine->kernel_filename; + kernel_cmdline = current_machine->kernel_cmdline; + dtb_arg = current_machine->dtb;/* default to pcbios dtb as passed by machine_init */ if (!dtb_arg && dtb_filename) { filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , dtb_filename);hw/nios2/boot.c +4
-5@@ -39,6 +39,7 @@#include "sysemu/device_tree.h" #include "sysemu/reset.h" #include "sysemu/sysemu.h" +#include "hw/boards.h" #include "hw/loader.h" #include "elf.h" @@ -120,16 +121,14 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,const char *dtb_filename, void (*machine_cpu_reset)(Nios2CPU *)) { - QemuOpts *machine_opts; const char *kernel_filename;const char *kernel_cmdline;const char *dtb_arg;char *filename =NULL ; - machine_opts =qemu_get_machine_opts (); - kernel_filename =qemu_opt_get (machine_opts,"kernel" ); - kernel_cmdline =qemu_opt_get (machine_opts,"append" ); - dtb_arg =qemu_opt_get (machine_opts,"dtb" ); + kernel_filename = current_machine->kernel_filename; + kernel_cmdline = current_machine->kernel_cmdline; + dtb_arg = current_machine->dtb;/* default to pcbios dtb as passed by machine_init */ if (!dtb_arg) { filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , dtb_filename);hw/ppc/e500.c +2
-3@@ -343,9 +343,8 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms, pmc->pci_pio_base >>32 , pmc->pci_pio_base, 0x0, 0x10000, }; - QemuOpts *machine_opts =qemu_get_machine_opts (); -const char *dtb_file =qemu_opt_get (machine_opts,"dtb" ); -const char *toplevel_compat =qemu_opt_get (machine_opts,"dt_compatible" ); +const char *dtb_file = machine->dtb; +const char *toplevel_compat = machine->dt_compatible;if (dtb_file) {char *filename;hw/ppc/spapr_nvdimm.c +2
-2@@ -38,7 +38,6 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm, {const MachineClass *mc =MACHINE_GET_CLASS (hotplug_dev);const MachineState *ms =MACHINE (hotplug_dev); -const char *nvdimm_opt =qemu_opt_get (qemu_get_machine_opts (),"nvdimm" ); g_autofree char *uuidstr = NULL;QemuUUID uuid;int ret;@@ -57,10 +56,11 @@ bool spapr_nvdimm_validate(HotplugHandler *hotplug_dev, NVDIMMDevice *nvdimm,* ensure that, if the user sets nvdimm=off, we error out * regardless of being 5.1 or newer. */ -if (!ms->nvdimms_state->is_enabled && nvdimm_opt) { +if (!ms->nvdimms_state->is_enabled && ms->nvdimms_state->has_is_enabled) {error_setg (errp,"nvdimm device found but 'nvdimm=off' was set" );return false; } + ms->nvdimms_state->is_enabled = true;if (object_property_get_int (OBJECT (nvdimm),NVDIMM_LABEL_SIZE_PROP , &error_abort) ==0 ) {hw/ppc/virtex_ml507.c +1
-1@@ -152,7 +152,7 @@ static int xilinx_load_device_tree(hwaddr addr,int r;const char *dtb_filename; - dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); + dtb_filename = current_machine->dtb;if (dtb_filename) { fdt =load_device_tree (dtb_filename, &fdt_size);if (!fdt) {hw/riscv/sifive_u.c +2
-4@@ -100,14 +100,12 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,int cpu;uint32_t *cells;char *nodename; -const char *dtb_filename;char ethclk_names[] ="pclk\0hclk" ;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle; - dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); -if (dtb_filename) { - fdt = s->fdt =load_device_tree (dtb_filename, &s->fdt_size); +if (ms->dtb) { + fdt = s->fdt =load_device_tree (ms->dtb, &s->fdt_size);if (!fdt) {error_report ("load_device_tree() failed" );exit (1 );hw/riscv/virt.c +2
-4@@ -181,7 +181,6 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, {void *fdt;int i, cpu, socket; -const char *dtb_filename;MachineState *mc =MACHINE (s);uint64_t addr, size;uint32_t *clint_cells, *plic_cells;@@ -195,9 +194,8 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,hwaddr flashsize = virt_memmap[VIRT_FLASH ].size /2 ;hwaddr flashbase = virt_memmap[VIRT_FLASH ].base; - dtb_filename =qemu_opt_get (qemu_get_machine_opts (),"dtb" ); -if (dtb_filename) { - fdt = s->fdt =load_device_tree (dtb_filename, &s->fdt_size); +if (mc->dtb) { + fdt = s->fdt =load_device_tree (mc->dtb, &s->fdt_size);if (!fdt) {error_report ("load_device_tree() failed" );exit (1 );hw/xtensa/xtfpga.c +4
-5@@ -233,11 +233,10 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)qemu_irq *extints;DriveInfo *dinfo;PFlashCFI01 *flash =NULL ; -QemuOpts *machine_opts =qemu_get_machine_opts (); -const char *kernel_filename =qemu_opt_get (machine_opts,"kernel" ); -const char *kernel_cmdline =qemu_opt_get (machine_opts,"append" ); -const char *dtb_filename =qemu_opt_get (machine_opts,"dtb" ); -const char *initrd_filename =qemu_opt_get (machine_opts,"initrd" ); +const char *kernel_filename = machine->kernel_filename; +const char *kernel_cmdline = machine->kernel_cmdline; +const char *dtb_filename = machine->dtb; +const char *initrd_filename = machine->initrd_filename;const unsigned system_io_size =224 * MiB;uint32_t freq =10000000 ;int n;include/sysemu/sysemu.h +0
-2@@ -104,8 +104,6 @@ typedef void QEMUBootSetHandler(void *opaque, const char *boot_order,void qemu_register_boot_set (QEMUBootSetHandler *func,void *opaque);void qemu_boot_set (const char *boot_order,Error **errp); -QemuOpts *qemu_get_machine_opts (void ); -bool defaults_enabled (void );void qemu_init (int argc,char **argv,char **envp);softmmu/device_tree.c +1
-1@@ -526,7 +526,7 @@ int qemu_fdt_add_subnode(void *fdt, const char *name)void qemu_fdt_dumpdtb (void *fdt,int size) { -const char *dumpdtb =qemu_opt_get (qemu_get_machine_opts (),"dumpdtb" ); +const char *dumpdtb = current_machine->dumpdtb;if (dumpdtb) {/* Dump the dtb to a file and quit */ softmmu/vl.c +1
-1@@ -481,7 +481,7 @@ static QemuOptsList qemu_fw_cfg_opts = {* * Returns: machine options (never null). */ -QemuOpts *qemu_get_machine_opts (void ) +static QemuOpts *qemu_get_machine_opts (void ) {return qemu_find_opts_singleton ("machine" ); }
Re: [PATCH 10/15] vl: make qemu_get_machine_opts static
Quoted 14 lines · Daniel Henrique Barboza
2) find a way to make
object_property_get_str()to returnkvm_type= NULL if the 'kvm_type' option is absent and keep spapr code
untouched. I don't have the knowledge to assess how hard this would be.3) I can change the pseries logic to add an explicit default value for kvm_type=NULL or kvm_type='' (i.e. no user input is given). We're already doing that in a sense, but it's not exposed to the user. I would call it 'auto' and expose it to the user as default value if no
kvm_typeis explictly set. This would enhance user experience a bit and avoid having to deal with a scenario where kvm_type=(blank) is a valid input.
Quoted 3 lines
David, if you think (3) is tolerable let me know and I can send a patch. IMO this change adds a bit of value regardless of Paolo's change.
Yes, I agree that (3) is a good idea. If you send a patch I can integrate it in the series.
Paolo
PATCH 11/15 qtest: add a QOM object for qtest
In reply to Paolo BonziniThe qtest server right now can only be created using the -qtest and -qtest-log options. Allow an alternative way to create it using "-object qtest,chardev=...,log=...".
--- softmmu/qtest.c | 144 ++++++++++++++++++++++++++++++++++++++++++++---- softmmu/vl.c | 5 +- 2 files changed, 135 insertions(+), 14 deletions(-)
softmmu/qtest.c +132 -12
@@ -27,6 +27,8 @@#include "qemu/error-report.h" #include "qemu/module.h" #include "qemu/cutils.h" +#include "qapi/qmp/qerror.h" +#include "qom/object_interfaces.h" #include CONFIG_DEVICES #ifdef CONFIG_PSERIES #include "hw/ppc/spapr_rtas.h"
@@ -849,18 +851,9 @@ static void qtest_event(void *opaque, QEMUChrEvent event)break ; } } -void qtest_server_init (const char *qtest_chrdev,const char *qtest_log,Error **errp) -{ -Chardev *chr; - - chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); - -if (chr ==NULL ) { -error_setg (errp,"Failed to initialize device for qtest: \"%s\"" , - qtest_chrdev); -return ; - } +static bool qtest_server_start (Chardev *chr,const char *qtest_log,Error **errp) +{if (qtest_log) {if (strcmp (qtest_log,"none" ) !=0 ) { qtest_log_fp =fopen (qtest_log,"w+" );
@@ -869,7 +862,9 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** qtest_log_fp = stderr; } -qemu_chr_fe_init (&qtest_chr, chr, errp); +if (!qemu_chr_fe_init (&qtest_chr, chr, errp)) { +return false; + }qemu_chr_fe_set_handlers (&qtest_chr, qtest_can_read, qtest_read, qtest_event,NULL , &qtest_chr,NULL , true);qemu_chr_fe_set_echo (&qtest_chr, true);
@@ -879,8 +874,25 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **if (!qtest_server_send) {qtest_server_set_send_handler (qtest_server_char_be_send, &qtest_chr); } +return true; +} + +void qtest_server_init (const char *qtest_chrdev,const char *qtest_log,Error **errp) +{ +Chardev *chr; + + chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); + +if (chr ==NULL ) { +error_setg (errp,"Failed to initialize device for qtest: \"%s\"" , + qtest_chrdev); +return ; + } + +qtest_server_start (chr, qtest_log, errp); } +void qtest_server_set_send_handler (void (*send)(void *,const char *),void *opaque) {
@@ -905,3 +917,111 @@ void qtest_server_inproc_recv(void *dummy, const char *buf)g_string_truncate (gstr,0 ); } } + +#define TYPE_QTEST "qtest" + +OBJECT_DECLARE_SIMPLE_TYPE(QTest, QTEST) + +struct QTest { +Object parent; + +bool complete; +char *chr_name; +Chardev *chr; +char *log; +}; + +static void qtest_complete (UserCreatable *uc,Error **errp) +{ +QTest *q =QTEST (uc); +if (qtest_driver ()) { +error_setg (errp,"Only one instance of qtest can be created" ); +return ; + } +if (!q->chr_name) { +error_setg (errp,"No backend specified" ); +return ; + } + +if (!qtest_server_start (q->chr, q->log, errp)) { +return ; + } + q->complete = true; +} + +static void qtest_set_log (Object *obj,const char *value,Error **errp) +{ +QTest *q =QTEST (obj); + +if (q->complete) { +error_setg (errp,QERR_PERMISSION_DENIED ); + }else { +g_free (q->log); + q->log =g_strdup (value); + } +} + +static char *qtest_get_log (Object *obj,Error **errp) +{ +QTest *q =QTEST (obj); + +return g_strdup (q->log); +} + +static void qtest_set_chardev (Object *obj,const char *value,Error **errp) +{ +QTest *q =QTEST (obj); +Chardev *chr; + +if (q->complete) { +error_setg (errp,QERR_PERMISSION_DENIED ); +return ; + } + + chr =qemu_chr_find (value); +if (!chr) { +error_setg (errp,"Cannot find character device '%s'" , value); +return ; + } + +g_free (q->chr_name); + q->chr_name =g_strdup (value); + q->chr = chr; +} + +static char *qtest_get_chardev (Object *obj,Error **errp) +{ +QTest *q =QTEST (obj); + +return g_strdup (q->chr_name); +} + +static void qtest_class_init (ObjectClass *oc,void *data) +{ +UserCreatableClass *ucc =USER_CREATABLE_CLASS (oc); + + ucc->complete = qtest_complete; + +object_class_property_add_str (oc,"chardev" , + qtest_get_chardev, qtest_set_chardev); +object_class_property_add_str (oc,"log" , + qtest_get_log, qtest_set_log); +} + +static const TypeInfo qtest_info = { + .name =TYPE_QTEST , + .parent =TYPE_OBJECT , + .class_init = qtest_class_init, + .instance_size =sizeof (QTest), + .interfaces = (InterfaceInfo []) { + {TYPE_USER_CREATABLE }, + { } + } +}; + +static void register_types (void ) +{ +type_register_static (&qtest_info); +} + +type_init (register_types);
softmmu/vl.c +3 -2
@@ -1685,8 +1685,9 @@ static bool object_create_early(const char *type, QemuOpts *opts)* add one, state the reason in a comment! */ -/* Reason: rng-egd property "chardev" */ -if (g_str_equal (type,"rng-egd" )) { +/* Reason: property "chardev" */ +if (g_str_equal (type,"rng-egd" ) || +g_str_equal (type,"qtest" )) {return false; }
Signature · 1 line
2.26.2
Re: [PATCH 11/15] qtest: add a QOM object for qtest
Quoted 65 lines · On Wed, 2 Dec 2020 03:18:50 -0500 Paolo Bonzini <[email protected]> wrote:
The qtest server right now can only be created using the -qtest and -qtest-log options. Allow an alternative way to create it using "-object qtest,chardev=...,log=...".
Signed-off-by Paolo Bonzini <[email protected]>--- softmmu/qtest.c | 144 ++++++++++++++++++++++++++++++++++++++++++++---- softmmu/vl.c | 5 +- 2 files changed, 135 insertions(+), 14 deletions(-)softmmu/qtest.c +13
-12@@ -27,6 +27,8 @@#include "qemu/error-report.h" #include "qemu/module.h" #include "qemu/cutils.h" +#include "qapi/qmp/qerror.h" +#include "qom/object_interfaces.h" #include CONFIG_DEVICES #ifdef CONFIG_PSERIES #include "hw/ppc/spapr_rtas.h" @@ -849,18 +851,9 @@ static void qtest_event(void *opaque, QEMUChrEvent event)break ; } } -void qtest_server_init (const char *qtest_chrdev,const char *qtest_log,Error **errp) -{ -Chardev *chr; - - chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); - -if (chr ==NULL ) { -error_setg (errp,"Failed to initialize device for qtest: \"%s\"" , - qtest_chrdev); -return ; - } +static bool qtest_server_start (Chardev *chr,const char *qtest_log,Error **errp) +{if (qtest_log) {if (strcmp (qtest_log,"none" ) !=0 ) { qtest_log_fp =fopen (qtest_log,"w+" );@@ -869,7 +862,9 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** qtest_log_fp = stderr; } -qemu_chr_fe_init (&qtest_chr, chr, errp); +if (!qemu_chr_fe_init (&qtest_chr, chr, errp)) { +return false; + }qemu_chr_fe_set_handlers (&qtest_chr, qtest_can_read, qtest_read, qtest_event,NULL , &qtest_chr,NULL , true);qemu_chr_fe_set_echo (&qtest_chr, true);@@ -879,8 +874,25 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **if (!qtest_server_send) {qtest_server_set_send_handler (qtest_server_char_be_send, &qtest_chr); } +return true; +} + +void qtest_server_init (const char *qtest_chrdev,const char *qtest_log,Error **errp) +{ +Chardev *chr;
softmmu/qtest.c void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** · line 892
Quoted 10 lines
softmmu/qtest.c +10
-0+ + chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); + +if (chr ==NULL ) { +error_setg (errp,"Failed to initialize device for qtest: \"%s\"" , + qtest_chrdev); +return ; + } + +qtest_server_start (chr, qtest_log, errp);
why not create qtest object here instead of trying to preserve old way, or create it directly at the place that calls qtest_server_init()?
Quoted 134 lines
softmmu/qtest.c +109
-0} +void qtest_server_set_send_handler (void (*send)(void *,const char *),void *opaque) {@@ -905,3 +917,111 @@ void qtest_server_inproc_recv(void *dummy, const char *buf)g_string_truncate (gstr,0 ); } } + +#define TYPE_QTEST "qtest" + +OBJECT_DECLARE_SIMPLE_TYPE(QTest, QTEST) + +struct QTest { +Object parent; + +bool complete; +char *chr_name; +Chardev *chr; +char *log; +}; + +static void qtest_complete (UserCreatable *uc,Error **errp) +{ +QTest *q =QTEST (uc); +if (qtest_driver ()) { +error_setg (errp,"Only one instance of qtest can be created" ); +return ; + } +if (!q->chr_name) { +error_setg (errp,"No backend specified" ); +return ; + } + +if (!qtest_server_start (q->chr, q->log, errp)) { +return ; + } + q->complete = true; +} + +static void qtest_set_log (Object *obj,const char *value,Error **errp) +{ +QTest *q =QTEST (obj); + +if (q->complete) { +error_setg (errp,QERR_PERMISSION_DENIED ); + }else { +g_free (q->log); + q->log =g_strdup (value); + } +} + +static char *qtest_get_log (Object *obj,Error **errp) +{ +QTest *q =QTEST (obj); + +return g_strdup (q->log); +} + +static void qtest_set_chardev (Object *obj,const char *value,Error **errp) +{ +QTest *q =QTEST (obj); +Chardev *chr; + +if (q->complete) { +error_setg (errp,QERR_PERMISSION_DENIED ); +return ; + } + + chr =qemu_chr_find (value); +if (!chr) { +error_setg (errp,"Cannot find character device '%s'" , value); +return ; + } + +g_free (q->chr_name); + q->chr_name =g_strdup (value); + q->chr = chr; +} + +static char *qtest_get_chardev (Object *obj,Error **errp) +{ +QTest *q =QTEST (obj); + +return g_strdup (q->chr_name); +} + +static void qtest_class_init (ObjectClass *oc,void *data) +{ +UserCreatableClass *ucc =USER_CREATABLE_CLASS (oc); + + ucc->complete = qtest_complete; + +object_class_property_add_str (oc,"chardev" , + qtest_get_chardev, qtest_set_chardev); +object_class_property_add_str (oc,"log" , + qtest_get_log, qtest_set_log); +} + +static const TypeInfo qtest_info = { + .name =TYPE_QTEST , + .parent =TYPE_OBJECT , + .class_init = qtest_class_init, + .instance_size =sizeof (QTest), + .interfaces = (InterfaceInfo []) { + {TYPE_USER_CREATABLE }, + { } + } +}; + +static void register_types (void ) +{ +type_register_static (&qtest_info); +} + +type_init (register_types);softmmu/vl.c +3
-2@@ -1685,8 +1685,9 @@ static bool object_create_early(const char *type, QemuOpts *opts)* add one, state the reason in a comment! */ -/* Reason: rng-egd property "chardev" */ -if (g_str_equal (type,"rng-egd" )) { +/* Reason: property "chardev" */ +if (g_str_equal (type,"rng-egd" ) || +g_str_equal (type,"qtest" )) {return false; }
Re: [PATCH 11/15] qtest: add a QOM object for qtest
Quoted 7 lines · Igor Mammedov
Quoted 7 lines
softmmu/qtest.c +7
-0+void qtest_server_init (const char *qtest_chrdev,const char *qtest_log,Error **errp) +{ +Chardev *chr; + + chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); + +if (chr ==NULL ) {
Quoted 8 lines
softmmu/qtest.c void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** · line 892
Quoted 6 lines
softmmu/qtest.c +6
-0+error_setg (errp,"Failed to initialize device for qtest: \"%s\"" , + qtest_chrdev); +return ; + } + +qtest_server_start (chr, qtest_log, errp);why not create qtest object here instead of trying to preserve old way, or create it directly at the place that calls
qtest_server_init()?
Because I wasn't sure of where to put it in the QOM object tree. So I punted and left it for later.
Paolo
Re: [PATCH 11/15] qtest: add a QOM object for qtest
Quoted 17 lines · On Mon, 7 Dec 2020 17:43:16 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 7 lines · Igor Mammedov
Quoted 7 lines
softmmu/qtest.c +7
-0+void qtest_server_init (const char *qtest_chrdev,const char *qtest_log,Error **errp) +{ +Chardev *chr; + + chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); + +if (chr ==NULL ) {Quoted 8 lines
softmmu/qtest.c void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** · line 892
Quoted 6 lines
softmmu/qtest.c +6
-0+error_setg (errp,"Failed to initialize device for qtest: \"%s\"" , + qtest_chrdev); +return ; + } + +qtest_server_start (chr, qtest_log, errp);why not create qtest object here instead of trying to preserve old way, or create it directly at the place that calls
qtest_server_init()?
Quoted 2 lines
Because I wasn't sure of where to put it in the QOM object tree. So I punted and left it for later.
but you implicitly decided where it should be (with -object qtest), it goes to /objects.
So I'd wouldn't put anywhere else to be consistent.
Quoted 3 lines
Paolo
Re: [PATCH 11/15] qtest: add a QOM object for qtest
Il lun 7 dic 2020, 17:57 Igor Mammedov <[email protected]> ha scritto:
Quoted 22 lines
Quoted 2 lines · On Mon, 7 Dec 2020 17:43:16 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 1 line · Igor Mammedov
Quoted 1 line
+void qtest_server_init(const char
*qtest_chrdev, const char
*qtest_log, Error **errp)Quoted 7 lines
Quoted 7 lines
softmmu/qtest.c void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **
Quoted 7 lines
softmmu/qtest.c +7
-0+{ +Chardev *chr; + + chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); + +if (chr ==NULL ) { + error_setg(errp, "Failed to initialize device for qtest:\"%s\"",
Quoted 8 lines
Quoted 7 lines
softmmu/qtest.c void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** · line 892
Quoted 5 lines
softmmu/qtest.c +5
-0+ qtest_chrdev); +return ; + } + +qtest_server_start (chr, qtest_log, errp);why not create qtest object here instead of trying to preserve old way, or create it directly at the place that calls
qtest_server_init()?
Quoted 7 lines
Quoted 2 lines
Because I wasn't sure of where to put it in the QOM object tree. So I punted and left it for later.
but you implicitly decided where it should be (with -object qtest), it goes to /objects.
So I'd wouldn't put anywhere else to be consistent.
No, /objects is for stuff created with -object exclusively. I suppose I could have the "well-known path" be /machine/qtest, and it would be either a child (for -qtest) or a link to /objects/some-id (for -object qtest). Should I implement that (as a separate patch on top of this one)?
Paolo
Quoted 5 lines
Quoted 3 lines
Paolo
Re: [PATCH 11/15] qtest: add a QOM object for qtest
Quoted 32 lines · On Mon, 7 Dec 2020 18:22:55 +0100 Paolo Bonzini <[email protected]> wrote:
Il lun 7 dic 2020, 17:57 Igor Mammedov <[email protected]> ha scritto:
Quoted 22 lines
Quoted 2 lines · On Mon, 7 Dec 2020 17:43:16 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 1 line · Igor Mammedov
Quoted 1 line
+void qtest_server_init(const char
*qtest_chrdev, const char
*qtest_log, Error **errp)Quoted 7 lines
Quoted 7 lines
softmmu/qtest.c void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **
Quoted 7 lines
softmmu/qtest.c +7
-0+{ +Chardev *chr; + + chr =qemu_chr_new ("qtest" , qtest_chrdev,NULL ); + +if (chr ==NULL ) { + error_setg(errp, "Failed to initialize device for qtest:\"%s\"",
Quoted 8 lines
Quoted 7 lines
softmmu/qtest.c void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** · line 892
Quoted 5 lines
softmmu/qtest.c +5
-0+ qtest_chrdev); +return ; + } + +qtest_server_start (chr, qtest_log, errp);why not create qtest object here instead of trying to preserve old way, or create it directly at the place that calls
qtest_server_init()?Quoted 7 lines
Quoted 2 lines
Because I wasn't sure of where to put it in the QOM object tree. So I punted and left it for later.
but you implicitly decided where it should be (with -object qtest), it goes to /objects.
So I'd wouldn't put anywhere else to be consistent.
Quoted 4 lines
No, /objects is for stuff created with -object exclusively. I suppose I could have the "well-known path" be /machine/qtest, and it would be either a child (for -qtest) or a link to /objects/some-id (for -object qtest). Should I implement that (as a separate patch on top of this one)?
yes
Quoted 10 lines
Paolo
Quoted 5 lines
Quoted 3 lines
Paolo
PATCH 12/15 plugin: propagate errors
In reply to Paolo Bonziniqemu_finish_machine_init currently can only exit QEMU if it fails. Prepare for giving it proper error propagation, and possibly for adding a plugin_add monitor command that calls an accelerator method.
While at it, make all errors from plugin_load look the same.
--- include/qemu/plugin.h | 4 ++-- linux-user/main.c | 4 +--- plugins/loader.c | 34 +++++++++++++++++----------------- softmmu/vl.c | 4 +--- 4 files changed, 21 insertions(+), 25 deletions(-)
include/qemu/plugin.h +2 -2
@@ -45,7 +45,7 @@ static inline void qemu_plugin_add_opts(void) }void qemu_plugin_opt_parse (const char *optarg,QemuPluginList *head); -int qemu_plugin_load_list (QemuPluginList *head); +int qemu_plugin_load_list (QemuPluginList *head,Error **errp);union qemu_plugin_cb_sig {qemu_plugin_simple_cb_t simple;
@@ -199,7 +199,7 @@ static inline void qemu_plugin_opt_parse(const char *optarg,exit (1 ); } -static inline int qemu_plugin_load_list (QemuPluginList *head) +static inline int qemu_plugin_load_list (QemuPluginList *head,Error **errp) {return 0 ; }
linux-user/main.c +1 -3
@@ -671,9 +671,7 @@ int main(int argc, char **argv, char **envp)exit (1 ); }trace_init_file (); -if (qemu_plugin_load_list (&plugins)) { -exit (1 ); - } +qemu_plugin_load_list (&plugins, &error_fatal);/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
plugins/loader.c +17 -17
@@ -150,7 +150,7 @@ static uint64_t xorshift64star(uint64_t x)return x *UINT64_C (2685821657736338717 ); } -static int plugin_load (struct qemu_plugin_desc *desc,const qemu_info_t *info) +static int plugin_load (struct qemu_plugin_desc *desc,const qemu_info_t *info,Error **errp) {qemu_plugin_install_func_t install;struct qemu_plugin_ctx *ctx;
@@ -163,37 +163,37 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info) ctx->handle =g_module_open (desc->path,G_MODULE_BIND_LOCAL );if (ctx->handle ==NULL ) { -error_report ("%s: %s" , __func__,g_module_error ()); +error_setg (errp,"Could not load plugin %s: %s" , desc->path,g_module_error ()); goto err_dlopen; }if (!g_module_symbol (ctx->handle,"qemu_plugin_install" , &sym)) { -error_report ("%s: %s" , __func__,g_module_error ()); +error_setg (errp,"Could not load plugin %s: %s" , desc->path,g_module_error ()); goto err_symbol; } install = (qemu_plugin_install_func_t ) sym;/* symbol was found; it could be NULL though */ if (install ==NULL ) { -error_report ("%s: %s: qemu_plugin_install is NULL" , - __func__, desc->path); +error_setg (errp,"Could not load plugin %s: qemu_plugin_install is NULL" , + desc->path); goto err_symbol; }if (!g_module_symbol (ctx->handle,"qemu_plugin_version" , &sym)) { -error_report ("TCG plugin %s does not declare API version %s" , - desc->path,g_module_error ()); +error_setg (errp,"Could not load plugin %s: plugin does not declare API version %s" , + desc->path,g_module_error ()); goto err_symbol; }else {int version = *(int *)sym;if (version <QEMU_PLUGIN_MIN_VERSION ) { -error_report ("TCG plugin %s requires API version %d, but " -"this QEMU supports only a minimum version of %d" , - desc->path, version,QEMU_PLUGIN_MIN_VERSION ); +error_setg (errp,"Could not load plugin %s: plugin requires API version %d, but " +"this QEMU supports only a minimum version of %d" , + desc->path, version,QEMU_PLUGIN_MIN_VERSION ); goto err_symbol; }else if (version >QEMU_PLUGIN_VERSION ) { -error_report ("TCG plugin %s requires API version %d, but " -"this QEMU supports only up to version %d" , - desc->path, version,QEMU_PLUGIN_VERSION ); +error_setg (errp,"Could not load plugin %s: plugin requires API version %d, but " +"this QEMU supports only up to version %d" , + desc->path, version,QEMU_PLUGIN_VERSION ); goto err_symbol; } }
@@ -220,8 +220,8 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info) rc =install (ctx->id, info, desc->argc, desc->argv); ctx->installing = false;if (rc) { -error_report ("%s: qemu_plugin_install returned error code %d" , - __func__, rc); +error_setg (errp,"Could not load plugin %s: qemu_plugin_install returned error code %d" , + desc->path, rc);/* * we cannot rely on the plugin doing its own cleanup, so * call a full uninstall if the plugin did not yet call it.
@@ -263,7 +263,7 @@ static void plugin_desc_free(struct qemu_plugin_desc *desc)* Note: the descriptor of each successfully installed plugin is removed * from the list given by @head. */ -int qemu_plugin_load_list (QemuPluginList *head) +int qemu_plugin_load_list (QemuPluginList *head,Error **errp) {struct qemu_plugin_desc *desc, *next; g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
@@ -283,7 +283,7 @@ int qemu_plugin_load_list(QemuPluginList *head) QTAILQ_FOREACH_SAFE(desc, head, entry, next) {int err; - err =plugin_load (desc, info); + err =plugin_load (desc, info, errp);if (err) {return err; }
softmmu/vl.c +1 -3
@@ -2417,9 +2417,7 @@ static void qemu_init_board(void) }/* process plugin before CPUs are created, but once -smp has been parsed */ -if (qemu_plugin_load_list (&plugin_list)) { -exit (1 ); - } +qemu_plugin_load_list (&plugin_list, &error_fatal);/* From here on we enter MACHINE_PHASE_INITIALIZED. */ machine_run_board_init (current_machine);
Signature · 1 line
2.26.2
Re: [PATCH 12/15] plugin: propagate errors
Quoted 8 lines · Paolo Bonzini
qemu_finish_machine_initcurrently can only exit QEMU if it fails. Prepare for giving it proper error propagation, and possibly for adding aplugin_addmonitor command that calls an accelerator method.While at it, make all errors from
plugin_loadlook the same.Signed-off-by Paolo Bonzini <[email protected]>
Signature · 1 line
Alex Bennée
Re: [PATCH 12/15] plugin: propagate errors
In reply to Paolo BonziniQuoted 8 lines · On Wed, 2 Dec 2020 03:18:51 -0500 Paolo Bonzini <[email protected]> wrote:
qemu_finish_machine_initcurrently can only exit QEMU if it fails. Prepare for giving it proper error propagation, and possibly for adding aplugin_addmonitor command that calls an accelerator method.While at it, make all errors from
plugin_loadlook the same.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 151 lines
--- include/qemu/plugin.h | 4 ++-- linux-user/main.c | 4 +--- plugins/loader.c | 34 +++++++++++++++++----------------- softmmu/vl.c | 4 +--- 4 files changed, 21 insertions(+), 25 deletions(-)include/qemu/plugin.h +2
-2@@ -45,7 +45,7 @@ static inline void qemu_plugin_add_opts(void) }void qemu_plugin_opt_parse (const char *optarg,QemuPluginList *head); -int qemu_plugin_load_list (QemuPluginList *head); +int qemu_plugin_load_list (QemuPluginList *head,Error **errp);union qemu_plugin_cb_sig {qemu_plugin_simple_cb_t simple;@@ -199,7 +199,7 @@ static inline void qemu_plugin_opt_parse(const char *optarg,exit (1 ); } -static inline int qemu_plugin_load_list (QemuPluginList *head) +static inline int qemu_plugin_load_list (QemuPluginList *head,Error **errp) {return 0 ; }linux-user/main.c +1
-3@@ -671,9 +671,7 @@ int main(int argc, char **argv, char **envp)exit (1 ); }trace_init_file (); -if (qemu_plugin_load_list (&plugins)) { -exit (1 ); - } +qemu_plugin_load_list (&plugins, &error_fatal);/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));plugins/loader.c +17
-17@@ -150,7 +150,7 @@ static uint64_t xorshift64star(uint64_t x)return x *UINT64_C (2685821657736338717 ); } -static int plugin_load (struct qemu_plugin_desc *desc,const qemu_info_t *info) +static int plugin_load (struct qemu_plugin_desc *desc,const qemu_info_t *info,Error **errp) {qemu_plugin_install_func_t install;struct qemu_plugin_ctx *ctx;@@ -163,37 +163,37 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info) ctx->handle =g_module_open (desc->path,G_MODULE_BIND_LOCAL );if (ctx->handle ==NULL ) { -error_report ("%s: %s" , __func__,g_module_error ()); +error_setg (errp,"Could not load plugin %s: %s" , desc->path,g_module_error ()); goto err_dlopen; }if (!g_module_symbol (ctx->handle,"qemu_plugin_install" , &sym)) { -error_report ("%s: %s" , __func__,g_module_error ()); +error_setg (errp,"Could not load plugin %s: %s" , desc->path,g_module_error ()); goto err_symbol; } install = (qemu_plugin_install_func_t ) sym;/* symbol was found; it could be NULL though */ if (install ==NULL ) { -error_report ("%s: %s: qemu_plugin_install is NULL" , - __func__, desc->path); +error_setg (errp,"Could not load plugin %s: qemu_plugin_install is NULL" , + desc->path); goto err_symbol; }if (!g_module_symbol (ctx->handle,"qemu_plugin_version" , &sym)) { -error_report ("TCG plugin %s does not declare API version %s" , - desc->path,g_module_error ()); +error_setg (errp,"Could not load plugin %s: plugin does not declare API version %s" , + desc->path,g_module_error ()); goto err_symbol; }else {int version = *(int *)sym;if (version <QEMU_PLUGIN_MIN_VERSION ) { -error_report ("TCG plugin %s requires API version %d, but " -"this QEMU supports only a minimum version of %d" , - desc->path, version,QEMU_PLUGIN_MIN_VERSION ); +error_setg (errp,"Could not load plugin %s: plugin requires API version %d, but " +"this QEMU supports only a minimum version of %d" , + desc->path, version,QEMU_PLUGIN_MIN_VERSION ); goto err_symbol; }else if (version >QEMU_PLUGIN_VERSION ) { -error_report ("TCG plugin %s requires API version %d, but " -"this QEMU supports only up to version %d" , - desc->path, version,QEMU_PLUGIN_VERSION ); +error_setg (errp,"Could not load plugin %s: plugin requires API version %d, but " +"this QEMU supports only up to version %d" , + desc->path, version,QEMU_PLUGIN_VERSION ); goto err_symbol; } }@@ -220,8 +220,8 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info) rc =install (ctx->id, info, desc->argc, desc->argv); ctx->installing = false;if (rc) { -error_report ("%s: qemu_plugin_install returned error code %d" , - __func__, rc); +error_setg (errp,"Could not load plugin %s: qemu_plugin_install returned error code %d" , + desc->path, rc);/* * we cannot rely on the plugin doing its own cleanup, so * call a full uninstall if the plugin did not yet call it. @@ -263,7 +263,7 @@ static void plugin_desc_free(struct qemu_plugin_desc *desc)* Note: the descriptor of each successfully installed plugin is removed * from the list given by @head. */ -int qemu_plugin_load_list (QemuPluginList *head) +int qemu_plugin_load_list (QemuPluginList *head,Error **errp) {struct qemu_plugin_desc *desc, *next; g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);@@ -283,7 +283,7 @@ int qemu_plugin_load_list(QemuPluginList *head) QTAILQ_FOREACH_SAFE(desc, head, entry, next) {int err; - err =plugin_load (desc, info); + err =plugin_load (desc, info, errp);if (err) {return err; }softmmu/vl.c +1
-3@@ -2417,9 +2417,7 @@ static void qemu_init_board(void) }/* process plugin before CPUs are created, but once -smp has been parsed */ -if (qemu_plugin_load_list (&plugin_list)) { -exit (1 ); - } +qemu_plugin_load_list (&plugin_list, &error_fatal);/* From here on we enter MACHINE_PHASE_INITIALIZED. */ machine_run_board_init (current_machine);
PATCH 13/15 memory: allow creating MemoryRegions before accelerators
In reply to Paolo BonziniCompute the DIRTY_MEMORY_CODE bit in memory_region_get_dirty_log_mask instead of memory_region_init_*. This makes it possible to allocate memory backend objects at any time.
--- softmmu/memory.c | 12 ++++++------ softmmu/vl.c | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-)
softmmu/memory.c +6 -6
@@ -1548,7 +1548,6 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc (size, share, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));
@@ -1573,7 +1572,6 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc_resizeable (size, max_size, resized, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));
@@ -1598,7 +1596,6 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->align = align; mr->ram_block =qemu_ram_alloc_from_file (size, mr, ram_flags, path, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));
@@ -1622,7 +1619,6 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->ram_block =qemu_ram_alloc_from_fd (size, mr, share ?RAM_SHARED :0 , fd, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));
@@ -1641,7 +1637,6 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL );
@@ -1661,7 +1656,7 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr, mr->ops = &ram_device_mem_ops; mr->opaque = mr; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; +/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL ); mr->ram_block =qemu_ram_alloc_from_ptr (size, ptr, mr, &error_fatal);
@@ -1819,6 +1814,11 @@ uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) memory_region_is_iommu(mr))) { mask |= (1 <<DIRTY_MEMORY_MIGRATION ); } + +if (tcg_enabled () && rb) { +/* TCG only cares about dirty memory logging for RAM, not IOMMU. */ + mask |= (1 <<DIRTY_MEMORY_CODE ); + }return mask; }
softmmu/vl.c +1 -5
@@ -1715,11 +1715,7 @@ static bool object_create_early(const char *type, QemuOpts *opts)return false; } -/* Memory allocation by backends needs to be done -* after configure_accelerator() (due to the tcg_enabled() -* checks at memory_region_init_*()). -* -* Also, allocation of large amounts of memory may delay +/* Allocation of large amounts of memory may delay * chardev initialization for too long, and trigger timeouts * on software that waits for a monitor socket to be created * (e.g. libvirt).
Signature · 1 line
2.26.2
Re: [PATCH 13/15] memory: allow creating MemoryRegions before accelerators
Quoted 64 lines · On Wed, 2 Dec 2020 03:18:52 -0500 Paolo Bonzini <[email protected]> wrote:
Compute the
DIRTY_MEMORY_CODEbit inmemory_region_get_dirty_log_maskinstead of memory_region_init_*. This makes it possible to allocate memory backend objects at any time.Signed-off-by Paolo Bonzini <[email protected]>--- softmmu/memory.c | 12 ++++++------ softmmu/vl.c | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-)softmmu/memory.c +1
-6@@ -1548,7 +1548,6 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc (size, share, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1573,7 +1572,6 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc_resizeable (size, max_size, resized, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1598,7 +1596,6 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->align = align; mr->ram_block =qemu_ram_alloc_from_file (size, mr, ram_flags, path, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1622,7 +1619,6 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->ram_block =qemu_ram_alloc_from_fd (size, mr, share ?RAM_SHARED :0 , fd, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1641,7 +1637,6 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL );@@ -1661,7 +1656,7 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr, mr->ops = &ram_device_mem_ops; mr->opaque = mr; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; +/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL ); mr->ram_block =qemu_ram_alloc_from_ptr (size, ptr, mr, &error_fatal);
softmmu/memory.c uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) · line 1823
Quoted 10 lines
softmmu/memory.c +5
-0@@ -1819,6 +1814,11 @@ uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) memory_region_is_iommu(mr))) { mask |= (1 <<DIRTY_MEMORY_MIGRATION ); } + +if (tcg_enabled () && rb) { +/* TCG only cares about dirty memory logging for RAM, not IOMMU. */ + mask |= (1 <<DIRTY_MEMORY_CODE ); + }return mask; }
Is following also necessary?:
softmmu/memory.c +2 -1
@@ -2033,7 +2033,8 @@ void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) }memory_region_transaction_begin (); - mr->dirty_log_mask = (mr->dirty_log_mask & ~mask) | (log * mask); + mr->dirty_log_mask = (memory_region_get_dirty_log_mask (mr) & ~mask) | + (log * mask); memory_region_update_pending |= mr->enabled;memory_region_transaction_commit (); }
Quoted 18 lines
softmmu/vl.c +1
-5@@ -1715,11 +1715,7 @@ static bool object_create_early(const char *type, QemuOpts *opts)return false; } -/* Memory allocation by backends needs to be done -* after configure_accelerator() (due to the tcg_enabled() -* checks at memory_region_init_*()). -* -* Also, allocation of large amounts of memory may delay +/* Allocation of large amounts of memory may delay * chardev initialization for too long, and trigger timeouts * on software that waits for a monitor socket to be created * (e.g. libvirt).
Re: [PATCH 13/15] memory: allow creating MemoryRegions before accelerators
Quoted 85 lines · Igor Mammedov
Quoted 64 lines · On Wed, 2 Dec 2020 03:18:52 -0500 Paolo Bonzini <[email protected]> wrote:
Compute the
DIRTY_MEMORY_CODEbit inmemory_region_get_dirty_log_maskinstead of memory_region_init_*. This makes it possible to allocate memory backend objects at any time.Signed-off-by Paolo Bonzini <[email protected]>--- softmmu/memory.c | 12 ++++++------ softmmu/vl.c | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-)softmmu/memory.c +1
-6@@ -1548,7 +1548,6 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc (size, share, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1573,7 +1572,6 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc_resizeable (size, max_size, resized, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1598,7 +1596,6 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->align = align; mr->ram_block =qemu_ram_alloc_from_file (size, mr, ram_flags, path, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1622,7 +1619,6 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->ram_block =qemu_ram_alloc_from_fd (size, mr, share ?RAM_SHARED :0 , fd, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1641,7 +1637,6 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL );@@ -1661,7 +1656,7 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr, mr->ops = &ram_device_mem_ops; mr->opaque = mr; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; +/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL ); mr->ram_block =qemu_ram_alloc_from_ptr (size, ptr, mr, &error_fatal);softmmu/memory.c uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) · line 1823
Quoted 10 lines
softmmu/memory.c +5
-0@@ -1819,6 +1814,11 @@ uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) memory_region_is_iommu(mr))) { mask |= (1 <<DIRTY_MEMORY_MIGRATION ); } + +if (tcg_enabled () && rb) { +/* TCG only cares about dirty memory logging for RAM, not IOMMU. */ + mask |= (1 <<DIRTY_MEMORY_CODE ); + }return mask; }Is following also necessary?:
softmmu/memory.c +0
-0
softmmu/memory.c void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) · line 2040
Quoted 9 lines
softmmu/memory.c +2
-1@@ -2033,7 +2033,8 @@ void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) }memory_region_transaction_begin (); - mr->dirty_log_mask = (mr->dirty_log_mask & ~mask) | (log * mask); + mr->dirty_log_mask = (memory_region_get_dirty_log_mask (mr) & ~mask) | + (log * mask); memory_region_update_pending |= mr->enabled;memory_region_transaction_commit (); }
No, 1 << DIRTY_MEMORY_CODE moves altogether from mr->dirty_log_mask to being only in the return value of memory_region_get_dirty_log_mask.
Paolo
Quoted 19 lines
Quoted 18 lines
softmmu/vl.c +1
-5@@ -1715,11 +1715,7 @@ static bool object_create_early(const char *type, QemuOpts *opts)return false; } -/* Memory allocation by backends needs to be done -* after configure_accelerator() (due to the tcg_enabled() -* checks at memory_region_init_*()). -* -* Also, allocation of large amounts of memory may delay +/* Allocation of large amounts of memory may delay * chardev initialization for too long, and trigger timeouts * on software that waits for a monitor socket to be created * (e.g. libvirt).
Re: [PATCH 13/15] memory: allow creating MemoryRegions before accelerators
In reply to Paolo BonziniQuoted 3 lines · On Wed, 2 Dec 2020 03:18:52 -0500 Paolo Bonzini <[email protected]> wrote:
Compute the
DIRTY_MEMORY_CODEbit inmemory_region_get_dirty_log_maskinstead of memory_region_init_*. This makes it possible to allocate memory backend objects at any time.
Quoted 88 lines
Signed-off-by Paolo Bonzini <[email protected]>--- softmmu/memory.c | 12 ++++++------ softmmu/vl.c | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-)softmmu/memory.c +6
-6@@ -1548,7 +1548,6 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc (size, share, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1573,7 +1572,6 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->ram_block =qemu_ram_alloc_resizeable (size, max_size, resized, mr, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1598,7 +1596,6 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->destructor = memory_region_destructor_ram; mr->align = align; mr->ram_block =qemu_ram_alloc_from_file (size, mr, ram_flags, path, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1622,7 +1619,6 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->ram_block =qemu_ram_alloc_from_fd (size, mr, share ?RAM_SHARED :0 , fd, &err); - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;if (err) { mr->size =int128_zero ();object_unparent (OBJECT (mr));@@ -1641,7 +1637,6 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ;/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL );@@ -1661,7 +1656,7 @@ void memory_region_init_ram_device_ptr(MemoryRegion *mr, mr->ops = &ram_device_mem_ops; mr->opaque = mr; mr->destructor = memory_region_destructor_ram; - mr->dirty_log_mask =tcg_enabled () ? (1 <<DIRTY_MEMORY_CODE ) :0 ; +/* qemu_ram_alloc_from_ptr cannot fail with ptr != NULL. */ assert (ptr !=NULL ); mr->ram_block =qemu_ram_alloc_from_ptr (size, ptr, mr, &error_fatal);@@ -1819,6 +1814,11 @@ uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) memory_region_is_iommu(mr))) { mask |= (1 <<DIRTY_MEMORY_MIGRATION ); } + +if (tcg_enabled () && rb) { +/* TCG only cares about dirty memory logging for RAM, not IOMMU. */ + mask |= (1 <<DIRTY_MEMORY_CODE ); + }return mask; }softmmu/vl.c +1
-5@@ -1715,11 +1715,7 @@ static bool object_create_early(const char *type, QemuOpts *opts)return false; } -/* Memory allocation by backends needs to be done -* after configure_accelerator() (due to the tcg_enabled() -* checks at memory_region_init_*()). -* -* Also, allocation of large amounts of memory may delay +/* Allocation of large amounts of memory may delay * chardev initialization for too long, and trigger timeouts * on software that waits for a monitor socket to be created * (e.g. libvirt).
PATCH 14/15 null-machine: do not create a default memdev
In reply to Paolo BonziniThe default RAM size is 0, so no RAM will be created anyway.
--- hw/core/null-machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/null-machine.c +1 -1
@@ -49,7 +49,7 @@ static void machine_none_machine_init(MachineClass *mc) mc->init = machine_none_init; mc->max_cpus =1 ; mc->default_ram_size =0 ; - mc->default_ram_id ="ram" ; + mc->default_ram_id =NULL ; mc->no_serial =1 ; mc->no_parallel =1 ; mc->no_floppy =1 ;
Signature · 1 line
2.26.2
Re: [PATCH 14/15] null-machine: do not create a default memdev
Quoted 12 lines · On Wed, 2 Dec 2020 03:18:53 -0500 Paolo Bonzini <[email protected]> wrote:
The default RAM size is 0, so no RAM will be created anyway.
Signed-off-by Paolo Bonzini <[email protected]>--- hw/core/null-machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/core/null-machine.c +0
-0
hw/core/null-machine.c static void machine_none_machine_init(MachineClass *mc) · line 52
Quoted 5 lines
hw/core/null-machine.c +1
-1@@ -49,7 +49,7 @@ static void machine_none_machine_init(MachineClass *mc) mc->init = machine_none_init; mc->max_cpus =1 ; mc->default_ram_size =0 ; - mc->default_ram_id ="ram" ; + mc->default_ram_id =NULL ;
probably that will break:
QEMU -m X -M none
maybe there is a bug over there but
"mc->default_ram_size = 0"
above, should result in
current_machine->ram_size == 0in case user hasn't provided "-m"
and hence memdev shouldn't be created
Quoted 3 lines
hw/core/null-machine.c +0
-0mc->no_serial =1 ; mc->no_parallel =1 ; mc->no_floppy =1 ;
Re: [PATCH 14/15] null-machine: do not create a default memdev
Quoted 6 lines · Igor Mammedov
hw/core/null-machine.c static void machine_none_machine_init(MachineClass *mc) · line 52
Quoted 3 lines
mc->default_ram_size = 0;hw/core/null-machine.c +1
-1- mc->default_ram_id ="ram" ; + mc->default_ram_id =NULL ;probably that will break:
QEMU -m X -M none
No, it works. "-m" is simply ignored, because the default memdev is created here:
if (machine_class->default_ram_id && current_machine->ram_size &&
numa_uses_legacy_mem() && !current_machine->ram_memdev_id) {
create_default_memdev(current_machine, mem_path);
}and is thus skipped for -M none.
Paolo
Quoted 8 lines
maybe there is a bug over there but
"mc->default_ram_size = 0" above, should result in current_machine->ram_size == 0in case user hasn't provided "-m"
and hence memdev shouldn't be created
Re: [PATCH 14/15] null-machine: do not create a default memdev
Quoted 10 lines · On Sat, 12 Dec 2020 00:24:25 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 6 lines · Igor Mammedov
hw/core/null-machine.c static void machine_none_machine_init(MachineClass *mc) · line 52
Quoted 3 lines
mc->default_ram_size = 0;hw/core/null-machine.c +1
-1- mc->default_ram_id ="ram" ; + mc->default_ram_id =NULL ;probably that will break:
QEMU -m X -M none
No, it works. "-m" is simply ignored, because the default memdev is created here:
you mean it doesn't explode.
By default with current code memdev should not be created, but it is created if users asks for it with -m. This patch breaks the later.
I'm not sure that any RAM on null machine is of any use at all but the if we decide to get rid of it completely, then we need to clean up
/* RAM at address zero */
if (mch->ram) {
memory_region_add_subregion(get_system_memory(), 0, mch->ram);
} and commit title/message should match what patch does and why.
Quoted 18 lines
if (machine_class->default_ram_id && current_machine->ram_size && numa_uses_legacy_mem() && !current_machine->ram_memdev_id) { create_default_memdev(current_machine, mem_path); }and is thus skipped for -M none.
Paolo
Quoted 8 lines
maybe there is a bug over there but
"mc->default_ram_size = 0" above, should result in current_machine->ram_size == 0in case user hasn't provided "-m"
and hence memdev shouldn't be created
Re: [PATCH 14/15] null-machine: do not create a default memdev
Quoted 9 lines · Igor Mammedov
Quoted 6 lines · On Sat, 12 Dec 2020 00:24:25 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 5 lines · Igor Mammedov
hw/core/null-machine.c static void machine_none_machine_init(MachineClass *mc) · line 52
Quoted 3 lines
mc->default_ram_size = 0;hw/core/null-machine.c +1
-1- mc->default_ram_id ="ram" ; + mc->default_ram_id =NULL ;probably that will break:
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
QEMU -m X -M none
No, it works. "-m" is simply ignored, because the default memdev is created here:
you mean it doesn't explode.
By default with current code memdev should not be created, but it is created if users asks for it with -m.
Oh ok, got it. I'll leave this patch aside for now and later, when I get round to posting the ram_memdev_id cleanup, try to remember why I added it.
Quoted 7 lines
I'm not sure that any RAM on null machine is of any use at all but the if we decide to get rid of it completely, then we need to clean up
/* RAM at address zero */ if (mch->ram) { memory_region_add_subregion(get_system_memory(), 0, mch->ram); }
This would still be needed because you _can_ get a non-null mch->ram (via "-M memdev") even if mc->default_ram_id == NULL.
Paolo
Quoted 22 lines
and commit title/message should match what patch does and why.
Quoted 18 lines
if (machine_class->default_ram_id && current_machine->ram_size && numa_uses_legacy_mem() && !current_machine->ram_memdev_id) { create_default_memdev(current_machine, mem_path); }and is thus skipped for -M none.
Paolo
Quoted 8 lines
maybe there is a bug over there but
"mc->default_ram_size = 0" above, should result in current_machine->ram_size == 0in case user hasn't provided "-m"
and hence memdev shouldn't be created
PATCH 15/15 monitor: allow quitting while in preconfig state
In reply to Paolo Bonzini--- hmp-commands.hx | 1 + qapi/control.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
hmp-commands.hx +1 -0
@@ -45,6 +45,7 @@ ERST .params = "", .help = "quit the emulator", .cmd = hmp_quit, + .flags = "p", }, SRST
qapi/control.json +2 -1
@@ -219,7 +219,8 @@ # -> { "execute": "quit" } # <- { "return": {} } ## -{ 'command': 'quit' } +{ 'command': 'quit', + 'allow-preconfig': true } ## # @MonitorMode:
Signature · 1 line
2.26.2
Re: [PATCH 15/15] monitor: allow quitting while in preconfig state
Quoted 1 line · On Wed, 2 Dec 2020 03:18:54 -0500 Paolo Bonzini <[email protected]> wrote:
Signed-off-by Paolo Bonzini <[email protected]>
Quoted 31 lines
--- hmp-commands.hx | 1 + qapi/control.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)hmp-commands.hx +1
-0@@ -45,6 +45,7 @@ ERST .params = "", .help = "quit the emulator", .cmd = hmp_quit, + .flags = "p", }, SRSTqapi/control.json +2
-1@@ -219,7 +219,8 @@ # -> { "execute": "quit" } # <- { "return": {} } ## -{ 'command': 'quit' } +{ 'command': 'quit', + 'allow-preconfig': true } ## # @MonitorMode:
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH 00/15] Finish cleaning up qemu_init
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
450811f monitor: allow quitting while in preconfig state dce3fd5 null-machine: do not create a default memdev e52482a memory: allow creating MemoryRegions before accelerators e951562 plugin: propagate errors
c29889b qtest: add a QOM object for qtest
f7526bf vl: make qemu_get_machine_opts static
5f1f6d1 machine: record whether nvdimm= was set 8e65049 machine: introduce MachineInitPhase
7c4cb1c chardev: do not use machine_init_done
0f1597f vl: move all generic initialization out of vl.c c55f69e vl: extract softmmu/globals.c
6df0eeb vl: extract softmmu/runstate.c
1c6bebb vl: allow -incoming defer with -preconfig 893660d vl: remove separate preconfig main_loop a028d58 remove preconfig state
=== OUTPUT BEGIN ===
1/15 Checking commit a028d58a8e83 (remove preconfig state)
ERROR: suspect code indent for conditional statements (4, 9) #27: FILE: hw/core/machine-qmp-cmds.c:289:
+ if (qdev_hotplug) {
+ error_setg(errp, "The command is permitted only before the machine has been created");
ERROR: line over 90 characters
#28: FILE: hw/core/machine-qmp-cmds.c:290:
+ error_setg(errp, "The command is permitted only before the machine has been created");
WARNING: line over 80 characters
#88: FILE: monitor/qmp-cmds.c:108:
+ error_setg(errp, "The command is permitted only before machine initialization");
ERROR: line over 90 characters
#150: FILE: softmmu/qdev-monitor.c:1006:
+ error_setg(errp, "The command '%s' is permitted only after machine initialization has completed",
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #207:
new file mode 100644
total: 3 errors, 2 warnings, 155 lines checked
Patch 1/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
2/15 Checking commit 893660defe11 (vl: remove separate preconfig main_loop)
WARNING: line over 80 characters
#93: FILE: softmmu/vl.c:3279:
+ error_setg(errp, "The command is permitted only before machine initialization");
total: 0 errors, 1 warnings, 161 lines checked
Patch 2/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/15 Checking commit 1c6bebbd00e1 (vl: allow -incoming defer with -preconfig) 4/15 Checking commit 6df0eeb3c804 (vl: extract softmmu/runstate.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #46:
new file mode 100644
WARNING: Block comments use a leading /* on a separate line #422: FILE: softmmu/runstate.c:372:
+ /* This happens for eg ^C at the terminal, so it's worth
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead #532: FILE: softmmu/runstate.c:482:
+ qemu_log_mask(LOG_GUEST_ERROR, "\nHV crash parameters: (%#"PRIx64
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead #533: FILE: softmmu/runstate.c:483:
+ " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n",
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead #533: FILE: softmmu/runstate.c:483:
+ " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n",
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead #533: FILE: softmmu/runstate.c:483:
+ " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n",
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x' prefix instead #533: FILE: softmmu/runstate.c:483:
+ " %#"PRIx64" %#"PRIx64" %#"PRIx64" %#"PRIx64")\n",
WARNING: Block comments use a leading /* on a separate line #646: FILE: softmmu/runstate.c:596:
+ /* Cannot call qemu_system_shutdown_request directly because
total: 5 errors, 3 warnings, 1585 lines checked
Patch 4/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/15 Checking commit c55f69ec8bed (vl: extract softmmu/globals.c)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #50:
new file mode 100644
ERROR: "foo* bar" should be "foo *bar"
#92: FILE: softmmu/globals.c:38:
+const char* keyboard_layout;
WARNING: Block comments use a leading /* on a separate line
#120: FILE: softmmu/globals.c:66:
+/* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in the
total: 1 errors, 2 warnings, 184 lines checked
Patch 5/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/15 Checking commit 0f1597fd687a (vl: move all generic initialization out of vl.c)
WARNING: line over 80 characters
#56: FILE: hw/core/machine.c:1200:
+ qemu_register_reset(restore_boot_order, g_strdup(current_machine->boot_order));
WARNING: Block comments use a leading /* on a separate line #66: FILE: hw/core/machine.c:1210:
+ /* TODO: once all bus devices are qdevified, this should be done
WARNING: Block comments use a trailing */ on a separate line #67: FILE: hw/core/machine.c:1211:
+ * when bus is created by qdev.c */
WARNING: Block comments use a leading /* on a separate line #88: FILE: hw/core/machine.c:1232:
+ /* This checkpoint is required by replay to separate prior clock
WARNING: Block comments use * on subsequent lines
#89: FILE: hw/core/machine.c:1233:
+ /* This checkpoint is required by replay to separate prior clock
+ reading from the other reads, because timer polling functions query
WARNING: Block comments use a trailing */ on a separate line #90: FILE: hw/core/machine.c:1234:
+ clock values from the log. */
total: 0 errors, 6 warnings, 164 lines checked
Patch 6/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
7/15 Checking commit 7c4cb1ca1ada (chardev: do not use machine_init_done)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #109:
deleted file mode 100644
total: 0 errors, 1 warnings, 142 lines checked
Patch 7/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/15 Checking commit 8e65049a2eac (machine: introduce MachineInitPhase)
ERROR: line over 90 characters
#27: FILE: hw/core/machine-qmp-cmds.c:290:
+ error_setg(errp, "The command is permitted only before the machine has been created");
WARNING: line over 80 characters
#232: FILE: softmmu/qdev-monitor.c:640:
+ if ((hide || phase_check(PHASE_MACHINE_READY)) && bus && !qbus_is_hotpluggable(bus)) {
WARNING: line over 80 characters
#254: FILE: softmmu/qdev-monitor.c:664:
+ /* No bus, no machine hotplug handler --> device is not hotpluggable */
WARNING: line over 80 characters
#255: FILE: softmmu/qdev-monitor.c:665:
+ error_setg(errp, "Device '%s' can not be hotplugged on this machine",
WARNING: line over 80 characters
#327: FILE: ui/console.c:1348:
+ } else if (console_type != GRAPHIC_CONSOLE || phase_check(PHASE_MACHINE_READY)) {
total: 1 errors, 4 warnings, 250 lines checked
Patch 8/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
9/15 Checking commit 5f1f6d1df6e6 (machine: record whether nvdimm= was set) 10/15 Checking commit f7526bf54d78 (vl: make qemu_get_machine_opts static)
WARNING: line over 80 characters
#33: FILE: accel/kvm/kvm-all.c:2072:
+ g_autofree char *kvm_type = object_property_get_str(OBJECT(current_machine),
total: 0 errors, 1 warnings, 195 lines checked
Patch 10/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/15 Checking commit c29889b0f815 (qtest: add a QOM object for qtest)
WARNING: line over 80 characters
#33: FILE: softmmu/qtest.c:855:
+static bool qtest_server_start(Chardev *chr, const char *qtest_log, Error **errp)
total: 0 errors, 1 warnings, 190 lines checked
Patch 11/15 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
12/15 Checking commit e9515620c1bb (plugin: propagate errors)
ERROR: line over 90 characters
#64: FILE: plugins/loader.c:153:
+static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info, Error **errp)
WARNING: line over 80 characters
#73: FILE: plugins/loader.c:166:
+ error_setg(errp, "Could not load plugin %s: %s", desc->path, g_module_error());
WARNING: line over 80 characters
#79: FILE: plugins/loader.c:171:
+ error_setg(errp, "Could not load plugin %s: %s", desc->path, g_module_error());
WARNING: line over 80 characters
#87: FILE: plugins/loader.c:177:
+ error_setg(errp, "Could not load plugin %s: qemu_plugin_install is NULL",
ERROR: line over 90 characters
#95: FILE: plugins/loader.c:183:
+ error_setg(errp, "Could not load plugin %s: plugin does not declare API version %s",
ERROR: line over 90 characters
#104: FILE: plugins/loader.c:189:
+ error_setg(errp, "Could not load plugin %s: plugin requires API version %d, but "
ERROR: line over 90 characters
#112: FILE: plugins/loader.c:194:
+ error_setg(errp, "Could not load plugin %s: plugin requires API version %d, but "
ERROR: line over 90 characters
#124: FILE: plugins/loader.c:223:
+ error_setg(errp, "Could not load plugin %s: qemu_plugin_install returned error code %d",
total: 5 errors, 3 warnings, 119 lines checked
Patch 12/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
13/15 Checking commit e52482a2d2ad (memory: allow creating MemoryRegions before accelerators)
WARNING: Block comments use a leading /* on a separate line
#93: FILE: softmmu/vl.c:1718:
+ /* Allocation of large amounts of memory may delay
total: 0 errors, 1 warnings, 66 lines checked
Patch 13/15 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
14/15 Checking commit dce3fd5895a3 (null-machine: do not create a default memdev) 15/15 Checking commit 450811f89668 (monitor: allow quitting while in preconfig state) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]