From patchwork Thu May 17 08:15:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkj81WJpz9s3X for ; Thu, 17 May 2018 18:18:52 +1000 (AEST) Received: from localhost ([::1]:41850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE7d-0004DE-Qf for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:18:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4V-0002RS-R8 for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4V-0002ox-0c for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50612 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 1fJE4U-0002on-Pb; Thu, 17 May 2018 04:15:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B42EF40201AF; Thu, 17 May 2018 08:15:33 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EE842166BAD; Thu, 17 May 2018 08:15:31 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:14 +0200 Message-Id: <20180517081527.14410-2-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 01/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The start of the address space does not have to be aligned for the search. Handle 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 = ms->device_memory->base; address_space_end = address_space_start + memory_region_size(&ms->device_memory->mr); - g_assert(QEMU_ALIGN_UP(address_space_start, align) == address_space_start); g_assert(address_space_end >= address_space_start); 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 = address_space_start; + new_addr = QEMU_ALIGN_UP(address_space_start, align); } /* find address range that will fit new memory device */ From patchwork Thu May 17 08:15:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkkP6QkDz9s3X for ; Thu, 17 May 2018 18:19:57 +1000 (AEST) Received: from localhost ([::1]:41855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE8h-00055E-Cf for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:19:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4Y-0002Sx-Nh for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4X-0002pt-Jz for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55596 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 1fJE4X-0002pe-Df; Thu, 17 May 2018 04:15:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1E1B859BA; Thu, 17 May 2018 08:15:36 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id F07EB215CDB7; Thu, 17 May 2018 08:15:33 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:15 +0200 Message-Id: <20180517081527.14410-3-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:36 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 02/14] memory-device: introduce separate config option 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Some architectures might support memory devices, while they don't support DIMM/NVDIMM. So let's - Rename CONFIG_MEM_HOTPLUG to CONFIG_MEM_DEVICE - Introduce CONFIG_DIMM and use it similarly to CONFIG NVDIMM CONFIG_DIMM and CONFIG_NVDIMM require CONFIG_MEM_DEVICE. Signed-off-by: David Hildenbrand Reviewed-by: Igor Mammedov --- default-configs/i386-softmmu.mak | 3 ++- default-configs/ppc64-softmmu.mak | 3 ++- default-configs/x86_64-softmmu.mak | 3 ++- hw/Makefile.objs | 2 +- hw/mem/Makefile.objs | 4 ++-- qapi/misc.json | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 8c7d4a0fa0..4c1637338b 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -50,7 +50,8 @@ CONFIG_PCI_Q35=y CONFIG_APIC=y CONFIG_IOAPIC=y CONFIG_PVPANIC=y -CONFIG_MEM_HOTPLUG=y +CONFIG_MEM_DEVICE=y +CONFIG_DIMM=y CONFIG_NVDIMM=y CONFIG_ACPI_NVDIMM=y CONFIG_PCIE_PORT=y diff --git a/default-configs/ppc64-softmmu.mak b/default-configs/ppc64-softmmu.mak index b94af6c7c6..f550573782 100644 --- a/default-configs/ppc64-softmmu.mak +++ b/default-configs/ppc64-softmmu.mak @@ -16,4 +16,5 @@ CONFIG_VIRTIO_VGA=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) -CONFIG_MEM_HOTPLUG=y +CONFIG_MEM_DEVICE=y +CONFIG_DIMM=y diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index 0390b4303c..7785351414 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -50,7 +50,8 @@ CONFIG_PCI_Q35=y CONFIG_APIC=y CONFIG_IOAPIC=y CONFIG_PVPANIC=y -CONFIG_MEM_HOTPLUG=y +CONFIG_MEM_DEVICE=y +CONFIG_DIMM=y CONFIG_NVDIMM=y CONFIG_ACPI_NVDIMM=y CONFIG_PCIE_PORT=y diff --git a/hw/Makefile.objs b/hw/Makefile.objs index 6a0ffe0afd..127a60eca4 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -33,7 +33,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += vfio/ devices-dirs-$(CONFIG_SOFTMMU) += virtio/ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ -devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/ +devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs index 10be4df2a2..3e2f7c5ca2 100644 --- a/hw/mem/Makefile.objs +++ b/hw/mem/Makefile.objs @@ -1,3 +1,3 @@ -common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o -common-obj-$(CONFIG_MEM_HOTPLUG) += memory-device.o +common-obj-$(CONFIG_DIMM) += pc-dimm.o +common-obj-$(CONFIG_MEM_DEVICE) += memory-device.o common-obj-$(CONFIG_NVDIMM) += nvdimm.o diff --git a/qapi/misc.json b/qapi/misc.json index f5988cc0b5..4e6265cd2e 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2060,7 +2060,7 @@ # # @plugged-memory: size of memory that can be hot-unplugged. This field # is omitted if target doesn't support memory hotplug -# (i.e. CONFIG_MEM_HOTPLUG not defined on build time). +# (i.e. CONFIG_MEM_DEVICE not defined at build time). # # Since: 2.11.0 ## From patchwork Thu May 17 08:15:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915181 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkmx01DFz9s3X for ; Thu, 17 May 2018 18:22:07 +1000 (AEST) Received: from localhost ([::1]:41925 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEAm-0007A5-TE for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:22:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4b-0002TE-O4 for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4a-0002rD-HL for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50690 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 1fJE4a-0002qx-9z; Thu, 17 May 2018 04:15:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACCFE40711C1; Thu, 17 May 2018 08:15:39 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A258215CDB7; Thu, 17 May 2018 08:15:37 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:16 +0200 Message-Id: <20180517081527.14410-4-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 17 May 2018 08:15:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 17 May 2018 08:15:39 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 03/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: David Gibson --- 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(DeviceState *dev) HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) { - HotplugHandler *hotplug_ctrl; + HotplugHandler *hotplug_ctrl = qdev_get_machine_hotplug_handler(dev); - if (dev->parent_bus && dev->parent_bus->hotplug_handler) { + if (hotplug_ctrl == NULL && dev->parent_bus) { hotplug_ctrl = dev->parent_bus->hotplug_handler; - } else { - hotplug_ctrl = 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 unless + * machine handler overrides it. + * + * Returns: pointer to object that implements TYPE_HOTPLUG_HANDLER interface + * 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, From patchwork Thu May 17 08:15:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkfZ6rjkz9s08 for ; Thu, 17 May 2018 18:16:38 +1000 (AEST) Received: from localhost ([::1]:41835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE5U-0002Yt-El for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:16:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49264) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4h-0002W7-3v for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4d-0002s7-4V for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50622 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 1fJE4c-0002rm-VD; Thu, 17 May 2018 04:15:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7728240201AF; Thu, 17 May 2018 08:15:42 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8C712166BAD; Thu, 17 May 2018 08:15:39 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:17 +0200 Message-Id: <20180517081527.14410-5-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:42 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 04/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 d768930d02..510076e156 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 = 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); } static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err = 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); } static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, @@ -2029,7 +2042,10 @@ static void pc_machine_device_unplug_request_cb(HotplugHandler *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, dev, + errp); + } else if (!dev->parent_bus) { error_setg(errp, "acpi: device unplug request for not supported device" " type: %s", object_get_typename(OBJECT(dev))); } @@ -2038,14 +2054,21 @@ static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev, static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err = 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 device" " type: %s", object_get_typename(OBJECT(dev))); } + error_propagate(errp, local_err); } static HotplugHandler *pc_get_hotpug_handler(MachineState *machine, From patchwork Thu May 17 08:15:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mknn2Vjdz9s3X for ; Thu, 17 May 2018 18:22:53 +1000 (AEST) Received: from localhost ([::1]:41933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEBX-0007kP-09 for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:22:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4g-0002W5-RK for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4g-0002tc-0S for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55610 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 1fJE4f-0002t3-R8; Thu, 17 May 2018 04:15:45 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4549719544E; Thu, 17 May 2018 08:15:45 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3EF0215CDB7; Thu, 17 May 2018 08:15:42 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:18 +0200 Message-Id: <20180517081527.14410-6-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:45 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 05/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Necessary to hotplug them cleanly later. We could drop the PC_DIMM check, as PC_DIMM are just memory devices, but this approach is cleaner. Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 510076e156..8bc41ef24b 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" /* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -2075,6 +2076,7 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState *machine, DeviceState *dev) { if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || + object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE) || object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { return HOTPLUG_HANDLER(machine); } From patchwork Thu May 17 08:15:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mks41tg8z9s3X for ; Thu, 17 May 2018 18:25:44 +1000 (AEST) Received: from localhost ([::1]:42063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEEH-0001ns-Vl for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:25:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4j-0002YJ-RO for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4i-0002uw-Qg for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:49 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50636 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 1fJE4i-0002uW-J4; Thu, 17 May 2018 04:15:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16E4C40201AF; Thu, 17 May 2018 08:15:48 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 818DC215CDB7; Thu, 17 May 2018 08:15:45 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:19 +0200 Message-Id: <20180517081527.14410-7-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:48 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 06/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Greg Kurz --- 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 ebf30dd60b..b7c5c95f7a 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3571,27 +3571,48 @@ static void spapr_machine_device_plug(HotplugHandler *hotplug_dev, { MachineState *ms = MACHINE(hotplug_dev); sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(ms); + Error *local_err = NULL; + /* final stage hotplug handler */ if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { int node; if (!smc->dr_lmb_enabled) { - error_setg(errp, "Memory hotplug not supported for this machine"); - return; + error_setg(&local_err, + "Memory hotplug not supported for this machine"); + goto out; } - node = object_property_get_uint(OBJECT(dev), PC_DIMM_NODE_PROP, errp); - if (*errp) { - return; + node = object_property_get_uint(OBJECT(dev), PC_DIMM_NODE_PROP, + &local_err); + if (local_err) { + goto out; } if (node < 0 || node >= MAX_NODES) { - error_setg(errp, "Invaild node %d", node); - return; + error_setg(&local_err, "Invaild node %d", node); + goto out; } - 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 = 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); } static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_dev, @@ -3618,17 +3639,27 @@ static void spapr_machine_device_unplug_request(HotplugHandler *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, dev, + errp); } } static void spapr_machine_device_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + Error *local_err = 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); } static HotplugHandler *spapr_get_hotplug_handler(MachineState *machine, @@ -3988,6 +4019,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) mc->get_default_cpu_node_id = spapr_get_default_cpu_node_id; mc->possible_cpu_arch_ids = spapr_possible_cpu_arch_ids; hc->unplug_request = spapr_machine_device_unplug_request; + hc->unplug = spapr_machine_device_unplug; smc->dr_lmb_enabled = true; mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0"); From patchwork Thu May 17 08:15:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkl403v2z9s3X for ; Thu, 17 May 2018 18:20:32 +1000 (AEST) Received: from localhost ([::1]:41862 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE9F-0005XK-J8 for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:20:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4p-0002dK-09 for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4l-0002wi-NZ for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54448 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 1fJE4l-0002wG-HO; Thu, 17 May 2018 04:15:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA5CA81FE16B; Thu, 17 May 2018 08:15:50 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5307F215CDB7; Thu, 17 May 2018 08:15:48 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:20 +0200 Message-Id: <20180517081527.14410-8-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 17 May 2018 08:15:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 17 May 2018 08:15:50 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 07/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Necessary to hotplug them cleanly later. Signed-off-by: David Hildenbrand --- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b7c5c95f7a..2f315f963b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3666,6 +3666,7 @@ static HotplugHandler *spapr_get_hotplug_handler(MachineState *machine, DeviceState *dev) { if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || + object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE) || object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) { return HOTPLUG_HANDLER(machine); } From patchwork Thu May 17 08:15:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkvT01v6z9s3X for ; Thu, 17 May 2018 18:27:48 +1000 (AEST) Received: from localhost ([::1]:42148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEGI-0003JA-Lh for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:27:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4p-0002dS-Av for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4o-0002xe-Cc for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55630 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 1fJE4o-0002xT-7B; Thu, 17 May 2018 04:15:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C559A859BA; Thu, 17 May 2018 08:15:53 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 414032166BAD; Thu, 17 May 2018 08:15:51 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:21 +0200 Message-Id: <20180517081527.14410-9-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:53 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 08/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 2f315f963b..286c38c842 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3291,7 +3291,8 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_state(sPAPRMachineState *ms, /* Callback to be called during DRC release. */ void spapr_lmb_release(DeviceState *dev) { - sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_hotplug_handler(dev)); + HotplugHandler *hotplug_ctrl = qdev_get_hotplug_handler(dev); + sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_ctrl); sPAPRDIMMState *ds = spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(dev)); /* This information will get lost if a migration occurs @@ -3309,9 +3310,21 @@ void spapr_lmb_release(DeviceState *dev) /* * Now that all the LMBs have been removed by the guest, call the - * pc-dimm unplug handler to cleanup up the pc-dimm device. + * unplug handler chain. This can never fail. */ - pc_dimm_memory_unplug(dev, MACHINE(spapr)); + hotplug_ctrl = 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 = SPAPR_MACHINE(hotplug_dev); + sPAPRDIMMState *ds = 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(HotplugHandler *hotplug_dev, Error *local_err = NULL; /* 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); } From patchwork Thu May 17 08:15:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkfq5YBbz9s08 for ; Thu, 17 May 2018 18:16:51 +1000 (AEST) Received: from localhost ([::1]:41836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE5h-0002jW-9a for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:16:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4s-0002ge-0m for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4r-0002z8-1t for qemu-devel@nongnu.org; Thu, 17 May 2018 04:15:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55636 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 1fJE4q-0002yq-UR; Thu, 17 May 2018 04:15:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90AA319544E; Thu, 17 May 2018 08:15:56 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E810215CDB7; Thu, 17 May 2018 08:15:53 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:22 +0200 Message-Id: <20180517081527.14410-10-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:15:56 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 09/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Let's handle it via hotplug_handler_unplug(). Signed-off-by: David Hildenbrand Acked-by: Igor Mammedov Acked-by: David Gibson --- 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 286c38c842..13d153b5a6 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 = MACHINE(qdev_get_hotplug_handler(dev)); + HotplugHandler *hotplug_ctrl = 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 *dev, + Error **errp) +{ + MachineState *ms = MACHINE(hotplug_dev); sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(ms); CPUCore *cc = CPU_CORE(dev); CPUArchId *core_slot = spapr_find_cpu_slot(ms, cc->core_id, NULL); @@ -3623,6 +3632,8 @@ static void spapr_machine_device_unplug(HotplugHandler *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); From patchwork Thu May 17 08:15:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkrv5r71z9s3X for ; Thu, 17 May 2018 18:25:35 +1000 (AEST) Received: from localhost ([::1]:42039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEE8-0001cu-IN for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:25:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4z-0002oW-PK for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4t-00030l-T9 for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50648 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 1fJE4t-00030V-Ov; Thu, 17 May 2018 04:15:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FABA40201AF; Thu, 17 May 2018 08:15:59 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE45A215CDB7; Thu, 17 May 2018 08:15:56 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:23 +0200 Message-Id: <20180517081527.14410-11-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:15:59 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 10/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; +/* + * MemoryDeviceClass functions should only be called on realized + * MemoryDevice instances. + */ typedef struct MemoryDeviceClass { InterfaceClass parent_class; + /* 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; MemoryDeviceInfoList *qmp_memory_device_list(void); From patchwork Thu May 17 08:15:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkvJ1Qxfz9s3X for ; Thu, 17 May 2018 18:27:39 +1000 (AEST) Received: from localhost ([::1]:42138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEG8-00038X-4G for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:27:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE4y-0002n7-5v for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4w-00031v-N0 for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:04 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55650 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 1fJE4w-00031f-I6; Thu, 17 May 2018 04:16:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F67619546D; Thu, 17 May 2018 08:16:02 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D552215CDC7; Thu, 17 May 2018 08:15:59 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:24 +0200 Message-Id: <20180517081527.14410-12-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:16:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 17 May 2018 08:16:02 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 11/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 MemoryDeviceState *md) return dimm->addr; } +static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr) +{ + PCDIMMDevice *dimm = PC_DIMM(md); + + dimm->addr = addr; +} + +static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md) +{ + const PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(md); + PCDIMMDevice *dimm = 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 *data) ddc->get_vmstate_memory_region = pc_dimm_get_vmstate_memory_region; mdc->get_addr = pc_dimm_md_get_addr; + mdc->set_addr = pc_dimm_md_set_addr; + mdc->get_memory_region = pc_dimm_md_get_memory_region; /* for a dimm plugged_size == region_size */ mdc->get_plugged_size = pc_dimm_md_get_region_size; mdc->get_region_size = pc_dimm_md_get_region_size; From patchwork Thu May 17 08:15:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915197 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40ml191J8Pz9s3X for ; Thu, 17 May 2018 18:32:43 +1000 (AEST) Received: from localhost ([::1]:42322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEL2-0006Yh-EE for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:32:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE53-0002sq-Tj for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE4z-000337-JJ for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50660 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 1fJE4z-00032r-DX; Thu, 17 May 2018 04:16:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0611240201AF; Thu, 17 May 2018 08:16:05 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CAD42166BAD; Thu, 17 May 2018 08:16:02 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:25 +0200 Message-Id: <20180517081527.14410-13-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:16:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 17 May 2018 08:16:05 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 12/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 8bc41ef24b..61f1537e14 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2010,6 +2010,16 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, { Error *local_err = NULL; + /* 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(HotplugHandler *hotplug_dev, hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev, &local_err); } +out: error_propagate(errp, local_err); } 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; } -static void memory_device_check_addable(MachineState *ms, uint64_t size, - Error **errp) -{ - uint64_t used_region_size = 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 left"); - 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 *hint, uint64_t align, uint64_t size, Error **errp) { uint64_t address_space_start, address_space_end; + uint64_t used_region_size = 0; GSList *list = NULL, *item; uint64_t new_addr = 0; - if (!ms->device_memory) { - error_setg(errp, "memory devices (e.g. for memory hotplug) are not " - "supported by the machine"); - return 0; - } - - if (!memory_region_size(&ms->device_memory->mr)) { - error_setg(errp, "memory devices (e.g. for memory hotplug) are not " - "enabled, please specify the maxmem option"); - return 0; - } address_space_start = ms->device_memory->base; address_space_end = address_space_start + memory_region_size(&ms->device_memory->mr); g_assert(address_space_end >= address_space_start); - 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; } @@ -242,6 +210,32 @@ uint64_t get_plugged_memory_size(void) return size; } +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 left"); + 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 13d153b5a6..562712def2 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3676,6 +3676,16 @@ static void spapr_machine_device_pre_plug(HotplugHandler *hotplug_dev, { Error *local_err = NULL; + /* 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(HotplugHandler *hotplug_dev, hotplug_handler_pre_plug(dev->parent_bus->hotplug_handler, dev, &local_err); } +out: error_propagate(errp, local_err); } 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 { 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 *hint, uint64_t align, uint64_t size, Error **errp); From patchwork Thu May 17 08:15:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915190 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mky34S7cz9s3x for ; Thu, 17 May 2018 18:30:03 +1000 (AEST) Received: from localhost ([::1]:42208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEIT-0004vo-8E for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:30:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE57-0002xF-AY for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE52-00034Y-B7 for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54462 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 1fJE52-00034K-5Z; Thu, 17 May 2018 04:16:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3C0B81FE145; Thu, 17 May 2018 08:16:07 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4262B215CDB7; Thu, 17 May 2018 08:16:05 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:26 +0200 Message-Id: <20180517081527.14410-14-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 17 May 2018 08:16:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 17 May 2018 08:16:07 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 13/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 61f1537e14..426fb534c2 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); } @@ -2080,7 +2086,16 @@ static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, error_setg(&local_err, "acpi: device unplug for not supported device" " 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)); + } } 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" static gint memory_device_addr_sort(gconstpointer a, gconstpointer b) { @@ -246,12 +247,21 @@ void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, addr - ms->device_memory->base, mr); } -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 = MEMORY_DEVICE_GET_CLASS(md); + MemoryRegion *mr = mdc->get_memory_region(md); + + /* we expect a previous call to memory_device_pre_plug */ g_assert(ms->device_memory); + 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); } static const TypeInfo memory_device_info = { 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 = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm); - MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort); - memory_device_unplug_region(machine, mr); vmstate_unregister_ram(vmstate_mr, dev); } 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 562712def2..abdd38a6b5 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); } @@ -3638,7 +3643,16 @@ static void spapr_machine_device_unplug(HotplugHandler *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)); + } } static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_dev, 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, const 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); #endif From patchwork Thu May 17 08:15:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 915189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40mkxT148mz9s3x for ; Thu, 17 May 2018 18:29:33 +1000 (AEST) Received: from localhost ([::1]:42189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJEHy-0004Wl-OJ for incoming@patchwork.ozlabs.org; Thu, 17 May 2018 04:29:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJE58-0002xI-1B for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJE56-000377-8I for qemu-devel@nongnu.org; Thu, 17 May 2018 04:16:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33478 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 1fJE55-00036G-V5; Thu, 17 May 2018 04:16:12 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 445EF401EF11; Thu, 17 May 2018 08:16:11 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-24.ams2.redhat.com [10.36.117.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id B29B0215CDA7; Thu, 17 May 2018 08:16:08 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 17 May 2018 10:15:27 +0200 Message-Id: <20180517081527.14410-15-david@redhat.com> In-Reply-To: <20180517081527.14410-1-david@redhat.com> References: <20180517081527.14410-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 17 May 2018 08:16:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 17 May 2018 08:16:11 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 14/14] 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 426fb534c2..f022eb042e 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 = NULL; PCMachineState *pcms = PC_MACHINE(hotplug_dev); - PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); - PCDIMMDevice *dimm = PC_DIMM(dev); - PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr; - uint64_t align = TARGET_PAGE_SIZE; bool is_nvdimm = object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); - mr = ddc->get_memory_region(dimm, &local_err); - if (local_err) { - goto out; - } - - if (memory_region_get_alignment(mr) && pcmc->enforce_aligned_dimm) { - align = 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; } - 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 = NULL; + /* first stage hotplug handler */ + if (object_dynamic_cast(OBJECT(dev), TYPE_MEMORY_DEVICE)) { + const PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(hotplug_dev); + uint64_t align = 0; + + /* compat handling: force to TARGET_PAGE_SIZE */ + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) && + !pcmc->enforce_aligned_dimm) { + align = 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, void *opaque) return 0; } -uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, - 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 = 0; @@ -237,11 +238,38 @@ void memory_device_pre_plug(MachineState *ms, const MemoryDeviceState *md, } } -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 = MEMORY_DEVICE_GET_CLASS(md); + const uint64_t size = mdc->get_region_size(md); + MemoryRegion *mr = mdc->get_memory_region(md); + uint64_t addr = 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 = *enforced_align; + } else { + align = memory_region_get_alignment(mr); + } + + /* our device might have stronger alignment requirements */ + if (mdc->get_align) { + align = MAX(align, mdc->get_align(md)); + } + + addr = memory_device_get_free_addr(ms, !addr ? NULL : &addr, align, + size, errp); + if (*errp) { + return; + } + trace_memory_device_assign_address(addr); + mdc->set_addr(md, addr); memory_region_add_subregion(&ms->device_memory->mr, addr - ms->device_memory->base, mr); 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; -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 = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm); Error *local_err = NULL; - MemoryRegion *mr; - uint64_t addr; - - mr = ddc->get_memory_region(dimm, &local_err); - if (local_err) { - goto out; - } - - addr = object_property_get_uint(OBJECT(dimm), - PC_DIMM_ADDR_PROP, &local_err); - if (local_err) { - goto out; - } - - addr = memory_device_get_free_addr(machine, !addr ? NULL : &addr, align, - 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); slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &local_err); if (local_err) { @@ -82,7 +56,6 @@ void pc_dimm_memory_plug(DeviceState *dev, MachineState *machine, } trace_mhp_pc_dimm_assigned_slot(slot); - memory_device_plug_region(machine, mr, addr); vmstate_register_ram(vmstate_mr, dev); 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 @@ # 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 abdd38a6b5..5a4dbbf31e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3144,16 +3144,15 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev, PCDIMMDevice *dimm = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); MemoryRegion *mr; - uint64_t align, size, addr; + uint64_t size, addr; mr = ddc->get_memory_region(dimm, &local_err); if (local_err) { goto out; } - align = memory_region_get_alignment(mr); size = memory_region_size(mr); - 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 = SPAPR_MACHINE_GET_CLASS(ms); Error *local_err = NULL; + /* 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 *hint, - 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); #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 { int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); -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