From nobody Thu Apr 25 03:30:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1555315468; cv=none; d=zoho.com; s=zohoarc; b=k2F/QcsDwUK5X+mO5R32QKm1o/tQB8Hy9HskFQiP2ma/fT+YEDpOfCSmj8VEGUWfx9wvmsgCM4VvD6TMgPVXT6Y11FfoxwxiNkTpBc8oqhzfeDJpXM32VfTDpp2ZfwQpvmqcnM9uIeWFL5XJ1PtISgX0x8IxiM9dT7cJsXcUkZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555315468; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4QsF3sVrv1zHyRTzlHWmciyuyU3w2ZDTcu+FlxeL9aU=; b=kVWk6uvgTUNYvemVICWUVyPMoYc9LiRj6c/eJg7gUL6GN4944NpH96IIYiryUigxrnE+ItT4LUJZi1k8BdOQUpqKkzdYjZ5pyG/0Q7ljOEGzaw7MU8s+PVXdy3f0NTILj4pHLdxVnjvBAe+KPUKu71tDg2QhdrsolLJKVD7PHaA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555315468986856.8094481974362; Mon, 15 Apr 2019 01:04:28 -0700 (PDT) Received: from localhost ([127.0.0.1]:46360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hFwbE-0002Rv-0b for importer@patchew.org; Mon, 15 Apr 2019 04:04:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hFwXu-0000gM-Ky for qemu-devel@nongnu.org; Mon, 15 Apr 2019 04:00:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hFwXs-0001Sy-UA for qemu-devel@nongnu.org; Mon, 15 Apr 2019 04:00:54 -0400 Received: from mga09.intel.com ([134.134.136.24]:40828) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hFwXp-0001PK-0w; Mon, 15 Apr 2019 04:00:49 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Apr 2019 01:00:46 -0700 Received: from xulike-server.sh.intel.com ([10.239.48.134]) by fmsmga008.fm.intel.com with ESMTP; 15 Apr 2019 01:00:44 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,352,1549958400"; d="scan'208";a="140739279" From: Like Xu To: qemu-trivial@nongnu.org Date: Mon, 15 Apr 2019 15:59:44 +0800 Message-Id: <1555315185-16414-2-git-send-email-like.xu@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1555315185-16414-1-git-send-email-like.xu@linux.intel.com> References: <1555315185-16414-1-git-send-email-like.xu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 Subject: [Qemu-devel] [PATCH v3 1/2] vl.c: refactor current_machine as non-global variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Thomas Huth , Eduardo Habkost , like.xu@intel.com, qemu-devel@nongnu.org, Markus Armbruster , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch makes the remaining dozen or so uses of the global current_machine outside vl.c use qdev_get_machine() instead, and then make current_machine local to vl.c instead of global. Suggested-by: Peter Maydell Signed-off-by: Like Xu Reviewed-by: Eduardo Habkost --- accel/kvm/kvm-all.c | 6 ++++-- device-hotplug.c | 3 ++- device_tree.c | 3 ++- exec.c | 6 ++++-- hw/ppc/spapr_rtas.c | 3 ++- include/hw/boards.h | 1 - migration/savevm.c | 9 ++++++--- qmp.c | 3 ++- target/i386/kvm.c | 3 ++- target/ppc/kvm.c | 3 ++- vl.c | 4 ++-- 11 files changed, 28 insertions(+), 16 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 241db49..d103de2 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -140,7 +140,8 @@ static const KVMCapabilityInfo kvm_required_capabilites= [] =3D { =20 int kvm_get_max_memslots(void) { - KVMState *s =3D KVM_STATE(current_machine->accelerator); + MachineState *ms =3D MACHINE(qdev_get_machine()); + KVMState *s =3D KVM_STATE(ms->accelerator); =20 return s->nr_slots; } @@ -1519,7 +1520,8 @@ static int kvm_max_vcpu_id(KVMState *s) =20 bool kvm_vcpu_id_is_valid(int vcpu_id) { - KVMState *s =3D KVM_STATE(current_machine->accelerator); + MachineState *ms =3D MACHINE(qdev_get_machine()); + KVMState *s =3D KVM_STATE(ms->accelerator); return vcpu_id >=3D 0 && vcpu_id < kvm_max_vcpu_id(s); } =20 diff --git a/device-hotplug.c b/device-hotplug.c index 6153259..d31c1f8 100644 --- a/device-hotplug.c +++ b/device-hotplug.c @@ -37,6 +37,7 @@ =20 static DriveInfo *add_init_drive(const char *optstr) { + MachineState *ms =3D MACHINE(qdev_get_machine()); Error *err =3D NULL; DriveInfo *dinfo; QemuOpts *opts; @@ -46,7 +47,7 @@ static DriveInfo *add_init_drive(const char *optstr) if (!opts) return NULL; =20 - mc =3D MACHINE_GET_CLASS(current_machine); + mc =3D MACHINE_GET_CLASS(ms); dinfo =3D drive_new(opts, mc->block_default_type, &err); if (err) { error_report_err(err); diff --git a/device_tree.c b/device_tree.c index f8b46b3..3294ef6 100644 --- a/device_tree.c +++ b/device_tree.c @@ -459,6 +459,7 @@ int qemu_fdt_setprop_phandle(void *fdt, const char *nod= e_path, =20 uint32_t qemu_fdt_alloc_phandle(void *fdt) { + MachineState *ms =3D MACHINE(qdev_get_machine()); static int phandle =3D 0x0; =20 /* @@ -466,7 +467,7 @@ uint32_t qemu_fdt_alloc_phandle(void *fdt) * which phandle id to start allocating phandles. */ if (!phandle) { - phandle =3D machine_phandle_start(current_machine); + phandle =3D machine_phandle_start(ms); } =20 if (!phandle) { diff --git a/exec.c b/exec.c index 6ab62f4..15ff2b1 100644 --- a/exec.c +++ b/exec.c @@ -1969,10 +1969,11 @@ static unsigned long last_ram_page(void) =20 static void qemu_ram_setup_dump(void *addr, ram_addr_t size) { + MachineState *ms =3D MACHINE(qdev_get_machine()); int ret; =20 /* Use MADV_DONTDUMP, if user doesn't want the guest memory in the cor= e */ - if (!machine_dump_guest_core(current_machine)) { + if (!machine_dump_guest_core(ms)) { ret =3D qemu_madvise(addr, size, QEMU_MADV_DONTDUMP); if (ret) { perror("qemu_madvise"); @@ -2094,7 +2095,8 @@ size_t qemu_ram_pagesize_largest(void) =20 static int memory_try_enable_merging(void *addr, size_t len) { - if (!machine_mem_merge(current_machine)) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + if (!machine_mem_merge(ms)) { /* disabled by the user */ return 0; } diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 24c45b1..51e320d 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -231,6 +231,7 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *c= pu, target_ulong args, uint32_t nret, target_ulong rets) { + MachineState *ms =3D MACHINE(spapr); target_ulong parameter =3D rtas_ld(args, 0); target_ulong buffer =3D rtas_ld(args, 1); target_ulong length =3D rtas_ld(args, 2); @@ -243,7 +244,7 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *c= pu, "DesProcs=3D%d," "MaxPlatProcs=3D%d", max_cpus, - current_machine->ram_size / MiB, + ms->ram_size / MiB, smp_cpus, max_cpus); ret =3D sysparm_st(buffer, length, param_val, strlen(param_val) + = 1); diff --git a/include/hw/boards.h b/include/hw/boards.h index e231860..1d598c8 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -58,7 +58,6 @@ void memory_region_allocate_system_memory(MemoryRegion *m= r, Object *owner, OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE) =20 MachineClass *find_default_machine(void); -extern MachineState *current_machine; =20 void machine_run_board_init(MachineState *machine); bool machine_usb(MachineState *machine); diff --git a/migration/savevm.c b/migration/savevm.c index 34bcad3..4261061 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -286,8 +286,9 @@ static uint32_t get_validatable_capabilities_count(void) =20 static int configuration_pre_save(void *opaque) { + MachineState *ms =3D MACHINE(qdev_get_machine()); SaveState *state =3D opaque; - const char *current_name =3D MACHINE_GET_CLASS(current_machine)->name; + const char *current_name =3D MACHINE_GET_CLASS(ms)->name; MigrationState *s =3D migrate_get_current(); int i, j; =20 @@ -355,8 +356,9 @@ static bool configuration_validate_capabilities(SaveSta= te *state) =20 static int configuration_post_load(void *opaque, int version_id) { + MachineState *ms =3D MACHINE(qdev_get_machine()); SaveState *state =3D opaque; - const char *current_name =3D MACHINE_GET_CLASS(current_machine)->name; + const char *current_name =3D MACHINE_GET_CLASS(ms)->name; =20 if (strncmp(state->name, current_name, state->len) !=3D 0) { error_report("Machine type received is '%.*s' and local is '%s'", @@ -566,9 +568,10 @@ static void dump_vmstate_vmsd(FILE *out_file, =20 static void dump_machine_type(FILE *out_file) { + MachineState *ms =3D MACHINE(qdev_get_machine()); MachineClass *mc; =20 - mc =3D MACHINE_GET_CLASS(current_machine); + mc =3D MACHINE_GET_CLASS(ms); =20 fprintf(out_file, " \"vmschkmachine\": {\n"); fprintf(out_file, " \"Name\": \"%s\"\n", mc->name); diff --git a/qmp.c b/qmp.c index b92d62c..f2a5473 100644 --- a/qmp.c +++ b/qmp.c @@ -119,9 +119,10 @@ void qmp_system_powerdown(Error **erp) =20 void qmp_cpu_add(int64_t id, Error **errp) { + MachineState *ms =3D MACHINE(qdev_get_machine()); MachineClass *mc; =20 - mc =3D MACHINE_GET_CLASS(current_machine); + mc =3D MACHINE_GET_CLASS(ms); if (mc->hot_add_cpu) { mc->hot_add_cpu(id, errp); } else { diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 3b29ce5..b25d766 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -134,7 +134,8 @@ bool kvm_allows_irq0_override(void) =20 static bool kvm_x2apic_api_set_flags(uint64_t flags) { - KVMState *s =3D KVM_STATE(current_machine->accelerator); + MachineState *ms =3D MACHINE(qdev_get_machine()); + KVMState *s =3D KVM_STATE(ms->accelerator); =20 return !kvm_vm_enable_cap(s, KVM_CAP_X2APIC_API, 0, flags); } diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 2427c8e..c3bea37 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -276,7 +276,8 @@ static void kvm_get_smmu_info(struct kvm_ppc_smmu_info = *info, Error **errp) =20 struct ppc_radix_page_info *kvm_get_radix_page_info(void) { - KVMState *s =3D KVM_STATE(current_machine->accelerator); + MachineState *ms =3D MACHINE(qdev_get_machine()); + KVMState *s =3D KVM_STATE(ms->accelerator); struct ppc_radix_page_info *radix_page_info; struct kvm_ppc_rmmu_info rmmu_info; int i; diff --git a/vl.c b/vl.c index c696ad2..a1a8b24 100644 --- a/vl.c +++ b/vl.c @@ -1266,6 +1266,8 @@ static QemuOptsList qemu_smp_opts =3D { }, }; =20 +static MachineState *current_machine; + static void smp_parse(QemuOpts *opts) { if (opts) { @@ -1463,8 +1465,6 @@ static int usb_parse(const char *cmdline) /***********************************************************/ /* machine registration */ =20 -MachineState *current_machine; - static MachineClass *find_machine(const char *name) { GSList *el, *machines =3D object_class_get_list(TYPE_MACHINE, false); --=20 1.8.3.1 From nobody Thu Apr 25 03:30:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com ARC-Seal: i=1; a=rsa-sha256; t=1555315380; cv=none; d=zoho.com; s=zohoarc; b=VlgV4O5L+KOkmAYDBfWITP9Mg3fFdAFZnzpzRGzpdU1dtJoRfU4e1JcjnCVLWOFU/rN6sOam+OLdBGhMHzdCzDzauC1npimyJbtWbwptgm09IZxltmLAjgzNKeeBoT3wH5JdiaztpiEzBaUeWauTmjnim7DofwEgMzUd0SbAX7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555315380; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=3/lHhUqE7Jntqvm9tiBH/TyDrtU6ex6Ad1JMS26Lu8I=; b=d8jiB8TQQYOA5XleytDNeRND0CgXYS26c7syUbfzLZ75ne32lI+6N9yLfCqaC8GPMiAcf/V/4zIXUfyRnFAm/+fFUGZeKZ4wDgAgngFGopxhkoMq8erXFtbI8hTZuF+GprtAHchIMNMK5yAVzxeNi9LyZa2CWYq/w1c22N6YvDE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555315380239942.1933078433525; Mon, 15 Apr 2019 01:03:00 -0700 (PDT) Received: from localhost ([127.0.0.1]:46350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hFwZq-0001WI-9l for importer@patchew.org; Mon, 15 Apr 2019 04:02:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hFwXs-0000cC-SL for qemu-devel@nongnu.org; Mon, 15 Apr 2019 04:00:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hFwXr-0001S7-Nl for qemu-devel@nongnu.org; Mon, 15 Apr 2019 04:00:52 -0400 Received: from mga09.intel.com ([134.134.136.24]:40824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hFwXp-0001NR-1Y; Mon, 15 Apr 2019 04:00:49 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Apr 2019 01:00:48 -0700 Received: from xulike-server.sh.intel.com ([10.239.48.134]) by fmsmga008.fm.intel.com with ESMTP; 15 Apr 2019 01:00:46 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,352,1549958400"; d="scan'208";a="140739282" From: Like Xu To: qemu-trivial@nongnu.org Date: Mon, 15 Apr 2019 15:59:45 +0800 Message-Id: <1555315185-16414-3-git-send-email-like.xu@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1555315185-16414-1-git-send-email-like.xu@linux.intel.com> References: <1555315185-16414-1-git-send-email-like.xu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 Subject: [Qemu-devel] [PATCH v3 2/2] core/qdev: refactor qdev_get_machine() with type assertion X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Thomas Huth , Eduardo Habkost , like.xu@intel.com, qemu-devel@nongnu.org, Markus Armbruster , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To avoid the misuse of qdev_get_machine() if machine hasn't been created ye= t, this patch uses qdev_get_machine_uncheck() for obj-common (share with user-= only mode) and adds type assertion to qdev_get_machine() in system-emulation mod= e. Suggested-by: Igor Mammedov Signed-off-by: Like Xu Reviewed-by: Eduardo Habkost --- hw/core/qdev.c | 16 +++++++++++++--- include/hw/qdev-core.h | 1 + qom/cpu.c | 5 +++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f9b6efe..8232216 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -223,7 +223,7 @@ HotplugHandler *qdev_get_machine_hotplug_handler(Device= State *dev) { MachineState *machine; MachineClass *mc; - Object *m_obj =3D qdev_get_machine(); + Object *m_obj =3D qdev_get_machine_uncheck(); =20 if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { machine =3D MACHINE(m_obj); @@ -815,7 +815,7 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) if (!obj->parent) { gchar *name =3D g_strdup_printf("device[%d]", unattached_count= ++); =20 - object_property_add_child(container_get(qdev_get_machine(), + object_property_add_child(container_get(qdev_get_machine_unche= ck(), "/unattached"), name, obj, &error_abort); unattached_parent =3D true; @@ -1095,7 +1095,7 @@ void device_reset(DeviceState *dev) } } =20 -Object *qdev_get_machine(void) +Object *qdev_get_machine_uncheck(void) { static Object *dev; =20 @@ -1106,6 +1106,16 @@ Object *qdev_get_machine(void) return dev; } =20 +Object *qdev_get_machine(void) +{ + static Object *dev; + + dev =3D qdev_get_machine_uncheck(); + assert(object_dynamic_cast(dev, TYPE_MACHINE) !=3D NULL); + + return dev; +} + static const TypeInfo device_type_info =3D { .name =3D TYPE_DEVICE, .parent =3D TYPE_OBJECT, diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 33ed3b8..e7c6a5a 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -429,6 +429,7 @@ const struct VMStateDescription *qdev_get_vmsd(DeviceSt= ate *dev); =20 const char *qdev_fw_name(DeviceState *dev); =20 +Object *qdev_get_machine_uncheck(void); Object *qdev_get_machine(void); =20 /* FIXME: make this a link<> */ diff --git a/qom/cpu.c b/qom/cpu.c index a8d2958..bb877d5 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -325,9 +325,10 @@ static void cpu_common_parse_features(const char *type= name, char *features, static void cpu_common_realizefn(DeviceState *dev, Error **errp) { CPUState *cpu =3D CPU(dev); - Object *machine =3D qdev_get_machine(); + Object *machine =3D qdev_get_machine_uncheck(); =20 - /* qdev_get_machine() can return something that's not TYPE_MACHINE + /* + * qdev_get_machine_uncheck() can return something that's not TYPE_MAC= HINE * if this is one of the user-only emulators; in that case there's * no need to check the ignore_memory_transaction_failures board flag. */ --=20 1.8.3.1