From nobody Sun Apr 12 05:58:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1771423316; cv=none; d=zohomail.com; s=zohoarc; b=CZ3tWacDiiDU4t/4MgWE28NvC30U/pK757PPh5coAarh+0TiweTwuAmhyaHCIm+sQucQzRkMA6SdbuHu9p6pz55Xkyo4tK+xExn01jJTKwDyMRXs41i0UFJwNpwdFzjicgfNaZInTQWHF8Hq067PVyRxA9s3sdnAyg2dvK3igMg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771423316; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YGFAO1IXnM0+bjnrxUtaJJdGMMhAn4QNXCcXW9XUah0=; b=j+yEpaA04Mk9/WlijsdCt7nAtukcNfeKQ2tZ1F3oi3zaUAn0gdSrcJriw+4740vmCROGe4qQyIW3akXdq+WI+vlX+BZsZAsAUP7FbSP7653ky8lN1HDYwdKg3g7f9pWEejvsN7XQyZ7ZUGP3dszRq4ukwPCmaFU0qdV1sSjHpYM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771423316951750.2116817282864; Wed, 18 Feb 2026 06:01:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsi7V-0004GK-6k; Wed, 18 Feb 2026 09:01:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsi6T-00040A-7E for qemu-devel@nongnu.org; Wed, 18 Feb 2026 09:00:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsi6Q-0007Bj-OT for qemu-devel@nongnu.org; Wed, 18 Feb 2026 09:00:32 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-xcdRyIQRPIiyTBMQLwze3A-1; Wed, 18 Feb 2026 09:00:15 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C926919344F9; Wed, 18 Feb 2026 14:00:14 +0000 (UTC) Received: from corto.redhat.com (unknown [10.45.224.251]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 314931956095; Wed, 18 Feb 2026 14:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771423229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YGFAO1IXnM0+bjnrxUtaJJdGMMhAn4QNXCcXW9XUah0=; b=Bknc9X8f9GDLrIqQwm4NSZiUtuT+IhKbBNnl8dDpYiMjD+AelmlNCvWRy1eypvSXLyj16f qD+AercUXhijva5/c7iyFxw7ZAMdHbtfAobDvmPsvTCYNIPGsV5CFwb0UNUXfhMIpVkC4q zE2hJ2m823hUYAa9R7lCuQ5MzsPH36Q= X-MC-Unique: xcdRyIQRPIiyTBMQLwze3A-1 X-Mimecast-MFC-AGG-ID: xcdRyIQRPIiyTBMQLwze3A_1771423215 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Ankit Agrawal , Cedric Le Goater Subject: [PULL 3/5] vfio: Add Error ** parameter to vfio_region_setup() Date: Wed, 18 Feb 2026 15:00:01 +0100 Message-ID: <20260218140003.1554502-4-clg@redhat.com> In-Reply-To: <20260218140003.1554502-1-clg@redhat.com> References: <20260218140003.1554502-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.043, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1771423318686154100 From: Ankit Agrawal Add an Error **errp parameter to vfio_region_setup() and vfio_setup_region_sparse_mmaps to allow proper error handling instead of just returning error codes. The function sets errors via error_setg() when failure occur. Suggested-by: Cedric Le Goater Signed-off-by: Ankit Agrawal Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20260217153010.408739-3-ankita@nvi= dia.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-region.h | 2 +- hw/vfio/display.c | 6 +++--- hw/vfio/pci.c | 3 +-- hw/vfio/region.c | 20 +++++++++++--------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/hw/vfio/vfio-region.h b/hw/vfio/vfio-region.h index ede6e0c8f992caa3292d280474c90ddef27eb3dd..9b21d4ee5ba16f8c05be83c75d1= c7a6ad4cf8370 100644 --- a/hw/vfio/vfio-region.h +++ b/hw/vfio/vfio-region.h @@ -38,7 +38,7 @@ void vfio_region_write(void *opaque, hwaddr addr, uint64_t vfio_region_read(void *opaque, hwaddr addr, unsigned size); int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, - int index, const char *name); + int index, const char *name, Error **errp); int vfio_region_mmap(VFIORegion *region); void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled); void vfio_region_unmap(VFIORegion *region); diff --git a/hw/vfio/display.c b/hw/vfio/display.c index faacd9019a558ea35a8730696472e967d4196919..5a42a6f7a29e77ec2489f942457= 221aed8118d0b 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -446,13 +446,13 @@ static void vfio_display_region_update(void *opaque) =20 if (!dpy->region.buffer.size) { /* mmap region */ + Error *error =3D NULL; ret =3D vfio_region_setup(OBJECT(vdev), &vdev->vbasedev, &dpy->region.buffer, plane.region_index, - "display"); + "display", &error); if (ret !=3D 0) { - error_report("%s: vfio_region_setup(%d): %s", - __func__, plane.region_index, strerror(-ret)); + error_report_err(error); goto err; } ret =3D vfio_region_mmap(&dpy->region.buffer); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 36d8fbe872eb9c0e2493b9710fc29e326dc1ec52..c89f3fbea348e780b7662c7d689= 3d9d778aae678 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3056,11 +3056,10 @@ bool vfio_pci_populate_device(VFIOPCIDevice *vdev, = Error **errp) char *name =3D g_strdup_printf("%s BAR %d", vbasedev->name, i); =20 ret =3D vfio_region_setup(OBJECT(vdev), vbasedev, - &vdev->bars[i].region, i, name); + &vdev->bars[i].region, i, name, errp); g_free(name); =20 if (ret) { - error_setg_errno(errp, -ret, "failed to get region %d info", i= ); return false; } =20 diff --git a/hw/vfio/region.c b/hw/vfio/region.c index 8fbc98918f5f7c76c5e2f99956b54b96d0908fd6..d464eadf9c048e29981da8af48f= 8f86933a98ad5 100644 --- a/hw/vfio/region.c +++ b/hw/vfio/region.c @@ -163,7 +163,8 @@ static int vfio_mmap_compare_offset(const void *a, cons= t void *b) } =20 static int vfio_setup_region_sparse_mmaps(VFIORegion *region, - struct vfio_region_info *info) + struct vfio_region_info *info, + Error **errp) { struct vfio_info_cap_header *hdr; struct vfio_region_info_cap_sparse_mmap *sparse; @@ -210,12 +211,12 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion = *region, off_t prev_end =3D region->mmaps[i - 1].offset + region->mmaps[i - 1].size; if (prev_end > region->mmaps[i].offset) { - error_report("%s: overlapping sparse mmap regions detected= " - "in region %d: [0x%"PRIx64"-0x%"PRIx64"] over= laps " - "with [0x%"PRIx64"-0x%"PRIx64"]", - __func__, region->nr, region->mmaps[i - 1].of= fset, - prev_end - 1, region->mmaps[i].offset, - region->mmaps[i].offset + region->mmaps[i].si= ze - 1); + error_setg(errp, "%s: overlapping sparse mmap regions dete= cted " + "in region %d: [0x%"PRIx64"-0x%"PRIx64"] overla= ps " + "with [0x%"PRIx64"-0x%"PRIx64"]", + __func__, region->nr, region->mmaps[i - 1].offs= et, + prev_end - 1, region->mmaps[i].offset, + region->mmaps[i].offset + region->mmaps[i].size= - 1); g_free(region->mmaps); region->mmaps =3D NULL; region->nr_mmaps =3D 0; @@ -228,13 +229,14 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion = *region, } =20 int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, - int index, const char *name) + int index, const char *name, Error **errp) { struct vfio_region_info *info =3D NULL; int ret; =20 ret =3D vfio_device_get_region_info(vbasedev, index, &info); if (ret) { + error_setg_errno(errp, -ret, "failed to get region %d info", index= ); return ret; } =20 @@ -253,7 +255,7 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, if (!vbasedev->no_mmap && region->flags & VFIO_REGION_INFO_FLAG_MMAP) { =20 - ret =3D vfio_setup_region_sparse_mmaps(region, info); + ret =3D vfio_setup_region_sparse_mmaps(region, info, errp); =20 if (ret =3D=3D -ENODEV) { region->nr_mmaps =3D 1; --=20 2.53.0