Move memory and boot to -machine
cover Move memory and boot to -machine
As the next step in turning command line options into shortcuts, this series does -boot and -m. It also makes -M memory-backend a link instead of special casing it in vl.c, and makes the MachineState validate memory configuration without needing help from vl.c.
Paolo Bonzini (5):
machine: use QAPI struct for boot configuration
machine: add boot compound property
machine: add mem compound property
machine: make memory-backend a link property
machine: move more memory validation to Machine object
hw/arm/nseries.c | 2 +- hw/core/machine.c | 242 +++++++++++++++++++++++++++++++++++----- hw/core/numa.c | 2 +- hw/hppa/machine.c | 6 +- hw/i386/pc.c | 2 +- hw/nvram/fw_cfg.c | 27 ++--- hw/ppc/mac_newworld.c | 2 +- hw/ppc/mac_oldworld.c | 2 +- hw/ppc/prep.c | 2 +- hw/ppc/spapr.c | 4 +- hw/s390x/ipl.c | 20 +--- hw/sparc/sun4m.c | 9 +- hw/sparc64/sun4u.c | 4 +- include/hw/boards.h | 7 +- include/sysemu/sysemu.h | 2 - qapi/machine.json | 48 ++++++++ softmmu/bootdevice.c | 3 +- softmmu/globals.c | 2 - softmmu/vl.c | 229 +++++++++++-------------------------- 19 files changed, 363 insertions(+), 252 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/5 machine: use QAPI struct for boot configuration
As part of converting -boot to a property with a QAPI type, define the struct and use it throughout QEMU to access boot configuration. machine_boot_parse takes care of doing the QemuOpts->QAPI conversion by hand, for now.
--- hw/arm/nseries.c | 2 +- hw/core/machine.c | 68 +++++++++++++++++++++++++++++++++++++++-- hw/hppa/machine.c | 6 ++-- hw/i386/pc.c | 2 +- hw/nvram/fw_cfg.c | 27 +++++----------- hw/ppc/mac_newworld.c | 2 +- hw/ppc/mac_oldworld.c | 2 +- hw/ppc/prep.c | 2 +- hw/ppc/spapr.c | 4 +-- hw/s390x/ipl.c | 20 ++++-------- hw/sparc/sun4m.c | 4 +-- hw/sparc64/sun4u.c | 4 +-- include/hw/boards.h | 4 +-- include/sysemu/sysemu.h | 2 -- qapi/machine.json | 30 ++++++++++++++++++ softmmu/bootdevice.c | 3 +- softmmu/globals.c | 2 -- softmmu/vl.c | 25 +-------------- 18 files changed, 127 insertions(+), 82 deletions(-)
hw/arm/nseries.c +1 -1
@@ -1365,7 +1365,7 @@ static void n8x0_init(MachineState *machine, }if (option_rom[0 ].name && - (machine->boot_order[0 ] =='n' || !machine->kernel_filename)) { + (machine->boot_config.order[0 ] =='n' || !machine->kernel_filename)) {uint8_t *nolo_tags =g_new (uint8_t,0x10000 );/* No, wait, better start at the ROM. */ s->mpu->cpu->env.regs[15 ] =OMAP2_Q2_BASE +0x400000 ;
hw/core/machine.c +65 -3
80 lines not on this page · raw message
hw/hppa/machine.c +3 -3
@@ -116,7 +116,7 @@ static FWCfgState *create_fw_cfg(MachineState *ms)fw_cfg_add_file (fw_cfg,"/etc/power-button-addr" ,g_memdup (&val,sizeof (val)),sizeof (val)); -fw_cfg_add_i16 (fw_cfg,FW_CFG_BOOT_DEVICE , ms->boot_order[0 ]); +fw_cfg_add_i16 (fw_cfg,FW_CFG_BOOT_DEVICE , ms->boot_config.order[0 ]);qemu_register_boot_set (fw_cfg_boot_set, fw_cfg);return fw_cfg;
@@ -309,8 +309,8 @@ static void machine_hppa_init(MachineState *machine)* mode (kernel_entry=1), and to boot from CD (gr[24]='d') * or hard disc * (gr[24]='c'). */ - kernel_entry = boot_menu ?1 :0 ; - cpu[0 ]->env.gr[24 ] = machine->boot_order[0 ]; + kernel_entry = machine->boot_config.has_menu ? machine->boot_config.menu :0 ; + cpu[0 ]->env.gr[24 ] = machine->boot_config.order[0 ]; }/* We jump to the firmware entry routine and pass the
hw/i386/pc.c +1 -1
@@ -672,7 +672,7 @@ void pc_cmos_init(PCMachineState *pcms,object_property_set_link (OBJECT (pcms),"rtc_state" ,OBJECT (s), &error_abort); -set_boot_dev (s,MACHINE (pcms)->boot_order, &error_fatal); +set_boot_dev (s,MACHINE (pcms)->boot_config.order, &error_fatal); val =0 ; val |=0x02 ;/* FPU is there */
hw/nvram/fw_cfg.c +7 -20
@@ -179,21 +179,13 @@ error:static void fw_cfg_bootsplash (FWCfgState *s) { -const char *boot_splash_filename =NULL ; -const char *boot_splash_time =NULL ;char *filename, *file_data;gsize file_size;int file_type; -/* get user configuration */ -QemuOptsList *plist =qemu_find_opts ("boot-opts" ); -QemuOpts *opts =QTAILQ_FIRST (&plist->head); - boot_splash_filename =qemu_opt_get (opts,"splash" ); - boot_splash_time =qemu_opt_get (opts,"splash-time" ); -/* insert splash time if user configurated */ -if (boot_splash_time) { -int64_t bst_val =qemu_opt_get_number (opts,"splash-time" ,-1 ); +if (current_machine->boot_config.has_splash_time) { +int64_t bst_val = current_machine->boot_config.splash_time;uint16_t bst_le16;/* validate the input */
@@ -209,7 +201,8 @@ static void fw_cfg_bootsplash(FWCfgState *s) }/* insert splash file if user configurated */ -if (boot_splash_filename) { +if (current_machine->boot_config.has_splash) { +const char *boot_splash_filename = current_machine->boot_config.splash; filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , boot_splash_filename);if (filename ==NULL ) {error_report ("failed to find file '%s'" , boot_splash_filename);
@@ -239,17 +232,11 @@ static void fw_cfg_bootsplash(FWCfgState *s)static void fw_cfg_reboot (FWCfgState *s) { -const char *reboot_timeout =NULL ;uint64_t rt_val =-1 ;uint32_t rt_le32; -/* get user configuration */ -QemuOptsList *plist =qemu_find_opts ("boot-opts" ); -QemuOpts *opts =QTAILQ_FIRST (&plist->head); - reboot_timeout =qemu_opt_get (opts,"reboot-timeout" ); - -if (reboot_timeout) { - rt_val =qemu_opt_get_number (opts,"reboot-timeout" ,-1 ); +if (current_machine->boot_config.has_reboot_timeout) { + rt_val = current_machine->boot_config.reboot_timeout;/* validate the input */ if (rt_val >0xffff && rt_val != (uint64_t )-1 ) {
@@ -1134,7 +1121,7 @@ static void fw_cfg_common_realize(DeviceState *dev, Error **errp)fw_cfg_add_bytes (s,FW_CFG_SIGNATURE , (char *)"QEMU" ,4 );fw_cfg_add_bytes (s,FW_CFG_UUID , &qemu_uuid,16 );fw_cfg_add_i16 (s,FW_CFG_NOGRAPHIC , (uint16_t )!machine->enable_graphics); -fw_cfg_add_i16 (s,FW_CFG_BOOT_MENU , (uint16_t )boot_menu); +fw_cfg_add_i16 (s,FW_CFG_BOOT_MENU , (uint16_t )(machine->boot_config.has_menu && machine->boot_config.menu));fw_cfg_bootsplash (s);fw_cfg_reboot (s);
hw/ppc/mac_newworld.c +1 -1
@@ -112,7 +112,7 @@ static void ppc_core99_init(MachineState *machine)const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename; -const char *boot_device = machine->boot_order; +const char *boot_device = machine->boot_config.order;Core99MachineState *core99_machine =CORE99_MACHINE (machine);PowerPCCPU *cpu =NULL ;CPUPPCState *env =NULL ;
hw/ppc/mac_oldworld.c +1 -1
@@ -83,7 +83,7 @@ static void ppc_heathrow_init(MachineState *machine) {ram_addr_t ram_size = machine->ram_size;const char *bios_name = machine->firmware ?:PROM_FILENAME ; -const char *boot_device = machine->boot_order; +const char *boot_device = machine->boot_config.order;PowerPCCPU *cpu =NULL ;CPUPPCState *env =NULL ;char *filename;
hw/ppc/prep.c +1 -1
@@ -381,7 +381,7 @@ static void ibm_40p_init(MachineState *machine) } boot_device ='m' ; }else { - boot_device = machine->boot_order[0 ]; + boot_device = machine->boot_config.order[0 ]; }fw_cfg_add_i16 (fw_cfg,FW_CFG_MAX_CPUS , (uint16_t )machine->smp.max_cpus);
hw/ppc/spapr.c +2 -2
@@ -1045,8 +1045,8 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)_FDT (fdt_setprop (fdt, chosen,"qemu,boot-kernel-le" ,NULL ,0 )); } } -if (boot_menu) { -_FDT ((fdt_setprop_cell (fdt, chosen,"qemu,boot-menu" , boot_menu))); +if (machine->boot_config.has_menu && machine->boot_config.menu) { +_FDT ((fdt_setprop_cell (fdt, chosen,"qemu,boot-menu" , true))); }_FDT (fdt_setprop_cell (fdt, chosen,"qemu,graphic-width" , graphic_width));_FDT (fdt_setprop_cell (fdt, chosen,"qemu,graphic-height" , graphic_height));
hw/s390x/ipl.c +6 -14
@@ -288,13 +288,10 @@ static Property s390_ipl_properties[] = {static void s390_ipl_set_boot_menu (S390IPLState *ipl) { -QemuOptsList *plist =qemu_find_opts ("boot-opts" ); -QemuOpts *opts =QTAILQ_FIRST (&plist->head); -const char *tmp;unsigned long splash_time =0 ;if (!get_boot_device (0 )) { -if (boot_menu) { +if (current_machine->boot_config.has_menu && current_machine->boot_config.menu) {error_report ("boot menu requires a bootindex to be specified for " "the IPL device" ); }
@@ -304,7 +301,7 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)switch (ipl->iplb.pbt) {case S390_IPL_TYPE_CCW :/* In the absence of -boot menu, use zipl parameters */ -if (!qemu_opt_get (opts,"menu" )) { +if (!current_machine->boot_config.has_menu) { ipl->qipl.qipl_flags |=QIPL_FLAG_BM_OPTS_ZIPL ;return ; }
@@ -312,26 +309,21 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl)case S390_IPL_TYPE_QEMU_SCSI :break ;default : -if (boot_menu) { +if (current_machine->boot_config.has_menu && current_machine->boot_config.menu) {error_report ("boot menu is not supported for this device type" ); }return ; } -if (!boot_menu) { +if (!current_machine->boot_config.has_menu || !current_machine->boot_config.menu) {return ; } ipl->qipl.qipl_flags |=QIPL_FLAG_BM_OPTS_CMD ; - tmp =qemu_opt_get (opts,"splash-time" ); - -if (tmp &&qemu_strtoul (tmp,NULL ,10 , &splash_time)) { -error_report ("splash-time is invalid, forcing it to 0" ); - ipl->qipl.boot_menu_timeout =0 ; -return ; +if (current_machine->boot_config.has_splash_time) { + splash_time = current_machine->boot_config.splash_time; } -if (splash_time >0xffffffff ) {error_report ("splash-time is too large, forcing it to max value" ); ipl->qipl.boot_menu_timeout =0xffffffff ;
hw/sparc/sun4m.c +2 -2
@@ -1049,7 +1049,7 @@ static void sun4m_hw_init(MachineState *machine) machine->ram_size, &initrd_size);nvram_init (nvram, (uint8_t *)&nd->macaddr, machine->kernel_cmdline, - machine->boot_order, machine->ram_size, kernel_size, + machine->boot_config.order, machine->ram_size, kernel_size, graphic_width, graphic_height, graphic_depth, hwdef->nvram_machine_id,"Sun4m" );
@@ -1090,7 +1090,7 @@ static void sun4m_hw_init(MachineState *machine) }fw_cfg_add_i32 (fw_cfg,FW_CFG_INITRD_ADDR ,INITRD_LOAD_ADDR );fw_cfg_add_i32 (fw_cfg,FW_CFG_INITRD_SIZE , initrd_size); -fw_cfg_add_i16 (fw_cfg,FW_CFG_BOOT_DEVICE , machine->boot_order[0 ]); +fw_cfg_add_i16 (fw_cfg,FW_CFG_BOOT_DEVICE , machine->boot_config.order[0 ]);qemu_register_boot_set (fw_cfg_boot_set, fw_cfg); }
hw/sparc64/sun4u.c +2 -2
@@ -695,7 +695,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem, &kernel_addr, &kernel_entry); sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", machine->ram_size, - machine->boot_order, + machine->boot_config.order, kernel_addr, kernel_size, machine->kernel_cmdline, initrd_addr, initrd_size,
@@ -727,7 +727,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem, }fw_cfg_add_i64 (fw_cfg,FW_CFG_INITRD_ADDR , initrd_addr);fw_cfg_add_i64 (fw_cfg,FW_CFG_INITRD_SIZE , initrd_size); -fw_cfg_add_i16 (fw_cfg,FW_CFG_BOOT_DEVICE , machine->boot_order[0 ]); +fw_cfg_add_i16 (fw_cfg,FW_CFG_BOOT_DEVICE , machine->boot_config.order[0 ]);fw_cfg_add_i16 (fw_cfg,FW_CFG_SPARC64_WIDTH , graphic_width);fw_cfg_add_i16 (fw_cfg,FW_CFG_SPARC64_HEIGHT , graphic_height);
include/hw/boards.h +2 -2
@@ -26,6 +26,7 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)extern MachineState *current_machine;void machine_run_board_init (MachineState *machine); +void machine_boot_parse (MachineState *ms,QemuOpts *opts,Error **errp);bool machine_usb (MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);
@@ -350,8 +351,7 @@ struct MachineState {ram_addr_t ram_size;ram_addr_t maxram_size;uint64_t ram_slots; -const char *boot_order; -const char *boot_once; +BootConfiguration boot_config;char *kernel_filename;char *kernel_cmdline;char *initrd_filename;
include/sysemu/sysemu.h +0 -2
@@ -43,8 +43,6 @@ extern int alt_grab;extern int ctrl_grab;extern int graphic_rotate;extern int old_param; -extern int boot_menu; -extern bool boot_strict;extern uint8_t *boot_splash_filedata;extern bool enable_mlock;extern bool enable_cpu_pm;
qapi/machine.json +30 -0
@@ -1393,6 +1393,36 @@ 'data': { 'device': 'str', 'msg': 'str' }, 'features': ['deprecated'] } +## +# @BootConfiguration: +# +# Schema for virtual machine boot configuration. +# +# @order: Boot order (a=floppy, c=hard disk, d=CD-ROM, n=network) +# +# @once: Boot order to apply on first boot +# +# @menu: Whether to show a boot menu +# +# @splash: The name of the file to be passed to the firmware as logo picture, if @menu is true. +# +# @splash-time: How long to show the logo picture, in milliseconds +# +# @reboot-timeout: Timeout before guest reboots after boot fails +# +# @strict: Whether to attempt booting from devices not included in the boot order +# +# Since: 6.1 +## +{ 'struct': 'BootConfiguration', 'data': { + '*order': 'str', + '*once': 'str', + '*menu': 'bool', + '*splash': 'str', + '*splash-time': 'int', + '*reboot-timeout': 'int', + '*strict': 'bool' } } + ## # @SMPConfiguration: #
softmmu/bootdevice.c +2 -1
@@ -268,7 +268,8 @@ char *get_boot_devices_list(size_t *size) *size = total; -if (boot_strict && *size >0 ) { +if (current_machine->boot_config.has_strict && + current_machine->boot_config.strict && *size >0 ) { list[total-1 ] ='\n' ; list =g_realloc (list, total +5 );memcpy (&list[total],"HALT" ,5 );
softmmu/globals.c +0 -2
@@ -53,8 +53,6 @@ int alt_grab;int ctrl_grab;unsigned int nb_prom_envs;const char *prom_envs[MAX_PROM_ENVS ]; -int boot_menu; -bool boot_strict;uint8_t *boot_splash_filedata;int only_migratable;/* turn it off unless user states otherwise */ int icount_align_option;
softmmu/vl.c +1 -24
@@ -1878,9 +1878,6 @@ static bool object_create_early(const char *type)static void qemu_apply_machine_options (QDict *qdict) { -MachineClass *machine_class =MACHINE_GET_CLASS (current_machine); -const char *boot_order =NULL ; -const char *boot_once =NULL ;QemuOpts *opts;object_set_properties_from_keyval (OBJECT (current_machine), qdict, false, &error_fatal);
@@ -1889,27 +1886,7 @@ static void qemu_apply_machine_options(QDict *qdict) current_machine->ram_slots = ram_slots; opts =qemu_opts_find (qemu_find_opts ("boot-opts" ),NULL ); -if (opts) { - boot_order =qemu_opt_get (opts,"order" ); -if (boot_order) { -validate_bootdevices (boot_order, &error_fatal); - } - - boot_once =qemu_opt_get (opts,"once" ); -if (boot_once) { -validate_bootdevices (boot_once, &error_fatal); - } - - boot_menu =qemu_opt_get_bool (opts,"menu" , boot_menu); - boot_strict =qemu_opt_get_bool (opts,"strict" , false); - } - -if (!boot_order) { - boot_order = machine_class->default_boot_order; - } - - current_machine->boot_order = boot_order; - current_machine->boot_once = boot_once; +machine_boot_parse (current_machine, opts, &error_fatal);if (semihosting_enabled () && !semihosting_get_argc ()) {/* fall back to the -kernel/-append */
Signature · 1 line
2.31.1
PATCH 2/5 machine: add boot compound property
In reply to Paolo BonziniMake -boot syntactic sugar for a compound property "-machine boot.{order,menu,...}". machine_boot_parse is replaced by the setter for the property.
--- hw/core/machine.c | 99 ++++++++++++++++++++++++--------------------- include/hw/boards.h | 1 - softmmu/vl.c | 16 +++----- 3 files changed, 58 insertions(+), 58 deletions(-)
hw/core/machine.c +53 -46
@@ -771,66 +771,63 @@ static void machine_set_smp(Object *obj, Visitor *v, const char *name,machine_parse_smp_config (ms, config, errp); } -void machine_boot_parse (MachineState *ms,QemuOpts *opts,Error **errp) +static void machine_get_boot (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +MachineState *ms =MACHINE (obj); +BootConfiguration *config = &ms->boot_config; +visit_type_BootConfiguration (v, name, &config, &error_abort); +} + +static void machine_free_boot_config (MachineState *ms) +{ +g_free (ms->boot_config.order); +g_free (ms->boot_config.once); +g_free (ms->boot_config.splash); +} + +static void machine_copy_boot_config (MachineState *ms,BootConfiguration *config) {MachineClass *machine_class =MACHINE_GET_CLASS (ms); -const char *s; + +machine_free_boot_config (ms); + ms->boot_config = *config; +if (!config->has_order) { + ms->boot_config.has_order = true; + ms->boot_config.order =g_strdup (machine_class->default_boot_order); + } +} + +static void machine_set_boot (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ERRP_GUARD (); +MachineState *ms =MACHINE (obj); +BootConfiguration *config =NULL ; - ms->boot_config = (BootConfiguration ) { - .has_order = true, - .order = (char *)machine_class->default_boot_order, - .has_strict = true, - .strict = false, - }; -if (!opts) { +if (!visit_type_BootConfiguration (v, name, &config, errp)) {return ; } - - s =qemu_opt_get (opts,"order" ); -if (s) { -validate_bootdevices (s, errp); +if (config->has_order) { +validate_bootdevices (config->order, errp);if (*errp) { -return ; + goto out_free; } - ms->boot_config.order = (char *)s; } - - s =qemu_opt_get (opts,"once" ); -if (s) { -validate_bootdevices (s, errp); +if (config->has_once) { +validate_bootdevices (config->once, errp);if (*errp) { -return ; + goto out_free; } - ms->boot_config.has_once = true; - ms->boot_config.once = (char *)s; } - s =qemu_opt_get (opts,"splash" ); -if (s) { - ms->boot_config.has_splash = true; - ms->boot_config.splash = (char *)s; - } - - s =qemu_opt_get (opts,"splash-time" ); -if (s) { - ms->boot_config.has_splash_time = true; - ms->boot_config.splash_time =qemu_opt_get_number (opts,"splash-time" ,-1 ); - } +machine_copy_boot_config (ms, config); +/* Strings live in ms->boot_config. */ +free (config); +return ; - s =qemu_opt_get (opts,"reboot-timeout" ); -if (s) { - ms->boot_config.has_reboot_timeout = true; - ms->boot_config.reboot_timeout =qemu_opt_get_number (opts,"reboot-timeout" ,-1 ); - } - - s =qemu_opt_get (opts,"menu" ); -if (s) { - ms->boot_config.has_menu = true; - ms->boot_config.menu =qemu_opt_get_bool (opts,"menu" , false); - } - - ms->boot_config.strict =qemu_opt_get_bool (opts,"strict" , false); +out_free: +qapi_free_BootConfiguration (config); }static void machine_class_init (ObjectClass *oc,void *data)
@@ -871,6 +868,12 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"dumpdtb" ,"Dump current dtb to a file and quit" ); +object_class_property_add (oc,"boot" ,"BootConfiguration" , + machine_get_boot, machine_set_boot, +NULL ,NULL ); +object_class_property_set_description (oc,"boot" , +"Boot configuration" ); +object_class_property_add (oc,"smp" ,"SMPConfiguration" , machine_get_smp, machine_set_smp,NULL ,NULL );
@@ -1004,12 +1007,16 @@ static void machine_initfn(Object *obj) ms->smp.clusters =1 ; ms->smp.cores =1 ; ms->smp.threads =1 ; + ms->smp.sockets =1 ; + +machine_copy_boot_config (ms, &(BootConfiguration ){0 }); }static void machine_finalize (Object *obj) {MachineState *ms =MACHINE (obj); +machine_free_boot_config (ms);g_free (ms->kernel_filename);g_free (ms->initrd_filename);g_free (ms->kernel_cmdline);
include/hw/boards.h +0 -1
@@ -26,7 +26,6 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)extern MachineState *current_machine;void machine_run_board_init (MachineState *machine); -void machine_boot_parse (MachineState *ms,QemuOpts *opts,Error **errp);bool machine_usb (MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);
softmmu/vl.c +5 -11
@@ -1878,16 +1878,11 @@ static bool object_create_early(const char *type)static void qemu_apply_machine_options (QDict *qdict) { -QemuOpts *opts; -object_set_properties_from_keyval (OBJECT (current_machine), qdict, false, &error_fatal); current_machine->ram_size = ram_size; current_machine->maxram_size = maxram_size; current_machine->ram_slots = ram_slots; - opts =qemu_opts_find (qemu_find_opts ("boot-opts" ),NULL ); -machine_boot_parse (current_machine, opts, &error_fatal); -if (semihosting_enabled () && !semihosting_get_argc ()) {/* fall back to the -kernel/-append */ semihosting_arg_fallback (current_machine->kernel_filename, current_machine->kernel_cmdline);
@@ -2183,7 +2178,8 @@ static bool is_qemuopts_group(const char *group) {if (g_str_equal (group,"object" ) ||g_str_equal (group,"machine" ) || -g_str_equal (group,"smp-opts" )) { +g_str_equal (group,"smp-opts" ) || +g_str_equal (group,"boot-opts" )) {return false; }return true;
@@ -2205,6 +2201,8 @@ static void qemu_record_config_group(const char *group, QDict *dict,keyval_merge (machine_opts_dict, dict, errp); }else if (g_str_equal (group,"smp-opts" )) {machine_merge_property ("smp" , dict, &error_fatal); + }else if (g_str_equal (group,"boot-opts" )) { +machine_merge_property ("boot" , dict, &error_fatal); }else {abort (); }
@@ -2947,11 +2945,7 @@ void qemu_init(int argc, char **argv, char **envp)drive_add (IF_DEFAULT ,2 , optarg,CDROM_OPTS );break ;case QEMU_OPTION_boot: - opts =qemu_opts_parse_noisily (qemu_find_opts ("boot-opts" ), - optarg, true); -if (!opts) { -exit (1 ); - } +machine_parse_property_opt (qemu_find_opts ("boot-opts" ),"boot" , optarg);break ;case QEMU_OPTION_fda:case QEMU_OPTION_fdb:
Signature · 1 line
2.31.1
PATCH 3/5 machine: add mem compound property
In reply to Paolo BonziniMake -m syntactic sugar for a compound property "-machine mem.{size,max-size,slots}". The new property does not have the magic conversion to megabytes of unsuffixed arguments, and also does not understand that "0" means the default size (you have to leave it out to get the default). This means that we need to convert the QemuOpts by hand to a QDict.
--- hw/core/machine.c | 80 ++++++++++++++++++++++++++++++ qapi/machine.json | 18 +++++++ softmmu/vl.c | 123 +++++++++++++++------------------------------- 3 files changed, 138 insertions(+), 83 deletions(-)
hw/core/machine.c +80 -0
@@ -520,6 +520,78 @@ static void machine_set_hmat(Object *obj, bool value, Error **errp) ms->numa_state->hmat_enabled = value; } +static void machine_get_mem (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +MachineState *ms =MACHINE (obj); +MemorySizeConfiguration mem = { + .has_size = true, + .size = ms->ram_size, + .has_max_size = !!ms->ram_slots, + .max_size = ms->maxram_size, + .has_slots = !!ms->ram_slots, + .slots = ms->ram_slots, + }; +MemorySizeConfiguration *p_mem = &mem; + +visit_type_MemorySizeConfiguration (v, name, &p_mem, &error_abort); +} + +static void machine_set_mem (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +MachineState *ms =MACHINE (obj); +MachineClass *mc =MACHINE_GET_CLASS (obj); +MemorySizeConfiguration *mem; + +ERRP_GUARD (); + +if (!visit_type_MemorySizeConfiguration (v, name, &mem, errp)) { +return ; + } + +if (!mem->has_size) { + mem->has_size = true; + mem->size = mc->default_ram_size; + } + mem->size =QEMU_ALIGN_UP (mem->size,8192 ); +if (mc->fixup_ram_size) { + mem->size = mc->fixup_ram_size (mem->size); + } +if ((ram_addr_t )mem->size != mem->size) { +error_setg (errp,"ram size too large" ); + goto out_free; + } + +if (mem->has_max_size) { +if (mem->max_size < mem->size) { +error_setg (errp,"invalid value of maxmem: " +"maximum memory size (0x%" PRIx64") must be at least " +"the initial memory size (0x%" PRIx64")" , + mem->max_size, mem->size); + goto out_free; + } +if (mem->has_slots && mem->slots && mem->max_size == mem->size) { +error_setg (errp,"invalid value of maxmem: " +"memory slots were specified but maximum memory size " +"(0x%" PRIx64") is equal to the initial memory size " +"(0x%" PRIx64")" , mem->max_size, mem->size); + goto out_free; + } + ms->maxram_size = mem->max_size; + }else { +if (mem->has_slots) { +error_setg (errp,"slots specified but no max-size" ); + goto out_free; + } + ms->maxram_size = mem->size; + } + ms->ram_size = mem->size; + ms->ram_slots = mem->has_slots ? mem->slots :0 ; +out_free: +qapi_free_MemorySizeConfiguration (mem); +} +static char *machine_get_nvdimm_persistence (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj);
@@ -940,6 +1012,12 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"memory-backend" ,"Set RAM backend" "Valid value is ID of hostmem based backend" ); + +object_class_property_add (oc,"memory" ,"MemorySizeConfiguration" , + machine_get_mem, machine_set_mem, +NULL ,NULL ); +object_class_property_set_description (oc,"memory" , +"Memory size configuration" ); }static void machine_class_base_init (ObjectClass *oc,void *data)
@@ -970,6 +1048,8 @@ static void machine_initfn(Object *obj) ms->mem_merge = true; ms->enable_graphics = true; ms->kernel_cmdline =g_strdup ("" ); + ms->ram_size = mc->default_ram_size; + ms->maxram_size = mc->default_ram_size;if (mc->nvdimm_supported) {Object *obj =OBJECT (ms);
qapi/machine.json +18 -0
@@ -1612,3 +1612,21 @@ ## { 'enum': 'SmbiosEntryPointType', 'data': [ '32', '64' ] } + +## +# @MemorySizeConfiguration: +# +# Schema for memory size configuration. +# +# @size: memory size in bytes +# +# @max-size: maximum hotpluggable memory size in bytes +# +# @slots: number of available memory slots for hotplug +# +# Since: 6.1 +## +{ 'struct': 'MemorySizeConfiguration', 'data': { + '*size': 'size', + '*max-size': 'size', + '*slots': 'uint64' } }
softmmu/vl.c +40 -83
225 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 4/5 machine: make memory-backend a link property
In reply to Paolo BonziniHandle HostMemoryBackend creation and setting of ms->ram entirely in machine_run_board_init.
--- hw/core/machine.c | 70 ++++++++++++++++++++++++++++++--------------- hw/core/numa.c | 2 +- hw/sparc/sun4m.c | 5 ++-- include/hw/boards.h | 4 +-- softmmu/vl.c | 62 ++++++++++++++------------------------- 5 files changed, 74 insertions(+), 69 deletions(-)
hw/core/machine.c +47 -23
@@ -36,6 +36,7 @@#include "exec/confidential-guest-support.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-pci.h" +#include "qom/object_interfaces.h" GlobalProperty hw_compat_6_2[] = { {"PIIX4_PM" ,"x-not-migrate-acpi-index" ,"on" },
@@ -650,21 +651,6 @@ bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type)return allowed; } -static char *machine_get_memdev (Object *obj,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -return g_strdup (ms->ram_memdev_id); -} - -static void machine_set_memdev (Object *obj,const char *value,Error **errp) -{ -MachineState *ms =MACHINE (obj); - -g_free (ms->ram_memdev_id); - ms->ram_memdev_id =g_strdup (value); -} -HotpluggableCPUList *machine_query_hotpluggable_cpus (MachineState *machine) {int i;
@@ -1007,8 +993,9 @@ static void machine_class_init(ObjectClass *oc, void *data)object_class_property_set_description (oc,"memory-encryption" ,"Set memory encryption object to use" ); -object_class_property_add_str (oc,"memory-backend" , - machine_get_memdev, machine_set_memdev); +object_class_property_add_link (oc,"memory-backend" ,TYPE_MEMORY_BACKEND , + offsetof(MachineState , memdev), object_property_allow_set_link, +OBJ_PROP_LINK_STRONG );object_class_property_set_description (oc,"memory-backend" ,"Set RAM backend" "Valid value is ID of hostmem based backend" );
@@ -1252,7 +1239,40 @@ MemoryRegion *machine_consume_memdev(MachineState *machine,return ret; } -void machine_run_board_init (MachineState *machine) +static bool create_default_memdev (MachineState *ms,const char *path,Error **errp) +{ +Object *obj; +MachineClass *mc =MACHINE_GET_CLASS (ms); +bool r = false; + + obj =object_new (path ?TYPE_MEMORY_BACKEND_FILE :TYPE_MEMORY_BACKEND_RAM ); +if (path) { +if (!object_property_set_str (obj,"mem-path" , path, errp)) { + goto out; + } + } +if (!object_property_set_int (obj,"size" , ms->ram_size, errp)) { + goto out; + } +object_property_add_child (object_get_objects_root (), mc->default_ram_id, + obj); +/* Ensure backend's memory region name is equal to mc->default_ram_id */ +if (!object_property_set_bool (obj,"x-use-canonical-path-for-ramblock-id" , + false, errp)) { + goto out; + } +if (!user_creatable_complete (USER_CREATABLE (obj), errp)) { + goto out; + } + r =object_property_set_link (OBJECT (ms),"memory-backend" , obj, errp); + +out: +object_unref (obj); +return r; +} + + +void machine_run_board_init (MachineState *machine,const char *mem_path,Error **errp) {MachineClass *machine_class =MACHINE_GET_CLASS (machine);ObjectClass *oc =object_class_by_name (machine->cpu_type);
@@ -1263,11 +1283,11 @@ void machine_run_board_init(MachineState *machine)clock values from the log. */ replay_checkpoint (CHECKPOINT_INIT ); -if (machine->ram_memdev_id) { -Object *o; - o =object_resolve_path_type (machine->ram_memdev_id, -TYPE_MEMORY_BACKEND ,NULL ); - machine->ram =machine_consume_memdev (machine,MEMORY_BACKEND (o)); +if (machine_class->default_ram_id && machine->ram_size && +numa_uses_legacy_mem () && !machine->memdev) { +if (!create_default_memdev (current_machine, mem_path, errp)) { +return ; + } }if (machine->numa_state) {
@@ -1277,6 +1297,10 @@ void machine_run_board_init(MachineState *machine) } } +if (!machine->ram && machine->memdev) { + machine->ram =machine_consume_memdev (machine, machine->memdev); + } +/* If the machine supports the valid_cpu_types check and the user * specified a CPU with -cpu check here that the user CPU is supported. */
hw/core/numa.c +1 -1
@@ -695,7 +695,7 @@ void numa_complete_configuration(MachineState *ms) }if (!numa_uses_legacy_mem () && mc->default_ram_id) { -if (ms->ram_memdev_id) { +if (ms->memdev) {error_report ("'-machine memory-backend' and '-numa memdev'" " properties are mutually exclusive" );exit (1 );
hw/sparc/sun4m.c +2 -3
@@ -832,8 +832,7 @@ static void sun4m_hw_init(MachineState *machine)SysBusDevice *s;unsigned int smp_cpus = machine->smp.cpus;unsigned int max_cpus = machine->smp.max_cpus; -Object *ram_memdev =object_resolve_path_type (machine->ram_memdev_id, -TYPE_MEMORY_BACKEND ,NULL ); +HostMemoryBackend *ram_memdev = machine->memdev;NICInfo *nd = &nd_table[0 ];if (machine->ram_size > hwdef->max_mem) {
@@ -853,7 +852,7 @@ static void sun4m_hw_init(MachineState *machine)/* Create and map RAM frontend */ dev =qdev_new ("memory" ); -object_property_set_link (OBJECT (dev),"memdev" , ram_memdev, &error_fatal); +object_property_set_link (OBJECT (dev),"memdev" ,OBJECT (ram_memdev), &error_fatal);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0 );
include/hw/boards.h +2 -2
@@ -25,7 +25,7 @@ OBJECT_DECLARE_TYPE(MachineState, MachineClass, MACHINE)extern MachineState *current_machine; -void machine_run_board_init (MachineState *machine); +void machine_run_board_init (MachineState *machine,const char *mem_path,Error **errp);bool machine_usb (MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);
@@ -339,7 +339,7 @@ struct MachineState {bool suppress_vmdesc;bool enable_graphics;ConfidentialGuestSupport *cgs; -char *ram_memdev_id; +HostMemoryBackend *memdev;/* * convenience alias to ram_memdev_id backend memory region * or to numa container memory region
softmmu/vl.c +22 -40
108 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 5/5 machine: move more memory validation to Machine object
In reply to Paolo BonziniThis allows setting memory properties without going through vl.c, and have them validated just the same.
--- hw/core/machine.c | 21 +++++++++++++++++++-- softmmu/vl.c | 17 +++-------------- 2 files changed, 22 insertions(+), 16 deletions(-)
hw/core/machine.c +19 -2
@@ -21,12 +21,14 @@#include "qapi/qapi-visit-common.h" #include "qapi/qapi-visit-machine.h" #include "qapi/visitor.h" +#include "qom/object_interfaces.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 "sysemu/xen.h" #include "qemu/error-report.h" #include "sysemu/qtest.h" #include "hw/pci/pci.h"
@@ -1283,8 +1285,23 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error *clock values from the log. */ replay_checkpoint (CHECKPOINT_INIT ); -if (machine_class->default_ram_id && machine->ram_size && -numa_uses_legacy_mem () && !machine->memdev) { +if (!xen_enabled ()) { +/* On 32-bit hosts, QEMU is limited by virtual address space */ +if (machine->ram_size > (2047 <<20 ) &&HOST_LONG_BITS ==32 ) { +error_setg (errp,"at most 2047 MB RAM can be simulated" ); +return ; + } + } + +if (machine->memdev) { +ram_addr_t backend_size =object_property_get_uint (OBJECT (machine->memdev), +"size" , &error_abort); +if (backend_size != machine->ram_size) { +error_setg (errp,"Machine memory size does not match the size of the memory backend" ); +return ; + } + }else if (machine_class->default_ram_id && machine->ram_size && +numa_uses_legacy_mem ()) {if (!create_default_memdev (current_machine, mem_path, errp)) {return ; }
softmmu/vl.c +3 -14
@@ -2021,24 +2021,13 @@ static void qemu_resolve_machine_memdev(void)error_report ("Memory backend '%s' not found" , ram_memdev_id);exit (EXIT_FAILURE ); } - backend_size =object_property_get_uint (backend,"size" , &error_abort); -if (have_custom_ram_size && backend_size != current_machine->ram_size) { -error_report ("Size specified by -m option must match size of " -"explicitly specified 'memory-backend' property" ); -exit (EXIT_FAILURE ); +if (!have_custom_ram_size) { + backend_size =object_property_get_uint (backend,"size" , &error_abort); + current_machine->ram_size = backend_size; } - current_machine->ram_size = backend_size;object_property_set_link (OBJECT (current_machine),"memory-backend" , backend, &error_fatal); } - -if (!xen_enabled ()) { -/* On 32-bit hosts, QEMU is limited by virtual address space */ -if (current_machine->ram_size > (2047 <<20 ) &&HOST_LONG_BITS ==32 ) { -error_report ("at most 2047 MB RAM can be simulated" ); -exit (1 ); - } - } }static void parse_memory_options (const char *arg)
Signature · 1 line
2.31.1