From nobody Tue Nov 4 18:59:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153052440556523.697788591263816; Mon, 2 Jul 2018 02:40:05 -0700 (PDT) Received: from localhost ([::1]:59661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZvJU-0006e3-TZ for importer@patchew.org; Mon, 02 Jul 2018 05:40:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZvHa-0005Nv-2n for qemu-devel@nongnu.org; Mon, 02 Jul 2018 05:38:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZvHW-0006km-5F for qemu-devel@nongnu.org; Mon, 02 Jul 2018 05:38:06 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56754 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 1fZvHV-0006ka-VC; Mon, 02 Jul 2018 05:38:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F9098011454; Mon, 2 Jul 2018 09:38:01 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-188.ams2.redhat.com [10.36.116.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54EB52156898; Mon, 2 Jul 2018 09:37:59 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 11:37:52 +0200 Message-Id: <20180702093755.7384-2-david@redhat.com> In-Reply-To: <20180702093755.7384-1-david@redhat.com> References: <20180702093755.7384-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 02 Jul 2018 09:38:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 02 Jul 2018 09:38:01 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 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 Reviewed-by: Eric Auger --- 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