From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502615507336.9498834227536; Mon, 23 Apr 2018 09:56:55 -0700 (PDT) Received: from localhost ([::1]:54537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAelq-0002o3-KW for importer@patchew.org; Mon, 23 Apr 2018 12:56:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAegv-0007Um-3u for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAegr-0007nl-3G for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38246 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAegq-0007mA-RU; Mon, 23 Apr 2018 12:51:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 119ED8DC4F; Mon, 23 Apr 2018 16:51:43 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id C61BA83B9E; Mon, 23 Apr 2018 16:51:40 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:16 +0200 Message-Id: <20180423165126.15441-2-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 23 Apr 2018 16:51:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 23 Apr 2018 16:51:43 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 01/11] pc-dimm: factor out MemoryDevice interface 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" On the qmp level, we already have the concept of memory devices: "query-memory-devices" Right now, we only support NVDIMM and PCDIMM. We want to map other devices later into the address space of the guest. Such device could e.g. be virtio devices. These devices will have a guest memory range assigned but won't be exposed via e.g. ACPI. We want to make them look like memory device, but not glued to pc-dimm. Especially, it will not always be possible to have TYPE_PC_DIMM as a parent class (e.g. virtio devices). Let's use an interface instead. As a first part, convert handling of - qmp_pc_dimm_device_list - get_plugged_memory_size to our new model. plug/unplug stuff etc. will follow later. A memory device will have to provide the following functions: - get_addr(): Necessary, as the property "addr" can e.g. not be used for virtio devices (already defined). - get_plugged_size(): The amount this device offers to the guest as of now. - get_region_size(): Because this can later on be bigger than the plugged size. - fill_device_info(): Fill MemoryDeviceInfo, e.g. for qmp. Reviewed-by: David Gibson Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/i386/acpi-build.c | 3 +- hw/mem/Makefile.objs | 1 + hw/mem/memory-device.c | 120 +++++++++++++++++++++++= ++++ hw/mem/pc-dimm.c | 120 ++++++++++++++---------= ---- hw/ppc/spapr.c | 3 +- hw/ppc/spapr_hcall.c | 1 + include/hw/mem/memory-device.h | 45 ++++++++++ include/hw/mem/pc-dimm.h | 2 - numa.c | 3 +- qmp.c | 4 +- stubs/Makefile.objs | 2 +- stubs/{qmp_pc_dimm.c =3D> qmp_memory_device.c} | 4 +- 12 files changed, 242 insertions(+), 66 deletions(-) create mode 100644 hw/mem/memory-device.c create mode 100644 include/hw/mem/memory-device.h rename stubs/{qmp_pc_dimm.c =3D> qmp_memory_device.c} (61%) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 3cf2a1679c..ca3645d57b 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -46,6 +46,7 @@ #include "hw/acpi/vmgenid.h" #include "sysemu/tpm_backend.h" #include "hw/timer/mc146818rtc_regs.h" +#include "hw/mem/memory-device.h" #include "sysemu/numa.h" =20 /* Supported chipsets: */ @@ -2253,7 +2254,7 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GA= rray *tcpalog) static void build_srat_hotpluggable_memory(GArray *table_data, uint64_t ba= se, uint64_t len, int default_node) { - MemoryDeviceInfoList *info_list =3D qmp_pc_dimm_device_list(); + MemoryDeviceInfoList *info_list =3D qmp_memory_device_list(); MemoryDeviceInfoList *info; MemoryDeviceInfo *mi; PCDIMMDeviceInfo *di; diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs index f12f8b97a2..10be4df2a2 100644 --- a/hw/mem/Makefile.objs +++ b/hw/mem/Makefile.objs @@ -1,2 +1,3 @@ common-obj-$(CONFIG_MEM_HOTPLUG) +=3D pc-dimm.o +common-obj-$(CONFIG_MEM_HOTPLUG) +=3D memory-device.o common-obj-$(CONFIG_NVDIMM) +=3D nvdimm.o diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c new file mode 100644 index 0000000000..6cbdaf99f3 --- /dev/null +++ b/hw/mem/memory-device.c @@ -0,0 +1,120 @@ +/* + * Memory Device Interface + * + * Copyright ProfitBricks GmbH 2012 + * Copyright (C) 2014 Red Hat Inc + * Copyright (c) 2018 Red Hat Inc + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/mem/memory-device.h" +#include "hw/qdev.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "qemu/range.h" + +static gint memory_device_addr_sort(gconstpointer a, gconstpointer b) +{ + const MemoryDeviceState *md_a =3D MEMORY_DEVICE(a); + const MemoryDeviceState *md_b =3D MEMORY_DEVICE(b); + const MemoryDeviceClass *mdc_a =3D MEMORY_DEVICE_GET_CLASS(a); + const MemoryDeviceClass *mdc_b =3D MEMORY_DEVICE_GET_CLASS(b); + const uint64_t addr_a =3D mdc_a->get_addr(md_a); + const uint64_t addr_b =3D mdc_b->get_addr(md_b); + + if (addr_a > addr_b) { + return 1; + } else if (addr_a < addr_b) { + return -1; + } + return 0; +} + +static int memory_device_build_list(Object *obj, void *opaque) +{ + GSList **list =3D opaque; + + if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) { + DeviceState *dev =3D DEVICE(obj); + if (dev->realized) { /* only realized memory devices matter */ + *list =3D g_slist_insert_sorted(*list, dev, memory_device_addr= _sort); + } + } + + object_child_foreach(obj, memory_device_build_list, opaque); + return 0; +} + +MemoryDeviceInfoList *qmp_memory_device_list(void) +{ + GSList *devices =3D NULL, *item; + MemoryDeviceInfoList *list =3D NULL, *prev =3D NULL; + + object_child_foreach(qdev_get_machine(), memory_device_build_list, + &devices); + + for (item =3D devices; item; item =3D g_slist_next(item)) { + const MemoryDeviceState *md =3D MEMORY_DEVICE(item->data); + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(item->dat= a); + MemoryDeviceInfoList *elem =3D g_new0(MemoryDeviceInfoList, 1); + MemoryDeviceInfo *info =3D g_new0(MemoryDeviceInfo, 1); + + mdc->fill_device_info(md, info); + + elem->value =3D info; + elem->next =3D NULL; + if (prev) { + prev->next =3D elem; + } else { + list =3D elem; + } + prev =3D elem; + } + + g_slist_free(devices); + + return list; +} + +static int memory_device_plugged_size(Object *obj, void *opaque) +{ + uint64_t *size =3D opaque; + + if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) { + const DeviceState *dev =3D DEVICE(obj); + const MemoryDeviceState *md =3D MEMORY_DEVICE(obj); + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(obj); + + if (dev->realized) { + *size +=3D mdc->get_plugged_size(md); + } + } + + object_child_foreach(obj, memory_device_plugged_size, opaque); + return 0; +} + +uint64_t get_plugged_memory_size(void) +{ + uint64_t size =3D 0; + + memory_device_plugged_size(qdev_get_machine(), &size); + + return size; +} + +static const TypeInfo memory_device_info =3D { + .name =3D TYPE_MEMORY_DEVICE, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(MemoryDeviceClass), +}; + +static void memory_device_register_types(void) +{ + type_register_static(&memory_device_info); +} + +type_init(memory_device_register_types) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 51350d9c2d..ef330628c1 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" +#include "hw/mem/memory-device.h" #include "qapi/error.h" #include "qemu/config-file.h" #include "qapi/visitor.h" @@ -158,11 +159,6 @@ uint64_t pc_existing_dimms_capacity(Error **errp) return cap.size; } =20 -uint64_t get_plugged_memory_size(void) -{ - return pc_existing_dimms_capacity(&error_abort); -} - static int pc_dimm_slot2bitmap(Object *obj, void *opaque) { unsigned long *bitmap =3D opaque; @@ -238,57 +234,6 @@ static int pc_dimm_built_list(Object *obj, void *opaqu= e) return 0; } =20 -MemoryDeviceInfoList *qmp_pc_dimm_device_list(void) -{ - GSList *dimms =3D NULL, *item; - MemoryDeviceInfoList *list =3D NULL, *prev =3D NULL; - - object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &dimms); - - for (item =3D dimms; item; item =3D g_slist_next(item)) { - PCDIMMDevice *dimm =3D PC_DIMM(item->data); - Object *obj =3D OBJECT(dimm); - MemoryDeviceInfoList *elem =3D g_new0(MemoryDeviceInfoList, 1); - MemoryDeviceInfo *info =3D g_new0(MemoryDeviceInfo, 1); - PCDIMMDeviceInfo *di =3D g_new0(PCDIMMDeviceInfo, 1); - bool is_nvdimm =3D object_dynamic_cast(obj, TYPE_NVDIMM); - DeviceClass *dc =3D DEVICE_GET_CLASS(obj); - DeviceState *dev =3D DEVICE(obj); - - if (dev->id) { - di->has_id =3D true; - di->id =3D g_strdup(dev->id); - } - di->hotplugged =3D dev->hotplugged; - di->hotpluggable =3D dc->hotpluggable; - di->addr =3D dimm->addr; - di->slot =3D dimm->slot; - di->node =3D dimm->node; - di->size =3D object_property_get_uint(obj, PC_DIMM_SIZE_PROP, NULL= ); - di->memdev =3D object_get_canonical_path(OBJECT(dimm->hostmem)); - - if (!is_nvdimm) { - info->u.dimm.data =3D di; - info->type =3D MEMORY_DEVICE_INFO_KIND_DIMM; - } else { - info->u.nvdimm.data =3D di; - info->type =3D MEMORY_DEVICE_INFO_KIND_NVDIMM; - } - elem->value =3D info; - elem->next =3D NULL; - if (prev) { - prev->next =3D elem; - } else { - list =3D elem; - } - prev =3D elem; - } - - g_slist_free(dimms); - - return list; -} - uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t si= ze, @@ -445,10 +390,63 @@ static MemoryRegion *pc_dimm_get_vmstate_memory_regio= n(PCDIMMDevice *dimm) return host_memory_backend_get_memory(dimm->hostmem, &error_abort); } =20 +static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md) +{ + const PCDIMMDevice *dimm =3D PC_DIMM(md); + + return dimm->addr; +} + +static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md) +{ + /* dropping const here is fine as we don't touch the memory region */ + PCDIMMDevice *dimm =3D PC_DIMM(md); + const PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(md); + MemoryRegion *mr; + + mr =3D ddc->get_memory_region(dimm, &error_abort); + if (!mr) { + return 0; + } + + return memory_region_size(mr); +} + +static void pc_dimm_md_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + PCDIMMDeviceInfo *di =3D g_new0(PCDIMMDeviceInfo, 1); + const DeviceClass *dc =3D DEVICE_GET_CLASS(md); + const PCDIMMDevice *dimm =3D PC_DIMM(md); + const DeviceState *dev =3D DEVICE(md); + + if (dev->id) { + di->has_id =3D true; + di->id =3D g_strdup(dev->id); + } + di->hotplugged =3D dev->hotplugged; + di->hotpluggable =3D dc->hotpluggable; + di->addr =3D dimm->addr; + di->slot =3D dimm->slot; + di->node =3D dimm->node; + di->size =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_SIZE_PROP, + NULL); + di->memdev =3D object_get_canonical_path(OBJECT(dimm->hostmem)); + + if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) { + info->u.nvdimm.data =3D di; + info->type =3D MEMORY_DEVICE_INFO_KIND_NVDIMM; + } else { + info->u.dimm.data =3D di; + info->type =3D MEMORY_DEVICE_INFO_KIND_DIMM; + } +} + static void pc_dimm_class_init(ObjectClass *oc, void *data) { DeviceClass *dc =3D DEVICE_CLASS(oc); PCDIMMDeviceClass *ddc =3D PC_DIMM_CLASS(oc); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(oc); =20 dc->realize =3D pc_dimm_realize; dc->unrealize =3D pc_dimm_unrealize; @@ -457,6 +455,12 @@ static void pc_dimm_class_init(ObjectClass *oc, void *= data) =20 ddc->get_memory_region =3D pc_dimm_get_memory_region; ddc->get_vmstate_memory_region =3D pc_dimm_get_vmstate_memory_region; + + mdc->get_addr =3D pc_dimm_md_get_addr; + /* for a dimm plugged_size =3D=3D region_size */ + mdc->get_plugged_size =3D pc_dimm_md_get_region_size; + mdc->get_region_size =3D pc_dimm_md_get_region_size; + mdc->fill_device_info =3D pc_dimm_md_fill_device_info; } =20 static TypeInfo pc_dimm_info =3D { @@ -466,6 +470,10 @@ static TypeInfo pc_dimm_info =3D { .instance_init =3D pc_dimm_init, .class_init =3D pc_dimm_class_init, .class_size =3D sizeof(PCDIMMDeviceClass), + .interfaces =3D (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, }; =20 static void pc_dimm_register_types(void) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a81570e7c8..a7428f7da7 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -74,6 +74,7 @@ #include "hw/compat.h" #include "qemu/cutils.h" #include "hw/ppc/spapr_cpu_core.h" +#include "hw/mem/memory-device.h" =20 #include =20 @@ -722,7 +723,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineSta= te *spapr, void *fdt) } =20 if (hotplug_lmb_start) { - dimms =3D qmp_pc_dimm_device_list(); + dimms =3D qmp_memory_device_list(); } =20 /* ibm,dynamic-memory */ diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 16bccdd5c0..4cdae3ca3a 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -14,6 +14,7 @@ #include "kvm_ppc.h" #include "hw/ppc/spapr_ovec.h" #include "mmu-book3s-v3.h" +#include "hw/mem/memory-device.h" =20 struct SPRSyncState { int spr; diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h new file mode 100644 index 0000000000..31f64cbab2 --- /dev/null +++ b/include/hw/mem/memory-device.h @@ -0,0 +1,45 @@ +/* + * Memory Device Interface + * + * Copyright (c) 2018 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef MEMORY_DEVICE_H +#define MEMORY_DEVICE_H + +#include "qom/object.h" +#include "hw/qdev.h" + +#define TYPE_MEMORY_DEVICE "memory-device" + +#define MEMORY_DEVICE_CLASS(klass) \ + OBJECT_CLASS_CHECK(MemoryDeviceClass, (klass), TYPE_MEMORY_DEVICE) +#define MEMORY_DEVICE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(MemoryDeviceClass, (obj), TYPE_MEMORY_DEVICE) +#define MEMORY_DEVICE(obj) \ + INTERFACE_CHECK(MemoryDeviceState, (obj), TYPE_MEMORY_DEVICE) + +typedef struct MemoryDeviceState { + Object parent_obj; +} MemoryDeviceState; + +typedef struct MemoryDeviceClass { + InterfaceClass parent_class; + + uint64_t (*get_addr)(const MemoryDeviceState *md); + uint64_t (*get_plugged_size)(const MemoryDeviceState *md); + uint64_t (*get_region_size)(const MemoryDeviceState *md); + void (*fill_device_info)(const MemoryDeviceState *md, + MemoryDeviceInfo *info); +} MemoryDeviceClass; + +MemoryDeviceInfoList *qmp_memory_device_list(void); +uint64_t get_plugged_memory_size(void); + +#endif diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 1fc479281c..e88073321f 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -93,9 +93,7 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_sta= rt, =20 int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); =20 -MemoryDeviceInfoList *qmp_pc_dimm_device_list(void); uint64_t pc_existing_dimms_capacity(Error **errp); -uint64_t get_plugged_memory_size(void); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, MemoryRegion *mr, uint64_t align, Error **errp); void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms, diff --git a/numa.c b/numa.c index 1116c90af9..6a0eaebc01 100644 --- a/numa.c +++ b/numa.c @@ -36,6 +36,7 @@ #include "hw/boards.h" #include "sysemu/hostmem.h" #include "hw/mem/pc-dimm.h" +#include "hw/mem/memory-device.h" #include "qemu/option.h" #include "qemu/config-file.h" #include "qemu/cutils.h" @@ -520,7 +521,7 @@ void memory_region_allocate_system_memory(MemoryRegion = *mr, Object *owner, =20 static void numa_stat_memory_devices(NumaNodeMem node_mem[]) { - MemoryDeviceInfoList *info_list =3D qmp_pc_dimm_device_list(); + MemoryDeviceInfoList *info_list =3D qmp_memory_device_list(); MemoryDeviceInfoList *info; PCDIMMDeviceInfo *pcdimm_info; =20 diff --git a/qmp.c b/qmp.c index f72261667f..3de029946a 100644 --- a/qmp.c +++ b/qmp.c @@ -39,7 +39,7 @@ #include "qapi/qobject-input-visitor.h" #include "hw/boards.h" #include "qom/object_interfaces.h" -#include "hw/mem/pc-dimm.h" +#include "hw/mem/memory-device.h" #include "hw/acpi/acpi_dev_interface.h" =20 NameInfo *qmp_query_name(Error **errp) @@ -731,7 +731,7 @@ void qmp_object_del(const char *id, Error **errp) =20 MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) { - return qmp_pc_dimm_device_list(); + return qmp_memory_device_list(); } =20 ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 2d59d84091..53d3f32cb2 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -34,7 +34,7 @@ stub-obj-y +=3D uuid.o stub-obj-y +=3D vm-stop.o stub-obj-y +=3D vmstate.o stub-obj-$(CONFIG_WIN32) +=3D fd-register.o -stub-obj-y +=3D qmp_pc_dimm.o +stub-obj-y +=3D qmp_memory_device.o stub-obj-y +=3D target-monitor-defs.o stub-obj-y +=3D target-get-monitor-def.o stub-obj-y +=3D pc_madt_cpu_entry.o diff --git a/stubs/qmp_pc_dimm.c b/stubs/qmp_memory_device.c similarity index 61% rename from stubs/qmp_pc_dimm.c rename to stubs/qmp_memory_device.c index b6b2cca89e..85ff8f2d7e 100644 --- a/stubs/qmp_pc_dimm.c +++ b/stubs/qmp_memory_device.c @@ -1,8 +1,8 @@ #include "qemu/osdep.h" #include "qom/object.h" -#include "hw/mem/pc-dimm.h" +#include "hw/mem/memory-device.h" =20 -MemoryDeviceInfoList *qmp_pc_dimm_device_list(void) +MemoryDeviceInfoList *qmp_memory_device_list(void) { return NULL; } --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502620182785.873379765182; Mon, 23 Apr 2018 09:57:00 -0700 (PDT) Received: from localhost ([::1]:54538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAelv-0002si-99 for importer@patchew.org; Mon, 23 Apr 2018 12:56:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49573) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAegv-0007Un-3v for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAegs-0007rk-59 for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38252 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAegr-0007pl-UV; Mon, 23 Apr 2018 12:51:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B1F57D843; Mon, 23 Apr 2018 16:51:45 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CC8483B9E; Mon, 23 Apr 2018 16:51:43 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:17 +0200 Message-Id: <20180423165126.15441-3-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 23 Apr 2018 16:51:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 23 Apr 2018 16:51:45 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 02/11] machine: make MemoryHotplugState accessible via the machine 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's allow to query the MemoryHotplugState directly from the machine. If the pointer is NULL, the machine does not support memory devices. If the pointer is !NULL, the machine supports memory devices and the data structure contains information about the applicable physical guest address space region. This allows us to generically detect if a certain machine has support for memory devices, and to generically manage it (find free address range, plug/unplug a memory region). We will rename "MemoryHotplugState" to something more meaningful ("DeviceMemory") after we completed factoring out the pc-dimm code into MemoryDevice code. Signed-off-by: David Hildenbrand Reviewed-by: Marcel Apfelbaum Reviewed-by: Michael S. Tsirkin --- hw/i386/acpi-build.c | 2 +- hw/i386/pc.c | 35 ++++++++++++++++++++--------------- hw/ppc/spapr.c | 35 +++++++++++++++++++---------------- hw/ppc/spapr_hcall.c | 2 +- hw/ppc/spapr_rtas_ddw.c | 2 +- include/hw/boards.h | 12 ++++++++++++ include/hw/i386/pc.h | 1 - include/hw/mem/pc-dimm.h | 12 +----------- include/hw/ppc/spapr.h | 1 - 9 files changed, 55 insertions(+), 47 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index ca3645d57b..70b37e6df4 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2411,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, Ma= chineState *machine) * providing _PXM method if necessary. */ if (hotplugabble_address_space_size) { - build_srat_hotpluggable_memory(table_data, pcms->hotplug_memory.ba= se, + build_srat_hotpluggable_memory(table_data, machine->device_memory-= >base, hotplugabble_address_space_size, pcms->numa_nodes - 1); } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d36bac8c89..19af0733fd 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1371,6 +1371,9 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 + /* always allocate the device memory information */ + machine->device_memory =3D g_malloc(sizeof(*machine->device_memory)); + /* initialize hotplug memory address space */ if (pcmc->has_reserved_memory && (machine->ram_size < machine->maxram_size)) { @@ -1390,7 +1393,7 @@ void pc_memory_init(PCMachineState *pcms, exit(EXIT_FAILURE); } =20 - pcms->hotplug_memory.base =3D + machine->device_memory->base =3D ROUND_UP(0x100000000ULL + pcms->above_4g_mem_size, 1ULL << 30); =20 if (pcmc->enforce_aligned_dimm) { @@ -1398,17 +1401,17 @@ void pc_memory_init(PCMachineState *pcms, hotplug_mem_size +=3D (1ULL << 30) * machine->ram_slots; } =20 - if ((pcms->hotplug_memory.base + hotplug_mem_size) < + if ((machine->device_memory->base + hotplug_mem_size) < hotplug_mem_size) { error_report("unsupported amount of maximum memory: " RAM_ADDR= _FMT, machine->maxram_size); exit(EXIT_FAILURE); } =20 - memory_region_init(&pcms->hotplug_memory.mr, OBJECT(pcms), + memory_region_init(&machine->device_memory->mr, OBJECT(pcms), "hotplug-memory", hotplug_mem_size); - memory_region_add_subregion(system_memory, pcms->hotplug_memory.ba= se, - &pcms->hotplug_memory.mr); + memory_region_add_subregion(system_memory, machine->device_memory-= >base, + &machine->device_memory->mr); } =20 /* Initialize PC system firmware */ @@ -1429,13 +1432,13 @@ void pc_memory_init(PCMachineState *pcms, =20 rom_set_fw(fw_cfg); =20 - if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) { + if (pcmc->has_reserved_memory && machine->device_memory->base) { uint64_t *val =3D g_malloc(sizeof(*val)); PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); - uint64_t res_mem_end =3D pcms->hotplug_memory.base; + uint64_t res_mem_end =3D machine->device_memory->base; =20 if (!pcmc->broken_reserved_end) { - res_mem_end +=3D memory_region_size(&pcms->hotplug_memory.mr); + res_mem_end +=3D memory_region_size(&machine->device_memory->m= r); } *val =3D cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30)); fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*va= l)); @@ -1462,12 +1465,13 @@ uint64_t pc_pci_hole64_start(void) { PCMachineState *pcms =3D PC_MACHINE(qdev_get_machine()); PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); + MachineState *ms =3D MACHINE(pcms); uint64_t hole64_start =3D 0; =20 - if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) { - hole64_start =3D pcms->hotplug_memory.base; + if (pcmc->has_reserved_memory && ms->device_memory->base) { + hole64_start =3D ms->device_memory->base; if (!pcmc->broken_reserved_end) { - hole64_start +=3D memory_region_size(&pcms->hotplug_memory.mr); + hole64_start +=3D memory_region_size(&ms->device_memory->mr); } } else { hole64_start =3D 0x100000000ULL + pcms->above_4g_mem_size; @@ -1711,7 +1715,8 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, goto out; } =20 - pc_dimm_memory_plug(dev, &pcms->hotplug_memory, mr, align, &local_err); + pc_dimm_memory_plug(dev, MACHINE(pcms)->device_memory, mr, align, + &local_err); if (local_err) { goto out; } @@ -1779,7 +1784,7 @@ static void pc_dimm_unplug(HotplugHandler *hotplug_de= v, goto out; } =20 - pc_dimm_memory_unplug(dev, &pcms->hotplug_memory, mr); + pc_dimm_memory_unplug(dev, MACHINE(pcms)->device_memory, mr); object_unparent(OBJECT(dev)); =20 out: @@ -2072,8 +2077,8 @@ pc_machine_get_hotplug_memory_region_size(Object *obj= , Visitor *v, const char *name, void *opaque, Error **errp) { - PCMachineState *pcms =3D PC_MACHINE(obj); - int64_t value =3D memory_region_size(&pcms->hotplug_memory.mr); + MachineState *ms =3D MACHINE(obj); + int64_t value =3D memory_region_size(&ms->device_memory->mr); =20 visit_type_int(v, name, &value, errp); } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a7428f7da7..56d5e8201b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -681,9 +681,9 @@ static int spapr_populate_drconf_memory(sPAPRMachineSta= te *spapr, void *fdt) int ret, i, offset; uint64_t lmb_size =3D SPAPR_MEMORY_BLOCK_SIZE; uint32_t prop_lmb_size[] =3D {0, cpu_to_be32(lmb_size)}; - uint32_t hotplug_lmb_start =3D spapr->hotplug_memory.base / lmb_size; - uint32_t nr_lmbs =3D (spapr->hotplug_memory.base + - memory_region_size(&spapr->hotplug_memory.mr)) / + uint32_t hotplug_lmb_start =3D machine->device_memory->base / lmb_size; + uint32_t nr_lmbs =3D (machine->device_memory->base + + memory_region_size(&machine->device_memory->mr)) / lmb_size; uint32_t *int_buf, *cur_index, buf_len; int nr_nodes =3D nb_numa_nodes ? nb_numa_nodes : 1; @@ -903,8 +903,8 @@ static void spapr_dt_rtas(sPAPRMachineState *spapr, voi= d *fdt) GString *hypertas =3D g_string_sized_new(256); GString *qemu_hypertas =3D g_string_sized_new(256); uint32_t refpoints[] =3D { cpu_to_be32(0x4), cpu_to_be32(0x4) }; - uint64_t max_hotplug_addr =3D spapr->hotplug_memory.base + - memory_region_size(&spapr->hotplug_memory.mr); + uint64_t max_hotplug_addr =3D MACHINE(spapr)->device_memory->base + + memory_region_size(&MACHINE(spapr)->device_memory->mr); uint32_t lrdr_capacity[] =3D { cpu_to_be32(max_hotplug_addr >> 32), cpu_to_be32(max_hotplug_addr & 0xffffffff), @@ -2174,7 +2174,7 @@ static void spapr_create_lmb_dr_connectors(sPAPRMachi= neState *spapr) for (i =3D 0; i < nr_lmbs; i++) { uint64_t addr; =20 - addr =3D i * lmb_size + spapr->hotplug_memory.base; + addr =3D i * lmb_size + machine->device_memory->base; spapr_dr_connector_new(OBJECT(spapr), TYPE_SPAPR_DRC_LMB, addr / lmb_size); } @@ -2526,7 +2526,10 @@ static void spapr_machine_init(MachineState *machine) memory_region_add_subregion(sysmem, 0, rma_region); } =20 - /* initialize hotplug memory address space */ + /* always allocate the device memory information */ + machine->device_memory =3D g_malloc(sizeof(*machine->device_memory)); + + /* initialize device memory address space */ if (machine->ram_size < machine->maxram_size) { ram_addr_t hotplug_mem_size =3D machine->maxram_size - machine->ra= m_size; /* @@ -2547,12 +2550,12 @@ static void spapr_machine_init(MachineState *machin= e) exit(1); } =20 - spapr->hotplug_memory.base =3D ROUND_UP(machine->ram_size, + machine->device_memory->base =3D ROUND_UP(machine->ram_size, SPAPR_HOTPLUG_MEM_ALIGN); - memory_region_init(&spapr->hotplug_memory.mr, OBJECT(spapr), + memory_region_init(&machine->device_memory->mr, OBJECT(spapr), "hotplug-memory", hotplug_mem_size); - memory_region_add_subregion(sysmem, spapr->hotplug_memory.base, - &spapr->hotplug_memory.mr); + memory_region_add_subregion(sysmem, machine->device_memory->base, + &machine->device_memory->mr); } =20 if (smc->dr_lmb_enabled) { @@ -3041,7 +3044,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, align =3D memory_region_get_alignment(mr); size =3D memory_region_size(mr); =20 - pc_dimm_memory_plug(dev, &ms->hotplug_memory, mr, align, &local_err); + pc_dimm_memory_plug(dev, MACHINE(ms)->device_memory, mr, align, &local= _err); if (local_err) { goto out; } @@ -3062,7 +3065,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, return; =20 out_unplug: - pc_dimm_memory_unplug(dev, &ms->hotplug_memory, mr); + pc_dimm_memory_unplug(dev, MACHINE(ms)->device_memory, mr); out: error_propagate(errp, local_err); } @@ -3202,7 +3205,7 @@ void spapr_lmb_release(DeviceState *dev) * Now that all the LMBs have been removed by the guest, call the * pc-dimm unplug handler to cleanup up the pc-dimm device. */ - pc_dimm_memory_unplug(dev, &spapr->hotplug_memory, mr); + pc_dimm_memory_unplug(dev, MACHINE(spapr)->device_memory, mr); object_unparent(OBJECT(dev)); spapr_pending_dimm_unplugs_remove(spapr, ds); } @@ -4159,8 +4162,8 @@ static void phb_placement_2_7(sPAPRMachineState *spap= r, uint32_t index, /* Can't just use maxram_size, because there may be an * alignment gap between normal and hotpluggable memory * regions */ - ram_top =3D spapr->hotplug_memory.base + - memory_region_size(&spapr->hotplug_memory.mr); + ram_top =3D MACHINE(spapr)->device_memory->base + + memory_region_size(&MACHINE(spapr)->device_memory->mr); } =20 phb0_base =3D QEMU_ALIGN_UP(ram_top, phb0_alignment); diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 4cdae3ca3a..e99686389d 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -64,7 +64,7 @@ static inline bool valid_ptex(PowerPCCPU *cpu, target_ulo= ng ptex) static bool is_ram_address(sPAPRMachineState *spapr, hwaddr addr) { MachineState *machine =3D MACHINE(spapr); - MemoryHotplugState *hpms =3D &spapr->hotplug_memory; + MemoryHotplugState *hpms =3D machine->device_memory; =20 if (addr < machine->ram_size) { return true; diff --git a/hw/ppc/spapr_rtas_ddw.c b/hw/ppc/spapr_rtas_ddw.c index 177dcffc9b..d3666c1921 100644 --- a/hw/ppc/spapr_rtas_ddw.c +++ b/hw/ppc/spapr_rtas_ddw.c @@ -122,7 +122,7 @@ static void rtas_ibm_query_pe_dma_window(PowerPCCPU *cp= u, if (machine->ram_size =3D=3D machine->maxram_size) { max_window_size =3D machine->ram_size; } else { - MemoryHotplugState *hpms =3D &spapr->hotplug_memory; + MemoryHotplugState *hpms =3D machine->device_memory; =20 max_window_size =3D hpms->base + memory_region_size(&hpms->mr); } diff --git a/include/hw/boards.h b/include/hw/boards.h index a609239112..ffc1ee782f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -214,6 +214,17 @@ struct MachineClass { int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx); }; =20 +/** + * MemoryHotplugState: + * @base: address in guest physical address space where the memory + * address space for memory devices starts + * @mr: address space container for memory devices + */ +typedef struct MemoryHotplugState { + hwaddr base; + MemoryRegion mr; +} MemoryHotplugState; + /** * MachineState: */ @@ -244,6 +255,7 @@ struct MachineState { bool enforce_config_section; bool enable_graphics; char *memory_encryption; + MemoryHotplugState *device_memory; =20 ram_addr_t ram_size; ram_addr_t maxram_size; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index ffee8413f0..07b596ee76 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -32,7 +32,6 @@ struct PCMachineState { /* */ =20 /* State for other subsystems/APIs: */ - MemoryHotplugState hotplug_memory; Notifier machine_done; =20 /* Pointers to devices and objects: */ diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index e88073321f..8bda37adab 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -19,6 +19,7 @@ #include "exec/memory.h" #include "sysemu/hostmem.h" #include "hw/qdev.h" +#include "hw/boards.h" =20 #define TYPE_PC_DIMM "pc-dimm" #define PC_DIMM(obj) \ @@ -75,17 +76,6 @@ typedef struct PCDIMMDeviceClass { MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm); } PCDIMMDeviceClass; =20 -/** - * MemoryHotplugState: - * @base: address in guest physical address space where hotplug memory - * address space begins. - * @mr: hotplug memory address space container - */ -typedef struct MemoryHotplugState { - hwaddr base; - MemoryRegion mr; -} MemoryHotplugState; - uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t si= ze, diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index d60b7c6d7a..56ff02d32a 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -162,7 +162,6 @@ struct sPAPRMachineState { =20 /*< public >*/ char *kvm_type; - MemoryHotplugState hotplug_memory; =20 const char *icp_type; =20 --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502444817563.2915199427421; Mon, 23 Apr 2018 09:54:04 -0700 (PDT) Received: from localhost ([::1]:54519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAej6-0000HT-27 for importer@patchew.org; Mon, 23 Apr 2018 12:54:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAegv-0007Up-QD for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAegu-0007ze-K1 for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59144 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAegu-0007yP-EE; Mon, 23 Apr 2018 12:51:48 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E363781A88D4; Mon, 23 Apr 2018 16:51:47 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id A67B57C5E; Mon, 23 Apr 2018 16:51:45 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:18 +0200 Message-Id: <20180423165126.15441-4-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:51:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:51:47 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 03/11] pc-dimm: no need to pass the memory region 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We can just query it ourselves. When unplugging, we should always be able to the region (as it was previously plugged). E.g. PPC already assumed that and used &error_abort. Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/i386/pc.c | 13 ++----------- hw/mem/pc-dimm.c | 12 +++++++++--- hw/ppc/spapr.c | 9 +++------ include/hw/mem/pc-dimm.h | 5 ++--- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 19af0733fd..c14dec492b 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1715,8 +1715,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, goto out; } =20 - pc_dimm_memory_plug(dev, MACHINE(pcms)->device_memory, mr, align, - &local_err); + pc_dimm_memory_plug(dev, MACHINE(pcms)->device_memory, align, &local_e= rr); if (local_err) { goto out; } @@ -1766,17 +1765,9 @@ static void pc_dimm_unplug(HotplugHandler *hotplug_d= ev, DeviceState *dev, Error **errp) { PCMachineState *pcms =3D PC_MACHINE(hotplug_dev); - PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr; HotplugHandlerClass *hhc; Error *local_err =3D NULL; =20 - mr =3D ddc->get_memory_region(dimm, &local_err); - if (local_err) { - goto out; - } - hhc =3D HOTPLUG_HANDLER_GET_CLASS(pcms->acpi_dev); hhc->unplug(HOTPLUG_HANDLER(pcms->acpi_dev), dev, &local_err); =20 @@ -1784,7 +1775,7 @@ static void pc_dimm_unplug(HotplugHandler *hotplug_de= v, goto out; } =20 - pc_dimm_memory_unplug(dev, MACHINE(pcms)->device_memory, mr); + pc_dimm_memory_unplug(dev, MACHINE(pcms)->device_memory); object_unparent(OBJECT(dev)); =20 out: diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index ef330628c1..aeff369f6f 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -37,7 +37,7 @@ typedef struct pc_dimms_capacity { } pc_dimms_capacity; =20 void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, - MemoryRegion *mr, uint64_t align, Error **errp) + uint64_t align, Error **errp) { int slot; MachineState *machine =3D MACHINE(qdev_get_machine()); @@ -46,8 +46,14 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplug= State *hpms, MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); Error *local_err =3D NULL; uint64_t existing_dimms_capacity =3D 0; + MemoryRegion *mr; uint64_t addr; =20 + mr =3D ddc->get_memory_region(dimm, &local_err); + if (local_err) { + goto out; + } + addr =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, &local_err); if (local_err) { @@ -116,12 +122,12 @@ out: error_propagate(errp, local_err); } =20 -void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms, - MemoryRegion *mr) +void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms) { PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); + MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); =20 memory_region_del_subregion(&hpms->mr, mr); vmstate_unregister_ram(vmstate_mr, dev); diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 56d5e8201b..8c13d165b4 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3044,7 +3044,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, align =3D memory_region_get_alignment(mr); size =3D memory_region_size(mr); =20 - pc_dimm_memory_plug(dev, MACHINE(ms)->device_memory, mr, align, &local= _err); + pc_dimm_memory_plug(dev, MACHINE(ms)->device_memory, align, &local_err= ); if (local_err) { goto out; } @@ -3065,7 +3065,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, return; =20 out_unplug: - pc_dimm_memory_unplug(dev, MACHINE(ms)->device_memory, mr); + pc_dimm_memory_unplug(dev, MACHINE(ms)->device_memory); out: error_propagate(errp, local_err); } @@ -3183,9 +3183,6 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_sta= te(sPAPRMachineState *ms, void spapr_lmb_release(DeviceState *dev) { sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_hotplug_handler(de= v)); - PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(= dev)); =20 /* This information will get lost if a migration occurs @@ -3205,7 +3202,7 @@ void spapr_lmb_release(DeviceState *dev) * Now that all the LMBs have been removed by the guest, call the * pc-dimm unplug handler to cleanup up the pc-dimm device. */ - pc_dimm_memory_unplug(dev, MACHINE(spapr)->device_memory, mr); + pc_dimm_memory_unplug(dev, MACHINE(spapr)->device_memory); object_unparent(OBJECT(dev)); spapr_pending_dimm_unplugs_remove(spapr, ds); } diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 8bda37adab..1d26e13cef 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -85,7 +85,6 @@ int pc_dimm_get_free_slot(const int *hint, int max_slots,= Error **errp); =20 uint64_t pc_existing_dimms_capacity(Error **errp); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, - MemoryRegion *mr, uint64_t align, Error **errp); -void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms, - MemoryRegion *mr); + uint64_t align, Error **errp); +void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms); #endif --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502795242599.723327523627; Mon, 23 Apr 2018 09:59:55 -0700 (PDT) Received: from localhost ([::1]:54555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAeok-0005S4-HE for importer@patchew.org; Mon, 23 Apr 2018 12:59:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAegy-0007VH-3T for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAegx-00086i-1x for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:51:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34386 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAegw-000855-SG; Mon, 23 Apr 2018 12:51:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5939C406C784; Mon, 23 Apr 2018 16:51:50 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A75B16791; Mon, 23 Apr 2018 16:51:48 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:19 +0200 Message-Id: <20180423165126.15441-5-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 16:51:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 16:51:50 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 04/11] pc-dimm: pass in the machine and to the MemoryHotplugState 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We use the machine internally either way, so let's just pass it in then. Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/i386/pc.c | 4 ++-- hw/mem/pc-dimm.c | 8 ++++---- hw/ppc/spapr.c | 6 +++--- include/hw/mem/pc-dimm.h | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c14dec492b..4b2ede9029 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1715,7 +1715,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, goto out; } =20 - pc_dimm_memory_plug(dev, MACHINE(pcms)->device_memory, align, &local_e= rr); + pc_dimm_memory_plug(dev, MACHINE(pcms), align, &local_err); if (local_err) { goto out; } @@ -1775,7 +1775,7 @@ static void pc_dimm_unplug(HotplugHandler *hotplug_de= v, goto out; } =20 - pc_dimm_memory_unplug(dev, MACHINE(pcms)->device_memory); + pc_dimm_memory_unplug(dev, MACHINE(pcms)); object_unparent(OBJECT(dev)); =20 out: diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index aeff369f6f..37b8be80a1 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -36,11 +36,11 @@ typedef struct pc_dimms_capacity { Error **errp; } pc_dimms_capacity; =20 -void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, +void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, uint64_t align, Error **errp) { int slot; - MachineState *machine =3D MACHINE(qdev_get_machine()); + MemoryHotplugState *hpms =3D machine->device_memory; PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); @@ -122,14 +122,14 @@ out: error_propagate(errp, local_err); } =20 -void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms) +void pc_dimm_memory_unplug(DeviceState *dev, MachineState *machine) { PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); =20 - memory_region_del_subregion(&hpms->mr, mr); + memory_region_del_subregion(&machine->device_memory->mr, mr); vmstate_unregister_ram(vmstate_mr, dev); } =20 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 8c13d165b4..8ecb716f72 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3044,7 +3044,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, align =3D memory_region_get_alignment(mr); size =3D memory_region_size(mr); =20 - pc_dimm_memory_plug(dev, MACHINE(ms)->device_memory, align, &local_err= ); + pc_dimm_memory_plug(dev, MACHINE(ms), align, &local_err); if (local_err) { goto out; } @@ -3065,7 +3065,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, return; =20 out_unplug: - pc_dimm_memory_unplug(dev, MACHINE(ms)->device_memory); + pc_dimm_memory_unplug(dev, MACHINE(ms)); out: error_propagate(errp, local_err); } @@ -3202,7 +3202,7 @@ void spapr_lmb_release(DeviceState *dev) * Now that all the LMBs have been removed by the guest, call the * pc-dimm unplug handler to cleanup up the pc-dimm device. */ - pc_dimm_memory_unplug(dev, MACHINE(spapr)->device_memory); + pc_dimm_memory_unplug(dev, MACHINE(spapr)); object_unparent(OBJECT(dev)); spapr_pending_dimm_unplugs_remove(spapr, ds); } diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 1d26e13cef..aa5930fbb6 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -84,7 +84,7 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_sta= rt, int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); =20 uint64_t pc_existing_dimms_capacity(Error **errp); -void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, +void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, uint64_t align, Error **errp); -void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms); +void pc_dimm_memory_unplug(DeviceState *dev, MachineState *machine); #endif --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502520045977.0728159565376; Mon, 23 Apr 2018 09:55:20 -0700 (PDT) Received: from localhost ([::1]:54521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAekI-0001QI-2S for importer@patchew.org; Mon, 23 Apr 2018 12:55:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAeh7-0007e5-GI for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAeh6-0008KZ-5A for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34396 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAeh5-0008K7-Vt; Mon, 23 Apr 2018 12:52:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76277406C790; Mon, 23 Apr 2018 16:51:59 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95C597C5E; Mon, 23 Apr 2018 16:51:50 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:20 +0200 Message-Id: <20180423165126.15441-6-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 16:51:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Apr 2018 16:51:59 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 05/11] pc-dimm: factor out address search into MemoryDevice code 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This mainly moves code, but does a handfull of optimizations: - We pass the machine instead of the address space properties - We check the hinted address directly and handle fragmented memory better - We make the search independent of pc-dimm Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/mem/memory-device.c | 86 ++++++++++++++++++++++++++++++++ hw/mem/pc-dimm.c | 109 +------------------------------------= ---- include/hw/mem/memory-device.h | 3 ++ include/hw/mem/pc-dimm.h | 5 -- 4 files changed, 91 insertions(+), 112 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 6cbdaf99f3..a2cb85462f 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -48,6 +48,92 @@ static int memory_device_build_list(Object *obj, void *o= paque) return 0; } =20 +uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hin= t, + uint64_t align, uint64_t size, + Error **errp) +{ + uint64_t address_space_start, address_space_end; + GSList *list =3D NULL, *item; + uint64_t new_addr =3D 0; + + if (!ms->device_memory) { + error_setg(errp, "memory devices (e.g. for memory hotplug) are not= " + "supported by the machine"); + return 0; + } + + if (!memory_region_size(&ms->device_memory->mr)) { + error_setg(errp, "memory devices (e.g. for memory hotplug) are not= " + "enabled, please specify the maxmem option"); + return 0; + } + address_space_start =3D ms->device_memory->base; + address_space_end =3D address_space_start + + memory_region_size(&ms->device_memory->mr); + g_assert(QEMU_ALIGN_UP(address_space_start, align) =3D=3D address_spac= e_start); + g_assert(address_space_end >=3D address_space_start); + + if (hint && QEMU_ALIGN_UP(*hint, align) !=3D *hint) { + error_setg(errp, "address must be aligned to 0x%" PRIx64 " bytes", + align); + return 0; + } + + if (QEMU_ALIGN_UP(size, align) !=3D size) { + error_setg(errp, "backend memory size must be multiple of 0x%" + PRIx64, align); + return 0; + } + + if (hint) { + new_addr =3D *hint; + if (new_addr < address_space_start) { + error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 + "] at 0x%" PRIx64, new_addr, size, address_space_st= art); + return 0; + } else if ((new_addr + size) > address_space_end) { + error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 + "] beyond 0x%" PRIx64, new_addr, size, + address_space_end); + return 0; + } + } else { + new_addr =3D address_space_start; + } + + /* find address range that will fit new memory device */ + object_child_foreach(OBJECT(ms), memory_device_build_list, &list); + for (item =3D list; item; item =3D g_slist_next(item)) { + const MemoryDeviceState *md =3D item->data; + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(OBJECT(md= )); + uint64_t md_size, md_addr; + + md_addr =3D mdc->get_addr(md); + md_size =3D mdc->get_region_size(md); + if (*errp) { + goto out; + } + + if (ranges_overlap(md_addr, md_size, new_addr, size)) { + if (hint) { + const DeviceState *d =3D DEVICE(md); + error_setg(errp, "address range conflicts with '%s'", d->i= d); + goto out; + } + new_addr =3D QEMU_ALIGN_UP(md_addr + md_size, align); + } + } + + if (new_addr + size > address_space_end) { + error_setg(errp, "could not find position in guest address space f= or " + "memory device - memory fragmented due to alignments"); + goto out; + } +out: + g_slist_free(list); + return new_addr; +} + MemoryDeviceInfoList *qmp_memory_device_list(void) { GSList *devices =3D NULL, *item; diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 37b8be80a1..9b70174fd9 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -23,9 +23,7 @@ #include "hw/mem/nvdimm.h" #include "hw/mem/memory-device.h" #include "qapi/error.h" -#include "qemu/config-file.h" #include "qapi/visitor.h" -#include "qemu/range.h" #include "sysemu/numa.h" #include "sysemu/kvm.h" #include "trace.h" @@ -60,10 +58,8 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState = *machine, goto out; } =20 - addr =3D pc_dimm_get_free_addr(hpms->base, - memory_region_size(&hpms->mr), - !addr ? NULL : &addr, align, - memory_region_size(mr), &local_err); + addr =3D memory_device_get_free_addr(machine, !addr ? NULL : &addr, al= ign, + memory_region_size(mr), &local_err); if (local_err) { goto out; } @@ -211,107 +207,6 @@ out: return slot; } =20 -static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer b) -{ - PCDIMMDevice *x =3D PC_DIMM(a); - PCDIMMDevice *y =3D PC_DIMM(b); - Int128 diff =3D int128_sub(int128_make64(x->addr), int128_make64(y->ad= dr)); - - if (int128_lt(diff, int128_zero())) { - return -1; - } else if (int128_gt(diff, int128_zero())) { - return 1; - } - return 0; -} - -static int pc_dimm_built_list(Object *obj, void *opaque) -{ - GSList **list =3D opaque; - - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - DeviceState *dev =3D DEVICE(obj); - if (dev->realized) { /* only realized DIMMs matter */ - *list =3D g_slist_insert_sorted(*list, dev, pc_dimm_addr_sort); - } - } - - object_child_foreach(obj, pc_dimm_built_list, opaque); - return 0; -} - -uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, - uint64_t address_space_size, - uint64_t *hint, uint64_t align, uint64_t si= ze, - Error **errp) -{ - GSList *list =3D NULL, *item; - uint64_t new_addr, ret =3D 0; - uint64_t address_space_end =3D address_space_start + address_space_siz= e; - - g_assert(QEMU_ALIGN_UP(address_space_start, align) =3D=3D address_spac= e_start); - - if (!address_space_size) { - error_setg(errp, "memory hotplug is not enabled, " - "please add maxmem option"); - goto out; - } - - if (hint && QEMU_ALIGN_UP(*hint, align) !=3D *hint) { - error_setg(errp, "address must be aligned to 0x%" PRIx64 " bytes", - align); - goto out; - } - - if (QEMU_ALIGN_UP(size, align) !=3D size) { - error_setg(errp, "backend memory size must be multiple of 0x%" - PRIx64, align); - goto out; - } - - assert(address_space_end > address_space_start); - object_child_foreach(qdev_get_machine(), pc_dimm_built_list, &list); - - if (hint) { - new_addr =3D *hint; - } else { - new_addr =3D address_space_start; - } - - /* find address range that will fit new DIMM */ - for (item =3D list; item; item =3D g_slist_next(item)) { - PCDIMMDevice *dimm =3D item->data; - uint64_t dimm_size =3D object_property_get_uint(OBJECT(dimm), - PC_DIMM_SIZE_PROP, - errp); - if (errp && *errp) { - goto out; - } - - if (ranges_overlap(dimm->addr, dimm_size, new_addr, size)) { - if (hint) { - DeviceState *d =3D DEVICE(dimm); - error_setg(errp, "address range conflicts with '%s'", d->i= d); - goto out; - } - new_addr =3D QEMU_ALIGN_UP(dimm->addr + dimm_size, align); - } - } - ret =3D new_addr; - - if (new_addr < address_space_start) { - error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 - "] at 0x%" PRIx64, new_addr, size, address_space_start); - } else if ((new_addr + size) > address_space_end) { - error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 - "] beyond 0x%" PRIx64, new_addr, size, address_space_en= d); - } - -out: - g_slist_free(list); - return ret; -} - static Property pc_dimm_properties[] =3D { DEFINE_PROP_UINT64(PC_DIMM_ADDR_PROP, PCDIMMDevice, addr, 0), DEFINE_PROP_UINT32(PC_DIMM_NODE_PROP, PCDIMMDevice, node, 0), diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 31f64cbab2..3427c7d424 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -41,5 +41,8 @@ typedef struct MemoryDeviceClass { =20 MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); +uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hin= t, + uint64_t align, uint64_t size, + Error **errp); =20 #endif diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index aa5930fbb6..e37fb5d5db 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -76,11 +76,6 @@ typedef struct PCDIMMDeviceClass { MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm); } PCDIMMDeviceClass; =20 -uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, - uint64_t address_space_size, - uint64_t *hint, uint64_t align, uint64_t si= ze, - Error **errp); - int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); =20 uint64_t pc_existing_dimms_capacity(Error **errp); --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502785002442.0599866789954; Mon, 23 Apr 2018 09:59:45 -0700 (PDT) Received: from localhost ([::1]:54551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAeoW-0005C5-Je for importer@patchew.org; Mon, 23 Apr 2018 12:59:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAehE-0007jJ-Ft for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAeh8-0008M9-G5 for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:08 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59156 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAeh8-0008Ls-AS; Mon, 23 Apr 2018 12:52:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D090C81A88A2; Mon, 23 Apr 2018 16:52:01 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id B15987C56; Mon, 23 Apr 2018 16:51:59 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:21 +0200 Message-Id: <20180423165126.15441-7-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:01 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 06/11] pc-dimm: factor out capacity and slot checks into MemoryDevice 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the checks into memory_device_get_free_addr(). This will check before doing any calculations if we have KVM/vhost slots left and if the total region size would be exceeded. Of course, while at it, make it independent of pc-dimm code. Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/mem/memory-device.c | 51 ++++++++++++++++++++++++++++++++++++++++ hw/mem/pc-dimm.c | 60 --------------------------------------------= ---- include/hw/mem/pc-dimm.h | 1 - 3 files changed, 51 insertions(+), 61 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index a2cb85462f..8535ddcb14 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -15,6 +15,8 @@ #include "qapi/error.h" #include "hw/boards.h" #include "qemu/range.h" +#include "hw/virtio/vhost.h" +#include "sysemu/kvm.h" =20 static gint memory_device_addr_sort(gconstpointer a, gconstpointer b) { @@ -48,6 +50,50 @@ static int memory_device_build_list(Object *obj, void *o= paque) return 0; } =20 +static int memory_device_used_region_size(Object *obj, void *opaque) +{ + uint64_t *size =3D opaque; + + if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) { + const DeviceState *dev =3D DEVICE(obj); + const MemoryDeviceState *md =3D MEMORY_DEVICE(obj); + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(obj); + + if (dev->realized) { + *size +=3D mdc->get_region_size(md); + } + } + + object_child_foreach(obj, memory_device_used_region_size, opaque); + return 0; +} + +static void memory_device_check_addable(MachineState *ms, uint64_t size, + Error **errp) +{ + uint64_t used_region_size =3D 0; + + /* we will need a new memory slot for kvm and vhost */ + if (kvm_enabled() && !kvm_has_free_slot(ms)) { + error_setg(errp, "hypervisor has no free memory slots left"); + return; + } + if (!vhost_has_free_slot()) { + error_setg(errp, "a used vhost backend has no free memory slots le= ft"); + return; + } + + /* will we exceed the total amount of memory specified */ + memory_device_used_region_size(OBJECT(ms), &used_region_size); + if (used_region_size + size > ms->maxram_size - ms->ram_size) { + error_setg(errp, "not enough space, currently 0x%" PRIx64 + " in use of total hot pluggable 0x" RAM_ADDR_FMT, + used_region_size, ms->maxram_size - ms->ram_size); + return; + } + +} + uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hin= t, uint64_t align, uint64_t size, Error **errp) @@ -73,6 +119,11 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, g_assert(QEMU_ALIGN_UP(address_space_start, align) =3D=3D address_spac= e_start); g_assert(address_space_end >=3D address_space_start); =20 + memory_device_check_addable(ms, size, errp); + if (*errp) { + return 0; + } + if (hint && QEMU_ALIGN_UP(*hint, align) !=3D *hint) { error_setg(errp, "address must be aligned to 0x%" PRIx64 " bytes", align); diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 9b70174fd9..8aa2d36ce9 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -25,9 +25,7 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "sysemu/numa.h" -#include "sysemu/kvm.h" #include "trace.h" -#include "hw/virtio/vhost.h" =20 typedef struct pc_dimms_capacity { uint64_t size; @@ -43,7 +41,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *= machine, PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); Error *local_err =3D NULL; - uint64_t existing_dimms_capacity =3D 0; MemoryRegion *mr; uint64_t addr; =20 @@ -64,20 +61,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState = *machine, goto out; } =20 - existing_dimms_capacity =3D pc_existing_dimms_capacity(&local_err); - if (local_err) { - goto out; - } - - if (existing_dimms_capacity + memory_region_size(mr) > - machine->maxram_size - machine->ram_size) { - error_setg(&local_err, "not enough space, currently 0x%" PRIx64 - " in use of total hot pluggable 0x" RAM_ADDR_FMT, - existing_dimms_capacity, - machine->maxram_size - machine->ram_size); - goto out; - } - object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_= err); if (local_err) { goto out; @@ -100,17 +83,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState= *machine, } trace_mhp_pc_dimm_assigned_slot(slot); =20 - if (kvm_enabled() && !kvm_has_free_slot(machine)) { - error_setg(&local_err, "hypervisor has no free memory slots left"); - goto out; - } - - if (!vhost_has_free_slot()) { - error_setg(&local_err, "a used vhost backend has no free" - " memory slots left"); - goto out; - } - memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr); vmstate_register_ram(vmstate_mr, dev); =20 @@ -129,38 +101,6 @@ void pc_dimm_memory_unplug(DeviceState *dev, MachineSt= ate *machine) vmstate_unregister_ram(vmstate_mr, dev); } =20 -static int pc_existing_dimms_capacity_internal(Object *obj, void *opaque) -{ - pc_dimms_capacity *cap =3D opaque; - uint64_t *size =3D &cap->size; - - if (object_dynamic_cast(obj, TYPE_PC_DIMM)) { - DeviceState *dev =3D DEVICE(obj); - - if (dev->realized) { - (*size) +=3D object_property_get_uint(obj, PC_DIMM_SIZE_PROP, - cap->errp); - } - - if (cap->errp && *cap->errp) { - return 1; - } - } - object_child_foreach(obj, pc_existing_dimms_capacity_internal, opaque); - return 0; -} - -uint64_t pc_existing_dimms_capacity(Error **errp) -{ - pc_dimms_capacity cap; - - cap.size =3D 0; - cap.errp =3D errp; - - pc_existing_dimms_capacity_internal(qdev_get_machine(), &cap); - return cap.size; -} - static int pc_dimm_slot2bitmap(Object *obj, void *opaque) { unsigned long *bitmap =3D opaque; diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index e37fb5d5db..627c8601d9 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -78,7 +78,6 @@ typedef struct PCDIMMDeviceClass { =20 int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); =20 -uint64_t pc_existing_dimms_capacity(Error **errp); void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, uint64_t align, Error **errp); void pc_dimm_memory_unplug(DeviceState *dev, MachineState *machine); --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502516795963.2334985272785; Mon, 23 Apr 2018 09:55:16 -0700 (PDT) Received: from localhost ([::1]:54520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAek9-0001DU-KA for importer@patchew.org; Mon, 23 Apr 2018 12:55:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAehF-0007kE-IR for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAehD-0008PI-4q for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59166 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAehC-0008Ou-Uw; Mon, 23 Apr 2018 12:52:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 653A481A88C8; Mon, 23 Apr 2018 16:52:06 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1817F7C59; Mon, 23 Apr 2018 16:52:01 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:22 +0200 Message-Id: <20180423165126.15441-8-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:06 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 07/11] pc-dimm: move actual plug/unplug of a memory region to MemoryDevice 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Registering the memory region for migration has do be done by the owner. There could be cases, where we don't want to migrate the memory. Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/mem/memory-device.c | 18 ++++++++++++++++++ hw/mem/pc-dimm.c | 5 ++--- include/hw/mem/memory-device.h | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 8535ddcb14..3e04f3954e 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -243,6 +243,24 @@ uint64_t get_plugged_memory_size(void) return size; } =20 +void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, + uint64_t addr) +{ + /* we expect a previous call to memory_device_get_free_addr() */ + g_assert(ms->device_memory); + + memory_region_add_subregion(&ms->device_memory->mr, + addr - ms->device_memory->base, mr); +} + +void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) +{ + /* we expect a previous call to memory_device_get_free_addr() */ + g_assert(ms->device_memory); + + memory_region_del_subregion(&ms->device_memory->mr, mr); +} + static const TypeInfo memory_device_info =3D { .name =3D TYPE_MEMORY_DEVICE, .parent =3D TYPE_INTERFACE, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 8aa2d36ce9..0119c68e01 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -36,7 +36,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *= machine, uint64_t align, Error **errp) { int slot; - MemoryHotplugState *hpms =3D machine->device_memory; PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); @@ -83,7 +82,7 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *= machine, } trace_mhp_pc_dimm_assigned_slot(slot); =20 - memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr); + memory_device_plug_region(machine, mr, addr); vmstate_register_ram(vmstate_mr, dev); =20 out: @@ -97,7 +96,7 @@ void pc_dimm_memory_unplug(DeviceState *dev, MachineState= *machine) MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); =20 - memory_region_del_subregion(&machine->device_memory->mr, mr); + memory_device_unplug_region(machine, mr); vmstate_unregister_ram(vmstate_mr, dev); } =20 diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 3427c7d424..2853b084b5 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -44,5 +44,8 @@ uint64_t get_plugged_memory_size(void); uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hin= t, uint64_t align, uint64_t size, Error **errp); +void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, + uint64_t addr); +void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); =20 #endif --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502703917652.0417227962533; Mon, 23 Apr 2018 09:58:23 -0700 (PDT) Received: from localhost ([::1]:54544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAenC-00040O-3B for importer@patchew.org; Mon, 23 Apr 2018 12:58:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAehI-0007nw-KD for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAehH-0008T1-NL for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51430 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAehH-0008SX-Ho; Mon, 23 Apr 2018 12:52:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CAF4FA46C; Mon, 23 Apr 2018 16:52:11 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id A07EB7C5E; Mon, 23 Apr 2018 16:52:06 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:23 +0200 Message-Id: <20180423165126.15441-9-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 23 Apr 2018 16:52:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 23 Apr 2018 16:52:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 08/11] machine: rename MemoryHotplugState to DeviceMemoryState 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rename it to better match the new terminology. Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/ppc/spapr_hcall.c | 6 +++--- hw/ppc/spapr_rtas_ddw.c | 5 ++--- include/hw/boards.h | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index e99686389d..3b3d927c98 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -64,13 +64,13 @@ static inline bool valid_ptex(PowerPCCPU *cpu, target_u= long ptex) static bool is_ram_address(sPAPRMachineState *spapr, hwaddr addr) { MachineState *machine =3D MACHINE(spapr); - MemoryHotplugState *hpms =3D machine->device_memory; + DeviceMemoryState *dms =3D machine->device_memory; =20 if (addr < machine->ram_size) { return true; } - if ((addr >=3D hpms->base) - && ((addr - hpms->base) < memory_region_size(&hpms->mr))) { + if ((addr >=3D dms->base) + && ((addr - dms->base) < memory_region_size(&dms->mr))) { return true; } =20 diff --git a/hw/ppc/spapr_rtas_ddw.c b/hw/ppc/spapr_rtas_ddw.c index d3666c1921..329feb148f 100644 --- a/hw/ppc/spapr_rtas_ddw.c +++ b/hw/ppc/spapr_rtas_ddw.c @@ -122,9 +122,8 @@ static void rtas_ibm_query_pe_dma_window(PowerPCCPU *cp= u, if (machine->ram_size =3D=3D machine->maxram_size) { max_window_size =3D machine->ram_size; } else { - MemoryHotplugState *hpms =3D machine->device_memory; - - max_window_size =3D hpms->base + memory_region_size(&hpms->mr); + max_window_size =3D machine->device_memory->base + + memory_region_size(&machine->device_memory->mr); } =20 avail =3D SPAPR_PCI_DMA_MAX_WINDOWS - spapr_phb_get_active_win_num(sph= b); diff --git a/include/hw/boards.h b/include/hw/boards.h index ffc1ee782f..8748964e6f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -215,15 +215,15 @@ struct MachineClass { }; =20 /** - * MemoryHotplugState: + * DeviceMemoryState: * @base: address in guest physical address space where the memory * address space for memory devices starts * @mr: address space container for memory devices */ -typedef struct MemoryHotplugState { +typedef struct DeviceMemoryState { hwaddr base; MemoryRegion mr; -} MemoryHotplugState; +} DeviceMemoryState; =20 /** * MachineState: @@ -255,7 +255,7 @@ struct MachineState { bool enforce_config_section; bool enable_graphics; char *memory_encryption; - MemoryHotplugState *device_memory; + DeviceMemoryState *device_memory; =20 ram_addr_t ram_size; ram_addr_t maxram_size; --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524503002872756.1055340573793; Mon, 23 Apr 2018 10:03:22 -0700 (PDT) Received: from localhost ([::1]:54595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAes6-0007v8-3b for importer@patchew.org; Mon, 23 Apr 2018 13:03:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAehS-0007vU-6R for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAehR-00009z-1F for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:48156 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAehQ-00009J-S0; Mon, 23 Apr 2018 12:52:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 55C24406E974; Mon, 23 Apr 2018 16:52:20 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 486CE7C53; Mon, 23 Apr 2018 16:52:11 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:24 +0200 Message-Id: <20180423165126.15441-10-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 16:52:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 16:52:20 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 09/11] pc: rename "hotplug memory" terminology to "device memory" 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's make it clear that we are dealing with device memory. That it can be used for memory hotplug is just a special case. Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- hw/i386/acpi-build.c | 2 +- hw/i386/pc.c | 25 ++++++++++++------------- include/hw/i386/pc.h | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 70b37e6df4..123430fbff 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2313,7 +2313,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, Ma= chineState *machine) const CPUArchIdList *apic_ids =3D mc->possible_cpu_arch_ids(machine); PCMachineState *pcms =3D PC_MACHINE(machine); ram_addr_t hotplugabble_address_space_size =3D - object_property_get_int(OBJECT(pcms), PC_MACHINE_MEMHP_REGION_SIZE, + object_property_get_int(OBJECT(pcms), PC_MACHINE_DEVMEM_REGION_SIZ= E, NULL); =20 srat_start =3D table_data->len; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 4b2ede9029..afbdf48fbb 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1374,11 +1374,10 @@ void pc_memory_init(PCMachineState *pcms, /* always allocate the device memory information */ machine->device_memory =3D g_malloc(sizeof(*machine->device_memory)); =20 - /* initialize hotplug memory address space */ + /* initialize device memory address space */ if (pcmc->has_reserved_memory && (machine->ram_size < machine->maxram_size)) { - ram_addr_t hotplug_mem_size =3D - machine->maxram_size - machine->ram_size; + ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; =20 if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { error_report("unsupported amount of memory slots: %"PRIu64, @@ -1397,19 +1396,19 @@ void pc_memory_init(PCMachineState *pcms, ROUND_UP(0x100000000ULL + pcms->above_4g_mem_size, 1ULL << 30); =20 if (pcmc->enforce_aligned_dimm) { - /* size hotplug region assuming 1G page max alignment per slot= */ - hotplug_mem_size +=3D (1ULL << 30) * machine->ram_slots; + /* size device region assuming 1G page max alignment per slot = */ + device_mem_size +=3D (1ULL << 30) * machine->ram_slots; } =20 - if ((machine->device_memory->base + hotplug_mem_size) < - hotplug_mem_size) { + if ((machine->device_memory->base + device_mem_size) < + device_mem_size) { error_report("unsupported amount of maximum memory: " RAM_ADDR= _FMT, machine->maxram_size); exit(EXIT_FAILURE); } =20 memory_region_init(&machine->device_memory->mr, OBJECT(pcms), - "hotplug-memory", hotplug_mem_size); + "device-memory", device_mem_size); memory_region_add_subregion(system_memory, machine->device_memory-= >base, &machine->device_memory->mr); } @@ -2064,9 +2063,9 @@ static HotplugHandler *pc_get_hotpug_handler(MachineS= tate *machine, } =20 static void -pc_machine_get_hotplug_memory_region_size(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) +pc_machine_get_device_memory_region_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { MachineState *ms =3D MACHINE(obj); int64_t value =3D memory_region_size(&ms->device_memory->mr); @@ -2373,8 +2372,8 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) nc->nmi_monitor_handler =3D x86_nmi; mc->default_cpu_type =3D TARGET_DEFAULT_CPU_TYPE; =20 - object_class_property_add(oc, PC_MACHINE_MEMHP_REGION_SIZE, "int", - pc_machine_get_hotplug_memory_region_size, NULL, + object_class_property_add(oc, PC_MACHINE_DEVMEM_REGION_SIZE, "int", + pc_machine_get_device_memory_region_size, NULL, NULL, NULL, &error_abort); =20 object_class_property_add(oc, PC_MACHINE_MAX_RAM_BELOW_4G, "size", diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 07b596ee76..2e834e6ded 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -71,7 +71,7 @@ struct PCMachineState { }; =20 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" -#define PC_MACHINE_MEMHP_REGION_SIZE "hotplug-memory-region-size" +#define PC_MACHINE_DEVMEM_REGION_SIZE "device-memory-region-size" #define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g" #define PC_MACHINE_VMPORT "vmport" #define PC_MACHINE_SMM "smm" --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524502857815691.0130020018453; Mon, 23 Apr 2018 10:00:57 -0700 (PDT) Received: from localhost ([::1]:54566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAepb-0006EQ-I5 for importer@patchew.org; Mon, 23 Apr 2018 13:00:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAehU-0007vr-DL for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAehT-0000Bh-CL for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59182 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAehT-0000BU-72; Mon, 23 Apr 2018 12:52:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B224B81A88C8; Mon, 23 Apr 2018 16:52:22 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 920877C53; Mon, 23 Apr 2018 16:52:20 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:25 +0200 Message-Id: <20180423165126.15441-11-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 16:52:22 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 10/11] spapr: rename "hotplug memory" terminology to "device memory" 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's make it clear at relevant places that we are dealing with device memory. That it can be used for memory hotplug is just a special case. Signed-off-by: David Hildenbrand Acked-by: David Gibson Reviewed-by: Michael S. Tsirkin --- hw/ppc/spapr.c | 28 ++++++++++++++-------------- include/hw/ppc/spapr.h | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 8ecb716f72..a32b88e41d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -681,7 +681,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineSta= te *spapr, void *fdt) int ret, i, offset; uint64_t lmb_size =3D SPAPR_MEMORY_BLOCK_SIZE; uint32_t prop_lmb_size[] =3D {0, cpu_to_be32(lmb_size)}; - uint32_t hotplug_lmb_start =3D machine->device_memory->base / lmb_size; + uint32_t device_lmb_start =3D machine->device_memory->base / lmb_size; uint32_t nr_lmbs =3D (machine->device_memory->base + memory_region_size(&machine->device_memory->mr)) / lmb_size; @@ -690,7 +690,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineSta= te *spapr, void *fdt) MemoryDeviceInfoList *dimms =3D NULL; =20 /* - * Don't create the node if there is no hotpluggable memory + * Don't create the node if there is no device memory */ if (machine->ram_size =3D=3D machine->maxram_size) { return 0; @@ -722,7 +722,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineSta= te *spapr, void *fdt) goto out; } =20 - if (hotplug_lmb_start) { + if (device_lmb_start) { dimms =3D qmp_memory_device_list(); } =20 @@ -733,7 +733,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineSta= te *spapr, void *fdt) uint64_t addr =3D i * lmb_size; uint32_t *dynamic_memory =3D cur_index; =20 - if (i >=3D hotplug_lmb_start) { + if (i >=3D device_lmb_start) { sPAPRDRConnector *drc; =20 drc =3D spapr_drc_by_id(TYPE_SPAPR_DRC_LMB, i); @@ -752,7 +752,7 @@ static int spapr_populate_drconf_memory(sPAPRMachineSta= te *spapr, void *fdt) } else { /* * LMB information for RMA, boot time RAM and gap b/n RAM and - * hotplug memory region -- all these are marked as reserved + * device memory region -- all these are marked as reserved * and as having no valid DRC. */ dynamic_memory[0] =3D cpu_to_be32(addr >> 32); @@ -903,11 +903,11 @@ static void spapr_dt_rtas(sPAPRMachineState *spapr, v= oid *fdt) GString *hypertas =3D g_string_sized_new(256); GString *qemu_hypertas =3D g_string_sized_new(256); uint32_t refpoints[] =3D { cpu_to_be32(0x4), cpu_to_be32(0x4) }; - uint64_t max_hotplug_addr =3D MACHINE(spapr)->device_memory->base + + uint64_t max_device_addr =3D MACHINE(spapr)->device_memory->base + memory_region_size(&MACHINE(spapr)->device_memory->mr); uint32_t lrdr_capacity[] =3D { - cpu_to_be32(max_hotplug_addr >> 32), - cpu_to_be32(max_hotplug_addr & 0xffffffff), + cpu_to_be32(max_device_addr >> 32), + cpu_to_be32(max_device_addr & 0xffffffff), 0, cpu_to_be32(SPAPR_MEMORY_BLOCK_SIZE), cpu_to_be32(max_cpus / smp_threads), }; @@ -2531,7 +2531,7 @@ static void spapr_machine_init(MachineState *machine) =20 /* initialize device memory address space */ if (machine->ram_size < machine->maxram_size) { - ram_addr_t hotplug_mem_size =3D machine->maxram_size - machine->ra= m_size; + ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; /* * Limit the number of hotpluggable memory slots to half the number * slots that KVM supports, leaving the other half for PCI and oth= er @@ -2551,9 +2551,9 @@ static void spapr_machine_init(MachineState *machine) } =20 machine->device_memory->base =3D ROUND_UP(machine->ram_size, - SPAPR_HOTPLUG_MEM_ALIGN); + SPAPR_DEVICE_MEM_ALIGN); memory_region_init(&machine->device_memory->mr, OBJECT(spapr), - "hotplug-memory", hotplug_mem_size); + "device-memory", device_mem_size); memory_region_add_subregion(sysmem, machine->device_memory->base, &machine->device_memory->mr); } @@ -4154,11 +4154,11 @@ static void phb_placement_2_7(sPAPRMachineState *sp= apr, uint32_t index, hwaddr phb0_base, phb_base; int i; =20 - /* Do we have hotpluggable memory? */ + /* Do we have device memory? */ if (MACHINE(spapr)->maxram_size > ram_top) { /* Can't just use maxram_size, because there may be an - * alignment gap between normal and hotpluggable memory - * regions */ + * alignment gap between normal and device memory regions + */ ram_top =3D MACHINE(spapr)->device_memory->base + memory_region_size(&MACHINE(spapr)->device_memory->mr); } diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 56ff02d32a..3388750fc7 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -747,8 +747,8 @@ int spapr_rng_populate_dt(void *fdt); */ #define SPAPR_MAX_RAM_SLOTS 32 =20 -/* 1GB alignment for hotplug memory region */ -#define SPAPR_HOTPLUG_MEM_ALIGN (1ULL << 30) +/* 1GB alignment for device memory region */ +#define SPAPR_DEVICE_MEM_ALIGN (1ULL << 30) =20 /* * Number of 32 bit words in each LMB list entry in ibm,dynamic-memory --=20 2.14.3 From nobody Fri May 10 16:11:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15245029475101010.3082672308982; Mon, 23 Apr 2018 10:02:27 -0700 (PDT) Received: from localhost ([::1]:54593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAerC-0007PY-Ov for importer@patchew.org; Mon, 23 Apr 2018 13:02:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAehW-0007y4-NL for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAehV-0000Dd-NT for qemu-devel@nongnu.org; Mon, 23 Apr 2018 12:52:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38274 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAehV-0000DE-Ir; Mon, 23 Apr 2018 12:52:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 154498DC3E; Mon, 23 Apr 2018 16:52:25 +0000 (UTC) Received: from t460s.redhat.com (unknown [10.36.118.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA4B215562; Mon, 23 Apr 2018 16:52:22 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 23 Apr 2018 18:51:26 +0200 Message-Id: <20180423165126.15441-12-david@redhat.com> In-Reply-To: <20180423165126.15441-1-david@redhat.com> References: <20180423165126.15441-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 23 Apr 2018 16:52:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 23 Apr 2018 16:52:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 11/11] vl: allow 'maxmem' without 'slot' 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , Alexander Graf , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We will be able to have memory devices (e.g. virtio) not requiring the slot parameter (e.g. not exposed via ACPI). We still need the maxmem parameter to setup a proper memory region for device memory. And some architectures (e.g. s390x) will have to set up the maximum possible guest address space size based on the maxmem parameter. As far as I can see, all code (pc.c,spapr.c,ACPI code) should handle !slots just fine, even though maxmem is set. Signed-off-by: David Hildenbrand Reviewed-by: Michael S. Tsirkin --- vl.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/vl.c b/vl.c index fce1fd12d8..acb815bc14 100644 --- a/vl.c +++ b/vl.c @@ -2887,7 +2887,6 @@ static void set_memory_options(uint64_t *ram_slots, r= am_addr_t *maxram_size, { uint64_t sz; const char *mem_str; - const char *maxmem_str, *slots_str; const ram_addr_t default_ram_size =3D mc->default_ram_size; QemuOpts *opts =3D qemu_find_opts_singleton("memory"); Location loc; @@ -2933,9 +2932,7 @@ static void set_memory_options(uint64_t *ram_slots, r= am_addr_t *maxram_size, qemu_opt_set_number(opts, "size", ram_size, &error_abort); *maxram_size =3D ram_size; =20 - maxmem_str =3D qemu_opt_get(opts, "maxmem"); - slots_str =3D qemu_opt_get(opts, "slots"); - if (maxmem_str && slots_str) { + if (qemu_opt_get(opts, "maxmem")) { uint64_t slots; =20 sz =3D qemu_opt_get_size(opts, "maxmem", 0); @@ -2946,13 +2943,7 @@ static void set_memory_options(uint64_t *ram_slots, = ram_addr_t *maxram_size, "the initial memory size (0x" RAM_ADDR_FMT ")", sz, ram_size); exit(EXIT_FAILURE); - } else if (sz > ram_size) { - if (!slots) { - error_report("invalid value of -m option: maxmem was " - "specified, but no hotplug slots were specifi= ed"); - exit(EXIT_FAILURE); - } - } else if (slots) { + } else if (slots && sz =3D=3D ram_size) { error_report("invalid value of -m option maxmem: " "memory slots were specified but maximum memory s= ize " "(0x%" PRIx64 ") is equal to the initial memory s= ize " @@ -2962,10 +2953,8 @@ static void set_memory_options(uint64_t *ram_slots, = ram_addr_t *maxram_size, =20 *maxram_size =3D sz; *ram_slots =3D slots; - } else if ((!maxmem_str && slots_str) || - (maxmem_str && !slots_str)) { - error_report("invalid -m option value: missing " - "'%s' option", slots_str ? "maxmem" : "slots"); + } else if (qemu_opt_get(opts, "slots")) { + error_report("invalid -m option value: missing 'maxmem' option"); exit(EXIT_FAILURE); } =20 --=20 2.14.3