From nobody Wed Oct 29 11:38:24 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 1526044958517570.8215778755343; Fri, 11 May 2018 06:22:38 -0700 (PDT) Received: from localhost ([::1]:44559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH800-0002Na-2r for importer@patchew.org; Fri, 11 May 2018 09:22:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7y4-0000pv-Bn for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7xy-0003ie-Rh for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57324 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 1fH7xy-0003iA-ND; Fri, 11 May 2018 09:20:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4934C125CC0; Fri, 11 May 2018 13:20:10 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EAE01208F9E; Fri, 11 May 2018 13:20:07 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:37 +0200 Message-Id: <20180511131953.12905-2-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 11 May 2018 13:20:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 11 May 2018 13:20:10 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 01/17] memory-device: drop assert related to align and start of address space 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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" The start of the address space does not have to be aligned for the search. Handly this case explicitly when starting the search for a new address. Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 3e04f3954e..361d38bfc5 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -116,7 +116,6 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, 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); @@ -149,7 +148,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, return 0; } } else { - new_addr =3D address_space_start; + new_addr =3D QEMU_ALIGN_UP(address_space_start, align); } =20 /* find address range that will fit new memory device */ --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526044961690323.40629470503995; Fri, 11 May 2018 06:22:41 -0700 (PDT) Received: from localhost ([::1]:44558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7zy-0002KN-EF for importer@patchew.org; Fri, 11 May 2018 09:22:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7y2-0000oz-MO for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7y1-0003mC-LS for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57334 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 1fH7y1-0003lJ-ES; Fri, 11 May 2018 09:20:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11E365BCB6; Fri, 11 May 2018 13:20:13 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81FA5100297A; Fri, 11 May 2018 13:20:10 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:38 +0200 Message-Id: <20180511131953.12905-3-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 11 May 2018 13:20:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 11 May 2018 13:20:13 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 02/17] qdev: let machine hotplug handler to override bus 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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" From: Igor Mammedov it will allow to return another hotplug handler than the default one for a specific bus based device type. Which is needed to handle non trivial plug/unplug sequences that need the access to resources configured outside of bus where device is attached. That will allow for returned hotplug handler to orchestrate wiring in arbitrary order, by chaining other hotplug handlers when it's needed. PS: It could be used for hybrid virtio-mem and virtio-pmem devices where it will return machine as hotplug handler which will do necessary wiring at machine level and then pass control down the chain to bus specific hotplug handler. Example of top level hotplug handler override and custom plug sequence: some_machine_get_hotplug_handler(machine){ if (object_dynamic_cast(OBJECT(dev), TYPE_SOME_BUS_DEVICE)) { return HOTPLUG_HANDLER(machine); } return NULL; } some_machine_device_plug(hotplug_dev, dev) { if (object_dynamic_cast(OBJECT(dev), TYPE_SOME_BUS_DEVICE)) { /* do machine specific initialization */ some_machine_init_special_device(dev) /* pass control to bus specific handler */ hotplug_handler_plug(dev->parent_bus->hotplug_handler, dev) } } Signed-off-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/core/qdev.c | 6 ++---- include/hw/qdev-core.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index f6f92473b8..885286f579 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -261,12 +261,10 @@ HotplugHandler *qdev_get_machine_hotplug_handler(Devi= ceState *dev) =20 HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) { - HotplugHandler *hotplug_ctrl; + HotplugHandler *hotplug_ctrl =3D qdev_get_machine_hotplug_handler(dev); =20 - if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + if (hotplug_ctrl =3D=3D NULL && dev->parent_bus) { hotplug_ctrl =3D dev->parent_bus->hotplug_handler; - } else { - hotplug_ctrl =3D qdev_get_machine_hotplug_handler(dev); } return hotplug_ctrl; } diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9453588160..e6a8eca558 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -286,6 +286,17 @@ void qdev_init_nofail(DeviceState *dev); void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version); HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev); +/** + * qdev_get_hotplug_handler: Get handler responsible for device wiring + * + * Find HOTPLUG_HANDLER for @dev that provides [pre|un]plug callbacks for = it. + * + * Note: in case @dev has a parent bus, it will be returned as handler unl= ess + * machine handler overrides it. + * + * Returns: pointer to object that implements TYPE_HOTPLUG_HANDLER interfa= ce + * or NULL if there aren't any. + */ HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev); void qdev_unplug(DeviceState *dev, Error **errp); void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045127894387.2054472321465; Fri, 11 May 2018 06:25:27 -0700 (PDT) Received: from localhost ([::1]:44588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH834-0005om-L0 for importer@patchew.org; Fri, 11 May 2018 09:25:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yB-0000wd-Ff for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yA-0003vO-Dg for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37028 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 1fH7yA-0003uc-8i; Fri, 11 May 2018 09:20:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9DE4F402B03F; Fri, 11 May 2018 13:20:21 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EB3E100297F; Fri, 11 May 2018 13:20:13 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:39 +0200 Message-Id: <20180511131953.12905-4-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:20:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:20:21 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 03/17] pc: prepare for multi stage hotplug handlers 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 multi stage hotplug handlers, we'll have to do some error handling in some hotplug functions, so let's use a local error variable (except for unplug requests). Also, add code to pass control to the final stage hotplug handler at the parent bus. Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index b2374febbb..39153fa083 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2007,19 +2007,32 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug= _dev, static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err =3D NULL; + + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { - pc_cpu_pre_plug(hotplug_dev, dev, errp); + pc_cpu_pre_plug(hotplug_dev, dev, &local_err); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev, + &local_err); } + error_propagate(errp, local_err); } =20 static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err =3D NULL; + + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { - pc_dimm_plug(hotplug_dev, dev, errp); + pc_dimm_plug(hotplug_dev, dev, &local_err); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { - pc_cpu_plug(hotplug_dev, dev, errp); + pc_cpu_plug(hotplug_dev, dev, &local_err); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_plug(dev->parent_bus->hotplug_handler, dev, &local= _err); } + error_propagate(errp, local_err); } =20 static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_de= v, @@ -2029,7 +2042,10 @@ static void pc_machine_device_unplug_request_cb(Hotp= lugHandler *hotplug_dev, pc_dimm_unplug_request(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_unplug_request_cb(hotplug_dev, dev, errp); - } else { + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_unplug_request(dev->parent_bus->hotplug_handler, d= ev, + errp); + } else if (!dev->parent_bus) { error_setg(errp, "acpi: device unplug request for not supported de= vice" " type: %s", object_get_typename(OBJECT(dev))); } @@ -2038,14 +2054,21 @@ static void pc_machine_device_unplug_request_cb(Hot= plugHandler *hotplug_dev, static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err =3D NULL; + + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { - pc_dimm_unplug(hotplug_dev, dev, errp); + pc_dimm_unplug(hotplug_dev, dev, &local_err); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { - pc_cpu_unplug_cb(hotplug_dev, dev, errp); - } else { - error_setg(errp, "acpi: device unplug for not supported device" + pc_cpu_unplug_cb(hotplug_dev, dev, &local_err); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, + &local_err); + } else if (!dev->parent_bus) { + error_setg(&local_err, "acpi: device unplug for not supported devi= ce" " type: %s", object_get_typename(OBJECT(dev))); } + error_propagate(errp, local_err); } =20 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine, --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045301611707.9120956112271; Fri, 11 May 2018 06:28:21 -0700 (PDT) Received: from localhost ([::1]:44632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH85r-0000pE-F1 for importer@patchew.org; Fri, 11 May 2018 09:28:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yF-00011S-SK for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yE-00041Y-U8 for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37040 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 1fH7yE-00040z-OE; Fri, 11 May 2018 09:20:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AA88402B03F; Fri, 11 May 2018 13:20:26 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB465100297B; Fri, 11 May 2018 13:20:21 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:40 +0200 Message-Id: <20180511131953.12905-5-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:20:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:20:26 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 04/17] pc: route all memory devices through the machine 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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" Necessary to hotplug them cleanly later. We can only support memory devices that are not DIMMs if we have a parent bus. Otherwise we might miss "Device '%s' can not be hotplugged on this machine" cases. Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 39153fa083..7a5558ebea 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -74,6 +74,7 @@ #include "hw/nmi.h" #include "hw/i386/intel_iommu.h" #include "hw/net/ne2000-isa.h" +#include "hw/mem/memory-device.h" =20 /* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -2079,6 +2080,12 @@ static HotplugHandler *pc_get_hotpug_handler(Machine= State *machine, return HOTPLUG_HANDLER(machine); } =20 + if (dev->parent_bus) { + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + return HOTPLUG_HANDLER(machine); + } + } + return NULL; } =20 --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045107062383.009871005685; Fri, 11 May 2018 06:25:07 -0700 (PDT) Received: from localhost ([::1]:44587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH82j-0005Tl-In for importer@patchew.org; Fri, 11 May 2018 09:25:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yJ-00014f-Du for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yI-00045E-4m for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37564 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 1fH7yH-00044h-UK; Fri, 11 May 2018 09:20:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 799FD40252ED; Fri, 11 May 2018 13:20:29 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94BA9100297B; Fri, 11 May 2018 13:20:26 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:41 +0200 Message-Id: <20180511131953.12905-6-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 11 May 2018 13:20:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 11 May 2018 13:20:29 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 05/17] spapr: prepare for multi stage hotplug handlers 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 multi stage hotplug handlers, we'll have to do some error handling in some hotplug functions, so let's use a local error variable (except for unplug requests). Also, add code to pass control to the final stage hotplug handler at the parent bus. Signed-off-by: David Hildenbrand --- hw/ppc/spapr.c | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a1abcba6ad..db09b626cc 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3571,27 +3571,48 @@ static void spapr_machine_device_plug(HotplugHandle= r *hotplug_dev, { MachineState *ms =3D MACHINE(hotplug_dev); sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(ms); + Error *local_err =3D NULL; =20 + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { int node; =20 if (!smc->dr_lmb_enabled) { - error_setg(errp, "Memory hotplug not supported for this machin= e"); - return; + error_setg(&local_err, + "Memory hotplug not supported for this machine"); + goto out; } - node =3D object_property_get_uint(OBJECT(dev), PC_DIMM_NODE_PROP, = errp); - if (*errp) { - return; + node =3D object_property_get_uint(OBJECT(dev), PC_DIMM_NODE_PROP, + &local_err); + if (local_err) { + goto out; } if (node < 0 || node >=3D MAX_NODES) { - error_setg(errp, "Invaild node %d", node); - return; + error_setg(&local_err, "Invaild node %d", node); + goto out; } =20 - spapr_memory_plug(hotplug_dev, dev, node, errp); + spapr_memory_plug(hotplug_dev, dev, node, &local_err); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { - spapr_core_plug(hotplug_dev, dev, errp); + spapr_core_plug(hotplug_dev, dev, &local_err); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_plug(dev->parent_bus->hotplug_handler, dev, &local= _err); + } +out: + error_propagate(errp, local_err); +} + +static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + Error *local_err =3D NULL; + + /* final stage hotplug handler */ + if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, + &local_err); } + error_propagate(errp, local_err); } =20 static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_de= v, @@ -3618,17 +3639,27 @@ static void spapr_machine_device_unplug_request(Hot= plugHandler *hotplug_dev, return; } spapr_core_unplug_request(hotplug_dev, dev, errp); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_unplug_request(dev->parent_bus->hotplug_handler, d= ev, + errp); } } =20 static void spapr_machine_device_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err =3D NULL; + + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { - spapr_memory_pre_plug(hotplug_dev, dev, errp); + spapr_memory_pre_plug(hotplug_dev, dev, &local_err); } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { - spapr_core_pre_plug(hotplug_dev, dev, errp); + spapr_core_pre_plug(hotplug_dev, dev, &local_err); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev, + &local_err); } + error_propagate(errp, local_err); } =20 static HotplugHandler *spapr_get_hotplug_handler(MachineState *machine, @@ -3987,6 +4018,7 @@ static void spapr_machine_class_init(ObjectClass *oc,= void *data) mc->get_default_cpu_node_id =3D spapr_get_default_cpu_node_id; mc->possible_cpu_arch_ids =3D spapr_possible_cpu_arch_ids; hc->unplug_request =3D spapr_machine_device_unplug_request; + hc->unplug =3D spapr_machine_device_unplug; =20 smc->dr_lmb_enabled =3D true; mc->default_cpu_type =3D POWERPC_CPU_TYPE_NAME("power8_v2.0"); --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045487789498.7834737039751; Fri, 11 May 2018 06:31:27 -0700 (PDT) Received: from localhost ([::1]:44662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH88q-0004RK-6h for importer@patchew.org; Fri, 11 May 2018 09:31:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yL-000173-Qk for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yK-00048Q-RU for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37058 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 1fH7yK-00047n-Lu; Fri, 11 May 2018 09:20:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45050400187E; Fri, 11 May 2018 13:20:32 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id B55F6100297B; Fri, 11 May 2018 13:20:29 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:42 +0200 Message-Id: <20180511131953.12905-7-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:20:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:20:32 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 06/17] spapr: route all memory devices through the machine 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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" Necessary to hotplug them cleanly later. We can only support memory devices that are not DIMMs if we have a parent bus. Otherwise we might miss "Device '%s' can not be hotplugged on this machine" cases. Signed-off-by: David Hildenbrand --- hw/ppc/spapr.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index db09b626cc..a7c84ec34c 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3669,6 +3669,13 @@ static HotplugHandler *spapr_get_hotplug_handler(Mac= hineState *machine, object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { return HOTPLUG_HANDLER(machine); } + + if (dev->parent_bus) { + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + return HOTPLUG_HANDLER(machine); + } + } + return NULL; } =20 --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045161682600.0039523187385; Fri, 11 May 2018 06:26:01 -0700 (PDT) Received: from localhost ([::1]:44595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH83c-0006Zv-Ak for importer@patchew.org; Fri, 11 May 2018 09:26:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yU-0001FX-J7 for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yT-0004JQ-Cc for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37588 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 1fH7yT-0004Iy-7j; Fri, 11 May 2018 09:20:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D746E402335F; Fri, 11 May 2018 13:20:40 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D089122774D; Fri, 11 May 2018 13:20:32 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:43 +0200 Message-Id: <20180511131953.12905-8-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 11 May 2018 13:20:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 11 May 2018 13:20:40 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 07/17] spapr: handle pc-dimm unplug via hotplug handler chain 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 handle it via hotplug_handler_unplug(). E.g. necessary to hotplug/ unplug memory devices (which a pc-dimm is) later. Signed-off-by: David Hildenbrand --- hw/ppc/spapr.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a7c84ec34c..7881565d41 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3291,7 +3291,8 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_sta= te(sPAPRMachineState *ms, /* Callback to be called during DRC release. */ void spapr_lmb_release(DeviceState *dev) { - sPAPRMachineState *spapr =3D SPAPR_MACHINE(qdev_get_hotplug_handler(de= v)); + HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_ctrl); sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(= dev)); =20 /* This information will get lost if a migration occurs @@ -3309,9 +3310,21 @@ void spapr_lmb_release(DeviceState *dev) =20 /* * Now that all the LMBs have been removed by the guest, call the - * pc-dimm unplug handler to cleanup up the pc-dimm device. + * unplug handler chain. This can never fail. */ - pc_dimm_memory_unplug(dev, MACHINE(spapr)); + hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); +} + +static void spapr_memory_unplug(HotplugHandler *hotplug_dev, DeviceState *= dev, + Error **errp) +{ + sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); + sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(= dev)); + + g_assert(ds); + g_assert(!ds->nr_lmbs); + pc_dimm_memory_unplug(dev, MACHINE(hotplug_dev)); object_unparent(OBJECT(dev)); spapr_pending_dimm_unplugs_remove(spapr, ds); } @@ -3608,7 +3621,9 @@ static void spapr_machine_device_unplug(HotplugHandle= r *hotplug_dev, Error *local_err =3D NULL; =20 /* final stage hotplug handler */ - if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + spapr_memory_unplug(hotplug_dev, dev, &local_err); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, &local_err); } --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526044972608104.27375974369875; Fri, 11 May 2018 06:22:52 -0700 (PDT) Received: from localhost ([::1]:44560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH80Z-000300-AW for importer@patchew.org; Fri, 11 May 2018 09:22:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yb-0001O7-7t for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yY-0004OA-47 for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53398 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 1fH7yX-0004Nm-VK; Fri, 11 May 2018 09:20:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D98C7D664; Fri, 11 May 2018 13:20:45 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F017100297E; Fri, 11 May 2018 13:20:40 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:44 +0200 Message-Id: <20180511131953.12905-9-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 11 May 2018 13:20:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 11 May 2018 13:20:45 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 08/17] spapr: handle cpu core unplug via hotplug handler chain 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 handle it via hotplug_handler_unplug(). Signed-off-by: David Hildenbrand --- hw/ppc/spapr.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 7881565d41..2df15f9db6 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3412,7 +3412,16 @@ static void *spapr_populate_hotplug_cpu_dt(CPUState = *cs, int *fdt_offset, /* Callback to be called during DRC release. */ void spapr_core_release(DeviceState *dev) { - MachineState *ms =3D MACHINE(qdev_get_hotplug_handler(dev)); + HotplugHandler *hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + + /* Call the unplug handler chain. This can never fail. */ + hotplug_handler_unplug(hotplug_ctrl, dev, &error_abort); +} + +static void spapr_core_unplug(HotplugHandler *hotplug_dev, DeviceState *de= v, + Error **errp) +{ + MachineState *ms =3D MACHINE(hotplug_dev); sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(ms); CPUCore *cc =3D CPU_CORE(dev); CPUArchId *core_slot =3D spapr_find_cpu_slot(ms, cc->core_id, NULL); @@ -3623,6 +3632,8 @@ static void spapr_machine_device_unplug(HotplugHandle= r *hotplug_dev, /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { spapr_memory_unplug(hotplug_dev, dev, &local_err); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { + spapr_core_unplug(hotplug_dev, dev, &local_err); } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, &local_err); --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045336538782.7080693297577; Fri, 11 May 2018 06:28:56 -0700 (PDT) Received: from localhost ([::1]:44633 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH86R-0001Zg-C4 for importer@patchew.org; Fri, 11 May 2018 09:28:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yb-0001Od-Qg for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7ya-0004QC-T9 for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49538 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 1fH7ya-0004Pu-O1; Fri, 11 May 2018 09:20:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5323F407B3B8; Fri, 11 May 2018 13:20:48 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id C935C1002974; Fri, 11 May 2018 13:20:45 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:45 +0200 Message-Id: <20180511131953.12905-10-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 11 May 2018 13:20:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 11 May 2018 13:20:48 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 09/17] memory-device: new functions to handle plug/unplug 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 plug/unplug memory devices. Signed-off-by: David Hildenbrand --- include/hw/mem/memory-device.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 2853b084b5..62d906be50 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -29,14 +29,24 @@ typedef struct MemoryDeviceState { Object parent_obj; } MemoryDeviceState; =20 +/* + * MemoryDeviceClass functions should only be called on realized + * MemoryDevice instances. + */ typedef struct MemoryDeviceClass { InterfaceClass parent_class; =20 + /* required functions that have to be implemented */ uint64_t (*get_addr)(const 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, 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 11:38:24 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 1526045142876637.274709982973; Fri, 11 May 2018 06:25:42 -0700 (PDT) Received: from localhost ([::1]:44590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH83J-00068w-JT for importer@patchew.org; Fri, 11 May 2018 09:25:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7ye-0001RV-GL for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yd-0004T9-JA for qemu-devel@nongnu.org; Fri, 11 May 2018 09:20:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53440 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 1fH7yd-0004Se-Fn; Fri, 11 May 2018 09:20:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19AAE7D65F; Fri, 11 May 2018 13:20:51 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E8641002974; Fri, 11 May 2018 13:20:48 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:46 +0200 Message-Id: <20180511131953.12905-11-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 11 May 2018 13:20:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 11 May 2018 13:20:51 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 10/17] 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 12da89d562..5e2e3263ab 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -244,6 +244,21 @@ 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) +{ + const PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(md); + PCDIMMDevice *dimm =3D PC_DIMM(md); + + return ddc->get_memory_region(dimm, &error_abort); +} + 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 +319,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; --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045719522272.85390043953373; Fri, 11 May 2018 06:35:19 -0700 (PDT) Received: from localhost ([::1]:44909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH8Cc-0000je-7f for importer@patchew.org; Fri, 11 May 2018 09:35:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yn-0001cv-Iy for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7ym-0004cg-8e for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57452 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 1fH7ym-0004bU-3P; Fri, 11 May 2018 09:21:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AABC15BCB6; Fri, 11 May 2018 13:20:59 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55E8C1002974; Fri, 11 May 2018 13:20:51 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:47 +0200 Message-Id: <20180511131953.12905-12-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 11 May 2018 13:20:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 11 May 2018 13:20:59 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 11/17] memory-device: factor out pre-plug into 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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-plug checks we can do without the device being realized into the applicable hotplug handler for pc and spapr. Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 11 +++++++ hw/mem/memory-device.c | 72 +++++++++++++++++++-------------------= ---- hw/ppc/spapr.c | 11 +++++++ include/hw/mem/memory-device.h | 2 ++ 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 7a5558ebea..49e590ef16 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2010,6 +2010,16 @@ static void pc_machine_device_pre_plug_cb(HotplugHan= dler *hotplug_dev, { Error *local_err =3D NULL; =20 + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_pre_plug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev), + &local_err); + } + + if (local_err) { + goto out; + } + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_pre_plug(hotplug_dev, dev, &local_err); @@ -2017,6 +2027,7 @@ static void pc_machine_device_pre_plug_cb(HotplugHand= ler *hotplug_dev, hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev, &local_err); } +out: error_propagate(errp, local_err); } =20 diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 361d38bfc5..d22c91993f 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -68,58 +68,26 @@ 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(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 @@ -242,6 +210,32 @@ uint64_t get_plugged_memory_size(void) return size; } =20 +void memory_device_pre_plug(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/hw/ppc/spapr.c b/hw/ppc/spapr.c index 2df15f9db6..870eafae28 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3676,6 +3676,16 @@ static void spapr_machine_device_pre_plug(HotplugHan= dler *hotplug_dev, { Error *local_err =3D NULL; =20 + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_pre_plug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev), + &local_err); + } + + if (local_err) { + goto out; + } + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { spapr_memory_pre_plug(hotplug_dev, dev, &local_err); @@ -3685,6 +3695,7 @@ static void spapr_machine_device_pre_plug(HotplugHand= ler *hotplug_dev, hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev, &local_err); } +out: error_propagate(errp, local_err); } =20 diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 62d906be50..3a4e9edc92 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -51,6 +51,8 @@ typedef struct MemoryDeviceClass { =20 MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); +void memory_device_pre_plug(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 11:38:24 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 152604558184777.18447972293234; Fri, 11 May 2018 06:33:01 -0700 (PDT) Received: from localhost ([::1]:44664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH8AO-0006JA-Co for importer@patchew.org; Fri, 11 May 2018 09:33:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7yx-0001nu-Ll for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7yv-0004w9-Gg for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55694 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 1fH7yv-0004ux-BE; Fri, 11 May 2018 09:21:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7D75818A6AB; Fri, 11 May 2018 13:21:08 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id E60931002970; Fri, 11 May 2018 13:20:59 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:48 +0200 Message-Id: <20180511131953.12905-13-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 13:21:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 13:21:08 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 12/17] memory-device: factor out unplug into 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 the unplug logic into the applicable hotplug handler for pc and spapr. We'll move the plug logic next, then this will look more symmetrical in the hotplug handlers. Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 17 ++++++++++++++++- hw/mem/memory-device.c | 14 ++++++++++++-- hw/mem/pc-dimm.c | 2 -- hw/mem/trace-events | 2 ++ hw/ppc/spapr.c | 16 +++++++++++++++- include/hw/mem/memory-device.h | 2 +- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 49e590ef16..b90cbd5495 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2044,6 +2044,12 @@ static void pc_machine_device_plug_cb(HotplugHandler= *hotplug_dev, } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { hotplug_handler_plug(dev->parent_bus->hotplug_handler, dev, &local= _err); } + + if (local_err) { + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_unplug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev)); + } + } error_propagate(errp, local_err); } =20 @@ -2080,7 +2086,16 @@ static void pc_machine_device_unplug_cb(HotplugHandl= er *hotplug_dev, error_setg(&local_err, "acpi: device unplug for not supported devi= ce" " type: %s", object_get_typename(OBJECT(dev))); } - error_propagate(errp, local_err); + + if (local_err) { + error_propagate(errp, local_err); + return; + } + + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_unplug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev)); + } } =20 static HotplugHandler *pc_get_hotpug_handler(MachineState *machine, diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index d22c91993f..8f10d613ea 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -17,6 +17,7 @@ #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) { @@ -246,12 +247,21 @@ void memory_device_plug_region(MachineState *ms, Memo= ryRegion *mr, addr - ms->device_memory->base, mr); } =20 -void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) +void memory_device_unplug(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_plug */ g_assert(ms->device_memory); =20 + if (!memory_region_is_mapped(mr)) { + return; + } + 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 5e2e3263ab..d487bb513b 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -94,9 +94,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..a661ee49a3 100644 --- a/hw/mem/trace-events +++ b/hw/mem/trace-events @@ -3,3 +3,5 @@ # 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_unassign_address(uint64_t addr) "0x%"PRIx64 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 870eafae28..4b5e4de7da 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3621,6 +3621,11 @@ static void spapr_machine_device_plug(HotplugHandler= *hotplug_dev, hotplug_handler_plug(dev->parent_bus->hotplug_handler, dev, &local= _err); } out: + if (local_err) { + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_unplug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev)); + } + } error_propagate(errp, local_err); } =20 @@ -3638,7 +3643,16 @@ static void spapr_machine_device_unplug(HotplugHandl= er *hotplug_dev, hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, &local_err); } - error_propagate(errp, local_err); + + if (local_err) { + error_propagate(errp, local_err); + return; + } + + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_unplug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev)); + } } =20 static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_de= v, diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 3a4e9edc92..b8365959e7 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -58,6 +58,6 @@ uint64_t memory_device_get_free_addr(MachineState *ms, co= nst uint64_t *hint, 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_unplug(MachineState *ms, MemoryDeviceState *md); =20 #endif --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045569127826.2550561730745; Fri, 11 May 2018 06:32:49 -0700 (PDT) Received: from localhost ([::1]:44663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH8AB-00063a-Mw for importer@patchew.org; Fri, 11 May 2018 09:32:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7z9-00020e-MM for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7z8-000562-2d for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55722 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 1fH7z7-00055Z-Su; Fri, 11 May 2018 09:21:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80BF8818A6AB; Fri, 11 May 2018 13:21:21 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 311B213D2CED; Fri, 11 May 2018 13:21:09 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:49 +0200 Message-Id: <20180511131953.12905-14-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 13:21:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 13:21:21 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 13/17] memory-device: factor out plug into 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 the plug logic into the applicable hotplug handler for pc and spapr. Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 35 ++++++++++++++++++++--------------- hw/mem/memory-device.c | 40 ++++++++++++++++++++++++++++++++++----= -- hw/mem/pc-dimm.c | 29 +---------------------------- hw/mem/trace-events | 2 +- hw/ppc/spapr.c | 15 ++++++++++++--- include/hw/mem/memory-device.h | 7 ++----- include/hw/mem/pc-dimm.h | 3 +-- 7 files changed, 71 insertions(+), 60 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index b90cbd5495..8bf0de1ef2 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1682,22 +1682,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 @@ -1715,7 +1701,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; } @@ -2036,6 +2022,25 @@ static void pc_machine_device_plug_cb(HotplugHandler= *hotplug_dev, { Error *local_err =3D NULL; =20 + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + const PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(hotplug_dev); + uint64_t align =3D 0; + + /* compat handling: force to TARGET_PAGE_SIZE */ + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) && + !pcmc->enforce_aligned_dimm) { + align =3D TARGET_PAGE_SIZE; + } + memory_device_plug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev), + align ? &align : NULL, &local_err); + } + + if (local_err) { + error_propagate(errp, local_err); + return; + } + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { pc_dimm_plug(hotplug_dev, dev, &local_err); diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 8f10d613ea..04bdb30f22 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -69,9 +69,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,11 +238,38 @@ void memory_device_pre_plug(MachineState *ms, const M= emoryDeviceState *md, } } =20 -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, - uint64_t addr) +void memory_device_plug(MachineState *ms, MemoryDeviceState *md, + uint64_t *enforced_align, Error **errp) { - /* we expect a previous call to memory_device_get_free_addr() */ + 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; + + /* we expect a previous call to memory_device_pre_plug */ g_assert(ms->device_memory); + g_assert(mr && !memory_region_is_mapped(mr)); + + /* compat handling, some alignment has to be enforced for DIMMs */ + if (enforced_align) { + align =3D *enforced_align; + } else { + align =3D memory_region_get_alignment(mr); + } + + /* our device might have stronger alignment requirements */ + if (mdc->get_align) { + align =3D MAX(align, mdc->get_align(md)); + } + + 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); =20 memory_region_add_subregion(&ms->device_memory->mr, addr - ms->device_memory->base, mr); diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index d487bb513b..8b1dcb3260 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: diff --git a/hw/mem/trace-events b/hw/mem/trace-events index a661ee49a3..930b6aa6ea 100644 --- a/hw/mem/trace-events +++ b/hw/mem/trace-events @@ -2,6 +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 4b5e4de7da..6bb677c95d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3144,16 +3144,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; } @@ -3595,6 +3594,16 @@ static void spapr_machine_device_plug(HotplugHandler= *hotplug_dev, sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(ms); Error *local_err =3D NULL; =20 + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_plug(ms, MEMORY_DEVICE(dev), NULL, &local_err); + } + + if (local_err) { + error_propagate(errp, local_err); + return; + } + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { int node; diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index b8365959e7..a7408597fd 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -53,11 +53,8 @@ MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); void memory_device_pre_plug(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_plug(MachineState *ms, MemoryDeviceState *md, + uint64_t *enforced_align, Error **errp); void memory_device_unplug(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 From nobody Wed Oct 29 11:38:24 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 1526045376106363.2888381244792; Fri, 11 May 2018 06:29:36 -0700 (PDT) Received: from localhost ([::1]:44635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH874-0002Kc-Qd for importer@patchew.org; Fri, 11 May 2018 09:29:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7zG-00029G-CQ for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7zE-0005CA-8R for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49626 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 1fH7zE-0005By-4O; Fri, 11 May 2018 09:21:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B31CE407607F; Fri, 11 May 2018 13:21:27 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCC55100297E; Fri, 11 May 2018 13:21:21 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:50 +0200 Message-Id: <20180511131953.12905-15-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 11 May 2018 13:21:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 11 May 2018 13:21:27 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 14/17] s390x/sclp: make sure ram_size and maxram_size stay in sync 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 s390x, we sometimes have to shrink ram_size in order to be able to correctly indicate the size to the guest. In case maxmem is not set, ram_size and maxram_size should always be kept equal. Make sure to also fixup maxram_size if necessary. In case maxmem is set, we really want to bail out in case we have to round down, as it basically can screw up the size of the device memory area later on. Pleas note that this fixup ususally does not happen with sane values for the ram size. Signed-off-by: David Hildenbrand --- hw/s390x/sclp.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c index 047d577313..0757914374 100644 --- a/hw/s390x/sclp.c +++ b/hw/s390x/sclp.c @@ -21,6 +21,8 @@ #include "hw/s390x/event-facility.h" #include "hw/s390x/s390-pci-bus.h" #include "hw/s390x/ipl.h" +#include "qemu/error-report.h" + =20 static inline SCLPDevice *get_sclp_device(void) { @@ -318,9 +320,19 @@ static void sclp_memory_init(SCLPDevice *sclp) * down to align with the nearest increment boundary. */ initial_mem =3D initial_mem >> increment_size << increment_size; =20 - machine->ram_size =3D initial_mem; - /* let's propagate the changed ram size into the global variable. */ - ram_size =3D initial_mem; + /* also shrink maxram_size in case we don't have maxmem configured */ + if (initial_mem !=3D machine->ram_size) { + if (machine->ram_size < machine->maxram_size) { + error_report("Ram size ('" RAM_ADDR_FMT "') had to be rounded " + "down to ('" RAM_ADDR_FMT "'), maxmem not support= ed", + machine->ram_size, initial_mem); + exit(1); + } + /* propagate the changed ram size into the different places */ + machine->ram_size =3D initial_mem; + ram_size =3D initial_mem; + machine->maxram_size =3D initial_mem; + } } =20 static void sclp_init(Object *obj) --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045857899597.6546674769525; Fri, 11 May 2018 06:37:37 -0700 (PDT) Received: from localhost ([::1]:45215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH8Eo-0002pG-GZ for importer@patchew.org; Fri, 11 May 2018 09:37:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7zR-0002Nz-EL for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7zO-0005LZ-8t for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55758 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 1fH7zO-0005LE-4p; Fri, 11 May 2018 09:21:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B756E818A6AB; Fri, 11 May 2018 13:21:37 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id F06541002979; Fri, 11 May 2018 13:21:27 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:51 +0200 Message-Id: <20180511131953.12905-16-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 13:21:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 11 May 2018 13:21:37 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 15/17] s390x: prepare for multi stage hotplug handlers 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 multi stage hotplug handlers, we'll have to do some error handling in some hotplug functions, so let's use a local error variable (except for unplug requests). Also, add code to pass control to the final stage hotplug handler at the parent bus. Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 100dfdc96d..ee0a2b124f 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -394,21 +394,56 @@ static void s390_machine_reset(void) s390_cpu_set_state(S390_CPU_STATE_OPERATING, ipl_cpu); } =20 +static void s390_machine_device_pre_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + Error *local_err =3D NULL; + + /* final stage hotplug handler */ + if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev, + &local_err); + } + error_propagate(errp, local_err); +} + static void s390_machine_device_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err =3D NULL; + + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { - s390_cpu_plug(hotplug_dev, dev, errp); + s390_cpu_plug(hotplug_dev, dev, &local_err); + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_plug(dev->parent_bus->hotplug_handler, dev, &local= _err); } + error_propagate(errp, local_err); } =20 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, Error **e= rrp) { + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { error_setg(errp, "CPU hot unplug not supported on this machine"); - return; + } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_unplug_request(dev->parent_bus->hotplug_handler, d= ev, + errp); + } +} + +static void s390_machine_device_unplug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + Error *local_err =3D NULL; + + /* final stage hotplug handler */ + if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev, + &local_err); } + error_propagate(errp, local_err); } =20 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms, @@ -496,8 +531,10 @@ static void ccw_machine_class_init(ObjectClass *oc, vo= id *data) mc->possible_cpu_arch_ids =3D s390_possible_cpu_arch_ids; /* it is overridden with 'host' cpu *in kvm_arch_init* */ mc->default_cpu_type =3D S390_CPU_TYPE_NAME("qemu"); + hc->pre_plug =3D s390_machine_device_pre_plug; hc->plug =3D s390_machine_device_plug; hc->unplug_request =3D s390_machine_device_unplug_request; + hc->unplug =3D s390_machine_device_unplug; nc->nmi_monitor_handler =3D s390_nmi; } =20 --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045586620190.3381349011379; Fri, 11 May 2018 06:33:06 -0700 (PDT) Received: from localhost ([::1]:44665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH8AR-0006Kx-6k for importer@patchew.org; Fri, 11 May 2018 09:33:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7zS-0002OO-1V for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7zR-0005Pq-1k for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37274 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 1fH7zQ-0005PL-Sw; Fri, 11 May 2018 09:21:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C761406F11D; Fri, 11 May 2018 13:21:40 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id F22951002979; Fri, 11 May 2018 13:21:37 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:52 +0200 Message-Id: <20180511131953.12905-17-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:21:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 13:21:40 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 16/17] s390x: initialize memory region for memory devices 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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" While s390x has no real interface for communicating devices mapped into the physical address space of the guest, paravirtualized devices can easily expose the applicable address range themselves. So let's use the difference between maxram_size and ram_size as the size for our hotplug memory area (just as on other architectures). Signed-off-by: David Hildenbrand --- hw/s390x/s390-virtio-ccw.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index ee0a2b124f..09b755282b 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -157,9 +157,11 @@ static void virtio_ccw_register_hcalls(void) #define KVM_MEM_MAX_NR_PAGES ((1ULL << 31) - 1) #define SEG_MSK (~0xfffffULL) #define KVM_SLOT_MAX_BYTES ((KVM_MEM_MAX_NR_PAGES * TARGET_PAGE_SIZE) & SE= G_MSK) -static void s390_memory_init(ram_addr_t mem_size) +static void s390_memory_init(MachineState *machine) { + S390CcwMachineState *ms =3D S390_CCW_MACHINE(machine); MemoryRegion *sysmem =3D get_system_memory(); + ram_addr_t mem_size =3D machine->ram_size; ram_addr_t chunk, offset =3D 0; unsigned int number =3D 0; gchar *name; @@ -181,6 +183,28 @@ static void s390_memory_init(ram_addr_t mem_size) } g_free(name); =20 + /* always allocate the device memory information */ + machine->device_memory =3D g_malloc0(sizeof(*machine->device_memory)); + + /* initialize device memory address space */ + if (machine->ram_size < machine->maxram_size) { + ram_addr_t device_mem_size =3D machine->maxram_size - machine->ram= _size; + + if (QEMU_ALIGN_UP(machine->maxram_size, TARGET_PAGE_SIZE) !=3D + machine->maxram_size) { + error_report("maximum memory size must be aligned to multiple = of " + "%d bytes", TARGET_PAGE_SIZE); + exit(EXIT_FAILURE); + } + + machine->device_memory->base =3D machine->ram_size; + memory_region_init(&machine->device_memory->mr, OBJECT(ms), + "device-memory", device_mem_size); + memory_region_add_subregion(sysmem, machine->device_memory->base, + &machine->device_memory->mr); + + } + /* Initialize storage key device */ s390_skeys_init(); /* Initialize storage attributes device */ @@ -304,7 +328,7 @@ static void ccw_init(MachineState *machine) DeviceState *dev; =20 s390_sclp_init(); - s390_memory_init(machine->ram_size); + s390_memory_init(machine); =20 /* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus(machine); --=20 2.14.3 From nobody Wed Oct 29 11:38:24 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 1526045758123534.8619318420805; Fri, 11 May 2018 06:35:58 -0700 (PDT) Received: from localhost ([::1]:44983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH8DB-0001N4-Rr for importer@patchew.org; Fri, 11 May 2018 09:35:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fH7zV-0002Sh-2x for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fH7zT-0005Rt-PY for qemu-devel@nongnu.org; Fri, 11 May 2018 09:21:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53642 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 1fH7zT-0005RS-LB; Fri, 11 May 2018 09:21:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 448AB7D65F; Fri, 11 May 2018 13:21:43 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-7.ams2.redhat.com [10.36.117.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id B800C1002979; Fri, 11 May 2018 13:21:40 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 11 May 2018 15:19:53 +0200 Message-Id: <20180511131953.12905-18-david@redhat.com> In-Reply-To: <20180511131953.12905-1-david@redhat.com> References: <20180511131953.12905-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 11 May 2018 13:21:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 11 May 2018 13:21:43 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 v2 17/17] s390x: support memory devices 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" , Cornelia Huck , David Hildenbrand , Markus Armbruster , Alexander Graf , Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , Luiz Capitulino , 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 route all memory devices we can hotplug through the machine hotplug handler, just like on pc and spapr. Signed-off-by: David Hildenbrand --- default-configs/s390x-softmmu.mak | 1 + hw/s390x/s390-virtio-ccw.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-soft= mmu.mak index 2f4bfe73b4..6b017b65fc 100644 --- a/default-configs/s390x-softmmu.mak +++ b/default-configs/s390x-softmmu.mak @@ -9,3 +9,4 @@ CONFIG_S390_FLIC=3Dy CONFIG_S390_FLIC_KVM=3D$(CONFIG_KVM) CONFIG_VFIO_CCW=3D$(CONFIG_LINUX) CONFIG_WDT_DIAG288=3Dy +CONFIG_MEM_HOTPLUG=3Dy diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 09b755282b..91687ca327 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -35,6 +35,7 @@ #include "migration/register.h" #include "cpu_models.h" #include "hw/nmi.h" +#include "hw/mem/memory-device.h" =20 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr) { @@ -436,12 +437,29 @@ static void s390_machine_device_plug(HotplugHandler *= hotplug_dev, { Error *local_err =3D NULL; =20 + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_plug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev), NULL, + &local_err); + } + + if (local_err) { + error_propagate(errp, local_err); + return; + } + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { s390_cpu_plug(hotplug_dev, dev, &local_err); } else if (dev->parent_bus && dev->parent_bus->hotplug_handler) { hotplug_handler_plug(dev->parent_bus->hotplug_handler, dev, &local= _err); } + + if (local_err) { + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_unplug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev)); + } + } error_propagate(errp, local_err); } =20 @@ -468,6 +486,16 @@ static void s390_machine_device_unplug(HotplugHandler = *hotplug_dev, &local_err); } error_propagate(errp, local_err); + + if (local_err) { + error_propagate(errp, local_err); + return; + } + + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + memory_device_unplug(MACHINE(hotplug_dev), MEMORY_DEVICE(dev)); + } } =20 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms, @@ -509,6 +537,13 @@ static HotplugHandler *s390_get_hotplug_handler(Machin= eState *machine, if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { return HOTPLUG_HANDLER(machine); } + + if (dev->parent_bus) { + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + return HOTPLUG_HANDLER(machine); + } + } + return NULL; } =20 --=20 2.14.3