From nobody Wed Nov 5 21:46:06 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 1537440464297229.12942128291263; Thu, 20 Sep 2018 03:47:44 -0700 (PDT) Received: from localhost ([::1]:49425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wUo-0006tS-Sp for importer@patchew.org; Thu, 20 Sep 2018 06:47:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHx-0003fI-8p for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHw-00079H-DE for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHw-00078q-3h; Thu, 20 Sep 2018 06:34:24 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69C37308404D; Thu, 20 Sep 2018 10:34:23 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74DE53091327; Thu, 20 Sep 2018 10:34:15 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:37 +0200 Message-Id: <20180920103243.28474-17-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 20 Sep 2018 10:34:23 +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 v3 16/22] memory-device: add optional 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. 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). Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 7 +++++-- include/hw/mem/memory-device.h | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 534bd38313..92878fc327 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -174,8 +174,11 @@ 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 ? mdc->get_device_id= (md) : + DEVICE(md)->id; + + error_setg(errp, "address range conflicts with '%s'", + id ? id : "(unnamed)"); goto out; } new_addr =3D QEMU_ALIGN_UP(md_addr + md_size, align); diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index fd0b43c224..66143cffc6 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -42,6 +42,9 @@ typedef struct MemoryDeviceState { * 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. + * @get_device_id: Optional. 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. */ typedef struct MemoryDeviceClass { /* private */ @@ -54,6 +57,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