From nobody Sun Feb 8 21:47:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1745338203; cv=none; d=zohomail.com; s=zohoarc; b=Eod/tFeTF0j+Eyu0M2Vsx/LIxvh6KxUNPIw18kWt06xsaaU+VPibR6bTzRcBDSBjR4Sqyw36Eova8vGT4E9XpIb63tm4PNTkbQ5HSSYg0y2tpooHYFI/S281zPOo+j3mgVxsRi3BQaksod0uVGlo4KEPG9Q2Lb/9sQe7HgAca+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745338203; 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=OXs6IWNaOUfd8auzX1OxgcybUIDY9I0NrLLwfLcBELs=; b=CS34+C0lrypkkvVC1gJHUksNfdUYfr0QuApTEyU+83uf8vnxohwgtxNYCTRUTi0Kb9EE2aXDE28SAMK811/RIPyiX+ybBaARv8zeQVbg6DhFwjP6poFSwBx0IVl6u5wrliqtJwkSKPGwVh7FMoTQSBwoE+ii8z5BuKZU6/g//54= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745338203451429.7594680372389; Tue, 22 Apr 2025 09:10:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u7GBf-0006Du-1x; Tue, 22 Apr 2025 12:09: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 1u7G6v-0000xt-4m for qemu-devel@nongnu.org; Tue, 22 Apr 2025 12:04: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 1u7G6s-0005Bi-Fe for qemu-devel@nongnu.org; Tue, 22 Apr 2025 12:04:36 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-XdT9J-O4PxO7ewh-fnoH5g-1; Tue, 22 Apr 2025 12:04:29 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 857BA1801A02; Tue, 22 Apr 2025 16:04:28 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.105]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B692418001DA; Tue, 22 Apr 2025 16:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745337873; 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=OXs6IWNaOUfd8auzX1OxgcybUIDY9I0NrLLwfLcBELs=; b=L0OFCzU7OruhEyYOuEbBDTB3zRG8gQ8kxzmCbglZEjq+sTYNpvSSy3Q9L5GHoaqgC8PtYv snh60aZ7zZ0oUXDmsUOVW4EBHK2qtlE84JcPm7bvtxwAxxzPMKwtjgLJKbq34YOHYSqGmW 2Dwa6f2k5T3ptSakJrucbwcRDIT1mEo= X-MC-Unique: XdT9J-O4PxO7ewh-fnoH5g-1 X-Mimecast-MFC-AGG-ID: XdT9J-O4PxO7ewh-fnoH5g_1745337868 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org, Alex Williamson Cc: Avihai Horon , Eric Auger , Zhenzhong Duan , John Levon , Joao Martins , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH v3 34/37] vfio: Introduce vfio_listener_un/register() routines Date: Tue, 22 Apr 2025 18:02:21 +0200 Message-ID: <20250422160224.199714-35-clg@redhat.com> In-Reply-To: <20250422160224.199714-1-clg@redhat.com> References: <20250422160224.199714-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.30.177.111 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.411, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: 1745338204723019100 This hides the MemoryListener implementation and makes the code common to both IOMMU backends, legacy and IOMMUFD. Reviewed-by: Joao Martins Reviewed-by: John Levon Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-35-clg@redh= at.com Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/vfio-listener.h | 3 ++- hw/vfio/container.c | 11 +++-------- hw/vfio/iommufd.c | 9 ++------- hw/vfio/listener.c | 22 +++++++++++++++++++++- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/hw/vfio/vfio-listener.h b/hw/vfio/vfio-listener.h index 93af6747b28955f038454a335b361787f8364a3a..eb69ddd374fa20683007cfc4e9a= 7bf6fe707f27d 100644 --- a/hw/vfio/vfio-listener.h +++ b/hw/vfio/vfio-listener.h @@ -9,6 +9,7 @@ #ifndef HW_VFIO_VFIO_LISTENER_H #define HW_VFIO_VFIO_LISTENER_H =20 -extern const MemoryListener vfio_memory_listener; +bool vfio_listener_register(VFIOContainerBase *bcontainer, Error **errp); +void vfio_listener_unregister(VFIOContainerBase *bcontainer); =20 #endif /* HW_VFIO_VFIO_LISTENER_H */ diff --git a/hw/vfio/container.c b/hw/vfio/container.c index acebb53dcb1b829d31cc31d9f7f2cc9599f952eb..f086e5c802f058c01ca740de338= 538106874fb03 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -616,12 +616,7 @@ static bool vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_next); =20 - bcontainer->listener =3D vfio_memory_listener; - memory_listener_register(&bcontainer->listener, bcontainer->space->as); - - if (bcontainer->error) { - error_propagate_prepend(errp, bcontainer->error, - "memory listener initialization failed: "); + if (!vfio_listener_register(bcontainer, errp)) { goto listener_release_exit; } =20 @@ -631,7 +626,7 @@ static bool vfio_connect_container(VFIOGroup *group, Ad= dressSpace *as, listener_release_exit: QLIST_REMOVE(group, container_next); vfio_kvm_device_del_group(group); - memory_listener_unregister(&bcontainer->listener); + vfio_listener_unregister(bcontainer); if (vioc->release) { vioc->release(bcontainer); } @@ -669,7 +664,7 @@ static void vfio_disconnect_container(VFIOGroup *group) * group. */ if (QLIST_EMPTY(&container->group_list)) { - memory_listener_unregister(&bcontainer->listener); + vfio_listener_unregister(bcontainer); if (vioc->release) { vioc->release(bcontainer); } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 7488d21215b6eee78c9c51cfb227d9c8c59c4978..e47720247d6acfd6ea0e5a2e2a2= eecabfa62dce3 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -410,7 +410,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDC= ontainer *container) if (!QLIST_EMPTY(&bcontainer->device_list)) { return; } - memory_listener_unregister(&bcontainer->listener); + vfio_listener_unregister(bcontainer); iommufd_backend_free_id(container->be, container->ioas_id); object_unref(container); } @@ -562,12 +562,7 @@ static bool iommufd_cdev_attach(const char *name, VFIO= Device *vbasedev, bcontainer->pgsizes =3D qemu_real_host_page_size(); } =20 - bcontainer->listener =3D vfio_memory_listener; - memory_listener_register(&bcontainer->listener, bcontainer->space->as); - - if (bcontainer->error) { - error_propagate_prepend(errp, bcontainer->error, - "memory listener initialization failed: "); + if (!vfio_listener_register(bcontainer, errp)) { goto err_listener_register; } =20 diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 8abcf8c14d7a9c386665660804c0e19eb93b6846..d0cd21ef6156471b93a69d29c6c= 52d49a58056a9 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -46,6 +46,7 @@ #include "system/tpm.h" #include "vfio-migration-internal.h" #include "vfio-helpers.h" +#include "vfio-listener.h" =20 /* * Device state interfaces @@ -1163,7 +1164,7 @@ static void vfio_listener_log_sync(MemoryListener *li= stener, } } =20 -const MemoryListener vfio_memory_listener =3D { +static const MemoryListener vfio_memory_listener =3D { .name =3D "vfio", .region_add =3D vfio_listener_region_add, .region_del =3D vfio_listener_region_del, @@ -1171,3 +1172,22 @@ const MemoryListener vfio_memory_listener =3D { .log_global_stop =3D vfio_listener_log_global_stop, .log_sync =3D vfio_listener_log_sync, }; + +bool vfio_listener_register(VFIOContainerBase *bcontainer, Error **errp) +{ + bcontainer->listener =3D vfio_memory_listener; + memory_listener_register(&bcontainer->listener, bcontainer->space->as); + + if (bcontainer->error) { + error_propagate_prepend(errp, bcontainer->error, + "memory listener initialization failed: "); + return false; + } + + return true; +} + +void vfio_listener_unregister(VFIOContainerBase *bcontainer) +{ + memory_listener_unregister(&bcontainer->listener); +} --=20 2.49.0