From nobody Mon Nov 25 09:54:40 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1716371793; cv=none; d=zohomail.com; s=zohoarc; b=Tm8JpvWagCb6EYCmRT3juROhHex+t1bybX5YdMmNZYsO0aWQRO+Xcbxgngma2AF+cUMS2fEi7TgYY0CJgVTNEoeBO6QbDF2PMT5BKmQcQDY1s4VB0frB9d3tt3HNFN3pfJlMs/tqtH4HO5Y3+gNLZ/ZF/oeo/DB6FjI75he/okE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371793; 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=3nCWXrD6ivgfDK6SHjy3Gb4DsacAI2nGBU3PXSO9MP8=; b=TFivcHoIj2X7PkfKGMc0AOpxnZ2AdWoSe3NWbjQxEc2XEqZmBOhx6EMS6y2ajV/1ViJBpp1Dfh1SLCFf3ogThD3CsGIFNeBAX/fygERgGt3PBpsmcUg+TtbWuLx39yd/dTAcvxvqZgcI2ORjpbWr76EJZZSh+DKEceUrP6P7UoA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716371793212342.5298009023219; Wed, 22 May 2024 02:56:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igm-0003R5-IM; Wed, 22 May 2024 05:55:16 -0400 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 1s9igb-0003LZ-Ux for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9igZ-0001Mo-O3 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:05 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-141-WSEKRwQ3Nladi5yTED6qNw-1; Wed, 22 May 2024 05:55:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id E37DF3C025C9; Wed, 22 May 2024 09:55:00 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F2FB7414; Wed, 22 May 2024 09:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371703; 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=3nCWXrD6ivgfDK6SHjy3Gb4DsacAI2nGBU3PXSO9MP8=; b=ZCERslPQDIZ3DVsWIs1/pR3rAE2PceyouzKqzam+sd+qQsDUNaFChOI2escn5HEG2j39UX kHncycsqAM9FFbZXQrm88jq/olzr4vapNkYtdHi7Rglj0Hv27Qji5prE3zmI1Wun6pzKoF PF4tDTlzzEIReuWJf1EqRP1t67M1ca8= X-MC-Unique: WSEKRwQ3Nladi5yTED6qNw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Eric Auger , Avihai Horon Subject: [PULL 08/47] vfio: Add Error** argument to .get_dirty_bitmap() handler Date: Wed, 22 May 2024 11:54:03 +0200 Message-ID: <20240522095442.195243-9-clg@redhat.com> In-Reply-To: <20240522095442.195243-1-clg@redhat.com> References: <20240522095442.195243-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.4.1 on 10.11.54.5 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.129.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.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: 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: 1716371794832100006 Let the callers do the error reporting. Add documentation while at it. Reviewed-by: Eric Auger Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 5 +-- include/hw/vfio/vfio-container-base.h | 19 +++++++-- hw/vfio/common.c | 60 +++++++++++++++++---------- hw/vfio/container-base.c | 6 +-- hw/vfio/container.c | 14 ++++--- 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 3ff633ad3b395e953a55683f5f0308bca50af3dd..b6ac24953667bc5f72f28480a6b= f0f4722069cb9 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -273,10 +273,9 @@ vfio_devices_all_running_and_mig_active(const VFIOCont= ainerBase *bcontainer); bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer= ); int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, - hwaddr size); + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp); int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, - uint64_t size, ram_addr_t ram_addr); + uint64_t size, ram_addr_t ram_addr, Error **errp= ); =20 /* Returns 0 on success, or a negative errno. */ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 326ceea52a2030eec9dad289a9845866c4a8c090..b04057ad1aff73d974ecec718d0= fe45f7a930b59 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -84,8 +84,7 @@ void vfio_container_del_section_window(VFIOContainerBase = *bcontainer, int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, bool start, Error **errp); int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, - hwaddr iova, hwaddr size); + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp); =20 void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space, @@ -138,9 +137,21 @@ struct VFIOIOMMUClass { */ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, bool start, Error **errp); + /** + * @query_dirty_bitmap + * + * Get bitmap of dirty pages from container + * + * @bcontainer: #VFIOContainerBase from which to get dirty pages + * @vbmap: #VFIOBitmap internal bitmap structure + * @iova: iova base address + * @size: size of iova range + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error + */ int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, - hwaddr iova, hwaddr size); + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp); /* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev, bool single); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7313043f1d161ed0326b5ba3fa1085608eaf6740..1fbd10801d35079341a833fa68a= 43de2b758cde0 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1140,8 +1140,7 @@ static int vfio_device_dma_logging_report(VFIODevice = *vbasedev, hwaddr iova, } =20 int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, hwaddr iova, - hwaddr size) + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp) { VFIODevice *vbasedev; int ret; @@ -1150,10 +1149,10 @@ int vfio_devices_query_dirty_bitmap(const VFIOConta= inerBase *bcontainer, ret =3D vfio_device_dma_logging_report(vbasedev, iova, size, vbmap->bitmap); if (ret) { - error_report("%s: Failed to get DMA logging report, iova: " - "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx - ", err: %d (%s)", - vbasedev->name, iova, size, ret, strerror(-ret)); + error_setg_errno(errp, -ret, + "%s: Failed to get DMA logging report, iova: " + "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx, + vbasedev->name, iova, size); =20 return ret; } @@ -1163,7 +1162,7 @@ int vfio_devices_query_dirty_bitmap(const VFIOContain= erBase *bcontainer, } =20 int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, - uint64_t size, ram_addr_t ram_addr) + uint64_t size, ram_addr_t ram_addr, Error **errp) { bool all_device_dirty_tracking =3D vfio_devices_all_device_dirty_tracking(bcontainer); @@ -1180,13 +1179,17 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *= bcontainer, uint64_t iova, =20 ret =3D vfio_bitmap_alloc(&vbmap, size); if (ret) { + error_setg_errno(errp, -ret, + "Failed to allocate dirty tracking bitmap"); return ret; } =20 if (all_device_dirty_tracking) { - ret =3D vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, = size); + ret =3D vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, = size, + errp); } else { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size); + ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size, + errp); } =20 if (ret) { @@ -1234,12 +1237,13 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifi= er *n, IOMMUTLBEntry *iotlb) } =20 ret =3D vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1, - translated_addr); + translated_addr, &local_err); if (ret) { - error_report("vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx") =3D %d (%s)", - bcontainer, iova, iotlb->addr_mask + 1, ret, - strerror(-ret)); + error_prepend(&local_err, + "vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") failed - ", bcontainer, iova, + iotlb->addr_mask + 1); + error_report_err(local_err); } =20 out_unlock: @@ -1259,12 +1263,19 @@ static int vfio_ram_discard_get_dirty_bitmap(Memory= RegionSection *section, const ram_addr_t ram_addr =3D memory_region_get_ram_addr(section->mr) + section->offset_within_region; VFIORamDiscardListener *vrdl =3D opaque; + Error *local_err =3D NULL; + int ret; =20 /* * Sync the whole mapped region (spanning multiple individual mappings) * in one go. */ - return vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr); + ret =3D vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr, + &local_err); + if (ret) { + error_report_err(local_err); + } + return ret; } =20 static int @@ -1296,7 +1307,7 @@ vfio_sync_ram_discard_listener_dirty_bitmap(VFIOConta= inerBase *bcontainer, } =20 static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, - MemoryRegionSection *section) + MemoryRegionSection *section, Error **er= rp) { ram_addr_t ram_addr; =20 @@ -1327,7 +1338,14 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase = *bcontainer, } return 0; } else if (memory_region_has_ram_discard_manager(section->mr)) { - return vfio_sync_ram_discard_listener_dirty_bitmap(bcontainer, sec= tion); + int ret; + + ret =3D vfio_sync_ram_discard_listener_dirty_bitmap(bcontainer, se= ction); + if (ret) { + error_setg(errp, + "Failed to sync dirty bitmap with RAM discard liste= ner"); + } + return ret; } =20 ram_addr =3D memory_region_get_ram_addr(section->mr) + @@ -1335,7 +1353,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *= bcontainer, =20 return vfio_get_dirty_bitmap(bcontainer, REAL_HOST_PAGE_ALIGN(section->offset_within_address_spa= ce), - int128_get64(section->size), ram_addr); + int128_get64(section->size), ram_addr, er= rp); } =20 static void vfio_listener_log_sync(MemoryListener *listener, @@ -1344,16 +1362,16 @@ static void vfio_listener_log_sync(MemoryListener *= listener, VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); int ret; + Error *local_err =3D NULL; =20 if (vfio_listener_skipped_section(section)) { return; } =20 if (vfio_devices_all_dirty_tracking(bcontainer)) { - ret =3D vfio_sync_dirty_bitmap(bcontainer, section); + ret =3D vfio_sync_dirty_bitmap(bcontainer, section, &local_err); if (ret) { - error_report("vfio: Failed to sync dirty bitmap, err: %d (%s)"= , ret, - strerror(-ret)); + error_report_err(local_err); vfio_set_migration_error(ret); } } diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 7c0764121d24b02b6c4e66e368d7dff78a6d65aa..26f4bb464a720c9895b35c7c9e0= 1c84d6322c3c9 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -64,11 +64,11 @@ int vfio_container_set_dirty_page_tracking(VFIOContaine= rBase *bcontainer, } =20 int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, - VFIOBitmap *vbmap, - hwaddr iova, hwaddr size) + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **er= rp) { g_assert(bcontainer->ops->query_dirty_bitmap); - return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, si= ze); + return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, si= ze, + errp); } =20 void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *= space, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index c35221fbe7dc5453050f97cd186fc958e24f28f7..9534120d4ac835bb58e37667dad= 8d39205404c08 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -130,6 +130,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBas= e *bcontainer, }; bool need_dirty_sync =3D false; int ret; + Error *local_err =3D NULL; =20 if (iotlb && vfio_devices_all_running_and_mig_active(bcontainer)) { if (!vfio_devices_all_device_dirty_tracking(bcontainer) && @@ -165,8 +166,9 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBas= e *bcontainer, =20 if (need_dirty_sync) { ret =3D vfio_get_dirty_bitmap(bcontainer, iova, size, - iotlb->translated_addr); + iotlb->translated_addr, &local_err); if (ret) { + error_report_err(local_err); return ret; } } @@ -235,8 +237,7 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainer= Base *bcontainer, } =20 static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontai= ner, - VFIOBitmap *vbmap, - hwaddr iova, hwaddr size) + VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error *= *errp) { const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, bcontainer); @@ -264,9 +265,10 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOCo= ntainerBase *bcontainer, ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, dbitmap); if (ret) { ret =3D -errno; - error_report("Failed to get dirty bitmap for iova: 0x%"PRIx64 - " size: 0x%"PRIx64" err: %d", (uint64_t)range->iova, - (uint64_t)range->size, errno); + error_setg_errno(errp, errno, + "Failed to get dirty bitmap for iova: 0x%"PRIx64 + " size: 0x%"PRIx64, (uint64_t)range->iova, + (uint64_t)range->size); } =20 g_free(dbitmap); --=20 2.45.1