From nobody Mon Nov 25 09:42:00 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=1715700856; cv=none; d=zohomail.com; s=zohoarc; b=ZENFo3YmuzxrGRIZBJJvxfS1c7km2eF9Z101stsKX+ixMIGsZGHv+2MH2qIIRVKT/U1+wQJK1vUCMvkIxqg0PE1JLWhqw/CAX/0uorj5mhpMNKpX578Ib0K9bxTOkV15xhziBKQRCtCKR8dqnqDORTeLKXG+3ct/2yFM7Gjqi7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700856; 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=saACD+bKt08Zn3rOT2iSL9usk+oPqoqtWSgLCYRdEDE=; b=deLGWrHb4lCKMfr8dAwjyykJjhkzL66TrZHa8eXo9AWFJTekE70uE/Cd6u5/5uRvxN5upqt0v1petsWa2evSpOXBiDoJxC/qmNLUbiwgQEo/0d2VZNpcb3Zyix6XwEB7FJFyAUQraLLfNMzhJGRx4M+DsRk384cgOwKYaN2vAqc= 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 1715700856889954.7364056197849; Tue, 14 May 2024 08:34:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8A-0001I5-Ss; Tue, 14 May 2024 11:31:55 -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 1s6u7z-0001CY-Mx for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:43 -0400 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 1s6u7x-0000Vw-Op for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:43 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-248-xB27HLVoNdmKo9VzjdPrMQ-1; Tue, 14 May 2024 11:31:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 BBD828E7802; Tue, 14 May 2024 15:31:35 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id E57EA200BFC7; Tue, 14 May 2024 15:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700700; 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=saACD+bKt08Zn3rOT2iSL9usk+oPqoqtWSgLCYRdEDE=; b=RoDwhUmyl35BTgItxicbQZwLj3G5ptXKCWg11CBIiAMH14RgnmuU2KzLlpqmB/MV3YeyD3 JFdCzeHa/7T65dRnr13OD04cXU9MIHBaGgTAdcfC+BzCUIOTu0ZckypLvRjeuK5oOYca19 UVkbbf0KuZx9zQD2hfwok52G8tVNDEk= X-MC-Unique: xB27HLVoNdmKo9VzjdPrMQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 1/9] vfio: Add Error** argument to .set_dirty_page_tracking() handler Date: Tue, 14 May 2024 17:31:22 +0200 Message-ID: <20240514153130.394307-2-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700858851100004 We will use the Error object to improve error reporting in the .log_global*() handlers of VFIO. Add documentation while at it. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- Changes in v5: - Fixed typo in set_dirty_page_tracking documentation =20 include/hw/vfio/vfio-container-base.h | 18 ++++++++++++++++-- hw/vfio/common.c | 4 ++-- hw/vfio/container-base.c | 4 ++-- hw/vfio/container.c | 6 +++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 3582d5f97a37877b2adfc0d0b06996c82403f8b7..326ceea52a2030eec9dad289a98= 45866c4a8c090 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -82,7 +82,7 @@ int vfio_container_add_section_window(VFIOContainerBase *= bcontainer, void vfio_container_del_section_window(VFIOContainerBase *bcontainer, MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, - bool start); + bool start, Error **errp); int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size); @@ -121,9 +121,23 @@ struct VFIOIOMMUClass { int (*attach_device)(const char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void (*detach_device)(VFIODevice *vbasedev); + /* migration feature */ + + /** + * @set_dirty_page_tracking + * + * Start or stop dirty pages tracking on VFIO container + * + * @bcontainer: #VFIOContainerBase on which to de/activate dirty + * page tracking + * @start: indicates whether to start or stop dirty pages tracking + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error + */ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, - bool start); + bool start, Error **errp); int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 8f9cbdc0264044ce587877a7d19d14b28527291b..485e53916491f1164d29e739fb7= 106c0c77df737 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1076,7 +1076,7 @@ static bool vfio_listener_log_global_start(MemoryList= ener *listener, if (vfio_devices_all_device_dirty_tracking(bcontainer)) { ret =3D vfio_devices_dma_logging_start(bcontainer); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true, N= ULL); } =20 if (ret) { @@ -1096,7 +1096,7 @@ static void vfio_listener_log_global_stop(MemoryListe= ner *listener) if (vfio_devices_all_device_dirty_tracking(bcontainer)) { vfio_devices_dma_logging_stop(bcontainer); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, = NULL); } =20 if (ret) { diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 913ae49077c4f09b7b27517c1231cfbe4befb7fb..7c0764121d24b02b6c4e66e368d= 7dff78a6d65aa 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -53,14 +53,14 @@ void vfio_container_del_section_window(VFIOContainerBas= e *bcontainer, } =20 int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, - bool start) + bool start, Error **errp) { if (!bcontainer->dirty_pages_supported) { return 0; } =20 g_assert(bcontainer->ops->set_dirty_page_tracking); - return bcontainer->ops->set_dirty_page_tracking(bcontainer, start); + return bcontainer->ops->set_dirty_page_tracking(bcontainer, start, err= p); } =20 int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 77bdec276ec49cb9cd767c0de42ec801b4421572..c35221fbe7dc5453050f97cd186= fc958e24f28f7 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -209,7 +209,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase = *bcontainer, hwaddr iova, =20 static int vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, - bool start) + bool start, Error **errp) { const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, bcontainer); @@ -227,8 +227,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainer= Base *bcontainer, ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, &dirty); if (ret) { ret =3D -errno; - error_report("Failed to set dirty tracking flag 0x%x errno: %d", - dirty.flags, errno); + error_setg_errno(errp, errno, "Failed to set dirty tracking flag 0= x%x", + dirty.flags); } =20 return ret; --=20 2.45.0 From nobody Mon Nov 25 09:42:00 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=1715700746; cv=none; d=zohomail.com; s=zohoarc; b=bjZ5dgRpzQNFgOgpKMEMbl5TRNULDplWVCzLg9mXzk96tnj6SS1jKW7/eQI/P4H84fjVoYsS1tcidh3RSPJquLRnDs6mL7g3npYRp8teUswt/d57MDAysm7fwbLS0dIgrlc6XPSaL1hbh1l637oUW7+GtZ5QaqA34nKsR7RM/BU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700746; 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=skSkJAZzco+gEh+aakE4hP8APfXoDw0JW8wFT7bOv/c=; b=jP7bNwM5kqn2YV3dQUIhl14zr5vC6pdAUDZiKVBjPeRzk0kIPtqC7FF3nOj3wlwanGG8Bvitgsij3Idg9X/EQlDJfwple7s/PzlNv0H8bnnEqKUlZ1Ar5N9qiwmoo+/PhfpeM8tcRJ1vIcHfiWqA9DSsfpsVRQPQsfVMRgtKrlk= 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 1715700746936987.6182959750834; Tue, 14 May 2024 08:32:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8G-0001NS-Lj; Tue, 14 May 2024 11:32:04 -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 1s6u81-0001Cn-2i for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:46 -0400 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 1s6u7x-0000Vr-SR for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:44 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-ST3SuB_qMaa39lkfLmDhRQ-1; Tue, 14 May 2024 11:31:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 24A0D801152; Tue, 14 May 2024 15:31:38 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id F136C21EE56B; Tue, 14 May 2024 15:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700700; 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=skSkJAZzco+gEh+aakE4hP8APfXoDw0JW8wFT7bOv/c=; b=XMa/5rWQpML3VU8TtlRyCmnWc0NXoavyvGNmnMyO0jbaEW7ANB7NsVGS0SGzezwjM8wmSC NBjhr4KuPwy9Ka8fLNoNVrP5gR5LAQzEOa/qeqI7GGs6+lYGfkg/hgHr45cGEKIwJMtBov N/VJC1V7E6KaicnnohVRxRfUzOm9ELg= X-MC-Unique: ST3SuB_qMaa39lkfLmDhRQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 2/9] vfio: Add Error** argument to vfio_devices_dma_logging_start() Date: Tue, 14 May 2024 17:31:23 +0200 Message-ID: <20240514153130.394307-3-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700748329100001 This allows to update the Error argument of the VFIO log_global_start() handler. Errors for container based logging will also be propagated to qemu_savevm_state_setup() when the ram save_setup() handler is executed. The vfio_set_migration_error() call becomes redundant in vfio_listener_log_global_start(). Remove it. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- Changes in v6: - Commit log improvements (Avihai) =20 Changes in v5: - Used error_setg_errno() in vfio_devices_dma_logging_start() =20 hw/vfio/common.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 485e53916491f1164d29e739fb7106c0c77df737..b5102f54a6474a50c6366e8fbce= 23812d55e384e 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1027,7 +1027,8 @@ static void vfio_device_feature_dma_logging_start_des= troy( g_free(feature); } =20 -static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) +static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer, + Error **errp) { struct vfio_device_feature *feature; VFIODirtyRanges ranges; @@ -1038,6 +1039,7 @@ static int vfio_devices_dma_logging_start(VFIOContain= erBase *bcontainer) feature =3D vfio_device_feature_dma_logging_start_create(bcontainer, &ranges); if (!feature) { + error_setg_errno(errp, errno, "Failed to prepare DMA logging"); return -errno; } =20 @@ -1049,8 +1051,8 @@ static int vfio_devices_dma_logging_start(VFIOContain= erBase *bcontainer) ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature); if (ret) { ret =3D -errno; - error_report("%s: Failed to start DMA logging, err %d (%s)", - vbasedev->name, ret, strerror(errno)); + error_setg_errno(errp, errno, "%s: Failed to start DMA logging= ", + vbasedev->name); goto out; } vbasedev->dirty_tracking =3D true; @@ -1069,20 +1071,19 @@ out: static bool vfio_listener_log_global_start(MemoryListener *listener, Error **errp) { + ERRP_GUARD(); VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); int ret; =20 if (vfio_devices_all_device_dirty_tracking(bcontainer)) { - ret =3D vfio_devices_dma_logging_start(bcontainer); + ret =3D vfio_devices_dma_logging_start(bcontainer, errp); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true, N= ULL); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true, e= rrp); } =20 if (ret) { - error_report("vfio: Could not start dirty page tracking, err: %d (= %s)", - ret, strerror(-ret)); - vfio_set_migration_error(ret); + error_prepend(errp, "vfio: Could not start dirty page tracking - "= ); } return !ret; } @@ -1091,17 +1092,20 @@ static void vfio_listener_log_global_stop(MemoryLis= tener *listener) { VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); + Error *local_err =3D NULL; int ret =3D 0; =20 if (vfio_devices_all_device_dirty_tracking(bcontainer)) { vfio_devices_dma_logging_stop(bcontainer); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, = NULL); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, + &local_err); } =20 if (ret) { - error_report("vfio: Could not stop dirty page tracking, err: %d (%= s)", - ret, strerror(-ret)); + error_prepend(&local_err, + "vfio: Could not stop dirty page tracking - "); + error_report_err(local_err); vfio_set_migration_error(ret); } } --=20 2.45.0 From nobody Mon Nov 25 09:42:00 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=1715700797; cv=none; d=zohomail.com; s=zohoarc; b=jsY8TTYN06/0xM6lba4WlOS6LoBtJ7t/kKEdM2HsWvGs/76w3RRsP8EjeTb5kLHdwpve5ZoXZqh3hNvHJNFlHLa+QTrcYIAZRrPbdR2FMjq93U/SlBEi2J22sKxtj2tFzWR3kJFgIdxewWTaCporIGHBxISsuNb/IYX2Va5EPGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700797; 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=FzcOFvM5eOI4Tz2O6INEtGmcZVpBGOn4j7Ks5j78BvE=; b=SDYAiL1JtoKES3We0cZSLwdK6TQCdEDLo9JbM+RXjRF9YXYE/C9IJjVOBcXKXlwwglIpDIjUxXaPMcBpG5KQP4STyggzi9WhewIZgISO+pGjRYAKGqqzdjsiaKqLdEaZC6x0uiCEH/1/ddO54vj5o0G27enrVbHeWF19RDwMHTY= 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 1715700797495335.55541372679806; Tue, 14 May 2024 08:33:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8D-0001KZ-Au; Tue, 14 May 2024 11:31:57 -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 1s6u83-0001FO-U4 for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:53 -0400 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 1s6u82-0000Wv-5S for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:47 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-TaS7c8fxOeaFiFE3SmQ4jw-1; Tue, 14 May 2024 11:31:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 2EA0218172C4; Tue, 14 May 2024 15:31:40 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 593E5200BD73; Tue, 14 May 2024 15:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700704; 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=FzcOFvM5eOI4Tz2O6INEtGmcZVpBGOn4j7Ks5j78BvE=; b=UAvZptDuTqAq5T9wYwXH64FqDCOz13PgCCZYCc7EqkWBryTNDhUaDCQsCCCHOABUE9cg/o IKqCnNqVfNea3XVJpWDC7RWwmvl3zNfgA9naGSpo4B1Dlvlt5X6N3LJL2x7r3yCQW3TP61 TXN6YB4BuTkV0/jEFqevBEWkYJcatZA= X-MC-Unique: TaS7c8fxOeaFiFE3SmQ4jw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 3/9] migration: Extend migration_file_set_error() with Error* argument Date: Tue, 14 May 2024 17:31:24 +0200 Message-ID: <20240514153130.394307-4-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700798563100001 Use it to update the current error of the migration stream if available and if not, simply print out the error. Next changes will update with an error to report. Reviewed-by: Avihai Horon Acked-by: Fabiano Rosas Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- Changes in v6: - Commit log improvements (Avihai) =20 include/migration/misc.h | 2 +- hw/vfio/common.c | 2 +- hw/vfio/migration.c | 4 ++-- migration/migration.c | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index bf7339cc1e6430226127fb6a878d06b458170858..bfadc5613bac614a316e5aed7da= 95d8c7845cf42 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -97,7 +97,7 @@ void migration_add_notifier_mode(NotifierWithReturn *noti= fy, =20 void migration_remove_notifier(NotifierWithReturn *notify); bool migration_is_running(void); -void migration_file_set_error(int err); +void migration_file_set_error(int ret, Error *err); =20 /* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ bool migration_in_incoming_postcopy(void); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b5102f54a6474a50c6366e8fbce23812d55e384e..ed5ee6349ced78b3bde68d2ee50= 6f78ba1a9dd9c 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -150,7 +150,7 @@ bool vfio_viommu_preset(VFIODevice *vbasedev) static void vfio_set_migration_error(int err) { if (migration_is_setup_or_active()) { - migration_file_set_error(err); + migration_file_set_error(err, NULL); } } =20 diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 06ae40969b6c19037e190008e14f28be646278cd..bf2fd0759ba6e4fb103cc5c1a43= edb180a3d0de4 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -726,7 +726,7 @@ static void vfio_vmstate_change_prepare(void *opaque, b= ool running, * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ - migration_file_set_error(ret); + migration_file_set_error(ret, NULL); } =20 trace_vfio_vmstate_change_prepare(vbasedev->name, running, @@ -756,7 +756,7 @@ static void vfio_vmstate_change(void *opaque, bool runn= ing, RunState state) * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ - migration_file_set_error(ret); + migration_file_set_error(ret, NULL); } =20 trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state), diff --git a/migration/migration.c b/migration/migration.c index e88b24f1e6cbe82dad3f890c00e264d2ab6ad355..70d66a441bf04761decf91dbe57= ce52c57fde58f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2994,13 +2994,15 @@ static MigThrError postcopy_pause(MigrationState *s) } } =20 -void migration_file_set_error(int err) +void migration_file_set_error(int ret, Error *err) { MigrationState *s =3D current_migration; =20 WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) { if (s->to_dst_file) { - qemu_file_set_error(s->to_dst_file, err); + qemu_file_set_error_obj(s->to_dst_file, ret, err); + } else if (err) { + error_report_err(err); } } } --=20 2.45.0 From nobody Mon Nov 25 09:42:00 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=1715700824; cv=none; d=zohomail.com; s=zohoarc; b=Z+3pBmgVhj7tu4Ds57sBjgYwXLqcoO+lubRq0e+gHUiJMTmkNLKis+RLQKQLbU/yMpLRwII2gWDB5PepltvZfnR7fVjJehREMYrSHDflK0H+QbAFrXmyW6aAXBtfIOUyWXIXBvFRWF5bNCCLQXdZvvWqrUabDoThO6knKqxkMzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700824; 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=Gx+mObJs2xLSb1nLxVDx2aLwOcLqA+MHWNsFeFjiTiE=; b=cTWQiYqU45FlylSGBV8vZ0tw7JW5JPseJQJnH/Xuyqu6iOmtrTB2rjD0kjVIRtz0JXwbK9ocG05V3HMF/G7pPXtIv5iDqSDCKiSL79E1EDQOa3s4OIa+PUvxG4XVK+ZR+JKS0ZSLkrzDspFq61yoawa0qaynGzQvZaGduQ549Gg= 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 1715700824652310.2030016189484; Tue, 14 May 2024 08:33:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8F-0001LU-2q; Tue, 14 May 2024 11:31:59 -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 1s6u8A-0001JA-TF for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:55 -0400 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 1s6u85-0000Xq-AQ for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:54 -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-620-BtJX5q-YN6S3fuAXymj1jQ-1; Tue, 14 May 2024 11:31:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 39CF03C0C2C0; Tue, 14 May 2024 15:31:42 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64298200BD83; Tue, 14 May 2024 15:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700707; 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=Gx+mObJs2xLSb1nLxVDx2aLwOcLqA+MHWNsFeFjiTiE=; b=PPDUeKwMYjQgCVKMBRWkwCqUQZZl0qpllB3EPSxUiXQoVu6KK7X/AQ+CGpG7CFPKHnnXOe mg2eBedMASoziPf+48JOPCCXDBbEw9ZZ3keLXfRc+V1296K9T1w0/imADhkyuaGtZwOxzE z+FawYMjYtClwP25/mVzmjd9DbRue0M= X-MC-Unique: BtJX5q-YN6S3fuAXymj1jQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 4/9] vfio/migration: Add an Error** argument to vfio_migration_set_state() Date: Tue, 14 May 2024 17:31:25 +0200 Message-ID: <20240514153130.394307-5-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700826715100001 Add an Error** argument to vfio_migration_set_state() and adjust callers, including vfio_save_setup(). The error will be propagated up to qemu_savevm_state_setup() where the save_setup() handler is executed. Modify vfio_vmstate_change_prepare() and vfio_vmstate_change() to store a reported error under the migration stream if a migration is in progress. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Avihai Horon --- Changes in v6: - Commit log improvements (Avihai)=20 - vfio_migration_set_state() : Dropped the error_setg_errno() change when setting device in recover state fails (Avihai) =20 - vfio_migration_state_notifier() : report local error (Avihai)=20 =20 Changes in v5: - Replaced error_setg() by error_setg_errno() in vfio_migration_set_state() - Rebased on 20c64c8a51a4 ("migration: migration_file_set_error") =20 hw/vfio/migration.c | 77 ++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index bf2fd0759ba6e4fb103cc5c1a43edb180a3d0de4..bf11135167ebb162dd41415656b= dacfa0e1ca550 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -82,7 +82,8 @@ static const char *mig_state_to_str(enum vfio_device_mig_= state state) =20 static int vfio_migration_set_state(VFIODevice *vbasedev, enum vfio_device_mig_state new_state, - enum vfio_device_mig_state recover_sta= te) + enum vfio_device_mig_state recover_sta= te, + Error **errp) { VFIOMigration *migration =3D vbasedev->migration; uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) + @@ -102,18 +103,19 @@ static int vfio_migration_set_state(VFIODevice *vbase= dev, ret =3D -errno; =20 if (recover_state =3D=3D VFIO_DEVICE_STATE_ERROR) { - error_report("%s: Failed setting device state to %s, err: %s. " - "Recover state is ERROR. Resetting device", - vbasedev->name, mig_state_to_str(new_state), - strerror(errno)); + error_setg_errno(errp, errno, + "%s: Failed setting device state to %s. " + "Recover state is ERROR. Resetting device", + vbasedev->name, mig_state_to_str(new_state)); =20 goto reset_device; } =20 - error_report( - "%s: Failed setting device state to %s, err: %s. Setting devic= e in recover state %s", - vbasedev->name, mig_state_to_str(new_state), - strerror(errno), mig_state_to_str(recover_state)); + error_setg_errno(errp, errno, + "%s: Failed setting device state to %s. " + "Setting device in recover state %s", + vbasedev->name, mig_state_to_str(new_state), + mig_state_to_str(recover_state)); =20 mig_state->device_state =3D recover_state; if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) { @@ -137,7 +139,7 @@ static int vfio_migration_set_state(VFIODevice *vbasede= v, * This can happen if the device is asynchronously reset and * terminates a data transfer. */ - error_report("%s: data_fd out of sync", vbasedev->name); + error_setg(errp, "%s: data_fd out of sync", vbasedev->name); close(mig_state->data_fd); =20 return -EBADF; @@ -168,10 +170,11 @@ reset_device: */ static int vfio_migration_set_state_or_reset(VFIODevice *vbasedev, - enum vfio_device_mig_state new_state) + enum vfio_device_mig_state new_state, + Error **errp) { return vfio_migration_set_state(vbasedev, new_state, - VFIO_DEVICE_STATE_ERROR); + VFIO_DEVICE_STATE_ERROR, errp); } =20 static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev, @@ -399,10 +402,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, = Error **errp) switch (migration->device_state) { case VFIO_DEVICE_STATE_RUNNING: ret =3D vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_P= RE_COPY, - VFIO_DEVICE_STATE_RUNNING); + VFIO_DEVICE_STATE_RUNNING, errp= ); if (ret) { - error_setg(errp, "%s: Failed to set new PRE_COPY state", - vbasedev->name); return ret; } =20 @@ -435,13 +436,20 @@ static void vfio_save_cleanup(void *opaque) { VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; + Error *local_err =3D NULL; + int ret; =20 /* * Changing device state from STOP_COPY to STOP can take time. Do it h= ere, * after migration has completed, so it won't increase downtime. */ if (migration->device_state =3D=3D VFIO_DEVICE_STATE_STOP_COPY) { - vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_STOP= ); + ret =3D vfio_migration_set_state_or_reset(vbasedev, + VFIO_DEVICE_STATE_STOP, + &local_err); + if (ret) { + error_report_err(local_err); + } } =20 g_free(migration->data_buffer); @@ -549,11 +557,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, vo= id *opaque) VFIODevice *vbasedev =3D opaque; ssize_t data_size; int ret; + Error *local_err =3D NULL; =20 /* We reach here with device state STOP or STOP_COPY only */ ret =3D vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY, - VFIO_DEVICE_STATE_STOP); + VFIO_DEVICE_STATE_STOP, &local_err); if (ret) { + error_report_err(local_err); return ret; } =20 @@ -591,14 +601,9 @@ static void vfio_save_state(QEMUFile *f, void *opaque) static int vfio_load_setup(QEMUFile *f, void *opaque, Error **errp) { VFIODevice *vbasedev =3D opaque; - int ret; =20 - ret =3D vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING, - vbasedev->migration->device_state); - if (ret) { - error_setg(errp, "%s: Failed to set RESUMING state", vbasedev->nam= e); - } - return ret; + return vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING, + vbasedev->migration->device_state, err= p); } =20 static int vfio_load_cleanup(void *opaque) @@ -714,19 +719,20 @@ static void vfio_vmstate_change_prepare(void *opaque,= bool running, VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; enum vfio_device_mig_state new_state; + Error *local_err =3D NULL; int ret; =20 new_state =3D migration->device_state =3D=3D VFIO_DEVICE_STATE_PRE_COP= Y ? VFIO_DEVICE_STATE_PRE_COPY_P2P : VFIO_DEVICE_STATE_RUNNING_P2P; =20 - ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state); + ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state, &local_= err); if (ret) { /* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ - migration_file_set_error(ret, NULL); + migration_file_set_error(ret, local_err); } =20 trace_vfio_vmstate_change_prepare(vbasedev->name, running, @@ -738,6 +744,7 @@ static void vfio_vmstate_change(void *opaque, bool runn= ing, RunState state) { VFIODevice *vbasedev =3D opaque; enum vfio_device_mig_state new_state; + Error *local_err =3D NULL; int ret; =20 if (running) { @@ -750,13 +757,13 @@ static void vfio_vmstate_change(void *opaque, bool ru= nning, RunState state) VFIO_DEVICE_STATE_STOP; } =20 - ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state); + ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state, &local_= err); if (ret) { /* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ - migration_file_set_error(ret, NULL); + migration_file_set_error(ret, local_err); } =20 trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state), @@ -769,11 +776,23 @@ static int vfio_migration_state_notifier(NotifierWith= Return *notifier, VFIOMigration *migration =3D container_of(notifier, VFIOMigration, migration_state); VFIODevice *vbasedev =3D migration->vbasedev; + Error *local_err =3D NULL; + int ret =3D 0; =20 trace_vfio_migration_state_notifier(vbasedev->name, e->type); =20 if (e->type =3D=3D MIG_EVENT_PRECOPY_FAILED) { - vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_RUNN= ING); + /* + * MigrationNotifyFunc may return an error code and an Error + * object only for MIG_EVENT_PRECOPY_SETUP. Hence, report the + * error locally and ignore the errp argument. + */ + ret =3D vfio_migration_set_state_or_reset(vbasedev, + VFIO_DEVICE_STATE_RUNNING, + &local_err); + if (ret) { + error_report_err(local_err); + } } return 0; } --=20 2.45.0 From nobody Mon Nov 25 09:42:00 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=1715700803; cv=none; d=zohomail.com; s=zohoarc; b=AY/iYvOZcB9kS/e+7bsjqSV55oR/UX/vkMTyTYBEZXMw4VLaZUv3vAfMlUkNGZIQW2TYs6iR10N1Uw0JXUcYF4dKWkMdNg74M1DS0pLiXB1Id0Rj3hngYEVMPjwhGatC4S3iQP4yOFCync+VpTp7i+NcfV1IjOr3HAAq/+w0Iyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700803; 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=rK+eFhltoXf/OlRwmffea/C7FFa4EO5qVBzYs30vq/k=; b=XM+OHCV2AQPqUogJpXcYRQQkeOLTTqtCaFvy+lPF/WP1ryPGBBh+LCaaFPsRwNV4jJws+ap8oJAFwAK/WMRKJ4G6qVPwHRWKCHZx4bWilgbNSJ6txLPXSjUsJAHJyKiE12zfzEFCif6nkInrCNPjQbPZjuGfpp/tsDXS1rz01QQ= 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 1715700803081360.9941195371655; Tue, 14 May 2024 08:33:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8F-0001Ln-HH; Tue, 14 May 2024 11:31:59 -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 1s6u89-0001HQ-I0 for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:53 -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 1s6u85-0000Xx-Ac for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:53 -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-437-YVUZ1yK3MtiqXwCLP8refw-1; Tue, 14 May 2024 11:31:44 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 448671C3F0E4; Tue, 14 May 2024 15:31:44 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FE9721EE56C; Tue, 14 May 2024 15:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700708; 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=rK+eFhltoXf/OlRwmffea/C7FFa4EO5qVBzYs30vq/k=; b=gzBv9kS+5X7NTSCbemNQ5M0RO0rQJhcXQtBW5LqcFb5vMHB/p+xv7klvMVfidDVprvnXDh 5/7t/MzA0Bg7mFXjhyDmsjzPN/xV1/8Ennlc0fBLDJZJcGsqf1es+bd9w7gNZD1PF9mKQY y8GBG+/ehJJl7+uCIrcHuCjeSqAVscQ= X-MC-Unique: YVUZ1yK3MtiqXwCLP8refw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 5/9] vfio/migration: Add Error** argument to .vfio_save_config() handler Date: Tue, 14 May 2024 17:31:26 +0200 Message-ID: <20240514153130.394307-6-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700804571100001 Use vmstate_save_state_with_err() to improve error reporting in the callers and store a reported error under the migration stream. Add documentation while at it. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Avihai Horon Reviewed-by: Eric Auger --- Changes in v6: - Modified title (Avihai)=20 - vfio_save_device_config_state() : Set errp if the migration stream is in error (Avihai)=20 - vfio_save_state() : Changed error prefix (Avihai) =20 include/hw/vfio/vfio-common.h | 25 ++++++++++++++++++++++++- hw/vfio/migration.c | 25 ++++++++++++++++++------- hw/vfio/pci.c | 5 +++-- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b9da6c08ef41174610eb92726c590309a53696a3..46f88493634b5634a9c14a5caa3= 3a463fbf2c50d 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -133,7 +133,30 @@ struct VFIODeviceOps { int (*vfio_hot_reset_multi)(VFIODevice *vdev); void (*vfio_eoi)(VFIODevice *vdev); Object *(*vfio_get_object)(VFIODevice *vdev); - void (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f); + + /** + * @vfio_save_config + * + * Save device config state + * + * @vdev: #VFIODevice for which to save the config + * @f: #QEMUFile where to send the data + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error + */ + int (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f, Error **errp); + + /** + * @vfio_load_config + * + * Load device config state + * + * @vdev: #VFIODevice for which to load the config + * @f: #QEMUFile where to get the data + * + * Returns zero to indicate success and negative for error + */ int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); }; =20 diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index bf11135167ebb162dd41415656bdacfa0e1ca550..d089fa9b937e725307c1a567554= 95d5b8fae2065 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -189,21 +189,30 @@ static int vfio_load_buffer(QEMUFile *f, VFIODevice *= vbasedev, return ret; } =20 -static int vfio_save_device_config_state(QEMUFile *f, void *opaque) +static int vfio_save_device_config_state(QEMUFile *f, void *opaque, + Error **errp) { VFIODevice *vbasedev =3D opaque; + int ret; =20 qemu_put_be64(f, VFIO_MIG_FLAG_DEV_CONFIG_STATE); =20 if (vbasedev->ops && vbasedev->ops->vfio_save_config) { - vbasedev->ops->vfio_save_config(vbasedev, f); + ret =3D vbasedev->ops->vfio_save_config(vbasedev, f, errp); + if (ret) { + return ret; + } } =20 qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); =20 trace_vfio_save_device_config_state(vbasedev->name); =20 - return qemu_file_get_error(f); + ret =3D qemu_file_get_error(f); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to save state"); + } + return ret; } =20 static int vfio_load_device_config_state(QEMUFile *f, void *opaque) @@ -588,13 +597,15 @@ static int vfio_save_complete_precopy(QEMUFile *f, vo= id *opaque) static void vfio_save_state(QEMUFile *f, void *opaque) { VFIODevice *vbasedev =3D opaque; + Error *local_err =3D NULL; int ret; =20 - ret =3D vfio_save_device_config_state(f, opaque); + ret =3D vfio_save_device_config_state(f, opaque, &local_err); if (ret) { - error_report("%s: Failed to save device config space", - vbasedev->name); - qemu_file_set_error(f, ret); + error_prepend(&local_err, + "vfio: Failed to save device config space of %s - ", + vbasedev->name); + qemu_file_set_error_obj(f, ret, local_err); } } =20 diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 64780d1b793345c8e8996fe6b7987059ce831c11..fc6e54e871508bb0e2a3ac9079a= 195c086531f21 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2586,11 +2586,12 @@ static const VMStateDescription vmstate_vfio_pci_co= nfig =3D { } }; =20 -static void vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f) +static int vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f, Error *= *errp) { VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); =20 - vmstate_save_state(f, &vmstate_vfio_pci_config, vdev, NULL); + return vmstate_save_state_with_err(f, &vmstate_vfio_pci_config, vdev, = NULL, + errp); } =20 static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) --=20 2.45.0 From nobody Mon Nov 25 09:42:00 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=1715700768; cv=none; d=zohomail.com; s=zohoarc; b=gipZG9eA2efeQykfOaAPfUjjJIOP/VL6Fh7WP791sWkhBuAOyK7I4s0bjcWl1z+s3d07wWoj5GZdyQKU4qoRjkrQCqF5ywkrEhfTvalLum7HyeiGR+BDFIf19EU2oI9ZUFEpy/kWf99IT9JPJmxcBR5ZmCEyrosot5UHTsL4kWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700768; 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=HBscjC0rcNJY8obaoxNAUQuYtuw+I02aGW012sVdNHs=; b=JJzfCa2H7qvbMky9OO18qAI0HwXi+HH3NP/tHFS/XKM47fe8jqX6N1squIKyFpTYL7jFGNA82A3qgT+MCd2+GpZCPWcgu3v2rKTFNKFPUO90aq3AVt3Uq0KfqqUa22byVew22ZbHiyBSgytaiQPDlJW2YM1AJYahl6n5SMuVQ50= 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 1715700768022226.9733100426604; Tue, 14 May 2024 08:32:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8G-0001Mp-6n; Tue, 14 May 2024 11:32:00 -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 1s6u8A-0001J9-SY for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:55 -0400 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 1s6u87-0000YO-Bc for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:54 -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-652-Nf8RPR8sN0-enaFjxrbJJA-1; Tue, 14 May 2024 11:31:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 9B17B1C3F0E4; Tue, 14 May 2024 15:31:46 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79D6C200BAB1; Tue, 14 May 2024 15:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700708; 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=HBscjC0rcNJY8obaoxNAUQuYtuw+I02aGW012sVdNHs=; b=SCIBLM4RcDfIIZ+ITUme39uCmWwhYMrAN64aYWvf9LGAirop4Ic38NLPdTY3x57crpR+mV kTR9Zgg7hqg6DJ0GwQV/XqecXb8POMtUo7q23ptscFT8FK50heSAUcUkJnbHWFmyQbguhN K07HdQS+XeGvhCf5XbvE4DjQKtrrPV4= X-MC-Unique: Nf8RPR8sN0-enaFjxrbJJA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 6/9] vfio: Reverse test on vfio_get_xlat_addr() Date: Tue, 14 May 2024 17:31:27 +0200 Message-ID: <20240514153130.394307-7-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700770378100003 It will simplify the changes coming after. Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- Changes in v6: - Modified title (Avihai) - vfio_iommu_map_dirty_notify() : Modified goto label (Avihai) =20 hw/vfio/common.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ed5ee6349ced78b3bde68d2ee506f78ba1a9dd9c..4e2ef3d3034e72aa6a546bcb9ea= 1f31a0bbd5b1b 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1224,16 +1224,20 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifi= er *n, IOMMUTLBEntry *iotlb) } =20 rcu_read_lock(); - if (vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) { - ret =3D vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask += 1, - translated_addr); - 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)); - } + if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) { + goto out_unlock; } + + ret =3D vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1, + translated_addr); + 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)); + } + +out_unlock: rcu_read_unlock(); =20 out: --=20 2.45.0 From nobody Mon Nov 25 09:42:00 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=1715700803; cv=none; d=zohomail.com; s=zohoarc; b=aV7W1LyvzdYaszTZHzxIlzOicRHgZoTLnPOyHXFLVd//dZ6R848yeE4qG6zu6wa2wb2NVd5v4fpOX6PdBu3PkCKYyRJqetgWIBqd5XYI8g4doiuDWCkBxwXiBWcBWgq+xMmRiMIhBD9wwgL11v9lmZgeyusY0siIdaEBAOizLwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700803; 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=IZj2PfVq3ADGOsN3a8NEycy3x/pIN9gywBfbm7M6pUU=; b=CCJkI4yzDtIOJnUruQZPnBklKkcFWOqOQqzspVBLnl/Q6ZbDqJsNNLBzxs20ufKjcE5cjA79uUtmuQ8+ED26pRu3Eg30xVpAb1HYCGFZD8RIy9a0wDsNqP5ocjq/+nk5+5M6paOPIwFLzD8Wo8uEvHev/b71WVvTC560es8AxKw= 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 1715700803032129.52440601485353; Tue, 14 May 2024 08:33:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8p-0001Ua-O4; Tue, 14 May 2024 11:32:36 -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 1s6u8D-0001L1-K2 for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:57 -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 1s6u8B-0000a7-PF for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:57 -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-491-zeA3v4qrO6SvVZdv3WFFCA-1; Tue, 14 May 2024 11:31:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 77F8929AB407; Tue, 14 May 2024 15:31:49 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id D12AA21EE56C; Tue, 14 May 2024 15:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700715; 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=IZj2PfVq3ADGOsN3a8NEycy3x/pIN9gywBfbm7M6pUU=; b=NZDUGgvmzminBeyjfLaD4ObTYo2E5WJLv6t11BIf/2BQIU6Upx5d0UpUKnrQM8S4SFVD2n 2dqeaIc+kegZrc/YlLagwJLmV9otUsXaeSmDCQuuoHWsVnpT5G3r7tC3J7n8ZITfU7yIA1 EdN404DAlZMK3FZSgxOSdrykAul2QfY= X-MC-Unique: zeA3v4qrO6SvVZdv3WFFCA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand Subject: [PATCH v6 7/9] memory: Add Error** argument to memory_get_xlat_addr() Date: Tue, 14 May 2024 17:31:28 +0200 Message-ID: <20240514153130.394307-8-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700804611100003 Let the callers do the reporting. This will be useful in vfio_iommu_map_dirty_notify(). Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: David Hildenbrand Reviewed-by: Peter Xu Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Avihai Horon Reviewed-by: Eric Auger --- Changes in v6: - Fixed memory_get_xlat_addr documentation (Avihai) =20 include/exec/memory.h | 15 ++++++++++++++- hw/vfio/common.c | 13 +++++++++---- hw/virtio/vhost-vdpa.c | 5 ++++- system/memory.c | 10 +++++----- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index d417d7f363dbbca6553c449582a93d5da73cca40..9cdd64e9c69b63f9d27cebc2e8c= b366e22ed7577 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -774,9 +774,22 @@ void ram_discard_manager_register_listener(RamDiscardM= anager *rdm, void ram_discard_manager_unregister_listener(RamDiscardManager *rdm, RamDiscardListener *rdl); =20 +/** + * memory_get_xlat_addr: Extract addresses from a TLB entry + * + * @iotlb: pointer to an #IOMMUTLBEntry + * @vaddr: virtual address + * @ram_addr: RAM address + * @read_only: indicates if writes are allowed + * @mr_has_discard_manager: indicates memory is controlled by a + * RamDiscardManager + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: true on success, else false setting @errp with error. + */ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, ram_addr_t *ram_addr, bool *read_only, - bool *mr_has_discard_manager); + bool *mr_has_discard_manager, Error **errp); =20 typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 4e2ef3d3034e72aa6a546bcb9ea1f31a0bbd5b1b..919c4c52bc1590fd6c0bda37ba5= 881f58ff2ffff 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -253,12 +253,13 @@ static bool vfio_listener_skipped_section(MemoryRegio= nSection *section) =20 /* Called with rcu_read_lock held. */ static bool vfio_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, - ram_addr_t *ram_addr, bool *read_only) + ram_addr_t *ram_addr, bool *read_only, + Error **errp) { bool ret, mr_has_discard_manager; =20 ret =3D memory_get_xlat_addr(iotlb, vaddr, ram_addr, read_only, - &mr_has_discard_manager); + &mr_has_discard_manager, errp); if (ret && mr_has_discard_manager) { /* * Malicious VMs might trigger discarding of IOMMU-mapped memory. = The @@ -288,6 +289,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) hwaddr iova =3D iotlb->iova + giommu->iommu_offset; void *vaddr; int ret; + Error *local_err =3D NULL; =20 trace_vfio_iommu_map_notify(iotlb->perm =3D=3D IOMMU_NONE ? "UNMAP" : = "MAP", iova, iova + iotlb->addr_mask); @@ -304,7 +306,8 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) if ((iotlb->perm & IOMMU_RW) !=3D IOMMU_NONE) { bool read_only; =20 - if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) { + if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, &local_er= r)) { + error_report_err(local_err); goto out; } /* @@ -1213,6 +1216,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) VFIOContainerBase *bcontainer =3D giommu->bcontainer; hwaddr iova =3D iotlb->iova + giommu->iommu_offset; ram_addr_t translated_addr; + Error *local_err =3D NULL; int ret =3D -EINVAL; =20 trace_vfio_iommu_map_dirty_notify(iova, iova + iotlb->addr_mask); @@ -1224,7 +1228,8 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) } =20 rcu_read_lock(); - if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) { + if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL, &local_er= r)) { + error_report_err(local_err); goto out_unlock; } =20 diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index e827b9175fc61f1ef419e48d90a440b00449312a..ed99ab87457d8f31b98ace96071= 3f48d47b27102 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -208,6 +208,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) void *vaddr; int ret; Int128 llend; + Error *local_err =3D NULL; =20 if (iotlb->target_as !=3D &address_space_memory) { error_report("Wrong target AS \"%s\", only system memory is allowe= d", @@ -227,7 +228,9 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) if ((iotlb->perm & IOMMU_RW) !=3D IOMMU_NONE) { bool read_only; =20 - if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL)) { + if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL, + &local_err)) { + error_report_err(local_err); return; } ret =3D vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova, diff --git a/system/memory.c b/system/memory.c index 642a449f8c867d38c62a748a4dfd5c055637c205..9540caa8a1f4da8501bf5ae9d7e= edde8b775e1dc 100644 --- a/system/memory.c +++ b/system/memory.c @@ -2179,7 +2179,7 @@ void ram_discard_manager_unregister_listener(RamDisca= rdManager *rdm, /* Called with rcu_read_lock held. */ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, ram_addr_t *ram_addr, bool *read_only, - bool *mr_has_discard_manager) + bool *mr_has_discard_manager, Error **errp) { MemoryRegion *mr; hwaddr xlat; @@ -2197,7 +2197,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void = **vaddr, mr =3D address_space_translate(&address_space_memory, iotlb->translate= d_addr, &xlat, &len, writable, MEMTXATTRS_UNSPECI= FIED); if (!memory_region_is_ram(mr)) { - error_report("iommu map to non memory area %" HWADDR_PRIx "", xlat= ); + error_setg(errp, "iommu map to non memory area %" HWADDR_PRIx "", = xlat); return false; } else if (memory_region_has_ram_discard_manager(mr)) { RamDiscardManager *rdm =3D memory_region_get_ram_discard_manager(m= r); @@ -2216,8 +2216,8 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void = **vaddr, * were already restored before IOMMUs are restored. */ if (!ram_discard_manager_is_populated(rdm, &tmp)) { - error_report("iommu map to discarded memory (e.g., unplugged v= ia" - " virtio-mem): %" HWADDR_PRIx "", + error_setg(errp, "iommu map to discarded memory (e.g., unplugg= ed" + " via virtio-mem): %" HWADDR_PRIx "", iotlb->translated_addr); return false; } @@ -2228,7 +2228,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void = **vaddr, * check that it did not truncate too much. */ if (len & iotlb->addr_mask) { - error_report("iommu has granularity incompatible with target AS"); + error_setg(errp, "iommu has granularity incompatible with target A= S"); return false; } =20 --=20 2.45.0 From nobody Mon Nov 25 09:42:00 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=1715700812; cv=none; d=zohomail.com; s=zohoarc; b=Hxfuo3/EipZhj2GfAZJbGpNKsbQ8zyW29Hz6TZUZdUz6q1J2l6/f5RZNDhh5WILjsFqmD+hH9qUfB1ceGywOykozq6ObUrF5Oz1rBxEj+GoMdVlpJmQ4kwf0M/lPBBbI+usSBklZMoXSJK7GGTb6c5h665yMeSIqHC7Yklo632s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700812; 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=vZaaTHHjLc4E6LoVlHi9FKhA+rwsdbB22P6g8wRH0oI=; b=G2BJZvXv0/G/nmlauodlho2twCfgiNzQbfuuIR2KBKCX7ectllAoqKAVuxyPcCAnJQVB2fYyqWhGeUT8b8R3eQKhrGVeY7jyvwUW7TrvZ3ywygOb5UykrEu22myj4i8/yk65jM9r92UrTCjh78clqYo+dr/pjUEsrOsVoFMCm0o= 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 1715700812371980.552176422496; Tue, 14 May 2024 08:33:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8v-0001hK-PX; Tue, 14 May 2024 11:32:41 -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 1s6u8F-0001Lm-8S for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:59 -0400 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 1s6u8D-0000aS-1E for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:59 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-438-EOxC9Tn5MfWCk67IBYFmAg-1; Tue, 14 May 2024 11:31:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 89FCE101A55E; Tue, 14 May 2024 15:31:51 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE278200BD83; Tue, 14 May 2024 15:31:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700716; 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=vZaaTHHjLc4E6LoVlHi9FKhA+rwsdbB22P6g8wRH0oI=; b=DJ6PygfNDW/SeI6RH2TOv4e5mb0MCYgCszuvOlYsEhOiam63Q7IH1ALm4zAXDmTyKahlM+ KSN9zNU6t+gVgdypG4FO8EsSNhM7O7H3sVNHrq5IANRJuzKEm7Bw9kCxkQ6uZJAbRR6KXN +PIWhqp8TRVTSPM9lA6jINsed1cr8RQ= X-MC-Unique: EOxC9Tn5MfWCk67IBYFmAg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 8/9] vfio: Add Error** argument to .get_dirty_bitmap() handler Date: Tue, 14 May 2024 17:31:29 +0200 Message-ID: <20240514153130.394307-9-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700814720100003 Let the callers do the error reporting. Add documentation while at it. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Avihai Horon Reviewed-by: Eric Auger --- Changes in v6: - Fixed the line wrapping (Avihai) - Fixed query_dirty_bitmap documentation (Avihai) =20 Changes in v5: - Replaced error_setg() by error_setg_errno() in vfio_devices_query_dirty_bitmap() and vfio_legacy_query_dirty_bitmap() - ':' -> '-' in vfio_iommu_map_dirty_notify() =20 include/hw/vfio/vfio-common.h | 4 +- include/hw/vfio/vfio-container-base.h | 21 +++++++-- hw/vfio/common.c | 61 ++++++++++++++++++--------- hw/vfio/container-base.c | 7 +-- hw/vfio/container.c | 14 +++--- 5 files changed, 72 insertions(+), 35 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 46f88493634b5634a9c14a5caa33a463fbf2c50d..68911d36676667352e94a978958= 28aff4b194b57 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -274,9 +274,9 @@ 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); + 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..42cfbf32dc737606c3f620d126f= 35d85d4833534 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -84,8 +84,8 @@ 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 **errp); =20 void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space, @@ -138,9 +138,22 @@ 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 919c4c52bc1590fd6c0bda37ba5881f58ff2ffff..9b5123d45fc1f9d5be4bbbf9289= 8f89cd11e1363 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1140,8 +1140,8 @@ 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 +1150,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 +1163,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 +1180,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 +1238,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 +1264,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 +1308,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 +1339,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 +1354,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 +1363,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..4fa250c46fd16333d2e2358ede8= b0a0afdb185b3 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -64,11 +64,12 @@ 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 **errp) { 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..e00db6546c652c61a352f8e4cd6= 5b212ecfb65bc 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; } } @@ -236,7 +238,8 @@ 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) + hwaddr iova, hwaddr size, + Error **errp) { const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, bcontainer); @@ -264,9 +267,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.0 From nobody Mon Nov 25 09:42:00 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=1715700814; cv=none; d=zohomail.com; s=zohoarc; b=BYyipfV6+kLFUqztdd2FpUZMMjVpiuoP/7jjrGkCxgiMOCy1nvFBWGm/o929KXWKeBgynwMYU7FiQBsf1eMehnBIEwyq+KJI0AmgfN/GIoF7AU5qom5u6OOc0TkqEfeL7uTpBwCMyXurX53knO0pLYfRv7zhH4JNETSdmWhZgRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715700814; 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=K50Sbx+baGUOM5ct96UQE3ekCjWLHex1Zj4JwbZd/y8=; b=JX3ko0vvjy6GHYQxy//rLjuR8fJodTwJgEdlLYQlVqW94BctsCY5fpXubyKX0cGFqe3nrR/pLmEp210akNn9Edpq43XrfH9cR8UEAeMNMfyK/78fMvFHuRiAGbCdbdNLodgikdig/7Zf6RezYfcghKo/ATfRqvejQMb14ctQpEY= 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 1715700814591405.48067889971605; Tue, 14 May 2024 08:33:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6u8t-0001b0-1h; Tue, 14 May 2024 11:32:39 -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 1s6u8G-0001NN-Cb for qemu-devel@nongnu.org; Tue, 14 May 2024 11:32:00 -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 1s6u8E-0000b5-RW for qemu-devel@nongnu.org; Tue, 14 May 2024 11:31:59 -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-279-6GyP6KnQOcGQEw8UOabGOA-1; Tue, 14 May 2024 11:31:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 92D303C000BB; Tue, 14 May 2024 15:31:53 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE557200BD73; Tue, 14 May 2024 15:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715700718; 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=K50Sbx+baGUOM5ct96UQE3ekCjWLHex1Zj4JwbZd/y8=; b=Jha+iVbkMM7LyVmncwkfb76MWbGv7jtteW/We1A9fe6z9CkBGxx6kn46DAKM60fsGUrP5Y YNfbYqsf5qHy8IC8LVgdruB0WmtYa4KrQb2rD0xBblM8TxBVC2BcC0s2y7SsbDRIGfcwVW DknS9bpiKImfW5u9HFPIQNghPjN1sjc= X-MC-Unique: 6GyP6KnQOcGQEw8UOabGOA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v6 9/9] vfio: Also trace event failures in vfio_save_complete_precopy() Date: Tue, 14 May 2024 17:31:30 +0200 Message-ID: <20240514153130.394307-10-clg@redhat.com> In-Reply-To: <20240514153130.394307-1-clg@redhat.com> References: <20240514153130.394307-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.6 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: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.974, 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: 1715700816638100005 vfio_save_complete_precopy() currently returns before doing the trace event. Change that. Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Eric Auger --- hw/vfio/migration.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index d089fa9b937e725307c1a56755495d5b8fae2065..b06d887df53155e676bf13fa03a= daf0627841994 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -585,9 +585,6 @@ static int vfio_save_complete_precopy(QEMUFile *f, void= *opaque) =20 qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); ret =3D qemu_file_get_error(f); - if (ret) { - return ret; - } =20 trace_vfio_save_complete_precopy(vbasedev->name, ret); =20 --=20 2.45.0