From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955089830325.75605526585025; Wed, 26 Sep 2018 02:44:49 -0700 (PDT) Received: from localhost ([::1]:57287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56N4-00034y-Sm for importer@patchew.org; Wed, 26 Sep 2018 05:44:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56L7-00017o-AQ for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56L6-0002x4-Hp for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56566) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56L6-0002wo-Bt; Wed, 26 Sep 2018 05:42:36 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C2CC3086266; Wed, 26 Sep 2018 09:42:35 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 279FE20154ED; Wed, 26 Sep 2018 09:42:31 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:41:56 +0200 Message-Id: <20180926094219.20322-2-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 26 Sep 2018 09:42:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 01/24] memory-device: fix alignment error message 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We're missing "x" after the leading 0. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 6de4f70bb4..0b52fe2c5e 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -120,7 +120,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, =20 /* address_space_start indicates the maximum alignment we expect */ if (QEMU_ALIGN_UP(address_space_start, align) !=3D address_space_start= ) { - error_setg(errp, "the alignment (0%" PRIx64 ") is not supported", + error_setg(errp, "the alignment (0x%" PRIx64 ") is not supported", align); return 0; } --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955086864505.76803954686375; Wed, 26 Sep 2018 02:44:46 -0700 (PDT) Received: from localhost ([::1]:57288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56N5-00037Z-83 for importer@patchew.org; Wed, 26 Sep 2018 05:44:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56LD-0001Bf-Dx for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56LA-0002zI-76 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40234) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56LA-0002yw-1I; Wed, 26 Sep 2018 05:42:40 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4CAAEBCD56; Wed, 26 Sep 2018 09:42:39 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBD3A2015AC7; Wed, 26 Sep 2018 09:42:35 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:41:57 +0200 Message-Id: <20180926094219.20322-3-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 26 Sep 2018 09:42:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 02/24] memory-device: fix error message when hinted address is too small 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The "at" should actually be a "before". if (new_addr < address_space_start) -> "can't add memory ... before... $address_space_start" So it looks similar to the other check } else if ((new_addr + size) > address_space_end) -> "can't add memory ... beyond..." Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Igor Mammedov Reviewed-by: David Gibson Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 0b52fe2c5e..7c706fadfc 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -146,7 +146,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, new_addr =3D *hint; if (new_addr < address_space_start) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 - "] at 0x%" PRIx64, new_addr, size, address_space_st= art); + "] before 0x%" PRIx64, new_addr, size, + address_space_start); return 0; } else if ((new_addr + size) > address_space_end) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955309728484.65898343986487; Wed, 26 Sep 2018 02:48:29 -0700 (PDT) Received: from localhost ([::1]:57310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Qm-000661-6h for importer@patchew.org; Wed, 26 Sep 2018 05:48:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56LF-0001De-7G for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56LE-00030h-0k for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56LD-000305-OU; Wed, 26 Sep 2018 05:42:43 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03570307D974; Wed, 26 Sep 2018 09:42:43 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 970C72010D97; Wed, 26 Sep 2018 09:42:39 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:41:58 +0200 Message-Id: <20180926094219.20322-4-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 26 Sep 2018 09:42:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 03/24] pc-dimm: pass PCDIMMDevice to pc_dimm_.*plug 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We're plugging/unplugging a PCDIMMDevice, so directly pass this type instead of a more generic DeviceState. Signed-off-by: David Hildenbrand Acked-by: David Gibson Reviewed-by: David Gibson Reviewed-by: Eric Auger Reviewed-by: Igor Mammedov --- hw/i386/pc.c | 6 +++--- hw/mem/pc-dimm.c | 16 +++++++--------- hw/ppc/spapr.c | 8 ++++---- include/hw/mem/pc-dimm.h | 6 +++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 03148450c8..86c16f9aaf 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1699,7 +1699,7 @@ static void pc_memory_pre_plug(HotplugHandler *hotplu= g_dev, DeviceState *dev, return; } =20 - pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), + pc_dimm_pre_plug(PC_DIMM(dev), MACHINE(hotplug_dev), pcmc->enforce_aligned_dimm ? NULL : &legacy_align, er= rp); } =20 @@ -1711,7 +1711,7 @@ static void pc_memory_plug(HotplugHandler *hotplug_de= v, PCMachineState *pcms =3D PC_MACHINE(hotplug_dev); bool is_nvdimm =3D object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); =20 - pc_dimm_plug(dev, MACHINE(pcms), &local_err); + pc_dimm_plug(PC_DIMM(dev), MACHINE(pcms), &local_err); if (local_err) { goto out; } @@ -1771,7 +1771,7 @@ static void pc_memory_unplug(HotplugHandler *hotplug_= dev, goto out; } =20 - pc_dimm_unplug(dev, MACHINE(pcms)); + pc_dimm_unplug(PC_DIMM(dev), MACHINE(pcms)); object_unparent(OBJECT(dev)); =20 out: diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index fb6bcaedc4..2375eb2731 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -29,11 +29,11 @@ =20 static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **e= rrp); =20 -void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, +void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine, const uint64_t *legacy_align, Error **errp) { - PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + DeviceState *dev =3D DEVICE(dimm); Error *local_err =3D NULL; MemoryRegion *mr; uint64_t addr, align; @@ -69,32 +69,30 @@ out: error_propagate(errp, local_err); } =20 -void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp) +void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp) { - 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_abort= ); MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); uint64_t addr; =20 - addr =3D object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, + addr =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, &error_abort); =20 memory_device_plug_region(machine, mr, addr); - vmstate_register_ram(vmstate_mr, dev); + vmstate_register_ram(vmstate_mr, DEVICE(dimm)); } =20 -void pc_dimm_unplug(DeviceState *dev, MachineState *machine) +void pc_dimm_unplug(PCDIMMDevice *dimm, 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, &error_abort= ); MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); =20 memory_device_unplug_region(machine, mr); - vmstate_unregister_ram(vmstate_mr, dev); + vmstate_unregister_ram(vmstate_mr, DEVICE(dimm)); } =20 static int pc_dimm_slot2bitmap(Object *obj, void *opaque) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 98868d893a..c078347b66 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3135,7 +3135,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, =20 size =3D memory_region_size(mr); =20 - pc_dimm_plug(dev, MACHINE(ms), &local_err); + pc_dimm_plug(dimm, MACHINE(ms), &local_err); if (local_err) { goto out; } @@ -3158,7 +3158,7 @@ static void spapr_memory_plug(HotplugHandler *hotplug= _dev, DeviceState *dev, return; =20 out_unplug: - pc_dimm_unplug(dev, MACHINE(ms)); + pc_dimm_unplug(dimm, MACHINE(ms)); out: error_propagate(errp, local_err); } @@ -3202,7 +3202,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, return; } =20 - pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), NULL, errp); + pc_dimm_pre_plug(dimm, MACHINE(hotplug_dev), NULL, errp); } =20 struct sPAPRDIMMState { @@ -3314,7 +3314,7 @@ static void spapr_memory_unplug(HotplugHandler *hotpl= ug_dev, DeviceState *dev) sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); sPAPRDIMMState *ds =3D spapr_pending_dimm_unplugs_find(spapr, PC_DIMM(= dev)); =20 - pc_dimm_unplug(dev, MACHINE(hotplug_dev)); + pc_dimm_unplug(PC_DIMM(dev), MACHINE(hotplug_dev)); object_unparent(OBJECT(dev)); spapr_pending_dimm_unplugs_remove(spapr, ds); } diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index b382eb4303..99cbd54de7 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -79,8 +79,8 @@ typedef struct PCDIMMDeviceClass { Error **errp); } PCDIMMDeviceClass; =20 -void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, +void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine, const uint64_t *legacy_align, Error **errp); -void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp); -void pc_dimm_unplug(DeviceState *dev, MachineState *machine); +void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp); +void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine); #endif --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955321351242.24042260992837; Wed, 26 Sep 2018 02:48:41 -0700 (PDT) Received: from localhost ([::1]:57311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Qy-0006dg-6r for importer@patchew.org; Wed, 26 Sep 2018 05:48:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56LO-0001Yd-0d for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56LK-00033Y-SC for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39594) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56LK-00033F-Kd; Wed, 26 Sep 2018 05:42:50 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCF4830E4EB3; Wed, 26 Sep 2018 09:42:49 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5088C2015C02; Wed, 26 Sep 2018 09:42:43 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:41:59 +0200 Message-Id: <20180926094219.20322-5-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 26 Sep 2018 09:42:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 04/24] memory-device: handle integer overflows properly 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Although unlikely in practice, we could have integer overflows on some calculations based on addresses and sizes, leading to error checks not triggering. Let's properly handle this whenever we do an addition. Make address_space_end point at the real end, instead of end + 1, so we don't have to handle special cases like it being 0. This will allow us to place a memory device at the very end of the guest physical 64bit address space (if ever possible). Also, QEMU_ALIGN_UP(md_addr + md_size, align) could (theoretically) wrap to address 0, so add a final check for 0. Reported-by: Dr. David Alan Gilbert Reviewed-by: David Gibson Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 7c706fadfc..8f0b9a9898 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -85,7 +85,8 @@ static void memory_device_check_addable(MachineState *ms,= uint64_t size, =20 /* 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) { + if (used_region_size + size < used_region_size || + 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); @@ -115,7 +116,7 @@ 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); + memory_region_size(&ms->device_memory->mr) - 1; g_assert(address_space_end >=3D address_space_start); =20 /* address_space_start indicates the maximum alignment we expect */ @@ -149,7 +150,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, "] before 0x%" PRIx64, new_addr, size, address_space_start); return 0; - } else if ((new_addr + size) > address_space_end) { + } else if (new_addr + size - 1 < new_addr || + new_addr + size - 1 > address_space_end) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 "] beyond 0x%" PRIx64, new_addr, size, address_space_end); @@ -182,7 +184,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, } } =20 - if (new_addr + size > address_space_end) { + if (new_addr + size - 1 < new_addr || !new_addr || + new_addr + size - 1 > address_space_end) { error_setg(errp, "could not find position in guest address space f= or " "memory device - memory fragmented due to alignments"); goto out; --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955529357838.6742332873392; Wed, 26 Sep 2018 02:52:09 -0700 (PDT) Received: from localhost ([::1]:57334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56UB-0000sa-T8 for importer@patchew.org; Wed, 26 Sep 2018 05:51:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56LR-0001fX-Ma for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56LQ-00038S-Sy for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:42:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53398) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56LQ-00035l-Nc; Wed, 26 Sep 2018 05:42:56 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3058307D97F; Wed, 26 Sep 2018 09:42:55 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36B7B2010D57; Wed, 26 Sep 2018 09:42:50 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:00 +0200 Message-Id: <20180926094219.20322-6-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 26 Sep 2018 09:42:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 05/24] memory-device: use memory device terminology in error messages 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" While we rephrased most error messages, we missed these. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Igor Mammedov Reviewed-by: David Gibson Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 8f0b9a9898..f7013d1456 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -88,7 +88,7 @@ static void memory_device_check_addable(MachineState *ms,= uint64_t size, if (used_region_size + size < used_region_size || 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, + " in use of total space for memory devices 0x" RAM_ADDR= _FMT, used_region_size, ms->maxram_size - ms->ram_size); return; } @@ -146,13 +146,13 @@ uint64_t memory_device_get_free_addr(MachineState *ms= , const uint64_t *hint, if (hint) { new_addr =3D *hint; if (new_addr < address_space_start) { - error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 + error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" = PRIx64 "] before 0x%" PRIx64, new_addr, size, address_space_start); return 0; } else if (new_addr + size - 1 < new_addr || new_addr + size - 1 > address_space_end) { - error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 + error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" = PRIx64 "] beyond 0x%" PRIx64, new_addr, size, address_space_end); return 0; --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955121381212.8266465434258; Wed, 26 Sep 2018 02:45:21 -0700 (PDT) Received: from localhost ([::1]:57290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Ng-0003cR-UL for importer@patchew.org; Wed, 26 Sep 2018 05:45:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56LZ-00023g-13 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56LU-0003BD-Ku for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56LU-0003AB-DH; Wed, 26 Sep 2018 05:43:00 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADFF981114; Wed, 26 Sep 2018 09:42:59 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D9952010D97; Wed, 26 Sep 2018 09:42:56 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:01 +0200 Message-Id: <20180926094219.20322-7-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 26 Sep 2018 09:42:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 06/24] 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Igor Mammedov Reviewed-by: David Gibson Acked-by: David Gibson Signed-off-by: David Hildenbrand --- default-configs/i386-softmmu.mak | 3 ++- default-configs/ppc64-softmmu.mak | 3 ++- hw/Makefile.objs | 2 +- hw/mem/Makefile.objs | 4 ++-- qapi/misc.json | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmm= u.mak index 8c7d4a0fa0..4c1637338b 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -50,7 +50,8 @@ CONFIG_PCI_Q35=3Dy CONFIG_APIC=3Dy CONFIG_IOAPIC=3Dy CONFIG_PVPANIC=3Dy -CONFIG_MEM_HOTPLUG=3Dy +CONFIG_MEM_DEVICE=3Dy +CONFIG_DIMM=3Dy CONFIG_NVDIMM=3Dy CONFIG_ACPI_NVDIMM=3Dy CONFIG_PCIE_PORT=3Dy diff --git a/default-configs/ppc64-softmmu.mak b/default-configs/ppc64-soft= mmu.mak index b94af6c7c6..f550573782 100644 --- a/default-configs/ppc64-softmmu.mak +++ b/default-configs/ppc64-softmmu.mak @@ -16,4 +16,5 @@ CONFIG_VIRTIO_VGA=3Dy CONFIG_XICS=3D$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=3D$(CONFIG_PSERIES) CONFIG_XICS_KVM=3D$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) -CONFIG_MEM_HOTPLUG=3Dy +CONFIG_MEM_DEVICE=3Dy +CONFIG_DIMM=3Dy diff --git a/hw/Makefile.objs b/hw/Makefile.objs index a19c1417ed..58872e27e0 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -33,7 +33,7 @@ devices-dirs-$(CONFIG_SOFTMMU) +=3D vfio/ devices-dirs-$(CONFIG_SOFTMMU) +=3D virtio/ devices-dirs-$(CONFIG_SOFTMMU) +=3D watchdog/ devices-dirs-$(CONFIG_SOFTMMU) +=3D xen/ -devices-dirs-$(CONFIG_MEM_HOTPLUG) +=3D mem/ +devices-dirs-$(CONFIG_MEM_DEVICE) +=3D mem/ devices-dirs-$(CONFIG_SOFTMMU) +=3D smbios/ devices-dirs-y +=3D core/ common-obj-y +=3D $(devices-dirs-y) diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs index 10be4df2a2..3e2f7c5ca2 100644 --- a/hw/mem/Makefile.objs +++ b/hw/mem/Makefile.objs @@ -1,3 +1,3 @@ -common-obj-$(CONFIG_MEM_HOTPLUG) +=3D pc-dimm.o -common-obj-$(CONFIG_MEM_HOTPLUG) +=3D memory-device.o +common-obj-$(CONFIG_DIMM) +=3D pc-dimm.o +common-obj-$(CONFIG_MEM_DEVICE) +=3D memory-device.o common-obj-$(CONFIG_NVDIMM) +=3D nvdimm.o diff --git a/qapi/misc.json b/qapi/misc.json index ada9af5add..e14efd70b0 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2066,7 +2066,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 ## --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955705707550.4625360229791; Wed, 26 Sep 2018 02:55:05 -0700 (PDT) Received: from localhost ([::1]:57349 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56XA-00046H-Fn for importer@patchew.org; Wed, 26 Sep 2018 05:55:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Lb-0002Ev-V6 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56La-0003D0-Gn for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56La-0003Cf-8r; Wed, 26 Sep 2018 05:43:06 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8388130832E6; Wed, 26 Sep 2018 09:43:05 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 099FE20154E7; Wed, 26 Sep 2018 09:42:59 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:02 +0200 Message-Id: <20180926094219.20322-8-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 26 Sep 2018 09:43:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 07/24] memory-device: forward errors in get_region_size()/get_plugged_size() 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's properly forward the errors, so errors from get_region_size() / get_plugged_size() can be handled. Users right now call both functions after the device has been realized, which is will never fail, so it is fine to continue using error_abort. While at it, remove a leftover error check (suggedted by Igor). Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand Reviewed-by: Eric Auger --- hw/mem/memory-device.c | 9 +++------ hw/mem/pc-dimm.c | 5 +++-- include/hw/mem/memory-device.h | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index f7013d1456..e935681438 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -60,7 +60,7 @@ static int memory_device_used_region_size(Object *obj, vo= id *opaque) const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(obj); =20 if (dev->realized) { - *size +=3D mdc->get_region_size(md); + *size +=3D mdc->get_region_size(md, &error_abort); } } =20 @@ -169,10 +169,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms,= const uint64_t *hint, uint64_t md_size, md_addr; =20 md_addr =3D mdc->get_addr(md); - md_size =3D mdc->get_region_size(md); - if (*errp) { - goto out; - } + md_size =3D mdc->get_region_size(md, &error_abort); =20 if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { @@ -236,7 +233,7 @@ static int memory_device_plugged_size(Object *obj, void= *opaque) const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(obj); =20 if (dev->realized) { - *size +=3D mdc->get_plugged_size(md); + *size +=3D mdc->get_plugged_size(md, &error_abort); } } =20 diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 2375eb2731..c948d57c63 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -234,14 +234,15 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDevic= eState *md) return dimm->addr; } =20 -static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md) +static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, + Error **errp) { /* dropping const here is fine as we don't touch the memory region */ PCDIMMDevice *dimm =3D PC_DIMM(md); const PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(md); MemoryRegion *mr; =20 - mr =3D ddc->get_memory_region(dimm, &error_abort); + mr =3D ddc->get_memory_region(dimm, errp); if (!mr) { return 0; } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 2853b084b5..f02b229837 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -33,8 +33,8 @@ typedef struct MemoryDeviceClass { InterfaceClass parent_class; =20 uint64_t (*get_addr)(const MemoryDeviceState *md); - uint64_t (*get_plugged_size)(const MemoryDeviceState *md); - uint64_t (*get_region_size)(const MemoryDeviceState *md); + uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp= ); + uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); } MemoryDeviceClass; --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955569047999.7507040795084; Wed, 26 Sep 2018 02:52:49 -0700 (PDT) Received: from localhost ([::1]:57337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Ux-0001Rk-RJ for importer@patchew.org; Wed, 26 Sep 2018 05:52:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44264) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Lo-0002XC-92 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Ll-0003G6-4W for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56994) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Lk-0003F6-B6; Wed, 26 Sep 2018 05:43:17 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74F9B85A04; Wed, 26 Sep 2018 09:43:12 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF35E2010DB2; Wed, 26 Sep 2018 09:43:05 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:03 +0200 Message-Id: <20180926094219.20322-9-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 26 Sep 2018 09:43:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 08/24] memory-device: document MemoryDeviceClass 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Document the functions and when to not expect errors. Reviewed-by: David Gibson Signed-off-by: David Hildenbrand Reviewed-by: Igor Mammedov --- include/hw/mem/memory-device.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index f02b229837..1d15cfc357 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -29,9 +29,25 @@ typedef struct MemoryDeviceState { Object parent_obj; } MemoryDeviceState; =20 +/** + * MemoryDeviceClass: + * @get_addr: The address of the @md in guest physical memory. "0" means t= hat + * no address has been specified by the user and that no address has been + * assigned yet. + * @get_plugged_size: The amount of memory provided by this @md currently + * usable ("plugged") by the guest. This is helpful for devices that + * dynamically manage the amount of memory accessible by the guest via + * the reserved memory region. For most devices, this corresponds to the + * size of the memory region. + * @get_region_size: The size of the memory region of the @md that's mapped + * in guest physical memory at @get_addr. + * @fill_device_info: Translate current @md state into #MemoryDeviceInfo. + */ typedef struct MemoryDeviceClass { + /* private */ InterfaceClass parent_class; =20 + /* public */ uint64_t (*get_addr)(const MemoryDeviceState *md); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp= ); uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955346123506.7787762777002; Wed, 26 Sep 2018 02:49:06 -0700 (PDT) Received: from localhost ([::1]:57312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56RM-0007Ck-Pa for importer@patchew.org; Wed, 26 Sep 2018 05:49:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Lr-0002aI-FS for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Lq-0003Hq-5S for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Lp-0003HO-27; Wed, 26 Sep 2018 05:43:22 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BF885F724; Wed, 26 Sep 2018 09:43:20 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC1612010D97; Wed, 26 Sep 2018 09:43:12 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:04 +0200 Message-Id: <20180926094219.20322-10-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 26 Sep 2018 09:43:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 09/24] memory-device: add and use memory_device_get_region_size() 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We will factor out get_memory_region() from pc-dimm to memory device code soon. Once that is done, get_region_size() can be implemented generically and essentially be replaced by memory_device_get_region_size (and work only on get_memory_region()). We have some users of get_memory_region() (spapr and pc-dimm code) that are only interested in the size. So let's rework them to use memory_device_get_region_size() first, then we can factor out get_memory_region() and eventually remove get_region_size() without touching the same code multiple times. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 13 ++++++++++--- hw/mem/pc-dimm.c | 10 ++++------ hw/ppc/spapr.c | 21 +++++++-------------- include/hw/mem/memory-device.h | 2 ++ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index e935681438..882364b388 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -57,10 +57,9 @@ static int memory_device_used_region_size(Object *obj, v= oid *opaque) if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) { const DeviceState *dev =3D DEVICE(obj); const MemoryDeviceState *md =3D MEMORY_DEVICE(obj); - const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(obj); =20 if (dev->realized) { - *size +=3D mdc->get_region_size(md, &error_abort); + *size +=3D memory_device_get_region_size(md, &error_abort); } } =20 @@ -169,7 +168,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, uint64_t md_size, md_addr; =20 md_addr =3D mdc->get_addr(md); - md_size =3D mdc->get_region_size(md, &error_abort); + md_size =3D memory_device_get_region_size(md, &error_abort); =20 if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { @@ -268,6 +267,14 @@ void memory_device_unplug_region(MachineState *ms, Mem= oryRegion *mr) memory_region_del_subregion(&ms->device_memory->mr, mr); } =20 +uint64_t memory_device_get_region_size(const MemoryDeviceState *md, + Error **errp) +{ + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + + return mdc->get_region_size(md, errp); +} + static const TypeInfo memory_device_info =3D { .name =3D TYPE_MEMORY_DEVICE, .parent =3D TYPE_INTERFACE, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index c948d57c63..76155c3f5a 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -161,16 +161,14 @@ static Property pc_dimm_properties[] =3D { static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + Error *local_err =3D NULL; uint64_t value; - MemoryRegion *mr; - PCDIMMDevice *dimm =3D PC_DIMM(obj); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(obj); =20 - mr =3D ddc->get_memory_region(dimm, errp); - if (!mr) { + value =3D memory_device_get_region_size(MEMORY_DEVICE(obj), &local_err= ); + if (local_err) { + error_propagate(errp, local_err); return; } - value =3D memory_region_size(mr); =20 visit_type_uint64(v, name, &value, errp); } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index c078347b66..c08130facb 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3128,12 +3128,10 @@ static void spapr_memory_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, Error *local_err =3D NULL; sPAPRMachineState *ms =3D SPAPR_MACHINE(hotplug_dev); PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); uint64_t size, addr; uint32_t node; =20 - size =3D memory_region_size(mr); + size =3D memory_device_get_region_size(MEMORY_DEVICE(dev), &error_abor= t); =20 pc_dimm_plug(dimm, MACHINE(ms), &local_err); if (local_err) { @@ -3169,9 +3167,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, const sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(hotplug_dev); sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); Error *local_err =3D NULL; - MemoryRegion *mr; uint64_t size; Object *memdev; hwaddr pagesize; @@ -3181,11 +3177,11 @@ static void spapr_memory_pre_plug(HotplugHandler *h= otplug_dev, DeviceState *dev, return; } =20 - mr =3D ddc->get_memory_region(dimm, errp); - if (!mr) { + size =3D memory_device_get_region_size(MEMORY_DEVICE(dimm), &local_err= ); + if (local_err) { + error_propagate(errp, local_err); return; } - size =3D memory_region_size(mr); =20 if (size % SPAPR_MEMORY_BLOCK_SIZE) { error_setg(errp, "Hotplugged memory size must be a multiple of " @@ -3257,9 +3253,8 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_sta= te(sPAPRMachineState *ms, PCDIMMDevice *dimm) { sPAPRDRConnector *drc; - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); - uint64_t size =3D memory_region_size(mr); + uint64_t size =3D memory_device_get_region_size(MEMORY_DEVICE(dimm), + &error_abort); uint32_t nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; uint32_t avail_lmbs =3D 0; uint64_t addr_start, addr; @@ -3325,14 +3320,12 @@ static void spapr_memory_unplug_request(HotplugHand= ler *hotplug_dev, sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); Error *local_err =3D NULL; PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); uint32_t nr_lmbs; uint64_t size, addr_start, addr; int i; sPAPRDRConnector *drc; =20 - size =3D memory_region_size(mr); + size =3D memory_device_get_region_size(MEMORY_DEVICE(dimm), &error_abo= rt); nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; =20 addr_start =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PRO= P, diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 1d15cfc357..2f04d67d68 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -63,5 +63,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, co= nst uint64_t *hint, void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); +uint64_t memory_device_get_region_size(const MemoryDeviceState *md, + Error **errp); =20 #endif --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955546922446.4979160936181; Wed, 26 Sep 2018 02:52:26 -0700 (PDT) Received: from localhost ([::1]:57336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Ub-0001BX-N8 for importer@patchew.org; Wed, 26 Sep 2018 05:52:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Lu-0002df-S2 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Lt-0003JV-Jh for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:43:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Ls-0003Is-Ps; Wed, 26 Sep 2018 05:43:25 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 136DC307D991; Wed, 26 Sep 2018 09:43:24 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94CA920154E7; Wed, 26 Sep 2018 09:43:20 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:05 +0200 Message-Id: <20180926094219.20322-11-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 26 Sep 2018 09:43:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 10/24] memory-device: factor out get_memory_region() from pc-dimm 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The memory region is necessary for plugging/unplugging a memory device. The region size (via get_region_size()) is no longer sufficient, as besides the alignment, also the region itself is required in order to add it to the device memory region of the machine via - memory_region_add_subregion - memory_region_del_subregion So, to factor out plugging/unplugging of memory devices from pc-dimm code, we have to factor out access to the memory region first. Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/mem/nvdimm.c | 9 ++++++--- hw/mem/pc-dimm.c | 27 ++++++++++++++++++--------- include/hw/mem/memory-device.h | 5 +++++ include/hw/mem/pc-dimm.h | 4 ---- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 1c6674c4ed..49324f3fae 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -27,6 +27,7 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "hw/mem/nvdimm.h" +#include "hw/mem/memory-device.h" =20 static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *nam= e, void *opaque, Error **errp) @@ -118,9 +119,10 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice = *nvdimm, Error **errp) nvdimm->nvdimm_mr->align =3D align; } =20 -static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **= errp) +static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md, + Error **errp) { - NVDIMMDevice *nvdimm =3D NVDIMM(dimm); + NVDIMMDevice *nvdimm =3D NVDIMM(md); Error *local_err =3D NULL; =20 if (!nvdimm->nvdimm_mr) { @@ -190,11 +192,12 @@ static Property nvdimm_properties[] =3D { static void nvdimm_class_init(ObjectClass *oc, void *data) { PCDIMMDeviceClass *ddc =3D PC_DIMM_CLASS(oc); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(oc); NVDIMMClass *nvc =3D NVDIMM_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); =20 ddc->realize =3D nvdimm_realize; - ddc->get_memory_region =3D nvdimm_get_memory_region; + mdc->get_memory_region =3D nvdimm_md_get_memory_region; dc->props =3D nvdimm_properties; =20 nvc->read_label_data =3D nvdimm_read_label_data; diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 76155c3f5a..477f8c8516 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -32,7 +32,7 @@ static int pc_dimm_get_free_slot(const int *hint, int max= _slots, Error **errp); void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine, const uint64_t *legacy_align, Error **errp) { - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); DeviceState *dev =3D DEVICE(dimm); Error *local_err =3D NULL; MemoryRegion *mr; @@ -49,7 +49,7 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *m= achine, object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_a= bort); trace_mhp_pc_dimm_assigned_slot(slot); =20 - mr =3D ddc->get_memory_region(dimm, &local_err); + mr =3D mdc->get_memory_region(MEMORY_DEVICE(dev), &local_err); if (local_err) { goto out; } @@ -72,9 +72,11 @@ out: void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp) { PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm, &error_abort= ); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); + MemoryRegion *mr =3D mdc->get_memory_region(MEMORY_DEVICE(dimm), + &error_abort); uint64_t addr; =20 addr =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, @@ -87,9 +89,11 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *mach= ine, Error **errp) void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine) { PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm, &error_abort= ); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); + MemoryRegion *mr =3D mdc->get_memory_region(MEMORY_DEVICE(dimm), + &error_abort); =20 memory_device_unplug_region(machine, mr); vmstate_unregister_ram(vmstate_mr, DEVICE(dimm)); @@ -235,12 +239,11 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDevic= eState *md) static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, Error **errp) { - /* dropping const here is fine as we don't touch the memory region */ - PCDIMMDevice *dimm =3D PC_DIMM(md); - const PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(md); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); MemoryRegion *mr; =20 - mr =3D ddc->get_memory_region(dimm, errp); + /* dropping const here is fine as we don't touch the memory region */ + mr =3D mdc->get_memory_region((MemoryDeviceState *)md, errp); if (!mr) { return 0; } @@ -248,6 +251,12 @@ static uint64_t pc_dimm_md_get_region_size(const Memor= yDeviceState *md, return memory_region_size(mr); } =20 +static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md, + Error **errp) +{ + return pc_dimm_get_memory_region(PC_DIMM(md), errp); +} + static void pc_dimm_md_fill_device_info(const MemoryDeviceState *md, MemoryDeviceInfo *info) { @@ -289,13 +298,13 @@ static void pc_dimm_class_init(ObjectClass *oc, void = *data) dc->props =3D pc_dimm_properties; dc->desc =3D "DIMM memory module"; =20 - ddc->get_memory_region =3D pc_dimm_get_memory_region; ddc->get_vmstate_memory_region =3D pc_dimm_get_memory_region; =20 mdc->get_addr =3D pc_dimm_md_get_addr; /* for a dimm plugged_size =3D=3D region_size */ mdc->get_plugged_size =3D pc_dimm_md_get_region_size; mdc->get_region_size =3D pc_dimm_md_get_region_size; + mdc->get_memory_region =3D pc_dimm_md_get_memory_region; mdc->fill_device_info =3D pc_dimm_md_fill_device_info; } =20 diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 2f04d67d68..6675c60cc3 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -41,6 +41,10 @@ typedef struct MemoryDeviceState { * size of the memory region. * @get_region_size: The size of the memory region of the @md that's mapped * in guest physical memory at @get_addr. + * @get_memory_region: The memory region of the @md that's mapped in guest + * physical memory at @get_addr. If a @md is ever composed of multiple + * successive memory regions, a covering memory region is to be used. + * Scattered memory regions are not supported for single devices. * @fill_device_info: Translate current @md state into #MemoryDeviceInfo. */ typedef struct MemoryDeviceClass { @@ -51,6 +55,7 @@ typedef struct MemoryDeviceClass { uint64_t (*get_addr)(const MemoryDeviceState *md); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp= ); uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); + MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp= ); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); } MemoryDeviceClass; diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 99cbd54de7..01436b9f50 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -61,9 +61,6 @@ typedef struct PCDIMMDevice { * PCDIMMDeviceClass: * @realize: called after common dimm is realized so that the dimm based * devices get the chance to do specified operations. - * @get_memory_region: returns #MemoryRegion associated with @dimm which - * is directly mapped into the physical address space of guest. Will not - * fail after the device was realized. * @get_vmstate_memory_region: returns #MemoryRegion which indicates the * memory of @dimm should be kept during live migration. Will not fail * after the device was realized. @@ -74,7 +71,6 @@ typedef struct PCDIMMDeviceClass { =20 /* public */ void (*realize)(PCDIMMDevice *dimm, Error **errp); - MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp); MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm, Error **errp); } PCDIMMDeviceClass; --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955912479919.4224751803802; Wed, 26 Sep 2018 02:58:32 -0700 (PDT) Received: from localhost ([::1]:57371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56aV-0007dq-C8 for importer@patchew.org; Wed, 26 Sep 2018 05:58:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Mf-0003F6-Bu for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Ma-0004xY-Ry for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7361) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56MZ-0004wx-3y; Wed, 26 Sep 2018 05:44:08 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 472C46E776; Wed, 26 Sep 2018 09:44:06 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B7792015C02; Wed, 26 Sep 2018 09:43:24 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:06 +0200 Message-Id: <20180926094219.20322-12-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 26 Sep 2018 09:44:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 11/24] memory-device: drop get_region_size() 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There are no remaining users of get_region_size() except memory_device_get_region_size() itself. We can make memory_device_get_region_size() work directly on get_memory_region() instead and drop get_region_size(). In addition, we can now use memory_device_get_region_size() in pc-dimm code to implement get_plugged_size()" Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 11 +++++++++-- hw/mem/pc-dimm.c | 18 +----------------- include/hw/mem/memory-device.h | 3 --- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 882364b388..9beaad1dba 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -270,9 +270,16 @@ void memory_device_unplug_region(MachineState *ms, Mem= oryRegion *mr) uint64_t memory_device_get_region_size(const MemoryDeviceState *md, Error **errp) { - MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + MemoryRegion *mr; =20 - return mdc->get_region_size(md, errp); + /* dropping const here is fine as we don't touch the memory region */ + mr =3D mdc->get_memory_region((MemoryDeviceState *)md, errp); + if (!mr) { + return 0; + } + + return memory_region_size(mr); } =20 static const TypeInfo memory_device_info =3D { diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 477f8c8516..4bd8c496bb 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -236,21 +236,6 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDevice= State *md) return dimm->addr; } =20 -static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, - Error **errp) -{ - MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); - MemoryRegion *mr; - - /* dropping const here is fine as we don't touch the memory region */ - mr =3D mdc->get_memory_region((MemoryDeviceState *)md, errp); - if (!mr) { - return 0; - } - - return memory_region_size(mr); -} - static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md, Error **errp) { @@ -302,8 +287,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *d= ata) =20 mdc->get_addr =3D pc_dimm_md_get_addr; /* for a dimm plugged_size =3D=3D region_size */ - mdc->get_plugged_size =3D pc_dimm_md_get_region_size; - mdc->get_region_size =3D pc_dimm_md_get_region_size; + mdc->get_plugged_size =3D memory_device_get_region_size; mdc->get_memory_region =3D pc_dimm_md_get_memory_region; mdc->fill_device_info =3D pc_dimm_md_fill_device_info; } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 6675c60cc3..642797655f 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -39,8 +39,6 @@ typedef struct MemoryDeviceState { * dynamically manage the amount of memory accessible by the guest via * the reserved memory region. For most devices, this corresponds to the * size of the memory region. - * @get_region_size: The size of the memory region of the @md that's mapped - * in guest physical memory at @get_addr. * @get_memory_region: The memory region of the @md that's mapped in guest * physical memory at @get_addr. If a @md is ever composed of multiple * successive memory regions, a covering memory region is to be used. @@ -54,7 +52,6 @@ typedef struct MemoryDeviceClass { /* public */ uint64_t (*get_addr)(const MemoryDeviceState *md); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp= ); - uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp= ); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956074472910.6636826085462; Wed, 26 Sep 2018 03:01:14 -0700 (PDT) Received: from localhost ([::1]:57393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56d7-0001D9-EL for importer@patchew.org; Wed, 26 Sep 2018 06:01:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Mi-0003HY-5n for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Mg-000546-VP for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32884) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Mg-0004yM-LF; Wed, 26 Sep 2018 05:44:14 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 015A37FDCF; Wed, 26 Sep 2018 09:44:10 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B0692015AD3; Wed, 26 Sep 2018 09:44:06 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:07 +0200 Message-Id: <20180926094219.20322-13-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 26 Sep 2018 09:44:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 12/24] memory-device: add device class function set_addr() 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To be able to factor out address asignment of memory devices, we will have to read (get_addr()) and write (set_addr()) the address. We can't use properties for this purpose, as properties are device specific. E.g. while the address property for a DIMM is called "addr", it might be called differently (e.g. "memaddr") for other devices. Especially virtio based memory devices cannot use "addr" as that is already reserved and used for the address on the bus (for the proxy device). Also, it might be possible to have memory devices without address properties (e.g. internal DIMM-like thingies). In contrast to get_addr(), we expect that set_addr() can fail. Keep it simple for now for pc-dimm and simply set the static property, that will fail once realized. Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/mem/pc-dimm.c | 7 +++++++ include/hw/mem/memory-device.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 4bd8c496bb..5873172175 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -236,6 +236,12 @@ 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, + Error **errp) +{ + object_property_set_uint(OBJECT(md), addr, PC_DIMM_ADDR_PROP, errp); +} + static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md, Error **errp) { @@ -286,6 +292,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *d= ata) ddc->get_vmstate_memory_region =3D pc_dimm_get_memory_region; =20 mdc->get_addr =3D pc_dimm_md_get_addr; + mdc->set_addr =3D pc_dimm_md_set_addr; /* for a dimm plugged_size =3D=3D region_size */ mdc->get_plugged_size =3D memory_device_get_region_size; mdc->get_memory_region =3D pc_dimm_md_get_memory_region; diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 642797655f..6395942b27 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -34,6 +34,7 @@ typedef struct MemoryDeviceState { * @get_addr: The address of the @md in guest physical memory. "0" means t= hat * no address has been specified by the user and that no address has been * assigned yet. + * @set_addr: Set the address of the @md in guest physical memory. * @get_plugged_size: The amount of memory provided by this @md currently * usable ("plugged") by the guest. This is helpful for devices that * dynamically manage the amount of memory accessible by the guest via @@ -51,6 +52,7 @@ typedef struct MemoryDeviceClass { =20 /* public */ uint64_t (*get_addr)(const MemoryDeviceState *md); + void (*set_addr)(MemoryDeviceState *md, uint64_t addr, Error **errp); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp= ); MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp= ); void (*fill_device_info)(const MemoryDeviceState *md, --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956274012242.73658208907636; Wed, 26 Sep 2018 03:04:34 -0700 (PDT) Received: from localhost ([::1]:57412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56gK-0004L3-3p for importer@patchew.org; Wed, 26 Sep 2018 06:04:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Mi-0003Ht-GG for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Mh-00054H-83 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38778) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Mg-00052C-Vj; Wed, 26 Sep 2018 05:44:15 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7739316BCA6; Wed, 26 Sep 2018 09:44:13 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 501B82010D57; Wed, 26 Sep 2018 09:44:10 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:08 +0200 Message-Id: <20180926094219.20322-14-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 26 Sep 2018 09:44:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 13/24] memory-device: complete factoring out pre_plug handling 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With all required memory device class functions in place, we can factor out pre_plug handling of memory devices. Take proper care of errors. We still have to carry along legacy_align required for pc compatibility handling. We will factor out tracing of the address separately in a follow-up patch. Reviewed-by: David Gibson Signed-off-by: David Hildenbrand Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 32 +++++++++++++++++++++++++++++--- hw/mem/pc-dimm.c | 15 +++------------ include/hw/mem/memory-device.h | 5 ++--- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 9beaad1dba..54e3f23b15 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -94,9 +94,10 @@ static void memory_device_check_addable(MachineState *ms= , uint64_t size, =20 } =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; GSList *list =3D NULL, *item; @@ -249,6 +250,31 @@ uint64_t get_plugged_memory_size(void) return size; } =20 +void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, + const uint64_t *legacy_align, Error **errp) +{ + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + Error *local_err =3D NULL; + uint64_t addr, align; + MemoryRegion *mr; + + mr =3D mdc->get_memory_region(md, &local_err); + if (local_err) { + goto out; + } + + align =3D legacy_align ? *legacy_align : memory_region_get_alignment(m= r); + addr =3D mdc->get_addr(md); + addr =3D memory_device_get_free_addr(ms, !addr ? NULL : &addr, align, + memory_region_size(mr), &local_err); + if (local_err) { + goto out; + } + mdc->set_addr(md, addr, &local_err); +out: + error_propagate(errp, local_err); +} + void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr) { diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 5873172175..ea9968e379 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -32,11 +32,9 @@ static int pc_dimm_get_free_slot(const int *hint, int ma= x_slots, Error **errp); void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine, const uint64_t *legacy_align, Error **errp) { - MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); DeviceState *dev =3D DEVICE(dimm); Error *local_err =3D NULL; - MemoryRegion *mr; - uint64_t addr, align; + uint64_t addr; int slot; =20 slot =3D object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, @@ -49,22 +47,15 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState = *machine, object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_a= bort); trace_mhp_pc_dimm_assigned_slot(slot); =20 - mr =3D mdc->get_memory_region(MEMORY_DEVICE(dev), &local_err); + memory_device_pre_plug(MEMORY_DEVICE(dev), machine, legacy_align, + &local_err); if (local_err) { goto out; } =20 - align =3D legacy_align ? *legacy_align : memory_region_get_alignment(m= r); addr =3D object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, &error_abort); - addr =3D memory_device_get_free_addr(machine, !addr ? NULL : &addr, al= ign, - memory_region_size(mr), &local_err); - if (local_err) { - goto out; - } trace_mhp_pc_dimm_assigned_address(addr); - object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, - &error_abort); out: error_propagate(errp, local_err); } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 6395942b27..df48b85285 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -61,9 +61,8 @@ typedef struct MemoryDeviceClass { =20 MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); -uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hin= t, - uint64_t align, uint64_t size, - Error **errp); +void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, + const uint64_t *legacy_align, Error **errp); void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955533792755.6852398870426; Wed, 26 Sep 2018 02:52:13 -0700 (PDT) Received: from localhost ([::1]:57335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56UG-0000wX-2w for importer@patchew.org; Wed, 26 Sep 2018 05:52:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Mn-0003MX-KL for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Mk-00056H-Hc for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38826) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Mk-00055r-9c; Wed, 26 Sep 2018 05:44:18 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F5DE30001DF; Wed, 26 Sep 2018 09:44:17 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B6DB2010D97; Wed, 26 Sep 2018 09:44:13 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:09 +0200 Message-Id: <20180926094219.20322-15-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 26 Sep 2018 09:44:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 14/24] memory-device: complete factoring out plug handling 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With the new memory device functions in place, we can factor out plugging of memory devices completely. Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 13 ++++++++++--- hw/mem/pc-dimm.c | 9 +-------- include/hw/mem/memory-device.h | 3 +-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 54e3f23b15..3914e2fe6f 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -275,10 +275,17 @@ out: error_propagate(errp, local_err); } =20 -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, - uint64_t addr) +void memory_device_plug(MemoryDeviceState *md, MachineState *ms) { - /* we expect a previous call to memory_device_get_free_addr() */ + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + const uint64_t addr =3D mdc->get_addr(md); + MemoryRegion *mr; + + /* + * We expect a previous call to memory_device_pre_plug() succeeded so + * it and can't fail at this point. + */ + mr =3D mdc->get_memory_region(md, &error_abort); g_assert(ms->device_memory); =20 memory_region_add_subregion(&ms->device_memory->mr, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index ea9968e379..07fa29a748 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -63,17 +63,10 @@ out: void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp) { PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm, &error_abort= ); - MemoryRegion *mr =3D mdc->get_memory_region(MEMORY_DEVICE(dimm), - &error_abort); - uint64_t addr; - - addr =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, - &error_abort); =20 - memory_device_plug_region(machine, mr, addr); + memory_device_plug(MEMORY_DEVICE(dimm), machine); vmstate_register_ram(vmstate_mr, DEVICE(dimm)); } =20 diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index df48b85285..8b58529843 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -63,8 +63,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, const uint64_t *legacy_align, Error **errp); -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, - uint64_t addr); +void memory_device_plug(MemoryDeviceState *md, MachineState *ms); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); uint64_t memory_device_get_region_size(const MemoryDeviceState *md, Error **errp); --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955711441507.2436009283366; Wed, 26 Sep 2018 02:55:11 -0700 (PDT) Received: from localhost ([::1]:57350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56XG-00049J-7f for importer@patchew.org; Wed, 26 Sep 2018 05:55:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Mp-0003O5-3y for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Mo-00057y-A9 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50007) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Mo-00057N-1z; Wed, 26 Sep 2018 05:44:22 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3855E30A76B9; Wed, 26 Sep 2018 09:44:21 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB1A32010D57; Wed, 26 Sep 2018 09:44:17 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:10 +0200 Message-Id: <20180926094219.20322-16-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 26 Sep 2018 09:44:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 15/24] memory-device: complete factoring out unplug handling 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With the new memory device functions in place, we can factor out unplugging of memory devices completely. Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 11 +++++++++-- hw/mem/pc-dimm.c | 5 +---- include/hw/mem/memory-device.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 3914e2fe6f..e8e282bf5e 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -292,9 +292,16 @@ void memory_device_plug(MemoryDeviceState *md, Machine= State *ms) addr - ms->device_memory->base, mr); } =20 -void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) +void memory_device_unplug(MemoryDeviceState *md, MachineState *ms) { - /* we expect a previous call to memory_device_get_free_addr() */ + const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + MemoryRegion *mr; + + /* + * We expect a previous call to memory_device_pre_plug() succeeded so + * it and can't fail at this point. + */ + mr =3D mdc->get_memory_region(md, &error_abort); g_assert(ms->device_memory); =20 memory_region_del_subregion(&ms->device_memory->mr, mr); diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 07fa29a748..5a9a3d831d 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -73,13 +73,10 @@ void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *mac= hine, Error **errp) void pc_dimm_unplug(PCDIMMDevice *dimm, MachineState *machine) { PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm, &error_abort= ); - MemoryRegion *mr =3D mdc->get_memory_region(MEMORY_DEVICE(dimm), - &error_abort); =20 - memory_device_unplug_region(machine, mr); + memory_device_unplug(MEMORY_DEVICE(dimm), machine); vmstate_unregister_ram(vmstate_mr, DEVICE(dimm)); } =20 diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 8b58529843..97de693bca 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -64,7 +64,7 @@ uint64_t get_plugged_memory_size(void); void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, const uint64_t *legacy_align, Error **errp); void memory_device_plug(MemoryDeviceState *md, MachineState *ms); -void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); +void memory_device_unplug(MemoryDeviceState *md, MachineState *ms); uint64_t memory_device_get_region_size(const MemoryDeviceState *md, Error **errp); =20 --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955894464614.1027751139255; Wed, 26 Sep 2018 02:58:14 -0700 (PDT) Received: from localhost ([::1]:57370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56aA-0007HS-4F for importer@patchew.org; Wed, 26 Sep 2018 05:58:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Ms-0003Sb-Qe for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Mr-00059z-UY for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Mr-00059e-Ms; Wed, 26 Sep 2018 05:44:25 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA8A530DF6EF; Wed, 26 Sep 2018 09:44:24 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82A7D2010D97; Wed, 26 Sep 2018 09:44:21 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:11 +0200 Message-Id: <20180926094219.20322-17-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 26 Sep 2018 09:44:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 16/24] memory-device: trace when pre_assigning/assigning/unassigning addresses 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's trace the address when pre_pluggin/plugging/unplugging a memory devic= e. Trace it when pre_plugging as well as when plugging, so we really know when a specific address is actually used. Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 6 ++++++ hw/mem/pc-dimm.c | 8 -------- hw/mem/trace-events | 5 ++++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index e8e282bf5e..cf85199a72 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) { @@ -271,6 +272,9 @@ void memory_device_pre_plug(MemoryDeviceState *md, Mach= ineState *ms, goto out; } mdc->set_addr(md, addr, &local_err); + if (!local_err) { + trace_memory_device_pre_assign_address(addr); + } out: error_propagate(errp, local_err); } @@ -290,6 +294,7 @@ void memory_device_plug(MemoryDeviceState *md, MachineS= tate *ms) =20 memory_region_add_subregion(&ms->device_memory->mr, addr - ms->device_memory->base, mr); + trace_memory_device_assign_address(addr); } =20 void memory_device_unplug(MemoryDeviceState *md, MachineState *ms) @@ -305,6 +310,7 @@ void memory_device_unplug(MemoryDeviceState *md, Machin= eState *ms) g_assert(ms->device_memory); =20 memory_region_del_subregion(&ms->device_memory->mr, mr); + trace_memory_device_unassign_address(mdc->get_addr(md)); } =20 uint64_t memory_device_get_region_size(const MemoryDeviceState *md, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 5a9a3d831d..9c0c487cb6 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -34,7 +34,6 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *m= achine, { DeviceState *dev =3D DEVICE(dimm); Error *local_err =3D NULL; - uint64_t addr; int slot; =20 slot =3D object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, @@ -49,13 +48,6 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *= machine, =20 memory_device_pre_plug(MEMORY_DEVICE(dev), machine, legacy_align, &local_err); - if (local_err) { - goto out; - } - - addr =3D object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, - &error_abort); - trace_mhp_pc_dimm_assigned_address(addr); out: error_propagate(errp, local_err); } diff --git a/hw/mem/trace-events b/hw/mem/trace-events index e150dcc497..b40482077e 100644 --- a/hw/mem/trace-events +++ b/hw/mem/trace-events @@ -2,4 +2,7 @@ =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_pre_assign_address(uint64_t addr) "0x%"PRIx64 +memory_device_assign_address(uint64_t addr) "0x%"PRIx64 +memory_device_unassign_address(uint64_t addr) "0x%"PRIx64 --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956049644625.2687029889042; Wed, 26 Sep 2018 03:00:49 -0700 (PDT) Received: from localhost ([::1]:57392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56ci-00012S-D2 for importer@patchew.org; Wed, 26 Sep 2018 06:00:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Mx-0003Wi-5q for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Mv-0005BW-St for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57096) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Mv-0005BG-KQ; Wed, 26 Sep 2018 05:44:29 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0BCC30833B0; Wed, 26 Sep 2018 09:44:28 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 412032010D97; Wed, 26 Sep 2018 09:44:25 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:12 +0200 Message-Id: <20180926094219.20322-18-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 26 Sep 2018 09:44:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 17/24] memory-device: add class function get_device_id() 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When reporting the id of virtio-based memory devices, we always have to take the one of the proxy device (parent), not the one of the memory device directly. Let's generalize this by allowing memory devices to specify an optional "get_device_id" function. This id can then be used to report errors to the user from memory-device.c code, without having to special case e.g. virtio devices. Provide a default function that can be overridden. While at it, properly treat id =3D=3D NULL and report "(unnamed)" instead. Details: When the user creates a virtio device (e.g. virtio-balloon-pci), two devices are actually created. 1. Virtio proxy device (e.g. TYPE_VIRTIO_BALLOON_PCI) 2. The "real" virtio device (e.g. TYPE_VIRTIO_BALLOON). 1. aliases all properties of 2, so 2. can be properly configured using 1. 1. gets the device ID set specified by the user. 2. gets no ID set. If we want to make 2. a MemoryDevice but report errors/information to the user, we always have to report the id of 1. (because that's the device the user instantiated and configured). Reviewed-by: David Gibson Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 19 +++++++++++++++++-- include/hw/mem/memory-device.h | 5 +++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index cf85199a72..6dc40e8764 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -174,8 +174,10 @@ static uint64_t memory_device_get_free_addr(MachineSta= te *ms, =20 if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { - const DeviceState *d =3D DEVICE(md); - error_setg(errp, "address range conflicts with '%s'", d->i= d); + const char *id =3D mdc->get_device_id(md); + + error_setg(errp, "address range conflicts with '%s'", + id ? id : "(unnamed)"); goto out; } new_addr =3D QEMU_ALIGN_UP(md_addr + md_size, align); @@ -328,10 +330,23 @@ uint64_t memory_device_get_region_size(const MemoryDe= viceState *md, return memory_region_size(mr); } =20 +static const char *memory_device_get_device_id(const MemoryDeviceState *md) +{ + return DEVICE(md)->id; +} + +static void memory_device_class_init(ObjectClass *oc, void *data) +{ + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(oc); + + mdc->get_device_id =3D memory_device_get_device_id; +} + static const TypeInfo memory_device_info =3D { .name =3D TYPE_MEMORY_DEVICE, .parent =3D TYPE_INTERFACE, .class_size =3D sizeof(MemoryDeviceClass), + .class_init =3D memory_device_class_init, }; =20 static void memory_device_register_types(void) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 97de693bca..52fc117ce2 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -45,6 +45,10 @@ typedef struct MemoryDeviceState { * successive memory regions, a covering memory region is to be used. * Scattered memory regions are not supported for single devices. * @fill_device_info: Translate current @md state into #MemoryDeviceInfo. + * @get_device_id: Allows memory devices behind proxy devices + * (e.g. virtio based) to report the id of the proxy device to the user + * instead of the (empty) id of the memory device. The default + * implementation (unless overridden) will return the ordinary device id. */ typedef struct MemoryDeviceClass { /* private */ @@ -57,6 +61,7 @@ typedef struct MemoryDeviceClass { MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp= ); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); + const char *(*get_device_id)(const MemoryDeviceState *md); } MemoryDeviceClass; =20 MemoryDeviceInfoList *qmp_memory_device_list(void); --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956482232283.0998243798033; Wed, 26 Sep 2018 03:08:02 -0700 (PDT) Received: from localhost ([::1]:57434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56jg-00071q-Tu for importer@patchew.org; Wed, 26 Sep 2018 06:08:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56N1-0003Zx-89 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56Mz-0005DO-J0 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56Mz-0005D5-Ar; Wed, 26 Sep 2018 05:44:33 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B95F30001DA; Wed, 26 Sep 2018 09:44:32 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BAC72010D97; Wed, 26 Sep 2018 09:44:29 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:13 +0200 Message-Id: <20180926094219.20322-19-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 26 Sep 2018 09:44:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 18/24] qdev: hotplug: provide do_unplug 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The unplug and unplug_request handlers are special: They are not executed when unrealizing a device, but rather trigger the removal of a device from device_del() via object_unparent() - to effectively unrealize a device. If such a device has a child bus and another device attached to that bus (e.g. how virtio devices are created with their proxy device), we will not get a call to the unplug handler. As we want to support hotplug handlers (and especially also some unplug logic to undo resource assignment) for such devices, we cannot simply call the unplug handler when unrealizing - it has a different semantic ("trigger removal"). To handle this scenario, we need a do_unplug handler, that will be executed for all devices with a hotplug handler. While at it, introduce hotplug_fn_nofail and fix a spelling mistake in a comment. Signed-off-by: David Hildenbrand --- hw/core/hotplug.c | 10 ++++++++++ hw/core/qdev.c | 6 ++++++ include/hw/hotplug.h | 26 ++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/hw/core/hotplug.c b/hw/core/hotplug.c index 2253072d0e..e7a68d5160 100644 --- a/hw/core/hotplug.c +++ b/hw/core/hotplug.c @@ -45,6 +45,16 @@ void hotplug_handler_post_plug(HotplugHandler *plug_hand= ler, } } =20 +void hotplug_handler_do_unplug(HotplugHandler *plug_handler, + DeviceState *plugged_dev) +{ + HotplugHandlerClass *hdc =3D HOTPLUG_HANDLER_GET_CLASS(plug_handler); + + if (hdc->do_unplug) { + hdc->do_unplug(plug_handler, plugged_dev); + } +} + void hotplug_handler_unplug_request(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 36b788a66b..dde2726099 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -873,6 +873,12 @@ static void device_set_realized(Object *obj, bool valu= e, Error **errp) } } else if (!value && dev->realized) { Error **local_errp =3D NULL; + + hotplug_ctrl =3D qdev_get_hotplug_handler(dev); + if (hotplug_ctrl) { + hotplug_handler_do_unplug(hotplug_ctrl, dev); + } + QLIST_FOREACH(bus, &dev->child_bus, sibling) { local_errp =3D local_err ? NULL : &local_err; object_property_set_bool(OBJECT(bus), false, "realized", diff --git a/include/hw/hotplug.h b/include/hw/hotplug.h index 51541d63e1..2fa5833cf1 100644 --- a/include/hw/hotplug.h +++ b/include/hw/hotplug.h @@ -31,13 +31,21 @@ typedef struct HotplugHandler { =20 /** * hotplug_fn: - * @plug_handler: a device performing plug/uplug action + * @plug_handler: a device performing (un)plug action * @plugged_dev: a device that has been (un)plugged * @errp: returns an error if this function fails */ typedef void (*hotplug_fn)(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp); =20 +/** + * hotplug_fn_nofail: + * @plug_handler: a device performing un(plug) action + * @plugged_dev: a device that has been (un)plugged + */ +typedef void (*hotplug_fn_nofail)(HotplugHandler *plug_handler, + DeviceState *plugged_dev); + /** * HotplugDeviceClass: * @@ -49,12 +57,17 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler, * @plug: plug callback called at end of device.realize(true). * @post_plug: post plug callback called after device.realize(true) and de= vice * reset + * @do_unplug: unplug callback called at start of device.realize(false) * @unplug_request: unplug request callback. * Used as a means to initiate device unplug for devices = that * require asynchronous unplug handling. * @unplug: unplug callback. * Used for device removal with devices that implement * asynchronous and synchronous (surprise) removal. + * Note: unplug_request and unplug are only called for devices to initiate + * unplug of a device hierarchy (e.g. triggered by device_del). For + * devices that will be removed along with this device hierarchy only + * do_unplug will be called (e.g. to unassign resources). */ typedef struct HotplugHandlerClass { /* */ @@ -63,7 +76,8 @@ typedef struct HotplugHandlerClass { /* */ hotplug_fn pre_plug; hotplug_fn plug; - void (*post_plug)(HotplugHandler *plug_handler, DeviceState *plugged_d= ev); + hotplug_fn_nofail post_plug; + hotplug_fn_nofail do_unplug; hotplug_fn unplug_request; hotplug_fn unplug; } HotplugHandlerClass; @@ -94,6 +108,14 @@ void hotplug_handler_pre_plug(HotplugHandler *plug_hand= ler, void hotplug_handler_post_plug(HotplugHandler *plug_handler, DeviceState *plugged_dev); =20 +/** + * hotplug_handler_do_unplug: + * + * Call #HotplugHandlerClass.do_unplug callback of @plug_handler. + */ +void hotplug_handler_do_unplug(HotplugHandler *plug_handler, + DeviceState *plugged_dev); + /** * hotplug_handler_unplug_request: * --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956666723828.3911110335702; Wed, 26 Sep 2018 03:11:06 -0700 (PDT) Received: from localhost ([::1]:57456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56mf-0001dk-Ju for importer@patchew.org; Wed, 26 Sep 2018 06:11:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56N6-0003em-N0 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56N4-0005FJ-65 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56N3-0005ES-MO; Wed, 26 Sep 2018 05:44:38 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6377D308A94D; Wed, 26 Sep 2018 09:44:36 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB7D72010D57; Wed, 26 Sep 2018 09:44:32 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:14 +0200 Message-Id: <20180926094219.20322-20-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 26 Sep 2018 09:44:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 19/24] virtio-pmem: prototype 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pankaj Gupta This is the current protoype of virtio-pmem. Support will require machine changes for the architectures that will support it, so it will not yet be compiled. Signed-off-by: Pankaj Gupta [ MemoryDevice/MemoryRegion changes, cleanups, addr property "memaddr", split up patches ] Signed-off-by: David Hildenbrand --- hw/virtio/Makefile.objs | 1 + hw/virtio/virtio-pmem.c | 224 ++++++++++++++++++++ include/hw/virtio/virtio-pmem.h | 40 ++++ include/standard-headers/linux/virtio_ids.h | 1 + qapi/misc.json | 26 ++- 5 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/virtio-pmem.c create mode 100644 include/hw/virtio/virtio-pmem.h diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 1b2799cfd8..75cdd90264 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -5,6 +5,7 @@ obj-y +=3D virtio.o common-obj-$(CONFIG_VIRTIO_RNG) +=3D virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-pci.o common-obj-$(CONFIG_VIRTIO_MMIO) +=3D virtio-mmio.o +obj-$(call land,$(CONFIG_VIRTIO_PMEM),$(CONFIG_LINUX)) +=3D virtio-pmem.o obj-$(CONFIG_VIRTIO_BALLOON) +=3D virtio-balloon.o obj-$(CONFIG_VIRTIO_CRYPTO) +=3D virtio-crypto.o obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) +=3D virtio-= crypto-pci.o diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c new file mode 100644 index 0000000000..0f8b509f0f --- /dev/null +++ b/hw/virtio/virtio-pmem.c @@ -0,0 +1,224 @@ +/* + * Virtio pmem device + * + * Copyright (C) 2018 Red Hat, Inc. + * Copyright (C) 2018 Pankaj Gupta + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "qemu/error-report.h" +#include "hw/virtio/virtio-access.h" +#include "hw/virtio/virtio-pmem.h" +#include "hw/mem/memory-device.h" +#include "block/aio.h" +#include "block/thread-pool.h" + +typedef struct VirtIOPMEMresp { + int ret; +} VirtIOPMEMResp; + +typedef struct VirtIODeviceRequest { + VirtQueueElement elem; + int fd; + VirtIOPMEM *pmem; + VirtIOPMEMResp resp; +} VirtIODeviceRequest; + +static int worker_cb(void *opaque) +{ + VirtIODeviceRequest *req =3D opaque; + int err =3D 0; + + printf("\n performing flush ..."); + /* flush raw backing image */ + err =3D fsync(req->fd); + printf("\n performed flush ...:errcode::%d", err); + if (err !=3D 0) { + err =3D EIO; + } + req->resp.ret =3D err; + + return 0; +} + +static void done_cb(void *opaque, int ret) +{ + VirtIODeviceRequest *req =3D opaque; + int len =3D iov_from_buf(req->elem.in_sg, req->elem.in_num, 0, + &req->resp, sizeof(VirtIOPMEMResp)); + + /* Callbacks are serialized, so no need to use atomic ops. */ + virtqueue_push(req->pmem->rq_vq, &req->elem, len); + virtio_notify((VirtIODevice *)req->pmem, req->pmem->rq_vq); + g_free(req); +} + +static void virtio_pmem_flush(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIODeviceRequest *req; + VirtIOPMEM *pmem =3D VIRTIO_PMEM(vdev); + HostMemoryBackend *backend =3D MEMORY_BACKEND(pmem->memdev); + ThreadPool *pool =3D aio_get_thread_pool(qemu_get_aio_context()); + + req =3D virtqueue_pop(vq, sizeof(VirtIODeviceRequest)); + if (!req) { + virtio_error(vdev, "virtio-pmem missing request data"); + return; + } + + if (req->elem.out_num < 1 || req->elem.in_num < 1) { + virtio_error(vdev, "virtio-pmem request not proper"); + g_free(req); + return; + } + req->fd =3D memory_region_get_fd(&backend->mr); + req->pmem =3D pmem; + thread_pool_submit_aio(pool, worker_cb, req, done_cb, req); +} + +static void virtio_pmem_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VirtIOPMEM *pmem =3D VIRTIO_PMEM(vdev); + struct virtio_pmem_config *pmemcfg =3D (struct virtio_pmem_config *) c= onfig; + + virtio_stq_p(vdev, &pmemcfg->start, pmem->start); + virtio_stq_p(vdev, &pmemcfg->size, memory_region_size(&pmem->memdev->m= r)); +} + +static uint64_t virtio_pmem_get_features(VirtIODevice *vdev, uint64_t feat= ures, + Error **errp) +{ + return features; +} + +static void virtio_pmem_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIOPMEM *pmem =3D VIRTIO_PMEM(dev); + + if (!pmem->memdev) { + error_setg(errp, "virtio-pmem memdev not set"); + return; + } else if (host_memory_backend_is_mapped(pmem->memdev)) { + char *path =3D object_get_canonical_path_component(OBJECT(pmem->me= mdev)); + error_setg(errp, "can't use already busy memdev: %s", path); + g_free(path); + return; + } + + host_memory_backend_set_mapped(pmem->memdev, true); + virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, + sizeof(struct virtio_pmem_config= )); + pmem->rq_vq =3D virtio_add_queue(vdev, 128, virtio_pmem_flush); +} + +static const char *virtio_pmem_md_get_device_id(const MemoryDeviceState *m= d) +{ + Object *obj =3D OBJECT(md); + + /* always return the ID of the proxy device the user configured */ + if (obj->parent && object_dynamic_cast(obj->parent, TYPE_DEVICE)) { + const DeviceState *parent_dev =3D DEVICE(obj->parent); + + return parent_dev->id; + } + return NULL; +} + +static void virtio_pmem_md_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + VirtioPMemDeviceInfo *vi =3D g_new0(VirtioPMemDeviceInfo, 1); + VirtIOPMEM *pmem =3D VIRTIO_PMEM(md); + const char *id =3D virtio_pmem_md_get_device_id(md); + + if (id) { + vi->has_id =3D true; + vi->id =3D g_strdup(id); + } + + vi->memaddr =3D pmem->start; + vi->size =3D pmem->memdev ? memory_region_size(&pmem->memdev->mr) : 0; + vi->memdev =3D object_get_canonical_path(OBJECT(pmem->memdev)); + + info->u.virtio_pmem.data =3D vi; + info->type =3D MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM; +} + +static uint64_t virtio_pmem_md_get_addr(const MemoryDeviceState *md) +{ + VirtIOPMEM *pmem =3D VIRTIO_PMEM(md); + + return pmem->start; +} + +static void virtio_pmem_md_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), addr, VIRTIO_PMEM_ADDR_PROP, errp= ); +} + +static MemoryRegion *virtio_pmem_md_get_memory_region(MemoryDeviceState *m= d, + Error **errp) +{ + VirtIOPMEM *pmem =3D VIRTIO_PMEM(md); + + if (!pmem->memdev) { + error_setg(errp, "'%s' property must be set", VIRTIO_PMEM_MEMDEV_P= ROP); + return NULL; + } + + return &pmem->memdev->mr; +} + +static Property virtio_pmem_properties[] =3D { + DEFINE_PROP_UINT64(VIRTIO_PMEM_ADDR_PROP, VirtIOPMEM, start, 0), + DEFINE_PROP_LINK(VIRTIO_PMEM_MEMDEV_PROP, VirtIOPMEM, memdev, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_pmem_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(klass); + + dc->props =3D virtio_pmem_properties; + + vdc->realize =3D virtio_pmem_realize; + vdc->get_config =3D virtio_pmem_get_config; + vdc->get_features =3D virtio_pmem_get_features; + + mdc->get_addr =3D virtio_pmem_md_get_addr; + mdc->set_addr =3D virtio_pmem_md_set_addr; + /* for virtio-pmem plugged_size =3D=3D region_size */ + mdc->get_plugged_size =3D memory_device_get_region_size; + mdc->get_memory_region =3D virtio_pmem_md_get_memory_region; + mdc->fill_device_info =3D virtio_pmem_md_fill_device_info; + mdc->get_device_id =3D virtio_pmem_md_get_device_id; +} + +static TypeInfo virtio_pmem_info =3D { + .name =3D TYPE_VIRTIO_PMEM, + .parent =3D TYPE_VIRTIO_DEVICE, + .class_init =3D virtio_pmem_class_init, + .instance_size =3D sizeof(VirtIOPMEM), + .interfaces =3D (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_pmem_info); +} + +type_init(virtio_register_types) diff --git a/include/hw/virtio/virtio-pmem.h b/include/hw/virtio/virtio-pme= m.h new file mode 100644 index 0000000000..11e549e0f1 --- /dev/null +++ b/include/hw/virtio/virtio-pmem.h @@ -0,0 +1,40 @@ +/* + * Virtio pmem Device + * + * Copyright Red Hat, Inc. 2018 + * Copyright Pankaj Gupta + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#ifndef QEMU_VIRTIO_PMEM_H +#define QEMU_VIRTIO_PMEM_H + +#include "hw/virtio/virtio.h" +#include "sysemu/hostmem.h" +#include "standard-headers/linux/virtio_ids.h" + +#define TYPE_VIRTIO_PMEM "virtio-pmem" + +#define VIRTIO_PMEM(obj) \ + OBJECT_CHECK(VirtIOPMEM, (obj), TYPE_VIRTIO_PMEM) + +#define VIRTIO_PMEM_ADDR_PROP "memaddr" +#define VIRTIO_PMEM_MEMDEV_PROP "memdev" + +/* VirtIOPMEM device structure */ +typedef struct VirtIOPMEM { + VirtIODevice parent_obj; + + VirtQueue *rq_vq; + uint64_t start; + HostMemoryBackend *memdev; +} VirtIOPMEM; + +struct virtio_pmem_config { + uint64_t start; + uint64_t size; +}; +#endif diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 6d5c3b2d4f..346389565a 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -43,5 +43,6 @@ #define VIRTIO_ID_INPUT 18 /* virtio input */ #define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ #define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ +#define VIRTIO_ID_PMEM 25 /* virtio pmem */ =20 #endif /* _LINUX_VIRTIO_IDS_H */ diff --git a/qapi/misc.json b/qapi/misc.json index e14efd70b0..94df118c45 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2912,6 +2912,29 @@ } } =20 +## +# @VirtioPMemDeviceInfo: +# +# VirtioPMem state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @size: size of memory that the device provides +# +# @memdev: memory backend linked with device +# +# Since: 3.1 +## +{ 'struct': 'VirtioPMemDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': 'size', + 'size': 'size', + 'memdev': 'str' + } +} + ## # @MemoryDeviceInfo: # @@ -2921,7 +2944,8 @@ ## { 'union': 'MemoryDeviceInfo', 'data': { 'dimm': 'PCDIMMDeviceInfo', - 'nvdimm': 'PCDIMMDeviceInfo' + 'nvdimm': 'PCDIMMDeviceInfo', + 'virtio-pmem': 'VirtioPMemDeviceInfo' } } =20 --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956046600185.85956480173343; Wed, 26 Sep 2018 03:00:46 -0700 (PDT) Received: from localhost ([::1]:57391 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56cf-00011J-ET for importer@patchew.org; Wed, 26 Sep 2018 06:00:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56N8-0003gw-Vk for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56N7-0005GT-WD for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58716) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56N7-0005Fq-GH; Wed, 26 Sep 2018 05:44:41 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 210BE8665F; Wed, 26 Sep 2018 09:44:40 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE2082010D97; Wed, 26 Sep 2018 09:44:36 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:15 +0200 Message-Id: <20180926094219.20322-21-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 26 Sep 2018 09:44:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 20/24] virtio-pci: proxy for virtio-pmem 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Pankaj Gupta We need a proxy device for virtio-pmem. Reviewed-by: David Gibson Signed-off-by: Pankaj Gupta [ split up patches ] Signed-off-by: David Hildenbrand --- hw/virtio/virtio-pci.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.h | 14 ++++++++++++++ include/hw/pci/pci.h | 1 + 3 files changed, 56 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 3a01fe90f0..dcfcefc1b5 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2521,6 +2521,46 @@ static const TypeInfo virtio_rng_pci_info =3D { .class_init =3D virtio_rng_pci_class_init, }; =20 +/* virtio-pmem-pci */ + +static void virtio_pmem_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VirtIOPMEMPCI *vpmem =3D VIRTIO_PMEM_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&vpmem->vdev); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void virtio_pmem_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D virtio_pmem_pci_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D PCI_DEVICE_ID_VIRTIO_PMEM; + pcidev_k->revision =3D VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id =3D PCI_CLASS_OTHERS; +} + +static void virtio_pmem_pci_instance_init(Object *obj) +{ + VirtIOPMEMPCI *dev =3D VIRTIO_PMEM_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_PMEM); +} + +static const TypeInfo virtio_pmem_pci_info =3D { + .name =3D TYPE_VIRTIO_PMEM_PCI, + .parent =3D TYPE_VIRTIO_PCI, + .instance_size =3D sizeof(VirtIOPMEMPCI), + .instance_init =3D virtio_pmem_pci_instance_init, + .class_init =3D virtio_pmem_pci_class_init, +}; + /* virtio-input-pci */ =20 static Property virtio_input_pci_properties[] =3D { @@ -2714,6 +2754,7 @@ static void virtio_pci_register_types(void) type_register_static(&virtio_balloon_pci_info); type_register_static(&virtio_serial_pci_info); type_register_static(&virtio_net_pci_info); + type_register_static(&virtio_pmem_pci_info); #ifdef CONFIG_VHOST_SCSI type_register_static(&vhost_scsi_pci_info); #endif diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 813082b0d7..fe74fcad3f 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -19,6 +19,7 @@ #include "hw/virtio/virtio-blk.h" #include "hw/virtio/virtio-net.h" #include "hw/virtio/virtio-rng.h" +#include "hw/virtio/virtio-pmem.h" #include "hw/virtio/virtio-serial.h" #include "hw/virtio/virtio-scsi.h" #include "hw/virtio/virtio-balloon.h" @@ -57,6 +58,7 @@ typedef struct VirtIOInputHostPCI VirtIOInputHostPCI; typedef struct VirtIOGPUPCI VirtIOGPUPCI; typedef struct VHostVSockPCI VHostVSockPCI; typedef struct VirtIOCryptoPCI VirtIOCryptoPCI; +typedef struct VirtIOPMEMPCI VirtIOPMEMPCI; =20 /* virtio-pci-bus */ =20 @@ -274,6 +276,18 @@ struct VirtIOBlkPCI { VirtIOBlock vdev; }; =20 +/* + * virtio-pmem-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VIRTIO_PMEM_PCI "virtio-pmem-pci" +#define VIRTIO_PMEM_PCI(obj) \ + OBJECT_CHECK(VirtIOPMEMPCI, (obj), TYPE_VIRTIO_PMEM_PCI) + +struct VirtIOPMEMPCI { + VirtIOPCIProxy parent_obj; + VirtIOPMEM vdev; +}; + /* * virtio-balloon-pci: This extends VirtioPCIProxy. */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index e6514bba23..44ae4c95d1 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -85,6 +85,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005 #define PCI_DEVICE_ID_VIRTIO_9P 0x1009 #define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012 +#define PCI_DEVICE_ID_VIRTIO_PMEM 0x1013 =20 #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 153795625833069.40919574070358; Wed, 26 Sep 2018 03:04:18 -0700 (PDT) Received: from localhost ([::1]:57410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56fv-0003dm-2I for importer@patchew.org; Wed, 26 Sep 2018 06:04:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56NC-0003k3-36 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56NB-0005Hy-EE for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42118) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56NB-0005Hb-3c; Wed, 26 Sep 2018 05:44:45 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19036A6DF4; Wed, 26 Sep 2018 09:44:44 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D56E2010D97; Wed, 26 Sep 2018 09:44:40 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:16 +0200 Message-Id: <20180926094219.20322-22-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 26 Sep 2018 09:44:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 21/24] hmp: handle virtio-pmem when printing memory device infos 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Print the memory device info just like for PCDIMM/NVDIMM. Signed-off-by: David Hildenbrand --- hmp.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/hmp.c b/hmp.c index 3a9f797677..159f82e155 100644 --- a/hmp.c +++ b/hmp.c @@ -2532,6 +2532,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDic= t *qdict) Error *err =3D NULL; MemoryDeviceInfoList *info_list =3D qmp_query_memory_devices(&err); MemoryDeviceInfoList *info; + VirtioPMemDeviceInfo *vpi; MemoryDeviceInfo *value; PCDIMMDeviceInfo *di; =20 @@ -2541,19 +2542,9 @@ void hmp_info_memory_devices(Monitor *mon, const QDi= ct *qdict) if (value) { switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: - di =3D value->u.dimm.data; - break; - case MEMORY_DEVICE_INFO_KIND_NVDIMM: - di =3D value->u.nvdimm.data; - break; - - default: - di =3D NULL; - break; - } - - if (di) { + di =3D (value->type =3D=3D MEMORY_DEVICE_INFO_KIND_DIMM) ? + value->u.dimm.data : value->u.nvdimm.data; monitor_printf(mon, "Memory device [%s]: \"%s\"\n", MemoryDeviceInfoKind_str(value->type), di->id ? di->id : ""); @@ -2566,6 +2557,18 @@ void hmp_info_memory_devices(Monitor *mon, const QDi= ct *qdict) di->hotplugged ? "true" : "false"); monitor_printf(mon, " hotpluggable: %s\n", di->hotpluggable ? "true" : "false"); + break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: + vpi =3D value->u.virtio_pmem.data; + monitor_printf(mon, "Memory device [%s]: \"%s\"\n", + MemoryDeviceInfoKind_str(value->type), + vpi->id ? vpi->id : ""); + monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->mem= addr); + monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); + monitor_printf(mon, " memdev: %s\n", vpi->memdev); + break; + default: + g_assert_not_reached(); } } } --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956443581475.3696266376346; Wed, 26 Sep 2018 03:07:23 -0700 (PDT) Received: from localhost ([::1]:57430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56j1-0006QU-93 for importer@patchew.org; Wed, 26 Sep 2018 06:07:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56NF-0003mZ-Lf for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56NE-0005Ix-OK for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58764) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56NE-0005Ij-I3; Wed, 26 Sep 2018 05:44:48 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAEE985A04; Wed, 26 Sep 2018 09:44:47 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65A7E2010CAB; Wed, 26 Sep 2018 09:44:44 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:17 +0200 Message-Id: <20180926094219.20322-23-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 26 Sep 2018 09:44:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 22/24] numa: handle virtio-pmem in NUMA stats 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Account the memory to node 0 for now. Once (if ever) virtio-pmem supports NUMA, we can account it to the right node. Signed-off-by: David Hildenbrand --- numa.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/numa.c b/numa.c index 81542d4ebb..1ff1418c1e 100644 --- a/numa.c +++ b/numa.c @@ -545,6 +545,7 @@ static void numa_stat_memory_devices(NumaNodeMem node_m= em[]) MemoryDeviceInfoList *info_list =3D qmp_memory_device_list(); MemoryDeviceInfoList *info; PCDIMMDeviceInfo *pcdimm_info; + VirtioPMemDeviceInfo *vpi; =20 for (info =3D info_list; info; info =3D info->next) { MemoryDeviceInfo *value =3D info->value; @@ -552,22 +553,21 @@ static void numa_stat_memory_devices(NumaNodeMem node= _mem[]) if (value) { switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: - pcdimm_info =3D value->u.dimm.data; - break; - case MEMORY_DEVICE_INFO_KIND_NVDIMM: - pcdimm_info =3D value->u.nvdimm.data; - break; - - default: - pcdimm_info =3D NULL; - break; - } - - if (pcdimm_info) { + pcdimm_info =3D (value->type =3D=3D MEMORY_DEVICE_INFO_KIN= D_DIMM) ? + value->u.dimm.data : value->u.nvdimm.data; node_mem[pcdimm_info->node].node_mem +=3D pcdimm_info->siz= e; node_mem[pcdimm_info->node].node_plugged_mem +=3D pcdimm_info->size; + break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: + vpi =3D value->u.virtio_pmem.data; + /* TODO: once we support numa, assign to right node */ + node_mem[0].node_mem +=3D vpi->size; + node_mem[0].node_plugged_mem +=3D vpi->size; + break; + default: + g_assert_not_reached(); } } } --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537955874283848.6238131478959; Wed, 26 Sep 2018 02:57:54 -0700 (PDT) Received: from localhost ([::1]:57368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56Zj-000663-3q for importer@patchew.org; Wed, 26 Sep 2018 05:57:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56NR-0003wv-Rd for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:45:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56NJ-0005Kw-I4 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:44:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44104) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56NJ-0005KY-96; Wed, 26 Sep 2018 05:44:53 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 892C330820C2; Wed, 26 Sep 2018 09:44:51 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23B872010D57; Wed, 26 Sep 2018 09:44:47 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:18 +0200 Message-Id: <20180926094219.20322-24-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 26 Sep 2018 09:44:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 23/24] virtio-pmem: hotplug support 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" virtio-pmem devices will have to be hotplugged using the machine hotplug handler just like other memory devices. Therefore, all machines that want to support virtio-pmem will have to modify their machine hotplug handler. virtio-pmem devices are realized when their parent proxy device (virtio-pmem-pci) is realized. Therefore, they are attached to a bus without a hotplug handler. This makes things a lot easier, because without a hotplug handler, we can directly get control over the device in the machine hotplug handler (otherwise we would have to overwrite control and pass control to the bus hotplug handler from the machine hotplug handler). As we have to implement support for each machine we want to support, add a safety net ("pre_plugged") that catches if the pre_plug handler was not called - if trying to realize it with a machine that does not support it. Otherwise creating and realizing virtio-pmem-pci along with virtio-pmem would work, however the memory-device part would not properly get hotplugged. Signed-off-by: David Hildenbrand --- hw/virtio/virtio-pmem.c | 34 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-pmem.h | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c index 0f8b509f0f..893e92237b 100644 --- a/hw/virtio/virtio-pmem.c +++ b/hw/virtio/virtio-pmem.c @@ -112,6 +112,12 @@ static void virtio_pmem_realize(DeviceState *dev, Erro= r **errp) return; } =20 + /* pre_plug handler wasn't executed (e.g. from machine hotplug handler= ) */ + if (!pmem->pre_plugged) { + error_setg(errp, "virtio-pmem is not compatible with the machine"); + return; + } + host_memory_backend_set_mapped(pmem->memdev, true); virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, sizeof(struct virtio_pmem_config= )); @@ -205,6 +211,34 @@ static void virtio_pmem_class_init(ObjectClass *klass,= void *data) mdc->get_device_id =3D virtio_pmem_md_get_device_id; } =20 +void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + /* + * The proxy device (e.g. virtio-pmem-pci) has an hotplug handler and + * will attach the virtio-pmem device to its bus (parent_bus). This + * device will realize the virtio-mem device from its realize function, + * therefore when it is hotplugged itself. The proxy device bus + * therefore has no hotplug handler and we don't have to forward any + * calls. + */ + if (!DEVICE(pmem)->parent_bus || + DEVICE(pmem)->parent_bus->hotplug_handler) { + error_setg(errp, "virtio-pmem is not compatible with the proxy."); + } + memory_device_pre_plug(MEMORY_DEVICE(pmem), ms, NULL, errp); + pmem->pre_plugged =3D true; +} + +void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + memory_device_plug(MEMORY_DEVICE(pmem), ms); +} + +void virtio_pmem_do_unplug(VirtIOPMEM *pmem, MachineState *ms) +{ + memory_device_unplug(MEMORY_DEVICE(pmem), ms); +} + static TypeInfo virtio_pmem_info =3D { .name =3D TYPE_VIRTIO_PMEM, .parent =3D TYPE_VIRTIO_DEVICE, diff --git a/include/hw/virtio/virtio-pmem.h b/include/hw/virtio/virtio-pme= m.h index 11e549e0f1..9cc70e391d 100644 --- a/include/hw/virtio/virtio-pmem.h +++ b/include/hw/virtio/virtio-pmem.h @@ -31,10 +31,21 @@ typedef struct VirtIOPMEM { VirtQueue *rq_vq; uint64_t start; HostMemoryBackend *memdev; + + /* + * Safety net to make sure we can catch trying to be realized on a + * machine that is not prepared to properly hotplug virtio-pmem from + * its machine hotplug handler. + */ + bool pre_plugged; } VirtIOPMEM; =20 struct virtio_pmem_config { uint64_t start; uint64_t size; }; + +void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp= ); +void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp); +void virtio_pmem_do_unplug(VirtIOPMEM *pmem, MachineState *ms); #endif --=20 2.17.1 From nobody Tue Apr 30 08:06:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537956806990823.8795913661864; Wed, 26 Sep 2018 03:13:26 -0700 (PDT) Received: from localhost ([::1]:57466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56ov-0003Mz-N9 for importer@patchew.org; Wed, 26 Sep 2018 06:13:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g56NX-00042U-8p for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:45:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g56NV-0005S2-MW for qemu-devel@nongnu.org; Wed, 26 Sep 2018 05:45:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g56NQ-0005LJ-3R; Wed, 26 Sep 2018 05:45:01 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E70C308A94D; Wed, 26 Sep 2018 09:44:55 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id D93712010D97; Wed, 26 Sep 2018 09:44:51 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:42:19 +0200 Message-Id: <20180926094219.20322-25-david@redhat.com> In-Reply-To: <20180926094219.20322-1-david@redhat.com> References: <20180926094219.20322-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 26 Sep 2018 09:44:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 24/24] pc: support for virtio-pmem 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" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Compile virtio-pmem for x86 and properly hotplug virtio-pmem devices (memory-device part) from our pc machine hotplug handler. Signed-off-by: David Hildenbrand --- default-configs/i386-softmmu.mak | 1 + hw/i386/pc.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmm= u.mak index 4c1637338b..dfb1e6d63a 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -51,6 +51,7 @@ CONFIG_APIC=3Dy CONFIG_IOAPIC=3Dy CONFIG_PVPANIC=3Dy CONFIG_MEM_DEVICE=3Dy +CONFIG_VIRTIO_PMEM=3Dy CONFIG_DIMM=3Dy CONFIG_NVDIMM=3Dy CONFIG_ACPI_NVDIMM=3Dy diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 86c16f9aaf..78e3295390 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/virtio/virtio-pmem.h" =20 /* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -2013,6 +2014,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHand= ler *hotplug_dev, pc_memory_pre_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { + virtio_pmem_pre_plug(VIRTIO_PMEM(dev), MACHINE(hotplug_dev), errp); } } =20 @@ -2023,6 +2026,8 @@ static void pc_machine_device_plug_cb(HotplugHandler = *hotplug_dev, pc_memory_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { + virtio_pmem_plug(VIRTIO_PMEM(dev), MACHINE(hotplug_dev), errp); } } =20 @@ -2052,11 +2057,20 @@ static void pc_machine_device_unplug_cb(HotplugHand= ler *hotplug_dev, } } =20 +static void pc_machine_device_do_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { + virtio_pmem_do_unplug(VIRTIO_PMEM(dev), MACHINE(hotplug_dev)); + } +} + 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_CPU)) { + object_dynamic_cast(OBJECT(dev), TYPE_CPU) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { return HOTPLUG_HANDLER(machine); } =20 @@ -2395,6 +2409,7 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) hc->pre_plug =3D pc_machine_device_pre_plug_cb; hc->plug =3D pc_machine_device_plug_cb; hc->unplug_request =3D pc_machine_device_unplug_request_cb; + hc->do_unplug =3D pc_machine_device_do_unplug_cb; hc->unplug =3D pc_machine_device_unplug_cb; nc->nmi_monitor_handler =3D x86_nmi; mc->default_cpu_type =3D TARGET_DEFAULT_CPU_TYPE; --=20 2.17.1