From nobody Mon Feb 9 18:46:27 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606908857; cv=none; d=zohomail.com; s=zohoarc; b=cu1iAqggqVLMdYA4FNwxsQPi1bzw+NnT58BG7PvrDHXYOGEwcLM0eGkMf5VpjGcSvXDZ8k9mKFKfI1cnxLMUl6oZu/F6LIerZo3nhAqNOsp3PnD9RZ/tEcdgDA2tj2iThOMe4lOb30qXLaBrqBC/klS5vftCZ9t9aaoBnPHJ4to= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606908857; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ut9JtSPhb4amh7jnT2ADdCw3oqkoNlY0wz3NwDnvJ74=; b=fZbwHhBIdeGmb1HFtBaK+LTxjZ+qhR1j1hVy5/33MaL2Tn16LAoUrOtbppj0JoVNzcIt5WcHrv5B42ujYwofoMoJqzcxkq/Oaq5JGuZnEc4DbcLdS6VPP9+IgpHIULdOGeNDVwQ1imhe8A46B5vbPDq7lu6/N/6dcgdiHcG/zG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1606908857528362.5212415707639; Wed, 2 Dec 2020 03:34:17 -0800 (PST) Received: from localhost ([::1]:33084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkO6C-0005oA-5P for importer@patchew.org; Wed, 02 Dec 2020 04:06:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkND9-0003Wi-48 for qemu-devel@nongnu.org; Wed, 02 Dec 2020 03:10:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kkNCR-0003ls-3T for qemu-devel@nongnu.org; Wed, 02 Dec 2020 03:10:02 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-YJ1J7-C8OpelXsVqoeyqZA-1; Wed, 02 Dec 2020 03:09:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60C0E1074642 for ; Wed, 2 Dec 2020 08:09:15 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 248DD10013BD for ; Wed, 2 Dec 2020 08:09:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606896558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ut9JtSPhb4amh7jnT2ADdCw3oqkoNlY0wz3NwDnvJ74=; b=hWu49TGVMs/U04okGp/ZlyGZgEAszOESyi4HKE2mLw4FGDlA9DHMkSCm+wQm/Z+XiJkLi9 AHQD80vUfer2WOoZdvuFGHYUYDg27b4lAjgCoOxcMSDTNNt4QYx3iidD6gASpF37DFQkPo FIH/k7wyABfkfHe/Mzr50dB1g6CCih8= X-MC-Unique: YJ1J7-C8OpelXsVqoeyqZA-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 068/113] vl: separate qemu_create_machine Date: Wed, 2 Dec 2020 03:08:04 -0500 Message-Id: <20201202080849.4125477-69-pbonzini@redhat.com> In-Reply-To: <20201202080849.4125477-1-pbonzini@redhat.com> References: <20201202080849.4125477-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.497, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Reviewed-by: Igor Mammedov Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 113 +++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index d9fe9f63c0..5af52454ee 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -133,6 +133,8 @@ static const char *boot_order; static const char *boot_once; static const char *incoming; static const char *loadvm; +static ram_addr_t maxram_size; +static uint64_t ram_slots; static int display_remote; static int snapshot; static QemuPluginList plugin_list =3D QTAILQ_HEAD_INITIALIZER(plugin_list); @@ -2795,8 +2797,13 @@ static void qemu_create_late_backends(void) qemu_semihosting_console_init(); } =20 -static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_siz= e, - MachineClass *mc) +static bool have_custom_ram_size(void) +{ + QemuOpts *opts =3D qemu_find_opts_singleton("memory"); + return !!qemu_opt_get_size(opts, "size", 0); +} + +static void set_memory_options(MachineClass *mc) { uint64_t sz; const char *mem_str; @@ -2846,7 +2853,7 @@ static bool set_memory_options(uint64_t *ram_slots, r= am_addr_t *maxram_size, =20 /* store value for the future use */ qemu_opt_set_number(opts, "size", ram_size, &error_abort); - *maxram_size =3D ram_size; + maxram_size =3D ram_size; =20 if (qemu_opt_get(opts, "maxmem")) { uint64_t slots; @@ -2867,15 +2874,59 @@ static bool set_memory_options(uint64_t *ram_slots,= ram_addr_t *maxram_size, exit(EXIT_FAILURE); } =20 - *maxram_size =3D sz; - *ram_slots =3D slots; + maxram_size =3D sz; + ram_slots =3D slots; } else if (qemu_opt_get(opts, "slots")) { error_report("invalid -m option value: missing 'maxmem' option"); exit(EXIT_FAILURE); } =20 loc_pop(&loc); - return !!mem_str; +} + +static void qemu_create_machine(MachineClass *machine_class) +{ + object_set_machine_compat_props(machine_class->compat_props); + + set_memory_options(machine_class); + + current_machine =3D MACHINE(object_new_with_class(OBJECT_CLASS(machine= _class))); + if (machine_help_func(qemu_get_machine_opts(), current_machine)) { + exit(0); + } + object_property_add_child(object_get_root(), "machine", + OBJECT(current_machine)); + object_property_add_child(container_get(OBJECT(current_machine), + "/unattached"), + "sysbus", OBJECT(sysbus_get_default())); + + if (machine_class->minimum_page_bits) { + if (!set_preferred_target_page_bits(machine_class->minimum_page_bi= ts)) { + /* This would be a board error: specifying a minimum smaller t= han + * a target's compile-time fixed setting. + */ + g_assert_not_reached(); + } + } + + cpu_exec_init_all(); + page_size_init(); + + if (machine_class->hw_version) { + qemu_set_hw_version(machine_class->hw_version); + } + + machine_smp_parse(current_machine, + qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal); + + /* + * Get the default machine options from the machine if it is not alrea= dy + * specified either by the configuration file or by the command line. + */ + if (machine_class->default_machine_opts) { + qemu_opts_set_defaults(qemu_find_opts("machine"), + machine_class->default_machine_opts, 0); + } } =20 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp) @@ -3404,10 +3455,7 @@ void qemu_init(int argc, char **argv, char **envp) const char *optarg; MachineClass *machine_class; bool userconfig =3D true; - ram_addr_t maxram_size; - uint64_t ram_slots =3D 0; FILE *vmstate_dump_file =3D NULL; - bool have_custom_ram_size; =20 qemu_add_opts(&qemu_drive_opts); qemu_add_drive_opts(&qemu_legacy_drive_opts); @@ -4333,49 +4381,7 @@ void qemu_init(int argc, char **argv, char **envp) =20 configure_rtc(qemu_find_opts_singleton("rtc")); =20 - machine_class =3D select_machine(); - object_set_machine_compat_props(machine_class->compat_props); - - have_custom_ram_size =3D set_memory_options(&ram_slots, &maxram_size, - machine_class); - - current_machine =3D MACHINE(object_new_with_class(OBJECT_CLASS(machine= _class))); - if (machine_help_func(qemu_get_machine_opts(), current_machine)) { - exit(0); - } - object_property_add_child(object_get_root(), "machine", - OBJECT(current_machine)); - object_property_add_child(container_get(OBJECT(current_machine), - "/unattached"), - "sysbus", OBJECT(sysbus_get_default())); - - if (machine_class->minimum_page_bits) { - if (!set_preferred_target_page_bits(machine_class->minimum_page_bi= ts)) { - /* This would be a board error: specifying a minimum smaller t= han - * a target's compile-time fixed setting. - */ - g_assert_not_reached(); - } - } - - cpu_exec_init_all(); - page_size_init(); - - if (machine_class->hw_version) { - qemu_set_hw_version(machine_class->hw_version); - } - - machine_smp_parse(current_machine, - qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal); - - /* - * Get the default machine options from the machine if it is not alrea= dy - * specified either by the configuration file or by the command line. - */ - if (machine_class->default_machine_opts) { - qemu_opts_set_defaults(qemu_find_opts("machine"), - machine_class->default_machine_opts, 0); - } + qemu_create_machine(select_machine()); =20 qemu_disable_default_devices(); qemu_create_default_devices(); @@ -4410,6 +4416,7 @@ void qemu_init(int argc, char **argv, char **envp) * called from configure_accelerator(). */ =20 + machine_class =3D MACHINE_GET_CLASS(current_machine); if (!qtest_enabled() && machine_class->deprecation_reason) { error_report("Machine type '%s' is deprecated: %s", machine_class->name, machine_class->deprecation_reaso= n); @@ -4470,7 +4477,7 @@ void qemu_init(int argc, char **argv, char **envp) exit(EXIT_FAILURE); } backend_size =3D object_property_get_uint(backend, "size", &error= _abort); - if (have_custom_ram_size && backend_size !=3D ram_size) { + if (have_custom_ram_size() && backend_size !=3D ram_size) { error_report("Size specified by -m option must match size = of " "explicitly specified 'memory-backend' proper= ty"); exit(EXIT_FAILURE); --=20 2.26.2