From nobody Sun Feb 8 20:52:29 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 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