From nobody Tue Feb 10 10:04:25 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 1529333494333929.3575618176078; Mon, 18 Jun 2018 07:51:34 -0700 (PDT) Received: from localhost ([::1]:35173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUvVD-0000Q1-1S for importer@patchew.org; Mon, 18 Jun 2018 10:51:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUvS0-0006op-8i for qemu-devel@nongnu.org; Mon, 18 Jun 2018 10:48:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUvRu-0004kY-0z for qemu-devel@nongnu.org; Mon, 18 Jun 2018 10:48:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41542 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 1fUvRt-0004kM-Ra; Mon, 18 Jun 2018 10:48:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 590667DAC3; Mon, 18 Jun 2018 14:48:05 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-240.ams2.redhat.com [10.36.117.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C2F52156880; Mon, 18 Jun 2018 14:48:03 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 16:47:57 +0200 Message-Id: <20180618144800.555-2-david@redhat.com> In-Reply-To: <20180618144800.555-1-david@redhat.com> References: <20180618144800.555-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 18 Jun 2018 14:48:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 18 Jun 2018 14:48:05 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v1 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" , 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(). Signed-off-by: David Hildenbrand Acked-by: David Gibson Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/i386/pc.c | 2 ++ hw/mem/pc-dimm.c | 35 ++++++++++++++++++----------------- hw/ppc/spapr.c | 1 + include/hw/mem/pc-dimm.h | 1 + 4 files changed, 22 insertions(+), 17 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 6934abc21e..9da233588b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3211,6 +3211,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, goto out; } =20 + pc_dimm_pre_plug(dev, MACHINE(hotplug_dev), errp); out: g_free(mem_dev); } 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