From nobody Wed Oct 29 17:11:29 2025 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 1525362690630709.4181118863431; Thu, 3 May 2018 08:51:30 -0700 (PDT) Received: from localhost ([::1]:57357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGVu-0001d1-EP for importer@patchew.org; Thu, 03 May 2018 11:51:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUS-0000gz-7w for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUP-0003fc-4b for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51536 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 1fEGUO-0003fP-W2; Thu, 03 May 2018 11:49:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8B3D29108; Thu, 3 May 2018 15:49:47 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 842E4215CDAF; Thu, 3 May 2018 15:49:45 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:29 +0200 Message-Id: <20180503154936.18946-2-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 03 May 2018 15:49:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 03 May 2018 15:49:47 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 1/8] memory-device: always compile support for memory devices for SOFTMMU 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 always compile support memory devices. MEM_HOTPLUG is very DIMM specific. Signed-off-by: David Hildenbrand --- hw/Makefile.objs | 2 +- hw/mem/Makefile.objs | 2 +- stubs/Makefile.objs | 1 - stubs/qmp_memory_device.c | 13 ------------- 4 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 stubs/qmp_memory_device.c diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 6a0ffe0afd..3d7d086930 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -33,7 +33,7 @@ devices-dirs-$(CONFIG_SOFTMMU) +=3D vfio/ devices-dirs-$(CONFIG_SOFTMMU) +=3D virtio/ devices-dirs-$(CONFIG_SOFTMMU) +=3D watchdog/ devices-dirs-$(CONFIG_SOFTMMU) +=3D xen/ -devices-dirs-$(CONFIG_MEM_HOTPLUG) +=3D mem/ +devices-dirs-$(CONFIG_SOFTMMU) +=3D mem/ devices-dirs-$(CONFIG_SOFTMMU) +=3D smbios/ devices-dirs-y +=3D core/ common-obj-y +=3D $(devices-dirs-y) diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs index 10be4df2a2..c5648fb2c5 100644 --- a/hw/mem/Makefile.objs +++ b/hw/mem/Makefile.objs @@ -1,3 +1,3 @@ common-obj-$(CONFIG_MEM_HOTPLUG) +=3D pc-dimm.o -common-obj-$(CONFIG_MEM_HOTPLUG) +=3D memory-device.o +common-obj-y +=3D memory-device.o common-obj-$(CONFIG_NVDIMM) +=3D nvdimm.o diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 53d3f32cb2..76ab2a9dbb 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -34,7 +34,6 @@ 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_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_memory_device.c b/stubs/qmp_memory_device.c deleted file mode 100644 index 85ff8f2d7e..0000000000 --- a/stubs/qmp_memory_device.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "qom/object.h" -#include "hw/mem/memory-device.h" - -MemoryDeviceInfoList *qmp_memory_device_list(void) -{ - return NULL; -} - -uint64_t get_plugged_memory_size(void) -{ - return (uint64_t)-1; -} --=20 2.14.3 From nobody Wed Oct 29 17:11:29 2025 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 1525362690780685.5234311384442; Thu, 3 May 2018 08:51:30 -0700 (PDT) Received: from localhost ([::1]:57358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGVv-0001dv-Rs for importer@patchew.org; Thu, 03 May 2018 11:51:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUS-0000h1-CB for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUQ-0003gP-O8 for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60478 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 1fEGUQ-0003gD-I2; Thu, 03 May 2018 11:49:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0EED94270963; Thu, 3 May 2018 15:49:50 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0B4F215CDAA; Thu, 3 May 2018 15:49:47 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:30 +0200 Message-Id: <20180503154936.18946-3-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 03 May 2018 15:49:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 03 May 2018 15:49:50 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 2/8] qdev: introduce ResourceHandler as a first-stage hotplug handler 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" Hotplug handlers usually do 3 things: 1. Allocate some resources for a new device 2. Make the new device visible for the guest 3. Notify the guest about the new device While 2. and 3. are only ever performed once for a device, there might be various resources to allocate. E.g. a MemoryDevice could be exposed via Virtio. The proxy device hotplug handler (e.g. virtio-pci, virtio-ccw) takes care of exposing the device to the guest. However, we also have to allocate system resources, like a portion in guest physical address space, which is to be handled by the machine. One key difference between a hotplug handler and a resource handler is that resource handlers have no "unplug_request". There is no communication with the guest (this is done by a "hotplug" handler). So conceptually, they are different. For now we live with the assumption, that - in additon to the existing hotplug handler which can do some resource asignment - at most one resource handler is necessary. We might even later decide to have multiple resource handlers for a specific device (e.g. one for each interface they implement). For now, this design is sufficient. Resource handlers have to run before the hotplug handler runs (esp before exposing the device to the guest). Signed-off-by: David Hildenbrand --- hw/core/Makefile.objs | 1 + hw/core/qdev.c | 41 ++++++++++++++++++++++++++++++- hw/core/resource-handler.c | 57 +++++++++++++++++++++++++++++++++++++++= ++++ include/hw/boards.h | 9 +++++++ include/hw/resource-handler.h | 46 ++++++++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 hw/core/resource-handler.c create mode 100644 include/hw/resource-handler.h diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index eb88ca979e..7474387fcd 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -6,6 +6,7 @@ common-obj-$(CONFIG_SOFTMMU) +=3D fw-path-provider.o # irq.o needed for qdev GPIO handling: common-obj-y +=3D irq.o common-obj-y +=3D hotplug.o +common-obj-y +=3D resource-handler.o common-obj-$(CONFIG_SOFTMMU) +=3D nmi.o =20 common-obj-$(CONFIG_EMPTY_SLOT) +=3D empty_slot.o diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f6f92473b8..042e275884 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -35,6 +35,7 @@ #include "qemu/error-report.h" #include "qemu/option.h" #include "hw/hotplug.h" +#include "hw/resource-handler.h" #include "hw/boards.h" #include "hw/sysbus.h" =20 @@ -271,6 +272,17 @@ HotplugHandler *qdev_get_hotplug_handler(DeviceState *= dev) return hotplug_ctrl; } =20 +static ResourceHandler *qdev_get_resource_handler(DeviceState *dev) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + + if (mc->get_resource_handler) { + return mc->get_resource_handler(ms, dev); + } + return NULL; +} + static int qdev_reset_one(DeviceState *dev, void *opaque) { device_reset(dev); @@ -814,6 +826,7 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) { DeviceState *dev =3D DEVICE(obj); DeviceClass *dc =3D DEVICE_GET_CLASS(dev); + ResourceHandler *resource_ctrl; HotplugHandler *hotplug_ctrl; BusState *bus; Error *local_err =3D NULL; @@ -825,6 +838,8 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) return; } =20 + resource_ctrl =3D qdev_get_resource_handler(dev); + if (value && !dev->realized) { if (!check_only_migratable(obj, &local_err)) { goto fail; @@ -840,6 +855,13 @@ static void device_set_realized(Object *obj, bool valu= e, Error **errp) g_free(name); } =20 + if (resource_ctrl) { + resource_handler_pre_assign(resource_ctrl, dev, &local_err); + if (local_err !=3D NULL) { + goto fail; + } + } + hotplug_ctrl =3D qdev_get_hotplug_handler(dev); if (hotplug_ctrl) { hotplug_handler_pre_plug(hotplug_ctrl, dev, &local_err); @@ -858,12 +880,19 @@ static void device_set_realized(Object *obj, bool val= ue, Error **errp) =20 DEVICE_LISTENER_CALL(realize, Forward, dev); =20 + if (resource_ctrl) { + resource_handler_assign(resource_ctrl, dev, &local_err); + if (local_err !=3D NULL) { + goto post_realize_fail; + } + } + if (hotplug_ctrl) { hotplug_handler_plug(hotplug_ctrl, dev, &local_err); } =20 if (local_err !=3D NULL) { - goto post_realize_fail; + goto post_assign_fail; } =20 /* @@ -903,6 +932,11 @@ static void device_set_realized(Object *obj, bool valu= e, Error **errp) if (qdev_get_vmsd(dev)) { vmstate_unregister(dev, qdev_get_vmsd(dev), dev); } + + if (resource_ctrl) { + resource_handler_unassign(resource_ctrl, dev); + } + if (dc->unrealize) { local_errp =3D local_err ? NULL : &local_err; dc->unrealize(dev, local_errp); @@ -928,6 +962,11 @@ child_realize_fail: vmstate_unregister(dev, qdev_get_vmsd(dev), dev); } =20 +post_assign_fail: + if (resource_ctrl) { + resource_handler_unassign(resource_ctrl, dev); + } + post_realize_fail: g_free(dev->canonical_path); dev->canonical_path =3D NULL; diff --git a/hw/core/resource-handler.c b/hw/core/resource-handler.c new file mode 100644 index 0000000000..0a1ff0e66a --- /dev/null +++ b/hw/core/resource-handler.c @@ -0,0 +1,57 @@ +/* + * Resource handler 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. + */ + +#include "qemu/osdep.h" +#include "hw/resource-handler.h" +#include "qemu/module.h" + +void resource_handler_pre_assign(ResourceHandler *rh, + const DeviceState *dev, Error **errp) +{ + ResourceHandlerClass *rhc =3D RESOURCE_HANDLER_GET_CLASS(rh); + + if (rhc->pre_assign) { + rhc->pre_assign(rh, dev, errp); + } +} + +void resource_handler_assign(ResourceHandler *rh, DeviceState *dev, + Error **errp) +{ + ResourceHandlerClass *rhc =3D RESOURCE_HANDLER_GET_CLASS(rh); + + if (rhc->assign) { + rhc->assign(rh, dev, errp); + } +} + +void resource_handler_unassign(ResourceHandler *rh, DeviceState *dev) +{ + ResourceHandlerClass *rhc =3D RESOURCE_HANDLER_GET_CLASS(rh); + + if (rhc->unassign) { + rhc->unassign(rh, dev); + } +} + +static const TypeInfo resource_handler_info =3D { + .name =3D TYPE_RESOURCE_HANDLER, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(ResourceHandlerClass), +}; + +static void resource_handler_register_types(void) +{ + type_register_static(&resource_handler_info); +} + +type_init(resource_handler_register_types) diff --git a/include/hw/boards.h b/include/hw/boards.h index 8748964e6f..ff5142d7c2 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -8,6 +8,7 @@ #include "hw/qdev.h" #include "qom/object.h" #include "qom/cpu.h" +#include "hw/resource-handler.h" =20 /** * memory_region_allocate_system_memory - Allocate a board's main memory @@ -115,6 +116,12 @@ typedef struct { * of HotplugHandler object, which handles hotplug operation * for a given @dev. It may return NULL if @dev doesn't require * any actions to be performed by hotplug handler. + * @get_resource_handler: this function is called when a new device is + * about to be hotplugged. If defined, it returns p= ointer + * to an instance of ResourceHandler object, which + * handles resource asignment for a given @dev. It + * may return NULL if @dev doesn't require any acti= ons + * to be performed by a resource handler. * @cpu_index_to_instance_props: * used to provide @cpu_index to socket/core/thread number mapping, all= owing * legacy code to perform maping from cpu_index to topology properties @@ -208,6 +215,8 @@ struct MachineClass { =20 HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); + ResourceHandler *(*get_resource_handler)(MachineState *machine, + const DeviceState *dev); CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *mac= hine, unsigned cpu_inde= x); const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); diff --git a/include/hw/resource-handler.h b/include/hw/resource-handler.h new file mode 100644 index 0000000000..3eda1bec5c --- /dev/null +++ b/include/hw/resource-handler.h @@ -0,0 +1,46 @@ +/* + * Resource handler 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 RESOURCE_HANDLER_H +#define RESOURCE_HANDLER_H + +#include "qom/object.h" + +#define TYPE_RESOURCE_HANDLER "resource-handler" + +#define RESOURCE_HANDLER_CLASS(klass) \ + OBJECT_CLASS_CHECK(ResourceHandlerClass, (klass), TYPE_RESOURCE_HANDLE= R) +#define RESOURCE_HANDLER_GET_CLASS(obj) \ + OBJECT_GET_CLASS(ResourceHandlerClass, (obj), TYPE_RESOURCE_HANDLER) +#define RESOURCE_HANDLER(obj) \ + INTERFACE_CHECK(ResourceHandler, (obj), TYPE_RESOURCE_HANDLER) + +typedef struct ResourceHandler { + Object Parent; +} ResourceHandler; + +typedef struct ResourceHandlerClass { + InterfaceClass parent; + + void (*pre_assign)(ResourceHandler *rh, const DeviceState *dev, + Error **errp); + void (*assign)(ResourceHandler *rh, DeviceState *dev, Error **errp); + void (*unassign)(ResourceHandler *rh, DeviceState *dev); +} ResourceHandlerClass; + +void resource_handler_pre_assign(ResourceHandler *rh, const DeviceState *d= ev, + Error **errp); +void resource_handler_assign(ResourceHandler *rh, DeviceState *dev, + Error **errp); +void resource_handler_unassign(ResourceHandler *rh, DeviceState *dev); + +#endif /* RESOURCE_HANDLER_H */ --=20 2.14.3 From nobody Wed Oct 29 17:11:29 2025 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 1525362794073319.45818257710766; Thu, 3 May 2018 08:53:14 -0700 (PDT) Received: from localhost ([::1]:57366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGXh-00037L-C4 for importer@patchew.org; Thu, 03 May 2018 11:53:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUT-0000hC-UJ for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUT-0003hT-3Y for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43270 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 1fEGUS-0003hG-Uv; Thu, 03 May 2018 11:49:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A89EF1207; Thu, 3 May 2018 15:49:52 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A6FC215CDAA; Thu, 3 May 2018 15:49:50 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:31 +0200 Message-Id: <20180503154936.18946-4-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 03 May 2018 15:49:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 03 May 2018 15:49:52 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 3/8] machine: provide default resource handler 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" Most resources that can't be handled via the hotplug handler will have to assign "system wide" resource. This is e.g. the case for memory devices. This will allow for a quite clean implementation for such handling. The new functions will soon be filled with life. Signed-off-by: David Hildenbrand --- hw/core/machine.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 2040177664..a41068410c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -517,8 +517,31 @@ void machine_set_cpu_numa_node(MachineState *machine, } } =20 +static ResourceHandler *machine_get_resource_handler(MachineState *machine, + const DeviceState *de= v) +{ + return NULL; +} + +static void machine_resource_handler_pre_assign(ResourceHandler *rh, + const DeviceState *dev, + Error **errp) +{ +} + +static void machine_resource_handler_assign(ResourceHandler *rh, + DeviceState *dev, Error **errp) +{ +} + +static void machine_resource_handler_unassign(ResourceHandler *rh, + DeviceState *dev) +{ +} + static void machine_class_init(ObjectClass *oc, void *data) { + ResourceHandlerClass *rhc =3D RESOURCE_HANDLER_CLASS(oc); MachineClass *mc =3D MACHINE_CLASS(oc); =20 /* Default 128 MB as guest ram size */ @@ -531,6 +554,12 @@ static void machine_class_init(ObjectClass *oc, void *= data) mc->numa_mem_align_shift =3D 23; mc->numa_auto_assign_ram =3D numa_default_auto_assign_ram; =20 + /* default resource handler */ + mc->get_resource_handler =3D machine_get_resource_handler; + rhc->pre_assign =3D machine_resource_handler_pre_assign; + rhc->assign =3D machine_resource_handler_assign; + rhc->unassign =3D machine_resource_handler_unassign; + object_class_property_add_str(oc, "accel", machine_get_accel, machine_set_accel, &error_abort); object_class_property_set_description(oc, "accel", @@ -868,6 +897,10 @@ static const TypeInfo machine_info =3D { .instance_size =3D sizeof(MachineState), .instance_init =3D machine_initfn, .instance_finalize =3D machine_finalize, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_RESOURCE_HANDLER }, + { } + }, }; =20 static void machine_register_types(void) --=20 2.14.3 From nobody Wed Oct 29 17:11:29 2025 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 1525362945146186.66424669306605; Thu, 3 May 2018 08:55:45 -0700 (PDT) Received: from localhost ([::1]:57384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGa8-0005IR-Gm for importer@patchew.org; Thu, 03 May 2018 11:55:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUW-0000j4-By for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUV-0003jH-Ex for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44932 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 1fEGUV-0003iy-B7; Thu, 03 May 2018 11:49:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9717819028E; Thu, 3 May 2018 15:49:54 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6851215CDAA; Thu, 3 May 2018 15:49:52 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:32 +0200 Message-Id: <20180503154936.18946-5-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 03 May 2018 15:49:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 03 May 2018 15:49:54 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 4/8] memory-device: new functions to handle resource assignment 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 need a handful of new functions: - set_addr(): To set the calculated address - get_memory_region(): To add it to the memory region container - get_addr(): If the device has any specific alignment requirements Using these and the existing functions, we can properly assign resources to memory devices. Signed-off-by: David Hildenbrand --- include/hw/mem/memory-device.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 2853b084b5..e43ce1c8d3 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -32,11 +32,17 @@ typedef struct MemoryDeviceState { typedef struct MemoryDeviceClass { InterfaceClass parent_class; =20 + /* required functions that have to be implemented */ uint64_t (*get_addr)(const MemoryDeviceState *md); + uint64_t (*set_addr)(MemoryDeviceState *md); + MemoryRegion * (*get_memory_region)(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); + + /* optional functions that can be implemented */ + uint64_t (*get_align)(const MemoryDeviceState *md); } MemoryDeviceClass; =20 MemoryDeviceInfoList *qmp_memory_device_list(void); --=20 2.14.3 From nobody Wed Oct 29 17:11:29 2025 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525362931214635.3508715850378; Thu, 3 May 2018 08:55:31 -0700 (PDT) Received: from localhost ([::1]:57378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGZl-0004yu-R9 for importer@patchew.org; Thu, 03 May 2018 11:55:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUY-0000m8-PW for qemu-devel@nongnu.org; Thu, 03 May 2018 11:50:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUX-0003kl-SQ for qemu-devel@nongnu.org; Thu, 03 May 2018 11:49:58 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51548 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 1fEGUX-0003kS-My; Thu, 03 May 2018 11:49:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31F27722C3; Thu, 3 May 2018 15:49:57 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11622215CDAA; Thu, 3 May 2018 15:49:54 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:33 +0200 Message-Id: <20180503154936.18946-6-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 03 May 2018 15:49:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 03 May 2018 15:49:57 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 5/8] pc-dimm: implement new memory device functions 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" Implement the new functions, we don't have to care about alignment for these DIMMs right now, so leave that function unimplemented. Signed-off-by: David Hildenbrand --- hw/mem/pc-dimm.c | 22 ++++++++++++++++++++++ include/hw/mem/memory-device.h | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 12da89d562..7ab9e77747 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -244,6 +244,26 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDevice= State *md) return dimm->addr; } =20 +static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr) +{ + PCDIMMDevice *dimm =3D PC_DIMM(md); + + dimm->addr =3D addr; +} + +static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md) +{ + 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); + g_assert(mr); + + return mr; +} + 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 */ @@ -304,6 +324,8 @@ static void pc_dimm_class_init(ObjectClass *oc, void *d= ata) ddc->get_vmstate_memory_region =3D pc_dimm_get_vmstate_memory_region; =20 mdc->get_addr =3D pc_dimm_md_get_addr; + mdc->set_addr =3D pc_dimm_md_set_addr; + mdc->get_memory_region =3D pc_dimm_md_get_memory_region; /* 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; diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index e43ce1c8d3..e10f2e854a 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -34,8 +34,8 @@ typedef struct MemoryDeviceClass { =20 /* required functions that have to be implemented */ uint64_t (*get_addr)(const MemoryDeviceState *md); - uint64_t (*set_addr)(MemoryDeviceState *md); - MemoryRegion * (*get_memory_region)(MemoryDeviceState *md); + void (*set_addr)(MemoryDeviceState *md, uint64_t addr); + MemoryRegion *(*get_memory_region)(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, --=20 2.14.3 From nobody Wed Oct 29 17:11:29 2025 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 1525363071363105.4206315155011; Thu, 3 May 2018 08:57:51 -0700 (PDT) Received: from localhost ([::1]:57404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGcA-0006ib-K6 for importer@patchew.org; Thu, 03 May 2018 11:57:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUb-0000p5-DA for qemu-devel@nongnu.org; Thu, 03 May 2018 11:50:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUa-0003lr-6M for qemu-devel@nongnu.org; Thu, 03 May 2018 11:50:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51556 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 1fEGUa-0003li-1G; Thu, 03 May 2018 11:50:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FFF66166C; Thu, 3 May 2018 15:49:59 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D687215CDAE; Thu, 3 May 2018 15:49:57 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:34 +0200 Message-Id: <20180503154936.18946-7-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 03 May 2018 15:49:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 03 May 2018 15:49:59 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 6/8] machine: introduce enforce_memory_device_align() and add it for pc 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" For compat handling, we'll have to ask the machine class if a certain memory device has alignment requirements when assigning resource to a memory device. This will only be required for PC for now, PPC is fine (and will be handled via the alignment of the memory region). Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 15 +++++++++++++++ include/hw/boards.h | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index ffcd7b85d9..9405e28cfa 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2332,6 +2332,20 @@ static void x86_nmi(NMIState *n, int cpu_index, Erro= r **errp) } } =20 +static void pc_machine_enforce_memory_device_align(const MachineClass *mc, + const MemoryDeviceState= *md, + uint64_t *align) +{ + const PCMachineClass *pcmc =3D PC_MACHINE_CLASS(mc); + + if (object_dynamic_cast(OBJECT(md), TYPE_PC_DIMM)) { + /* compat handling: force to TARGET_PAGE_SIZE */ + if (!pcmc->enforce_aligned_dimm) { + *align =3D TARGET_PAGE_SIZE; + } + } +} + static void pc_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -2371,6 +2385,7 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) hc->unplug =3D pc_machine_device_unplug_cb; nc->nmi_monitor_handler =3D x86_nmi; mc->default_cpu_type =3D TARGET_DEFAULT_CPU_TYPE; + mc->enforce_memory_device_align =3D pc_machine_enforce_memory_device_a= lign; =20 object_class_property_add(oc, PC_MACHINE_DEVMEM_REGION_SIZE, "int", pc_machine_get_device_memory_region_size, NULL, diff --git a/include/hw/boards.h b/include/hw/boards.h index ff5142d7c2..db66f2e2d9 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -9,6 +9,7 @@ #include "qom/object.h" #include "qom/cpu.h" #include "hw/resource-handler.h" +#include "hw/mem/memory-device.h" =20 /** * memory_region_allocate_system_memory - Allocate a board's main memory @@ -163,6 +164,10 @@ typedef struct { * should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. + * @enforce_memory_device_align: + * For some memory devices (e.g. DIMMs), alignment has to be enforced f= or + * compat handling by the machine. This function will only modify the + * asignment if it needs to be enforced. */ struct MachineClass { /*< private >*/ @@ -221,6 +226,9 @@ struct MachineClass { unsigned cpu_inde= x); const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx); + void (*enforce_memory_device_align)(const MachineClass *mc, + const MemoryDeviceState *md, + uint64_t *align); }; =20 /** --=20 2.14.3 From nobody Wed Oct 29 17:11:29 2025 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 1525363042167472.12632427715573; Thu, 3 May 2018 08:57:22 -0700 (PDT) Received: from localhost ([::1]:57402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGbb-0006N8-0P for importer@patchew.org; Thu, 03 May 2018 11:57:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUd-0000s1-MK for qemu-devel@nongnu.org; Thu, 03 May 2018 11:50:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUc-0003nK-Kw for qemu-devel@nongnu.org; Thu, 03 May 2018 11:50:03 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60494 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 1fEGUc-0003mr-GN; Thu, 03 May 2018 11:50:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06E5A406F88F; Thu, 3 May 2018 15:50:02 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCA2E215CDAE; Thu, 3 May 2018 15:49:59 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:35 +0200 Message-Id: <20180503154936.18946-8-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 03 May 2018 15:50:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 03 May 2018 15:50:02 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 7/8] memory-device: factor out pre-assign into default resource handler 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 move all pre-assign checks we can do without the device being realized into the default resource handler. Signed-off-by: David Hildenbrand --- hw/core/machine.c | 17 ++++++++++ hw/mem/memory-device.c | 72 +++++++++++++++++++-------------------= ---- include/hw/mem/memory-device.h | 2 ++ 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index a41068410c..e763501c66 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -21,6 +21,7 @@ #include "qemu/error-report.h" #include "qemu/cutils.h" #include "sysemu/qtest.h" +#include "hw/mem/memory-device.h" =20 static char *machine_get_accel(Object *obj, Error **errp) { @@ -520,6 +521,9 @@ void machine_set_cpu_numa_node(MachineState *machine, static ResourceHandler *machine_get_resource_handler(MachineState *machine, const DeviceState *de= v) { + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + return RESOURCE_HANDLER(machine); + } return NULL; } =20 @@ -527,6 +531,19 @@ static void machine_resource_handler_pre_assign(Resour= ceHandler *rh, const DeviceState *dev, Error **errp) { + MachineState *ms =3D MACHINE(rh); + Error *local_err =3D NULL; + + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + const MemoryDeviceState *md =3D MEMORY_DEVICE(dev); + + memory_device_pre_assign(ms, md, &local_err); + if (local_err) { + goto out; + } + } +out: + error_propagate(errp, local_err); } =20 static void machine_resource_handler_assign(ResourceHandler *rh, diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 3e04f3954e..aa04e0c962 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -68,59 +68,27 @@ static int memory_device_used_region_size(Object *obj, = void *opaque) return 0; } =20 -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) { uint64_t address_space_start, address_space_end; + uint64_t used_region_size =3D 0; GSList *list =3D NULL, *item; uint64_t new_addr =3D 0; =20 - 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); =20 - memory_device_check_addable(ms, size, errp); - if (*errp) { + /* 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 0; } =20 @@ -243,6 +211,32 @@ uint64_t get_plugged_memory_size(void) return size; } =20 +void memory_device_pre_assign(MachineState *ms, + const MemoryDeviceState *md, Error **errp) +{ + if (!ms->device_memory) { + error_setg(errp, "memory devices (e.g. for memory hotplug) are not= " + "supported by the machine"); + return; + } + + 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; + } + + /* 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; + } +} + void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr) { diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index e10f2e854a..edbd964ac7 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -47,6 +47,8 @@ typedef struct MemoryDeviceClass { =20 MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); +void memory_device_pre_assign(MachineState *ms, + const MemoryDeviceState *md, Error **errp); uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hin= t, uint64_t align, uint64_t size, Error **errp); --=20 2.14.3 From nobody Wed Oct 29 17:11:29 2025 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 1525363178637131.15451844066; Thu, 3 May 2018 08:59:38 -0700 (PDT) Received: from localhost ([::1]:57416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGdt-0008EE-Ni for importer@patchew.org; Thu, 03 May 2018 11:59:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEGUk-0000y3-60 for qemu-devel@nongnu.org; Thu, 03 May 2018 11:50:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fEGUg-0003pU-RM for qemu-devel@nongnu.org; Thu, 03 May 2018 11:50:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52762 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 1fEGUg-0003p7-LO; Thu, 03 May 2018 11:50:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27C74401DEAB; Thu, 3 May 2018 15:50:06 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F769215CDAF; Thu, 3 May 2018 15:50:02 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 17:49:36 +0200 Message-Id: <20180503154936.18946-9-david@redhat.com> In-Reply-To: <20180503154936.18946-1-david@redhat.com> References: <20180503154936.18946-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 03 May 2018 15:50:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 03 May 2018 15:50:06 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 v1 8/8] memory-device: factor out (un)assign into default resource handler 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 moves the remaining bits into the default resource handler. The pc-dimm remainings are limited to slot and migration handling. Compatibility to old machines on x86 should be guaranteed by using the newly introduced machine class function for enforcing alignment of DIMMs. Signed-off-by: David Hildenbrand --- hw/core/machine.c | 20 +++++++++++++++++ hw/i386/pc.c | 16 +------------- hw/mem/memory-device.c | 50 +++++++++++++++++++++++++++++++++++---= ---- hw/mem/pc-dimm.c | 31 +------------------------- hw/mem/trace-events | 4 +++- hw/ppc/spapr.c | 5 ++--- include/hw/mem/memory-device.h | 9 +++----- include/hw/mem/pc-dimm.h | 3 +-- 8 files changed, 73 insertions(+), 65 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index e763501c66..7fc1a6bc5e 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -549,11 +549,31 @@ out: static void machine_resource_handler_assign(ResourceHandler *rh, DeviceState *dev, Error **errp) { + MachineState *ms =3D MACHINE(rh); + Error *local_err =3D NULL; + + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + MemoryDeviceState *md =3D MEMORY_DEVICE(dev); + + memory_device_assign(ms, md, &local_err); + if (local_err) { + goto out; + } + } +out: + error_propagate(errp, local_err); } =20 static void machine_resource_handler_unassign(ResourceHandler *rh, DeviceState *dev) { + MachineState *ms =3D MACHINE(rh); + + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + MemoryDeviceState *md =3D MEMORY_DEVICE(dev); + + memory_device_unassign(ms, md); + } } =20 static void machine_class_init(ObjectClass *oc, void *data) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 9405e28cfa..385f18bb53 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1681,22 +1681,8 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, HotplugHandlerClass *hhc; Error *local_err =3D NULL; PCMachineState *pcms =3D PC_MACHINE(hotplug_dev); - PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); - PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr; - uint64_t align =3D TARGET_PAGE_SIZE; bool is_nvdimm =3D object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); =20 - mr =3D ddc->get_memory_region(dimm, &local_err); - if (local_err) { - goto out; - } - - if (memory_region_get_alignment(mr) && pcmc->enforce_aligned_dimm) { - align =3D memory_region_get_alignment(mr); - } - /* * When -no-acpi is used with Q35 machine type, no ACPI is built, * but pcms->acpi_dev is still created. Check !acpi_enabled in @@ -1714,7 +1700,7 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev, goto out; } =20 - pc_dimm_memory_plug(dev, MACHINE(pcms), align, &local_err); + pc_dimm_memory_plug(dev, MACHINE(pcms), &local_err); if (local_err) { goto out; } diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index aa04e0c962..f7f19f6ed2 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -17,6 +17,8 @@ #include "qemu/range.h" #include "hw/virtio/vhost.h" #include "sysemu/kvm.h" +#include "trace.h" + =20 static gint memory_device_addr_sort(gconstpointer a, gconstpointer b) { @@ -68,9 +70,10 @@ static int memory_device_used_region_size(Object *obj, v= oid *opaque) 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) +static uint64_t memory_device_get_free_addr(MachineState *ms, + const uint64_t *hint, + uint64_t align, uint64_t size, + Error **errp) { uint64_t address_space_start, address_space_end; uint64_t used_region_size =3D 0; @@ -237,22 +240,53 @@ void memory_device_pre_assign(MachineState *ms, } } =20 -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, - uint64_t addr) +void memory_device_assign(MachineState *ms, MemoryDeviceState *md, + Error **errp) { - /* we expect a previous call to memory_device_get_free_addr() */ + const MachineClass *mc =3D MACHINE_GET_CLASS(ms); + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + const uint64_t size =3D mdc->get_region_size(md); + MemoryRegion *mr =3D mdc->get_memory_region(md); + uint64_t addr =3D mdc->get_addr(md); + uint64_t align =3D memory_region_get_alignment(mr); + + /* we expect a previous call to memory_device_pre_assign */ g_assert(ms->device_memory); =20 + /* our device might have stronger alignment requirements */ + if (mdc->get_align) { + align =3D MAX(align, mdc->get_align(md)); + } + + /* for compat handling, some alignment has to be enforced for DIMMs */ + if (mc->enforce_memory_device_align) { + /* align unchanged if nothing is to be enforced */ + mc->enforce_memory_device_align(mc, md, &align); + } + + addr =3D memory_device_get_free_addr(ms, !addr ? NULL : &addr, align, + size, errp); + if (*errp) { + return; + } + trace_memory_device_assign_address(addr); + mdc->set_addr(md, addr); + memory_region_add_subregion(&ms->device_memory->mr, addr - ms->device_memory->base, mr); } =20 -void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) +void memory_device_unassign(MachineState *ms, MemoryDeviceState *md) { - /* we expect a previous call to memory_device_get_free_addr() */ + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + MemoryRegion *mr =3D mdc->get_memory_region(md); + + /* we expect a previous call to memory_device_pre_assign */ g_assert(ms->device_memory); =20 memory_region_del_subregion(&ms->device_memory->mr, mr); + trace_memory_device_unassign_address(mdc->get_addr(md)); + mdc->set_addr(md, 0); } =20 static const TypeInfo memory_device_info =3D { diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 7ab9e77747..9c5eb1fb16 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -32,39 +32,13 @@ typedef struct pc_dimms_capacity { Error **errp; } pc_dimms_capacity; =20 -void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, - uint64_t align, Error **errp) +void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, Error **= errp) { int slot; PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm); Error *local_err =3D NULL; - MemoryRegion *mr; - uint64_t addr; - - 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) { - goto out; - } - - addr =3D memory_device_get_free_addr(machine, !addr ? NULL : &addr, al= ign, - memory_region_size(mr), &local_err); - if (local_err) { - goto out; - } - - object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_= err); - if (local_err) { - goto out; - } - trace_mhp_pc_dimm_assigned_address(addr); =20 slot =3D object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &loca= l_err); if (local_err) { @@ -82,7 +56,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *= machine, } trace_mhp_pc_dimm_assigned_slot(slot); =20 - memory_device_plug_region(machine, mr, addr); vmstate_register_ram(vmstate_mr, dev); =20 out: @@ -94,9 +67,7 @@ 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_device_unplug_region(machine, mr); vmstate_unregister_ram(vmstate_mr, dev); } =20 diff --git a/hw/mem/trace-events b/hw/mem/trace-events index e150dcc497..930b6aa6ea 100644 --- a/hw/mem/trace-events +++ b/hw/mem/trace-events @@ -2,4 +2,6 @@ =20 # hw/mem/pc-dimm.c mhp_pc_dimm_assigned_slot(int slot) "%d" -mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64 +# hw/mem/memory-device.c +memory_device_assign_address(uint64_t addr) "0x%"PRIx64 +memory_device_unassign_address(uint64_t addr) "0x%"PRIx64 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 428f6c79c5..818e7232d8 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3162,16 +3162,15 @@ static void spapr_memory_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *mr; - uint64_t align, size, addr; + uint64_t size, addr; =20 mr =3D ddc->get_memory_region(dimm, &local_err); if (local_err) { goto out; } - align =3D memory_region_get_alignment(mr); size =3D memory_region_size(mr); =20 - pc_dimm_memory_plug(dev, MACHINE(ms), align, &local_err); + pc_dimm_memory_plug(dev, MACHINE(ms), &local_err); if (local_err) { goto out; } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index edbd964ac7..6cedbaf747 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -49,11 +49,8 @@ MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); void memory_device_pre_assign(MachineState *ms, const MemoryDeviceState *md, Error **errp); -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); +void memory_device_assign(MachineState *ms, MemoryDeviceState *md, + Error **errp); +void memory_device_unassign(MachineState *ms, MemoryDeviceState *md); =20 #endif diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 627c8601d9..006c80fb2e 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 -void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, - uint64_t align, Error **errp); +void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, Error **= errp); void pc_dimm_memory_unplug(DeviceState *dev, MachineState *machine); #endif --=20 2.14.3