From nobody Sun Feb 8 09:43:15 2026 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 1530188412002610.9037653768933; Thu, 28 Jun 2018 05:20:12 -0700 (PDT) Received: from localhost ([::1]:36302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVuF-000580-5j for importer@patchew.org; Thu, 28 Jun 2018 08:20:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVoj-0001G6-P5 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYVoh-0002Xl-G5 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34810 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYVoh-0002XB-BQ; Thu, 28 Jun 2018 08:14:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC3498A9EF; Thu, 28 Jun 2018 12:14:26 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-166.ams2.redhat.com [10.36.116.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE7F41C731; Thu, 28 Jun 2018 12:14:24 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 14:14:14 +0200 Message-Id: <20180628121417.1980-2-david@redhat.com> In-Reply-To: <20180628121417.1980-1-david@redhat.com> References: <20180628121417.1980-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 28 Jun 2018 12:14:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 28 Jun 2018 12:14:27 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 1/4] pc-dimm: assign and verify the "slot" property during pre_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: Eduardo Habkost , "Michael S . Tsirkin" , Stefan Weil , Xiao Guangrong , David Hildenbrand , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We can assign and verify the slot before realizing and trying to plug. reading/writing the slot property should never fail, so let's reduce error handling a bit by using &error_abort. To do this during pre_plug, add and use (x86, ppc) pc_dimm_pre_plug(). Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 2 ++ hw/mem/pc-dimm.c | 35 ++++++++++++++++++----------------- hw/ppc/spapr.c | 9 ++++++++- include/hw/mem/pc-dimm.h | 1 + 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f310040351..bf986baf91 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1695,6 +1695,8 @@ static void pc_memory_pre_plug(HotplugHandler *hotplu= g_dev, DeviceState *dev, error_setg(errp, "nvdimm is not enabled: missing 'nvdimm' in '-M'"= ); return; } + + pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), errp); } =20 static void pc_memory_plug(HotplugHandler *hotplug_dev, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 65843bc52a..e56c4daef2 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -29,10 +29,27 @@ =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, Error **err= p) +{ + Error *local_err =3D NULL; + int slot; + + slot =3D object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, + &error_abort); + slot =3D pc_dimm_get_free_slot(slot =3D=3D PC_DIMM_UNASSIGNED_SLOT ? N= ULL : &slot, + machine->ram_slots, &local_err); + if (local_err) { + goto out; + } + object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_a= bort); + trace_mhp_pc_dimm_assigned_slot(slot); +out: + error_propagate(errp, local_err); +} + void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align, Error **errp) { - int slot; PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *vmstate_mr =3D ddc->get_vmstate_memory_region(dimm, @@ -59,22 +76,6 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machin= e, uint64_t align, } trace_mhp_pc_dimm_assigned_address(addr); =20 - slot =3D object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, &loca= l_err); - if (local_err) { - goto out; - } - - slot =3D pc_dimm_get_free_slot(slot =3D=3D PC_DIMM_UNASSIGNED_SLOT ? N= ULL : &slot, - machine->ram_slots, &local_err); - if (local_err) { - goto out; - } - object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &local_e= rr); - if (local_err) { - goto out; - } - trace_mhp_pc_dimm_assigned_slot(slot); - memory_device_plug_region(machine, mr, addr); vmstate_register_ram(vmstate_mr, dev); =20 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b32b971a14..bf012235b6 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3191,6 +3191,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *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; @@ -3216,7 +3217,13 @@ static void spapr_memory_pre_plug(HotplugHandler *ho= tplug_dev, DeviceState *dev, memdev =3D object_property_get_link(OBJECT(dimm), PC_DIMM_MEMDEV_PROP, &error_abort); pagesize =3D host_memory_backend_pagesize(MEMORY_BACKEND(memdev)); - spapr_check_pagesize(spapr, pagesize, errp); + spapr_check_pagesize(spapr, pagesize, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), errp); } =20 struct sPAPRDIMMState { diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 26ebb7d5e9..7b120416d1 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -79,6 +79,7 @@ typedef struct PCDIMMDeviceClass { Error **errp); } PCDIMMDeviceClass; =20 +void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, Error **err= p); void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align, Error **errp); void pc_dimm_unplug(DeviceState *dev, MachineState *machine); --=20 2.17.1 From nobody Sun Feb 8 09:43:15 2026 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 153018818544579.97753977742263; Thu, 28 Jun 2018 05:16:25 -0700 (PDT) Received: from localhost ([::1]:36285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVqW-0002U5-RN for importer@patchew.org; Thu, 28 Jun 2018 08:16:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVok-0001Gl-Vh for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYVok-0002bW-4f for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34164 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYVoj-0002av-V6; Thu, 28 Jun 2018 08:14:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 884AA81663C5; Thu, 28 Jun 2018 12:14:29 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-166.ams2.redhat.com [10.36.116.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 833131C55D; Thu, 28 Jun 2018 12:14:27 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 14:14:15 +0200 Message-Id: <20180628121417.1980-3-david@redhat.com> In-Reply-To: <20180628121417.1980-1-david@redhat.com> References: <20180628121417.1980-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 28 Jun 2018 12:14:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 28 Jun 2018 12:14:29 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/4] util/oslib-win32: indicate alignment for qemu_anon_ram_alloc() 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: Eduardo Habkost , "Michael S . Tsirkin" , Stefan Weil , Xiao Guangrong , David Hildenbrand , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's set the alignment just like for the posix variant. This will implicitly set the alignment of the underlying memory region and therefore make memory_region_get_alignment(mr) return something > 0 for all memory backends applicable to PCDIMM/NVDIMM. This will allow us to drop special handling in pc.c for memory_region_get_alignment(mr) =3D=3D 0, as we can then assume that it is always set (and AFAICS >=3D getpagesize()). For pc in pc_memory_plug(), under Windows TARGET_PAGE_SIZE =3D=3D getpagesi= ze(), therefore alignment of DIMMs will not change, and therefore also not the guest physical memory layout. For spapr in spapr_memory_plug(), an alignment of 0 would have been used until now. Now getpagesize() is used. But as the size of DIMMs has to be multiple of 256MB on spapr, automatic address asignment will not change the layout (no memory holes will be created as the alignment change will not apply if DIMMs start/end on 256MB boundaries). Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- util/oslib-win32.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index bb5ad28bd3..6e87721419 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -76,6 +76,10 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align, = bool shared) memory is page aligned. */ ptr =3D VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); trace_qemu_anon_ram_alloc(size, ptr); + + if (ptr && align) { + *align =3D getpagesize(); + } return ptr; } =20 --=20 2.17.1 From nobody Sun Feb 8 09:43:15 2026 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 153018838767273.40800877238587; Thu, 28 Jun 2018 05:19:47 -0700 (PDT) Received: from localhost ([::1]:36301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVtq-0004re-PP for importer@patchew.org; Thu, 28 Jun 2018 08:19:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVon-0001IL-FV for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYVom-0002e0-Ax for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49032 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYVom-0002dP-4x; Thu, 28 Jun 2018 08:14:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C604340255D7; Thu, 28 Jun 2018 12:14:31 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-166.ams2.redhat.com [10.36.116.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id C39231C72E; Thu, 28 Jun 2018 12:14:29 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 14:14:16 +0200 Message-Id: <20180628121417.1980-4-david@redhat.com> In-Reply-To: <20180628121417.1980-1-david@redhat.com> References: <20180628121417.1980-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 28 Jun 2018 12:14:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 28 Jun 2018 12:14:31 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/4] pc: drop memory region alignment check for 0 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: Eduardo Habkost , "Michael S . Tsirkin" , Stefan Weil , Xiao Guangrong , David Hildenbrand , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" All applicable memory regions always have an alignment > 0. All memory backends result in file_ram_alloc() or qemu_anon_ram_alloc() getting called, setting the alignment to > 0. So a PCDIMM memory region always has an alignment > 0. NVDIMM copy the alignment of the original memory memory region into the handcrafted memory region that will be used at this place. So the check for 0 can be dropped and we can reduce the special handling. Dropping this check makes factoring out of alignment handling easier as compat handling only has to look at pcmc->enforce_aligned_dimm and not care about the alignment of the memory region. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/i386/pc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index bf986baf91..934b7155b1 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1712,7 +1712,7 @@ static void pc_memory_plug(HotplugHandler *hotplug_de= v, uint64_t align =3D TARGET_PAGE_SIZE; bool is_nvdimm =3D object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); =20 - if (memory_region_get_alignment(mr) && pcmc->enforce_aligned_dimm) { + if (pcmc->enforce_aligned_dimm) { align =3D memory_region_get_alignment(mr); } =20 --=20 2.17.1 From nobody Sun Feb 8 09:43:15 2026 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 1530188211877495.9223573012373; Thu, 28 Jun 2018 05:16:51 -0700 (PDT) Received: from localhost ([::1]:36287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVr1-0002sl-2y for importer@patchew.org; Thu, 28 Jun 2018 08:16:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYVoq-0001LG-4H for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYVoo-0002gR-MT for qemu-devel@nongnu.org; Thu, 28 Jun 2018 08:14:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42738 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYVoo-0002fq-FS; Thu, 28 Jun 2018 08:14:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F57B87A81; Thu, 28 Jun 2018 12:14:34 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-166.ams2.redhat.com [10.36.116.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E1DC1C72C; Thu, 28 Jun 2018 12:14:31 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 14:14:17 +0200 Message-Id: <20180628121417.1980-5-david@redhat.com> In-Reply-To: <20180628121417.1980-1-david@redhat.com> References: <20180628121417.1980-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 28 Jun 2018 12:14:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 28 Jun 2018 12:14:34 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 4/4] pc-dimm: assign and verify the "addr" property during pre_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: Eduardo Habkost , "Michael S . Tsirkin" , Stefan Weil , Xiao Guangrong , David Hildenbrand , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We can assign and verify the slot before realizing and trying to plug. reading/writing the address property should never fail, so let's reduce error handling a bit by using &error_abort. Getting access to the memory region now might however fail. So forward errors from get_memory_region() properly. Keep tracing the assigned address for now in the plug code, as that's the point we are sure plugging succeeded and the address willa ctually be used. As all memory devices should use the alignment of the underlying memory region for guest physical address asignment, do detection of the alignment in pc_dimm_pre_plug(), but allow pc.c to overwrite the alignment for compatibility handling. Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 16 ++++-------- hw/mem/pc-dimm.c | 53 +++++++++++++++++++++++----------------- hw/ppc/spapr.c | 7 +++--- include/hw/mem/pc-dimm.h | 6 ++--- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 934b7155b1..16e4b5baff 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1678,7 +1678,9 @@ static void pc_memory_pre_plug(HotplugHandler *hotplu= g_dev, DeviceState *dev, Error **errp) { const PCMachineState *pcms =3D PC_MACHINE(hotplug_dev); + const PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); const bool is_nvdimm =3D object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); + const uint64_t compat_align =3D TARGET_PAGE_SIZE; =20 /* * When -no-acpi is used with Q35 machine type, no ACPI is built, @@ -1696,7 +1698,8 @@ static void pc_memory_pre_plug(HotplugHandler *hotplu= g_dev, DeviceState *dev, return; } =20 - pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), errp); + pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), + pcmc->enforce_aligned_dimm ? NULL : &compat_align, er= rp); } =20 static void pc_memory_plug(HotplugHandler *hotplug_dev, @@ -1705,18 +1708,9 @@ static void pc_memory_plug(HotplugHandler *hotplug_d= ev, HotplugHandlerClass *hhc; Error *local_err =3D NULL; PCMachineState *pcms =3D PC_MACHINE(hotplug_dev); - PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); - PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); - uint64_t align =3D TARGET_PAGE_SIZE; bool is_nvdimm =3D object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); =20 - if (pcmc->enforce_aligned_dimm) { - align =3D memory_region_get_alignment(mr); - } - - pc_dimm_plug(dev, MACHINE(pcms), align, &local_err); + pc_dimm_plug(dev, MACHINE(pcms), &local_err); if (local_err) { goto out; } diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index e56c4daef2..8e2e8549dc 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -29,9 +29,14 @@ =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, Error **err= p) +void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, + const uint64_t *compat_align, Error **errp) { + PCDIMMDevice *dimm =3D PC_DIMM(dev); + PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); Error *local_err =3D NULL; + MemoryRegion *mr; + uint64_t addr, align; int slot; =20 slot =3D object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, @@ -43,44 +48,46 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *m= achine, Error **errp) } object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_a= bort); trace_mhp_pc_dimm_assigned_slot(slot); + + mr =3D ddc->get_memory_region(dimm, &local_err); + if (local_err) { + goto out; + } + + if (compat_align) { + align =3D *compat_align; + } else { + align =3D memory_region_get_alignment(mr); + } + + 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; + } + object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, + &error_abort); out: error_propagate(errp, local_err); } =20 -void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align, - Error **errp) +void pc_dimm_plug(DeviceState *dev, 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); - Error *local_err =3D NULL; uint64_t addr; =20 - addr =3D object_property_get_uint(OBJECT(dimm), - PC_DIMM_ADDR_PROP, &local_err); - if (local_err) { - goto out; - } - - addr =3D memory_device_get_free_addr(machine, !addr ? NULL : &addr, al= ign, - memory_region_size(mr), &local_err); - if (local_err) { - goto out; - } - - object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, &local_= err); - if (local_err) { - goto out; - } + addr =3D object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, + &error_abort); trace_mhp_pc_dimm_assigned_address(addr); =20 memory_device_plug_region(machine, mr, addr); vmstate_register_ram(vmstate_mr, dev); - -out: - error_propagate(errp, local_err); } =20 void pc_dimm_unplug(DeviceState *dev, MachineState *machine) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index bf012235b6..33543c6373 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3150,13 +3150,12 @@ static void spapr_memory_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, PCDIMMDevice *dimm =3D PC_DIMM(dev); PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); - uint64_t align, size, addr; + uint64_t size, addr; uint32_t node; =20 - align =3D memory_region_get_alignment(mr); size =3D memory_region_size(mr); =20 - pc_dimm_plug(dev, MACHINE(ms), align, &local_err); + pc_dimm_plug(dev, MACHINE(ms), &local_err); if (local_err) { goto out; } @@ -3223,7 +3222,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, return; } =20 - pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), errp); + pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), NULL, errp); } =20 struct sPAPRDIMMState { diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 7b120416d1..6457b2a25f 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, Error **err= p); -void pc_dimm_plug(DeviceState *dev, MachineState *machine, uint64_t align, - Error **errp); +void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, + const uint64_t *compat_align, Error **errp); +void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp); void pc_dimm_unplug(DeviceState *dev, MachineState *machine); #endif --=20 2.17.1