From nobody Mon Nov 25 08:03:46 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=1716371954; cv=none; d=zohomail.com; s=zohoarc; b=MGSV7lknrngRbegFKDjqESZuVl+gHQiZcDqBEznckJREfatyETruZ/QW1cyYB9xCoNnuu9WVMKgbC394pj5S12WKhXuxLmQhN8EHG0ZyuS2Qvflz8Auf+5IHBvnUQLuO7NsbmqBpcquHH9VtWToZHjkAWTktiiNkExi2Hr2aWi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371954; 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=/MB4km9OgFQtXTFi96ON/NSe91r3XXzTqkR+UJNq5fo=; b=l10E+ANbuu3LAdAE6Kk4KK/NWH/bm9S3XuMSJwx3fK/3MtZ5krFXpLRSTLLsiIuiDSmKqDMA0qx4BAR6QgaXNrGkhjo77ChFNsg0Y5Q6Ts1tk8HZdf9QCYNo/WD2d7+4E1CWNaYWugP3859FmDh7828xGFr88GJRpTFhNEDZDco= 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 1716371954500490.0022707566775; Wed, 22 May 2024 02:59:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igZ-0003Jp-15; Wed, 22 May 2024 05:55:03 -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 1s9igX-0003Iq-Cb for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:01 -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 1s9igP-0001Kn-Ke for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:01 -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-582-7ZBH115FMYGApdHZES-4_w-1; Wed, 22 May 2024 05:54:48 -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 E23541C29EA4; Wed, 22 May 2024 09:54:47 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AE9228E3; Wed, 22 May 2024 09:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371692; 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=/MB4km9OgFQtXTFi96ON/NSe91r3XXzTqkR+UJNq5fo=; b=AwZyIcx/WjgyHyTDG8Bnt2LV+MY+81VA+iaJzyo1VauYxIh1uV5hFUlq8C3ucO2g7stkFg SaJy/8ZQssE4eFCHc5/cW6aYkBnoVoiXP+x5KbkJeSx5hFAn+rek1Bk0LQ4Bu8+m91dIdF IOSktYZnliUIyD3t2jaHPeRbk7zbq1w= X-MC-Unique: 7ZBH115FMYGApdHZES-4_w-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?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Avihai Horon , Eric Auger Subject: [PULL 01/47] vfio: Add Error** argument to .set_dirty_page_tracking() handler Date: Wed, 22 May 2024 11:53:56 +0200 Message-ID: <20240522095442.195243-2-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: 1716371955659100001 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 Reviewed-by: Eric Auger Signed-off-by: C=C3=A9dric Le Goater --- 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.1 From nobody Mon Nov 25 08:03:46 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=1716371860; cv=none; d=zohomail.com; s=zohoarc; b=bGm6nY0zi55vDdcNWkdorqTHLQVlgJPbfVV4onlRfJL0dywJQaS/46DUzsXvqJGKhEvfXP6QTWa3vL/RekfbDFFRvalMl37fAtPWBRCCbXKIL0zmGfKEXXEfUDdr73UqOusEgGDO888PsWgHlz7dTHUX1/SJQkJRDF86EZUCogE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371860; 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=JNzWVEEJfTYAPd2Z1GarMupMW/E5F1a67FOHEFatTnI=; b=m+7MQs1zPM8C2e8aSr9N8NK1zUAhF4J/nO/JZh2n4nfC0qRXsGEyvuTKzy+f0H+vTcjTVVKh8F2Kug0rqUo0AiqYdoqWPVxYIVFI4DKgdL4+ecggp8n07IKKDzhziQLaEcZD548tY+rL5ZeTlPO5BYeHCbexE5umqjr9mzIRiX0= 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 171637186076595.3667724870295; Wed, 22 May 2024 02:57:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igW-0003HK-9l; Wed, 22 May 2024 05:55: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 1s9igU-0003GR-CJ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:54:58 -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 1s9igP-0001Km-Kg for qemu-devel@nongnu.org; Wed, 22 May 2024 05:54:58 -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-456--qpNdOGIPiumAvoi_iEr2w-1; Wed, 22 May 2024 05:54:50 -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 B1C808058D4; Wed, 22 May 2024 09:54:49 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23E7C7412; Wed, 22 May 2024 09:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371692; 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=JNzWVEEJfTYAPd2Z1GarMupMW/E5F1a67FOHEFatTnI=; b=TVdL0M7PBDIQgZeMpVGlZc0/pqaWETBMqGfrVMKGIan8NmCqdl1gXQ1IgT8lu8u/tXw8Cj l5/K9ajN9Yl4DTtiYN41iQ7Td/PS19Rm57VeH+N4SIp9nvg8LXc6U2SQ7X+rNGC7KpwmxR Xe31PjY8WIebgF2Pz6DO/OB9XcafTGU= X-MC-Unique: -qpNdOGIPiumAvoi_iEr2w-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?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Avihai Horon , Eric Auger Subject: [PULL 02/47] vfio: Add Error** argument to vfio_devices_dma_logging_start() Date: Wed, 22 May 2024 11:53:57 +0200 Message-ID: <20240522095442.195243-3-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371861129100001 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. Also, errors from vfio_container_set_dirty_page_tracking() are now collected and reported. 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 Reviewed-by: Eric Auger Signed-off-by: C=C3=A9dric Le Goater --- 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.1 From nobody Mon Nov 25 08:03:46 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=1716371971; cv=none; d=zohomail.com; s=zohoarc; b=amBhzEDpMIoGSpt0Qx5QBc6WaKcmteHPNDqC7eLBLxZk3OePJSFO5Aj3C9A4bz1BDgTaQoMQvbl16TAnQ2ZuLRJKK84CwAEaegA4OR2bYBCmt4PFbZQuWk15VitriprUo3NxebwqTcs+hYbiPKAB7o/Q2aKbnpQ6ADBvcTodSNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371971; 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=SNxv7/60eUJcfONXYmCtenXDRBXj73n249ApeAqGfC8=; b=nFKTXudUOEdxYfz90gs2k/cLH4SUOB0rZNkPTJmZmlO2A8rwsdoEh2RmHZ2cqvGqRqbWd2+78TGvXi+lAYZFT+DamVynikaOdxn/8OXq0UVLnwX8xhn6dB4huYqGd7lKajtsFl2HDOLlnBOs1HFJBs1laHq9+oE8X9cwVu+qzas= 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 1716371971611540.3962004523378; Wed, 22 May 2024 02:59:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igZ-0003KX-8z; Wed, 22 May 2024 05:55:03 -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 1s9igV-0003H5-JZ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:54:59 -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 1s9igS-0001L4-8m for qemu-devel@nongnu.org; Wed, 22 May 2024 05:54: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-493-73YE14-2NUqlyFXQSgWWkA-1; Wed, 22 May 2024 05:54:51 -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 80A00185A780; Wed, 22 May 2024 09:54:51 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6F7251BF; Wed, 22 May 2024 09:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371695; 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=SNxv7/60eUJcfONXYmCtenXDRBXj73n249ApeAqGfC8=; b=T7I99cVMkeQhC+1jfobEktCJY9GfdpLoJvwGzWsP/k0UZBUc8dKg3ZtqEFi1hJiHaIRpyQ SzIDzL65rsNzF2rNWuKpKTbEko3HHcFUk9anYDU0QGWHO3xUweTJWAnL4CkhJd3DQQIenD 4ADhgHSPjMesnbUP0/bF3ic7hecYosw= X-MC-Unique: 73YE14-2NUqlyFXQSgWWkA-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?= , Avihai Horon , Fabiano Rosas , Eric Auger Subject: [PULL 03/47] migration: Extend migration_file_set_error() with Error* argument Date: Wed, 22 May 2024 11:53:58 +0200 Message-ID: <20240522095442.195243-4-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: 1716371973706100005 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 Reviewed-by: Eric Auger Signed-off-by: C=C3=A9dric Le Goater --- include/migration/misc.h | 2 +- hw/vfio/common.c | 4 ++-- hw/vfio/migration.c | 4 ++-- migration/migration.c | 6 ++++-- 4 files changed, 9 insertions(+), 7 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..2c97de6c730d963d961bf81c083= 1326c0e25afa7 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -147,10 +147,10 @@ bool vfio_viommu_preset(VFIODevice *vbasedev) return vbasedev->bcontainer->space->as !=3D &address_space_memory; } =20 -static void vfio_set_migration_error(int err) +static void vfio_set_migration_error(int ret) { if (migration_is_setup_or_active()) { - migration_file_set_error(err); + migration_file_set_error(ret, 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.1 From nobody Mon Nov 25 08:03:46 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=1716371795; cv=none; d=zohomail.com; s=zohoarc; b=ZlzQT/+1bERMoQivkN23zQfmf214byEnuGOIbVaAi5vhsX5awFmAFCWKct4N/WKe6T1J4xoA2YCcppBaR0CIrfCVFLDYnz0/gsPGEIXtajccvV1xA4fQ2+K/Cjc4RMc8qUOJNMWQjBPIExfnZMI/C0qgq7pnZ3rEFGDwhKhIaMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371795; 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=+wkuVxm/m7QZkvBeQpTS3DAa0U02Ht3x47UzpcAta9k=; b=R/h3uCbpF2iFLAqVZWFb7lc5TIghzz2y8nlK48XUhG0QkOrO2ezCnmbSXJVGIWKXNRxWrGnXW/dM8gqZi/NGzTWuO+igXq/7ea0DMYleAM/yQgMThFFXPP40jYbwm7IKNdkR7OimOZEw9IO9w6hNTyZIFzk8Yy2IxFX+g+PwwBo= 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 1716371795885747.348042850953; Wed, 22 May 2024 02:56:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igW-0003HG-5A; Wed, 22 May 2024 05:55: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 1s9igV-0003Gw-0H for qemu-devel@nongnu.org; Wed, 22 May 2024 05:54:59 -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 1s9igR-0001L1-Ul for qemu-devel@nongnu.org; Wed, 22 May 2024 05:54:58 -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-663-ooR55a-mO_q16izqU-nXCA-1; Wed, 22 May 2024 05:54:53 -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 D76D680118E; Wed, 22 May 2024 09:54:52 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id B61C17414; Wed, 22 May 2024 09:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371695; 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=+wkuVxm/m7QZkvBeQpTS3DAa0U02Ht3x47UzpcAta9k=; b=ZvivNpqXHfqG4p7L4vHFu+8G1nqKBM6L50EzpCyMtWncrOLmpECWH4C5nm8MUHFwJV54al Ly7DxQtC4ZMcdyWVx9TF8P7QAWT9tcaN8SuvyJ7mfOkneyt74FtqRXo5mdJVelWqMXuxPj bAIbby+IwM4KbH/+vgUd9PE2apWGjY0= X-MC-Unique: ooR55a-mO_q16izqU-nXCA-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?= , Avihai Horon Subject: [PULL 04/47] vfio/migration: Add an Error** argument to vfio_migration_set_state() Date: Wed, 22 May 2024 11:53:59 +0200 Message-ID: <20240522095442.195243-5-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: 1716371796896100021 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. Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration.c | 81 +++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index bf2fd0759ba6e4fb103cc5c1a43edb180a3d0de4..43fed0dbdbe3415ae2dd68fbe45= b302b85a80fa4 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) + @@ -92,6 +93,9 @@ static int vfio_migration_set_state(VFIODevice *vbasedev, struct vfio_device_feature_mig_state *mig_state =3D (struct vfio_device_feature_mig_state *)feature->data; int ret; + g_autofree char *error_prefix =3D + g_strdup_printf("%s: Failed setting device state to %s.", + vbasedev->name, mig_state_to_str(new_state)); =20 feature->argsz =3D sizeof(buf); feature->flags =3D @@ -102,22 +106,24 @@ 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 Recover state is ERROR. Resetting device", + error_prefix); =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 Setting device in recover state %s", + error_prefix, mig_state_to_str(recover_state)); =20 mig_state->device_state =3D recover_state; if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) { ret =3D -errno; + /* + * If setting the device in recover state fails, report + * the error here and propagate the first error. + */ error_report( "%s: Failed setting device in recover state, err: %s. Rese= tting device", vbasedev->name, strerror(errno)); @@ -137,7 +143,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 +174,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 +406,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 +440,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 +561,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 +605,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 +723,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 +748,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 +761,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 +780,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; =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 not return an error code and an Error + * object for MIG_EVENT_PRECOPY_FAILED. 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.1 From nobody Mon Nov 25 08:03:46 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=1716371993; cv=none; d=zohomail.com; s=zohoarc; b=CQIduHLIm8Z9MctX1WdNmIYZypJ8WbW3NIS9JScQU7fUJpqjwGyzVqImlR09zQLTv1S0PaE759gFF1gBF5C0YJfR2IWYB67gxCW2JFieEKafjbcYJ90oo6CBQhCpBI3IJ1wQJ96/YVFjPPXCVAoFViLLy6uwz19OPutk6zvfvTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371993; 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=yk48fTK5ShS0KxYI3y5riI0T9zcDblHOiC8pDta+dQE=; b=da3SKz6CDk/xj/EN4W/hoBglJVKYXbtITSwZS8r5dnFwPW5EX66HgBS4uj3G/RTO/gujjvxELL0bbNneb2ooY2JRcnY9sY39V1Vokq/V/Wks/Q7e6/EJ7/QFXOCrx9JT66gZ7X/B9RBFuGpsyOR4GxvKm6Cms174IGQtOX+iEk4= 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 1716371993618691.2476212396904; Wed, 22 May 2024 02:59:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igY-0003JF-5K; Wed, 22 May 2024 05:55:02 -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 1s9igW-0003I2-Ln for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55: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 1s9igV-0001Lu-3a for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:00 -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-553-DtDUsr4UOrqJRzypIKYYXg-1; Wed, 22 May 2024 05:54:55 -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 A7AAB1C29EA5; Wed, 22 May 2024 09:54:54 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 196A028E2; Wed, 22 May 2024 09:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371698; 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=yk48fTK5ShS0KxYI3y5riI0T9zcDblHOiC8pDta+dQE=; b=cIJza6I+UH+8jClMDHZts0RX6PfOxKbBdEtEgoSp1UMD9Na5KG5Sz65UTIMSWYERnvG24J ALS0qfF3ZrERRHV81t24A8pMfKAh+SJPwYUG2LmVD+KKk80YHcsxa0jPv2sVdpARRLMlFv vPYHFACNuD1dxKJWrBv7EACvAA7EgHM= X-MC-Unique: DtDUsr4UOrqJRzypIKYYXg-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?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eric Auger , Avihai Horon Subject: [PULL 05/47] vfio/migration: Add Error** argument to .vfio_save_config() handler Date: Wed, 22 May 2024 11:54:00 +0200 Message-ID: <20240522095442.195243-6-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: 1716371993798100001 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 Reviewed-by: Eric Auger Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater --- 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 d66e27db02a4db8329204f88d02a204eedf1caa1..3ff633ad3b395e953a55683f5f0= 308bca50af3dd 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 43fed0dbdbe3415ae2dd68fbe45b302b85a80fa4..5d91364f3bbc34060d84b4b4b18= 23eadbc7b12bf 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -193,21 +193,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) @@ -592,13 +601,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.1 From nobody Mon Nov 25 08:03:46 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=1716371978; cv=none; d=zohomail.com; s=zohoarc; b=C3saUqQ8cgebnQjmzifBP6RzwHutpuI66rllqU87gAlAjlQyqIwfQESEc9p9cDWo37spe3kWPkNR1DFLOugom05TXyq1XnFASD35oykcKWsDIvm3TILkwqgLnfX5WxYZTiUFNhaHY10KFeQkJGWssatRkkYGAx7DQQhrb566OD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371978; 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=3RLQ8cLxAbacMJh81IpGsppsMBbfX1IyWcmt2O0Rxtw=; b=WOF3xFHkBMzPj0Pt7BtTY+CevS1WtnAWVKjZCIDbgNbZhGApaO4RHAq3wuETMVeeskD4pbb3YNTYlfcchEGHzRFmLWlKziAG+Thaf9idZUu+UdTQ2fHpJMBiLeSLZCeuuACoatM/VWxm0AMLXKwpR5+oJ7AhFF+PBOuHgQCodo8= 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 1716371978629159.06734645487347; Wed, 22 May 2024 02:59:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igZ-0003Km-PZ; Wed, 22 May 2024 05:55:03 -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 1s9igY-0003JY-Ok for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:02 -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 1s9igX-0001MC-57 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:02 -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-221-O1hqmBF9NN210ggnG7Lpfg-1; Wed, 22 May 2024 05:54:56 -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 5A60A380008F; Wed, 22 May 2024 09:54:56 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCD467414; Wed, 22 May 2024 09:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371700; 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=3RLQ8cLxAbacMJh81IpGsppsMBbfX1IyWcmt2O0Rxtw=; b=ec/IAYxX73H418E36jybguSxp810OC3mIs+GAwqZ9u9oF6NIwp5YbCkwevvp4Qq4Ue/Tya zIUWKkuVaPlr0l5g4w40dGgMq8CKFDnlLkMYd03qb+B++8ohnJ9w50DJX/kHtxutii6vT5 H0y9vFM7qJwvPBQ1x0y6D05NzWv4pmI= X-MC-Unique: O1hqmBF9NN210ggnG7Lpfg-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?= , Avihai Horon , Eric Auger Subject: [PULL 06/47] vfio: Reverse test on vfio_get_xlat_addr() Date: Wed, 22 May 2024 11:54:01 +0200 Message-ID: <20240522095442.195243-7-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: 1716371979715100001 It will simplify the changes coming after. Reviewed-by: Avihai Horon Reviewed-by: Eric Auger Signed-off-by: C=C3=A9dric Le Goater --- 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 2c97de6c730d963d961bf81c0831326c0e25afa7..c7f274fb5c851e4c44498552891= 265018d2c5313 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.1 From nobody Mon Nov 25 08:03:46 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=1716372086; cv=none; d=zohomail.com; s=zohoarc; b=RvipRv1eIV5jNhUyX5My/xqfOdQCDmmNYmjFW3Y+d+uX3Z55GuinwQhEWeZiucT5jbbz1UMx4KcI3MYy6Od1YNSFul742P/Ckf/xOXjbrujPJNpG/aLgA4F95IkxpPlXhXt1QG/tttvzbb6ygN3ToED6cyC1F8zCfNwOIKW+uT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372086; 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=xEgW3e/XEuQ2cctgyXjEEqmbcF5A+1Z7ssJBUhFQbnc=; b=oAo5NBKP5OYlH05XZM4TBr/dDMorVgwCllKc2RLmAiYfrYQoPCtuGjtYLq1B0c4MCHCsGeiRbcGnjuYTVu9kYEXLY+2znDsj1EkTwXU/X5n93+ZMQlQUr5+Vhhd1iXyhfxK5amWD0v7Tbzyoms/PIzfbQOUoq7xquc3qQbq+//M= 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 171637208682820.22662853653003; Wed, 22 May 2024 03:01:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igh-0003P4-OM; Wed, 22 May 2024 05:55:11 -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-0003LQ-2y for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:05 -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-0001Mg-5v for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:04 -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-277-Rz1qrY-fO9y4d9ylXtfhSw-1; Wed, 22 May 2024 05:54:59 -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 3A5E01C29EA7; Wed, 22 May 2024 09:54:59 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EE6251BF; Wed, 22 May 2024 09:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371702; 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=xEgW3e/XEuQ2cctgyXjEEqmbcF5A+1Z7ssJBUhFQbnc=; b=ULYADHlkQfK15puymEiimqHGezMez/OWS690KL2WDMJyqLu0GEmgnUNSImo8oAAEE+BP2a YNMwQOMr5HXtg3mneFqvGT4fqWsvuEdGzHObIlwUrJnWLG8fsAtpjoVjYLlmcLIlgkORbz foYP2m3V1ozR4vFR8UBrcHj5w9bPcQg= X-MC-Unique: Rz1qrY-fO9y4d9ylXtfhSw-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?= , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand , Peter Xu , Eric Auger , Avihai Horon Subject: [PULL 07/47] memory: Add Error** argument to memory_get_xlat_addr() Date: Wed, 22 May 2024 11:54:02 +0200 Message-ID: <20240522095442.195243-8-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: 1716372104506100007 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 Reviewed-by: Eric Auger Reviewed-by: Avihai Horon Signed-off-by: C=C3=A9dric Le Goater --- 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 c7f274fb5c851e4c44498552891265018d2c5313..7313043f1d161ed0326b5ba3fa1= 085608eaf6740 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.1 From nobody Mon Nov 25 08:03:46 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 From nobody Mon Nov 25 08:03:46 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=1716372043; cv=none; d=zohomail.com; s=zohoarc; b=XUKvTMCHP8BUHRLzOC2TR164Kw2EU2TMfDZL/wBBC694Dy9XgspfVtzQMYEx84IlLnP4zsBUPDXLlBUKU0uVuFuj44xTMnCRuGOE2M2Ejf7El7iI6oFF5YrVgODyNntFgJt5vmyLN+7NBheZhan6bRP2eRjqVKd2JtGRIwj0RVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372043; 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=MHlpOzAERKwUXaVdd7c30VjfAwVvtvu8O3LwHu87a58=; b=gcx8n2JNse1F1i6Kp+UAicbGPKnmnwxZJQd7bJKMw9PxyIHvXrvfuHrExwMDJSWRLHRvO60n9h3pwUgXacwqeXGAbJKQSFu9WCZCQW2AzEu8dxYP1ekP3CPpAkLduv7Fd6T4H5lkFopFRZHzAAGcy7eyL4eqHtXAFBt1JZtCPeM= 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 1716372043429248.91064750963847; Wed, 22 May 2024 03:00:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igh-0003PN-Si; Wed, 22 May 2024 05:55:11 -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 1s9igd-0003Mn-93 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:08 -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 1s9igb-0001Mw-Lf for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:07 -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-187-KOigH0FqPu6KLkhEFezQTQ-1; Wed, 22 May 2024 05:55:03 -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 A9EBB8058D8; Wed, 22 May 2024 09:55:02 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2429E28E2; Wed, 22 May 2024 09:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371704; 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=MHlpOzAERKwUXaVdd7c30VjfAwVvtvu8O3LwHu87a58=; b=fPogpRqhZFtGGWtL9/SfTrgHHZBRc52m/tKjloR+NPTzEbUg3ksJbRlTeAvnxSWfbnGxYN QUh9pldkQsQH3jyEkWJVDG9VWWMehf84MKYsuupOwV7Xp05IqTWDcyroSvaGYL4oAM9Wsk mtZ8QYpO6LJrWvY8aolgqLevfmGeOSw= X-MC-Unique: KOigH0FqPu6KLkhEFezQTQ-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?= , Avihai Horon , Eric Auger Subject: [PULL 09/47] vfio: Also trace event failures in vfio_save_complete_precopy() Date: Wed, 22 May 2024 11:54:04 +0200 Message-ID: <20240522095442.195243-10-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: 1716372044018100001 vfio_save_complete_precopy() currently returns before doing the trace event. Change that. Reviewed-by: Avihai Horon Reviewed-by: Eric Auger Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 5d91364f3bbc34060d84b4b4b1823eadbc7b12bf..c4403a38ddb5e7e09fbcde0ad41= 32653ecaf0d24 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -589,9 +589,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.1 From nobody Mon Nov 25 08:03:46 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=1716371810; cv=none; d=zohomail.com; s=zohoarc; b=lZxcuijUvagX/B+T5wpslrAB0wj1i37h4IPqj1FWqrKBL+kaLkPeSaANJkZIyePL8oSjy7CcLecbkdA88MNbcsrIUWVAVBOX5jvRGmab7HVLNzXl4d6rl3KAgze5zfS16oGg5z0qw8pbF2ugahmJevUrEnkkTOfw0AUYB/0Jqa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371810; 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=zz+fwUrHlDOtbBCoqeAzkshOeTlKuN2gnxbfLw7Fe10=; b=cDD0c0gBOynyZYR5fExR25kkGbv50GrSD4HEJmhTQAPx++2Cze6MyMAlcC0Mwr83aYVRHZJu+u4eI4auk/jCEcqzEYG7QCATXkCWPrU83D/fGJRTvj6+TKPt+rSW7UT6oHOO4yF4wRfgkUizdFvotmO+jPYEBiez593gWuf/Cxg= 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 171637181047849.940789195703246; Wed, 22 May 2024 02:56:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igw-0003Uf-IN; Wed, 22 May 2024 05:55:26 -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 1s9igg-0003P5-5X for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:11 -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 1s9igd-0001NM-LN for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:09 -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-609-FIv4vUI9NZ2KAj2HET7G2Q-1; Wed, 22 May 2024 05:55:04 -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 2C6593C000AD; Wed, 22 May 2024 09:55:04 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF30E28E3; Wed, 22 May 2024 09:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371706; 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=zz+fwUrHlDOtbBCoqeAzkshOeTlKuN2gnxbfLw7Fe10=; b=DY2tJD9x0xjF8XR3c0r/caAQlVx33BVLxwVc7CJsBkJ3IhrCQo7g7C35Rk6kHRBXTx2V88 UVYVN0Y/JuJkO2PIlXxB5gmnFAfYXaxnKr+x7t5+P2IyklDJ1SrQxLAavKqp+rKL5Y2mzi 9kZdTiQGZoeYvmoqjVYbYBq0KYMu8v0= X-MC-Unique: FIv4vUI9NZ2KAj2HET7G2Q-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?= , Markus Armbruster , Anthony Krowiak Subject: [PULL 10/47] vfio/ap: Use g_autofree variable in vfio_ap_register_irq_notifier() Date: Wed, 22 May 2024 11:54:05 +0200 Message-ID: <20240522095442.195243-11-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: 1716371810877100006 Reviewed-by: Markus Armbruster Reviewed-by: Anthony Krowiak Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ap.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 7c4caa5938636937680fec87e999249ac84a4498..03f8ffaa5e2bf13cf8daa2f44aa= 4cf17809abd94 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -77,7 +77,7 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice *v= apdev, size_t argsz; IOHandler *fd_read; EventNotifier *notifier; - struct vfio_irq_info *irq_info; + g_autofree struct vfio_irq_info *irq_info =3D NULL; VFIODevice *vdev =3D &vapdev->vdev; =20 switch (irq) { @@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevic= e *vapdev, if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, irq_info) < 0 || irq_info->count < 1) { error_setg_errno(errp, errno, "vfio: Error getting irq info"); - goto out_free_info; + return; } =20 if (event_notifier_init(notifier, 0)) { error_setg_errno(errp, errno, "vfio: Unable to init event notifier for irq (%d)= ", irq); - goto out_free_info; + return; } =20 fd =3D event_notifier_get_fd(notifier); @@ -122,10 +122,6 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice= *vapdev, qemu_set_fd_handler(fd, NULL, NULL, vapdev); event_notifier_cleanup(notifier); } - -out_free_info: - g_free(irq_info); - } =20 static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev, --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371854; cv=none; d=zohomail.com; s=zohoarc; b=SVAGfeV3qlz1tSFi8SADn0GM5OnLUm0EgaOGhiUryBUqUqAMkChli7VQ/5bWD8dYHvtCPf7+32CeYsTwKKRLnhU2dDwhAQUlcL8F7LW6+gUz33N0a7Z372qZYMo2TcSgEmdY7RmnKw7hGW7CzUba2u+GIQBVoKr7DQeUUG1ku8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371854; 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=XpbNH3QG7hQ6uA4cNyBiYCTL+aMLHBgPlTwqzjzOh+s=; b=Lf+8afzAIKQKSU/R09DS1HWYFRueJqRjGMOW1svV1ozpWDNXBYiIMBw9dhDVd0kqgOHtSDKlmEQxzTS6TdMka9ewM9Ax85xbtlzEPGHlhQXopY9I1qXMMsESllqsRsuj5gSuNUAqqfDsmH95qBDnQ+DgfutizlkPwQl/z6eOhgQ= 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 1716371854436483.1656485471625; Wed, 22 May 2024 02:57:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igq-0003S0-Ll; Wed, 22 May 2024 05:55:20 -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 1s9igg-0003P7-DE for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:11 -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 1s9igd-0001NZ-UN for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:10 -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-669-_EsZpI3SPx2Q2wJKO6zo7Q-1; Wed, 22 May 2024 05:55:05 -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 8405E101A54F for ; Wed, 22 May 2024 09:55:05 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61E6728E6; Wed, 22 May 2024 09:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371707; 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=XpbNH3QG7hQ6uA4cNyBiYCTL+aMLHBgPlTwqzjzOh+s=; b=ZogyVAmTMUejIDjSAMt2cTtQeHdVQpfcfjnPo6S81gIcbwLJomEWshb7N/cNEHDljcrfqe 3FJb0bsDo1ThISn4CHsyghh5fd85udte0IamaFcKt2jxYC1AT9EHGslQuUub4aw53PIBWW JCnkNnNlpKYi/dK0FnboLJDXcnVsdSs= X-MC-Unique: _EsZpI3SPx2Q2wJKO6zo7Q-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?= , Markus Armbruster Subject: [PULL 11/47] vfio/ap: Make vfio_ap_register_irq_notifier() return a bool Date: Wed, 22 May 2024 11:54:06 +0200 Message-ID: <20240522095442.195243-12-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: 1716371855070100001 Since vfio_ap_register_irq_notifier() takes and 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section. Reviewed-by: Markus Armbruster Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ap.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 03f8ffaa5e2bf13cf8daa2f44aa4cf17809abd94..8bb024e2fde4a1d72346dee4b66= 2d762374326b9 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -70,7 +70,7 @@ static void vfio_ap_req_notifier_handler(void *opaque) } } =20 -static void vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev, +static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev, unsigned int irq, Error **errp) { int fd; @@ -87,13 +87,13 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice = *vapdev, break; default: error_setg(errp, "vfio: Unsupported device irq(%d)", irq); - return; + return false; } =20 if (vdev->num_irqs < irq + 1) { error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)", irq, vdev->num_irqs); - return; + return false; } =20 argsz =3D sizeof(*irq_info); @@ -104,14 +104,14 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevic= e *vapdev, if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, irq_info) < 0 || irq_info->count < 1) { error_setg_errno(errp, errno, "vfio: Error getting irq info"); - return; + return false; } =20 if (event_notifier_init(notifier, 0)) { error_setg_errno(errp, errno, "vfio: Unable to init event notifier for irq (%d)= ", irq); - return; + return false; } =20 fd =3D event_notifier_get_fd(notifier); @@ -122,6 +122,8 @@ static void vfio_ap_register_irq_notifier(VFIOAPDevice = *vapdev, qemu_set_fd_handler(fd, NULL, NULL, vapdev); event_notifier_cleanup(notifier); } + + return true; } =20 static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev, @@ -167,8 +169,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **e= rrp) goto error; } =20 - vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err); - if (err) { + if (!vfio_ap_register_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX, &err= )) { /* * Report this error, but do not make it a failing condition. * Lack of this IRQ in the host does not prevent normal operation. --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371882; cv=none; d=zohomail.com; s=zohoarc; b=XdWsaNdWDVfOnQq4Tt1nDNX308MmAO7BWOp9NmuPK5ShFRYExDbO02v3svh0mf7a1GIZxQIYskuxoFnWafxg/kI/jFoauYgMryTVPSwa/RvwoT79qyXpPwhMxI6jXaX5M5ZFh7ORR7UT3tk/mYSb3pCogdNC2IJ0/enQsxrTZNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371882; 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=MIGTWmrq7gmEPJCdTPW3Iy9adWxbYc3LKxV5QyfhzTM=; b=ZWOzxtiAqHyH+vkKnt+WgASaQ5m90exEIMVK//eOJRLye9TKxuexBBbJk1R7bjmR861A4e+d8oBpTvlAOrKD3V1jhiJR9V8B7lVsYQYMo11EXjwPVTuDXZy8gowmyPXSVxE5/YW2KYvBwGQ7ffIYqliXF8Uapcr1xJkTGQdRflw= 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 1716371882456765.451841281586; Wed, 22 May 2024 02:58:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igw-0003Ug-JE; Wed, 22 May 2024 05:55:26 -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 1s9igl-0003Qy-Qu for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:16 -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 1s9igk-0001Pf-A2 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:15 -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-388-eW7KvvT5NL-HezqsWx7o5A-1; Wed, 22 May 2024 05:55:07 -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 0066485A58C; Wed, 22 May 2024 09:55:07 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id B90557414; Wed, 22 May 2024 09:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371710; 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=MIGTWmrq7gmEPJCdTPW3Iy9adWxbYc3LKxV5QyfhzTM=; b=dJjkHTS06m9DA1rtOub+HmuQwzWFwuVKIikkPu2HGpujUCxPxKf0uMnS79uYm/w2+EdUmD d905D0kIrjEwZG3IEY02yofYbxHc7pJbWATqNJ3FCJxccQ6gmxN6nKsT8m0YU+rlNAxQAH 8CUVmTLR+z39V5Lw4wSoabjyzk804iY= X-MC-Unique: eW7KvvT5NL-HezqsWx7o5A-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?= , Markus Armbruster , Eric Farman Subject: [PULL 12/47] vfio/ccw: Use g_autofree variable in vfio_ccw_register_irq_notifier() Date: Wed, 22 May 2024 11:54:07 +0200 Message-ID: <20240522095442.195243-13-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371883445100002 Reviewed-by: Markus Armbruster Reviewed-by: Eric Farman Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ccw.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 90e4a534371684c08e112364e1537eb8979f73f4..6764388bc47a970329fce223362= 6ccb8178e0165 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -384,7 +384,7 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevic= e *vcdev, Error **errp) { VFIODevice *vdev =3D &vcdev->vdev; - struct vfio_irq_info *irq_info; + g_autofree struct vfio_irq_info *irq_info =3D NULL; size_t argsz; int fd; EventNotifier *notifier; @@ -421,14 +421,14 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDev= ice *vcdev, if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, irq_info) < 0 || irq_info->count < 1) { error_setg_errno(errp, errno, "vfio: Error getting irq info"); - goto out_free_info; + return; } =20 if (event_notifier_init(notifier, 0)) { error_setg_errno(errp, errno, "vfio: Unable to init event notifier for irq (%d)= ", irq); - goto out_free_info; + return; } =20 fd =3D event_notifier_get_fd(notifier); @@ -439,9 +439,6 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevic= e *vcdev, qemu_set_fd_handler(fd, NULL, NULL, vcdev); event_notifier_cleanup(notifier); } - -out_free_info: - g_free(irq_info); } =20 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev, --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716372149; cv=none; d=zohomail.com; s=zohoarc; b=ntpjXuaRG3ovEenbeyTm2OKVy/X3maCFbB0/9T20H4XUm5JiZtS72SxgnOYW0+QdeX1XPIj48kwDRtwQ5mft7tO240oM9M4fEU2aX+wPjIaOR8KFVlwoHZbRe14Ss9iV7xNy82dAFXb2whOhYFKeyvBfFeIfAkMp9qIfGrxYXwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372149; 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=PYGjldkPYHoH5A5sfKwcPOo2ffdx4sbmA1HzAej7FO0=; b=Yjha29FU+B17Us1/CFAbln5GZPjEU0ek4F0tk3n+ed4qtO7im1SztAICyhRbVq+AX5hhCMbcWY/og0yt2tF289ETDXyGC8cJgGXap4oOTo+QsPPaXWTZX7Aw1oPNAS7rTpN8R7akpDoLhuh1NkcL1PK8JM5YIYlpZTwJEHyTYoA= 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 1716372149321658.8333641834324; Wed, 22 May 2024 03:02:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihD-0003g7-4H; Wed, 22 May 2024 05:55:43 -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 1s9ih0-0003XV-SW for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:30 -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 1s9igk-0001Pz-Cf for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:29 -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-442-wMN70ybSPLeA5XI_5yOQkQ-1; Wed, 22 May 2024 05:55:08 -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 723AE85A58C; Wed, 22 May 2024 09:55:08 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 351A528E3; Wed, 22 May 2024 09:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371713; 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=PYGjldkPYHoH5A5sfKwcPOo2ffdx4sbmA1HzAej7FO0=; b=U6fzVryKbYvBZtXnyI60YSE9QEDUhFonYR51lfJLpeFcR64VBt3nZUgnxIrQYj7Tt6Ufh3 7JJmKL5ufRIQEvism+GazEjpkh+4txNKG38cYXbHv/z3LmR8B3xLQS65bQo77b56VLjsn+ OvMTW4w83taOuCXxdIiIYfUfpjuUJ3M= X-MC-Unique: wMN70ybSPLeA5XI_5yOQkQ-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?= , Markus Armbruster , Eric Farman Subject: [PULL 13/47] vfio/ccw: Make vfio_ccw_register_irq_notifier() return a bool Date: Wed, 22 May 2024 11:54:08 +0200 Message-ID: <20240522095442.195243-14-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: 1716372150637100001 Since vfio_ccw_register_irq_notifier() takes an 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section. Reviewed-by: Markus Armbruster Reviewed-by: Eric Farman Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ccw.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 6764388bc47a970329fce2233626ccb8178e0165..1c630f6e9abe93ae0c2b5615d44= 09669f096c8c9 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -379,7 +379,7 @@ read_err: css_inject_io_interrupt(sch); } =20 -static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, +static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, unsigned int irq, Error **errp) { @@ -405,13 +405,13 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDev= ice *vcdev, break; default: error_setg(errp, "vfio: Unsupported device irq(%d)", irq); - return; + return false; } =20 if (vdev->num_irqs < irq + 1) { error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)", irq, vdev->num_irqs); - return; + return false; } =20 argsz =3D sizeof(*irq_info); @@ -421,14 +421,14 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDev= ice *vcdev, if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, irq_info) < 0 || irq_info->count < 1) { error_setg_errno(errp, errno, "vfio: Error getting irq info"); - return; + return false; } =20 if (event_notifier_init(notifier, 0)) { error_setg_errno(errp, errno, "vfio: Unable to init event notifier for irq (%d)= ", irq); - return; + return false; } =20 fd =3D event_notifier_get_fd(notifier); @@ -439,6 +439,8 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevic= e *vcdev, qemu_set_fd_handler(fd, NULL, NULL, vcdev); event_notifier_cleanup(notifier); } + + return true; } =20 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev, @@ -602,20 +604,18 @@ static void vfio_ccw_realize(DeviceState *dev, Error = **errp) goto out_region_err; } =20 - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err); - if (err) { + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err= )) { goto out_io_notifier_err; } =20 if (vcdev->crw_region) { - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, &err= ); - if (err) { + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, + &err)) { goto out_irq_notifier_err; } } =20 - vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err); - if (err) { + if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &er= r)) { /* * Report this error, but do not make it a failing condition. * Lack of this IRQ in the host does not prevent normal operation. --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716372008; cv=none; d=zohomail.com; s=zohoarc; b=jqvZPJOMQgblWabtmoTgafQTPLdPvBKgD/6mVmxTVwE0UlsSaXbfhzb+l9LaQeHbCvHXkXHhuL8UudC1eZ/fqgJqpCPBAVqLNcAb6vFTFNvOEet4kQl6s5iO4/iBwlcJp01ceJbx0KS4Iy+25CbC0KqtDk4CUzv2zkWaJLjBJL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372008; 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=FbYDvgZ3A8fXGUyykwgKl2IroA+m5TOvdcZPY3ucw2s=; b=geWTb+dLWrCrUkoFfl84y+T0G2sarxQxolAPF2Fe3Dh6IDpSLfD//1p0c9eWA+bD1S7Nf/7WO0KQOtOdNMtwTnXDPNfRnM1u9JELcw/FHuvZTYcBfZdyAqhS90qOD2yOaYub2jUY6rr9BB3YwQ1ikUmnrjJCzxgddTKfpaOhDTw= 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 1716372008711414.435011900385; Wed, 22 May 2024 03:00:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ih2-0003Yu-OD; Wed, 22 May 2024 05:55:33 -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 1s9ign-0003RM-4u for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:18 -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 1s9igk-0001Q3-N5 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:16 -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-175-V2N0Rg6uP-2KXOGCFsHy_w-1; Wed, 22 May 2024 05:55:10 -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 74087380673C; Wed, 22 May 2024 09:55:10 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id A79F27414; Wed, 22 May 2024 09:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371714; 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=FbYDvgZ3A8fXGUyykwgKl2IroA+m5TOvdcZPY3ucw2s=; b=QuluR2mC4UNjv5dpiha5/bJUjaNuMiNplpNC+tt7ulVSddmsBGMFPG9bXdGAXnRGZ+1DdR 7YsWxdOqyXYcdiWgTLG70EKv5HaaFNANfuu/UNrpily6+GTU+Chk5rRlsvuDxZFHj8QNnH 1nV5TbHrSkUsEoFvKkLUHNtltKyJq60= X-MC-Unique: V2N0Rg6uP-2KXOGCFsHy_w-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Vinayak Kale , "Michael S . Tsirkin" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 14/47] vfio/pci: migration: Skip config space check for Vendor Specific Information in VSC during restore/load Date: Wed, 22 May 2024 11:54:09 +0200 Message-ID: <20240522095442.195243-15-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: 1716372009888100003 From: Vinayak Kale In case of migration, during restore operation, qemu checks config space of= the pci device with the config space in the migration stream captured during sa= ve operation. In case of config space data mismatch, restore operation is fail= ed. config space check is done in function get_pci_config_device(). By default = VSC (vendor-specific-capability) in config space is checked. Due to qemu's config space check for VSC, live migration is broken across N= VIDIA vGPU devices in situation where source and destination host driver is diffe= rent. In this situation, Vendor Specific Information in VSC varies on the destina= tion to ensure vGPU feature capabilities exposed to the guest driver are compati= ble with destination host. If a vfio-pci device is migration capable and vfio-pci vendor driver is OK = with volatile Vendor Specific Info in VSC then qemu should exempt config space c= heck for Vendor Specific Info. It is vendor driver's responsibility to ensure th= at VSC is consistent across migration. Here consistency could mean that VSC fo= rmat should be same on source and destination, however actual Vendor Specific In= fo may not be byte-to-byte identical. This patch skips the check for Vendor Specific Information in VSC for VFIO-= PCI device by clearing pdev->cmask[] offsets. Config space check is still enfor= ced for 3 byte VSC header. If cmask[] is not set for an offset, then qemu skips config space check for that offset. VSC check is skipped for machine types >=3D 9.1. The check would be enforce= d on older machine types (<=3D 9.0). Cc: Alex Williamson Cc: Michael S. Tsirkin Cc: C=C3=A9dric Le Goater Signed-off-by: Vinayak Kale Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 1 + hw/core/machine.c | 1 + hw/vfio/pci.c | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 6e64a2654e690af11b72710530a41135b726e96f..92cd62d1159dbd47d878454f201= f9c18112a7692 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -177,6 +177,7 @@ struct VFIOPCIDevice { OnOffAuto ramfb_migrate; bool defer_kvm_irq_routing; bool clear_parent_atomics_on_exit; + bool skip_vsc_check; VFIODisplay *dpy; Notifier irqchip_change_notifier; }; diff --git a/hw/core/machine.c b/hw/core/machine.c index c7ceb1150147eb2bdd5f7ef583d00cee88f306cd..3442f31f9458c4e1bdde366aa40= bfe3ad8b321a8 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -35,6 +35,7 @@ =20 GlobalProperty hw_compat_9_0[] =3D { {"arm-cpu", "backcompat-cntfrq", "true" }, + {"vfio-pci", "skip-vsc-check", "false" }, }; const size_t hw_compat_9_0_len =3D G_N_ELEMENTS(hw_compat_9_0); =20 diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index fc6e54e871508bb0e2a3ac9079a195c086531f21..4789d43c0f9cc7ef94b73adc815= 377f7222d8c57 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2134,6 +2134,28 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, u= int8_t pos) } } =20 +static int vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos, + uint8_t size, Error **errp) +{ + PCIDevice *pdev =3D &vdev->pdev; + + pos =3D pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp); + if (pos < 0) { + return pos; + } + + /* + * Exempt config space check for Vendor Specific Information during + * restore/load. + * Config space check is still enforced for 3 byte VSC header. + */ + if (vdev->skip_vsc_check && size > 3) { + memset(pdev->cmask + pos + 3, 0, size - 3); + } + + return pos; +} + static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp) { ERRP_GUARD(); @@ -2202,6 +2224,9 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint= 8_t pos, Error **errp) vfio_check_af_flr(vdev, pos); ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); break; + case PCI_CAP_ID_VNDR: + ret =3D vfio_add_vendor_specific_cap(vdev, pos, size, errp); + break; default: ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); break; @@ -3391,6 +3416,7 @@ static Property vfio_pci_dev_properties[] =3D { DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd, TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), #endif + DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true= ), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371794; cv=none; d=zohomail.com; s=zohoarc; b=g4EZvJfOqo6+gE+PVTch7KpfT6jB8E2E+BccyafgLN5ClItw4BWHgvPiuSEhjzsKVUJW1qINpWRIkXhnctkh3JDp6F2Z/Ru5+ZEfwT9mA80pedIcUd6bcS+/SKXgv4irpMhHaaESFgaidAmx8P3mES1sIgDPinOeCF0OdyXjnEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371794; 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=0VQ9NVIxSHCsEaByjV2CBIUySE2+PXzk48re8ExyFxo=; b=TYLjjwSOnqg/3+xTypYA195oJqCSPOH1VTUMZQEiFCX7DtDyQMLfDJw2kJ6nExqd3I/PsLiCNeUCBbythYSkGhL2mtCrH2yEfWY4CdySopfxSiCvVQd6uNMpD9FK+11SBaTMnLGbB1vs/v/3uwLkSLtE/vOZ4jcDotB8YFcJSO0= 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 1716371794547134.0414996633907; Wed, 22 May 2024 02:56:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9igz-0003Vu-1H; Wed, 22 May 2024 05:55:30 -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 1s9igo-0003Ru-JV for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:20 -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 1s9igm-0001QY-FZ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:18 -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-179-7kB82LrMOQO0fKBWph7wUA-1; Wed, 22 May 2024 05:55:12 -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 CAC2B3C025C2; Wed, 22 May 2024 09:55:11 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id A942E28E2; Wed, 22 May 2024 09:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371715; 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=0VQ9NVIxSHCsEaByjV2CBIUySE2+PXzk48re8ExyFxo=; b=dkNjqezOrvKS6ljF359JAChoNQmvspXjqhIgUIFnYBtYWP8NkcxvNtxlbwUD205hsOedVU PlTM05hsnuzJvmM6/2epKl/BWWAfYBL/VQz2iihqevPSGui3mCVkC9NSV+htBGe4/uVvTG hkFksD60IoEPnoPbcHpr+lUK+LzR8zM= X-MC-Unique: 7kB82LrMOQO0fKBWph7wUA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 15/47] qapi/vfio: Add VFIO migration QAPI event Date: Wed, 22 May 2024 11:54:10 +0200 Message-ID: <20240522095442.195243-16-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: 1716371794838100007 From: Avihai Horon Add a new QAPI event for VFIO migration. This event will be emitted when a VFIO device changes its migration state, for example, during migration or when stopping/starting the guest. This event can be used by management applications to get updates on the current state of the VFIO device for their own purposes. Note that this new event is introduced since VFIO devices have a unique set of migration states which cannot be described as accurately by other existing events such as run state or migration status. Signed-off-by: Avihai Horon Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- MAINTAINERS | 1 + qapi/qapi-schema.json | 1 + qapi/vfio.json | 67 +++++++++++++++++++++++++++++++++++++++++++ qapi/meson.build | 1 + 4 files changed, 70 insertions(+) create mode 100644 qapi/vfio.json diff --git a/MAINTAINERS b/MAINTAINERS index 1b79767d61960189eaa9d3d736e77722b8d5d9f0..448dc951c50913e7111d3bb6833= a00acea7f50f1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2164,6 +2164,7 @@ F: hw/vfio/* F: include/hw/vfio/ F: docs/igd-assign.txt F: docs/devel/migration/vfio.rst +F: qapi/vfio.json =20 vfio-ccw M: Eric Farman diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 5e33da7228f22abd20fa49f32c95e6a381ababd1..b1581988e4eba99cbe9ca535019= 18dd2d9bcfe44 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -78,5 +78,6 @@ { 'include': 'pci.json' } { 'include': 'stats.json' } { 'include': 'virtio.json' } +{ 'include': 'vfio.json' } { 'include': 'cryptodev.json' } { 'include': 'cxl.json' } diff --git a/qapi/vfio.json b/qapi/vfio.json new file mode 100644 index 0000000000000000000000000000000000000000..a0e5013188a4d16d842c8463d6e= 4c33742e06a97 --- /dev/null +++ b/qapi/vfio.json @@ -0,0 +1,67 @@ +# -*- Mode: Python -*- +# vim: filetype=3Dpython +# + +## +# =3D VFIO devices +## + +## +# @VfioMigrationState: +# +# An enumeration of the VFIO device migration states. +# +# @stop: The device is stopped. +# +# @running: The device is running. +# +# @stop-copy: The device is stopped and its internal state is available +# for reading. +# +# @resuming: The device is stopped and its internal state is available +# for writing. +# +# @running-p2p: The device is running in the P2P quiescent state. +# +# @pre-copy: The device is running, tracking its internal state and its +# internal state is available for reading. +# +# @pre-copy-p2p: The device is running in the P2P quiescent state, +# tracking its internal state and its internal state is available +# for reading. +# +# Since: 9.1 +## +{ 'enum': 'VfioMigrationState', + 'data': [ 'stop', 'running', 'stop-copy', 'resuming', 'running-p2p', + 'pre-copy', 'pre-copy-p2p' ], + 'prefix': 'QAPI_VFIO_MIGRATION_STATE' } + +## +# @VFIO_MIGRATION: +# +# This event is emitted when a VFIO device migration state is changed. +# +# @device-id: The device's id, if it has one. +# +# @qom-path: The device's QOM path. +# +# @device-state: The new changed device migration state. +# +# Since: 9.1 +# +# Example: +# +# <- { "timestamp": { "seconds": 1713771323, "microseconds": 212268 }, +# "event": "VFIO_MIGRATION", +# "data": { +# "device-id": "vfio_dev1", +# "qom-path": "/machine/peripheral/vfio_dev1", +# "device-state": "stop" } } +## +{ 'event': 'VFIO_MIGRATION', + 'data': { + 'device-id': 'str', + 'qom-path': 'str', + 'device-state': 'VfioMigrationState' + } } diff --git a/qapi/meson.build b/qapi/meson.build index c92af6e063a1b13ec3cce18e0572a859779b2ce4..e7bc54e5d047090aa2cdb823ef9= ff4b892adb614 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -52,6 +52,7 @@ qapi_all_modules =3D [ 'stats', 'trace', 'transaction', + 'vfio', 'virtio', 'yank', ] --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371846; cv=none; d=zohomail.com; s=zohoarc; b=f7a1Fg7zX6C/9oOi71XhSVrdt65OnuGlvipZHBrYNWsEggz0PnpJ6bPMtyiGjUz5e2m35NTYOoznLnbJYrCGbvfhkg4fF8hAgmOiZwCfxrnA7A1Dw13eapiQldco/ptZxkLpt6pQ4IJgpLRJnAfbB3SghgIWBzze80f2AbuFJTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371846; 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=mb4TS0heb25hYEpWvRRpq8aztVfsgZO11urO3GR9nl8=; b=Gmb5AHA5b2bWpfPCRjvZl46Ax62vxyRVMdVwVFTCh0MyeJ+JYHUeVr4s0tkKk2uvI+zQtE1VjefDN333Mk1+UpgN4Lx4qjbZdrXqUNSHJgiDtBpSZwV7GqRocAHufDFPZlMn3c2l5NA605ynB/1teA0hY25U+sNvcSb8iabJq5k= 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 1716371846513270.64152919469086; Wed, 22 May 2024 02:57:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ih0-0003XZ-Vr; Wed, 22 May 2024 05:55:31 -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 1s9igo-0003Rt-J5 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:20 -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 1s9igm-0001QM-2P for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:17 -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-593-R3SEFLHgPlWuyXg7-NVZRg-1; Wed, 22 May 2024 05:55:13 -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 2D3F7101A525; Wed, 22 May 2024 09:55:13 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C03351BF; Wed, 22 May 2024 09:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371715; 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=mb4TS0heb25hYEpWvRRpq8aztVfsgZO11urO3GR9nl8=; b=N/JW4uR7pUSB2IEvKeHk06t9nWmhEQMaRckTxBwvV4ITZKSzN5qbhRSh4gAzGaHyOINQDP Ewq1aHaN/Dck4lh4v3aZmAwOP/MxZijWWx3tGtoVohlRo52jZAjU60nDcFHg+Z/fWvyWlO iinx+90NDCLPuge1YZChwtTivo/5i6I= X-MC-Unique: R3SEFLHgPlWuyXg7-NVZRg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 16/47] vfio/migration: Emit VFIO migration QAPI event Date: Wed, 22 May 2024 11:54:11 +0200 Message-ID: <20240522095442.195243-17-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: 1716371847062100002 From: Avihai Horon Emit VFIO migration QAPI event when a VFIO device changes its migration state. This can be used by management applications to get updates on the current state of the VFIO device for their own purposes. A new per VFIO device capability, "migration-events", is added so events can be enabled only for the required devices. It is disabled by default. Signed-off-by: Avihai Horon Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 1 + hw/vfio/migration.c | 59 +++++++++++++++++++++++++++++++++-- hw/vfio/pci.c | 2 ++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b6ac24953667bc5f72f28480a6bf0f4722069cb9..878e34a12874f63fcb8bbc8dc8c= a3d2dfa84fdb4 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -115,6 +115,7 @@ typedef struct VFIODevice { bool no_mmap; bool ram_block_discard_allowed; OnOffAuto enable_migration; + bool migration_events; VFIODeviceOps *ops; unsigned int num_irqs; unsigned int num_regions; diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index c4403a38ddb5e7e09fbcde0ad4132653ecaf0d24..af579b868d7caa726fde1eeb73c= 832ebc3136a7a 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -24,6 +24,7 @@ #include "migration/register.h" #include "migration/blocker.h" #include "qapi/error.h" +#include "qapi/qapi-events-vfio.h" #include "exec/ramlist.h" #include "exec/ram_addr.h" #include "pci.h" @@ -80,6 +81,58 @@ static const char *mig_state_to_str(enum vfio_device_mig= _state state) } } =20 +static VfioMigrationState +mig_state_to_qapi_state(enum vfio_device_mig_state state) +{ + switch (state) { + case VFIO_DEVICE_STATE_STOP: + return QAPI_VFIO_MIGRATION_STATE_STOP; + case VFIO_DEVICE_STATE_RUNNING: + return QAPI_VFIO_MIGRATION_STATE_RUNNING; + case VFIO_DEVICE_STATE_STOP_COPY: + return QAPI_VFIO_MIGRATION_STATE_STOP_COPY; + case VFIO_DEVICE_STATE_RESUMING: + return QAPI_VFIO_MIGRATION_STATE_RESUMING; + case VFIO_DEVICE_STATE_RUNNING_P2P: + return QAPI_VFIO_MIGRATION_STATE_RUNNING_P2P; + case VFIO_DEVICE_STATE_PRE_COPY: + return QAPI_VFIO_MIGRATION_STATE_PRE_COPY; + case VFIO_DEVICE_STATE_PRE_COPY_P2P: + return QAPI_VFIO_MIGRATION_STATE_PRE_COPY_P2P; + default: + g_assert_not_reached(); + } +} + +static void vfio_migration_send_event(VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + DeviceState *dev =3D vbasedev->dev; + g_autofree char *qom_path =3D NULL; + Object *obj; + + if (!vbasedev->migration_events) { + return; + } + + g_assert(vbasedev->ops->vfio_get_object); + obj =3D vbasedev->ops->vfio_get_object(vbasedev); + g_assert(obj); + qom_path =3D object_get_canonical_path(obj); + + qapi_event_send_vfio_migration( + dev->id, qom_path, mig_state_to_qapi_state(migration->device_state= )); +} + +static void vfio_migration_set_device_state(VFIODevice *vbasedev, + enum vfio_device_mig_state sta= te) +{ + VFIOMigration *migration =3D vbasedev->migration; + + migration->device_state =3D state; + vfio_migration_send_event(vbasedev); +} + static int vfio_migration_set_state(VFIODevice *vbasedev, enum vfio_device_mig_state new_state, enum vfio_device_mig_state recover_sta= te, @@ -131,12 +184,12 @@ static int vfio_migration_set_state(VFIODevice *vbase= dev, goto reset_device; } =20 - migration->device_state =3D recover_state; + vfio_migration_set_device_state(vbasedev, recover_state); =20 return ret; } =20 - migration->device_state =3D new_state; + vfio_migration_set_device_state(vbasedev, new_state); if (mig_state->data_fd !=3D -1) { if (migration->data_fd !=3D -1) { /* @@ -162,7 +215,7 @@ reset_device: strerror(errno)); } =20 - migration->device_state =3D VFIO_DEVICE_STATE_RUNNING; + vfio_migration_set_device_state(vbasedev, VFIO_DEVICE_STATE_RUNNING); =20 return ret; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4789d43c0f9cc7ef94b73adc815377f7222d8c57..b5d1d398b120076c85cdd92d617= 93393f65e8554 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3388,6 +3388,8 @@ static Property vfio_pci_dev_properties[] =3D { VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT, false), DEFINE_PROP_ON_OFF_AUTO("enable-migration", VFIOPCIDevice, vbasedev.enable_migration, ON_OFF_AUTO_AUTO), + DEFINE_PROP_BOOL("migration-events", VFIOPCIDevice, + vbasedev.migration_events, false), DEFINE_PROP_BOOL("x-no-mmap", VFIOPCIDevice, vbasedev.no_mmap, false), DEFINE_PROP_BOOL("x-balloon-allowed", VFIOPCIDevice, vbasedev.ram_block_discard_allowed, false), --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=WIwFnEfZuGfLHXJrLAXzuUt9YuuhEDuGwhowNxvKMB4ZgQ1V3K4FrO5+PRQtMP9erQpVaS2GMypNu08dWFD5L8a8UsNx25g/wjmRXnNsMDxxL1TTF7orsIp7E/FsN1EulPwE4NdpGLyZZDEYWfdelGePMCLcDIZpM1uEoxRifOY= 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=tEsTrJqprE7ehqM1WFBRNx3rhC2HpuESGFKtGQaEOVk=; b=A+wdHyrjuKU72ykMmuZCgAvBIH7dq1x/XMZNx5ozGEZZxuJ0wcFO8fWuc7+nML1eX1dTmr1+F8ERdEQwgosJm8whk8LQ+0Up2Ad1EvIQtUZS+cEgkcAXasplPt14SJ0BAXWpjv7zmh12sRudg62Lp//zUyCnWdgVQkqcDhcBb3k= 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 1716371793329479.08748425468275; 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 1s9ihF-0003lh-SZ; Wed, 22 May 2024 05:55:45 -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 1s9ih7-0003bP-OQ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:40 -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 1s9ih5-0001kR-8u for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:37 -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-416-CgJ1v5GxPBOniC7Zb7Z6Hw-1; Wed, 22 May 2024 05:55:31 -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 C896D801190; Wed, 22 May 2024 09:55:14 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 630032818; Wed, 22 May 2024 09:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371734; 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=tEsTrJqprE7ehqM1WFBRNx3rhC2HpuESGFKtGQaEOVk=; b=PyOXz4EFO8yxy0xOsuEActdjt5Ref/A2Ihj0/7GbLOmVfrwIxYdQEccR+xM8qI/bP8npBK +2z3kEqwL/x+9HShd18mXIef/ntzZzLywhbMVl29lu8q3ZdwyUspdc9GJ+zYb2n60gDjTc XAD/U4r4zE2PDALBg0xXfjbPCdqoiTs= X-MC-Unique: CgJ1v5GxPBOniC7Zb7Z6Hw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 17/47] vfio/migration: Don't emit STOP_COPY VFIO migration QAPI event twice Date: Wed, 22 May 2024 11:54:12 +0200 Message-ID: <20240522095442.195243-18-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371794825100005 From: Avihai Horon When migrating a VFIO device that supports pre-copy, it is transitioned to STOP_COPY twice: once in vfio_vmstate_change() and second time in vfio_save_complete_precopy(). The second transition is harmless, as it's a STOP_COPY->STOP_COPY no-op transition. However, with the newly added VFIO migration QAPI event, the STOP_COPY event is undesirably emitted twice. Prevent this by returning early in vfio_migration_set_state() if new_state is the same as current device state. Note that the STOP_COPY transition in vfio_save_complete_precopy() is essential for VFIO devices that don't support pre-copy, for migrating an already stopped guest and for snapshots. Signed-off-by: Avihai Horon Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index af579b868d7caa726fde1eeb73c832ebc3136a7a..56edffaf6251e28e39ef3299139= 4697abb1b9e55 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -150,6 +150,10 @@ static int vfio_migration_set_state(VFIODevice *vbased= ev, g_strdup_printf("%s: Failed setting device state to %s.", vbasedev->name, mig_state_to_str(new_state)); =20 + if (new_state =3D=3D migration->device_state) { + return 0; + } + feature->argsz =3D sizeof(buf); feature->flags =3D VFIO_DEVICE_FEATURE_SET | VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE; --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371845; cv=none; d=zohomail.com; s=zohoarc; b=khCq+mjoEykoOwMs0IIuDo5s55ncnA2vUk4TAXGW1g2cNJ6zNXmpgOtnU7OYSgjx5qZqdf2fwC2N+s9r9snj02tbglJMpycLHCGpkwG5bzMcwYOfKg3DC2xDKDPN+h0YHBz00O34x+Uw0V5ZExol9IG7RjJGnEe4/1ceTlLjYZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371845; 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=JT/bVHrvMqyK5ucSJY0O+P5XBU+ZBQiDckhZnyN66vk=; b=GT9i/tuyj7CA/ZjAJTYvXIbg7T5s80z1VFS478IxO5erXOUnyPRojRHk1/8rn+bgByS4s+gZp7ebYUzzxJ7UD+n3pTKn283RcQBLW1ZyTFcBCwuKQWxzarx8DSXeJHOVUBZn2bDtRrI3CyvngJO+6yYcDgc3xYq1GcUaHwefQDI= 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 1716371845016927.2101341634517; Wed, 22 May 2024 02:57:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ih3-0003ZJ-O1; Wed, 22 May 2024 05:55:33 -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 1s9igq-0003S3-EG for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:20 -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 1s9igo-0001Qv-R8 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:20 -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-611-O-ugEHkON0mPg8fxSqaXqQ-1; Wed, 22 May 2024 05:55:16 -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 2B3D9800994; Wed, 22 May 2024 09:55:16 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0934951BF; Wed, 22 May 2024 09:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371718; 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=JT/bVHrvMqyK5ucSJY0O+P5XBU+ZBQiDckhZnyN66vk=; b=TkhPxouE7B+dg/6UR9ULhXmXsRdDEPEn2UY3RtsFa/4KCXz5laSt5G0Pbs83agnR11qyHg tlvJ/9+0qpUnIC0JUAXxtmgklaizvbSMqHQxX8InCzQHpWgNFpM1PhigFTOzFv1LYI1Hbz MDxVEtqcyxXbe4cGNvZ8rUoNJW+Ln1c= X-MC-Unique: O-ugEHkON0mPg8fxSqaXqQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Avihai Horon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 18/47] vfio/migration: Enhance VFIO migration state tracing Date: Wed, 22 May 2024 11:54:13 +0200 Message-ID: <20240522095442.195243-19-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: 1716371847053100001 From: Avihai Horon Move trace_vfio_migration_set_state() to the top of the function, add recover_state to it, and add a new trace event to vfio_migration_set_device_state(). This improves tracing of device state changes as state changes are now also logged when vfio_migration_set_state() fails (covering recover state and device reset transitions) and in no-op state transitions to the same state. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Avihai Horon Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration.c | 8 ++++++-- hw/vfio/trace-events | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 56edffaf6251e28e39ef32991394697abb1b9e55..34d4be2ce1b13626a8690d47873= 66ee41a9ebe1e 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -129,6 +129,9 @@ static void vfio_migration_set_device_state(VFIODevice = *vbasedev, { VFIOMigration *migration =3D vbasedev->migration; =20 + trace_vfio_migration_set_device_state(vbasedev->name, + mig_state_to_str(state)); + migration->device_state =3D state; vfio_migration_send_event(vbasedev); } @@ -150,6 +153,9 @@ static int vfio_migration_set_state(VFIODevice *vbasede= v, g_strdup_printf("%s: Failed setting device state to %s.", vbasedev->name, mig_state_to_str(new_state)); =20 + trace_vfio_migration_set_state(vbasedev->name, mig_state_to_str(new_st= ate), + mig_state_to_str(recover_state)); + if (new_state =3D=3D migration->device_state) { return 0; } @@ -209,8 +215,6 @@ static int vfio_migration_set_state(VFIODevice *vbasede= v, migration->data_fd =3D mig_state->data_fd; } =20 - trace_vfio_migration_set_state(vbasedev->name, mig_state_to_str(new_st= ate)); - return 0; =20 reset_device: diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index f0474b244bf04d044e8327c88bf49aef349afcca..64161bf6f44cffd73851a90b706= 94120a5fb2a82 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -152,7 +152,8 @@ vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 vfio_load_state_device_data(const char *name, uint64_t data_size, int ret)= " (%s) size 0x%"PRIx64" ret %d" vfio_migration_realize(const char *name) " (%s)" -vfio_migration_set_state(const char *name, const char *state) " (%s) state= %s" +vfio_migration_set_device_state(const char *name, const char *state) " (%s= ) state %s" +vfio_migration_set_state(const char *name, const char *new_state, const ch= ar *recover_state) " (%s) new state %s, recover state %s" vfio_migration_state_notifier(const char *name, int state) " (%s) state %d" vfio_save_block(const char *name, int data_size) " (%s) data_size %d" vfio_save_cleanup(const char *name) " (%s)" --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371972; cv=none; d=zohomail.com; s=zohoarc; b=U/mDHuTA/BfkUns2lzuY3FD3iWgWIQsHq6Ty0a1yyWEQc8fTYUKkJozZqLsL+qoMhhZf3I+dNRYS3VXhSBkLB/NjqKO6JFAPKZD00TPbtCDh1cPI0+EKuoVrbcGP2uvYiOG2asgy4rHtv1O3q1K+ujo2a4cfxGQ88Uu1TVSJpHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371972; 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=iBxnSmYQ7sV1y/gKpXlFsOBwVTzLl/e3739ed4f2Da4=; b=CqFq2qA+FrMnOcgllLh4As0fBM/GkeNdflk+ad4JFXQk5oR2141Y6POGea34Gud1wLZmSO59FiFXTx1ZV51DE52GSMcWv8BskXYrDDQdRSSaUyt6poPDp6R+tSP1ln12oD2pLEp3Hf7ga/uur4jSS7gxNQM3JNP1gHL/1aN609w= 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 1716371972233385.7662949693414; Wed, 22 May 2024 02:59:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ih4-0003a2-BH; Wed, 22 May 2024 05:55:34 -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 1s9igv-0003Tg-3J for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:25 -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 1s9igr-0001eE-PV for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:23 -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-335-NNT2iThIPxOlFgsKgZMQqg-1; Wed, 22 May 2024 05:55:17 -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 845188058D5; Wed, 22 May 2024 09:55:17 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 605207412; Wed, 22 May 2024 09:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371721; 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=iBxnSmYQ7sV1y/gKpXlFsOBwVTzLl/e3739ed4f2Da4=; b=YEeIFcBHU0CxNGxT9eqWoO1SpWEZWegXZBe1jfoqxJntZVE3lDAowrpw71g149iYSOPL5V 8cqOn4WC8k6zssnrKeteHspShihhl7c2yqkWnTAOEhk7dX+aH+duyFzNKutkepJkSdamLU cB27EwMzvM1kRHv5qGgsPbq5w2brUl0= X-MC-Unique: NNT2iThIPxOlFgsKgZMQqg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 19/47] vfio/pci: Use g_autofree in vfio_realize Date: Wed, 22 May 2024 11:54:14 +0200 Message-ID: <20240522095442.195243-20-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: 1716371973689100003 From: Zhenzhong Duan Local pointer name is allocated before vfio_attach_device() call and freed after the call. Same for tmp when calling realpath(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index b5d1d398b120076c85cdd92d61793393f65e8554..84f7bff664fd7595b75cce1f697= 4068144f0d42d 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2972,12 +2972,13 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) ERRP_GUARD(); VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); VFIODevice *vbasedev =3D &vdev->vbasedev; - char *tmp, *subsys; + char *subsys; Error *err =3D NULL; int i, ret; bool is_mdev; char uuid[UUID_STR_LEN]; - char *name; + g_autofree char *name =3D NULL; + g_autofree char *tmp =3D NULL; =20 if (vbasedev->fd < 0 && !vbasedev->sysfsdev) { if (!(~vdev->host.domain || ~vdev->host.bus || @@ -3008,7 +3009,6 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) */ tmp =3D g_strdup_printf("%s/subsystem", vbasedev->sysfsdev); subsys =3D realpath(tmp, NULL); - g_free(tmp); is_mdev =3D subsys && (strcmp(subsys, "/sys/bus/mdev") =3D=3D 0); free(subsys); =20 @@ -3029,7 +3029,6 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 ret =3D vfio_attach_device(name, vbasedev, pci_device_iommu_address_space(pdev), errp); - g_free(name); if (ret) { goto error; } --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371945; cv=none; d=zohomail.com; s=zohoarc; b=gUwsP4HOcl0LHmf8k5S5YZSHbYbemle6Lo4H88iuLNIP7UgSxt27ofT/bdmdY1CWqeH4Ra3bF7XqdA4+7082IuqFKaUUJjBUBtRxRxa78Q9GBev1zeOPB/MKchU3pUtODzSNE2wjJw/5djN1XhNu3R6cFnDhoUSGki1Vy/99pAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371945; 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=3WaTlSsqxAurzfVnD7xv9hK2IAt2NGci5ug1KS6LYtw=; b=NTSoruqUHgjtYT1WuxIrSUxsU9KHk1PfnpInXaPfRzUEKt2YpzwkEZqx/Ft5WDv5DrohyFf2Ov7qoX+gS75UtmMn29dX/e+hWzBPBN+sBogqL2X5PaQDsToW+WVXx+aCdjzoEg5vuHTqXn1tDhkkVj8z7QIEvF0Tgto9CQBEm1g= 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 1716371945165645.1991225657384; Wed, 22 May 2024 02:59:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihC-0003e1-5C; Wed, 22 May 2024 05:55:42 -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 1s9igw-0003VT-TL for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:28 -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 1s9igt-0001ff-MK for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:26 -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-625-1mVmHPVQP5ugOuYSHqPctg-1; Wed, 22 May 2024 05:55:19 -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 E0722101A555; Wed, 22 May 2024 09:55:18 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8FC551BF; Wed, 22 May 2024 09:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371722; 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=3WaTlSsqxAurzfVnD7xv9hK2IAt2NGci5ug1KS6LYtw=; b=T6VKFONlicKzK7+m6oNdMgQiWXt3BfHcaVqKKsMPgX35F6Z6kps6HqXbdb9qsIVzvsQb1m mMR/mwk43uAsIcJq12cbj5mvmIXYFUK60LPU1UbgW+Hqe9FXkIyAdlPS7HXMCWd4HmrMV4 H1ec5QybYk5lQkfvofza4Fef5yg6WDs= X-MC-Unique: 1mVmHPVQP5ugOuYSHqPctg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 20/47] vfio/pci: Use g_autofree in iommufd_cdev_get_info_iova_range() Date: Wed, 22 May 2024 11:54:15 +0200 Message-ID: <20240522095442.195243-21-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: 1716371945543100001 From: Zhenzhong Duan Local pointer info is freed before return from iommufd_cdev_get_info_iova_range(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 8827ffe636e2aba1551ba794bf666a7a214590b7..c6441279728fcede1dde2a099c0= 76ad04c464a1f 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -258,7 +258,7 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFD= Container *container, uint32_t ioas_id, Error **errp) { VFIOContainerBase *bcontainer =3D &container->bcontainer; - struct iommu_ioas_iova_ranges *info; + g_autofree struct iommu_ioas_iova_ranges *info =3D NULL; struct iommu_iova_range *iova_ranges; int ret, sz, fd =3D container->be->fd; =20 @@ -291,12 +291,10 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMU= FDContainer *container, } bcontainer->pgsizes =3D info->out_iova_alignment; =20 - g_free(info); return 0; =20 error: ret =3D -errno; - g_free(info); error_setg_errno(errp, errno, "Cannot get IOVA ranges"); return ret; } --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716372061; cv=none; d=zohomail.com; s=zohoarc; b=f3jwFqR73W1zWqXUtE3nJg8ftxu/AojT4+PR9l36piW+02dlVYXIE2dxURSZ+odaurADKc1xwfVDULbDgA4qfVNRMlA472FUUlPio5ycDvTLRXER1BQlkotU0/LsU1NvZVTdTfdmtlFex6JanBasTQAjjivwmLtPsWdrcbnM9do= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372061; 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=bWjCvBHLClbA3cqzzO6MNrC/zHAI88qWAW+VrP5Fssw=; b=A6+d9oTbE5eYIvPEm/X/OkNhhku0O3kSKxlAHVdKGed27XZaV3xgHb/xj60WVGvoPzXMp4blzYEdTx7m52z+s8AjICVGgByR7Jj3o68lgUo3CAvcS9Z55z4qmCWVZRPt57g4D3oB8qkmPCXBzLKqyHoNXzj0+4Q8tw5nSlacek4= 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 1716372061782385.0062129431137; Wed, 22 May 2024 03:01:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ih1-0003Yg-PN; Wed, 22 May 2024 05:55:31 -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 1s9igw-0003VU-Tt for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:28 -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 1s9igu-0001g3-Rs for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:26 -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-504-q5fNgkBxNVS6bRFaFmjvZA-1; Wed, 22 May 2024 05:55:20 -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 41D608058D1; Wed, 22 May 2024 09:55:20 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 216E47414; Wed, 22 May 2024 09:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371722; 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=bWjCvBHLClbA3cqzzO6MNrC/zHAI88qWAW+VrP5Fssw=; b=EUS1hJafovU7Z/0RNyAE7IZUxxSeBojUo3UuJGX3OwnYgNLa48Rxayg7OJuAB6q/5v2Efv KHJ19L/pYJTXV2ShDtUVcg/b5uMB5WqikfegC/tCFIWtRrQpcchsNa5BL0OAClbXVIjuBJ r+EjaETEp77yxooN3xAWiKZEM7MjgHQ= X-MC-Unique: q5fNgkBxNVS6bRFaFmjvZA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 21/47] vfio: Make VFIOIOMMUClass::attach_device() and its wrapper return bool Date: Wed, 22 May 2024 11:54:16 +0200 Message-ID: <20240522095442.195243-22-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716372064179100005 From: Zhenzhong Duan Make VFIOIOMMUClass::attach_device() and its wrapper function vfio_attach_device() return bool. This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 4 ++-- include/hw/vfio/vfio-container-base.h | 4 ++-- hw/vfio/ap.c | 6 ++---- hw/vfio/ccw.c | 6 ++---- hw/vfio/common.c | 4 ++-- hw/vfio/container.c | 14 +++++++------- hw/vfio/iommufd.c | 11 +++++------ hw/vfio/pci.c | 5 ++--- hw/vfio/platform.c | 7 +++---- 9 files changed, 27 insertions(+), 34 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 878e34a12874f63fcb8bbc8dc8ca3d2dfa84fdb4..e85817e65e65317d08bc2b17b73= 8449198784796 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -222,8 +222,8 @@ void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); struct vfio_device_info *vfio_get_device_info(int fd); -int vfio_attach_device(char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp); +bool vfio_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp); void vfio_detach_device(VFIODevice *vbasedev); =20 int vfio_kvm_device_add_fd(int fd, Error **errp); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index b04057ad1aff73d974ecec718d0fe45f7a930b59..44927ca8c3583246145defe043a= c34da604d39bf 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -117,8 +117,8 @@ struct VFIOIOMMUClass { int (*dma_unmap)(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb); - int (*attach_device)(const char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp); + bool (*attach_device)(const char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp); void (*detach_device)(VFIODevice *vbasedev); =20 /* migration feature */ diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 8bb024e2fde4a1d72346dee4b662d762374326b9..ba653ef70f08ebdf482009baafc= 62eb33ebda9a8 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -154,7 +154,6 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevic= e *vapdev, static void vfio_ap_realize(DeviceState *dev, Error **errp) { ERRP_GUARD(); - int ret; Error *err =3D NULL; VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(dev); VFIODevice *vbasedev =3D &vapdev->vdev; @@ -163,9 +162,8 @@ static void vfio_ap_realize(DeviceState *dev, Error **e= rrp) return; } =20 - ret =3D vfio_attach_device(vbasedev->name, vbasedev, - &address_space_memory, errp); - if (ret) { + if (!vfio_attach_device(vbasedev->name, vbasedev, + &address_space_memory, errp)) { goto error; } =20 diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 1c630f6e9abe93ae0c2b5615d4409669f096c8c9..89bb98016764e65cf826183d7a3= 8c59d429f6eeb 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -579,7 +579,6 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) S390CCWDeviceClass *cdc =3D S390_CCW_DEVICE_GET_CLASS(cdev); VFIODevice *vbasedev =3D &vcdev->vdev; Error *err =3D NULL; - int ret; =20 /* Call the class init function for subchannel. */ if (cdc->realize) { @@ -593,9 +592,8 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) return; } =20 - ret =3D vfio_attach_device(cdev->mdevid, vbasedev, - &address_space_memory, errp); - if (ret) { + if (!vfio_attach_device(cdev->mdevid, vbasedev, + &address_space_memory, errp)) { goto out_attach_dev_err; } =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 1fbd10801d35079341a833fa68a43de2b758cde0..c04a259ffd7cfcfba480335bea1= ddff787f47bdc 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1523,8 +1523,8 @@ retry: return info; } =20 -int vfio_attach_device(char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp) +bool vfio_attach_device(char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) { const VFIOIOMMUClass *ops =3D VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY)); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 9534120d4ac835bb58e37667dad8d39205404c08..e7c416774791d506cc7c4696fb6= a6d94dc809c8e 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -910,8 +910,8 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Er= ror **errp) * @name and @vbasedev->name are likely to be different depending * on the type of the device, hence the need for passing @name */ -static int vfio_legacy_attach_device(const char *name, VFIODevice *vbasede= v, - AddressSpace *as, Error **errp) +static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbased= ev, + AddressSpace *as, Error **errp) { int groupid =3D vfio_device_groupid(vbasedev, errp); VFIODevice *vbasedev_iter; @@ -920,27 +920,27 @@ static int vfio_legacy_attach_device(const char *name= , VFIODevice *vbasedev, int ret; =20 if (groupid < 0) { - return groupid; + return false; } =20 trace_vfio_attach_device(vbasedev->name, groupid); =20 group =3D vfio_get_group(groupid, as, errp); if (!group) { - return -ENOENT; + return false; } =20 QLIST_FOREACH(vbasedev_iter, &group->device_list, next) { if (strcmp(vbasedev_iter->name, vbasedev->name) =3D=3D 0) { error_setg(errp, "device is already attached"); vfio_put_group(group); - return -EBUSY; + return false; } } ret =3D vfio_get_device(group, name, vbasedev, errp); if (ret) { vfio_put_group(group); - return ret; + return false; } =20 bcontainer =3D &group->container->bcontainer; @@ -948,7 +948,7 @@ static int vfio_legacy_attach_device(const char *name, = VFIODevice *vbasedev, QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next); QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next); =20 - return ret; + return true; } =20 static void vfio_legacy_detach_device(VFIODevice *vbasedev) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index c6441279728fcede1dde2a099c076ad04c464a1f..4c6992fca11969bc8fe26c11e90= 2e2521d6bff7a 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -299,8 +299,8 @@ error: return ret; } =20 -static int iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, - AddressSpace *as, Error **errp) +static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, + AddressSpace *as, Error **errp) { VFIOContainerBase *bcontainer; VFIOIOMMUFDContainer *container; @@ -315,7 +315,7 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, if (vbasedev->fd < 0) { devfd =3D iommufd_cdev_getfd(vbasedev->sysfsdev, errp); if (devfd < 0) { - return devfd; + return false; } vbasedev->fd =3D devfd; } else { @@ -392,7 +392,6 @@ static int iommufd_cdev_attach(const char *name, VFIODe= vice *vbasedev, memory_listener_register(&bcontainer->listener, bcontainer->space->as); =20 if (bcontainer->error) { - ret =3D -1; error_propagate_prepend(errp, bcontainer->error, "memory listener initialization failed: "); goto err_listener_register; @@ -431,7 +430,7 @@ found_container: =20 trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_ir= qs, vbasedev->num_regions, vbasedev->flags); - return 0; + return true; =20 err_listener_register: iommufd_cdev_ram_block_discard_disable(false); @@ -444,7 +443,7 @@ err_alloc_ioas: iommufd_cdev_unbind_and_disconnect(vbasedev); err_connect_bind: close(vbasedev->fd); - return ret; + return false; } =20 static void iommufd_cdev_detach(VFIODevice *vbasedev) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 84f7bff664fd7595b75cce1f6974068144f0d42d..c1adef5cf8fb241df510514610f= 05c8a0d51a9f9 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3027,9 +3027,8 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) name =3D g_strdup(vbasedev->name); } =20 - ret =3D vfio_attach_device(name, vbasedev, - pci_device_iommu_address_space(pdev), errp); - if (ret) { + if (!vfio_attach_device(name, vbasedev, + pci_device_iommu_address_space(pdev), errp)) { goto error; } =20 diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index dcd2365fb35344d4383989169fa23bab7cc3d8de..2bd16096bbd1b4a1da579448e93= 1cb0803d54bb6 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -552,10 +552,9 @@ static int vfio_base_device_init(VFIODevice *vbasedev,= Error **errp) return ret; } =20 - ret =3D vfio_attach_device(vbasedev->name, vbasedev, - &address_space_memory, errp); - if (ret) { - return ret; + if (!vfio_attach_device(vbasedev->name, vbasedev, + &address_space_memory, errp)) { + return -EINVAL; } =20 ret =3D vfio_populate_device(vbasedev, errp); --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716372104; cv=none; d=zohomail.com; s=zohoarc; b=jVm7oO2QXovTJZt+saegwupSFV/rSWsMTO/wNbw1H7RV+wb0llYm04hDAuEDo1Jc2a9rwf5+wdHOGceeQezusnzUU+SlOmncP1BQhJBLj7Ee+bZQELkZu76X7oUrvAelnGWE6TlsOve5l5i6qNM1j8vgCy2zlht16keYz2WUIj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372104; 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=+aiaEkCxG//DdU0IUGAS4mKXWBN7H5W5sSyTxn3jxbw=; b=FpkYiOvh4yNBwxjGBYLbQWNvernE3Yk1jsBJ9h6B/nbyzad4RrCP6UhYuwgrA+ZsplZf8lNXaH0CUnEKDU13scWP4ZT1520H1UFfULJKyYQrSBYj2DNOij9Bp/U4FDB3OtieHDJGj+Km1v4+1o9XVFiGmSiHO8uBL78Cgpy59+k= 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 1716372104273940.0158706189061; Wed, 22 May 2024 03:01:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ih1-0003Yk-W2; Wed, 22 May 2024 05:55:32 -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 1s9igy-0003WI-VI for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:30 -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 1s9igw-0001iU-RW for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:28 -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-15-7w3DL21MO-aB4m2YhnapCA-1; Wed, 22 May 2024 05:55:21 -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 96CCC8058D4; Wed, 22 May 2024 09:55:21 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76AEF7412; Wed, 22 May 2024 09:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371726; 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=+aiaEkCxG//DdU0IUGAS4mKXWBN7H5W5sSyTxn3jxbw=; b=EGHEBdu2UD5h92b9W5D7AqM78WGfaY+JiZCxXYKmbJVaKFkpy3r09pEhcbUYuNKnVM18Iu I18esY4APTSLtL656ms6EfkgM5sfI/FNUqCOVroxA8GEM0ftfJqKmiaWYnOrF5dKANvCRK HDjOJxy/ruhlN9zmHl1cKmr2oL1cJCc= X-MC-Unique: 7w3DL21MO-aB4m2YhnapCA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 22/47] vfio: Make VFIOIOMMUClass::setup() return bool Date: Wed, 22 May 2024 11:54:17 +0200 Message-ID: <20240522095442.195243-23-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: 1716372106379100009 From: Zhenzhong Duan This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 2 +- hw/vfio/container.c | 10 +++++----- hw/vfio/spapr.c | 12 +++++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 44927ca8c3583246145defe043ac34da604d39bf..202e23cb6b800983b036bf3808c= 0ec38b1c363d0 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -110,7 +110,7 @@ struct VFIOIOMMUClass { InterfaceClass parent_class; =20 /* basic feature */ - int (*setup)(VFIOContainerBase *bcontainer, Error **errp); + bool (*setup)(VFIOContainerBase *bcontainer, Error **errp); int (*dma_map)(const VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, void *vaddr, bool readonly); diff --git a/hw/vfio/container.c b/hw/vfio/container.c index e7c416774791d506cc7c4696fb6a6d94dc809c8e..f2e9560a1906c4151535260e348= 8ee80ca90e78b 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -507,7 +507,7 @@ static void vfio_get_iommu_info_migration(VFIOContainer= *container, } } =20 -static int vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp) +static bool vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp) { VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, bcontainer); @@ -517,7 +517,7 @@ static int vfio_legacy_setup(VFIOContainerBase *bcontai= ner, Error **errp) ret =3D vfio_get_iommu_info(container, &info); if (ret) { error_setg_errno(errp, -ret, "Failed to get VFIO IOMMU info"); - return ret; + return false; } =20 if (info->flags & VFIO_IOMMU_INFO_PGSIZES) { @@ -533,7 +533,7 @@ static int vfio_legacy_setup(VFIOContainerBase *bcontai= ner, Error **errp) vfio_get_info_iova_range(info, bcontainer); =20 vfio_get_iommu_info_migration(container, info); - return 0; + return true; } =20 static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, @@ -635,8 +635,8 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, =20 assert(bcontainer->ops->setup); =20 - ret =3D bcontainer->ops->setup(bcontainer, errp); - if (ret) { + if (!bcontainer->ops->setup(bcontainer, errp)) { + ret =3D -EINVAL; goto enable_discards_exit; } =20 diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 0d949bb728212534a7e2296e491aa8d95f45945d..148b257c9ca6a0f957115f8060d= db50e377dfcb8 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -458,8 +458,8 @@ static void vfio_spapr_container_release(VFIOContainerB= ase *bcontainer) } } =20 -static int vfio_spapr_container_setup(VFIOContainerBase *bcontainer, - Error **errp) +static bool vfio_spapr_container_setup(VFIOContainerBase *bcontainer, + Error **errp) { VFIOContainer *container =3D container_of(bcontainer, VFIOContainer, bcontainer); @@ -480,7 +480,7 @@ static int vfio_spapr_container_setup(VFIOContainerBase= *bcontainer, ret =3D ioctl(fd, VFIO_IOMMU_ENABLE); if (ret) { error_setg_errno(errp, errno, "failed to enable container"); - return -errno; + return false; } } else { scontainer->prereg_listener =3D vfio_prereg_listener; @@ -488,7 +488,6 @@ static int vfio_spapr_container_setup(VFIOContainerBase= *bcontainer, memory_listener_register(&scontainer->prereg_listener, &address_space_memory); if (bcontainer->error) { - ret =3D -1; error_propagate_prepend(errp, bcontainer->error, "RAM memory listener initialization failed: "); goto listener_unregister_exit; @@ -500,7 +499,6 @@ static int vfio_spapr_container_setup(VFIOContainerBase= *bcontainer, if (ret) { error_setg_errno(errp, errno, "VFIO_IOMMU_SPAPR_TCE_GET_INFO failed"); - ret =3D -errno; goto listener_unregister_exit; } =20 @@ -527,13 +525,13 @@ static int vfio_spapr_container_setup(VFIOContainerBa= se *bcontainer, 0x1000); } =20 - return 0; + return true; =20 listener_unregister_exit: if (v2) { memory_listener_unregister(&scontainer->prereg_listener); } - return ret; + return false; } =20 static void vfio_iommu_spapr_class_init(ObjectClass *klass, void *data) --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371929; cv=none; d=zohomail.com; s=zohoarc; b=il0h78edWjh7qF+4KsALW1ZsIyvHSyBFrFaFuMRYopjJU23MfHC/nmhwB76JFeaIBHpErPDC5vXPrXHC6lYwI5rz/W9uax76k23bTP55td/CDSXjeTDHP5dKgAuRXW9TXt7FUhMYLcZru2wrxEiNEvmgQrgspoNu23HKso7YuyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371929; 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=EKvPDWgFPSPC8JKnCi/wa4wS5hggDzLtJx0kiZlHEPA=; b=C+vVr39VfV4QXRfOxnJz5P6D7BgXmjEuvUd9rm7LwNE529WCVij0kNBrTGsrsXlP4hQuoJrhKA3vFY3jlrMsnlgBcIakxKgVL0b5BE5t84xgbWehV/WT1y94KbwxS73J0c8FN+QKofwG+yMUOfQwgqFWlW75Ew/yZupB3hbNHt0= 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 1716371929532164.26898402870268; Wed, 22 May 2024 02:58:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihC-0003cl-1N; Wed, 22 May 2024 05:55:42 -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 1s9ih0-0003XY-Sy for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:30 -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 1s9igx-0001iu-IS for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:28 -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-224-aZX8qPCUOgGlfzmxjjRkGw-1; Wed, 22 May 2024 05:55:23 -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 ED89A29AA3B4; Wed, 22 May 2024 09:55:22 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC00651BF; Wed, 22 May 2024 09:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371727; 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=EKvPDWgFPSPC8JKnCi/wa4wS5hggDzLtJx0kiZlHEPA=; b=YrfA9JoCvng01vumpOX+6p3GtED+yhiLEct9VSzC7OeKOcro5mmrLM77zkONZmg6XXOBlz Lz9jGG5k9w6f9pxQnuvsWlA01vuy2Q+nA+VCHmNNXtMbxOEJ9idDojhB/09KqcBBiMmtSx phJT3/x+YIFNuFziHd7Seery4fm22zg= X-MC-Unique: aZX8qPCUOgGlfzmxjjRkGw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 23/47] vfio: Make VFIOIOMMUClass::add_window() and its wrapper return bool Date: Wed, 22 May 2024 11:54:18 +0200 Message-ID: <20240522095442.195243-24-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371931482100001 From: Zhenzhong Duan Make VFIOIOMMUClass::add_window() and its wrapper function vfio_container_add_section_window() return bool. This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 12 ++++++------ hw/vfio/common.c | 2 +- hw/vfio/container-base.c | 8 ++++---- hw/vfio/spapr.c | 16 ++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index 202e23cb6b800983b036bf3808c0ec38b1c363d0..2776481fc97ef5720b10a4e3b3e= 6deaa075ece75 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -76,9 +76,9 @@ int vfio_container_dma_map(VFIOContainerBase *bcontainer, int vfio_container_dma_unmap(VFIOContainerBase *bcontainer, hwaddr iova, ram_addr_t size, IOMMUTLBEntry *iotlb); -int vfio_container_add_section_window(VFIOContainerBase *bcontainer, - MemoryRegionSection *section, - Error **errp); +bool vfio_container_add_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp); void vfio_container_del_section_window(VFIOContainerBase *bcontainer, MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, @@ -156,9 +156,9 @@ struct VFIOIOMMUClass { int (*pci_hot_reset)(VFIODevice *vbasedev, bool single); =20 /* SPAPR specific */ - int (*add_window)(VFIOContainerBase *bcontainer, - MemoryRegionSection *section, - Error **errp); + bool (*add_window)(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp); void (*del_window)(VFIOContainerBase *bcontainer, MemoryRegionSection *section); void (*release)(VFIOContainerBase *bcontainer); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index c04a259ffd7cfcfba480335bea1ddff787f47bdc..f9619a1dfbc689b10d70a60ce21= b9b018f32391f 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -588,7 +588,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, return; } =20 - if (vfio_container_add_section_window(bcontainer, section, &err)) { + if (!vfio_container_add_section_window(bcontainer, section, &err)) { goto fail; } =20 diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 26f4bb464a720c9895b35c7c9e01c84d6322c3c9..760d9d0622b2e847ecb3368c88d= f772efb06043f 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -31,12 +31,12 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontai= ner, return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb); } =20 -int vfio_container_add_section_window(VFIOContainerBase *bcontainer, - MemoryRegionSection *section, - Error **errp) +bool vfio_container_add_section_window(VFIOContainerBase *bcontainer, + MemoryRegionSection *section, + Error **errp) { if (!bcontainer->ops->add_window) { - return 0; + return true; } =20 return bcontainer->ops->add_window(bcontainer, section, errp); diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c index 148b257c9ca6a0f957115f8060ddb50e377dfcb8..47b040f1bcca7dd0b5cf052d941= b43541e98a3c5 100644 --- a/hw/vfio/spapr.c +++ b/hw/vfio/spapr.c @@ -323,7 +323,7 @@ static int vfio_spapr_create_window(VFIOContainer *cont= ainer, return 0; } =20 -static int +static bool vfio_spapr_container_add_section_window(VFIOContainerBase *bcontainer, MemoryRegionSection *section, Error **errp) @@ -351,13 +351,13 @@ vfio_spapr_container_add_section_window(VFIOContainer= Base *bcontainer, error_setg(errp, "Container %p can't map guest IOVA region" " 0x%"HWADDR_PRIx"..0x%"HWADDR_PRIx, container, iova, end); - return -EINVAL; + return false; } - return 0; + return true; } =20 if (container->iommu_type !=3D VFIO_SPAPR_TCE_v2_IOMMU) { - return 0; + return true; } =20 /* For now intersections are not allowed, we may relax this later */ @@ -373,14 +373,14 @@ vfio_spapr_container_add_section_window(VFIOContainer= Base *bcontainer, section->offset_within_address_space + int128_get64(section->size) - 1, hostwin->min_iova, hostwin->max_iova); - return -EINVAL; + return false; } } =20 ret =3D vfio_spapr_create_window(container, section, &pgsize); if (ret) { error_setg_errno(errp, -ret, "Failed to create SPAPR window"); - return ret; + return false; } =20 vfio_host_win_add(scontainer, section->offset_within_address_space, @@ -406,14 +406,14 @@ vfio_spapr_container_add_section_window(VFIOContainer= Base *bcontainer, "vfio: failed GROUP_SET_SPAPR_TCE for= " "KVM VFIO device %d and group fd %d", param.tablefd, param.groupfd); - return -errno; + return false; } trace_vfio_spapr_group_attach(param.groupfd, param.tablefd= ); } } } #endif - return 0; + return true; } =20 static void --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716372119; cv=none; d=zohomail.com; s=zohoarc; b=Rcsg3U5ctb47Iua8yePovFWY0WFYNnTsSSJZZfL+D3O/Xa9D7Y9wFfcGn0Y3vg3/nf4HPWY7bSTs+T3DglFgH3R5AAjLFWJ1/9dMpx+o8EvrttBkOFggyfvbEY87cfYygqecWOyAntq2bVtwfa5zkR/Wps7XJD2k13MW6rOvsqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372119; 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=U3DTNO1j5SMlYNlsYmgdbbnL9vW6hJcpWt869udaP+g=; b=TLl2NiHIs1wxnGIscqI1/gV6RN9ZNQ5LWOZOZOFYUouXsXj/UOmiqP1uqVuhi6/KEOdkwzSkuiChKwqH50KNDfWF8bxBQNFlXupcxBXNSpa24b4h158kQXeotx5KBsG0M0FDVfRxA3yNUUcTeLk2CyEFw35vf2IqgwMOLmH/Tcw= 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 1716372119601947.2060165802983; Wed, 22 May 2024 03:01:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihD-0003h1-Tb; Wed, 22 May 2024 05:55:43 -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 1s9ih0-0003Xa-TU for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:30 -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 1s9igy-0001j2-Nm for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:30 -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-259-ZGwaFJV5PBSeCCJbnEFOdQ-1; Wed, 22 May 2024 05:55:24 -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 5607129AA3B4; Wed, 22 May 2024 09:55:24 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EEAF7412; Wed, 22 May 2024 09:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371727; 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=U3DTNO1j5SMlYNlsYmgdbbnL9vW6hJcpWt869udaP+g=; b=I/017pzUrfcBujMPWnfY+3Pdw6v4XSMMgcDFviPGzk603HWGwWWaOokby2lACziZnL/UNF GpHuuMXraVoVrJK4ZPGL1zd3Rjz9Ru6pQfZfqMJJqC8cgUh4poHEINjFCJbsUZrcL/k+Ae kAG1L+P/dygOqtO/I8xDBkQTTBbTJXY= X-MC-Unique: ZGwaFJV5PBSeCCJbnEFOdQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 24/47] vfio/container: Make vfio_connect_container() return bool Date: Wed, 22 May 2024 11:54:19 +0200 Message-ID: <20240522095442.195243-25-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: 1716372120501100003 From: Zhenzhong Duan This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index f2e9560a1906c4151535260e3488ee80ca90e78b..802828ddff061fef25b8e4c997a= 68348d4be9892 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -536,8 +536,8 @@ static bool vfio_legacy_setup(VFIOContainerBase *bconta= iner, Error **errp) return true; } =20 -static int vfio_connect_container(VFIOGroup *group, AddressSpace *as, - Error **errp) +static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as, + Error **errp) { VFIOContainer *container; VFIOContainerBase *bcontainer; @@ -589,19 +589,18 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, error_report("vfio: error disconnecting group %d from" " container", group->groupid); } - return ret; + return false; } group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_nex= t); vfio_kvm_device_add_group(group); - return 0; + return true; } } =20 fd =3D qemu_open_old("/dev/vfio/vfio", O_RDWR); if (fd < 0) { error_setg_errno(errp, errno, "failed to open /dev/vfio/vfio"); - ret =3D -errno; goto put_space_exit; } =20 @@ -609,7 +608,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, if (ret !=3D VFIO_API_VERSION) { error_setg(errp, "supported vfio version: %d, " "reported version: %d", VFIO_API_VERSION, ret); - ret =3D -EINVAL; goto close_fd_exit; } =20 @@ -636,7 +634,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, assert(bcontainer->ops->setup); =20 if (!bcontainer->ops->setup(bcontainer, errp)) { - ret =3D -EINVAL; goto enable_discards_exit; } =20 @@ -652,7 +649,6 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, memory_listener_register(&bcontainer->listener, bcontainer->space->as); =20 if (bcontainer->error) { - ret =3D -1; error_propagate_prepend(errp, bcontainer->error, "memory listener initialization failed: "); goto listener_release_exit; @@ -660,7 +656,7 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, =20 bcontainer->initialized =3D true; =20 - return 0; + return true; listener_release_exit: QLIST_REMOVE(group, container_next); QLIST_REMOVE(bcontainer, next); @@ -685,7 +681,7 @@ close_fd_exit: put_space_exit: vfio_put_address_space(space); =20 - return ret; + return false; } =20 static void vfio_disconnect_container(VFIOGroup *group) @@ -772,7 +768,7 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSp= ace *as, Error **errp) group->groupid =3D groupid; QLIST_INIT(&group->device_list); =20 - if (vfio_connect_container(group, as, errp)) { + if (!vfio_connect_container(group, as, errp)) { error_prepend(errp, "failed to setup container for group %d: ", groupid); goto close_fd_exit; --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716371915; cv=none; d=zohomail.com; s=zohoarc; b=Z1VwUclHm4xifO6uovEQBE0PCaFqjKhQSIwCs6IFOm9Prr1aUylLL8TpZJhK6TMTUrU2osz0DMjwyHORxyZG1HpXq/Vplz6zcwYZyZQkVAyma83lKv44dIGEyZzo/HtdIwukgnBA/k9qjtzedRpstHGaF5xbUefg1AFg+nLjByc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371915; 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=vw2zTHzLsIJf+NLe+QWmmQ2AB9G2JtY38zOEeTbtoxo=; b=JGoOesOq7+Bwei1XkspWDaAKum/JKnlnOPvBCIfI5nlcTNd8xsoWBcdG8yMhMrBMOO9zBiBazt6Bvh4xY4hQVec/EVmxUuHBrQpegmG45Q5/7zvZmKKrOo+xo1MrfAnbF5ds+3Yd37V/lpOEf8r1CXgisooVrvKbPB96ky9w228= 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 1716371915509441.96909157412233; Wed, 22 May 2024 02:58:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihC-0003d6-1N; Wed, 22 May 2024 05:55:42 -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 1s9ih2-0003Z0-JQ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:32 -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 1s9ih0-0001jM-K7 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:31 -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-518-GnqohcBzNDuxLVkhRGEqog-1; Wed, 22 May 2024 05:55:25 -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 AB5F8380008D; Wed, 22 May 2024 09:55:25 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B07E28E5; Wed, 22 May 2024 09:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371729; 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=vw2zTHzLsIJf+NLe+QWmmQ2AB9G2JtY38zOEeTbtoxo=; b=SLt61pwnsPD+446DSmkxoGq35WSYHBrgborbKleqFvl/2XA8FxVCdRNfJLcfYMXahxHlDs i4HIrIX7iqOcejc3JGX9o2MMGZOvNfvcNbUws1NQbQ3ykHWqPM7O/a0ySUebMgDFWMS/s8 g3NdYvYb0jhyqk/yZg6aLgd1qBLkQuY= X-MC-Unique: GnqohcBzNDuxLVkhRGEqog-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 25/47] vfio/container: Make vfio_set_iommu() return bool Date: Wed, 22 May 2024 11:54:20 +0200 Message-ID: <20240522095442.195243-26-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371917395100001 From: Zhenzhong Duan This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 802828ddff061fef25b8e4c997a68348d4be9892..e330b2897423b97fee467884f42= 37669ceff4756 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -393,21 +393,20 @@ static const VFIOIOMMUClass *vfio_get_iommu_class(int= iommu_type, Error **errp) return VFIO_IOMMU_CLASS(klass); } =20 -static int vfio_set_iommu(VFIOContainer *container, int group_fd, - VFIOAddressSpace *space, Error **errp) +static bool vfio_set_iommu(VFIOContainer *container, int group_fd, + VFIOAddressSpace *space, Error **errp) { - int iommu_type, ret; + int iommu_type; const VFIOIOMMUClass *vioc; =20 iommu_type =3D vfio_get_iommu_type(container, errp); if (iommu_type < 0) { - return iommu_type; + return false; } =20 - ret =3D ioctl(group_fd, VFIO_GROUP_SET_CONTAINER, &container->fd); - if (ret) { + if (ioctl(group_fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) { error_setg_errno(errp, errno, "Failed to set group container"); - return -errno; + return false; } =20 while (ioctl(container->fd, VFIO_SET_IOMMU, iommu_type)) { @@ -422,7 +421,7 @@ static int vfio_set_iommu(VFIOContainer *container, int= group_fd, continue; } error_setg_errno(errp, errno, "Failed to set iommu for container"); - return -errno; + return false; } =20 container->iommu_type =3D iommu_type; @@ -430,11 +429,11 @@ static int vfio_set_iommu(VFIOContainer *container, i= nt group_fd, vioc =3D vfio_get_iommu_class(iommu_type, errp); if (!vioc) { error_setg(errp, "No available IOMMU models"); - return -EINVAL; + return false; } =20 vfio_container_init(&container->bcontainer, space, vioc); - return 0; + return true; } =20 static int vfio_get_iommu_info(VFIOContainer *container, @@ -615,8 +614,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, container->fd =3D fd; bcontainer =3D &container->bcontainer; =20 - ret =3D vfio_set_iommu(container, group->fd, space, errp); - if (ret) { + if (!vfio_set_iommu(container, group->fd, space, errp)) { goto free_container_exit; } =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716372049; cv=none; d=zohomail.com; s=zohoarc; b=cVZ3u4bV9vry47EJn+oqVK0I9uW+Fsa/+jaQTBtrU1zpmswXFVbFmEPORHAEpeJIddbWmeXcn5NVOXR06lSheYH4v1F8p9EQWaB5OPdChQC436U7JOcSh5D2lxaRpSuucz2CsOevsvAP41LcFTz6148SlEo2R1z1hRFC52KpooI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372049; 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=tasUQp7d0Yx+T4QoQ921x6/KbPxPVRWp4GsazcxRjlU=; b=MrCyZTNQDdRBp73zo26tfESLYtUNdlPOOCeyqehx9hNLwtC0mO/zJrEcCO4ojjLQJDSTkCOyfblJIfRTRPwrbQt1sozalaA+60bZqTHuKEO8mh1j0FcgQ7/9g0tUvTNjmxhu4qYQS6RfuSIL3GkElSIiFGvGYLDKNnj8eapfyU8= 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 1716372049654513.441288487957; Wed, 22 May 2024 03:00:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihL-0004BB-4i; Wed, 22 May 2024 05:55:51 -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 1s9ih4-0003a3-2k for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:34 -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 1s9ih2-0001jq-CB for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:33 -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-303-oiiYnyzQMJK6y-MrmgZ1pg-1; Wed, 22 May 2024 05:55:27 -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 0C55A101A525; Wed, 22 May 2024 09:55:27 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFE0F51BF; Wed, 22 May 2024 09:55:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371731; 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=tasUQp7d0Yx+T4QoQ921x6/KbPxPVRWp4GsazcxRjlU=; b=D4m5GbQrwxSnu1g8qQ2EucUZy0/D22FvO2YOb1g4Z5ypc/uHvba/CSxSNo4iaM3Hy0qS+S fDnDx4p4mc6TylnMgzk6h5w+xAHr6m2DfCrWhL/kMXpCDHC1iaJBmpYXOBG9ic8R7rk+kG /1l+HP8HO1f1XJW4M4LjdxCyoZ7Fmhc= X-MC-Unique: oiiYnyzQMJK6y-MrmgZ1pg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 26/47] vfio/container: Make vfio_get_device() return bool Date: Wed, 22 May 2024 11:54:21 +0200 Message-ID: <20240522095442.195243-27-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: 1716372050086100001 From: Zhenzhong Duan This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/container.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/hw/vfio/container.c b/hw/vfio/container.c index e330b2897423b97fee467884f4237669ceff4756..53649e397cab94f8a2b61e6d66f= 21d635556e04e 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -802,8 +802,8 @@ static void vfio_put_group(VFIOGroup *group) g_free(group); } =20 -static int vfio_get_device(VFIOGroup *group, const char *name, - VFIODevice *vbasedev, Error **errp) +static bool vfio_get_device(VFIOGroup *group, const char *name, + VFIODevice *vbasedev, Error **errp) { g_autofree struct vfio_device_info *info =3D NULL; int fd; @@ -815,14 +815,14 @@ static int vfio_get_device(VFIOGroup *group, const ch= ar *name, error_append_hint(errp, "Verify all devices in group %d are bound to vfio- " "or pci-stub and not already in use\n", group->group= id); - return fd; + return false; } =20 info =3D vfio_get_device_info(fd); if (!info) { error_setg_errno(errp, errno, "error getting device info"); close(fd); - return -1; + return false; } =20 /* @@ -837,7 +837,7 @@ static int vfio_get_device(VFIOGroup *group, const char= *name, error_setg(errp, "Inconsistent setting of support for discardi= ng " "RAM (e.g., balloon) within group"); close(fd); - return -1; + return false; } =20 if (!group->ram_block_discard_allowed) { @@ -858,7 +858,7 @@ static int vfio_get_device(VFIOGroup *group, const char= *name, =20 vbasedev->reset_works =3D !!(info->flags & VFIO_DEVICE_FLAGS_RESET); =20 - return 0; + return true; } =20 static void vfio_put_base_device(VFIODevice *vbasedev) @@ -911,7 +911,6 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, VFIODevice *vbasedev_iter; VFIOGroup *group; VFIOContainerBase *bcontainer; - int ret; =20 if (groupid < 0) { return false; @@ -931,8 +930,7 @@ static bool vfio_legacy_attach_device(const char *name,= VFIODevice *vbasedev, return false; } } - ret =3D vfio_get_device(group, name, vbasedev, errp); - if (ret) { + if (!vfio_get_device(group, name, vbasedev, errp)) { vfio_put_group(group); return false; } --=20 2.45.1 From nobody Mon Nov 25 08:03:46 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=1716372091; cv=none; d=zohomail.com; s=zohoarc; b=iypflkfyISJHyfUDndHpxDUdMgH6RLkvy7/cs4T3Ujevz7LgOrohHlQ1eYwUJS8qzuYZT9KLu1+bfKBdIB3lB5nJ5/pQ8HOV3L3c/86DdBaNSaAQ+9gEhR53uBYe9zGMa0sphdhZlc7ilw5SbSFpXWJZqNWreyLTPgZbzf39sC0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372091; 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=kFtutvjf0zUiypPGo01idxZBqeuziW+TRjNWvGNy6Ss=; b=R6BebyBK9JsB5x9vZ3KxXtBH47NrUoAmO9U8Z5oX1bx9OK5Mv7AecyNyJ0HBvBo7AC9mGE+c83w61YUhctYoo2pknp0zQYWBpILcfLvBSA1t03n0O5hLygkrEhk5QLjsAUMONKeHqPisvz0PDO0qdt9fGNJkvVJzUvHmlZnPGWM= 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 1716372091554204.70090758153424; Wed, 22 May 2024 03:01:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihM-0004Kn-6I; Wed, 22 May 2024 05:55:52 -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 1s9ih5-0003af-N0 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:36 -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 1s9ih3-0001k3-ND for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:35 -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-613-e5yMDknzPVqf9QHJK-GQ5g-1; Wed, 22 May 2024 05:55:28 -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 607733C0009E; Wed, 22 May 2024 09:55:28 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40C2F28E2; Wed, 22 May 2024 09:55:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371732; 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=kFtutvjf0zUiypPGo01idxZBqeuziW+TRjNWvGNy6Ss=; b=Tqpr4uC1JyWmnQHm9+vAJXFI2N4uCbf6mEg5o/wKA/P0olWsdHMpiO7ShNI2H8CWvT/VTi kPnJ+/k3yQF+MSiujyGpbOWMVS/RjvsoaIV40wsyUgarQxfBnZ+XxLCqXW1jYYsl/xLHHq fKWZTlDdehmJHPR5wyJMUQDW8WQ4rOo= X-MC-Unique: e5yMDknzPVqf9QHJK-GQ5g-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 27/47] vfio/iommufd: Make iommufd_cdev_*() return bool Date: Wed, 22 May 2024 11:54:22 +0200 Message-ID: <20240522095442.195243-28-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: 1716372094325100003 From: Zhenzhong Duan This is to follow the coding standand to return bool if 'Error **' is used to pass error. The changed functions include: iommufd_cdev_kvm_device_add iommufd_cdev_connect_and_bind iommufd_cdev_attach_ioas_hwpt iommufd_cdev_detach_ioas_hwpt iommufd_cdev_attach_container iommufd_cdev_get_info_iova_range After the change, all functions in hw/vfio/iommufd.c follows the standand. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/iommufd.c | 88 +++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 4c6992fca11969bc8fe26c11e902e2521d6bff7a..84c86b970e756d34b202d5b18ae= 51c30c730e092 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -49,9 +49,9 @@ static int iommufd_cdev_unmap(const VFIOContainerBase *bc= ontainer, container->ioas_id, iova, size); } =20 -static int iommufd_cdev_kvm_device_add(VFIODevice *vbasedev, Error **errp) +static bool iommufd_cdev_kvm_device_add(VFIODevice *vbasedev, Error **errp) { - return vfio_kvm_device_add_fd(vbasedev->fd, errp); + return !vfio_kvm_device_add_fd(vbasedev->fd, errp); } =20 static void iommufd_cdev_kvm_device_del(VFIODevice *vbasedev) @@ -63,18 +63,16 @@ static void iommufd_cdev_kvm_device_del(VFIODevice *vba= sedev) } } =20 -static int iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **err= p) +static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **er= rp) { IOMMUFDBackend *iommufd =3D vbasedev->iommufd; struct vfio_device_bind_iommufd bind =3D { .argsz =3D sizeof(bind), .flags =3D 0, }; - int ret; =20 - ret =3D iommufd_backend_connect(iommufd, errp); - if (ret) { - return ret; + if (iommufd_backend_connect(iommufd, errp)) { + return false; } =20 /* @@ -82,15 +80,13 @@ static int iommufd_cdev_connect_and_bind(VFIODevice *vb= asedev, Error **errp) * in KVM. Especially for some emulated devices, it requires * to have kvm information in the device open. */ - ret =3D iommufd_cdev_kvm_device_add(vbasedev, errp); - if (ret) { + if (!iommufd_cdev_kvm_device_add(vbasedev, errp)) { goto err_kvm_device_add; } =20 /* Bind device to iommufd */ bind.iommufd =3D iommufd->fd; - ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind); - if (ret) { + if (ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) { error_setg_errno(errp, errno, "error bind device fd=3D%d to iommuf= d=3D%d", vbasedev->fd, bind.iommufd); goto err_bind; @@ -99,12 +95,12 @@ static int iommufd_cdev_connect_and_bind(VFIODevice *vb= asedev, Error **errp) vbasedev->devid =3D bind.out_devid; trace_iommufd_cdev_connect_and_bind(bind.iommufd, vbasedev->name, vbasedev->fd, vbasedev->devid); - return ret; + return true; err_bind: iommufd_cdev_kvm_device_del(vbasedev); err_kvm_device_add: iommufd_backend_disconnect(iommufd); - return ret; + return false; } =20 static void iommufd_cdev_unbind_and_disconnect(VFIODevice *vbasedev) @@ -176,10 +172,10 @@ out: return ret; } =20 -static int iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t id, +static bool iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t i= d, Error **errp) { - int ret, iommufd =3D vbasedev->iommufd->fd; + int iommufd =3D vbasedev->iommufd->fd; struct vfio_device_attach_iommufd_pt attach_data =3D { .argsz =3D sizeof(attach_data), .flags =3D 0, @@ -187,38 +183,38 @@ static int iommufd_cdev_attach_ioas_hwpt(VFIODevice *= vbasedev, uint32_t id, }; =20 /* Attach device to an IOAS or hwpt within iommufd */ - ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_dat= a); - if (ret) { + if (ioctl(vbasedev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_data)) { error_setg_errno(errp, errno, "[iommufd=3D%d] error attach %s (%d) to id=3D%d", iommufd, vbasedev->name, vbasedev->fd, id); - } else { - trace_iommufd_cdev_attach_ioas_hwpt(iommufd, vbasedev->name, - vbasedev->fd, id); + return false; } - return ret; + + trace_iommufd_cdev_attach_ioas_hwpt(iommufd, vbasedev->name, + vbasedev->fd, id); + return true; } =20 -static int iommufd_cdev_detach_ioas_hwpt(VFIODevice *vbasedev, Error **err= p) +static bool iommufd_cdev_detach_ioas_hwpt(VFIODevice *vbasedev, Error **er= rp) { - int ret, iommufd =3D vbasedev->iommufd->fd; + int iommufd =3D vbasedev->iommufd->fd; struct vfio_device_detach_iommufd_pt detach_data =3D { .argsz =3D sizeof(detach_data), .flags =3D 0, }; =20 - ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_DETACH_IOMMUFD_PT, &detach_dat= a); - if (ret) { + if (ioctl(vbasedev->fd, VFIO_DEVICE_DETACH_IOMMUFD_PT, &detach_data)) { error_setg_errno(errp, errno, "detach %s failed", vbasedev->name); - } else { - trace_iommufd_cdev_detach_ioas_hwpt(iommufd, vbasedev->name); + return false; } - return ret; + + trace_iommufd_cdev_detach_ioas_hwpt(iommufd, vbasedev->name); + return true; } =20 -static int iommufd_cdev_attach_container(VFIODevice *vbasedev, - VFIOIOMMUFDContainer *container, - Error **errp) +static bool iommufd_cdev_attach_container(VFIODevice *vbasedev, + VFIOIOMMUFDContainer *container, + Error **errp) { return iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, err= p); } @@ -228,7 +224,7 @@ static void iommufd_cdev_detach_container(VFIODevice *v= basedev, { Error *err =3D NULL; =20 - if (iommufd_cdev_detach_ioas_hwpt(vbasedev, &err)) { + if (!iommufd_cdev_detach_ioas_hwpt(vbasedev, &err)) { error_report_err(err); } } @@ -254,20 +250,19 @@ static int iommufd_cdev_ram_block_discard_disable(boo= l state) return ram_block_uncoordinated_discard_disable(state); } =20 -static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *containe= r, - uint32_t ioas_id, Error **errp) +static bool iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *contain= er, + uint32_t ioas_id, Error **err= p) { VFIOContainerBase *bcontainer =3D &container->bcontainer; g_autofree struct iommu_ioas_iova_ranges *info =3D NULL; struct iommu_iova_range *iova_ranges; - int ret, sz, fd =3D container->be->fd; + int sz, fd =3D container->be->fd; =20 info =3D g_malloc0(sizeof(*info)); info->size =3D sizeof(*info); info->ioas_id =3D ioas_id; =20 - ret =3D ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info); - if (ret && errno !=3D EMSGSIZE) { + if (ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info) && errno !=3D EMSGSIZE) { goto error; } =20 @@ -275,8 +270,7 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMUFD= Container *container, info =3D g_realloc(info, sizeof(*info) + sz); info->allowed_iovas =3D (uintptr_t)(info + 1); =20 - ret =3D ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info); - if (ret) { + if (ioctl(fd, IOMMU_IOAS_IOVA_RANGES, info)) { goto error; } =20 @@ -291,12 +285,11 @@ static int iommufd_cdev_get_info_iova_range(VFIOIOMMU= FDContainer *container, } bcontainer->pgsizes =3D info->out_iova_alignment; =20 - return 0; + return true; =20 error: - ret =3D -errno; error_setg_errno(errp, errno, "Cannot get IOVA ranges"); - return ret; + return false; } =20 static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, @@ -322,8 +315,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, devfd =3D vbasedev->fd; } =20 - ret =3D iommufd_cdev_connect_and_bind(vbasedev, errp); - if (ret) { + if (!iommufd_cdev_connect_and_bind(vbasedev, errp)) { goto err_connect_bind; } =20 @@ -336,7 +328,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, vbasedev->iommufd !=3D container->be) { continue; } - if (iommufd_cdev_attach_container(vbasedev, container, &err)) { + if (!iommufd_cdev_attach_container(vbasedev, container, &err)) { const char *msg =3D error_get_pretty(err); =20 trace_iommufd_cdev_fail_attach_existing_container(msg); @@ -369,8 +361,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, vfio_container_init(bcontainer, space, iommufd_vioc); QLIST_INSERT_HEAD(&space->containers, bcontainer, next); =20 - ret =3D iommufd_cdev_attach_container(vbasedev, container, errp); - if (ret) { + if (!iommufd_cdev_attach_container(vbasedev, container, errp)) { goto err_attach_container; } =20 @@ -379,8 +370,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, goto err_discard_disable; } =20 - ret =3D iommufd_cdev_get_info_iova_range(container, ioas_id, &err); - if (ret) { + if (!iommufd_cdev_get_info_iova_range(container, ioas_id, &err)) { error_append_hint(&err, "Fallback to default 64bit IOVA range and 4K page size\= n"); warn_report_err(err); --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371897; cv=none; d=zohomail.com; s=zohoarc; b=AdJ9X/ms1FAHA7gbDUUJ15jhqxPfgIkOQi5BSBy+gNJ8CN+N0GiPmy0E3Oa/ixywHYUmpYSklOmSaL5KfWKMBWJGog8icBTt54vb8nl0Ds1w9M7jc/6sz4c/6b2n5oqr3rda5hIvhWk6qsjjQ5e2X9mX3D/tNjFzUbOquRPdnCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371897; 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=cRuuNZBzxypv/pnih3IuYyo3ywdxPulrg4+T5lQo/rM=; b=gz6xJdACia6r+aWmaj6wi28LXpg33VZK/UqhieCE86LxB7vMXbx6+iH1wAg2CuUcsG06vl/QQDE+Zehf/HvAgM6A0hAjOLDTyjptVMy86V5Vqho75LX59B3D7WWYGGFgeVLEFY7fOYWDyFuCRnLlLWPN/Vez82+L7YNZhPDRdVk= 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 1716371897755460.02133744950413; Wed, 22 May 2024 02:58:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihG-0003nJ-Nq; Wed, 22 May 2024 05:55:46 -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 1s9ih4-0003a4-31 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:34 -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 1s9ih2-0001jt-Bx for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:33 -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-588-nJjsmpVfPEmlL6Kyq9Euxw-1; Wed, 22 May 2024 05:55:30 -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 B65F5101A551; Wed, 22 May 2024 09:55:29 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95A257412; Wed, 22 May 2024 09:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371731; 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=cRuuNZBzxypv/pnih3IuYyo3ywdxPulrg4+T5lQo/rM=; b=P6I9Q31DQlR1Ax57NapmT7HGqxSG8V9oTceFJHDLkxqO24BB2UNg0rzfbUt9kvBOuPaMW/ yf+96w+YwUV2JoJEZK8xXL8+zx9IFL8CISBBf3kQdEIovSPWvbh3ZWR/ZKfipa7fbv6oQR HZvfmL8e4IyB9q/fe+kJ5HfVkmI7NWk= X-MC-Unique: nJjsmpVfPEmlL6Kyq9Euxw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 28/47] vfio/cpr: Make vfio_cpr_register_container() return bool Date: Wed, 22 May 2024 11:54:23 +0200 Message-ID: <20240522095442.195243-29-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371899330100001 From: Zhenzhong Duan This is to follow the coding standand to return bool if 'Error **' is used to pass error. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 2 +- hw/vfio/container.c | 3 +-- hw/vfio/cpr.c | 4 ++-- hw/vfio/iommufd.c | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index e85817e65e65317d08bc2b17b738449198784796..b7bb4f5304addcdb03c971f27f9= 9e5350ad0940a 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -229,7 +229,7 @@ void vfio_detach_device(VFIODevice *vbasedev); int vfio_kvm_device_add_fd(int fd, Error **errp); int vfio_kvm_device_del_fd(int fd, Error **errp); =20 -int vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **err= p); +bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp); void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer); =20 extern const MemoryRegionOps vfio_region_ops; diff --git a/hw/vfio/container.c b/hw/vfio/container.c index 53649e397cab94f8a2b61e6d66f21d635556e04e..096cc972586df14a4a68074b703= 8a9661b1558e2 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -618,8 +618,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, goto free_container_exit; } =20 - ret =3D vfio_cpr_register_container(bcontainer, errp); - if (ret) { + if (!vfio_cpr_register_container(bcontainer, errp)) { goto free_container_exit; } =20 diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c index 392c2dd95d14664bade0ae74655e91bc839504c0..87e51fcee176fe1fa93349f08e9= f9ca84b474729 100644 --- a/hw/vfio/cpr.c +++ b/hw/vfio/cpr.c @@ -25,12 +25,12 @@ static int vfio_cpr_reboot_notifier(NotifierWithReturn = *notifier, return 0; } =20 -int vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **err= p) +bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **er= rp) { migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier, vfio_cpr_reboot_notifier, MIG_MODE_CPR_REBOOT); - return 0; + return true; } =20 void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 84c86b970e756d34b202d5b18ae51c30c730e092..6a446b16dcd64838dc9ebb6150c= d5ed85ec6fef3 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -396,8 +396,7 @@ found_container: goto err_listener_register; } =20 - ret =3D vfio_cpr_register_container(bcontainer, errp); - if (ret) { + if (!vfio_cpr_register_container(bcontainer, errp)) { goto err_listener_register; } =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371923; cv=none; d=zohomail.com; s=zohoarc; b=CIWvp8a0tBV0Zag1sVIzEN2upSiYFDchFnJAb/aZo0XFpTLlBb+5kvGX2hXuIdJqknpYe51D1Eih1Prup95cJ4lI3ueCTv0O5B5OscQR0KZHFkRta4O0pUzXbQN2Q/l6Fsl9BxD573ZmjYiaVGrpBt9PnItJJVBo0v12gulWSrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371923; 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=3IyGXEIi8Lck1UpUIn2/C+Qvo2TjwD4ZA/zkD428RJ8=; b=Lw0K0K7K01Tw08lTkOXnuFxNQYLFgPVF1kbNd38CrO8fHrQgD4dBpqSUPdt0g484OEL1btbISmqVxRNvJTPGmSuEogYl4L43hdSAQGL+5vTlnRrNaI3xx7+DjE5CdK+VVYGntuUVu0ny2Wae+PgKEV1S1rHFfSNeBc38vOasll0= 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 171637192352280.32977506839097; Wed, 22 May 2024 02:58:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihI-0003xw-7v; Wed, 22 May 2024 05:55:48 -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 1s9ih8-0003bW-1s for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:40 -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 1s9ih6-0001kT-98 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:37 -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-484-SIxyxu6NONiFXsB1UtYdzA-1; Wed, 22 May 2024 05:55:31 -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 1A1111C29EA4; Wed, 22 May 2024 09:55:31 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB17C28E2; Wed, 22 May 2024 09:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371734; 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=3IyGXEIi8Lck1UpUIn2/C+Qvo2TjwD4ZA/zkD428RJ8=; b=Wm1d81BJnhfF8ksgl36SJ5zvbJV2HC4djeNjxWf5Yhv6xjmfpAqD0Kf1c3qQV9AdNyoX2w SxQd4t/uNago5SfAhEtzEGUnJ4xYaje2o5wzfyYGak1dCZ6k+Vwb82CAvfYBklwkRFYDwU vljVgiHti6pZa8WuW7c+/pIrN19kBAk= X-MC-Unique: SIxyxu6NONiFXsB1UtYdzA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 29/47] backends/iommufd: Make iommufd_backend_*() return bool Date: Wed, 22 May 2024 11:54:24 +0200 Message-ID: <20240522095442.195243-30-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371925476100005 From: Zhenzhong Duan This is to follow the coding standand to return bool if 'Error **' is used to pass error. The changed functions include: iommufd_backend_connect iommufd_backend_alloc_ioas By this chance, simplify the functions a bit by avoiding duplicate recordings, e.g., log through either error interface or trace, not both. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/sysemu/iommufd.h | 6 +++--- backends/iommufd.c | 29 +++++++++++++---------------- hw/vfio/iommufd.c | 5 ++--- backends/trace-events | 4 ++-- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h index 9af27ebd6ccb78ca8e16aa3c62629aab9f7f31e4..293bfbe967215381532b8267227= dde61fa9157b7 100644 --- a/include/sysemu/iommufd.h +++ b/include/sysemu/iommufd.h @@ -23,11 +23,11 @@ struct IOMMUFDBackend { /*< public >*/ }; =20 -int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); +bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); void iommufd_backend_disconnect(IOMMUFDBackend *be); =20 -int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, - Error **errp); +bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp); void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr i= ova, ram_addr_t size, void *vaddr, bool readonly); diff --git a/backends/iommufd.c b/backends/iommufd.c index 76a0204852f73466a9f31492a08d89d468bff7c0..c506afbdac4beddb7dac88f74f1= 0544f7a083e58 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -72,24 +72,22 @@ static void iommufd_backend_class_init(ObjectClass *oc,= void *data) object_class_property_add_str(oc, "fd", NULL, iommufd_backend_set_fd); } =20 -int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) +bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp) { - int fd, ret =3D 0; + int fd; =20 if (be->owned && !be->users) { fd =3D qemu_open_old("/dev/iommu", O_RDWR); if (fd < 0) { error_setg_errno(errp, errno, "/dev/iommu opening failed"); - ret =3D fd; - goto out; + return false; } be->fd =3D fd; } be->users++; -out: - trace_iommufd_backend_connect(be->fd, be->owned, - be->users, ret); - return ret; + + trace_iommufd_backend_connect(be->fd, be->owned, be->users); + return true; } =20 void iommufd_backend_disconnect(IOMMUFDBackend *be) @@ -106,25 +104,24 @@ out: trace_iommufd_backend_disconnect(be->fd, be->users); } =20 -int iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, - Error **errp) +bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, + Error **errp) { - int ret, fd =3D be->fd; + int fd =3D be->fd; struct iommu_ioas_alloc alloc_data =3D { .size =3D sizeof(alloc_data), .flags =3D 0, }; =20 - ret =3D ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data); - if (ret) { + if (ioctl(fd, IOMMU_IOAS_ALLOC, &alloc_data)) { error_setg_errno(errp, errno, "Failed to allocate ioas"); - return ret; + return false; } =20 *ioas_id =3D alloc_data.out_ioas_id; - trace_iommufd_backend_alloc_ioas(fd, *ioas_id, ret); + trace_iommufd_backend_alloc_ioas(fd, *ioas_id); =20 - return ret; + return true; } =20 void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 6a446b16dcd64838dc9ebb6150cd5ed85ec6fef3..554f9a6292454f51015ab3a56df= 3fab6a482ccb7 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -71,7 +71,7 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *vba= sedev, Error **errp) .flags =3D 0, }; =20 - if (iommufd_backend_connect(iommufd, errp)) { + if (!iommufd_backend_connect(iommufd, errp)) { return false; } =20 @@ -346,8 +346,7 @@ static bool iommufd_cdev_attach(const char *name, VFIOD= evice *vbasedev, } =20 /* Need to allocate a new dedicated container */ - ret =3D iommufd_backend_alloc_ioas(vbasedev->iommufd, &ioas_id, errp); - if (ret < 0) { + if (!iommufd_backend_alloc_ioas(vbasedev->iommufd, &ioas_id, errp)) { goto err_alloc_ioas; } =20 diff --git a/backends/trace-events b/backends/trace-events index d45c6e31a67ed66d94787f60eb08a525cf6ff68b..211e6f374adcef25be0409ce3e4= 2cbed6f31b744 100644 --- a/backends/trace-events +++ b/backends/trace-events @@ -7,11 +7,11 @@ dbus_vmstate_loading(const char *id) "id: %s" dbus_vmstate_saving(const char *id) "id: %s" =20 # iommufd.c -iommufd_backend_connect(int fd, bool owned, uint32_t users, int ret) "fd= =3D%d owned=3D%d users=3D%d (%d)" +iommufd_backend_connect(int fd, bool owned, uint32_t users) "fd=3D%d owned= =3D%d users=3D%d" iommufd_backend_disconnect(int fd, uint32_t users) "fd=3D%d users=3D%d" iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=3D%d" iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_= t size, void *vaddr, bool readonly, int ret) " iommufd=3D%d ioas=3D%d iova= =3D0x%"PRIx64" size=3D0x%"PRIx64" addr=3D%p readonly=3D%d (%d)" iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t i= ova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=3D%d ioas= =3D%d iova=3D0x%"PRIx64" size=3D0x%"PRIx64" (%d)" iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint6= 4_t size, int ret) " iommufd=3D%d ioas=3D%d iova=3D0x%"PRIx64" size=3D0x%"P= RIx64" (%d)" -iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas, int ret) " iommufd= =3D%d ioas=3D%d (%d)" +iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=3D%d ioas= =3D%d" iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=3D%d = id=3D%d (%d)" --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716372101; cv=none; d=zohomail.com; s=zohoarc; b=N+3G8SHyqRSi506UQzJqna6upoHfyhK5V1mvWc7rwXG5IiupSNAfyHAhIpI8Cn85yragMQC4plYcShmMM4JDBv/A9+Huid8evGYHlZtP6rsgn0ho+M+Iku4mhv7GdcDUJ29bgi+U9VTYl0YS+9gWbI+7iKo7fs8h4jfcNybxNZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372101; 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=DMOxYYRcoL+OG3/njrsJOgo7fJUzW9n8pgdZCpEu3hI=; b=I5arahs/QSXYtPNFmX0XEQCkvWlvufynysvmHJqdx4El738AZNG6WtbyVHNbpz+TCBJwG/0ivCxWzzx6dZDimUdtDMRyHLQhA8jcy+GqknESep7oXpiS64pAFdF0t0PUQvz+pJw6bPjYDNr+5ocp8je0x/3YCOTTeeXq9e1Junw= 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 1716372101007307.3457723215124; Wed, 22 May 2024 03:01:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihE-0003hI-7Q; Wed, 22 May 2024 05:55:44 -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 1s9ih9-0003cB-0I for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:40 -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 1s9ih6-0001kU-AN for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:38 -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-660-QkjBp-0uP1O6yAeCcW9SHg-1; Wed, 22 May 2024 05:55:33 -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 C6B91857A83; Wed, 22 May 2024 09:55:32 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EDE42870; Wed, 22 May 2024 09:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371734; 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=DMOxYYRcoL+OG3/njrsJOgo7fJUzW9n8pgdZCpEu3hI=; b=GjC3NHb892PA4KUv/X/30qXF5uEP+wRLLwx9lQt2+1zWp0pOQEV7lZGUfKBXd4pwjo9Hlr DRQvPuwmqlQhz0qjT9aVFrCnbXiaMR8t4OYpvRur0dehAjpqRjtvBx8jkwPlAo5Jgao/xh Vklf7uVSMveqIy2eizgQJzwcCI2YYEE= X-MC-Unique: QkjBp-0uP1O6yAeCcW9SHg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , Gerd Hoffmann , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 30/47] vfio/display: Fix error path in call site of ramfb_setup() Date: Wed, 22 May 2024 11:54:25 +0200 Message-ID: <20240522095442.195243-31-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716372102526100003 From: Zhenzhong Duan vfio_display_dmabuf_init() and vfio_display_region_init() calls ramfb_setup() without checking its return value. So we may run into a situation that vfio_display_probe() succeed but errp is set. This is risky and may lead to assert failure in error_setv(). Cc: Gerd Hoffmann Fixes: b290659fc3d ("hw/vfio/display: add ramfb support") Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/display.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/vfio/display.c b/hw/vfio/display.c index fe624a6c9b86e7204e2763ab62ef60903f19d350..d28b724102d5970cb2b9dc7464d= c7575b6f441d9 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -361,6 +361,9 @@ static int vfio_display_dmabuf_init(VFIOPCIDevice *vdev= , Error **errp) vdev); if (vdev->enable_ramfb) { vdev->dpy->ramfb =3D ramfb_setup(errp); + if (!vdev->dpy->ramfb) { + return -EINVAL; + } } vfio_display_edid_init(vdev); return 0; @@ -488,6 +491,9 @@ static int vfio_display_region_init(VFIOPCIDevice *vdev= , Error **errp) vdev); if (vdev->enable_ramfb) { vdev->dpy->ramfb =3D ramfb_setup(errp); + if (!vdev->dpy->ramfb) { + return -EINVAL; + } } return 0; } --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371924; cv=none; d=zohomail.com; s=zohoarc; b=YSqzmSIGenfmGfZ+pTtCPeUiBIZJAXb/nhYhqy3oMOghkzXXXl1oXip0OW7mZcpA+SrmO0bQoi2NUFvwtbr5320Wh+qZO4+luyJkeOVd3IiGBHKB1+p2Xp6RUwW8z/o2n6Z2JBLVIo32M83xYr1uuTxx/ndtj6PZPGfR7jNV+G0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371924; 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=MK7K8BRp1eb4ATPYy85ppbWOHv6VwOzA0avlScVc0/4=; b=I2wgFyPVpbXL3ZuwWCJRqqurcKEoMBm/UPCPfKg73HX2wVIAYzr4T3WNelfZXfk8c17MAQVXDk9bDbIeJj0WnzqJZiLMqQ1pCt9N+7FGeA1bSTstRj8YvnwGu5w4TBT29YoMuIHQbPkt8rS0UxRZV+zBnVCrMFlkxa1JqaBNYJg= 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 1716371924181550.3691135046266; Wed, 22 May 2024 02:58:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihG-0003i9-16; Wed, 22 May 2024 05:55:46 -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 1s9ih9-0003cc-R7 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:40 -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 1s9ih8-0001kr-8h for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:39 -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-577-mrdypOdFOduDmMsgojTCGw-1; Wed, 22 May 2024 05:55:34 -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 343AB185AD2D; Wed, 22 May 2024 09:55:34 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07D9228E2; Wed, 22 May 2024 09:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371737; 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=MK7K8BRp1eb4ATPYy85ppbWOHv6VwOzA0avlScVc0/4=; b=QkomxB7k7nEFs/lS2Sy+gq7L/ifc2rfh8tbemmj2re1/lBiSgwHqHSXe1U8dHLEmFi1fl6 S3lGz5AbEVRwZdY8Q+PPBwRxbboioAnTLnQAUrt0c6dCE5zenxsACUrRpRPMfRezqk51pD X1tUoMf06EKh26AkQ4ekYw/J6xaOvTs= X-MC-Unique: mrdypOdFOduDmMsgojTCGw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 31/47] vfio/display: Make vfio_display_*() return bool Date: Wed, 22 May 2024 11:54:26 +0200 Message-ID: <20240522095442.195243-32-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: 1716371925444100002 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 2 +- hw/vfio/display.c | 20 ++++++++++---------- hw/vfio/pci.c | 3 +-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 92cd62d1159dbd47d878454f201f9c18112a7692..a5ac9efd4bb6d4070cac02f3eeb= 156d1018cd20f 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -232,7 +232,7 @@ int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, Error **errp); =20 void vfio_display_reset(VFIOPCIDevice *vdev); -int vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); +bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); void vfio_display_finalize(VFIOPCIDevice *vdev); =20 extern const VMStateDescription vfio_display_vmstate; diff --git a/hw/vfio/display.c b/hw/vfio/display.c index d28b724102d5970cb2b9dc7464dc7575b6f441d9..661e921616f4b85613d5f6053c3= 0348a4ee6cbd2 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -348,11 +348,11 @@ static const GraphicHwOps vfio_display_dmabuf_ops =3D= { .ui_info =3D vfio_display_edid_ui_info, }; =20 -static int vfio_display_dmabuf_init(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_display_dmabuf_init(VFIOPCIDevice *vdev, Error **errp) { if (!display_opengl) { error_setg(errp, "vfio-display-dmabuf: opengl not available"); - return -1; + return false; } =20 vdev->dpy =3D g_new0(VFIODisplay, 1); @@ -362,11 +362,11 @@ static int vfio_display_dmabuf_init(VFIOPCIDevice *vd= ev, Error **errp) if (vdev->enable_ramfb) { vdev->dpy->ramfb =3D ramfb_setup(errp); if (!vdev->dpy->ramfb) { - return -EINVAL; + return false; } } vfio_display_edid_init(vdev); - return 0; + return true; } =20 static void vfio_display_dmabuf_exit(VFIODisplay *dpy) @@ -483,7 +483,7 @@ static const GraphicHwOps vfio_display_region_ops =3D { .gfx_update =3D vfio_display_region_update, }; =20 -static int vfio_display_region_init(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_display_region_init(VFIOPCIDevice *vdev, Error **errp) { vdev->dpy =3D g_new0(VFIODisplay, 1); vdev->dpy->con =3D graphic_console_init(DEVICE(vdev), 0, @@ -492,10 +492,10 @@ static int vfio_display_region_init(VFIOPCIDevice *vd= ev, Error **errp) if (vdev->enable_ramfb) { vdev->dpy->ramfb =3D ramfb_setup(errp); if (!vdev->dpy->ramfb) { - return -EINVAL; + return false; } } - return 0; + return true; } =20 static void vfio_display_region_exit(VFIODisplay *dpy) @@ -510,7 +510,7 @@ static void vfio_display_region_exit(VFIODisplay *dpy) =20 /* ---------------------------------------------------------------------- = */ =20 -int vfio_display_probe(VFIOPCIDevice *vdev, Error **errp) +bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp) { struct vfio_device_gfx_plane_info probe; int ret; @@ -533,11 +533,11 @@ int vfio_display_probe(VFIOPCIDevice *vdev, Error **e= rrp) =20 if (vdev->display =3D=3D ON_OFF_AUTO_AUTO) { /* not an error in automatic mode */ - return 0; + return true; } =20 error_setg(errp, "vfio: device doesn't support any (known) display met= hod"); - return -1; + return false; } =20 void vfio_display_finalize(VFIOPCIDevice *vdev) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c1adef5cf8fb241df510514610f05c8a0d51a9f9..a447013a1da90f534ab07409c6c= a39263f7f6f88 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3200,8 +3200,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) } =20 if (vdev->display !=3D ON_OFF_AUTO_OFF) { - ret =3D vfio_display_probe(vdev, errp); - if (ret) { + if (!vfio_display_probe(vdev, errp)) { goto out_deregister; } } --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716372124; cv=none; d=zohomail.com; s=zohoarc; b=LIqmJv8rBJatS9xpuFfXVUEhEPDYcocZJZLbhk48/SqMtfDDnz2zbIENfCiiR+WjuNT2JKwXGosODIRSly0Av8oEBwtf5k7bHdrIy88XKI+SGoHumXRG6BXvglqAC4Ia2mMcvZc3ASb9zaHwh4W0QFWNWpcqlWWXPCGZIgCzutM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372124; 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=nZUMeKTzot/OLM2x334vR7f5WKqELIyvA+NQUVE+Wis=; b=XIQ6T9c5PRLX9wUC3dvSbpxAp/Kciof4tQ3N+94VRwQRtyuFBcChPLJNZbQBHR0uDXRHndmRqc3i9dcnfyGdFiz+kUD7bERhLJD309CKbci0gn/BXnNY7v7qQ6SaXRSc2Pypp4xAndtsT9Psy+Wkx93l+flwjIDsw1h6BgJ90kg= 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 1716372124047396.0981564939211; Wed, 22 May 2024 03:02:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihE-0003hb-KJ; Wed, 22 May 2024 05:55:44 -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 1s9ihB-0003dY-6a for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:41 -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 1s9ih9-0001l6-OS for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:40 -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-592-ZzG78P_4MTOh9VH53JdZsQ-1; Wed, 22 May 2024 05:55:35 -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 8895D3800089; Wed, 22 May 2024 09:55:35 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 654367412; Wed, 22 May 2024 09:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371739; 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=nZUMeKTzot/OLM2x334vR7f5WKqELIyvA+NQUVE+Wis=; b=YD0TcuqNm5DLY1yhX8Abf+C3pQRL4z7Wmy9IH0fW1mkaYDtV1MdpPpkp3K1+3vo7Xva6nK 7yofZBVCtdkcjDl7rxK85Q6w2Wd3SKCfQpeYzTE0+NF3YwtncwhJ3ntzorCVgUXXnBEq1a 7BvVDBJbS+MxhSqX5N9V9J7fo154kTk= X-MC-Unique: ZzG78P_4MTOh9VH53JdZsQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 32/47] vfio/helpers: Use g_autofree in vfio_set_irq_signaling() Date: Wed, 22 May 2024 11:54:27 +0200 Message-ID: <20240522095442.195243-33-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716372124495100003 From: Zhenzhong Duan Local pointer irq_set is freed before return from vfio_set_irq_signaling(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/helpers.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 47b4096c05ee8915c42b763fa18754c425aa00f6..1f3bdd9bf059beec186d87ba477= 2f2f6e34bc7d4 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -111,7 +111,7 @@ int vfio_set_irq_signaling(VFIODevice *vbasedev, int in= dex, int subindex, int action, int fd, Error **errp) { ERRP_GUARD(); - struct vfio_irq_set *irq_set; + g_autofree struct vfio_irq_set *irq_set =3D NULL; int argsz, ret =3D 0; const char *name; int32_t *pfd; @@ -130,7 +130,6 @@ int vfio_set_irq_signaling(VFIODevice *vbasedev, int in= dex, int subindex, if (ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) { ret =3D -errno; } - g_free(irq_set); =20 if (!ret) { return 0; --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371972; cv=none; d=zohomail.com; s=zohoarc; b=Z/D4ex2UZPBPLyXKKy8+7EdknNsp/Xe5yJXwgxJwRCwsnjbgBiMcPmMkUXWfC6x+8G31WCIz8aJ2e+qfySlIzPrSEI1SrIuRc9J/H27JZe9I+ozaek3Hmm3sP2uc+BYlHYSLW+q35AIWRvh1jtsp0/YMwxP33Bsihz87AdYaCmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371972; 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=xkFlQMtohJj8//vP37dXhvJksj+4U+xOpp45FX5Unf8=; b=AiunX1AqLp0mwgaBW4Gjl/pzx1i3Gp2Hc8m6soJpVoo7/WzG7g8qpNOaF28nBzBhWe7BAQXLQ6QAT5wozDNFoeYsGI0BUl7IMU6jpluQYQIemyQnMRkGhega3I03eY5opG97Qh+u4Kc7luhGUn9fvgE/AH/sqYRNAE0FoxXbvWw= 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 1716371972137997.2786495213084; Wed, 22 May 2024 02:59:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihK-0004Af-UZ; Wed, 22 May 2024 05:55:51 -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 1s9ihC-0003fm-Tx for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:42 -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 1s9ihA-0001lG-Sj for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:42 -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-9-agmYHbl_M9K6Xkr9r8Q_1g-1; Wed, 22 May 2024 05:55:37 -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 E31B3380673C; Wed, 22 May 2024 09:55:36 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1ED028E2; Wed, 22 May 2024 09:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371740; 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=xkFlQMtohJj8//vP37dXhvJksj+4U+xOpp45FX5Unf8=; b=Tn1TFW8pWMM9tI0pismlb281Eg5i1RCqoabo7pYo14Ibs//0quIYktcUkbHjhVvw+lbDqK aa+PVivtgrjPc27TQINX6dBSWSnIyBor06EN9kHu1P2ELz61Ujbb56VLOKD89B0GcBbFFB b4NNV9q9gtb74XfQtbcOvJ1I/mGJhyQ= X-MC-Unique: agmYHbl_M9K6Xkr9r8Q_1g-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 33/47] vfio/helpers: Make vfio_set_irq_signaling() return bool Date: Wed, 22 May 2024 11:54:28 +0200 Message-ID: <20240522095442.195243-34-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: 1716371973696100004 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 4 ++-- hw/vfio/ap.c | 8 +++---- hw/vfio/ccw.c | 8 +++---- hw/vfio/helpers.c | 18 ++++++---------- hw/vfio/pci.c | 40 ++++++++++++++++++----------------- hw/vfio/platform.c | 18 +++++++--------- 6 files changed, 46 insertions(+), 50 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b7bb4f5304addcdb03c971f27f99e5350ad0940a..b712799caffdc950b593a87d569= d7f5281976e2f 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -207,8 +207,8 @@ void vfio_spapr_container_deinit(VFIOContainer *contain= er); void vfio_disable_irqindex(VFIODevice *vbasedev, int index); void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index); void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index); -int vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, - int action, int fd, Error **errp); +bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, + int action, int fd, Error **errp); void vfio_region_write(void *opaque, hwaddr addr, uint64_t data, unsigned size); uint64_t vfio_region_read(void *opaque, diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index ba653ef70f08ebdf482009baafc62eb33ebda9a8..d8a9615feec065e98f538319120= 87d9878fdff9c 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -117,8 +117,8 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice = *vapdev, fd =3D event_notifier_get_fd(notifier); qemu_set_fd_handler(fd, fd_read, NULL, vapdev); =20 - if (vfio_set_irq_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER, = fd, - errp)) { + if (!vfio_set_irq_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER,= fd, + errp)) { qemu_set_fd_handler(fd, NULL, NULL, vapdev); event_notifier_cleanup(notifier); } @@ -141,8 +141,8 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevic= e *vapdev, return; } =20 - if (vfio_set_irq_signaling(&vapdev->vdev, irq, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_set_irq_signaling(&vapdev->vdev, irq, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vapdev->vdev.name); } =20 diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 89bb98016764e65cf826183d7a38c59d429f6eeb..1f578a3c75d975e12bbac52b368= 3e6fd193801cb 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -434,8 +434,8 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevic= e *vcdev, fd =3D event_notifier_get_fd(notifier); qemu_set_fd_handler(fd, fd_read, NULL, vcdev); =20 - if (vfio_set_irq_signaling(vdev, irq, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { + if (!vfio_set_irq_signaling(vdev, irq, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { qemu_set_fd_handler(fd, NULL, NULL, vcdev); event_notifier_cleanup(notifier); } @@ -464,8 +464,8 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDev= ice *vcdev, return; } =20 - if (vfio_set_irq_signaling(&vcdev->vdev, irq, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_set_irq_signaling(&vcdev->vdev, irq, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name); } =20 diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 1f3bdd9bf059beec186d87ba4772f2f6e34bc7d4..9edbc966884de12e7248af8d50d= 87f26c8cd2764 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -107,12 +107,12 @@ static const char *index_to_str(VFIODevice *vbasedev,= int index) } } =20 -int vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, - int action, int fd, Error **errp) +bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, + int action, int fd, Error **errp) { ERRP_GUARD(); g_autofree struct vfio_irq_set *irq_set =3D NULL; - int argsz, ret =3D 0; + int argsz; const char *name; int32_t *pfd; =20 @@ -127,15 +127,11 @@ int vfio_set_irq_signaling(VFIODevice *vbasedev, int = index, int subindex, pfd =3D (int32_t *)&irq_set->data; *pfd =3D fd; =20 - if (ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) { - ret =3D -errno; + if (!ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) { + return true; } =20 - if (!ret) { - return 0; - } - - error_setg_errno(errp, -ret, "VFIO_DEVICE_SET_IRQS failure"); + error_setg_errno(errp, errno, "VFIO_DEVICE_SET_IRQS failure"); =20 name =3D index_to_str(vbasedev, index); if (name) { @@ -146,7 +142,7 @@ int vfio_set_irq_signaling(VFIODevice *vbasedev, int in= dex, int subindex, error_prepend(errp, "Failed to %s %s eventfd signaling for interrupt ", fd < 0 ? "tear down" : "set up", action_to_str(action)); - return ret; + return false; } =20 /* diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index a447013a1da90f534ab07409c6ca39263f7f6f88..358da4497b8ab9b58b4f36252d1= 857279efbe521 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -147,10 +147,10 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev,= Error **errp) goto fail_irqfd; } =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_UNMASK, - event_notifier_get_fd(&vdev->intx.unmask), - errp)) { + if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, = 0, + VFIO_IRQ_SET_ACTION_UNMASK, + event_notifier_get_fd(&vdev->intx.unmask), + errp)) { goto fail_vfio; } =20 @@ -295,8 +295,8 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) fd =3D event_notifier_get_fd(&vdev->intx.interrupt); qemu_set_fd_handler(fd, vfio_intx_interrupt, NULL, vdev); =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { + if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, = 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->intx.interrupt); return -errno; @@ -590,9 +590,10 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, un= signed int nr, fd =3D event_notifier_get_fd(&vector->interrupt); } =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, - VFIO_PCI_MSIX_IRQ_INDEX, nr, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &e= rr)) { + if (!vfio_set_irq_signaling(&vdev->vbasedev, + VFIO_PCI_MSIX_IRQ_INDEX, nr, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, + &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.nam= e); } } @@ -634,8 +635,9 @@ static void vfio_msix_vector_release(PCIDevice *pdev, u= nsigned int nr) int32_t fd =3D event_notifier_get_fd(&vector->interrupt); Error *err =3D NULL; =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDE= X, nr, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err))= { + if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_IND= EX, + nr, VFIO_IRQ_SET_ACTION_TRIGGER, fd, + &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } } @@ -2873,8 +2875,8 @@ static void vfio_register_err_notifier(VFIOPCIDevice = *vdev) fd =3D event_notifier_get_fd(&vdev->err_notifier); qemu_set_fd_handler(fd, vfio_err_notifier_handler, NULL, vdev); =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { + if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->err_notifier); @@ -2890,8 +2892,8 @@ static void vfio_unregister_err_notifier(VFIOPCIDevic= e *vdev) return; } =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } qemu_set_fd_handler(event_notifier_get_fd(&vdev->err_notifier), @@ -2938,8 +2940,8 @@ static void vfio_register_req_notifier(VFIOPCIDevice = *vdev) fd =3D event_notifier_get_fd(&vdev->req_notifier); qemu_set_fd_handler(fd, vfio_req_notifier_handler, NULL, vdev); =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { + if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->req_notifier); @@ -2956,8 +2958,8 @@ static void vfio_unregister_req_notifier(VFIOPCIDevic= e *vdev) return; } =20 - if (vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { + if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } qemu_set_fd_handler(event_notifier_get_fd(&vdev->req_notifier), diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 2bd16096bbd1b4a1da579448e931cb0803d54bb6..3233ca86918a22b69265b83a1a9= dec8b6b59380f 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -115,18 +115,17 @@ static int vfio_set_trigger_eventfd(VFIOINTp *intp, VFIODevice *vbasedev =3D &intp->vdev->vbasedev; int32_t fd =3D event_notifier_get_fd(intp->interrupt); Error *err =3D NULL; - int ret; =20 qemu_set_fd_handler(fd, (IOHandler *)handler, NULL, intp); =20 - ret =3D vfio_set_irq_signaling(vbasedev, intp->pin, 0, - VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err); - if (ret) { + if (!vfio_set_irq_signaling(vbasedev, intp->pin, 0, + VFIO_IRQ_SET_ACTION_TRIGGER, fd, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vbasedev->name); qemu_set_fd_handler(fd, NULL, NULL, NULL); + return -EINVAL; } =20 - return ret; + return 0; } =20 /* @@ -355,15 +354,14 @@ static int vfio_set_resample_eventfd(VFIOINTp *intp) int32_t fd =3D event_notifier_get_fd(intp->unmask); VFIODevice *vbasedev =3D &intp->vdev->vbasedev; Error *err =3D NULL; - int ret; =20 qemu_set_fd_handler(fd, NULL, NULL, NULL); - ret =3D vfio_set_irq_signaling(vbasedev, intp->pin, 0, - VFIO_IRQ_SET_ACTION_UNMASK, fd, &err); - if (ret) { + if (!vfio_set_irq_signaling(vbasedev, intp->pin, 0, + VFIO_IRQ_SET_ACTION_UNMASK, fd, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vbasedev->name); + return -EINVAL; } - return ret; + return 0; } =20 /** --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716372006; cv=none; d=zohomail.com; s=zohoarc; b=JGZ3Hyv3ynOk1R5GysM/sAIxTm2xb0L+d0zkjq9A6aslp/MLrHBuNiqQQPDNom9qMmSDjKzzbWZXC22ohZoTfXNfojkd6vuv325IhCRYC5ld+jFPjk/dpCrWNlHtHaj5piWUvJoQFQhaR3vQ7/WYLKIS2t0lbJqhN2Gf3yBcITc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372006; 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=ZPJI4jkMtJpab0/3uJYRgdID4KuU50kijZ9YVzhF8fo=; b=a07bEztYUaLZKQItdnCHmGiYerS76OIC6qd9Ayhg1mI8x0ua2Kwy6qsdh7+FJ50RKlFXlFiICvXghFkz/1wnMwMUqVMSLLfSrS3KTnUXbXy9txjbdmAYtq+XbcXql2N8db10Za5B76kGy2ygqoXseqXf+/gNBSz2kcDm9APfiSc= 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 171637200660732.01911334571855; Wed, 22 May 2024 03:00:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihI-0003yA-8J; Wed, 22 May 2024 05:55:48 -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 1s9ihG-0003n6-7g for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:46 -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 1s9ihD-0001lh-Fu for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:45 -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-133-B1nthK5bNqWkPPij9uub9g-1; Wed, 22 May 2024 05:55:38 -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 45F75185A780; Wed, 22 May 2024 09:55:38 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22ECE51BF; Wed, 22 May 2024 09:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371742; 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=ZPJI4jkMtJpab0/3uJYRgdID4KuU50kijZ9YVzhF8fo=; b=D8ziA4Gqmm3sVLnpRrRDPyaon326ZhBxb6GSgwb/AyOoMWtcvty7MdxGTSQCpVWMA2xsfN RqaRWcVUU1OroUkOR21ilU5kwHgeBM3ZfQEAKsvUEFRr/lVp16muhzCu3TIT28a6hyZEJI KnyaD4WjAacnS4DKLOPESuUFdPjawuc= X-MC-Unique: B1nthK5bNqWkPPij9uub9g-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 34/47] vfio/helpers: Make vfio_device_get_name() return bool Date: Wed, 22 May 2024 11:54:29 +0200 Message-ID: <20240522095442.195243-35-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: 1716372011871100005 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 2 +- hw/vfio/ap.c | 2 +- hw/vfio/ccw.c | 2 +- hw/vfio/helpers.c | 8 ++++---- hw/vfio/pci.c | 2 +- hw/vfio/platform.c | 5 ++--- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index b712799caffdc950b593a87d569d7f5281976e2f..4cb1ab8645dcdf604f3c2bb2932= 8668fd5eb7284 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -279,7 +279,7 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcon= tainer, uint64_t iova, 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); +bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp); void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p); void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, DeviceState *dev, bool ram_discard); diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index d8a9615feec065e98f53831912087d9878fdff9c..c12531a7886a2fe87598be0861f= ba5923bd2c206 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -158,7 +158,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **e= rrp) VFIOAPDevice *vapdev =3D VFIO_AP_DEVICE(dev); VFIODevice *vbasedev =3D &vapdev->vdev; =20 - if (vfio_device_get_name(vbasedev, errp) < 0) { + if (!vfio_device_get_name(vbasedev, errp)) { return; } =20 diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 1f578a3c75d975e12bbac52b3683e6fd193801cb..8850ca17c84632d278e27819cd5= 2e104ed436d6c 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -588,7 +588,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) } } =20 - if (vfio_device_get_name(vbasedev, errp) < 0) { + if (!vfio_device_get_name(vbasedev, errp)) { return; } =20 diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 9edbc966884de12e7248af8d50d87f26c8cd2764..4b079dc383683a71d1d96507a0f= b66a4bc3ba923 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -607,7 +607,7 @@ bool vfio_has_region_cap(VFIODevice *vbasedev, int regi= on, uint16_t cap_type) return ret; } =20 -int vfio_device_get_name(VFIODevice *vbasedev, Error **errp) +bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp) { ERRP_GUARD(); struct stat st; @@ -616,7 +616,7 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **= errp) if (stat(vbasedev->sysfsdev, &st) < 0) { error_setg_errno(errp, errno, "no such host device"); error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev); - return -errno; + return false; } /* User may specify a name, e.g: VFIO platform device */ if (!vbasedev->name) { @@ -625,7 +625,7 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **= errp) } else { if (!vbasedev->iommufd) { error_setg(errp, "Use FD passing only with iommufd backend"); - return -EINVAL; + return false; } /* * Give a name with fd so any function printing out vbasedev->name @@ -636,7 +636,7 @@ int vfio_device_get_name(VFIODevice *vbasedev, Error **= errp) } } =20 - return 0; + return true; } =20 void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **err= p) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 358da4497b8ab9b58b4f36252d1857279efbe521..aad012c34885ff2a5a39039777d= ddd962236b41b 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2999,7 +2999,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) vdev->host.slot, vdev->host.function); } =20 - if (vfio_device_get_name(vbasedev, errp) < 0) { + if (!vfio_device_get_name(vbasedev, errp)) { return; } =20 diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 3233ca86918a22b69265b83a1a9dec8b6b59380f..e1a32863d919fe09a743f5fb108= f9787984d4378 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -545,9 +545,8 @@ static int vfio_base_device_init(VFIODevice *vbasedev, = Error **errp) vbasedev->name); } =20 - ret =3D vfio_device_get_name(vbasedev, errp); - if (ret) { - return ret; + if (!vfio_device_get_name(vbasedev, errp)) { + return -EINVAL; } =20 if (!vfio_attach_device(vbasedev->name, vbasedev, --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=BZfLbXLAhVFtmkhYemQgsSWAOUEm0iQ1AiaYIDoFdvDrd5srASF4yYVnORJc4GMok7oa32d9ZMXzvzAChP0ICqgEci1s1Yc6HEplX2BfJKpOe0YNR//fwpynDcUG6/cqCm+wxQT5kU7+goXHLlTVVvN9GSKdA7JDQ5lQYSjlGBY= 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=Ngui3EdeL/PoRl67peYHgHmXRZ/AvOL33ibesNHCX3g=; b=TwBVQ5xFOV9pE0n9fcuPN8tfi+bR0IWb7jZq3SZ9Tbs+qSEUucJnH6TsWloebXzh7yG3Sc5Gwk7FFapA0XukOQvsZRpr+t56GOBYmiiU7Dij3qkS78v+9xpvGP1P4NNXdNM5IP7EJLw4henGE4IxKFNicH1r58JDYYmmiAyeK5c= 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 1716371793126602.2091683235268; 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 1s9ihT-00058t-RU; Wed, 22 May 2024 05:55: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 1s9ihS-0004yE-3C for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:58 -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 1s9ihC-0001lV-Ld for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:57 -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-141-_ZVBIr-JOOGHi6gvf8DDqA-1; Wed, 22 May 2024 05:55:39 -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 99D5280028D; Wed, 22 May 2024 09:55:39 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78B2D28E3; Wed, 22 May 2024 09:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371742; 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=Ngui3EdeL/PoRl67peYHgHmXRZ/AvOL33ibesNHCX3g=; b=J6Z++6R4nK7/HbLohIfMTDj3my9Xzj/yUx8S45kLSEYXX1RB1rzVIQ0VRwTKr2qBvT3drD tqMaAcFpKS0FlCbyakcn5Gj8TWFRb+UkPLjrfNMGczkvB/cid7Do7CEikAqw+kY5IUcGKt fIRtNWgC9eJ8T7qiRGxgH/1IiIsfcO8= X-MC-Unique: _ZVBIr-JOOGHi6gvf8DDqA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 35/47] vfio/platform: Make vfio_populate_device() and vfio_base_device_init() return bool Date: Wed, 22 May 2024 11:54:30 +0200 Message-ID: <20240522095442.195243-36-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, 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: 1716371794840100008 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/platform.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index e1a32863d919fe09a743f5fb108f9787984d4378..a85c199c76aa25559acf931621b= 84dd3dac6184d 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -441,7 +441,7 @@ static int vfio_platform_hot_reset_multi(VFIODevice *vb= asedev) * @errp: error object * */ -static int vfio_populate_device(VFIODevice *vbasedev, Error **errp) +static bool vfio_populate_device(VFIODevice *vbasedev, Error **errp) { VFIOINTp *intp, *tmp; int i, ret =3D -1; @@ -450,7 +450,7 @@ static int vfio_populate_device(VFIODevice *vbasedev, E= rror **errp) =20 if (!(vbasedev->flags & VFIO_DEVICE_FLAGS_PLATFORM)) { error_setg(errp, "this isn't a platform device"); - return ret; + return false; } =20 vdev->regions =3D g_new0(VFIORegion *, vbasedev->num_regions); @@ -487,12 +487,11 @@ static int vfio_populate_device(VFIODevice *vbasedev,= Error **errp) irq.flags); intp =3D vfio_init_intp(vbasedev, irq, errp); if (!intp) { - ret =3D -1; goto irq_err; } } } - return 0; + return true; irq_err: timer_del(vdev->mmap_timer); QLIST_FOREACH_SAFE(intp, &vdev->intp_list, next, tmp) { @@ -507,7 +506,7 @@ reg_error: g_free(vdev->regions[i]); } g_free(vdev->regions); - return ret; + return false; } =20 /* specialized functions for VFIO Platform devices */ @@ -527,10 +526,8 @@ static VFIODeviceOps vfio_platform_ops =3D { * fd retrieval, resource query. * Precondition: the device name must be initialized */ -static int vfio_base_device_init(VFIODevice *vbasedev, Error **errp) +static bool vfio_base_device_init(VFIODevice *vbasedev, Error **errp) { - int ret; - /* @fd takes precedence over @sysfsdev which takes precedence over @ho= st */ if (vbasedev->fd < 0 && vbasedev->sysfsdev) { g_free(vbasedev->name); @@ -538,7 +535,7 @@ static int vfio_base_device_init(VFIODevice *vbasedev, = Error **errp) } else if (vbasedev->fd < 0) { if (!vbasedev->name || strchr(vbasedev->name, '/')) { error_setg(errp, "wrong host device name"); - return -EINVAL; + return false; } =20 vbasedev->sysfsdev =3D g_strdup_printf("/sys/bus/platform/devices/= %s", @@ -546,20 +543,20 @@ static int vfio_base_device_init(VFIODevice *vbasedev= , Error **errp) } =20 if (!vfio_device_get_name(vbasedev, errp)) { - return -EINVAL; + return false; } =20 if (!vfio_attach_device(vbasedev->name, vbasedev, &address_space_memory, errp)) { - return -EINVAL; + return false; } =20 - ret =3D vfio_populate_device(vbasedev, errp); - if (ret) { - vfio_detach_device(vbasedev); + if (vfio_populate_device(vbasedev, errp)) { + return true; } =20 - return ret; + vfio_detach_device(vbasedev); + return false; } =20 /** @@ -576,7 +573,7 @@ static void vfio_platform_realize(DeviceState *dev, Err= or **errp) VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(dev); SysBusDevice *sbdev =3D SYS_BUS_DEVICE(dev); VFIODevice *vbasedev =3D &vdev->vbasedev; - int i, ret; + int i; =20 qemu_mutex_init(&vdev->intp_mutex); =20 @@ -584,9 +581,8 @@ static void vfio_platform_realize(DeviceState *dev, Err= or **errp) vbasedev->sysfsdev : vbasedev->name, vdev->compat); =20 - ret =3D vfio_base_device_init(vbasedev, errp); - if (ret) { - goto out; + if (!vfio_base_device_init(vbasedev, errp)) { + goto init_err; } =20 if (!vdev->compat) { @@ -618,11 +614,9 @@ static void vfio_platform_realize(DeviceState *dev, Er= ror **errp) } sysbus_init_mmio(sbdev, vdev->regions[i]->mem); } -out: - if (!ret) { - return; - } + return; =20 +init_err: if (vdev->vbasedev.name) { error_prepend(errp, VFIO_MSG_PREFIX, vdev->vbasedev.name); } else { --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371840; cv=none; d=zohomail.com; s=zohoarc; b=In4y8JAY01Zoj5zhUANJSYP1kPusYkVaCR67P7/EsWHr6mEkaodWqX1Ha6D/iGismuw4YDb3c0iL+HNFI2rvYbULxn64gxujtpTRfqr4dQmP9XZjQtZZdGhS8gXWsx2tzP+m5ps1X5Nl8zU1BBdRipAFhCogSKrPGV5C30cxBB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371840; 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=vOI4wBHXF1so/a94L2k2ZhYao0kW/v+zFhWWTorCMZE=; b=A+z7F7mKnrcQoiRhg/E7wi7S+2ZxbkpVQbHg07Dz+X7jPPWLbBlApFs9O/tS4Z29cqqYEZT5y/PVeipk8c5ub5xQxVFq7Zsdym8AwwT/EWre2UWaktukeptc5uy788dklFlCd7zzcknfkMedXVmdA92F7PWPd58cpHgDN7YVz1U= 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 1716371840592701.8251598828667; Wed, 22 May 2024 02:57:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihJ-000437-GF; Wed, 22 May 2024 05:55:49 -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 1s9ihG-0003pz-R8 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55: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 1s9ihD-0001ll-L4 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:46 -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-694-Kcr5uj7nMKeYRYWO1sE8eQ-1; Wed, 22 May 2024 05:55:41 -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 F0D223C025D2; Wed, 22 May 2024 09:55:40 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE46228E2; Wed, 22 May 2024 09:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371743; 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=vOI4wBHXF1so/a94L2k2ZhYao0kW/v+zFhWWTorCMZE=; b=WYhr/OxLQJs/GDvUZ+vjvj2DYLIDPW1CC2rbiyUX/Rx5eLgveB+PZO+i409+0MZHhLPRG+ NXiZ4jBy6CR6A4CZOdnaH16epoHTo9LZj7AHEyg0hr4RoAG5Asoct70roGpyfnDyvUYpOm bBuRFofyrBm4O02SGYDkieocMla7Aas= X-MC-Unique: Kcr5uj7nMKeYRYWO1sE8eQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 36/47] vfio/ccw: Make vfio_ccw_get_region() return a bool Date: Wed, 22 May 2024 11:54:31 +0200 Message-ID: <20240522095442.195243-37-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371841049100002 From: Zhenzhong Duan Since vfio_populate_device() takes an 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/ccw.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c index 8850ca17c84632d278e27819cd52e104ed436d6c..2600e62e37238779800dc2b3a0b= d315d7633017b 100644 --- a/hw/vfio/ccw.c +++ b/hw/vfio/ccw.c @@ -474,7 +474,7 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDev= ice *vcdev, event_notifier_cleanup(notifier); } =20 -static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp) +static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp) { VFIODevice *vdev =3D &vcdev->vdev; struct vfio_region_info *info; @@ -483,7 +483,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, E= rror **errp) /* Sanity check device */ if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) { error_setg(errp, "vfio: Um, this isn't a vfio-ccw device"); - return; + return false; } =20 /* @@ -493,13 +493,13 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev,= Error **errp) if (vdev->num_regions < VFIO_CCW_CONFIG_REGION_INDEX + 1) { error_setg(errp, "vfio: too few regions (%u), expected at least %u= ", vdev->num_regions, VFIO_CCW_CONFIG_REGION_INDEX + 1); - return; + return false; } =20 ret =3D vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info= ); if (ret) { error_setg_errno(errp, -ret, "vfio: Error getting config info"); - return; + return false; } =20 vcdev->io_region_size =3D info->size; @@ -553,7 +553,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, E= rror **errp) g_free(info); } =20 - return; + return true; =20 out_err: g_free(vcdev->crw_region); @@ -561,7 +561,7 @@ out_err: g_free(vcdev->async_cmd_region); g_free(vcdev->io_region); g_free(info); - return; + return false; } =20 static void vfio_ccw_put_region(VFIOCCWDevice *vcdev) @@ -597,8 +597,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **= errp) goto out_attach_dev_err; } =20 - vfio_ccw_get_region(vcdev, &err); - if (err) { + if (!vfio_ccw_get_region(vcdev, &err)) { goto out_region_err; } =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371810; cv=none; d=zohomail.com; s=zohoarc; b=F4VIr/FpqsZyAxL22BYZestVj/gitNUQRkcXVI4LGrygF3FgwAzgFZtZitAQzfqkIxnt3tG3mNcSfNbPrF5PFK/sXe/o5IE+u7y0JHMKXiWtS38/HWynxLtTBC2pkJyK4beQuCDQV70b8FK4EzLJUGi9qv4Ldc5sXB19V6BGCSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371810; 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=Wmo6MS5izlXdTvxEwKEvXFrvfXH3rJrzKQLemJ1NuoU=; b=S1hXjZSTEmxuShu4sNcA6RVLTEr/6L/Gzu2rMcwWki1a9f2ntajPNEze50VABcyYQ/XwYSw0FJKbRBud4giSopaXkaUbj1WEHox6Iac6REdnZk1soVqdpf93m+1MHnO+px87KsmE/8oBd8VolHwCGQaj5BkPD7+tFwQ+Q/rngIc= 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 1716371810233709.2549293324287; Wed, 22 May 2024 02:56:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihJ-00043J-GZ; Wed, 22 May 2024 05:55:49 -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 1s9ihG-0003qG-So for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55: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 1s9ihE-0001lw-RS for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:46 -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-104-JKcF0W5BO4qku0ERx_uc-A-1; Wed, 22 May 2024 05:55:42 -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 5DE0F81227E; Wed, 22 May 2024 09:55:42 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CB3451BF; Wed, 22 May 2024 09:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371744; 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=Wmo6MS5izlXdTvxEwKEvXFrvfXH3rJrzKQLemJ1NuoU=; b=gtUHy2r5uyUHqD1YddyYgTh+uoIY7Sr79U8B+xk+EZWUqHG8+2P12B06sImqhWbjCR+q6i 4CrE8KY5rRiOoBxocWvoB9ewvvk98dj9IFJSAL1GODeNtk29tzE3Y/rKr9MtNXqvGLdMPb AKcbRMzwrQD+GDSPqsVc2+lmfo5ESgg= X-MC-Unique: JKcF0W5BO4qku0ERx_uc-A-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 37/47] vfio/pci: Make vfio_intx_enable_kvm() return a bool Date: Wed, 22 May 2024 11:54:32 +0200 Message-ID: <20240522095442.195243-38-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371810869100005 From: Zhenzhong Duan Since vfio_intx_enable_kvm() takes an 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index aad012c34885ff2a5a39039777dddd962236b41b..12fb534d796f52724f365746c9c= 8c2491265f03d 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -116,7 +116,7 @@ static void vfio_intx_eoi(VFIODevice *vbasedev) vfio_unmask_single_irqindex(vbasedev, VFIO_PCI_INTX_IRQ_INDEX); } =20 -static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) { #ifdef CONFIG_KVM int irq_fd =3D event_notifier_get_fd(&vdev->intx.interrupt); @@ -124,7 +124,7 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, E= rror **errp) if (vdev->no_kvm_intx || !kvm_irqfds_enabled() || vdev->intx.route.mode !=3D PCI_INTX_ENABLED || !kvm_resamplefds_enabled()) { - return; + return true; } =20 /* Get to a known interrupt state */ @@ -161,7 +161,7 @@ static void vfio_intx_enable_kvm(VFIOPCIDevice *vdev, E= rror **errp) =20 trace_vfio_intx_enable_kvm(vdev->vbasedev.name); =20 - return; + return true; =20 fail_vfio: kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.interrupt, @@ -171,6 +171,9 @@ fail_irqfd: fail: qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev); vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); + return false; +#else + return true; #endif } =20 @@ -226,8 +229,7 @@ static void vfio_intx_update(VFIOPCIDevice *vdev, PCIIN= TxRoute *route) return; } =20 - vfio_intx_enable_kvm(vdev, &err); - if (err) { + if (!vfio_intx_enable_kvm(vdev, &err)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } =20 @@ -302,8 +304,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) return -errno; } =20 - vfio_intx_enable_kvm(vdev, &err); - if (err) { + if (!vfio_intx_enable_kvm(vdev, &err)) { warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371923; cv=none; d=zohomail.com; s=zohoarc; b=D8GkG96sJU2CwU4Ihv0DDQUlKclbJFgedeqYRZ0K84Nce2E257vY8Obe5Fuqwj2pP6rMkDjxpc5kBCLdzN2fsuMzsEI1A98CnMQwNNg5kctS0LVZh1pxqC8zo45em4gNipSUH0kUMOTg2qpHMdu1KmlGLINinQkwKnWXlvn3AVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371923; 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=jiXazmRRX1pWr+z+tk9NOgQnGvpDX8eXjR2eT/8ADoM=; b=lwCV/M5szPleSkNqjcx8BRphsTXl/YlPkjDLkzJqMkl20wqgYiv4Hsr0LLayD8XYEva5gVdwGR5UBOUHVG49/JpVFrvA16iJ2X/OzcVsIBhdX8Qq2x4AyOykqKLrfgVAP6Lwcs5A4EVVEpPinzJ7OstpiqMTkqqnIa7OJvAr+7U= 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 1716371923574585.4833410842244; Wed, 22 May 2024 02:58:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihN-0004Vs-RM; Wed, 22 May 2024 05:55:54 -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 1s9ihI-000400-EQ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:48 -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 1s9ihG-0001m5-IV for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:48 -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-397-kLtksRauPqaz_tuYysGRVA-1; Wed, 22 May 2024 05:55:44 -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 B58AA29AA3B2; Wed, 22 May 2024 09:55:43 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 935DD2818; Wed, 22 May 2024 09:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371745; 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=jiXazmRRX1pWr+z+tk9NOgQnGvpDX8eXjR2eT/8ADoM=; b=RXaw5olRa0pfXgyykDQSQRLdSWKHid6p3lpOIbtRTY9Vo9BtkBdTCUwF8GzMAfJsYY9siI Qyr10twE/1O8rs0cBT79rZVOXhw2QmlwwOgLE0AbF6n2iJAJe7uLhEtmJEBr/TPDzHrVJa uRrZ6paLJSTae+fQOMAQBj/U/Bj34I4= X-MC-Unique: kLtksRauPqaz_tuYysGRVA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 38/47] vfio/pci: Make vfio_pci_relocate_msix() and vfio_msix_early_setup() return a bool Date: Wed, 22 May 2024 11:54:33 +0200 Message-ID: <20240522095442.195243-39-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: 1716371925443100001 From: Zhenzhong Duan Since vfio_pci_relocate_msix() and vfio_msix_early_setup() takes an 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section. By this chance, pass errp directly to vfio_msix_early_setup() to avoid calling error_propagate(). Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 12fb534d796f52724f365746c9c8c2491265f03d..4fb5fd0c9f61627c402164fc4be= d1868540350e0 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1450,13 +1450,13 @@ static void vfio_pci_fixup_msix_region(VFIOPCIDevic= e *vdev) } } =20 -static void vfio_pci_relocate_msix(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_pci_relocate_msix(VFIOPCIDevice *vdev, Error **errp) { int target_bar =3D -1; size_t msix_sz; =20 if (!vdev->msix || vdev->msix_relo =3D=3D OFF_AUTOPCIBAR_OFF) { - return; + return true; } =20 /* The actual minimum size of MSI-X structures */ @@ -1479,7 +1479,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vde= v, Error **errp) if (target_bar < 0) { error_setg(errp, "No automatic MSI-X relocation available for " "device %04x:%04x", vdev->vendor_id, vdev->device_i= d); - return; + return false; } } else { target_bar =3D (int)(vdev->msix_relo - OFF_AUTOPCIBAR_BAR0); @@ -1489,7 +1489,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vde= v, Error **errp) if (vdev->bars[target_bar].ioport) { error_setg(errp, "Invalid MSI-X relocation BAR %d, " "I/O port BAR", target_bar); - return; + return false; } =20 /* Cannot use a BAR in the "shadow" of a 64-bit BAR */ @@ -1497,7 +1497,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vde= v, Error **errp) target_bar > 0 && vdev->bars[target_bar - 1].mem64) { error_setg(errp, "Invalid MSI-X relocation BAR %d, " "consumed by 64-bit BAR %d", target_bar, target_bar - 1= ); - return; + return false; } =20 /* 2GB max size for 32-bit BARs, cannot double if already > 1G */ @@ -1505,7 +1505,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vde= v, Error **errp) !vdev->bars[target_bar].mem64) { error_setg(errp, "Invalid MSI-X relocation BAR %d, " "no space to extend 32-bit BAR", target_bar); - return; + return false; } =20 /* @@ -1540,6 +1540,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vde= v, Error **errp) =20 trace_vfio_msix_relo(vdev->vbasedev.name, vdev->msix->table_bar, vdev->msix->table_offset); + return true; } =20 /* @@ -1550,7 +1551,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vde= v, Error **errp) * need to first look for where the MSI-X table lives. So we * unfortunately split MSI-X setup across two functions. */ -static void vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp) { uint8_t pos; uint16_t ctrl; @@ -1562,25 +1563,25 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vd= ev, Error **errp) =20 pos =3D pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX); if (!pos) { - return; + return true; } =20 if (pread(fd, &ctrl, sizeof(ctrl), vdev->config_offset + pos + PCI_MSIX_FLAGS) !=3D sizeof(ctrl= )) { error_setg_errno(errp, errno, "failed to read PCI MSIX FLAGS"); - return; + return false; } =20 if (pread(fd, &table, sizeof(table), vdev->config_offset + pos + PCI_MSIX_TABLE) !=3D sizeof(tabl= e)) { error_setg_errno(errp, errno, "failed to read PCI MSIX TABLE"); - return; + return false; } =20 if (pread(fd, &pba, sizeof(pba), vdev->config_offset + pos + PCI_MSIX_PBA) !=3D sizeof(pba)) { error_setg_errno(errp, errno, "failed to read PCI MSIX PBA"); - return; + return false; } =20 ctrl =3D le16_to_cpu(ctrl); @@ -1598,7 +1599,7 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) if (ret < 0) { error_setg_errno(errp, -ret, "failed to get MSI-X irq info"); g_free(msix); - return; + return false; } =20 msix->noresize =3D !!(irq_info.flags & VFIO_IRQ_INFO_NORESIZE); @@ -1630,7 +1631,7 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) error_setg(errp, "hardware reports invalid configuration, " "MSIX PBA outside of specified BAR"); g_free(msix); - return; + return false; } } =20 @@ -1641,7 +1642,7 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) =20 vfio_pci_fixup_msix_region(vdev); =20 - vfio_pci_relocate_msix(vdev, errp); + return vfio_pci_relocate_msix(vdev, errp); } =20 static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) @@ -3130,9 +3131,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 vfio_bars_prepare(vdev); =20 - vfio_msix_early_setup(vdev, &err); - if (err) { - error_propagate(errp, err); + if (!vfio_msix_early_setup(vdev, errp)) { goto error; } =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371907; cv=none; d=zohomail.com; s=zohoarc; b=GeMGBNB3itn43VKlRQeFoEGyCzm9UvhPHVEVX1Bm763Tn/qRqsTYfA/I2Ge0CpsWQmCYailA4HE95fnLS56AL5VV5D8qPGI+HXVVIPxfDgk3/RdFYPV0kM3CDOQY1iCYgQ5D2IhZ3LR/KjeUUEyVuTWSdM4HGnMtPQj+MQjWW8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371907; 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=Wrt6okKOnmpVXT/eryr4wzTcDbGf2/zr75j5q/NxDYM=; b=Q1g1ZvUo9EMM5d7WhTHRvlgwNKb1sMTQo6GrJTQNh6VrjFiKCpbOPd2QXZGiDTnQuVGI68RdTCQYytIZraYXuW3IvBwybN6gE/ppV3RurIsus3YRbfHLEmOT2cPLbNcV+RfVw1ij6BnVjWCys12e+H6glesLCcZYCVj2kB2Sr40= 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 1716371907423199.72099384522005; Wed, 22 May 2024 02:58:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihP-0004kE-RY; Wed, 22 May 2024 05:55: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 1s9ihJ-000458-M6 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:49 -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 1s9ihH-0001mW-Qi for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:49 -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-387-PsrgeyJBPFan7zxVji58Xw-1; Wed, 22 May 2024 05:55:45 -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 1705C80118E; Wed, 22 May 2024 09:55:45 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id EABB451BF; Wed, 22 May 2024 09:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371747; 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=Wrt6okKOnmpVXT/eryr4wzTcDbGf2/zr75j5q/NxDYM=; b=B7QZHUX9dXKcB19BfukZ/G1GeSk9fTVriFJqVxp5wemQ5NuCte5LeMfdCOBZ1WyHCQZkVi yBY1QcwB0u4PDIH/8ILdqRv23wg7xU4td2uKS7zLM9KQ9cy85sgHKBylnoxYTtvbu8tgeJ L6edKthMN4fyA6/bv7vi7uTaRFWUh3w= X-MC-Unique: PsrgeyJBPFan7zxVji58Xw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 39/47] vfio/pci: Make vfio_populate_device() return a bool Date: Wed, 22 May 2024 11:54:34 +0200 Message-ID: <20240522095442.195243-40-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: 1716371909357100001 From: Zhenzhong Duan Since vfio_populate_device() takes an 'Error **' argument, best practices suggest to return a bool. See the qapi/error.h Rules section. By this chance, pass errp directly to vfio_populate_device() to avoid calling error_propagate(). Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4fb5fd0c9f61627c402164fc4bed1868540350e0..46d3c618596d95266543e9a0ebc= 65c04d9a7cc5d 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2740,7 +2740,7 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **er= rp) return 0; } =20 -static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev =3D &vdev->vbasedev; struct vfio_region_info *reg_info; @@ -2750,18 +2750,18 @@ static void vfio_populate_device(VFIOPCIDevice *vde= v, Error **errp) /* Sanity check device */ if (!(vbasedev->flags & VFIO_DEVICE_FLAGS_PCI)) { error_setg(errp, "this isn't a PCI device"); - return; + return false; } =20 if (vbasedev->num_regions < VFIO_PCI_CONFIG_REGION_INDEX + 1) { error_setg(errp, "unexpected number of io regions %u", vbasedev->num_regions); - return; + return false; } =20 if (vbasedev->num_irqs < VFIO_PCI_MSIX_IRQ_INDEX + 1) { error_setg(errp, "unexpected number of irqs %u", vbasedev->num_irq= s); - return; + return false; } =20 for (i =3D VFIO_PCI_BAR0_REGION_INDEX; i < VFIO_PCI_ROM_REGION_INDEX; = i++) { @@ -2773,7 +2773,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) =20 if (ret) { error_setg_errno(errp, -ret, "failed to get region %d info", i= ); - return; + return false; } =20 QLIST_INIT(&vdev->bars[i].quirks); @@ -2783,7 +2783,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) VFIO_PCI_CONFIG_REGION_INDEX, ®_info); if (ret) { error_setg_errno(errp, -ret, "failed to get config info"); - return; + return false; } =20 trace_vfio_populate_device_config(vdev->vbasedev.name, @@ -2804,7 +2804,7 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) if (ret) { error_append_hint(errp, "device does not support " "requested feature x-vga\n"); - return; + return false; } } =20 @@ -2821,6 +2821,8 @@ static void vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) "Could not enable error recovery for the device", vbasedev->name); } + + return true; } =20 static void vfio_pci_put_device(VFIOPCIDevice *vdev) @@ -2977,7 +2979,6 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) VFIOPCIDevice *vdev =3D VFIO_PCI(pdev); VFIODevice *vbasedev =3D &vdev->vbasedev; char *subsys; - Error *err =3D NULL; int i, ret; bool is_mdev; char uuid[UUID_STR_LEN]; @@ -3036,9 +3037,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) goto error; } =20 - vfio_populate_device(vdev, &err); - if (err) { - error_propagate(errp, err); + if (!vfio_populate_device(vdev, errp)) { goto error; } =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371831; cv=none; d=zohomail.com; s=zohoarc; b=Xn8jZI5UDXEEZJMujSy7M1L6t+BMg7Xy2qEpBeY+SV0WIGjh+BPQe+hz0nbjU0ZRqRHr+4wjUPC6wrOSD6dziPOj1FjjtDvQTp9u7XUvMVc8npAEaKlpo2npaPqBqhuZbAegKfG3/QVioTzySRS5uNohrh3KgFSpMbUJbW06bBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371831; 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=1nFoqPth8EfyKaLxOsrot/mOUmVot+IilUwyOPA6FkM=; b=UQcq7rimfLgh+Lisz66t0WAhpXZi41ktYH2p+QG1JIwpJe8RoiJc3ZJg+UJiHhRZr6NtSvf6WCKSiLzDYRLrIZ8/AaJ/DGv+Dv5IhUOhYtiarsF/lG0mijK6N3kUyquTo2IGlSYqxNDU4SXFue3xzyAd/vtDjzMz55mLsmvPY2Q= 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 1716371831697694.5759309016752; Wed, 22 May 2024 02:57:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihT-00057H-HC; Wed, 22 May 2024 05:55: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 1s9ihM-0004Oy-Pk for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:52 -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 1s9ihK-0001nz-VE for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:52 -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-199-LqsT3Ye7OHq0mCIS4C2VJw-1; Wed, 22 May 2024 05:55:46 -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 6CB86800994; Wed, 22 May 2024 09:55:46 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AE822818; Wed, 22 May 2024 09:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371750; 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=1nFoqPth8EfyKaLxOsrot/mOUmVot+IilUwyOPA6FkM=; b=DrZaUMXSw4eENe63at7rTP1L2xyHmK1bZcYKBTnnmmVxvQQOFc8Z8Q3iZLQHbcs1nxaDOC bzkkK7zJFEUxPbRhgdzMXOB3leh8n3cTXXfejVzKiaIKX1iqNghd+2y0aAZYmnEbdBwaTy Z+rw8x9eJMDUtnpN9NnNGl5L6eMRTQM= X-MC-Unique: LqsT3Ye7OHq0mCIS4C2VJw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 40/47] vfio/pci: Make vfio_intx_enable() return bool Date: Wed, 22 May 2024 11:54:35 +0200 Message-ID: <20240522095442.195243-41-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: 1716371832999100001 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 46d3c618596d95266543e9a0ebc65c04d9a7cc5d..7f35cb8a29176840412652afe5a= b31cd52a1bf06 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -261,7 +261,7 @@ static void vfio_irqchip_change(Notifier *notify, void = *data) vfio_intx_update(vdev, &vdev->intx.route); } =20 -static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) { uint8_t pin =3D vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1= ); Error *err =3D NULL; @@ -270,7 +270,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) =20 =20 if (!pin) { - return 0; + return true; } =20 vfio_disable_interrupts(vdev); @@ -292,7 +292,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) ret =3D event_notifier_init(&vdev->intx.interrupt, 0); if (ret) { error_setg_errno(errp, -ret, "event_notifier_init failed"); - return ret; + return false; } fd =3D event_notifier_get_fd(&vdev->intx.interrupt); qemu_set_fd_handler(fd, vfio_intx_interrupt, NULL, vdev); @@ -301,7 +301,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { qemu_set_fd_handler(fd, NULL, NULL, vdev); event_notifier_cleanup(&vdev->intx.interrupt); - return -errno; + return false; } =20 if (!vfio_intx_enable_kvm(vdev, &err)) { @@ -311,7 +311,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error = **errp) vdev->interrupt =3D VFIO_INT_INTx; =20 trace_vfio_intx_enable(vdev->vbasedev.name); - return 0; + return true; } =20 static void vfio_intx_disable(VFIOPCIDevice *vdev) @@ -836,8 +836,7 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev) vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX); =20 vfio_msi_disable_common(vdev); - vfio_intx_enable(vdev, &err); - if (err) { + if (!vfio_intx_enable(vdev, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } =20 @@ -2450,8 +2449,7 @@ void vfio_pci_post_reset(VFIOPCIDevice *vdev) Error *err =3D NULL; int nr; =20 - vfio_intx_enable(vdev, &err); - if (err) { + if (!vfio_intx_enable(vdev, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); } =20 @@ -3194,8 +3192,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) vfio_intx_routing_notifier); vdev->irqchip_change_notifier.notify =3D vfio_irqchip_change; kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier); - ret =3D vfio_intx_enable(vdev, errp); - if (ret) { + if (!vfio_intx_enable(vdev, errp)) { goto out_deregister; } } --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371792; cv=none; d=zohomail.com; s=zohoarc; b=Fb9G+WYvuHlC/LRdIjbSMPpjRlNUh3vbcRKHcqf9xj4ap2kOMuDP5jt1+SXJ80cmOe/WWTuwpUbjLYUzYsQqmgDWgO0KvJIFVf8wlshaeRdPfBX2oYm1YOmer7Xw/kgL35MJKZcPEGIip4j2NRN0cCsbUbhFPxklUYuLHFCJy54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371792; 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=q2GVlx4T78UrS5NSTaGqL+rb9an85n4nQ6EqCCzH1hk=; b=mHylZnPIbG71yKSxHqevL4P2E7N4MpI1ZDETna9AW7DbrkyLi0KEoQXcQUjGokFsHCaGr4FKVHyvTLukJL/ewnuEHA4x5NynVhDoQRkcQXhAeSnjqwSRa/LmTXUme2UKOg38LVzuDa8/C5DSWVQVXIMQ9zV8OopugsQr4k6GwTI= 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 1716371792161849.8166345144127; Wed, 22 May 2024 02:56:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihQ-0004rJ-R1; Wed, 22 May 2024 05:55:56 -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 1s9ihM-0004OD-NU for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:52 -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 1s9ihK-0001nu-PR for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:52 -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-35-7GoPZ7bANgaC_vW9ap0ePg-1; Wed, 22 May 2024 05:55:48 -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 C31018029EB; Wed, 22 May 2024 09:55:47 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id A19BB28E3; Wed, 22 May 2024 09:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371750; 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=q2GVlx4T78UrS5NSTaGqL+rb9an85n4nQ6EqCCzH1hk=; b=QOOj2prgNKO1DkJBLy1M+QLxK3tTxDKMr5Z36Q0vA2XtJ7JMgNdQrjcpfDEBbP++sbWGAS LIs6ebUhAm4ebA1z/UbVkwUBk9wVW50BluSA43BCvRq2DkWRMTy8Grj1u7oGd15xM7aCvH sP47RT3TWTLctWdFQqr8OZK+SfcG7zs= X-MC-Unique: 7GoPZ7bANgaC_vW9ap0ePg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 41/47] vfio/pci: Make vfio_populate_vga() return bool Date: Wed, 22 May 2024 11:54:36 +0200 Message-ID: <20240522095442.195243-42-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: 1716371792849100001 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 2 +- hw/vfio/igd.c | 2 +- hw/vfio/pci.c | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index a5ac9efd4bb6d4070cac02f3eeb156d1018cd20f..7914f019d5ed563ae7b60be1703= 3aedacaaa00ff 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -225,7 +225,7 @@ bool vfio_pci_host_match(PCIHostDeviceAddress *addr, co= nst char *name); int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, struct vfio_pci_hot_reset_info **info_= p); =20 -int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); +bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); =20 int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, struct vfio_region_info *info, diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index b31ee79c60b5e567f84f561cfb63849960648340..ffe57c5954e5d05a57a66b2a3f0= cc44fef508126 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -478,7 +478,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) * try to enable it. Probably shouldn't be using legacy mode without = VGA, * but also no point in us enabling VGA if disabled in hardware. */ - if (!(gmch & 0x2) && !vdev->vga && vfio_populate_vga(vdev, &err)) { + if (!(gmch & 0x2) && !vdev->vga && !vfio_populate_vga(vdev, &err)) { error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); error_report("IGD device %s failed to enable VGA access, " "legacy mode disabled", vdev->vbasedev.name); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 7f35cb8a29176840412652afe5ab31cd52a1bf06..ab8f74299eab85e224a02f45d4b= 506e860b514f9 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2670,7 +2670,7 @@ static VFIODeviceOps vfio_pci_ops =3D { .vfio_load_config =3D vfio_pci_load_config, }; =20 -int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) +bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev =3D &vdev->vbasedev; struct vfio_region_info *reg_info; @@ -2681,7 +2681,7 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **er= rp) error_setg_errno(errp, -ret, "failed getting region info for VGA region index = %d", VFIO_PCI_VGA_REGION_INDEX); - return ret; + return false; } =20 if (!(reg_info->flags & VFIO_REGION_INFO_FLAG_READ) || @@ -2691,7 +2691,7 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **er= rp) (unsigned long)reg_info->flags, (unsigned long)reg_info->size); g_free(reg_info); - return -EINVAL; + return false; } =20 vdev->vga =3D g_new0(VFIOVGA, 1); @@ -2735,7 +2735,7 @@ int vfio_populate_vga(VFIOPCIDevice *vdev, Error **er= rp) &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem, &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem); =20 - return 0; + return true; } =20 static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) @@ -2798,8 +2798,7 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) g_free(reg_info); =20 if (vdev->features & VFIO_FEATURE_ENABLE_VGA) { - ret =3D vfio_populate_vga(vdev, errp); - if (ret) { + if (!vfio_populate_vga(vdev, errp)) { error_append_hint(errp, "device does not support " "requested feature x-vga\n"); return false; --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371807; cv=none; d=zohomail.com; s=zohoarc; b=RJXaNv5sgrJtBxoqvISLO8oE+XpcYmJJjfjXkGv6Ys1w9rEwPQwcah+ubU0hgNm35eHsEiBHQbl8eshRtWRw5UnTT1IFVASoh83oXQtnUMiEeSmzh+tNiduQJDJ9oDMDyTYiUxCtcWPUMsV0g93/TcN88mD8Hjml64JvF/AlpVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371807; 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=NNLlcHvWav9P68aqT0gvS8T3g+3N5HiMfA2h8sJ5x7g=; b=T6VxgAZvTvihgbJg541Tp5Z+epmkWjLnlcl0zfZzZvdcKZo2J+LKK6qgpbsopryedKR7GKCQDbVsPV21YEjSFVpyH9SbktgDo/2icOTYEVHEAL6Qxy6ozTcOmoD2Ve9rEmGrtNIPFYO7Y14dkWtIzI8u9O5jW6RQuYkGGqWEzJU= 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 1716371807749882.908492156498; Wed, 22 May 2024 02:56:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihS-0004yp-9j; Wed, 22 May 2024 05:55:58 -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 1s9ihP-0004ez-5b for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:55 -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 1s9ihL-0001ou-TU for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:54 -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-235-yBhmIAcPPXSRCgc3A17tRQ-1; Wed, 22 May 2024 05:55:49 -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 25C6B8008A4; Wed, 22 May 2024 09:55:49 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 047CA2818; Wed, 22 May 2024 09:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371751; 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=NNLlcHvWav9P68aqT0gvS8T3g+3N5HiMfA2h8sJ5x7g=; b=Vcw7ZD7wowelFSIx/hymDv5LqlHgOhT6yzIWmImVbcQfJHoyt67q6mTkX/aCEpfjTHpoB7 MO3uR3zOloamP3HYekorZXYf3H8y/KgWUPyTKugOvjMMEuQgaTJ0GX/OExjGzQjz8qZokT KHJkobvrNs9CsxDLRJQ+ebOk6dC5xNk= X-MC-Unique: yBhmIAcPPXSRCgc3A17tRQ-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 42/47] vfio/pci: Make capability related functions return bool Date: Wed, 22 May 2024 11:54:37 +0200 Message-ID: <20240522095442.195243-43-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: 1716371808918100001 From: Zhenzhong Duan The functions operating on capability don't have a consistent return style. Below functions are in bool-valued functions style: vfio_msi_setup() vfio_msix_setup() vfio_add_std_cap() vfio_add_capabilities() Below two are integer-valued functions: vfio_add_vendor_specific_cap() vfio_setup_pcie_cap() But the returned integer is only used for check succeed/failure. Change them all to return bool so now all capability related functions follow the coding standand in qapi/error.h to return bool. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 77 ++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index ab8f74299eab85e224a02f45d4b506e860b514f9..c3323912dd773e80ad2dbbefc5d= 833e8a33cd147 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1339,7 +1339,7 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vd= ev) } } =20 -static int vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp) +static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp) { uint16_t ctrl; bool msi_64bit, msi_maskbit; @@ -1349,7 +1349,7 @@ static int vfio_msi_setup(VFIOPCIDevice *vdev, int po= s, Error **errp) if (pread(vdev->vbasedev.fd, &ctrl, sizeof(ctrl), vdev->config_offset + pos + PCI_CAP_FLAGS) !=3D sizeof(ctrl)= ) { error_setg_errno(errp, errno, "failed reading MSI PCI_CAP_FLAGS"); - return -errno; + return false; } ctrl =3D le16_to_cpu(ctrl); =20 @@ -1362,14 +1362,14 @@ static int vfio_msi_setup(VFIOPCIDevice *vdev, int = pos, Error **errp) ret =3D msi_init(&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, &e= rr); if (ret < 0) { if (ret =3D=3D -ENOTSUP) { - return 0; + return true; } error_propagate_prepend(errp, err, "msi_init failed: "); - return ret; + return false; } vdev->msi_cap_size =3D 0xa + (msi_maskbit ? 0xa : 0) + (msi_64bit ? 0x= 4 : 0); =20 - return 0; + return true; } =20 static void vfio_pci_fixup_msix_region(VFIOPCIDevice *vdev) @@ -1644,7 +1644,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) return vfio_pci_relocate_msix(vdev, errp); } =20 -static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) +static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) { int ret; Error *err =3D NULL; @@ -1660,11 +1660,11 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int= pos, Error **errp) if (ret < 0) { if (ret =3D=3D -ENOTSUP) { warn_report_err(err); - return 0; + return true; } =20 error_propagate(errp, err); - return ret; + return false; } =20 /* @@ -1698,7 +1698,7 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int p= os, Error **errp) memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false); } =20 - return 0; + return true; } =20 static void vfio_teardown_msi(VFIOPCIDevice *vdev) @@ -1977,8 +1977,8 @@ static void vfio_pci_disable_rp_atomics(VFIOPCIDevice= *vdev) } } =20 -static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size, - Error **errp) +static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size, + Error **errp) { uint16_t flags; uint8_t type; @@ -1992,7 +1992,7 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, i= nt pos, uint8_t size, =20 error_setg(errp, "assignment of PCIe type 0x%x " "devices is not currently supported", type); - return -EINVAL; + return false; } =20 if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) { @@ -2025,7 +2025,7 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, i= nt pos, uint8_t size, } =20 if (pci_bus_is_express(bus)) { - return 0; + return true; } =20 } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) { @@ -2063,7 +2063,7 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, i= nt pos, uint8_t size, * Legacy endpoints don't belong on the root complex. Windows * seems to be happier with devices if we skip the capability. */ - return 0; + return true; } =20 } else { @@ -2099,12 +2099,12 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev,= int pos, uint8_t size, pos =3D pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size, errp); if (pos < 0) { - return pos; + return false; } =20 vdev->pdev.exp.exp_cap =3D pos; =20 - return pos; + return true; } =20 static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos) @@ -2137,14 +2137,14 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, = uint8_t pos) } } =20 -static int vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos, - uint8_t size, Error **errp) +static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos, + uint8_t size, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; =20 pos =3D pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp); if (pos < 0) { - return pos; + return false; } =20 /* @@ -2156,15 +2156,15 @@ static int vfio_add_vendor_specific_cap(VFIOPCIDevi= ce *vdev, int pos, memset(pdev->cmask + pos + 3, 0, size - 3); } =20 - return pos; + return true; } =20 -static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp) +static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **err= p) { ERRP_GUARD(); PCIDevice *pdev =3D &vdev->pdev; uint8_t cap_id, next, size; - int ret; + bool ret; =20 cap_id =3D pdev->config[pos]; next =3D pdev->config[pos + PCI_CAP_LIST_NEXT]; @@ -2185,9 +2185,8 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint= 8_t pos, Error **errp) * will be changed as we unwind the stack. */ if (next) { - ret =3D vfio_add_std_cap(vdev, next, errp); - if (ret) { - return ret; + if (!vfio_add_std_cap(vdev, next, errp)) { + return false; } } else { /* Begin the rebuild, use QEMU emulated list bits */ @@ -2197,7 +2196,7 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint= 8_t pos, Error **errp) =20 ret =3D vfio_add_virt_caps(vdev, errp); if (ret) { - return ret; + return false; } } =20 @@ -2221,28 +2220,27 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, ui= nt8_t pos, Error **errp) case PCI_CAP_ID_PM: vfio_check_pm_reset(vdev, pos); vdev->pm_cap =3D pos; - ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); + ret =3D pci_add_capability(pdev, cap_id, pos, size, errp) >=3D 0; break; case PCI_CAP_ID_AF: vfio_check_af_flr(vdev, pos); - ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); + ret =3D pci_add_capability(pdev, cap_id, pos, size, errp) >=3D 0; break; case PCI_CAP_ID_VNDR: ret =3D vfio_add_vendor_specific_cap(vdev, pos, size, errp); break; default: - ret =3D pci_add_capability(pdev, cap_id, pos, size, errp); + ret =3D pci_add_capability(pdev, cap_id, pos, size, errp) >=3D 0; break; } =20 - if (ret < 0) { + if (!ret) { error_prepend(errp, "failed to add PCI capability 0x%x[0x%x]@0x%x: ", cap_id, size, pos); - return ret; } =20 - return 0; + return ret; } =20 static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos) @@ -2388,23 +2386,21 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) return; } =20 -static int vfio_add_capabilities(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_add_capabilities(VFIOPCIDevice *vdev, Error **errp) { PCIDevice *pdev =3D &vdev->pdev; - int ret; =20 if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) || !pdev->config[PCI_CAPABILITY_LIST]) { - return 0; /* Nothing to add */ + return true; /* Nothing to add */ } =20 - ret =3D vfio_add_std_cap(vdev, pdev->config[PCI_CAPABILITY_LIST], errp= ); - if (ret) { - return ret; + if (!vfio_add_std_cap(vdev, pdev->config[PCI_CAPABILITY_LIST], errp)) { + return false; } =20 vfio_add_ext_cap(vdev); - return 0; + return true; } =20 void vfio_pci_pre_reset(VFIOPCIDevice *vdev) @@ -3133,8 +3129,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 vfio_bars_register(vdev); =20 - ret =3D vfio_add_capabilities(vdev, errp); - if (ret) { + if (!vfio_add_capabilities(vdev, errp)) { goto out_teardown; } =20 --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371870; cv=none; d=zohomail.com; s=zohoarc; b=OR2dlX7F97LRmIJZX+OMX6Zniwnn8/9sGeon0MUGJOh8LjqlG3bWam7pNhvZi/DHmrFQp0KlL6xYl/kN3NOuxVOF2ZEq6sU6PcylLmwH0JJd97ul7kL9jI29sUMtAjvwA2hmeE13ycn9lT8qijWfZBDFXDJ7nTa9CNrKmk0bsNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371870; 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=AQLP11xvZN6uvXb51wiiCAK/2iWO1h1NlMZ+wOG0u/E=; b=guPx4auV3f3I2S+TPkPpjCfnMK2i2FkpEvCeHjcqa5XTqhfY9lbTjYd6bYAgpe9koK2zqqInzLOOJwSqV3/KNP0/rG13ZF0CK/jPBAT1zekjLe8uamGNoFNxZrsnsGpTvkFNqJA+O5IxOw0Mg3UzehOqIe4JCTMK+0casyKKrMs= 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 1716371870625257.7414786431136; Wed, 22 May 2024 02:57:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihX-0005XU-1Q; Wed, 22 May 2024 05:56:03 -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 1s9ihP-0004ii-KS for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:55 -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 1s9ihO-0001qR-2I for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:55 -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-231-s5jUAUP2NKK-PRr8cyr-cA-1; Wed, 22 May 2024 05:55:50 -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 8404F8058D5; Wed, 22 May 2024 09:55:50 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B13B51BF; Wed, 22 May 2024 09:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371752; 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=AQLP11xvZN6uvXb51wiiCAK/2iWO1h1NlMZ+wOG0u/E=; b=jVaRN2n+y18QFZLBACzht9v8qYhYARgqZqigqsFFNIH+iqwVb3G50TLWub3EV9ndfCPYyD xx4ZhRJ1fnwrokF22UeimBSbR0xYIixYyqieWTTB2GUpBsKO09Lk6QItXb+jnSl5UMs3Hs s9uwJBQHmsOiYzn5eeCdG47D+tUYndo= X-MC-Unique: s5jUAUP2NKK-PRr8cyr-cA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 43/47] vfio/pci: Use g_autofree for vfio_region_info pointer Date: Wed, 22 May 2024 11:54:38 +0200 Message-ID: <20240522095442.195243-44-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: 1716371871163100001 From: Zhenzhong Duan Pointer opregion is freed after vfio_pci_igd_opregion_init(). Use 'g_autofree' to avoid the g_free() calls. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index c3323912dd773e80ad2dbbefc5d833e8a33cd147..8379d2284a20bed0c0bd24e46bb= b39e321dc9767 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3143,7 +3143,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) =20 if (!vdev->igd_opregion && vdev->features & VFIO_FEATURE_ENABLE_IGD_OPREGION) { - struct vfio_region_info *opregion; + g_autofree struct vfio_region_info *opregion =3D NULL; =20 if (vdev->pdev.qdev.hotplugged) { error_setg(errp, @@ -3162,7 +3162,6 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) } =20 ret =3D vfio_pci_igd_opregion_init(vdev, opregion, errp); - g_free(opregion); if (ret) { goto out_teardown; } --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371845; cv=none; d=zohomail.com; s=zohoarc; b=FlKFio/PW13JeE9C0nt3TbNq/bnDwDF7RZsT4ZiZgkrh3b66cy5jL2sg2s2/GiDmHgdSmYoi8vIVkIM5D8S2YHimYF8A/oYZc1/wcWigbBOy0X3UwSbaIipijxhthV6q0sasKMwniVaB9nN42rlEFHMJVwbjd8QxRY3IL7tXOdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371845; 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=N3A+EghA+9cMUObGB+bwhp8bYWIKjsA69gpm6h6H9oo=; b=gHgkDd18ulN2rKg3F4ts271Lkg1vbfEG5IJ8lABnmqUx1SkFfW8u1ou0VWPYeray/+lhzxJoWGsHzQvBIZyq20d4n7/pFsyqPPu5PTyQ+l1GLGq2slSQvSMsIrF38UYq5VQWMdxEPKe+DiwlYhaPpEKqeCGiSeMsEKbsTeR5ZP8= 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 1716371845231889.9040127597336; Wed, 22 May 2024 02:57:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihX-0005aU-Hk; Wed, 22 May 2024 05:56:03 -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 1s9ihR-0004xl-Vj for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:58 -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 1s9ihQ-0001tl-BB for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:57 -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-354-eocvhGdLPLCt9UWwp_iT5Q-1; Wed, 22 May 2024 05:55:52 -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 DCFAC81227E; Wed, 22 May 2024 09:55:51 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id B95417412; Wed, 22 May 2024 09:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371755; 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=N3A+EghA+9cMUObGB+bwhp8bYWIKjsA69gpm6h6H9oo=; b=WtpaiktO3gHyK+vzTSeMhWlWMcFIsJmTIJpD5/TwTdTUlqRzVJ/bW8MH93Ox2IuOO9dOYC Gc9YIikWQVBFtwgpiee4PiIkanfIutig8/EfDAVYgf2m47tEp6Lw8MyBbRm2+ue5y6q2aH SY7OlOBUqNLrzJ93XIMTBwWhtCvIRag= X-MC-Unique: eocvhGdLPLCt9UWwp_iT5Q-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 44/47] vfio/pci-quirks: Make vfio_pci_igd_opregion_init() return bool Date: Wed, 22 May 2024 11:54:39 +0200 Message-ID: <20240522095442.195243-45-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716371847073100003 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 6 +++--- hw/vfio/igd.c | 3 +-- hw/vfio/pci-quirks.c | 8 ++++---- hw/vfio/pci.c | 3 +-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 7914f019d5ed563ae7b60be17033aedacaaa00ff..f1586810726584ecfc35ef68564= 6faacabefbec0 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -227,9 +227,9 @@ int vfio_pci_get_pci_hot_reset_info(VFIOPCIDevice *vdev, =20 bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp); =20 -int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, - struct vfio_region_info *info, - Error **errp); +bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, + struct vfio_region_info *info, + Error **errp); =20 void vfio_display_reset(VFIOPCIDevice *vdev); bool vfio_display_probe(VFIOPCIDevice *vdev, Error **errp); diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index ffe57c5954e5d05a57a66b2a3f0cc44fef508126..402fc5ce1da966fda1340f328e0= 611cb1a2a0635 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -502,8 +502,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) } =20 /* Setup OpRegion access */ - ret =3D vfio_pci_igd_opregion_init(vdev, opregion, &err); - if (ret) { + if (!vfio_pci_igd_opregion_init(vdev, opregion, &err)) { error_append_hint(&err, "IGD legacy mode disabled\n"); error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); goto out; diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 496fd1ee86bd2d53bf094860e330f4f0a5081365..ca27917159785f760f688c8db0a= 9ac492080d74b 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1169,8 +1169,8 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevi= ce *vdev, int nr) * the table and to write the base address of that memory to the ASLS regi= ster * of the IGD device. */ -int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, - struct vfio_region_info *info, Error **errp) +bool vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, + struct vfio_region_info *info, Error **err= p) { int ret; =20 @@ -1181,7 +1181,7 @@ int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, error_setg(errp, "failed to read IGD OpRegion"); g_free(vdev->igd_opregion); vdev->igd_opregion =3D NULL; - return -EINVAL; + return false; } =20 /* @@ -1206,7 +1206,7 @@ int vfio_pci_igd_opregion_init(VFIOPCIDevice *vdev, pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0); pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0); =20 - return 0; + return true; } =20 /* diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 8379d2284a20bed0c0bd24e46bbb39e321dc9767..76a3931dba1da1a638ae574825f= e9dfe1390b21f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -3161,8 +3161,7 @@ static void vfio_realize(PCIDevice *pdev, Error **err= p) goto out_teardown; } =20 - ret =3D vfio_pci_igd_opregion_init(vdev, opregion, errp); - if (ret) { + if (!vfio_pci_igd_opregion_init(vdev, opregion, errp)) { goto out_teardown; } } --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371840; cv=none; d=zohomail.com; s=zohoarc; b=BKGSjmh3oRSn4MXYBF1fxSHe31D3L0Q2E52ufWsRy3rZMHBBPHTUgIGTmwGYp2icPrOVg2UjH/pY4q0JwjP89kpiU5zinWKz7TZpt8euHV71vvgC8PUygHky2CTyEsSESd2AlaVh8eMzfzaNB18zlRlJBOE5SFW0H4/ZzLiadkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371840; 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=yanOxKaS7eId/4S/INjcbQanK+cHyaJV4bzSFLnJpok=; b=ibL+TjVDaMNFAqFrNjxOh1bbR/HdCeEC7sxk/avoSPyPw357cHLRNFo9xHoONI+5smKcadlFREY0liresxqqBYWNtX14kbspp9cgeIVyvWnfbTZDJAmkvxvUxU6ADWAu+P6wMo954c2F3V1yNKAhtiqEaegh9SM/g18ehg4emWg= 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 1716371840107871.9205299865918; Wed, 22 May 2024 02:57:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihU-0005Eg-VN; Wed, 22 May 2024 05:56:01 -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 1s9ihS-000524-Ps for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:58 -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 1s9ihQ-0001uG-Sm for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55:58 -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-395-tXeuvYV7Mh21350McE-9EA-1; Wed, 22 May 2024 05:55:53 -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 3FC02800CA2; Wed, 22 May 2024 09:55:53 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E83D28E2; Wed, 22 May 2024 09:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371756; 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=yanOxKaS7eId/4S/INjcbQanK+cHyaJV4bzSFLnJpok=; b=GoYUXaKgplB3yVXGYHr/Mo+GiFCe9PbHIWyA1Ue749nkSO6Tv+UR5MtVxBKX0JRCIPretF SyJW4yM0f+9dMUgi8xx4twpw2X0hd3zTyW+63HzZIL2jqwJilOv0J6EI1HRzCFglhfLA2s DTdKRv/sxp2Ffve1i7XwwvxkxjGQq9g= X-MC-Unique: tXeuvYV7Mh21350McE-9EA-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 45/47] vfio/pci-quirks: Make vfio_add_*_cap() return bool Date: Wed, 22 May 2024 11:54:40 +0200 Message-ID: <20240522095442.195243-46-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: 1716371841046100001 From: Zhenzhong Duan This is to follow the coding standand in qapi/error.h to return bool for bool-valued functions. Include below functions: vfio_add_virt_caps() vfio_add_nv_gpudirect_cap() vfio_add_vmd_shadow_cap() Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.h | 2 +- hw/vfio/pci-quirks.c | 42 +++++++++++++++++++----------------------- hw/vfio/pci.c | 3 +-- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index f1586810726584ecfc35ef685646faacabefbec0..bf67df2fbc09b3d0fd97d25dfaa= 5290ab33b03ea 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -212,7 +212,7 @@ void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr); void vfio_bar_quirk_exit(VFIOPCIDevice *vdev, int nr); void vfio_bar_quirk_finalize(VFIOPCIDevice *vdev, int nr); void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev); -int vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp); +bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp); void vfio_quirk_reset(VFIOPCIDevice *vdev); VFIOQuirk *vfio_quirk_alloc(int nr_mem); void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr); diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index ca27917159785f760f688c8db0a9ac492080d74b..39dae72497e0315eeb580dbcd52= 55c58bc38c8ed 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -1536,7 +1536,7 @@ static bool is_valid_std_cap_offset(uint8_t pos) pos <=3D (PCI_CFG_SPACE_SIZE - PCI_CAP_SIZEOF)); } =20 -static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp) { ERRP_GUARD(); PCIDevice *pdev =3D &vdev->pdev; @@ -1545,18 +1545,18 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice = *vdev, Error **errp) uint8_t tmp; =20 if (vdev->nv_gpudirect_clique =3D=3D 0xFF) { - return 0; + return true; } =20 if (!vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID)) { error_setg(errp, "NVIDIA GPUDirect Clique ID: invalid device vendo= r"); - return -EINVAL; + return false; } =20 if (pci_get_byte(pdev->config + PCI_CLASS_DEVICE + 1) !=3D PCI_BASE_CLASS_DISPLAY) { error_setg(errp, "NVIDIA GPUDirect Clique ID: unsupported PCI clas= s"); - return -EINVAL; + return false; } =20 /* @@ -1572,7 +1572,7 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *v= dev, Error **errp) vdev->config_offset + PCI_CAPABILITY_LIST); if (ret !=3D 1 || !is_valid_std_cap_offset(tmp)) { error_setg(errp, "NVIDIA GPUDirect Clique ID: error getting cap li= st"); - return -EINVAL; + return false; } =20 do { @@ -1590,13 +1590,13 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice = *vdev, Error **errp) pos =3D 0xD4; } else { error_setg(errp, "NVIDIA GPUDirect Clique ID: invalid config space= "); - return -EINVAL; + return false; } =20 ret =3D pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, 8, errp); if (ret < 0) { error_prepend(errp, "Failed to add NVIDIA GPUDirect cap: "); - return ret; + return false; } =20 memset(vdev->emulated_config_bits + pos, 0xFF, 8); @@ -1608,7 +1608,7 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *v= dev, Error **errp) pci_set_byte(pdev->config + pos++, vdev->nv_gpudirect_clique << 3); pci_set_byte(pdev->config + pos, 0); =20 - return 0; + return true; } =20 /* @@ -1629,7 +1629,7 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *v= dev, Error **errp) */ #define VMD_SHADOW_CAP_VER 1 #define VMD_SHADOW_CAP_LEN 24 -static int vfio_add_vmd_shadow_cap(VFIOPCIDevice *vdev, Error **errp) +static bool vfio_add_vmd_shadow_cap(VFIOPCIDevice *vdev, Error **errp) { ERRP_GUARD(); uint8_t membar_phys[16]; @@ -1639,7 +1639,7 @@ static int vfio_add_vmd_shadow_cap(VFIOPCIDevice *vde= v, Error **errp) vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, 0x467F) || vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, 0x4C3D) || vfio_pci_is(vdev, PCI_VENDOR_ID_INTEL, 0x9A0B))) { - return 0; + return true; } =20 ret =3D pread(vdev->vbasedev.fd, membar_phys, 16, @@ -1647,14 +1647,14 @@ static int vfio_add_vmd_shadow_cap(VFIOPCIDevice *v= dev, Error **errp) if (ret !=3D 16) { error_report("VMD %s cannot read MEMBARs (%d)", vdev->vbasedev.name, ret); - return -EFAULT; + return false; } =20 ret =3D pci_add_capability(&vdev->pdev, PCI_CAP_ID_VNDR, pos, VMD_SHADOW_CAP_LEN, errp); if (ret < 0) { error_prepend(errp, "Failed to add VMD MEMBAR Shadow cap: "); - return ret; + return false; } =20 memset(vdev->emulated_config_bits + pos, 0xFF, VMD_SHADOW_CAP_LEN); @@ -1664,22 +1664,18 @@ static int vfio_add_vmd_shadow_cap(VFIOPCIDevice *v= dev, Error **errp) pci_set_long(vdev->pdev.config + pos, 0x53484457); /* SHDW */ memcpy(vdev->pdev.config + pos + 4, membar_phys, 16); =20 - return 0; + return true; } =20 -int vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp) +bool vfio_add_virt_caps(VFIOPCIDevice *vdev, Error **errp) { - int ret; - - ret =3D vfio_add_nv_gpudirect_cap(vdev, errp); - if (ret) { - return ret; + if (!vfio_add_nv_gpudirect_cap(vdev, errp)) { + return false; } =20 - ret =3D vfio_add_vmd_shadow_cap(vdev, errp); - if (ret) { - return ret; + if (!vfio_add_vmd_shadow_cap(vdev, errp)) { + return false; } =20 - return 0; + return true; } diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 76a3931dba1da1a638ae574825fe9dfe1390b21f..35ad9b582f6b99510a812edab5c= 2855c697a1da2 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2194,8 +2194,7 @@ static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uin= t8_t pos, Error **errp) vdev->emulated_config_bits[PCI_CAPABILITY_LIST] =3D 0xff; vdev->emulated_config_bits[PCI_STATUS] |=3D PCI_STATUS_CAP_LIST; =20 - ret =3D vfio_add_virt_caps(vdev, errp); - if (ret) { + if (!vfio_add_virt_caps(vdev, errp)) { return false; } } --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716372087; cv=none; d=zohomail.com; s=zohoarc; b=NwypRwt9oa03xN4e0J7P2/RFYG/I92+uTeIm/hmUGl7GEFi9SYpReCqmVeqfRpPX4p8IoRYys/e+3H+A9AbtB6t+b397NXTez33j1tc7YpgeGsg55gE778J+kZkLIfv8OIgRIE1AIGvfCYTVm1CYiuT7OANd3udKMUYrLPWZwHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716372087; 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=bI8EFdfj0J9kzuJuVZ6pxe0myBd7KeFUuEsMYCohD7w=; b=cA+RtYZ666r8e6S32J0bcNdmbLT5my/3Nc32m6usyZF0dNyURyQ97kxmRbUctM7ua4omlVx+8AVzsKdWadNMhyt8ajRtkM1m72Xwy/RsMCTd1IGTu7mDQbU81ESVP5K9v3Rf+9Yco7nqo3tq99cWHIzRQ5RnTtEGHIcjkXbbz0o= 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 1716372087326617.9879120101679; Wed, 22 May 2024 03:01:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihZ-0005dz-7E; Wed, 22 May 2024 05:56:05 -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 1s9ihV-0005LN-I9 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:56:01 -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 1s9ihT-0001wn-NJ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:56:01 -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-222-In4WNdwxMkmTp_leCLrxiw-1; Wed, 22 May 2024 05:55:54 -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 94FA5101A52C; Wed, 22 May 2024 09:55:54 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7420551BF; Wed, 22 May 2024 09:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371759; 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=bI8EFdfj0J9kzuJuVZ6pxe0myBd7KeFUuEsMYCohD7w=; b=RgnPb2+owFArqCQLuar6fQg+E+nr7m+AW7x2z5xX/iBF0RnY2HPNsSc6b1MUomK1QQHgqb FpQJKW52I9L0Aerk8Kfz+a2pR2uw97b5ZHrRYKbSel5hbt83EBV7vOVjNoyuS/0QsanjWp bOdxZfDFM0rHkbZXshME9ZQD0IG3nsY= X-MC-Unique: In4WNdwxMkmTp_leCLrxiw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 46/47] vfio: Use g_autofree in all call site of vfio_get_region_info() Date: Wed, 22 May 2024 11:54:41 +0200 Message-ID: <20240522095442.195243-47-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.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.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: 1716372088310100001 From: Zhenzhong Duan There are some exceptions when pointer to vfio_region_info is reused. In that case, the pointed memory is freed manually. Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/helpers.c | 7 ++----- hw/vfio/igd.c | 5 ++--- hw/vfio/pci.c | 13 +++---------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 4b079dc383683a71d1d96507a0fb66a4bc3ba923..27ea26aa48f67e6518f871ac651= ab8d2703cc611 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -343,7 +343,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *r= egion, int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *regio= n, int index, const char *name) { - struct vfio_region_info *info; + g_autofree struct vfio_region_info *info =3D NULL; int ret; =20 ret =3D vfio_get_region_info(vbasedev, index, &info); @@ -376,8 +376,6 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, } } =20 - g_free(info); - trace_vfio_region_setup(vbasedev->name, index, name, region->flags, region->fd_offset, region->size= ); return 0; @@ -594,14 +592,13 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, ui= nt32_t type, =20 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe) { - struct vfio_region_info *info =3D NULL; + g_autofree struct vfio_region_info *info =3D NULL; bool ret =3D false; =20 if (!vfio_get_region_info(vbasedev, region, &info)) { if (vfio_get_region_info_cap(info, cap_type)) { ret =3D true; } - g_free(info); } =20 return ret; diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 402fc5ce1da966fda1340f328e0611cb1a2a0635..1e79202f2bd136b0bafd4f08c2f= 1407e467e0d65 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -367,8 +367,8 @@ static const MemoryRegionOps vfio_igd_index_quirk =3D { =20 void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { - struct vfio_region_info *rom =3D NULL, *opregion =3D NULL, - *host =3D NULL, *lpc =3D NULL; + g_autofree struct vfio_region_info *rom =3D NULL; + struct vfio_region_info *opregion =3D NULL, *host =3D NULL, *lpc =3D N= ULL; VFIOQuirk *quirk; VFIOIGDQuirk *igd; PCIDevice *lpc_bridge; @@ -609,7 +609,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, ggms_mb + gms_mb); =20 out: - g_free(rom); g_free(opregion); g_free(host); g_free(lpc); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 35ad9b582f6b99510a812edab5c2855c697a1da2..74a79bdf61f9aeb4860d532b6c0= 76dd3491dd0ab 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -879,7 +879,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev) =20 static void vfio_pci_load_rom(VFIOPCIDevice *vdev) { - struct vfio_region_info *reg_info; + g_autofree struct vfio_region_info *reg_info =3D NULL; uint64_t size; off_t off =3D 0; ssize_t bytes; @@ -897,8 +897,6 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) vdev->rom_size =3D size =3D reg_info->size; vdev->rom_offset =3D reg_info->offset; =20 - g_free(reg_info); - if (!vdev->rom_size) { vdev->rom_read_failed =3D true; error_report("vfio-pci: Cannot read device rom at " @@ -2668,7 +2666,7 @@ static VFIODeviceOps vfio_pci_ops =3D { bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev =3D &vdev->vbasedev; - struct vfio_region_info *reg_info; + g_autofree struct vfio_region_info *reg_info =3D NULL; int ret; =20 ret =3D vfio_get_region_info(vbasedev, VFIO_PCI_VGA_REGION_INDEX, ®= _info); @@ -2685,7 +2683,6 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) error_setg(errp, "unexpected VGA info, flags 0x%lx, size 0x%lx", (unsigned long)reg_info->flags, (unsigned long)reg_info->size); - g_free(reg_info); return false; } =20 @@ -2694,8 +2691,6 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) vdev->vga->fd_offset =3D reg_info->offset; vdev->vga->fd =3D vdev->vbasedev.fd; =20 - g_free(reg_info); - vdev->vga->region[QEMU_PCI_VGA_MEM].offset =3D QEMU_PCI_VGA_MEM_BASE; vdev->vga->region[QEMU_PCI_VGA_MEM].nr =3D QEMU_PCI_VGA_MEM; QLIST_INIT(&vdev->vga->region[QEMU_PCI_VGA_MEM].quirks); @@ -2736,7 +2731,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) { VFIODevice *vbasedev =3D &vdev->vbasedev; - struct vfio_region_info *reg_info; + g_autofree struct vfio_region_info *reg_info =3D NULL; struct vfio_irq_info irq_info =3D { .argsz =3D sizeof(irq_info) }; int i, ret =3D -1; =20 @@ -2790,8 +2785,6 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev,= Error **errp) } vdev->config_offset =3D reg_info->offset; =20 - g_free(reg_info); - if (vdev->features & VFIO_FEATURE_ENABLE_VGA) { if (!vfio_populate_vga(vdev, errp)) { error_append_hint(errp, "device does not support " --=20 2.45.1 From nobody Mon Nov 25 08:03:47 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=1716371847; cv=none; d=zohomail.com; s=zohoarc; b=PgCVE9Enlfeb7vD33396yV3dAFunta5fKwQqYoKCm3dpgzrXvlGxnWuMZEAKsW0OAQ/yadj4R62dN055VEnp6FvrWmBLZZ4oMQZU8s/1+w5OoGyMV+gov1hSIdqdz151rwzjOHcg7lCUdQFFf6oVrrNjDC48OPwzDsNVfIpz0jY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716371847; 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=wKSNjl0lt4yslzVe4UOEZ3ud0SqQvcTMh97IKf8SyQs=; b=NuSv02jYD03lTSai5AHDrwvd7JhTA93T061WjoaSJtad3Ip3vuid6ETpnhpNFzSHHhW7LimM91fhcN11gNo5yiNtqwUY2iMDwFn7e43OknfZbSd9SIeTDRXO/luv0wFsCceQaYnan340q6w/CYfX1DP4DFrnqXgzerMenZBp63A= 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 1716371847526435.1438178341373; Wed, 22 May 2024 02:57:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ihY-0005en-AC; Wed, 22 May 2024 05:56: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 1s9ihU-0005D3-80 for qemu-devel@nongnu.org; Wed, 22 May 2024 05:56: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 1s9ihS-0001wB-FJ for qemu-devel@nongnu.org; Wed, 22 May 2024 05:55: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-649-BdH2wSQBNoCfOxN_Yb6xDw-1; Wed, 22 May 2024 05:55:56 -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 EB4B9380008F; Wed, 22 May 2024 09:55:55 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA8057412; Wed, 22 May 2024 09:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716371757; 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=wKSNjl0lt4yslzVe4UOEZ3ud0SqQvcTMh97IKf8SyQs=; b=RJw8uaxSRVJkLbVz7X9807EORKuPk9srYdOSqnywCTfSXjrmGB+iOFdZryI4xBUefs1xuP 4TKr63PNZNK54rjqIzKzaH/E5r01rfj7w2sUMwtJm7cU4/99Ggwd+xEnd7VQP4tflnSlAd Ug+yJZzZAchaytl/2RmAhMuCjzLEBAI= X-MC-Unique: BdH2wSQBNoCfOxN_Yb6xDw-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Zhenzhong Duan , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 47/47] vfio/igd: Use g_autofree in vfio_probe_igd_bar4_quirk() Date: Wed, 22 May 2024 11:54:42 +0200 Message-ID: <20240522095442.195243-48-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: 1716371849129100013 From: Zhenzhong Duan Pointer opregion, host and lpc are allocated and freed in vfio_probe_igd_bar4_quirk(). Use g_autofree to automatically free them. Signed-off-by: Zhenzhong Duan Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/igd.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 1e79202f2bd136b0bafd4f08c2f1407e467e0d65..d320d032a7f3b19df0d055178f6= fefe4bdfd8668 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -368,7 +368,9 @@ static const MemoryRegionOps vfio_igd_index_quirk =3D { void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { g_autofree struct vfio_region_info *rom =3D NULL; - struct vfio_region_info *opregion =3D NULL, *host =3D NULL, *lpc =3D N= ULL; + g_autofree struct vfio_region_info *opregion =3D NULL; + g_autofree struct vfio_region_info *host =3D NULL; + g_autofree struct vfio_region_info *lpc =3D NULL; VFIOQuirk *quirk; VFIOIGDQuirk *igd; PCIDevice *lpc_bridge; @@ -426,7 +428,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) if ((ret || !rom->size) && !vdev->pdev.romfile) { error_report("IGD device %s has no ROM, legacy mode disabled", vdev->vbasedev.name); - goto out; + return; } =20 /* @@ -437,7 +439,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) error_report("IGD device %s hotplugged, ROM disabled, " "legacy mode disabled", vdev->vbasedev.name); vdev->rom_read_failed =3D true; - goto out; + return; } =20 /* @@ -450,7 +452,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) if (ret) { error_report("IGD device %s does not support OpRegion access," "legacy mode disabled", vdev->vbasedev.name); - goto out; + return; } =20 ret =3D vfio_get_dev_region_info(&vdev->vbasedev, @@ -459,7 +461,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) if (ret) { error_report("IGD device %s does not support host bridge access," "legacy mode disabled", vdev->vbasedev.name); - goto out; + return; } =20 ret =3D vfio_get_dev_region_info(&vdev->vbasedev, @@ -468,7 +470,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) if (ret) { error_report("IGD device %s does not support LPC bridge access," "legacy mode disabled", vdev->vbasedev.name); - goto out; + return; } =20 gmch =3D vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4); @@ -482,7 +484,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); error_report("IGD device %s failed to enable VGA access, " "legacy mode disabled", vdev->vbasedev.name); - goto out; + return; } =20 /* Create our LPC/ISA bridge */ @@ -490,7 +492,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) if (ret) { error_report("IGD device %s failed to create LPC bridge, " "legacy mode disabled", vdev->vbasedev.name); - goto out; + return; } =20 /* Stuff some host values into the VM PCI host bridge */ @@ -498,14 +500,14 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, i= nt nr) if (ret) { error_report("IGD device %s failed to modify host bridge, " "legacy mode disabled", vdev->vbasedev.name); - goto out; + return; } =20 /* Setup OpRegion access */ if (!vfio_pci_igd_opregion_init(vdev, opregion, &err)) { error_append_hint(&err, "IGD legacy mode disabled\n"); error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name); - goto out; + return; } =20 /* Setup our quirk to munge GTT addresses to the VM allocated buffer */ @@ -607,9 +609,4 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int= nr) } =20 trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, ggms_mb + gms_mb); - -out: - g_free(opregion); - g_free(host); - g_free(lpc); } --=20 2.45.1