qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-10.1 00/32] vfio: Spring cleanup
@ 2025-03-18  9:53 Cédric Le Goater
  2025-03-18  9:53 ` [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c Cédric Le Goater
                   ` (31 more replies)
  0 siblings, 32 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Hello,

Several large extensions were merged in VFIO recently: migration
support with dirty tracking, support for different host IOMMU backend
devices, multifd support, etc. This adds up to the previous
extensions: vfio-platform, AP, CCW. The result is that VFIO is now a
subsystem of over +16,000 lines of code :

  QEMU 2.0  :   3988 total
  QEMU 2.12 :   9336 total
  QEMU 6.2  :  12715 total
  QEMU 8.2  :  13690 total
  QEMU 9.2  :  15680 total
  QEMU 10.0 :  16607 total

Organization is weak, naming inconsistent, the vfio-common.h header
file and common.c are quite messy. It's time to address the technical
debt before adding new features.

This proposal reorganizes some of the VFIO files to isolate features,
introduces new files and renames services to better reflect the
namespace they belong to. This is code reshuffling and there are no
intentional functional changes. If more could be done, please propose !
Timing seems right.

I hope we can merge this when the QEMU 10.1 cycle starts and then
address the two large series waiting : live update and vfio-user.

Thanks,

C. 

Cédric Le Goater (32):
  vfio: Move vfio_mig_active() into migration.c
  vfio: Rename vfio_reset_bytes_transferred()
  vfio: Introduce a new header file for external migration services
  vfio: Make vfio_un/block_multiple_devices_migration() static
  vfio: Make vfio_viommu_preset() static
  vfio: Introduce a new header file for internal migration services
  vfio: Introduce a new header file for VFIOdisplay declarations
  vfio: Move VFIOHostDMAWindow definition into spapr.c
  vfio: Introduce a new header file for VFIOIOMMUFD declarations
  vfio: Introduce new files for VFIORegion definitions and declarations
  vfio: Introduce a new header file for VFIOcontainer declarations
  vfio: Make vfio_group_list static
  vfio: Move VFIOAddressSpace helpers into container-base.c
  vfio: Move Host IOMMU type declarations into their respective files
  vfio: Introduce a new header file for helper services
  vfio: Move vfio_get_info_dma_avail() into helpers.c
  vfio: Move vfio_kvm_device_add/del_fd() to helpers.c
  vfio: Move vfio_get_device_info() to helpers.c
  vfio: Introduce a new file for VFIODevice definitions
  vfio: Introduce new files for CPR definitions and declarations
  vfio: Move vfio_kvm_device_fd() into helpers.c
  vfio: Move vfio_device_list into device.c
  vfio: Move vfio_de/attach_device() into device.c
  vfio: Introduce new files for dirty tracking definitions and
    declarations
  vfio: Move vfio_set_migration_error() into migration.c
  vfio: Rename vfio-common.h to vfio-device.h
  vfio: Rename VFIODevice related services
  vfio: Make vfio_devices_query_dirty_bitmap() static
  vfio: Rename VFIOContainer related services
  vfio: Rename VFIO dirty tracking services
  vfio: Introduce vfio_dirty_tracking_un/register() routines
  vfio: Rename RAM discard related services

 hw/vfio/cpr.h                          |  15 +
 hw/vfio/dirty-tracking.h               |  19 +
 hw/vfio/display.h                      |  42 ++
 hw/vfio/helpers.h                      |  35 ++
 hw/vfio/iommufd.h                      |  29 +
 hw/vfio/migration-multifd.h            |   2 +-
 hw/vfio/migration.h                    |  73 +++
 hw/vfio/pci.h                          |   3 +-
 include/hw/s390x/vfio-ccw.h            |   2 +-
 include/hw/vfio/vfio-common.h          | 346 ------------
 include/hw/vfio/vfio-container-base.h  |   5 +
 include/hw/vfio/vfio-container.h       |  35 ++
 include/hw/vfio/vfio-device.h          | 148 ++++++
 include/hw/vfio/vfio-migration.h       |  17 +
 include/hw/vfio/vfio-platform.h        |   4 +-
 include/hw/vfio/vfio-region.h          |  47 ++
 backends/iommufd.c                     |   2 +-
 hw/core/sysbus-fdt.c                   |   1 +
 hw/ppc/spapr_pci_vfio.c                |   6 +-
 hw/s390x/s390-pci-vfio.c               |   3 +-
 hw/vfio/ap.c                           |  10 +-
 hw/vfio/ccw.c                          |  20 +-
 hw/vfio/container-base.c               |  69 +++
 hw/vfio/container.c                    | 123 ++---
 hw/vfio/cpr.c                          |   3 +-
 hw/vfio/device.c                       | 371 +++++++++++++
 hw/vfio/{common.c => dirty-tracking.c} | 382 ++------------
 hw/vfio/display.c                      |   4 +-
 hw/vfio/helpers.c                      | 702 +++----------------------
 hw/vfio/igd.c                          |   8 +-
 hw/vfio/iommufd.c                      |  25 +-
 hw/vfio/migration-multifd.c            |   4 +-
 hw/vfio/migration.c                    | 112 +++-
 hw/vfio/pci-quirks.c                   |   1 +
 hw/vfio/pci.c                          |  51 +-
 hw/vfio/platform.c                     |  11 +-
 hw/vfio/region.c                       | 396 ++++++++++++++
 hw/vfio/spapr.c                        |  10 +-
 migration/target.c                     |   4 +-
 hw/vfio/meson.build                    |   8 +-
 hw/vfio/trace-events                   |  36 +-
 41 files changed, 1711 insertions(+), 1473 deletions(-)
 create mode 100644 hw/vfio/cpr.h
 create mode 100644 hw/vfio/dirty-tracking.h
 create mode 100644 hw/vfio/display.h
 create mode 100644 hw/vfio/helpers.h
 create mode 100644 hw/vfio/iommufd.h
 create mode 100644 hw/vfio/migration.h
 delete mode 100644 include/hw/vfio/vfio-common.h
 create mode 100644 include/hw/vfio/vfio-container.h
 create mode 100644 include/hw/vfio/vfio-device.h
 create mode 100644 include/hw/vfio/vfio-migration.h
 create mode 100644 include/hw/vfio/vfio-region.h
 create mode 100644 hw/vfio/device.c
 rename hw/vfio/{common.c => dirty-tracking.c} (81%)
 create mode 100644 hw/vfio/region.c

-- 
2.48.1



^ permalink raw reply	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19  9:10   ` John Levon
  2025-03-19 11:54   ` Avihai Horon
  2025-03-18  9:53 ` [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred() Cédric Le Goater
                   ` (30 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

vfio_mig_active() is part of the VFIO migration API. Move the
definitions where VFIO migration is implemented.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/common.c    | 16 ----------------
 hw/vfio/migration.c | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 1a0d9290f88c9774a98f65087a36b86922b21a73..4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -66,22 +66,6 @@ int vfio_kvm_device_fd = -1;
  * Device state interfaces
  */
 
-bool vfio_mig_active(void)
-{
-    VFIODevice *vbasedev;
-
-    if (QLIST_EMPTY(&vfio_device_list)) {
-        return false;
-    }
-
-    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
-        if (vbasedev->migration_blocker) {
-            return false;
-        }
-    }
-    return true;
-}
-
 static Error *multiple_devices_migration_blocker;
 
 /*
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index fbff46cfc35e0ee69e9599c9f8efc7437bbe3370..b5fb0d218808d010d8210612d3182dde8f33514b 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -1062,6 +1062,22 @@ void vfio_mig_add_bytes_transferred(unsigned long val)
     qatomic_add(&bytes_transferred, val);
 }
 
+bool vfio_mig_active(void)
+{
+    VFIODevice *vbasedev;
+
+    if (QLIST_EMPTY(&vfio_device_list)) {
+        return false;
+    }
+
+    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
+        if (vbasedev->migration_blocker) {
+            return false;
+        }
+    }
+    return true;
+}
+
 /*
  * Return true when either migration initialized or blocker registered.
  * Currently only return false when adding blocker fails which will
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred()
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
  2025-03-18  9:53 ` [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19  7:33   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2025-03-18  9:53 ` [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services Cédric Le Goater
                   ` (29 subsequent siblings)
  31 siblings, 3 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Enforce a 'vfio_mig_' prefix for the VFIO migration API to better
reflect the namespace these routines belong to.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h | 2 +-
 hw/vfio/migration.c           | 2 +-
 migration/target.c            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 04b123a6c929a8f47d740fc5433b54dadd32f731..9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -295,7 +295,7 @@ int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
 void vfio_unblock_multiple_devices_migration(void);
 bool vfio_viommu_preset(VFIODevice *vbasedev);
 int64_t vfio_mig_bytes_transferred(void);
-void vfio_reset_bytes_transferred(void);
+void vfio_mig_reset_bytes_transferred(void);
 void vfio_mig_add_bytes_transferred(unsigned long val);
 bool vfio_device_state_is_running(VFIODevice *vbasedev);
 bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index b5fb0d218808d010d8210612d3182dde8f33514b..8bf65b8e11094b8363692dba3084b762362c7dd6 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -1052,7 +1052,7 @@ int64_t vfio_mig_bytes_transferred(void)
     return MIN(qatomic_read(&bytes_transferred), INT64_MAX);
 }
 
-void vfio_reset_bytes_transferred(void)
+void vfio_mig_reset_bytes_transferred(void)
 {
     qatomic_set(&bytes_transferred, 0);
 }
diff --git a/migration/target.c b/migration/target.c
index a6ffa9a5ce312d1e64157b650827aa726eb4d364..f5d8cfe7c2a3473f4bd3f5068145598c60973c58 100644
--- a/migration/target.c
+++ b/migration/target.c
@@ -25,7 +25,7 @@ void migration_populate_vfio_info(MigrationInfo *info)
 
 void migration_reset_vfio_bytes_transferred(void)
 {
-    vfio_reset_bytes_transferred();
+    vfio_mig_reset_bytes_transferred();
 }
 #else
 void migration_populate_vfio_info(MigrationInfo *info)
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
  2025-03-18  9:53 ` [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c Cédric Le Goater
  2025-03-18  9:53 ` [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred() Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 11:48   ` Prasad Pandit
  2025-03-19 12:37   ` Avihai Horon
  2025-03-18  9:53 ` [PATCH for-10.1 04/32] vfio: Make vfio_un/block_multiple_devices_migration() static Cédric Le Goater
                   ` (28 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

The migration core subsytem makes uses of the VFIO migration API to
collect statistics on the number of bytes transferred. These services
are declared in "hw/vfio/vfio-common.h" which also contains VFIO
internal declarations. Move the migration declarations into a new
header file "hw/vfio/vfio-migration.h" to reduce the exposure of VFIO
internals.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h    |  4 ----
 include/hw/vfio/vfio-migration.h | 17 +++++++++++++++++
 hw/vfio/migration-multifd.c      |  1 +
 hw/vfio/migration.c              |  1 +
 migration/target.c               |  2 +-
 5 files changed, 20 insertions(+), 5 deletions(-)
 create mode 100644 include/hw/vfio/vfio-migration.h

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -290,13 +290,9 @@ extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
 extern int vfio_kvm_device_fd;
 
-bool vfio_mig_active(void);
 int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
 void vfio_unblock_multiple_devices_migration(void);
 bool vfio_viommu_preset(VFIODevice *vbasedev);
-int64_t vfio_mig_bytes_transferred(void);
-void vfio_mig_reset_bytes_transferred(void);
-void vfio_mig_add_bytes_transferred(unsigned long val);
 bool vfio_device_state_is_running(VFIODevice *vbasedev);
 bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
 
diff --git a/include/hw/vfio/vfio-migration.h b/include/hw/vfio/vfio-migration.h
new file mode 100644
index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
--- /dev/null
+++ b/include/hw/vfio/vfio-migration.h
@@ -0,0 +1,17 @@
+/*
+ * VFIO migration interface
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_VFIO_MIGRATION_H
+#define HW_VFIO_VFIO_MIGRATION_H
+
+bool vfio_mig_active(void);
+int64_t vfio_mig_bytes_transferred(void);
+void vfio_mig_reset_bytes_transferred(void);
+void vfio_mig_add_bytes_transferred(unsigned long val);
+
+#endif /* HW_VFIO_VFIO_MIGRATION_H */
diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
--- a/hw/vfio/migration-multifd.c
+++ b/hw/vfio/migration-multifd.c
@@ -11,6 +11,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-migration.h"
 #include "migration/misc.h"
 #include "qapi/error.h"
 #include "qemu/bswap.h"
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -17,6 +17,7 @@
 
 #include "system/runstate.h"
 #include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-migration.h"
 #include "migration/misc.h"
 #include "migration/savevm.h"
 #include "migration/vmstate.h"
diff --git a/migration/target.c b/migration/target.c
index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
--- a/migration/target.c
+++ b/migration/target.c
@@ -11,7 +11,7 @@
 #include CONFIG_DEVICES
 
 #ifdef CONFIG_VFIO
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-migration.h"
 #endif
 
 #ifdef CONFIG_VFIO
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 04/32] vfio: Make vfio_un/block_multiple_devices_migration() static
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (2 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 12:38   ` Joao Martins
  2025-03-18  9:53 ` [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static Cédric Le Goater
                   ` (27 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Both of these routines are only used in file "migration.c". Move them
there.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h |  2 --
 hw/vfio/common.c              | 62 -----------------------------------
 hw/vfio/migration.c           | 62 +++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 64 deletions(-)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 5fc7ee76573375bc8464baee29ab88974fac3d3b..5f082e5a321d97e90066d48cd3c1eaad56912ccb 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -290,8 +290,6 @@ extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
 extern int vfio_kvm_device_fd;
 
-int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
-void vfio_unblock_multiple_devices_migration(void);
 bool vfio_viommu_preset(VFIODevice *vbasedev);
 bool vfio_device_state_is_running(VFIODevice *vbasedev);
 bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f..ace7a4403bd49f35cf85009015b3ba315f80cd30 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -41,7 +41,6 @@
 #include "trace.h"
 #include "qapi/error.h"
 #include "migration/misc.h"
-#include "migration/blocker.h"
 #include "migration/qemu-file.h"
 #include "system/tcg.h"
 #include "system/tpm.h"
@@ -66,67 +65,6 @@ int vfio_kvm_device_fd = -1;
  * Device state interfaces
  */
 
-static Error *multiple_devices_migration_blocker;
-
-/*
- * Multiple devices migration is allowed only if all devices support P2P
- * migration. Single device migration is allowed regardless of P2P migration
- * support.
- */
-static bool vfio_multiple_devices_migration_is_supported(void)
-{
-    VFIODevice *vbasedev;
-    unsigned int device_num = 0;
-    bool all_support_p2p = true;
-
-    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
-        if (vbasedev->migration) {
-            device_num++;
-
-            if (!(vbasedev->migration->mig_flags & VFIO_MIGRATION_P2P)) {
-                all_support_p2p = false;
-            }
-        }
-    }
-
-    return all_support_p2p || device_num <= 1;
-}
-
-int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp)
-{
-    int ret;
-
-    if (vfio_multiple_devices_migration_is_supported()) {
-        return 0;
-    }
-
-    if (vbasedev->enable_migration == ON_OFF_AUTO_ON) {
-        error_setg(errp, "Multiple VFIO devices migration is supported only if "
-                         "all of them support P2P migration");
-        return -EINVAL;
-    }
-
-    if (multiple_devices_migration_blocker) {
-        return 0;
-    }
-
-    error_setg(&multiple_devices_migration_blocker,
-               "Multiple VFIO devices migration is supported only if all of "
-               "them support P2P migration");
-    ret = migrate_add_blocker_normal(&multiple_devices_migration_blocker, errp);
-
-    return ret;
-}
-
-void vfio_unblock_multiple_devices_migration(void)
-{
-    if (!multiple_devices_migration_blocker ||
-        !vfio_multiple_devices_migration_is_supported()) {
-        return;
-    }
-
-    migrate_del_blocker(&multiple_devices_migration_blocker);
-}
 
 bool vfio_viommu_preset(VFIODevice *vbasedev)
 {
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 75096377ffecf62b3bab91102a00d723827ea4c7..951e073a20287c46ca199b1648782b59415d0d2a 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -1022,6 +1022,68 @@ static int vfio_migration_init(VFIODevice *vbasedev)
     return 0;
 }
 
+static Error *multiple_devices_migration_blocker;
+
+/*
+ * Multiple devices migration is allowed only if all devices support P2P
+ * migration. Single device migration is allowed regardless of P2P migration
+ * support.
+ */
+static bool vfio_multiple_devices_migration_is_supported(void)
+{
+    VFIODevice *vbasedev;
+    unsigned int device_num = 0;
+    bool all_support_p2p = true;
+
+    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
+        if (vbasedev->migration) {
+            device_num++;
+
+            if (!(vbasedev->migration->mig_flags & VFIO_MIGRATION_P2P)) {
+                all_support_p2p = false;
+            }
+        }
+    }
+
+    return all_support_p2p || device_num <= 1;
+}
+
+static int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp)
+{
+    int ret;
+
+    if (vfio_multiple_devices_migration_is_supported()) {
+        return 0;
+    }
+
+    if (vbasedev->enable_migration == ON_OFF_AUTO_ON) {
+        error_setg(errp, "Multiple VFIO devices migration is supported only if "
+                         "all of them support P2P migration");
+        return -EINVAL;
+    }
+
+    if (multiple_devices_migration_blocker) {
+        return 0;
+    }
+
+    error_setg(&multiple_devices_migration_blocker,
+               "Multiple VFIO devices migration is supported only if all of "
+               "them support P2P migration");
+    ret = migrate_add_blocker_normal(&multiple_devices_migration_blocker, errp);
+
+    return ret;
+}
+
+static void vfio_unblock_multiple_devices_migration(void)
+{
+    if (!multiple_devices_migration_blocker ||
+        !vfio_multiple_devices_migration_is_supported()) {
+        return;
+    }
+
+    migrate_del_blocker(&multiple_devices_migration_blocker);
+}
+
 static void vfio_migration_deinit(VFIODevice *vbasedev)
 {
     VFIOMigration *migration = vbasedev->migration;
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (3 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 04/32] vfio: Make vfio_un/block_multiple_devices_migration() static Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 12:26   ` Joao Martins
  2025-03-19 16:50   ` John Levon
  2025-03-18  9:53 ` [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services Cédric Le Goater
                   ` (26 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

This routine is only used in file "migration.c". Move it there.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h | 1 -
 hw/vfio/common.c              | 6 ------
 hw/vfio/migration.c           | 5 +++++
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 5f082e5a321d97e90066d48cd3c1eaad56912ccb..0aae88131cffda1a90b8ccd0224387133c0fa83a 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -290,7 +290,6 @@ extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
 extern int vfio_kvm_device_fd;
 
-bool vfio_viommu_preset(VFIODevice *vbasedev);
 bool vfio_device_state_is_running(VFIODevice *vbasedev);
 bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
 
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index ace7a4403bd49f35cf85009015b3ba315f80cd30..0b9b071cd0490867bb6aa4ceb261350ccd6e1125 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -65,12 +65,6 @@ int vfio_kvm_device_fd = -1;
  * Device state interfaces
  */
 
-
-bool vfio_viommu_preset(VFIODevice *vbasedev)
-{
-    return vbasedev->bcontainer->space->as != &address_space_memory;
-}
-
 static void vfio_set_migration_error(int ret)
 {
     if (migration_is_running()) {
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 951e073a20287c46ca199b1648782b59415d0d2a..a1ba993ce549fce0d2a9a60ba07d4782c87c0c09 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -1141,6 +1141,11 @@ bool vfio_mig_active(void)
     return true;
 }
 
+static bool vfio_viommu_preset(VFIODevice *vbasedev)
+{
+    return vbasedev->bcontainer->space->as != &address_space_memory;
+}
+
 /*
  * Return true when either migration initialized or blocker registered.
  * Currently only return false when adding blocker fails which will
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (4 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 12:29   ` Prasad Pandit
                     ` (2 more replies)
  2025-03-18  9:53 ` [PATCH for-10.1 07/32] vfio: Introduce a new header file for VFIOdisplay declarations Cédric Le Goater
                   ` (25 subsequent siblings)
  31 siblings, 3 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Gather all VFIO migration related declarations into "migration.h" to
reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/migration.h           | 72 +++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h | 54 +-------------------------
 hw/vfio/common.c              | 17 +--------
 hw/vfio/iommufd.c             |  1 +
 hw/vfio/migration-multifd.c   |  1 +
 hw/vfio/migration.c           | 17 +++++++++
 hw/vfio/pci.c                 |  1 +
 7 files changed, 94 insertions(+), 69 deletions(-)
 create mode 100644 hw/vfio/migration.h

diff --git a/hw/vfio/migration.h b/hw/vfio/migration.h
new file mode 100644
index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
--- /dev/null
+++ b/hw/vfio/migration.h
@@ -0,0 +1,72 @@
+/*
+ * VFIO migration
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_MIGRATION_H
+#define HW_VFIO_MIGRATION_H
+
+#ifdef CONFIG_LINUX
+#include <linux/vfio.h>
+#endif
+
+#include "qemu/notify.h"
+
+/*
+ * Flags to be used as unique delimiters for VFIO devices in the migration
+ * stream. These flags are composed as:
+ * 0xffffffff => MSB 32-bit all 1s
+ * 0xef10     => Magic ID, represents emulated (virtual) function IO
+ * 0x0000     => 16-bits reserved for flags
+ *
+ * The beginning of state information is marked by _DEV_CONFIG_STATE,
+ * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
+ * certain state information is marked by _END_OF_STATE.
+ */
+#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
+#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
+#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
+#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
+#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
+
+typedef struct VFIODevice VFIODevice;
+typedef struct VFIOMultifd VFIOMultifd;
+
+typedef struct VFIOMigration {
+    struct VFIODevice *vbasedev;
+    VMChangeStateEntry *vm_state;
+    NotifierWithReturn migration_state;
+    uint32_t device_state;
+    int data_fd;
+    void *data_buffer;
+    size_t data_buffer_size;
+    uint64_t mig_flags;
+    uint64_t precopy_init_size;
+    uint64_t precopy_dirty_size;
+    bool multifd_transfer;
+    VFIOMultifd *multifd;
+    bool initial_data_sent;
+
+    bool event_save_iterate_started;
+    bool event_precopy_empty_hit;
+} VFIOMigration;
+
+
+bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
+void vfio_migration_exit(VFIODevice *vbasedev);
+bool vfio_device_state_is_running(VFIODevice *vbasedev);
+bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
+int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
+int vfio_load_device_config_state(QEMUFile *f, void *opaque);
+
+#ifdef CONFIG_LINUX
+int vfio_migration_set_state(VFIODevice *vbasedev,
+                             enum vfio_device_mig_state new_state,
+                             enum vfio_device_mig_state recover_state,
+                             Error **errp);
+#endif
+
+#endif /* HW_VFIO_MIGRATION_H */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 0aae88131cffda1a90b8ccd0224387133c0fa83a..799e12d43747addbf444c15052f629b65978322f 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -23,7 +23,6 @@
 
 #include "exec/memory.h"
 #include "qemu/queue.h"
-#include "qemu/notify.h"
 #include "ui/console.h"
 #include "hw/display/ramfb.h"
 #ifdef CONFIG_LINUX
@@ -36,23 +35,6 @@
 
 #define VFIO_MSG_PREFIX "vfio %s: "
 
-/*
- * Flags to be used as unique delimiters for VFIO devices in the migration
- * stream. These flags are composed as:
- * 0xffffffff => MSB 32-bit all 1s
- * 0xef10     => Magic ID, represents emulated (virtual) function IO
- * 0x0000     => 16-bits reserved for flags
- *
- * The beginning of state information is marked by _DEV_CONFIG_STATE,
- * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
- * certain state information is marked by _END_OF_STATE.
- */
-#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
-#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
-#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
-#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
-#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
-
 enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
@@ -78,27 +60,6 @@ typedef struct VFIORegion {
     uint8_t nr; /* cache the region number for debug */
 } VFIORegion;
 
-typedef struct VFIOMultifd VFIOMultifd;
-
-typedef struct VFIOMigration {
-    struct VFIODevice *vbasedev;
-    VMChangeStateEntry *vm_state;
-    NotifierWithReturn migration_state;
-    uint32_t device_state;
-    int data_fd;
-    void *data_buffer;
-    size_t data_buffer_size;
-    uint64_t mig_flags;
-    uint64_t precopy_init_size;
-    uint64_t precopy_dirty_size;
-    bool multifd_transfer;
-    VFIOMultifd *multifd;
-    bool initial_data_sent;
-
-    bool event_save_iterate_started;
-    bool event_precopy_empty_hit;
-} VFIOMigration;
-
 struct VFIOGroup;
 
 typedef struct VFIOContainer {
@@ -136,6 +97,7 @@ typedef struct VFIOIOMMUFDContainer {
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD);
 
 typedef struct VFIODeviceOps VFIODeviceOps;
+typedef struct VFIOMigration VFIOMigration;
 
 typedef struct VFIODevice {
     QLIST_ENTRY(VFIODevice) next;
@@ -290,12 +252,6 @@ extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
 extern int vfio_kvm_device_fd;
 
-bool vfio_device_state_is_running(VFIODevice *vbasedev);
-bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
-
-int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
-int vfio_load_device_config_state(QEMUFile *f, void *opaque);
-
 #ifdef CONFIG_LINUX
 int vfio_get_region_info(VFIODevice *vbasedev, int index,
                          struct vfio_region_info **info);
@@ -310,16 +266,8 @@ struct vfio_info_cap_header *
 vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
 struct vfio_info_cap_header *
 vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
-
-int vfio_migration_set_state(VFIODevice *vbasedev,
-                             enum vfio_device_mig_state new_state,
-                             enum vfio_device_mig_state recover_state,
-                             Error **errp);
 #endif
 
-bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
-void vfio_migration_exit(VFIODevice *vbasedev);
-
 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
 bool vfio_devices_all_dirty_tracking_started(
     const VFIOContainerBase *bcontainer);
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -44,6 +44,7 @@
 #include "migration/qemu-file.h"
 #include "system/tcg.h"
 #include "system/tpm.h"
+#include "migration.h"
 
 VFIODeviceList vfio_device_list =
     QLIST_HEAD_INITIALIZER(vfio_device_list);
@@ -72,22 +73,6 @@ static void vfio_set_migration_error(int ret)
     }
 }
 
-bool vfio_device_state_is_running(VFIODevice *vbasedev)
-{
-    VFIOMigration *migration = vbasedev->migration;
-
-    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
-           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
-}
-
-bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
-{
-    VFIOMigration *migration = vbasedev->migration;
-
-    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
-           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
-}
-
 static bool vfio_devices_all_device_dirty_tracking_started(
     const VFIOContainerBase *bcontainer)
 {
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -25,6 +25,7 @@
 #include "qemu/cutils.h"
 #include "qemu/chardev_open.h"
 #include "pci.h"
+#include "migration.h"
 
 static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                             ram_addr_t size, void *vaddr, bool readonly)
diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
--- a/hw/vfio/migration-multifd.c
+++ b/hw/vfio/migration-multifd.c
@@ -22,6 +22,7 @@
 #include "io/channel-buffer.h"
 #include "migration/qemu-file.h"
 #include "migration-multifd.h"
+#include "migration.h"
 #include "trace.h"
 
 #define VFIO_DEVICE_STATE_CONFIG_STATE (1)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -31,6 +31,7 @@
 #include "pci.h"
 #include "trace.h"
 #include "hw/hw.h"
+#include "migration.h"
 
 /*
  * This is an arbitrary size based on migration of mlx5 devices, where typically
@@ -1222,3 +1223,19 @@ void vfio_migration_exit(VFIODevice *vbasedev)
 
     migrate_del_blocker(&vbasedev->migration_blocker);
 }
+
+bool vfio_device_state_is_running(VFIODevice *vbasedev)
+{
+    VFIOMigration *migration = vbasedev->migration;
+
+    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
+           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
+}
+
+bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
+{
+    VFIOMigration *migration = vbasedev->migration;
+
+    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
+           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
+}
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -44,6 +44,7 @@
 #include "migration/blocker.h"
 #include "migration/qemu-file.h"
 #include "system/iommufd.h"
+#include "migration.h"
 
 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
 
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 07/32] vfio: Introduce a new header file for VFIOdisplay declarations
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (5 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-20  9:50   ` John Levon
  2025-03-18  9:53 ` [PATCH for-10.1 08/32] vfio: Move VFIOHostDMAWindow definition into spapr.c Cédric Le Goater
                   ` (24 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Gather all VFIOdisplay related declarations into "display.h" to
reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/display.h             | 41 +++++++++++++++++++++++++++++++++++
 hw/vfio/pci.h                 |  1 +
 include/hw/vfio/vfio-common.h | 28 ------------------------
 hw/vfio/display.c             |  2 +-
 4 files changed, 43 insertions(+), 29 deletions(-)
 create mode 100644 hw/vfio/display.h

diff --git a/hw/vfio/display.h b/hw/vfio/display.h
new file mode 100644
index 0000000000000000000000000000000000000000..93a4df2dfa5b39946d700b3df76233f0d7b0343f
--- /dev/null
+++ b/hw/vfio/display.h
@@ -0,0 +1,41 @@
+/*
+ * VFIO display
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_DISPLAY_H
+#define HW_VFIO_DISPLAY_H
+
+#include "ui/console.h"
+#include "hw/display/ramfb.h"
+
+typedef struct VFIODMABuf {
+    QemuDmaBuf *buf;
+    uint32_t pos_x, pos_y, pos_updates;
+    uint32_t hot_x, hot_y, hot_updates;
+    int dmabuf_id;
+    QTAILQ_ENTRY(VFIODMABuf) next;
+} VFIODMABuf;
+
+typedef struct VFIODisplay {
+    QemuConsole *con;
+    RAMFBState *ramfb;
+    struct vfio_region_info *edid_info;
+    struct vfio_region_gfx_edid *edid_regs;
+    uint8_t *edid_blob;
+    QEMUTimer *edid_link_timer;
+    struct {
+        VFIORegion buffer;
+        DisplaySurface *surface;
+    } region;
+    struct {
+        QTAILQ_HEAD(, VFIODMABuf) bufs;
+        VFIODMABuf *primary;
+        VFIODMABuf *cursor;
+    } dmabuf;
+} VFIODisplay;
+
+#endif /* HW_VFIO_DISPLAY_H */
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index d94ecaba689c4681687c0a6796ffbcda522ae179..c84bba81487136d205ca30049c812d00e832c377 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -20,6 +20,7 @@
 #include "qemu/timer.h"
 #include "qom/object.h"
 #include "system/kvm.h"
+#include "display.h"
 
 #define PCI_ANY_ID (~0)
 
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 799e12d43747addbf444c15052f629b65978322f..288c2fb3d0e792427c0e7655002248829b4d189a 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -23,8 +23,6 @@
 
 #include "exec/memory.h"
 #include "qemu/queue.h"
-#include "ui/console.h"
-#include "hw/display/ramfb.h"
 #ifdef CONFIG_LINUX
 #include <linux/vfio.h>
 #endif
@@ -182,32 +180,6 @@ typedef struct VFIOGroup {
 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \
             TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
 
-typedef struct VFIODMABuf {
-    QemuDmaBuf *buf;
-    uint32_t pos_x, pos_y, pos_updates;
-    uint32_t hot_x, hot_y, hot_updates;
-    int dmabuf_id;
-    QTAILQ_ENTRY(VFIODMABuf) next;
-} VFIODMABuf;
-
-typedef struct VFIODisplay {
-    QemuConsole *con;
-    RAMFBState *ramfb;
-    struct vfio_region_info *edid_info;
-    struct vfio_region_gfx_edid *edid_regs;
-    uint8_t *edid_blob;
-    QEMUTimer *edid_link_timer;
-    struct {
-        VFIORegion buffer;
-        DisplaySurface *surface;
-    } region;
-    struct {
-        QTAILQ_HEAD(, VFIODMABuf) bufs;
-        VFIODMABuf *primary;
-        VFIODMABuf *cursor;
-    } dmabuf;
-} VFIODisplay;
-
 VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
 void vfio_put_address_space(VFIOAddressSpace *space);
 void vfio_address_space_insert(VFIOAddressSpace *space,
diff --git a/hw/vfio/display.c b/hw/vfio/display.c
index ea87830fe0d5fc66f3f27a16bde5d75b7b6280c0..2c06361c67cb074b88f2649b3b9fd21b7bacf07c 100644
--- a/hw/vfio/display.c
+++ b/hw/vfio/display.c
@@ -16,9 +16,9 @@
 
 #include "qemu/error-report.h"
 #include "hw/display/edid.h"
-#include "ui/console.h"
 #include "qapi/error.h"
 #include "pci.h"
+#include "display.h"
 #include "trace.h"
 
 #ifndef DRM_PLANE_TYPE_PRIMARY
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 08/32] vfio: Move VFIOHostDMAWindow definition into spapr.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (6 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 07/32] vfio: Introduce a new header file for VFIOdisplay declarations Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-20  9:43   ` John Levon
  2025-03-18  9:53 ` [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations Cédric Le Goater
                   ` (23 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

VFIOHostDMAWindow is only used in file "spapr.c". Move it there.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h | 7 -------
 hw/vfio/spapr.c               | 7 +++++++
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 288c2fb3d0e792427c0e7655002248829b4d189a..3355c2d4e57569d7bb01b4d9378fb49a807335e8 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -69,13 +69,6 @@ typedef struct VFIOContainer {
 
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
 
-typedef struct VFIOHostDMAWindow {
-    hwaddr min_iova;
-    hwaddr max_iova;
-    uint64_t iova_pgsizes;
-    QLIST_ENTRY(VFIOHostDMAWindow) hostwin_next;
-} VFIOHostDMAWindow;
-
 typedef struct IOMMUFDBackend IOMMUFDBackend;
 
 typedef struct VFIOIOASHwpt {
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 1a5d1611f2cdc8fa6254a77b8ec3d1f56d28e3a6..021cdedbfa483f0599ad3c858a77fc6570f1ace8 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -22,6 +22,13 @@
 #include "qapi/error.h"
 #include "trace.h"
 
+typedef struct VFIOHostDMAWindow {
+    hwaddr min_iova;
+    hwaddr max_iova;
+    uint64_t iova_pgsizes;
+    QLIST_ENTRY(VFIOHostDMAWindow) hostwin_next;
+} VFIOHostDMAWindow;
+
 typedef struct VFIOSpaprContainer {
     VFIOContainer container;
     MemoryListener prereg_listener;
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (7 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 08/32] vfio: Move VFIOHostDMAWindow definition into spapr.c Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19  9:09   ` John Levon
  2025-03-20  9:18   ` Duan, Zhenzhong
  2025-03-18  9:53 ` [PATCH for-10.1 10/32] vfio: Introduce new files for VFIORegion definitions and declarations Cédric Le Goater
                   ` (22 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Gather all VFIOIOMMUFD related declarations into "iommufd.h" to
reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/iommufd.h             | 29 +++++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h | 21 +++------------------
 hw/vfio/iommufd.c             |  1 +
 3 files changed, 33 insertions(+), 18 deletions(-)
 create mode 100644 hw/vfio/iommufd.h

diff --git a/hw/vfio/iommufd.h b/hw/vfio/iommufd.h
new file mode 100644
index 0000000000000000000000000000000000000000..7d87994c4fadbc328b6ac7f9aee00469dd8808b0
--- /dev/null
+++ b/hw/vfio/iommufd.h
@@ -0,0 +1,29 @@
+/*
+ * VFIO iommufd
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_IOMMUFD_H
+#define HW_VFIO_IOMMUFD_H
+
+
+typedef struct VFIOIOASHwpt {
+    uint32_t hwpt_id;
+    uint32_t hwpt_flags;
+    QLIST_HEAD(, VFIODevice) device_list;
+    QLIST_ENTRY(VFIOIOASHwpt) next;
+} VFIOIOASHwpt;
+
+typedef struct VFIOIOMMUFDContainer {
+    VFIOContainerBase bcontainer;
+    IOMMUFDBackend *be;
+    uint32_t ioas_id;
+    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
+} VFIOIOMMUFDContainer;
+
+OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD);
+
+#endif /* HW_VFIO_IOMMUFD_H */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 3355c2d4e57569d7bb01b4d9378fb49a807335e8..8d48f5300a791d8858fe29d1bb905f814ef11990 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -69,27 +69,12 @@ typedef struct VFIOContainer {
 
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
 
-typedef struct IOMMUFDBackend IOMMUFDBackend;
-
-typedef struct VFIOIOASHwpt {
-    uint32_t hwpt_id;
-    uint32_t hwpt_flags;
-    QLIST_HEAD(, VFIODevice) device_list;
-    QLIST_ENTRY(VFIOIOASHwpt) next;
-} VFIOIOASHwpt;
-
-typedef struct VFIOIOMMUFDContainer {
-    VFIOContainerBase bcontainer;
-    IOMMUFDBackend *be;
-    uint32_t ioas_id;
-    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
-} VFIOIOMMUFDContainer;
-
-OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD);
-
 typedef struct VFIODeviceOps VFIODeviceOps;
 typedef struct VFIOMigration VFIOMigration;
 
+typedef struct IOMMUFDBackend IOMMUFDBackend;
+typedef struct VFIOIOASHwpt VFIOIOASHwpt;
+
 typedef struct VFIODevice {
     QLIST_ENTRY(VFIODevice) next;
     QLIST_ENTRY(VFIODevice) container_next;
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0..a219b6453037e2d4e0d12800ea25678885af98f8 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -26,6 +26,7 @@
 #include "qemu/chardev_open.h"
 #include "pci.h"
 #include "migration.h"
+#include "iommufd.h"
 
 static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                             ram_addr_t size, void *vaddr, bool readonly)
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 10/32] vfio: Introduce new files for VFIORegion definitions and declarations
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (8 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 16:54   ` John Levon
  2025-03-18  9:53 ` [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations Cédric Le Goater
                   ` (21 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Gather all VFIORegion related declarations and definitions into their
own files to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".

These declarations are made available externally (for "sysbus-fdt.c").
This is for 'vfio-platform' devices which have been deprecated and
will be removed in QEMU 10.2.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/display.h               |   1 +
 include/hw/vfio/vfio-common.h   |  32 +--
 include/hw/vfio/vfio-platform.h |   2 +
 include/hw/vfio/vfio-region.h   |  47 ++++
 hw/core/sysbus-fdt.c            |   1 +
 hw/vfio/helpers.c               | 363 -----------------------------
 hw/vfio/pci-quirks.c            |   1 +
 hw/vfio/pci.c                   |   1 +
 hw/vfio/platform.c              |   1 +
 hw/vfio/region.c                | 395 ++++++++++++++++++++++++++++++++
 hw/vfio/meson.build             |   1 +
 hw/vfio/trace-events            |  16 +-
 12 files changed, 460 insertions(+), 401 deletions(-)
 create mode 100644 include/hw/vfio/vfio-region.h
 create mode 100644 hw/vfio/region.c

diff --git a/hw/vfio/display.h b/hw/vfio/display.h
index 93a4df2dfa5b39946d700b3df76233f0d7b0343f..34c2b3a6b797ee25d2f3d89ed78293ed2430ad94 100644
--- a/hw/vfio/display.h
+++ b/hw/vfio/display.h
@@ -11,6 +11,7 @@
 
 #include "ui/console.h"
 #include "hw/display/ramfb.h"
+#include "hw/vfio/vfio-region.h"
 
 typedef struct VFIODMABuf {
     QemuDmaBuf *buf;
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 8d48f5300a791d8858fe29d1bb905f814ef11990..3d470d79325526e0508683c445a7635c78a57e34 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -39,25 +39,6 @@ enum {
     VFIO_DEVICE_TYPE_CCW = 2,
     VFIO_DEVICE_TYPE_AP = 3,
 };
-
-typedef struct VFIOMmap {
-    MemoryRegion mem;
-    void *mmap;
-    off_t offset;
-    size_t size;
-} VFIOMmap;
-
-typedef struct VFIORegion {
-    struct VFIODevice *vbasedev;
-    off_t fd_offset; /* offset of region within device fd */
-    MemoryRegion *mem; /* slow, read/write access */
-    size_t size;
-    uint32_t flags; /* VFIO region flags (rd/wr/mmap) */
-    uint32_t nr_mmaps;
-    VFIOMmap *mmaps;
-    uint8_t nr; /* cache the region number for debug */
-} VFIORegion;
-
 struct VFIOGroup;
 
 typedef struct VFIOContainer {
@@ -168,17 +149,7 @@ void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index);
 void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index);
 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,
-                          hwaddr addr, unsigned size);
-int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
-                      int index, const char *name);
-int vfio_region_mmap(VFIORegion *region);
-void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled);
-void vfio_region_unmap(VFIORegion *region);
-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);
 bool vfio_device_is_mdev(VFIODevice *vbasedev);
@@ -194,7 +165,6 @@ int vfio_kvm_device_del_fd(int fd, Error **errp);
 bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp);
 void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer);
 
-extern const MemoryRegionOps vfio_region_ops;
 typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;
 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
 extern VFIOGroupList vfio_group_list;
diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h
index c414c3dffcc840a2f40a1b252d0f7b4e309c78d4..3191545717da51abc41d10cd3646cd047b4a676c 100644
--- a/include/hw/vfio/vfio-platform.h
+++ b/include/hw/vfio/vfio-platform.h
@@ -47,6 +47,8 @@ typedef struct VFIOINTp {
 /* function type for user side eventfd handler */
 typedef void (*eventfd_user_side_handler_t)(VFIOINTp *intp);
 
+typedef struct VFIORegion VFIORegion;
+
 struct VFIOPlatformDevice {
     SysBusDevice sbdev;
     VFIODevice vbasedev; /* not a QOM object */
diff --git a/include/hw/vfio/vfio-region.h b/include/hw/vfio/vfio-region.h
new file mode 100644
index 0000000000000000000000000000000000000000..80600b78f9bf58562761f40dfc8b2b22c6d7a8b2
--- /dev/null
+++ b/include/hw/vfio/vfio-region.h
@@ -0,0 +1,47 @@
+/*
+ * VFIO region
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_REGION_H
+#define HW_VFIO_REGION_H
+
+#include "exec/memory.h"
+
+typedef struct VFIODevice VFIODevice;
+
+typedef struct VFIOMmap {
+    MemoryRegion mem;
+    void *mmap;
+    off_t offset;
+    size_t size;
+} VFIOMmap;
+
+typedef struct VFIORegion {
+    struct VFIODevice *vbasedev;
+    off_t fd_offset; /* offset of region within device fd */
+    MemoryRegion *mem; /* slow, read/write access */
+    size_t size;
+    uint32_t flags; /* VFIO region flags (rd/wr/mmap) */
+    uint32_t nr_mmaps;
+    VFIOMmap *mmaps;
+    uint8_t nr; /* cache the region number for debug */
+} VFIORegion;
+
+
+void vfio_region_write(void *opaque, hwaddr addr,
+                           uint64_t data, unsigned size);
+uint64_t vfio_region_read(void *opaque,
+                          hwaddr addr, unsigned size);
+int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
+                      int index, const char *name);
+int vfio_region_mmap(VFIORegion *region);
+void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled);
+void vfio_region_unmap(VFIORegion *region);
+void vfio_region_exit(VFIORegion *region);
+void vfio_region_finalize(VFIORegion *region);
+
+#endif /* HW_VFIO_REGION_H */
diff --git a/hw/core/sysbus-fdt.c b/hw/core/sysbus-fdt.c
index e85066b905637b1ca34b5965f383df341f3a4eb7..c339a27875cbee8131b064674aa09adf4b9efa25 100644
--- a/hw/core/sysbus-fdt.c
+++ b/hw/core/sysbus-fdt.c
@@ -35,6 +35,7 @@
 #include "hw/vfio/vfio-platform.h"
 #include "hw/vfio/vfio-calxeda-xgmac.h"
 #include "hw/vfio/vfio-amd-xgbe.h"
+#include "hw/vfio/vfio-region.h"
 #include "hw/display/ramfb.h"
 #include "hw/uefi/var-service-api.h"
 #include "hw/arm/fdt.h"
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index 4b255d4f3a9e81f55df00c68fc71da769fd5bd04..89403943a7a219e491b6812d50b27b7f1fd7b4a4 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -147,118 +147,6 @@ bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
     return false;
 }
 
-/*
- * IO Port/MMIO - Beware of the endians, VFIO is always little endian
- */
-void vfio_region_write(void *opaque, hwaddr addr,
-                       uint64_t data, unsigned size)
-{
-    VFIORegion *region = opaque;
-    VFIODevice *vbasedev = region->vbasedev;
-    union {
-        uint8_t byte;
-        uint16_t word;
-        uint32_t dword;
-        uint64_t qword;
-    } buf;
-
-    switch (size) {
-    case 1:
-        buf.byte = data;
-        break;
-    case 2:
-        buf.word = cpu_to_le16(data);
-        break;
-    case 4:
-        buf.dword = cpu_to_le32(data);
-        break;
-    case 8:
-        buf.qword = cpu_to_le64(data);
-        break;
-    default:
-        hw_error("vfio: unsupported write size, %u bytes", size);
-        break;
-    }
-
-    if (pwrite(vbasedev->fd, &buf, size, region->fd_offset + addr) != size) {
-        error_report("%s(%s:region%d+0x%"HWADDR_PRIx", 0x%"PRIx64
-                     ",%d) failed: %m",
-                     __func__, vbasedev->name, region->nr,
-                     addr, data, size);
-    }
-
-    trace_vfio_region_write(vbasedev->name, region->nr, addr, data, size);
-
-    /*
-     * A read or write to a BAR always signals an INTx EOI.  This will
-     * do nothing if not pending (including not in INTx mode).  We assume
-     * that a BAR access is in response to an interrupt and that BAR
-     * accesses will service the interrupt.  Unfortunately, we don't know
-     * which access will service the interrupt, so we're potentially
-     * getting quite a few host interrupts per guest interrupt.
-     */
-    vbasedev->ops->vfio_eoi(vbasedev);
-}
-
-uint64_t vfio_region_read(void *opaque,
-                          hwaddr addr, unsigned size)
-{
-    VFIORegion *region = opaque;
-    VFIODevice *vbasedev = region->vbasedev;
-    union {
-        uint8_t byte;
-        uint16_t word;
-        uint32_t dword;
-        uint64_t qword;
-    } buf;
-    uint64_t data = 0;
-
-    if (pread(vbasedev->fd, &buf, size, region->fd_offset + addr) != size) {
-        error_report("%s(%s:region%d+0x%"HWADDR_PRIx", %d) failed: %m",
-                     __func__, vbasedev->name, region->nr,
-                     addr, size);
-        return (uint64_t)-1;
-    }
-    switch (size) {
-    case 1:
-        data = buf.byte;
-        break;
-    case 2:
-        data = le16_to_cpu(buf.word);
-        break;
-    case 4:
-        data = le32_to_cpu(buf.dword);
-        break;
-    case 8:
-        data = le64_to_cpu(buf.qword);
-        break;
-    default:
-        hw_error("vfio: unsupported read size, %u bytes", size);
-        break;
-    }
-
-    trace_vfio_region_read(vbasedev->name, region->nr, addr, size, data);
-
-    /* Same as write above */
-    vbasedev->ops->vfio_eoi(vbasedev);
-
-    return data;
-}
-
-const MemoryRegionOps vfio_region_ops = {
-    .read = vfio_region_read,
-    .write = vfio_region_write,
-    .endianness = DEVICE_LITTLE_ENDIAN,
-    .valid = {
-        .min_access_size = 1,
-        .max_access_size = 8,
-    },
-    .impl = {
-        .min_access_size = 1,
-        .max_access_size = 8,
-    },
-};
-
 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size)
 {
     vbmap->pages = REAL_HOST_PAGE_ALIGN(size) / qemu_real_host_page_size();
@@ -306,257 +194,6 @@ vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id)
     return vfio_get_cap((void *)info, info->cap_offset, id);
 }
 
-static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
-                                          struct vfio_region_info *info)
-{
-    struct vfio_info_cap_header *hdr;
-    struct vfio_region_info_cap_sparse_mmap *sparse;
-    int i, j;
-
-    hdr = vfio_get_region_info_cap(info, VFIO_REGION_INFO_CAP_SPARSE_MMAP);
-    if (!hdr) {
-        return -ENODEV;
-    }
-
-    sparse = container_of(hdr, struct vfio_region_info_cap_sparse_mmap, header);
-
-    trace_vfio_region_sparse_mmap_header(region->vbasedev->name,
-                                         region->nr, sparse->nr_areas);
-
-    region->mmaps = g_new0(VFIOMmap, sparse->nr_areas);
-
-    for (i = 0, j = 0; i < sparse->nr_areas; i++) {
-        if (sparse->areas[i].size) {
-            trace_vfio_region_sparse_mmap_entry(i, sparse->areas[i].offset,
-                                            sparse->areas[i].offset +
-                                            sparse->areas[i].size - 1);
-            region->mmaps[j].offset = sparse->areas[i].offset;
-            region->mmaps[j].size = sparse->areas[i].size;
-            j++;
-        }
-    }
-
-    region->nr_mmaps = j;
-    region->mmaps = g_realloc(region->mmaps, j * sizeof(VFIOMmap));
-
-    return 0;
-}
-
-int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
-                      int index, const char *name)
-{
-    g_autofree struct vfio_region_info *info = NULL;
-    int ret;
-
-    ret = vfio_get_region_info(vbasedev, index, &info);
-    if (ret) {
-        return ret;
-    }
-
-    region->vbasedev = vbasedev;
-    region->flags = info->flags;
-    region->size = info->size;
-    region->fd_offset = info->offset;
-    region->nr = index;
-
-    if (region->size) {
-        region->mem = g_new0(MemoryRegion, 1);
-        memory_region_init_io(region->mem, obj, &vfio_region_ops,
-                              region, name, region->size);
-
-        if (!vbasedev->no_mmap &&
-            region->flags & VFIO_REGION_INFO_FLAG_MMAP) {
-
-            ret = vfio_setup_region_sparse_mmaps(region, info);
-
-            if (ret) {
-                region->nr_mmaps = 1;
-                region->mmaps = g_new0(VFIOMmap, region->nr_mmaps);
-                region->mmaps[0].offset = 0;
-                region->mmaps[0].size = region->size;
-            }
-        }
-    }
-
-    trace_vfio_region_setup(vbasedev->name, index, name,
-                            region->flags, region->fd_offset, region->size);
-    return 0;
-}
-
-static void vfio_subregion_unmap(VFIORegion *region, int index)
-{
-    trace_vfio_region_unmap(memory_region_name(&region->mmaps[index].mem),
-                            region->mmaps[index].offset,
-                            region->mmaps[index].offset +
-                            region->mmaps[index].size - 1);
-    memory_region_del_subregion(region->mem, &region->mmaps[index].mem);
-    munmap(region->mmaps[index].mmap, region->mmaps[index].size);
-    object_unparent(OBJECT(&region->mmaps[index].mem));
-    region->mmaps[index].mmap = NULL;
-}
-
-int vfio_region_mmap(VFIORegion *region)
-{
-    int i, ret, prot = 0;
-    char *name;
-
-    if (!region->mem) {
-        return 0;
-    }
-
-    prot |= region->flags & VFIO_REGION_INFO_FLAG_READ ? PROT_READ : 0;
-    prot |= region->flags & VFIO_REGION_INFO_FLAG_WRITE ? PROT_WRITE : 0;
-
-    for (i = 0; i < region->nr_mmaps; i++) {
-        size_t align = MIN(1ULL << ctz64(region->mmaps[i].size), 1 * GiB);
-        void *map_base, *map_align;
-
-        /*
-         * Align the mmap for more efficient mapping in the kernel.  Ideally
-         * we'd know the PMD and PUD mapping sizes to use as discrete alignment
-         * intervals, but we don't.  As of Linux v6.12, the largest PUD size
-         * supporting huge pfnmap is 1GiB (ARCH_SUPPORTS_PUD_PFNMAP is only set
-         * on x86_64).  Align by power-of-two size, capped at 1GiB.
-         *
-         * NB. qemu_memalign() and friends actually allocate memory, whereas
-         * the region size here can exceed host memory, therefore we manually
-         * create an oversized anonymous mapping and clean it up for alignment.
-         */
-        map_base = mmap(0, region->mmaps[i].size + align, PROT_NONE,
-                        MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-        if (map_base == MAP_FAILED) {
-            ret = -errno;
-            goto no_mmap;
-        }
-
-        map_align = (void *)ROUND_UP((uintptr_t)map_base, (uintptr_t)align);
-        munmap(map_base, map_align - map_base);
-        munmap(map_align + region->mmaps[i].size,
-               align - (map_align - map_base));
-
-        region->mmaps[i].mmap = mmap(map_align, region->mmaps[i].size, prot,
-                                     MAP_SHARED | MAP_FIXED,
-                                     region->vbasedev->fd,
-                                     region->fd_offset +
-                                     region->mmaps[i].offset);
-        if (region->mmaps[i].mmap == MAP_FAILED) {
-            ret = -errno;
-            goto no_mmap;
-        }
-
-        name = g_strdup_printf("%s mmaps[%d]",
-                               memory_region_name(region->mem), i);
-        memory_region_init_ram_device_ptr(&region->mmaps[i].mem,
-                                          memory_region_owner(region->mem),
-                                          name, region->mmaps[i].size,
-                                          region->mmaps[i].mmap);
-        g_free(name);
-        memory_region_add_subregion(region->mem, region->mmaps[i].offset,
-                                    &region->mmaps[i].mem);
-
-        trace_vfio_region_mmap(memory_region_name(&region->mmaps[i].mem),
-                               region->mmaps[i].offset,
-                               region->mmaps[i].offset +
-                               region->mmaps[i].size - 1);
-    }
-
-    return 0;
-
-no_mmap:
-    trace_vfio_region_mmap_fault(memory_region_name(region->mem), i,
-                                 region->fd_offset + region->mmaps[i].offset,
-                                 region->fd_offset + region->mmaps[i].offset +
-                                 region->mmaps[i].size - 1, ret);
-
-    region->mmaps[i].mmap = NULL;
-
-    for (i--; i >= 0; i--) {
-        vfio_subregion_unmap(region, i);
-    }
-
-    return ret;
-}
-
-void vfio_region_unmap(VFIORegion *region)
-{
-    int i;
-
-    if (!region->mem) {
-        return;
-    }
-
-    for (i = 0; i < region->nr_mmaps; i++) {
-        if (region->mmaps[i].mmap) {
-            vfio_subregion_unmap(region, i);
-        }
-    }
-}
-
-void vfio_region_exit(VFIORegion *region)
-{
-    int i;
-
-    if (!region->mem) {
-        return;
-    }
-
-    for (i = 0; i < region->nr_mmaps; i++) {
-        if (region->mmaps[i].mmap) {
-            memory_region_del_subregion(region->mem, &region->mmaps[i].mem);
-        }
-    }
-
-    trace_vfio_region_exit(region->vbasedev->name, region->nr);
-}
-
-void vfio_region_finalize(VFIORegion *region)
-{
-    int i;
-
-    if (!region->mem) {
-        return;
-    }
-
-    for (i = 0; i < region->nr_mmaps; i++) {
-        if (region->mmaps[i].mmap) {
-            munmap(region->mmaps[i].mmap, region->mmaps[i].size);
-            object_unparent(OBJECT(&region->mmaps[i].mem));
-        }
-    }
-
-    object_unparent(OBJECT(region->mem));
-
-    g_free(region->mem);
-    g_free(region->mmaps);
-
-    trace_vfio_region_finalize(region->vbasedev->name, region->nr);
-
-    region->mem = NULL;
-    region->mmaps = NULL;
-    region->nr_mmaps = 0;
-    region->size = 0;
-    region->flags = 0;
-    region->nr = 0;
-}
-
-void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled)
-{
-    int i;
-
-    if (!region->mem) {
-        return;
-    }
-
-    for (i = 0; i < region->nr_mmaps; i++) {
-        if (region->mmaps[i].mmap) {
-            memory_region_set_enabled(&region->mmaps[i].mem, enabled);
-        }
-    }
-
-    trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem),
-                                        enabled);
-}
-
 int vfio_get_region_info(VFIODevice *vbasedev, int index,
                          struct vfio_region_info **info)
 {
diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index 3f002252acfb7ac809107c99bdbdbaf66d56a50d..4591ec68da877b307f43ea1a830c315721b57e9e 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -26,6 +26,7 @@
 #include "hw/qdev-properties.h"
 #include "pci.h"
 #include "pci-quirks.h"
+#include "hw/vfio/vfio-region.h"
 #include "trace.h"
 
 /*
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 3612f6fe7d0864fe3789f4ea221da01ef87d0664..6bf5a4dc720f717b2593b1b272927a13f2932d27 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -45,6 +45,7 @@
 #include "migration/qemu-file.h"
 #include "system/iommufd.h"
 #include "migration.h"
+#include "hw/vfio/vfio-region.h"
 
 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
 
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 67bc57409c1f5a6978690c3dc07d249ea0248aa0..83b53d57149a343a00eb6d6f78c1cbea004dbaa2 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -37,6 +37,7 @@
 #include "hw/platform-bus.h"
 #include "hw/qdev-properties.h"
 #include "system/kvm.h"
+#include "hw/vfio/vfio-region.h"
 
 /*
  * Functions used whatever the injection method
diff --git a/hw/vfio/region.c b/hw/vfio/region.c
new file mode 100644
index 0000000000000000000000000000000000000000..3e174c3dcb0b699fd0cee00d104250d8ae97f698
--- /dev/null
+++ b/hw/vfio/region.c
@@ -0,0 +1,395 @@
+/*
+ * low level and IOMMU backend agnostic helpers used by VFIO devices,
+ * related to regions, interrupts, capabilities
+ *
+ * Copyright Red Hat, Inc. 2012
+ *
+ * Authors:
+ *  Alex Williamson <alex.williamson@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Based on qemu-kvm device-assignment:
+ *  Adapted for KVM by Qumranet.
+ *  Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com)
+ *  Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com)
+ *  Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com)
+ *  Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com)
+ *  Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com)
+ */
+
+#include "qemu/osdep.h"
+#include <sys/ioctl.h>
+
+#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/pci.h"
+#include "hw/hw.h"
+#include "trace.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "qemu/units.h"
+#include "monitor/monitor.h"
+
+/*
+ * IO Port/MMIO - Beware of the endians, VFIO is always little endian
+ */
+void vfio_region_write(void *opaque, hwaddr addr,
+                       uint64_t data, unsigned size)
+{
+    VFIORegion *region = opaque;
+    VFIODevice *vbasedev = region->vbasedev;
+    union {
+        uint8_t byte;
+        uint16_t word;
+        uint32_t dword;
+        uint64_t qword;
+    } buf;
+
+    switch (size) {
+    case 1:
+        buf.byte = data;
+        break;
+    case 2:
+        buf.word = cpu_to_le16(data);
+        break;
+    case 4:
+        buf.dword = cpu_to_le32(data);
+        break;
+    case 8:
+        buf.qword = cpu_to_le64(data);
+        break;
+    default:
+        hw_error("vfio: unsupported write size, %u bytes", size);
+        break;
+    }
+
+    if (pwrite(vbasedev->fd, &buf, size, region->fd_offset + addr) != size) {
+        error_report("%s(%s:region%d+0x%"HWADDR_PRIx", 0x%"PRIx64
+                     ",%d) failed: %m",
+                     __func__, vbasedev->name, region->nr,
+                     addr, data, size);
+    }
+
+    trace_vfio_region_write(vbasedev->name, region->nr, addr, data, size);
+
+    /*
+     * A read or write to a BAR always signals an INTx EOI.  This will
+     * do nothing if not pending (including not in INTx mode).  We assume
+     * that a BAR access is in response to an interrupt and that BAR
+     * accesses will service the interrupt.  Unfortunately, we don't know
+     * which access will service the interrupt, so we're potentially
+     * getting quite a few host interrupts per guest interrupt.
+     */
+    vbasedev->ops->vfio_eoi(vbasedev);
+}
+
+uint64_t vfio_region_read(void *opaque,
+                          hwaddr addr, unsigned size)
+{
+    VFIORegion *region = opaque;
+    VFIODevice *vbasedev = region->vbasedev;
+    union {
+        uint8_t byte;
+        uint16_t word;
+        uint32_t dword;
+        uint64_t qword;
+    } buf;
+    uint64_t data = 0;
+
+    if (pread(vbasedev->fd, &buf, size, region->fd_offset + addr) != size) {
+        error_report("%s(%s:region%d+0x%"HWADDR_PRIx", %d) failed: %m",
+                     __func__, vbasedev->name, region->nr,
+                     addr, size);
+        return (uint64_t)-1;
+    }
+    switch (size) {
+    case 1:
+        data = buf.byte;
+        break;
+    case 2:
+        data = le16_to_cpu(buf.word);
+        break;
+    case 4:
+        data = le32_to_cpu(buf.dword);
+        break;
+    case 8:
+        data = le64_to_cpu(buf.qword);
+        break;
+    default:
+        hw_error("vfio: unsupported read size, %u bytes", size);
+        break;
+    }
+
+    trace_vfio_region_read(vbasedev->name, region->nr, addr, size, data);
+
+    /* Same as write above */
+    vbasedev->ops->vfio_eoi(vbasedev);
+
+    return data;
+}
+
+static const MemoryRegionOps vfio_region_ops = {
+    .read = vfio_region_read,
+    .write = vfio_region_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 8,
+    },
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 8,
+    },
+};
+
+static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
+                                          struct vfio_region_info *info)
+{
+    struct vfio_info_cap_header *hdr;
+    struct vfio_region_info_cap_sparse_mmap *sparse;
+    int i, j;
+
+    hdr = vfio_get_region_info_cap(info, VFIO_REGION_INFO_CAP_SPARSE_MMAP);
+    if (!hdr) {
+        return -ENODEV;
+    }
+
+    sparse = container_of(hdr, struct vfio_region_info_cap_sparse_mmap, header);
+
+    trace_vfio_region_sparse_mmap_header(region->vbasedev->name,
+                                         region->nr, sparse->nr_areas);
+
+    region->mmaps = g_new0(VFIOMmap, sparse->nr_areas);
+
+    for (i = 0, j = 0; i < sparse->nr_areas; i++) {
+        if (sparse->areas[i].size) {
+            trace_vfio_region_sparse_mmap_entry(i, sparse->areas[i].offset,
+                                            sparse->areas[i].offset +
+                                            sparse->areas[i].size - 1);
+            region->mmaps[j].offset = sparse->areas[i].offset;
+            region->mmaps[j].size = sparse->areas[i].size;
+            j++;
+        }
+    }
+
+    region->nr_mmaps = j;
+    region->mmaps = g_realloc(region->mmaps, j * sizeof(VFIOMmap));
+
+    return 0;
+}
+
+int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
+                      int index, const char *name)
+{
+    g_autofree struct vfio_region_info *info = NULL;
+    int ret;
+
+    ret = vfio_get_region_info(vbasedev, index, &info);
+    if (ret) {
+        return ret;
+    }
+
+    region->vbasedev = vbasedev;
+    region->flags = info->flags;
+    region->size = info->size;
+    region->fd_offset = info->offset;
+    region->nr = index;
+
+    if (region->size) {
+        region->mem = g_new0(MemoryRegion, 1);
+        memory_region_init_io(region->mem, obj, &vfio_region_ops,
+                              region, name, region->size);
+
+        if (!vbasedev->no_mmap &&
+            region->flags & VFIO_REGION_INFO_FLAG_MMAP) {
+
+            ret = vfio_setup_region_sparse_mmaps(region, info);
+
+            if (ret) {
+                region->nr_mmaps = 1;
+                region->mmaps = g_new0(VFIOMmap, region->nr_mmaps);
+                region->mmaps[0].offset = 0;
+                region->mmaps[0].size = region->size;
+            }
+        }
+    }
+
+    trace_vfio_region_setup(vbasedev->name, index, name,
+                            region->flags, region->fd_offset, region->size);
+    return 0;
+}
+
+static void vfio_subregion_unmap(VFIORegion *region, int index)
+{
+    trace_vfio_region_unmap(memory_region_name(&region->mmaps[index].mem),
+                            region->mmaps[index].offset,
+                            region->mmaps[index].offset +
+                            region->mmaps[index].size - 1);
+    memory_region_del_subregion(region->mem, &region->mmaps[index].mem);
+    munmap(region->mmaps[index].mmap, region->mmaps[index].size);
+    object_unparent(OBJECT(&region->mmaps[index].mem));
+    region->mmaps[index].mmap = NULL;
+}
+
+int vfio_region_mmap(VFIORegion *region)
+{
+    int i, ret, prot = 0;
+    char *name;
+
+    if (!region->mem) {
+        return 0;
+    }
+
+    prot |= region->flags & VFIO_REGION_INFO_FLAG_READ ? PROT_READ : 0;
+    prot |= region->flags & VFIO_REGION_INFO_FLAG_WRITE ? PROT_WRITE : 0;
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        size_t align = MIN(1ULL << ctz64(region->mmaps[i].size), 1 * GiB);
+        void *map_base, *map_align;
+
+        /*
+         * Align the mmap for more efficient mapping in the kernel.  Ideally
+         * we'd know the PMD and PUD mapping sizes to use as discrete alignment
+         * intervals, but we don't.  As of Linux v6.12, the largest PUD size
+         * supporting huge pfnmap is 1GiB (ARCH_SUPPORTS_PUD_PFNMAP is only set
+         * on x86_64).  Align by power-of-two size, capped at 1GiB.
+         *
+         * NB. qemu_memalign() and friends actually allocate memory, whereas
+         * the region size here can exceed host memory, therefore we manually
+         * create an oversized anonymous mapping and clean it up for alignment.
+         */
+        map_base = mmap(0, region->mmaps[i].size + align, PROT_NONE,
+                        MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+        if (map_base == MAP_FAILED) {
+            ret = -errno;
+            goto no_mmap;
+        }
+
+        map_align = (void *)ROUND_UP((uintptr_t)map_base, (uintptr_t)align);
+        munmap(map_base, map_align - map_base);
+        munmap(map_align + region->mmaps[i].size,
+               align - (map_align - map_base));
+
+        region->mmaps[i].mmap = mmap(map_align, region->mmaps[i].size, prot,
+                                     MAP_SHARED | MAP_FIXED,
+                                     region->vbasedev->fd,
+                                     region->fd_offset +
+                                     region->mmaps[i].offset);
+        if (region->mmaps[i].mmap == MAP_FAILED) {
+            ret = -errno;
+            goto no_mmap;
+        }
+
+        name = g_strdup_printf("%s mmaps[%d]",
+                               memory_region_name(region->mem), i);
+        memory_region_init_ram_device_ptr(&region->mmaps[i].mem,
+                                          memory_region_owner(region->mem),
+                                          name, region->mmaps[i].size,
+                                          region->mmaps[i].mmap);
+        g_free(name);
+        memory_region_add_subregion(region->mem, region->mmaps[i].offset,
+                                    &region->mmaps[i].mem);
+
+        trace_vfio_region_mmap(memory_region_name(&region->mmaps[i].mem),
+                               region->mmaps[i].offset,
+                               region->mmaps[i].offset +
+                               region->mmaps[i].size - 1);
+    }
+
+    return 0;
+
+no_mmap:
+    trace_vfio_region_mmap_fault(memory_region_name(region->mem), i,
+                                 region->fd_offset + region->mmaps[i].offset,
+                                 region->fd_offset + region->mmaps[i].offset +
+                                 region->mmaps[i].size - 1, ret);
+
+    region->mmaps[i].mmap = NULL;
+
+    for (i--; i >= 0; i--) {
+        vfio_subregion_unmap(region, i);
+    }
+
+    return ret;
+}
+
+void vfio_region_unmap(VFIORegion *region)
+{
+    int i;
+
+    if (!region->mem) {
+        return;
+    }
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        if (region->mmaps[i].mmap) {
+            vfio_subregion_unmap(region, i);
+        }
+    }
+}
+
+void vfio_region_exit(VFIORegion *region)
+{
+    int i;
+
+    if (!region->mem) {
+        return;
+    }
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        if (region->mmaps[i].mmap) {
+            memory_region_del_subregion(region->mem, &region->mmaps[i].mem);
+        }
+    }
+
+    trace_vfio_region_exit(region->vbasedev->name, region->nr);
+}
+
+void vfio_region_finalize(VFIORegion *region)
+{
+    int i;
+
+    if (!region->mem) {
+        return;
+    }
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        if (region->mmaps[i].mmap) {
+            munmap(region->mmaps[i].mmap, region->mmaps[i].size);
+            object_unparent(OBJECT(&region->mmaps[i].mem));
+        }
+    }
+
+    object_unparent(OBJECT(region->mem));
+
+    g_free(region->mem);
+    g_free(region->mmaps);
+
+    trace_vfio_region_finalize(region->vbasedev->name, region->nr);
+
+    region->mem = NULL;
+    region->mmaps = NULL;
+    region->nr_mmaps = 0;
+    region->size = 0;
+    region->flags = 0;
+    region->nr = 0;
+}
+
+void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled)
+{
+    int i;
+
+    if (!region->mem) {
+        return;
+    }
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        if (region->mmaps[i].mmap) {
+            memory_region_set_enabled(&region->mmaps[i].mem, enabled);
+        }
+    }
+
+    trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem),
+                                        enabled);
+}
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index a8939c838657b09c38f93ad69d541df5aea30a6f..07010c7c9e01a39ae3449c54d2027a2cdd0a7a4d 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -23,6 +23,7 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
   'migration.c',
   'migration-multifd.c',
   'cpr.c',
+  'region.c',
 ))
 system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
   'iommufd.c',
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index 9347e3a5f6607ec6907f9b426da9ab90553292cf..81f4130100c48012c15b5b4858446149a7eaf5b6 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -90,8 +90,6 @@ vfio_pci_igd_host_bridge_enabled(const char *name) "%s"
 vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s"
 
 # common.c
-vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
-vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
 vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_end) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64
 vfio_listener_region_skip(const char *name, uint64_t start, uint64_t end) "SKIPPING %s 0x%"PRIx64" - 0x%"PRIx64
 vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to liobn fd %d"
@@ -107,6 +105,15 @@ vfio_disconnect_container(int fd) "close container->fd=%d"
 vfio_put_group(int fd) "close group->fd=%d"
 vfio_get_device(const char * name, unsigned int flags, unsigned int num_regions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u"
 vfio_put_base_device(int fd) "close vdev->fd=%d"
+vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%08x"
+vfio_legacy_dma_unmap_overflow_workaround(void) ""
+vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
+vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
+vfio_reset_handler(void) ""
+
+# region.c
+vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
+vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
 vfio_region_setup(const char *dev, int index, const char *name, unsigned long flags, unsigned long offset, unsigned long size) "Device %s, region %d \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx"
 vfio_region_mmap_fault(const char *name, int index, unsigned long offset, unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault: %d"
 vfio_region_mmap(const char *name, unsigned long offset, unsigned long end) "Region %s [0x%lx - 0x%lx]"
@@ -116,11 +123,6 @@ vfio_region_mmaps_set_enabled(const char *name, bool enabled) "Region %s mmaps e
 vfio_region_unmap(const char *name, unsigned long offset, unsigned long end) "Region %s unmap [0x%lx - 0x%lx]"
 vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Device %s region %d: %d sparse mmap entries"
 vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end) "sparse entry %d [0x%lx - 0x%lx]"
-vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%08x"
-vfio_legacy_dma_unmap_overflow_workaround(void) ""
-vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
-vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
-vfio_reset_handler(void) ""
 
 # platform.c
 vfio_platform_realize(char *name, char *compat) "vfio device %s, compat = %s"
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (9 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 10/32] vfio: Introduce new files for VFIORegion definitions and declarations Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 17:00   ` John Levon
  2025-03-20  9:24   ` Duan, Zhenzhong
  2025-03-18  9:53 ` [PATCH for-10.1 12/32] vfio: Make vfio_group_list static Cédric Le Goater
                   ` (20 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Gather all VFIOcontainer related declarations into "container.h" to
reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".

These declarations are made available externally for PPC and s390x.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h    | 19 -----------------
 include/hw/vfio/vfio-container.h | 35 ++++++++++++++++++++++++++++++++
 hw/ppc/spapr_pci_vfio.c          |  1 +
 hw/s390x/s390-pci-vfio.c         |  2 +-
 hw/vfio/container.c              |  1 +
 hw/vfio/spapr.c                  |  1 +
 6 files changed, 39 insertions(+), 20 deletions(-)
 create mode 100644 include/hw/vfio/vfio-container.h

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 3d470d79325526e0508683c445a7635c78a57e34..aebce091088f5027c31c7782a1683e763bd766ec 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -39,16 +39,6 @@ enum {
     VFIO_DEVICE_TYPE_CCW = 2,
     VFIO_DEVICE_TYPE_AP = 3,
 };
-struct VFIOGroup;
-
-typedef struct VFIOContainer {
-    VFIOContainerBase bcontainer;
-    int fd; /* /dev/vfio/vfio, empowered by the attached groups */
-    unsigned iommu_type;
-    QLIST_HEAD(, VFIOGroup) group_list;
-} VFIOContainer;
-
-OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
 
 typedef struct VFIODeviceOps VFIODeviceOps;
 typedef struct VFIOMigration VFIOMigration;
@@ -125,15 +115,6 @@ struct VFIODeviceOps {
     int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f);
 };
 
-typedef struct VFIOGroup {
-    int fd;
-    int groupid;
-    VFIOContainer *container;
-    QLIST_HEAD(, VFIODevice) device_list;
-    QLIST_ENTRY(VFIOGroup) next;
-    QLIST_ENTRY(VFIOGroup) container_next;
-    bool ram_block_discard_allowed;
-} VFIOGroup;
 
 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \
diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-container.h
new file mode 100644
index 0000000000000000000000000000000000000000..fe1a849f884968c47a6ea876fc37b2842cb025da
--- /dev/null
+++ b/include/hw/vfio/vfio-container.h
@@ -0,0 +1,35 @@
+/*
+ * VFIO container
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_CONTAINER_H
+#define HW_VFIO_CONTAINER_H
+
+#include "hw/vfio/vfio-container-base.h"
+
+typedef struct VFIOContainer VFIOContainer;
+
+typedef struct VFIOGroup {
+    int fd;
+    int groupid;
+    VFIOContainer *container;
+    QLIST_HEAD(, VFIODevice) device_list;
+    QLIST_ENTRY(VFIOGroup) next;
+    QLIST_ENTRY(VFIOGroup) container_next;
+    bool ram_block_discard_allowed;
+} VFIOGroup;
+
+typedef struct VFIOContainer {
+    VFIOContainerBase bcontainer;
+    int fd; /* /dev/vfio/vfio, empowered by the attached groups */
+    unsigned iommu_type;
+    QLIST_HEAD(, VFIOGroup) group_list;
+} VFIOContainer;
+
+OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
+
+#endif /* HW_VFIO_CONTAINER_H */
diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
index 76b2a3487b5d6f21528e9c301341eb27bc8fec1d..1722a5bfa3983d42baac558f22410e36eed375f5 100644
--- a/hw/ppc/spapr_pci_vfio.c
+++ b/hw/ppc/spapr_pci_vfio.c
@@ -25,6 +25,7 @@
 #include "hw/pci/msix.h"
 #include "hw/pci/pci_device.h"
 #include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-container.h"
 #include "qemu/error-report.h"
 #include CONFIG_DEVICES /* CONFIG_VFIO_PCI */
 
diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index 6236ac7f1e686c9774ade172bf57a1e526b59939..88d4c5b3ecc617c5b93ca53cba0850666db3a67b 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -20,7 +20,7 @@
 #include "hw/s390x/s390-pci-clp.h"
 #include "hw/s390x/s390-pci-vfio.h"
 #include "hw/vfio/pci.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-container.h"
 
 /*
  * Get the current DMA available count from vfio.  Returns true if vfio is
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 7c57bdd27b72731db5cf4f9446d954e143b4747e..75b5ebf4716c55d8c32a845c875981cef8fb5610 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -32,6 +32,7 @@
 #include "trace.h"
 #include "qapi/error.h"
 #include "pci.h"
+#include "hw/vfio/vfio-container.h"
 
 VFIOGroupList vfio_group_list =
     QLIST_HEAD_INITIALIZER(vfio_group_list);
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 021cdedbfa483f0599ad3c858a77fc6570f1ace8..4adfd50967313d1a5c3c4033a57c37eeb3a779a7 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -16,6 +16,7 @@
 #include "exec/address-spaces.h"
 
 #include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-container.h"
 #include "hw/hw.h"
 #include "exec/ram_addr.h"
 #include "qemu/error-report.h"
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 12/32] vfio: Make vfio_group_list static
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (10 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-20  9:28   ` Duan, Zhenzhong
  2025-03-20  9:38   ` John Levon
  2025-03-18  9:53 ` [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c Cédric Le Goater
                   ` (19 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

vfio_group_list is only used in file "container.c".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h | 2 --
 hw/vfio/container.c           | 3 ++-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index aebce091088f5027c31c7782a1683e763bd766ec..e23626856e6ff96939a4660f059833f166aa88e9 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -146,9 +146,7 @@ int vfio_kvm_device_del_fd(int fd, Error **errp);
 bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp);
 void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer);
 
-typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;
 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
-extern VFIOGroupList vfio_group_list;
 extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
 extern int vfio_kvm_device_fd;
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 75b5ebf4716c55d8c32a845c875981cef8fb5610..8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -34,7 +34,8 @@
 #include "pci.h"
 #include "hw/vfio/vfio-container.h"
 
-VFIOGroupList vfio_group_list =
+typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;
+static VFIOGroupList vfio_group_list =
     QLIST_HEAD_INITIALIZER(vfio_group_list);
 
 static int vfio_ram_block_discard_disable(VFIOContainer *container, bool state)
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (11 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 12/32] vfio: Make vfio_group_list static Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 16:45   ` John Levon
  2025-03-20  9:36   ` Duan, Zhenzhong
  2025-03-18  9:53 ` [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files Cédric Le Goater
                   ` (18 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

VFIOAddressSpace is a common object used by VFIOContainerBase which is
declared in "hw/vfio/vfio-container-base.h". Move the VFIOAddressSpace
related services into "container-base.c".

While at it, rename :

  vfio_get_address_space -> vfio_address_space_get
  vfio_put_address_space -> vfio_address_space_put

to better reflect the namespace these routines belong to.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h         |  6 ---
 include/hw/vfio/vfio-container-base.h |  5 ++
 hw/ppc/spapr_pci_vfio.c               |  5 +-
 hw/vfio/common.c                      | 66 -------------------------
 hw/vfio/container-base.c              | 69 +++++++++++++++++++++++++++
 hw/vfio/container.c                   |  6 +--
 hw/vfio/iommufd.c                     |  6 +--
 hw/vfio/trace-events                  |  4 +-
 8 files changed, 85 insertions(+), 82 deletions(-)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236cac0bbe834b39 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -120,18 +120,12 @@ struct VFIODeviceOps {
 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \
             TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
 
-VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
-void vfio_put_address_space(VFIOAddressSpace *space);
-void vfio_address_space_insert(VFIOAddressSpace *space,
-                               VFIOContainerBase *bcontainer);
-
 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);
 bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
                             int action, int fd, Error **errp);
 
-void vfio_reset_handler(void *opaque);
 struct vfio_device_info *vfio_get_device_info(int fd);
 bool vfio_device_is_mdev(VFIODevice *vbasedev);
 bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
index 4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda9548c8e60afefe794 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -71,6 +71,11 @@ typedef struct VFIORamDiscardListener {
     QLIST_ENTRY(VFIORamDiscardListener) next;
 } VFIORamDiscardListener;
 
+VFIOAddressSpace *vfio_address_space_get(AddressSpace *as);
+void vfio_address_space_put(VFIOAddressSpace *space);
+void vfio_address_space_insert(VFIOAddressSpace *space,
+                               VFIOContainerBase *bcontainer);
+
 int vfio_container_dma_map(VFIOContainerBase *bcontainer,
                            hwaddr iova, ram_addr_t size,
                            void *vaddr, bool readonly);
diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
index 1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc2195bf68418e5206 100644
--- a/hw/ppc/spapr_pci_vfio.c
+++ b/hw/ppc/spapr_pci_vfio.c
@@ -24,7 +24,6 @@
 #include "hw/pci-host/spapr.h"
 #include "hw/pci/msix.h"
 #include "hw/pci/pci_device.h"
-#include "hw/vfio/vfio-common.h"
 #include "hw/vfio/vfio-container.h"
 #include "qemu/error-report.h"
 #include CONFIG_DEVICES /* CONFIG_VFIO_PCI */
@@ -86,7 +85,7 @@ static int vfio_eeh_container_op(VFIOContainer *container, uint32_t op)
 
 static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
 {
-    VFIOAddressSpace *space = vfio_get_address_space(as);
+    VFIOAddressSpace *space = vfio_address_space_get(as);
     VFIOContainerBase *bcontainer = NULL;
 
     if (QLIST_EMPTY(&space->containers)) {
@@ -106,7 +105,7 @@ static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
     }
 
 out:
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
     return container_of(bcontainer, VFIOContainer, bcontainer);
 }
 
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 0e3746eddd1c08e98bf57a59d542e158487d346e..08e2494d7c4a9858657724730b2829290fb3f197 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -36,7 +36,6 @@
 #include "qemu/main-loop.h"
 #include "qemu/range.h"
 #include "system/kvm.h"
-#include "system/reset.h"
 #include "system/runstate.h"
 #include "trace.h"
 #include "qapi/error.h"
@@ -48,8 +47,6 @@
 
 VFIODeviceList vfio_device_list =
     QLIST_HEAD_INITIALIZER(vfio_device_list);
-static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
-    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
 
 #ifdef CONFIG_KVM
 /*
@@ -1304,24 +1301,6 @@ const MemoryListener vfio_memory_listener = {
     .log_sync = vfio_listener_log_sync,
 };
 
-void vfio_reset_handler(void *opaque)
-{
-    VFIODevice *vbasedev;
-
-    trace_vfio_reset_handler();
-    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
-        if (vbasedev->dev->realized) {
-            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
-        }
-    }
-
-    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
-        if (vbasedev->dev->realized && vbasedev->needs_reset) {
-            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
-        }
-    }
-}
-
 int vfio_kvm_device_add_fd(int fd, Error **errp)
 {
 #ifdef CONFIG_KVM
@@ -1380,51 +1359,6 @@ int vfio_kvm_device_del_fd(int fd, Error **errp)
     return 0;
 }
 
-VFIOAddressSpace *vfio_get_address_space(AddressSpace *as)
-{
-    VFIOAddressSpace *space;
-
-    QLIST_FOREACH(space, &vfio_address_spaces, list) {
-        if (space->as == as) {
-            return space;
-        }
-    }
-
-    /* No suitable VFIOAddressSpace, create a new one */
-    space = g_malloc0(sizeof(*space));
-    space->as = as;
-    QLIST_INIT(&space->containers);
-
-    if (QLIST_EMPTY(&vfio_address_spaces)) {
-        qemu_register_reset(vfio_reset_handler, NULL);
-    }
-
-    QLIST_INSERT_HEAD(&vfio_address_spaces, space, list);
-
-    return space;
-}
-
-void vfio_put_address_space(VFIOAddressSpace *space)
-{
-    if (!QLIST_EMPTY(&space->containers)) {
-        return;
-    }
-
-    QLIST_REMOVE(space, list);
-    g_free(space);
-
-    if (QLIST_EMPTY(&vfio_address_spaces)) {
-        qemu_unregister_reset(vfio_reset_handler, NULL);
-    }
-}
-
-void vfio_address_space_insert(VFIOAddressSpace *space,
-                               VFIOContainerBase *bcontainer)
-{
-    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
-    bcontainer->space = space;
-}
-
 struct vfio_device_info *vfio_get_device_info(int fd)
 {
     struct vfio_device_info *info;
diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
index 749a3fd29dd6fc9143f14edf7e4ac6238315fcce..83e83ab9e67de8b004dfaf0067e4c466a6c88451 100644
--- a/hw/vfio/container-base.c
+++ b/hw/vfio/container-base.c
@@ -13,7 +13,76 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
+#include "system/reset.h"
 #include "hw/vfio/vfio-container-base.h"
+#include "hw/vfio/vfio-common.h" /* for vfio_device_list */
+#include "trace.h"
+
+static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
+    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
+
+static void vfio_reset_handler(void *opaque)
+{
+    VFIODevice *vbasedev;
+
+    trace_vfio_reset_handler();
+    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
+        if (vbasedev->dev->realized) {
+            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
+        }
+    }
+
+    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
+        if (vbasedev->dev->realized && vbasedev->needs_reset) {
+            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
+        }
+    }
+}
+
+VFIOAddressSpace *vfio_address_space_get(AddressSpace *as)
+{
+    VFIOAddressSpace *space;
+
+    QLIST_FOREACH(space, &vfio_address_spaces, list) {
+        if (space->as == as) {
+            return space;
+        }
+    }
+
+    /* No suitable VFIOAddressSpace, create a new one */
+    space = g_malloc0(sizeof(*space));
+    space->as = as;
+    QLIST_INIT(&space->containers);
+
+    if (QLIST_EMPTY(&vfio_address_spaces)) {
+        qemu_register_reset(vfio_reset_handler, NULL);
+    }
+
+    QLIST_INSERT_HEAD(&vfio_address_spaces, space, list);
+
+    return space;
+}
+
+void vfio_address_space_put(VFIOAddressSpace *space)
+{
+    if (!QLIST_EMPTY(&space->containers)) {
+        return;
+    }
+
+    QLIST_REMOVE(space, list);
+    g_free(space);
+
+    if (QLIST_EMPTY(&vfio_address_spaces)) {
+        qemu_unregister_reset(vfio_reset_handler, NULL);
+    }
+}
+
+void vfio_address_space_insert(VFIOAddressSpace *space,
+                               VFIOContainerBase *bcontainer)
+{
+    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
+    bcontainer->space = space;
+}
 
 int vfio_container_dma_map(VFIOContainerBase *bcontainer,
                            hwaddr iova, ram_addr_t size,
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb..9b86e24a4072e579bcdc2c060ce42608ee44ee2e 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -546,7 +546,7 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
     VFIOAddressSpace *space;
     VFIOIOMMUClass *vioc;
 
-    space = vfio_get_address_space(as);
+    space = vfio_address_space_get(as);
 
     /*
      * VFIO is currently incompatible with discarding of RAM insofar as the
@@ -675,7 +675,7 @@ close_fd_exit:
     close(fd);
 
 put_space_exit:
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
 
     return false;
 }
@@ -714,7 +714,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
         close(container->fd);
         object_unref(container);
 
-        vfio_put_address_space(space);
+        vfio_address_space_put(space);
     }
 }
 
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index a219b6453037e2d4e0d12800ea25678885af98f8..a170f5c71218db8c9b2f00b1a45ee900b6b21346 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -487,7 +487,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
         goto err_connect_bind;
     }
 
-    space = vfio_get_address_space(as);
+    space = vfio_address_space_get(as);
 
     /*
      * The HostIOMMUDevice data from legacy backend is static and doesn't need
@@ -607,7 +607,7 @@ err_discard_disable:
 err_attach_container:
     iommufd_cdev_container_destroy(container);
 err_alloc_ioas:
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
     iommufd_cdev_unbind_and_disconnect(vbasedev);
 err_connect_bind:
     close(vbasedev->fd);
@@ -632,7 +632,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev)
     vfio_cpr_unregister_container(bcontainer);
     iommufd_cdev_detach_container(vbasedev, container);
     iommufd_cdev_container_destroy(container);
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
 
     iommufd_cdev_unbind_and_disconnect(vbasedev);
     close(vbasedev->fd);
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index 81f4130100c48012c15b5b4858446149a7eaf5b6..c3691c1a172c31c5b10bfd6967c32fd32b65d0f7 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -109,7 +109,6 @@ vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype
 vfio_legacy_dma_unmap_overflow_workaround(void) ""
 vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
-vfio_reset_handler(void) ""
 
 # region.c
 vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
@@ -194,3 +193,6 @@ iommufd_cdev_fail_attach_existing_container(const char *msg) " %s"
 iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [iommufd=%d] new IOMMUFD container with ioasid=%d"
 iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int num_regions, int flags) " %s (%d) num_irqs=%d num_regions=%d flags=%d"
 iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, int dev_id) "\t%04x:%02x:%02x.%x devid %d"
+
+# container-base.c
+vfio_reset_handler(void) ""
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (12 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19  9:10   ` John Levon
  2025-03-20  9:36   ` Duan, Zhenzhong
  2025-03-18  9:53 ` [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services Cédric Le Goater
                   ` (17 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

These definitions don't have any use outside of their respective
submodules. There is no need to expose them externally. Keep them
private.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h | 5 -----
 hw/vfio/container.c           | 2 ++
 hw/vfio/iommufd.c             | 3 +++
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 2ea7f9c6f6e7e752699954ac236cac0bbe834b39..c45a18ab3af7d0b55a41d607a17d93079ae445d7 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -115,11 +115,6 @@ struct VFIODeviceOps {
     int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f);
 };
 
-
-#define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
-#define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \
-            TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
-
 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);
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 9b86e24a4072e579bcdc2c060ce42608ee44ee2e..9aa9f6931f591211e46f57029df2ca194f9c3eaf 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -34,6 +34,8 @@
 #include "pci.h"
 #include "hw/vfio/vfio-container.h"
 
+#define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
+
 typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;
 static VFIOGroupList vfio_group_list =
     QLIST_HEAD_INITIALIZER(vfio_group_list);
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index a170f5c71218db8c9b2f00b1a45ee900b6b21346..ce47c85c0dde424b36b482344ff8c92fc2485f9f 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -28,6 +28,9 @@
 #include "migration.h"
 #include "iommufd.h"
 
+#define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO             \
+            TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
+
 static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                             ram_addr_t size, void *vaddr, bool readonly)
 {
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (13 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-20  9:40   ` John Levon
  2025-03-18  9:53 ` [PATCH for-10.1 16/32] vfio: Move vfio_get_info_dma_avail() into helpers.c Cédric Le Goater
                   ` (16 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Gather all helper routine declarations into "helpers.h" to reduce
exposure of VFIO internals in "hw/vfio/vfio-common.h".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/helpers.h             | 26 ++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h |  7 -------
 hw/s390x/s390-pci-vfio.c      |  1 +
 hw/vfio/common.c              |  1 +
 hw/vfio/container.c           |  1 +
 hw/vfio/helpers.c             |  1 +
 hw/vfio/pci.c                 |  1 +
 hw/vfio/region.c              |  1 +
 8 files changed, 32 insertions(+), 7 deletions(-)
 create mode 100644 hw/vfio/helpers.h

diff --git a/hw/vfio/helpers.h b/hw/vfio/helpers.h
new file mode 100644
index 0000000000000000000000000000000000000000..b70f7082562dedff9d97db80d2eecc7ddf71e2af
--- /dev/null
+++ b/hw/vfio/helpers.h
@@ -0,0 +1,26 @@
+/*
+ * VFIO helpers
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_HELPERS_H
+#define HW_VFIO_HELPERS_H
+
+#ifdef CONFIG_LINUX
+#include <linux/vfio.h>
+
+struct vfio_info_cap_header *
+vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
+struct vfio_info_cap_header *
+vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
+struct vfio_info_cap_header *
+vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
+
+#endif
+
+int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
+
+#endif /* HW_VFIO_HELPERS_H */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c45a18ab3af7d0b55a41d607a17d93079ae445d7..0fe424633c9cb94195c08d0b62ca4fb8ffccd79c 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -146,17 +146,10 @@ int vfio_get_region_info(VFIODevice *vbasedev, int index,
 int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
                              uint32_t subtype, struct vfio_region_info **info);
 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
-struct vfio_info_cap_header *
-vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
 bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
                              unsigned int *avail);
-struct vfio_info_cap_header *
-vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
-struct vfio_info_cap_header *
-vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
 #endif
 
-int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
 bool vfio_devices_all_dirty_tracking_started(
     const VFIOContainerBase *bcontainer);
 bool
diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index 88d4c5b3ecc617c5b93ca53cba0850666db3a67b..83c8e84919aecf2a8581205f3de5061aceb20ea8 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -21,6 +21,7 @@
 #include "hw/s390x/s390-pci-vfio.h"
 #include "hw/vfio/pci.h"
 #include "hw/vfio/vfio-container.h"
+#include "hw/vfio/helpers.h"
 
 /*
  * Get the current DMA available count from vfio.  Returns true if vfio is
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 08e2494d7c4a9858657724730b2829290fb3f197..3a20b121fcaf361596bc975437f9a358effc7f88 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -44,6 +44,7 @@
 #include "system/tcg.h"
 #include "system/tpm.h"
 #include "migration.h"
+#include "helpers.h"
 
 VFIODeviceList vfio_device_list =
     QLIST_HEAD_INITIALIZER(vfio_device_list);
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 9aa9f6931f591211e46f57029df2ca194f9c3eaf..a6f7359faefc02b01ca05f76b4c1f8a9934a9091 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -33,6 +33,7 @@
 #include "qapi/error.h"
 #include "pci.h"
 #include "hw/vfio/vfio-container.h"
+#include "helpers.h"
 
 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
 
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index 89403943a7a219e491b6812d50b27b7f1fd7b4a4..9d635c18156d3271bad824b74fbc5b6f1f810a95 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -30,6 +30,7 @@
 #include "qemu/error-report.h"
 #include "qemu/units.h"
 #include "monitor/monitor.h"
+#include "helpers.h"
 
 /*
  * Common VFIO interrupt disable
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 6bf5a4dc720f717b2593b1b272927a13f2932d27..c0d314265836759beaf65afd85153b465179ecce 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -46,6 +46,7 @@
 #include "system/iommufd.h"
 #include "migration.h"
 #include "hw/vfio/vfio-region.h"
+#include "helpers.h"
 
 #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
 
diff --git a/hw/vfio/region.c b/hw/vfio/region.c
index 3e174c3dcb0b699fd0cee00d104250d8ae97f698..87bf5e046a432dfedf3be3c1c7e8f33e006da004 100644
--- a/hw/vfio/region.c
+++ b/hw/vfio/region.c
@@ -30,6 +30,7 @@
 #include "qemu/error-report.h"
 #include "qemu/units.h"
 #include "monitor/monitor.h"
+#include "helpers.h"
 
 /*
  * IO Port/MMIO - Beware of the endians, VFIO is always little endian
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 16/32] vfio: Move vfio_get_info_dma_avail() into helpers.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (14 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services Cédric Le Goater
@ 2025-03-18  9:53 ` Cédric Le Goater
  2025-03-19 16:50   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c Cédric Le Goater
                   ` (15 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:53 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

vfio_get_info_dma_avail() is a low level routine similar to the other
routines extracting capabilities from 'struct vfio_iommu_type1_info'.
It belongs to file "helpers.c".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/helpers.h             |  5 ++++-
 include/hw/vfio/vfio-common.h |  2 --
 hw/vfio/container.c           | 31 -------------------------------
 hw/vfio/helpers.c             | 31 +++++++++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/hw/vfio/helpers.h b/hw/vfio/helpers.h
index b70f7082562dedff9d97db80d2eecc7ddf71e2af..c70eef4fd6f98fc1df9bc8ecbf72fa1ea484e3c0 100644
--- a/hw/vfio/helpers.h
+++ b/hw/vfio/helpers.h
@@ -18,7 +18,10 @@ struct vfio_info_cap_header *
 vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
 struct vfio_info_cap_header *
 vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
-
+struct vfio_info_cap_header *
+vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id);
+bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
+                             unsigned int *avail);
 #endif
 
 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 0fe424633c9cb94195c08d0b62ca4fb8ffccd79c..b7c1f049582c07aefdc2a0cef2805e7b478ffe84 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -146,8 +146,6 @@ int vfio_get_region_info(VFIODevice *vbasedev, int index,
 int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
                              uint32_t subtype, struct vfio_region_info **info);
 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
-bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
-                             unsigned int *avail);
 #endif
 
 bool vfio_devices_all_dirty_tracking_started(
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index a6f7359faefc02b01ca05f76b4c1f8a9934a9091..e1b06e71c47ab8d24e7da878f801020b22936430 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -278,37 +278,6 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
     return ret;
 }
 
-static struct vfio_info_cap_header *
-vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id)
-{
-    if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) {
-        return NULL;
-    }
-
-    return vfio_get_cap((void *)info, info->cap_offset, id);
-}
-
-bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
-                             unsigned int *avail)
-{
-    struct vfio_info_cap_header *hdr;
-    struct vfio_iommu_type1_info_dma_avail *cap;
-
-    /* If the capability cannot be found, assume no DMA limiting */
-    hdr = vfio_get_iommu_type1_info_cap(info,
-                                        VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL);
-    if (!hdr) {
-        return false;
-    }
-
-    if (avail != NULL) {
-        cap = (void *) hdr;
-        *avail = cap->avail;
-    }
-
-    return true;
-}
-
 static bool vfio_get_info_iova_range(struct vfio_iommu_type1_info *info,
                                      VFIOContainerBase *bcontainer)
 {
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index 9d635c18156d3271bad824b74fbc5b6f1f810a95..f42dcf82c58c978a45975eb1d015d64f4e39b3cf 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -222,6 +222,37 @@ retry:
     return 0;
 }
 
+struct vfio_info_cap_header *
+vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id)
+{
+    if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) {
+        return NULL;
+    }
+
+    return vfio_get_cap((void *)info, info->cap_offset, id);
+}
+
+bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
+                             unsigned int *avail)
+{
+    struct vfio_info_cap_header *hdr;
+    struct vfio_iommu_type1_info_dma_avail *cap;
+
+    /* If the capability cannot be found, assume no DMA limiting */
+    hdr = vfio_get_iommu_type1_info_cap(info,
+                                        VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL);
+    if (!hdr) {
+        return false;
+    }
+
+    if (avail != NULL) {
+        cap = (void *) hdr;
+        *avail = cap->avail;
+    }
+
+    return true;
+}
+
 int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
                              uint32_t subtype, struct vfio_region_info **info)
 {
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (15 preceding siblings ...)
  2025-03-18  9:53 ` [PATCH for-10.1 16/32] vfio: Move vfio_get_info_dma_avail() into helpers.c Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 16:46   ` John Levon
  2025-03-20  9:40   ` Duan, Zhenzhong
  2025-03-18  9:54 ` [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() " Cédric Le Goater
                   ` (14 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

vfio_kvm_device_add/del_fd() are low level routines. Move them with
the other helpers.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/helpers.h             |  3 ++
 include/hw/vfio/vfio-common.h |  3 --
 hw/vfio/common.c              | 58 ----------------------------------
 hw/vfio/helpers.c             | 59 +++++++++++++++++++++++++++++++++++
 hw/vfio/iommufd.c             |  1 +
 hw/vfio/meson.build           |  2 +-
 6 files changed, 64 insertions(+), 62 deletions(-)

diff --git a/hw/vfio/helpers.h b/hw/vfio/helpers.h
index c70eef4fd6f98fc1df9bc8ecbf72fa1ea484e3c0..397908735c6b285d3d9e012f30488589408235ae 100644
--- a/hw/vfio/helpers.h
+++ b/hw/vfio/helpers.h
@@ -26,4 +26,7 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
 
 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
 
+int vfio_kvm_device_add_fd(int fd, Error **errp);
+int vfio_kvm_device_del_fd(int fd, Error **errp);
+
 #endif /* HW_VFIO_HELPERS_H */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index b7c1f049582c07aefdc2a0cef2805e7b478ffe84..35b765357f85346ecfabfae782f3aa8d83d9e7ae 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -129,9 +129,6 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
 void vfio_detach_device(VFIODevice *vbasedev);
 VFIODevice *vfio_get_vfio_device(Object *obj);
 
-int vfio_kvm_device_add_fd(int fd, Error **errp);
-int vfio_kvm_device_del_fd(int fd, Error **errp);
-
 bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp);
 void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer);
 
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 3a20b121fcaf361596bc975437f9a358effc7f88..9c1b635a813ffff97426d2c3beec84de1b9afe63 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1302,64 +1302,6 @@ const MemoryListener vfio_memory_listener = {
     .log_sync = vfio_listener_log_sync,
 };
 
-int vfio_kvm_device_add_fd(int fd, Error **errp)
-{
-#ifdef CONFIG_KVM
-    struct kvm_device_attr attr = {
-        .group = KVM_DEV_VFIO_FILE,
-        .attr = KVM_DEV_VFIO_FILE_ADD,
-        .addr = (uint64_t)(unsigned long)&fd,
-    };
-
-    if (!kvm_enabled()) {
-        return 0;
-    }
-
-    if (vfio_kvm_device_fd < 0) {
-        struct kvm_create_device cd = {
-            .type = KVM_DEV_TYPE_VFIO,
-        };
-
-        if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) {
-            error_setg_errno(errp, errno, "Failed to create KVM VFIO device");
-            return -errno;
-        }
-
-        vfio_kvm_device_fd = cd.fd;
-    }
-
-    if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
-        error_setg_errno(errp, errno, "Failed to add fd %d to KVM VFIO device",
-                         fd);
-        return -errno;
-    }
-#endif
-    return 0;
-}
-
-int vfio_kvm_device_del_fd(int fd, Error **errp)
-{
-#ifdef CONFIG_KVM
-    struct kvm_device_attr attr = {
-        .group = KVM_DEV_VFIO_FILE,
-        .attr = KVM_DEV_VFIO_FILE_DEL,
-        .addr = (uint64_t)(unsigned long)&fd,
-    };
-
-    if (vfio_kvm_device_fd < 0) {
-        error_setg(errp, "KVM VFIO device isn't created yet");
-        return -EINVAL;
-    }
-
-    if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
-        error_setg_errno(errp, errno,
-                         "Failed to remove fd %d from KVM VFIO device", fd);
-        return -errno;
-    }
-#endif
-    return 0;
-}
-
 struct vfio_device_info *vfio_get_device_info(int fd)
 {
     struct vfio_device_info *info;
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index f42dcf82c58c978a45975eb1d015d64f4e39b3cf..cec9e2008ba146c15e54a2865d5a40984e7dfc8c 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -22,6 +22,7 @@
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
 
+#include "system/kvm.h"
 #include "hw/vfio/vfio-common.h"
 #include "hw/vfio/pci.h"
 #include "hw/hw.h"
@@ -253,6 +254,64 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
     return true;
 }
 
+int vfio_kvm_device_add_fd(int fd, Error **errp)
+{
+#ifdef CONFIG_KVM
+    struct kvm_device_attr attr = {
+        .group = KVM_DEV_VFIO_FILE,
+        .attr = KVM_DEV_VFIO_FILE_ADD,
+        .addr = (uint64_t)(unsigned long)&fd,
+    };
+
+    if (!kvm_enabled()) {
+        return 0;
+    }
+
+    if (vfio_kvm_device_fd < 0) {
+        struct kvm_create_device cd = {
+            .type = KVM_DEV_TYPE_VFIO,
+        };
+
+        if (kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd)) {
+            error_setg_errno(errp, errno, "Failed to create KVM VFIO device");
+            return -errno;
+        }
+
+        vfio_kvm_device_fd = cd.fd;
+    }
+
+    if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
+        error_setg_errno(errp, errno, "Failed to add fd %d to KVM VFIO device",
+                         fd);
+        return -errno;
+    }
+#endif
+    return 0;
+}
+
+int vfio_kvm_device_del_fd(int fd, Error **errp)
+{
+#ifdef CONFIG_KVM
+    struct kvm_device_attr attr = {
+        .group = KVM_DEV_VFIO_FILE,
+        .attr = KVM_DEV_VFIO_FILE_DEL,
+        .addr = (uint64_t)(unsigned long)&fd,
+    };
+
+    if (vfio_kvm_device_fd < 0) {
+        error_setg(errp, "KVM VFIO device isn't created yet");
+        return -EINVAL;
+    }
+
+    if (ioctl(vfio_kvm_device_fd, KVM_SET_DEVICE_ATTR, &attr)) {
+        error_setg_errno(errp, errno,
+                         "Failed to remove fd %d from KVM VFIO device", fd);
+        return -errno;
+    }
+#endif
+    return 0;
+}
+
 int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
                              uint32_t subtype, struct vfio_region_info **info)
 {
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index ce47c85c0dde424b36b482344ff8c92fc2485f9f..bc586e02803af984d1801159eb427d3415e373ab 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -27,6 +27,7 @@
 #include "pci.h"
 #include "migration.h"
 #include "iommufd.h"
+#include "helpers.h"
 
 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO             \
             TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index 07010c7c9e01a39ae3449c54d2027a2cdd0a7a4d..21795b3d19e5db0c93993c0cb4a951a70d260f10 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -2,6 +2,7 @@ vfio_ss = ss.source_set()
 vfio_ss.add(files(
   'common.c',
   'container.c',
+  'helpers.c',
 ))
 vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
@@ -18,7 +19,6 @@ specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
 system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
 system_ss.add(when: 'CONFIG_VFIO', if_true: files(
-  'helpers.c',
   'container-base.c',
   'migration.c',
   'migration-multifd.c',
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() to helpers.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (16 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-20  9:41   ` John Levon
  2025-03-20  9:42   ` Duan, Zhenzhong
  2025-03-18  9:54 ` [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions Cédric Le Goater
                   ` (13 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

vfio_get_device_info() is a low level routine. Move it with the other
helpers.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/helpers.h             |  1 +
 include/hw/vfio/vfio-common.h |  1 -
 hw/vfio/common.c              | 24 ------------------------
 hw/vfio/helpers.c             | 24 ++++++++++++++++++++++++
 4 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/hw/vfio/helpers.h b/hw/vfio/helpers.h
index 397908735c6b285d3d9e012f30488589408235ae..8ac1f13c6e2a51983f69f81072cb134ff8969c70 100644
--- a/hw/vfio/helpers.h
+++ b/hw/vfio/helpers.h
@@ -25,6 +25,7 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
 #endif
 
 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
+struct vfio_device_info *vfio_get_device_info(int fd);
 
 int vfio_kvm_device_add_fd(int fd, Error **errp);
 int vfio_kvm_device_del_fd(int fd, Error **errp);
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 35b765357f85346ecfabfae782f3aa8d83d9e7ae..848412ea53ccd903313855fd30490d897c8681c0 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -121,7 +121,6 @@ void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index);
 bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
                             int action, int fd, Error **errp);
 
-struct vfio_device_info *vfio_get_device_info(int fd);
 bool vfio_device_is_mdev(VFIODevice *vbasedev);
 bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
 bool vfio_attach_device(char *name, VFIODevice *vbasedev,
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 9c1b635a813ffff97426d2c3beec84de1b9afe63..e70e4c077ca27ce0d2f990d684196f2f74f6f07a 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1302,30 +1302,6 @@ const MemoryListener vfio_memory_listener = {
     .log_sync = vfio_listener_log_sync,
 };
 
-struct vfio_device_info *vfio_get_device_info(int fd)
-{
-    struct vfio_device_info *info;
-    uint32_t argsz = sizeof(*info);
-
-    info = g_malloc0(argsz);
-
-retry:
-    info->argsz = argsz;
-
-    if (ioctl(fd, VFIO_DEVICE_GET_INFO, info)) {
-        g_free(info);
-        return NULL;
-    }
-
-    if (info->argsz > argsz) {
-        argsz = info->argsz;
-        info = g_realloc(info, argsz);
-        goto retry;
-    }
-
-    return info;
-}
-
 bool vfio_attach_device(char *name, VFIODevice *vbasedev,
                         AddressSpace *as, Error **errp)
 {
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index cec9e2008ba146c15e54a2865d5a40984e7dfc8c..e9ad0c6792558a00f316baab40bf857c3306faaa 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -312,6 +312,30 @@ int vfio_kvm_device_del_fd(int fd, Error **errp)
     return 0;
 }
 
+struct vfio_device_info *vfio_get_device_info(int fd)
+{
+    struct vfio_device_info *info;
+    uint32_t argsz = sizeof(*info);
+
+    info = g_malloc0(argsz);
+
+retry:
+    info->argsz = argsz;
+
+    if (ioctl(fd, VFIO_DEVICE_GET_INFO, info)) {
+        g_free(info);
+        return NULL;
+    }
+
+    if (info->argsz > argsz) {
+        argsz = info->argsz;
+        info = g_realloc(info, argsz);
+        goto retry;
+    }
+
+    return info;
+}
+
 int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
                              uint32_t subtype, struct vfio_region_info **info)
 {
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (17 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() " Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 16:42   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 20/32] vfio: Introduce new files for CPR definitions and declarations Cédric Le Goater
                   ` (12 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Move all VFIODevice related routines of helpers.c into a new "device.c"
file.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/device.c     | 331 +++++++++++++++++++++++++++++++++++++++++++
 hw/vfio/helpers.c    | 303 ---------------------------------------
 hw/vfio/meson.build  |   1 +
 hw/vfio/trace-events |   4 +-
 4 files changed, 335 insertions(+), 304 deletions(-)
 create mode 100644 hw/vfio/device.c

diff --git a/hw/vfio/device.c b/hw/vfio/device.c
new file mode 100644
index 0000000000000000000000000000000000000000..daa5bae59ca9c65ef23aa193d4e63976fcefdde0
--- /dev/null
+++ b/hw/vfio/device.c
@@ -0,0 +1,331 @@
+/*
+ * low level and IOMMU backend agnostic helpers used by VFIO devices,
+ * related to regions, interrupts, capabilities
+ *
+ * Copyright Red Hat, Inc. 2012
+ *
+ * Authors:
+ *  Alex Williamson <alex.williamson@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Based on qemu-kvm device-assignment:
+ *  Adapted for KVM by Qumranet.
+ *  Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com)
+ *  Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com)
+ *  Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com)
+ *  Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com)
+ *  Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com)
+ */
+
+#include "qemu/osdep.h"
+#include <sys/ioctl.h>
+
+#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/pci.h"
+#include "hw/hw.h"
+#include "trace.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "qemu/units.h"
+#include "monitor/monitor.h"
+#include "helpers.h"
+
+/*
+ * Common VFIO interrupt disable
+ */
+void vfio_disable_irqindex(VFIODevice *vbasedev, int index)
+{
+    struct vfio_irq_set irq_set = {
+        .argsz = sizeof(irq_set),
+        .flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER,
+        .index = index,
+        .start = 0,
+        .count = 0,
+    };
+
+    ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
+}
+
+void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index)
+{
+    struct vfio_irq_set irq_set = {
+        .argsz = sizeof(irq_set),
+        .flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK,
+        .index = index,
+        .start = 0,
+        .count = 1,
+    };
+
+    ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
+}
+
+void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index)
+{
+    struct vfio_irq_set irq_set = {
+        .argsz = sizeof(irq_set),
+        .flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_MASK,
+        .index = index,
+        .start = 0,
+        .count = 1,
+    };
+
+    ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
+}
+
+static inline const char *action_to_str(int action)
+{
+    switch (action) {
+    case VFIO_IRQ_SET_ACTION_MASK:
+        return "MASK";
+    case VFIO_IRQ_SET_ACTION_UNMASK:
+        return "UNMASK";
+    case VFIO_IRQ_SET_ACTION_TRIGGER:
+        return "TRIGGER";
+    default:
+        return "UNKNOWN ACTION";
+    }
+}
+
+static const char *index_to_str(VFIODevice *vbasedev, int index)
+{
+    if (vbasedev->type != VFIO_DEVICE_TYPE_PCI) {
+        return NULL;
+    }
+
+    switch (index) {
+    case VFIO_PCI_INTX_IRQ_INDEX:
+        return "INTX";
+    case VFIO_PCI_MSI_IRQ_INDEX:
+        return "MSI";
+    case VFIO_PCI_MSIX_IRQ_INDEX:
+        return "MSIX";
+    case VFIO_PCI_ERR_IRQ_INDEX:
+        return "ERR";
+    case VFIO_PCI_REQ_IRQ_INDEX:
+        return "REQ";
+    default:
+        return NULL;
+    }
+}
+
+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 = NULL;
+    int argsz;
+    const char *name;
+    int32_t *pfd;
+
+    argsz = sizeof(*irq_set) + sizeof(*pfd);
+
+    irq_set = g_malloc0(argsz);
+    irq_set->argsz = argsz;
+    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | action;
+    irq_set->index = index;
+    irq_set->start = subindex;
+    irq_set->count = 1;
+    pfd = (int32_t *)&irq_set->data;
+    *pfd = fd;
+
+    if (!ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
+        return true;
+    }
+
+    error_setg_errno(errp, errno, "VFIO_DEVICE_SET_IRQS failure");
+
+    name = index_to_str(vbasedev, index);
+    if (name) {
+        error_prepend(errp, "%s-%d: ", name, subindex);
+    } else {
+        error_prepend(errp, "index %d-%d: ", index, subindex);
+    }
+    error_prepend(errp,
+                  "Failed to %s %s eventfd signaling for interrupt ",
+                  fd < 0 ? "tear down" : "set up", action_to_str(action));
+    return false;
+}
+
+int vfio_get_region_info(VFIODevice *vbasedev, int index,
+                         struct vfio_region_info **info)
+{
+    size_t argsz = sizeof(struct vfio_region_info);
+
+    *info = g_malloc0(argsz);
+
+    (*info)->index = index;
+retry:
+    (*info)->argsz = argsz;
+
+    if (ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, *info)) {
+        g_free(*info);
+        *info = NULL;
+        return -errno;
+    }
+
+    if ((*info)->argsz > argsz) {
+        argsz = (*info)->argsz;
+        *info = g_realloc(*info, argsz);
+
+        goto retry;
+    }
+
+    return 0;
+}
+
+int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
+                             uint32_t subtype, struct vfio_region_info **info)
+{
+    int i;
+
+    for (i = 0; i < vbasedev->num_regions; i++) {
+        struct vfio_info_cap_header *hdr;
+        struct vfio_region_info_cap_type *cap_type;
+
+        if (vfio_get_region_info(vbasedev, i, info)) {
+            continue;
+        }
+
+        hdr = vfio_get_region_info_cap(*info, VFIO_REGION_INFO_CAP_TYPE);
+        if (!hdr) {
+            g_free(*info);
+            continue;
+        }
+
+        cap_type = container_of(hdr, struct vfio_region_info_cap_type, header);
+
+        trace_vfio_get_dev_region(vbasedev->name, i,
+                                  cap_type->type, cap_type->subtype);
+
+        if (cap_type->type == type && cap_type->subtype == subtype) {
+            return 0;
+        }
+
+        g_free(*info);
+    }
+
+    *info = NULL;
+    return -ENODEV;
+}
+
+bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
+{
+    g_autofree struct vfio_region_info *info = NULL;
+    bool ret = false;
+
+    if (!vfio_get_region_info(vbasedev, region, &info)) {
+        if (vfio_get_region_info_cap(info, cap_type)) {
+            ret = true;
+        }
+    }
+
+    return ret;
+}
+
+bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
+{
+    ERRP_GUARD();
+    struct stat st;
+
+    if (vbasedev->fd < 0) {
+        if (stat(vbasedev->sysfsdev, &st) < 0) {
+            error_setg_errno(errp, errno, "no such host device");
+            error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev);
+            return false;
+        }
+        /* User may specify a name, e.g: VFIO platform device */
+        if (!vbasedev->name) {
+            vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
+        }
+    } else {
+        if (!vbasedev->iommufd) {
+            error_setg(errp, "Use FD passing only with iommufd backend");
+            return false;
+        }
+        /*
+         * Give a name with fd so any function printing out vbasedev->name
+         * will not break.
+         */
+        if (!vbasedev->name) {
+            vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
+        }
+    }
+
+    return true;
+}
+
+void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)
+{
+    ERRP_GUARD();
+    int fd = monitor_fd_param(monitor_cur(), str, errp);
+
+    if (fd < 0) {
+        error_prepend(errp, "Could not parse remote object fd %s:", str);
+        return;
+    }
+    vbasedev->fd = fd;
+}
+
+void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
+                      DeviceState *dev, bool ram_discard)
+{
+    vbasedev->type = type;
+    vbasedev->ops = ops;
+    vbasedev->dev = dev;
+    vbasedev->fd = -1;
+
+    vbasedev->ram_block_discard_allowed = ram_discard;
+}
+
+int vfio_device_get_aw_bits(VFIODevice *vdev)
+{
+    /*
+     * iova_ranges is a sorted list. For old kernels that support
+     * VFIO but not support query of iova ranges, iova_ranges is NULL,
+     * in this case HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX(64) is returned.
+     */
+    GList *l = g_list_last(vdev->bcontainer->iova_ranges);
+
+    if (l) {
+        Range *range = l->data;
+        return range_get_last_bit(range) + 1;
+    }
+
+    return HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX;
+}
+
+bool vfio_device_is_mdev(VFIODevice *vbasedev)
+{
+    g_autofree char *subsys = NULL;
+    g_autofree char *tmp = NULL;
+
+    if (!vbasedev->sysfsdev) {
+        return false;
+    }
+
+    tmp = g_strdup_printf("%s/subsystem", vbasedev->sysfsdev);
+    subsys = realpath(tmp, NULL);
+    return subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
+}
+
+bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp)
+{
+    HostIOMMUDevice *hiod = vbasedev->hiod;
+
+    if (!hiod) {
+        return true;
+    }
+
+    return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp);
+}
+
+VFIODevice *vfio_get_vfio_device(Object *obj)
+{
+    if (object_dynamic_cast(obj, TYPE_VFIO_PCI)) {
+        return &VFIO_PCI(obj)->vbasedev;
+    } else {
+        return NULL;
+    }
+}
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index e9ad0c6792558a00f316baab40bf857c3306faaa..ffc40ff43c8b614f044d6131562e5837cd932aa5 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -24,131 +24,10 @@
 
 #include "system/kvm.h"
 #include "hw/vfio/vfio-common.h"
-#include "hw/vfio/pci.h"
 #include "hw/hw.h"
-#include "trace.h"
 #include "qapi/error.h"
-#include "qemu/error-report.h"
-#include "qemu/units.h"
-#include "monitor/monitor.h"
 #include "helpers.h"
 
-/*
- * Common VFIO interrupt disable
- */
-void vfio_disable_irqindex(VFIODevice *vbasedev, int index)
-{
-    struct vfio_irq_set irq_set = {
-        .argsz = sizeof(irq_set),
-        .flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_TRIGGER,
-        .index = index,
-        .start = 0,
-        .count = 0,
-    };
-
-    ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
-}
-
-void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index)
-{
-    struct vfio_irq_set irq_set = {
-        .argsz = sizeof(irq_set),
-        .flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_UNMASK,
-        .index = index,
-        .start = 0,
-        .count = 1,
-    };
-
-    ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
-}
-
-void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index)
-{
-    struct vfio_irq_set irq_set = {
-        .argsz = sizeof(irq_set),
-        .flags = VFIO_IRQ_SET_DATA_NONE | VFIO_IRQ_SET_ACTION_MASK,
-        .index = index,
-        .start = 0,
-        .count = 1,
-    };
-
-    ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
-}
-
-static inline const char *action_to_str(int action)
-{
-    switch (action) {
-    case VFIO_IRQ_SET_ACTION_MASK:
-        return "MASK";
-    case VFIO_IRQ_SET_ACTION_UNMASK:
-        return "UNMASK";
-    case VFIO_IRQ_SET_ACTION_TRIGGER:
-        return "TRIGGER";
-    default:
-        return "UNKNOWN ACTION";
-    }
-}
-
-static const char *index_to_str(VFIODevice *vbasedev, int index)
-{
-    if (vbasedev->type != VFIO_DEVICE_TYPE_PCI) {
-        return NULL;
-    }
-
-    switch (index) {
-    case VFIO_PCI_INTX_IRQ_INDEX:
-        return "INTX";
-    case VFIO_PCI_MSI_IRQ_INDEX:
-        return "MSI";
-    case VFIO_PCI_MSIX_IRQ_INDEX:
-        return "MSIX";
-    case VFIO_PCI_ERR_IRQ_INDEX:
-        return "ERR";
-    case VFIO_PCI_REQ_IRQ_INDEX:
-        return "REQ";
-    default:
-        return NULL;
-    }
-}
-
-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 = NULL;
-    int argsz;
-    const char *name;
-    int32_t *pfd;
-
-    argsz = sizeof(*irq_set) + sizeof(*pfd);
-
-    irq_set = g_malloc0(argsz);
-    irq_set->argsz = argsz;
-    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | action;
-    irq_set->index = index;
-    irq_set->start = subindex;
-    irq_set->count = 1;
-    pfd = (int32_t *)&irq_set->data;
-    *pfd = fd;
-
-    if (!ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
-        return true;
-    }
-
-    error_setg_errno(errp, errno, "VFIO_DEVICE_SET_IRQS failure");
-
-    name = index_to_str(vbasedev, index);
-    if (name) {
-        error_prepend(errp, "%s-%d: ", name, subindex);
-    } else {
-        error_prepend(errp, "index %d-%d: ", index, subindex);
-    }
-    error_prepend(errp,
-                  "Failed to %s %s eventfd signaling for interrupt ",
-                  fd < 0 ? "tear down" : "set up", action_to_str(action));
-    return false;
-}
-
 int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size)
 {
     vbmap->pages = REAL_HOST_PAGE_ALIGN(size) / qemu_real_host_page_size();
@@ -196,33 +75,6 @@ vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id)
     return vfio_get_cap((void *)info, info->cap_offset, id);
 }
 
-int vfio_get_region_info(VFIODevice *vbasedev, int index,
-                         struct vfio_region_info **info)
-{
-    size_t argsz = sizeof(struct vfio_region_info);
-
-    *info = g_malloc0(argsz);
-
-    (*info)->index = index;
-retry:
-    (*info)->argsz = argsz;
-
-    if (ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, *info)) {
-        g_free(*info);
-        *info = NULL;
-        return -errno;
-    }
-
-    if ((*info)->argsz > argsz) {
-        argsz = (*info)->argsz;
-        *info = g_realloc(*info, argsz);
-
-        goto retry;
-    }
-
-    return 0;
-}
-
 struct vfio_info_cap_header *
 vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id)
 {
@@ -335,158 +187,3 @@ retry:
 
     return info;
 }
-
-int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
-                             uint32_t subtype, struct vfio_region_info **info)
-{
-    int i;
-
-    for (i = 0; i < vbasedev->num_regions; i++) {
-        struct vfio_info_cap_header *hdr;
-        struct vfio_region_info_cap_type *cap_type;
-
-        if (vfio_get_region_info(vbasedev, i, info)) {
-            continue;
-        }
-
-        hdr = vfio_get_region_info_cap(*info, VFIO_REGION_INFO_CAP_TYPE);
-        if (!hdr) {
-            g_free(*info);
-            continue;
-        }
-
-        cap_type = container_of(hdr, struct vfio_region_info_cap_type, header);
-
-        trace_vfio_get_dev_region(vbasedev->name, i,
-                                  cap_type->type, cap_type->subtype);
-
-        if (cap_type->type == type && cap_type->subtype == subtype) {
-            return 0;
-        }
-
-        g_free(*info);
-    }
-
-    *info = NULL;
-    return -ENODEV;
-}
-
-bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
-{
-    g_autofree struct vfio_region_info *info = NULL;
-    bool ret = false;
-
-    if (!vfio_get_region_info(vbasedev, region, &info)) {
-        if (vfio_get_region_info_cap(info, cap_type)) {
-            ret = true;
-        }
-    }
-
-    return ret;
-}
-
-bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)
-{
-    ERRP_GUARD();
-    struct stat st;
-
-    if (vbasedev->fd < 0) {
-        if (stat(vbasedev->sysfsdev, &st) < 0) {
-            error_setg_errno(errp, errno, "no such host device");
-            error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev);
-            return false;
-        }
-        /* User may specify a name, e.g: VFIO platform device */
-        if (!vbasedev->name) {
-            vbasedev->name = g_path_get_basename(vbasedev->sysfsdev);
-        }
-    } else {
-        if (!vbasedev->iommufd) {
-            error_setg(errp, "Use FD passing only with iommufd backend");
-            return false;
-        }
-        /*
-         * Give a name with fd so any function printing out vbasedev->name
-         * will not break.
-         */
-        if (!vbasedev->name) {
-            vbasedev->name = g_strdup_printf("VFIO_FD%d", vbasedev->fd);
-        }
-    }
-
-    return true;
-}
-
-void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp)
-{
-    ERRP_GUARD();
-    int fd = monitor_fd_param(monitor_cur(), str, errp);
-
-    if (fd < 0) {
-        error_prepend(errp, "Could not parse remote object fd %s:", str);
-        return;
-    }
-    vbasedev->fd = fd;
-}
-
-void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops,
-                      DeviceState *dev, bool ram_discard)
-{
-    vbasedev->type = type;
-    vbasedev->ops = ops;
-    vbasedev->dev = dev;
-    vbasedev->fd = -1;
-
-    vbasedev->ram_block_discard_allowed = ram_discard;
-}
-
-int vfio_device_get_aw_bits(VFIODevice *vdev)
-{
-    /*
-     * iova_ranges is a sorted list. For old kernels that support
-     * VFIO but not support query of iova ranges, iova_ranges is NULL,
-     * in this case HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX(64) is returned.
-     */
-    GList *l = g_list_last(vdev->bcontainer->iova_ranges);
-
-    if (l) {
-        Range *range = l->data;
-        return range_get_last_bit(range) + 1;
-    }
-
-    return HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX;
-}
-
-bool vfio_device_is_mdev(VFIODevice *vbasedev)
-{
-    g_autofree char *subsys = NULL;
-    g_autofree char *tmp = NULL;
-
-    if (!vbasedev->sysfsdev) {
-        return false;
-    }
-
-    tmp = g_strdup_printf("%s/subsystem", vbasedev->sysfsdev);
-    subsys = realpath(tmp, NULL);
-    return subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
-}
-
-bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp)
-{
-    HostIOMMUDevice *hiod = vbasedev->hiod;
-
-    if (!hiod) {
-        return true;
-    }
-
-    return HOST_IOMMU_DEVICE_GET_CLASS(hiod)->realize(hiod, vbasedev, errp);
-}
-
-VFIODevice *vfio_get_vfio_device(Object *obj)
-{
-    if (object_dynamic_cast(obj, TYPE_VFIO_PCI)) {
-        return &VFIO_PCI(obj)->vbasedev;
-    } else {
-        return NULL;
-    }
-}
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index 21795b3d19e5db0c93993c0cb4a951a70d260f10..60caa366175edee6bc69c0febebaef84e752e346 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -20,6 +20,7 @@ system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
 system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
 system_ss.add(when: 'CONFIG_VFIO', if_true: files(
   'container-base.c',
+  'device.c',
   'migration.c',
   'migration-multifd.c',
   'cpr.c',
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index c3691c1a172c31c5b10bfd6967c32fd32b65d0f7..a1d01e9dde6ec52964d4804e9cbce5a6a32b7879 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -105,7 +105,6 @@ vfio_disconnect_container(int fd) "close container->fd=%d"
 vfio_put_group(int fd) "close group->fd=%d"
 vfio_get_device(const char * name, unsigned int flags, unsigned int num_regions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u"
 vfio_put_base_device(int fd) "close vdev->fd=%d"
-vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%08x"
 vfio_legacy_dma_unmap_overflow_workaround(void) ""
 vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
@@ -196,3 +195,6 @@ iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int functi
 
 # container-base.c
 vfio_reset_handler(void) ""
+
+# device.c
+vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%08x"
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 20/32] vfio: Introduce new files for CPR definitions and declarations
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (18 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 17:01   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 21/32] vfio: Move vfio_kvm_device_fd() into helpers.c Cédric Le Goater
                   ` (11 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Gather all CPR related declarations into "cpr.h" to reduce exposure
of VFIO internals in "hw/vfio/vfio-common.h".

Order file list in meson.build while at it.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/cpr.h                 | 15 +++++++++++++++
 include/hw/vfio/vfio-common.h |  3 ---
 hw/vfio/container.c           |  1 +
 hw/vfio/cpr.c                 |  1 +
 hw/vfio/iommufd.c             |  1 +
 hw/vfio/meson.build           |  2 +-
 6 files changed, 19 insertions(+), 4 deletions(-)
 create mode 100644 hw/vfio/cpr.h

diff --git a/hw/vfio/cpr.h b/hw/vfio/cpr.h
new file mode 100644
index 0000000000000000000000000000000000000000..88a5e7f878a3e01df3410f6f0a9c8b5ccddefe28
--- /dev/null
+++ b/hw/vfio/cpr.h
@@ -0,0 +1,15 @@
+/*
+ * VFIO display
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_CPR_H
+#define HW_VFIO_CPR_H
+
+bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp);
+void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer);
+
+#endif /* HW_VFIO_CPR_H */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 848412ea53ccd903313855fd30490d897c8681c0..7f1df4fc0c545ceb117ad6c090bd3f701456a70c 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -128,9 +128,6 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
 void vfio_detach_device(VFIODevice *vbasedev);
 VFIODevice *vfio_get_vfio_device(Object *obj);
 
-bool vfio_cpr_register_container(VFIOContainerBase *bcontainer, Error **errp);
-void vfio_cpr_unregister_container(VFIOContainerBase *bcontainer);
-
 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
 extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index e1b06e71c47ab8d24e7da878f801020b22936430..4e41a7476549a0c5e464e499d059db5aca6e3470 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -34,6 +34,7 @@
 #include "pci.h"
 #include "hw/vfio/vfio-container.h"
 #include "helpers.h"
+#include "cpr.h"
 
 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
 
diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
index 3d1c8d290a5e6b6d67e244931a9ef8c194a0b574..e1bba1726402f41ee394f25b6e613d27f44b2a2c 100644
--- a/hw/vfio/cpr.c
+++ b/hw/vfio/cpr.c
@@ -10,6 +10,7 @@
 #include "migration/misc.h"
 #include "qapi/error.h"
 #include "system/runstate.h"
+#include "cpr.h"
 
 static int vfio_cpr_reboot_notifier(NotifierWithReturn *notifier,
                                     MigrationEvent *e, Error **errp)
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index bc586e02803af984d1801159eb427d3415e373ab..b25f3b4086d7b7fc6fcd519a9b8b2904513a655f 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -28,6 +28,7 @@
 #include "migration.h"
 #include "iommufd.h"
 #include "helpers.h"
+#include "cpr.h"
 
 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO             \
             TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index 60caa366175edee6bc69c0febebaef84e752e346..1f89bd28c13dea55bcfff476ce99d51b453d8533 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -20,10 +20,10 @@ system_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
 system_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
 system_ss.add(when: 'CONFIG_VFIO', if_true: files(
   'container-base.c',
+  'cpr.c',
   'device.c',
   'migration.c',
   'migration-multifd.c',
-  'cpr.c',
   'region.c',
 ))
 system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 21/32] vfio: Move vfio_kvm_device_fd() into helpers.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (19 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 20/32] vfio: Introduce new files for CPR definitions and declarations Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-20  9:44   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 22/32] vfio: Move vfio_device_list into device.c Cédric Le Goater
                   ` (10 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

The vfio_kvm_device_add/del_fd() routines opening the VFIO pseudo
device are defined in "helpers.c". Move 'vfio_kvm_device_fd'
definition there and its declaration into "helpers.h" to reduce
exposure of VFIO internals in "hw/vfio/vfio-common.h".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/helpers.h             |  2 ++
 include/hw/vfio/vfio-common.h |  1 -
 hw/vfio/common.c              | 11 -----------
 hw/vfio/helpers.c             | 11 +++++++++++
 hw/vfio/spapr.c               |  2 +-
 5 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/hw/vfio/helpers.h b/hw/vfio/helpers.h
index 8ac1f13c6e2a51983f69f81072cb134ff8969c70..416b045c6aacd4b6186fc86c4e38be80cad81bbe 100644
--- a/hw/vfio/helpers.h
+++ b/hw/vfio/helpers.h
@@ -12,6 +12,8 @@
 #ifdef CONFIG_LINUX
 #include <linux/vfio.h>
 
+extern int vfio_kvm_device_fd;
+
 struct vfio_info_cap_header *
 vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
 struct vfio_info_cap_header *
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 7f1df4fc0c545ceb117ad6c090bd3f701456a70c..184a422916f62259158e8759efc473a5efb2b2f7 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -131,7 +131,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj);
 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
 extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
-extern int vfio_kvm_device_fd;
 
 #ifdef CONFIG_LINUX
 int vfio_get_region_info(VFIODevice *vbasedev, int index,
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index e70e4c077ca27ce0d2f990d684196f2f74f6f07a..52f440c0d05fa9f781221032442b6118ef898a10 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -49,17 +49,6 @@
 VFIODeviceList vfio_device_list =
     QLIST_HEAD_INITIALIZER(vfio_device_list);
 
-#ifdef CONFIG_KVM
-/*
- * We have a single VFIO pseudo device per KVM VM.  Once created it lives
- * for the life of the VM.  Closing the file descriptor only drops our
- * reference to it and the device's reference to kvm.  Therefore once
- * initialized, this file descriptor is only released on QEMU exit and
- * we'll re-use it should another vfio device be attached before then.
- */
-int vfio_kvm_device_fd = -1;
-#endif
-
 /*
  * Device state interfaces
  */
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index ffc40ff43c8b614f044d6131562e5837cd932aa5..e99d312a9f5c7462644ea3d0de2e9de38979f851 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -106,6 +106,17 @@ bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
     return true;
 }
 
+#ifdef CONFIG_KVM
+/*
+ * We have a single VFIO pseudo device per KVM VM.  Once created it lives
+ * for the life of the VM.  Closing the file descriptor only drops our
+ * reference to it and the device's reference to kvm.  Therefore once
+ * initialized, this file descriptor is only released on QEMU exit and
+ * we'll re-use it should another vfio device be attached before then.
+ */
+int vfio_kvm_device_fd = -1;
+#endif
+
 int vfio_kvm_device_add_fd(int fd, Error **errp)
 {
 #ifdef CONFIG_KVM
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 4adfd50967313d1a5c3c4033a57c37eeb3a779a7..e9c954352857ab4a437b84eeda6b5a95ce285472 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -15,13 +15,13 @@
 #include "system/hostmem.h"
 #include "exec/address-spaces.h"
 
-#include "hw/vfio/vfio-common.h"
 #include "hw/vfio/vfio-container.h"
 #include "hw/hw.h"
 #include "exec/ram_addr.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "trace.h"
+#include "helpers.h"
 
 typedef struct VFIOHostDMAWindow {
     hwaddr min_iova;
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 22/32] vfio: Move vfio_device_list into device.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (20 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 21/32] vfio: Move vfio_kvm_device_fd() into helpers.c Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-20  9:29   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 23/32] vfio: Move vfio_de/attach_device() " Cédric Le Goater
                   ` (9 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

'vfio_device_list' is VFIODevice related. Move its definitions into
"device.c".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/common.c | 3 ---
 hw/vfio/device.c | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 52f440c0d05fa9f781221032442b6118ef898a10..df9585d1a471f893da072068f6056bbc6731d448 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -46,9 +46,6 @@
 #include "migration.h"
 #include "helpers.h"
 
-VFIODeviceList vfio_device_list =
-    QLIST_HEAD_INITIALIZER(vfio_device_list);
-
 /*
  * Device state interfaces
  */
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index daa5bae59ca9c65ef23aa193d4e63976fcefdde0..2e0ddec942690514e692b2380a909f15ece430f5 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -32,6 +32,9 @@
 #include "monitor/monitor.h"
 #include "helpers.h"
 
+VFIODeviceList vfio_device_list =
+    QLIST_HEAD_INITIALIZER(vfio_device_list);
+
 /*
  * Common VFIO interrupt disable
  */
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 23/32] vfio: Move vfio_de/attach_device() into device.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (21 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 22/32] vfio: Move vfio_device_list into device.c Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 16:58   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations Cédric Le Goater
                   ` (8 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

These routines are VFIODevice related. Move their definitions into
"device.c".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/common.c | 37 -------------------------------------
 hw/vfio/device.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index df9585d1a471f893da072068f6056bbc6731d448..ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1287,40 +1287,3 @@ const MemoryListener vfio_memory_listener = {
     .log_global_stop = vfio_listener_log_global_stop,
     .log_sync = vfio_listener_log_sync,
 };
-
-bool vfio_attach_device(char *name, VFIODevice *vbasedev,
-                        AddressSpace *as, Error **errp)
-{
-    const VFIOIOMMUClass *ops =
-        VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY));
-    HostIOMMUDevice *hiod = NULL;
-
-    if (vbasedev->iommufd) {
-        ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
-    }
-
-    assert(ops);
-
-
-    if (!vbasedev->mdev) {
-        hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename));
-        vbasedev->hiod = hiod;
-    }
-
-    if (!ops->attach_device(name, vbasedev, as, errp)) {
-        object_unref(hiod);
-        vbasedev->hiod = NULL;
-        return false;
-    }
-
-    return true;
-}
-
-void vfio_detach_device(VFIODevice *vbasedev)
-{
-    if (!vbasedev->bcontainer) {
-        return;
-    }
-    object_unref(vbasedev->hiod);
-    VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev);
-}
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 2e0ddec942690514e692b2380a909f15ece430f5..e6a1bbcda2297f9e6272fff9b1c228b6772457ce 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -332,3 +332,40 @@ VFIODevice *vfio_get_vfio_device(Object *obj)
         return NULL;
     }
 }
+
+bool vfio_attach_device(char *name, VFIODevice *vbasedev,
+                        AddressSpace *as, Error **errp)
+{
+    const VFIOIOMMUClass *ops =
+        VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_LEGACY));
+    HostIOMMUDevice *hiod = NULL;
+
+    if (vbasedev->iommufd) {
+        ops = VFIO_IOMMU_CLASS(object_class_by_name(TYPE_VFIO_IOMMU_IOMMUFD));
+    }
+
+    assert(ops);
+
+
+    if (!vbasedev->mdev) {
+        hiod = HOST_IOMMU_DEVICE(object_new(ops->hiod_typename));
+        vbasedev->hiod = hiod;
+    }
+
+    if (!ops->attach_device(name, vbasedev, as, errp)) {
+        object_unref(hiod);
+        vbasedev->hiod = NULL;
+        return false;
+    }
+
+    return true;
+}
+
+void vfio_detach_device(VFIODevice *vbasedev)
+{
+    if (!vbasedev->bcontainer) {
+        return;
+    }
+    object_unref(vbasedev->hiod);
+    VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev);
+}
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (22 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 23/32] vfio: Move vfio_de/attach_device() " Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 13:23   ` Joao Martins
                     ` (2 more replies)
  2025-03-18  9:54 ` [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c Cédric Le Goater
                   ` (7 subsequent siblings)
  31 siblings, 3 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

File "common.c" has been emptied of most of its definitions by the
previous changes and the only definitions left are related to dirty
tracking. Rename it to "dirty-tracking.c" and introduce its associated
"dirty-tracking.h" header file for the declarations.

Cleanup a little the includes while at it.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/dirty-tracking.h               | 22 ++++++++++++++++++++++
 include/hw/vfio/vfio-common.h          | 10 ----------
 hw/vfio/container.c                    |  1 +
 hw/vfio/{common.c => dirty-tracking.c} |  5 +----
 hw/vfio/iommufd.c                      |  1 +
 hw/vfio/meson.build                    |  2 +-
 hw/vfio/trace-events                   |  2 +-
 7 files changed, 27 insertions(+), 16 deletions(-)
 create mode 100644 hw/vfio/dirty-tracking.h
 rename hw/vfio/{common.c => dirty-tracking.c} (99%)

diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
new file mode 100644
index 0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a
--- /dev/null
+++ b/hw/vfio/dirty-tracking.h
@@ -0,0 +1,22 @@
+/*
+ * VFIO dirty page tracking routines
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_DIRTY_TRACKING_H
+#define HW_VFIO_DIRTY_TRACKING_H
+
+extern const MemoryListener vfio_memory_listener;
+
+bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *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,
+                                    Error **errp);
+int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
+                          uint64_t size, ram_addr_t ram_addr, Error **errp);
+
+#endif /* HW_VFIO_DIRTY_TRACKING_H */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878d4d61818497426 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -130,7 +130,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj);
 
 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
 extern VFIODeviceList vfio_device_list;
-extern const MemoryListener vfio_memory_listener;
 
 #ifdef CONFIG_LINUX
 int vfio_get_region_info(VFIODevice *vbasedev, int index,
@@ -140,15 +139,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
 #endif
 
-bool vfio_devices_all_dirty_tracking_started(
-    const VFIOContainerBase *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, Error **errp);
-int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
-                          uint64_t size, ram_addr_t ram_addr, Error **errp);
-
 /* Returns 0 on success, or a negative errno. */
 bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
 void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -35,6 +35,7 @@
 #include "hw/vfio/vfio-container.h"
 #include "helpers.h"
 #include "cpr.h"
+#include "dirty-tracking.h"
 
 #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
 
diff --git a/hw/vfio/common.c b/hw/vfio/dirty-tracking.c
similarity index 99%
rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c
index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/dirty-tracking.c
@@ -20,14 +20,10 @@
 
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
-#ifdef CONFIG_KVM
-#include <linux/kvm.h>
-#endif
 #include <linux/vfio.h>
 
 #include "hw/vfio/vfio-common.h"
 #include "hw/vfio/pci.h"
-#include "exec/address-spaces.h"
 #include "exec/memory.h"
 #include "exec/ram_addr.h"
 #include "exec/target_page.h"
@@ -45,6 +41,7 @@
 #include "system/tpm.h"
 #include "migration.h"
 #include "helpers.h"
+#include "dirty-tracking.h"
 
 /*
  * Device state interfaces
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index b25f3b4086d7b7fc6fcd519a9b8b2904513a655f..9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -29,6 +29,7 @@
 #include "iommufd.h"
 #include "helpers.h"
 #include "cpr.h"
+#include "dirty-tracking.h"
 
 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO             \
             TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
index 1f89bd28c13dea55bcfff476ce99d51b453d8533..b6f5a7eeeda035b5872c2a19f8086384e000f420 100644
--- a/hw/vfio/meson.build
+++ b/hw/vfio/meson.build
@@ -1,6 +1,6 @@
 vfio_ss = ss.source_set()
 vfio_ss.add(files(
-  'common.c',
+  'dirty-tracking.c',
   'container.c',
   'helpers.c',
 ))
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index a1d01e9dde6ec52964d4804e9cbce5a6a32b7879..f3bdcebe938dcca77b913ef81a74644c622b5d8a 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -89,7 +89,7 @@ vfio_pci_igd_bdsm_enabled(const char *name, int size) "%s %dMB"
 vfio_pci_igd_host_bridge_enabled(const char *name) "%s"
 vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s"
 
-# common.c
+# dirty-tracking.c
 vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_end) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64
 vfio_listener_region_skip(const char *name, uint64_t start, uint64_t end) "SKIPPING %s 0x%"PRIx64" - 0x%"PRIx64
 vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to liobn fd %d"
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (23 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 12:12   ` Prasad Pandit
  2025-03-19 17:00   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h Cédric Le Goater
                   ` (6 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

This routine is related to VFIO migration. It belongs to "migration.c".
While at it, rename it to better reflect the namespace it belongs to.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/migration.h      |  1 +
 hw/vfio/dirty-tracking.c | 19 +++++--------------
 hw/vfio/migration.c      |  7 +++++++
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/hw/vfio/migration.h b/hw/vfio/migration.h
index 7ad2141d06a7c97f034db908f9ce19fd06f415b9..9b57d7dc1a6c6143c19e1ee85807d036b1363624 100644
--- a/hw/vfio/migration.h
+++ b/hw/vfio/migration.h
@@ -68,5 +68,6 @@ int vfio_migration_set_state(VFIODevice *vbasedev,
                              enum vfio_device_mig_state recover_state,
                              Error **errp);
 #endif
+void vfio_migration_set_error(int ret);
 
 #endif /* HW_VFIO_MIGRATION_H */
diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
index 441f9d9a08c06a88dda44ef143dcee5f0a89a900..447e09ed84993e3fbe1ed9b27a8269a9f0f46339 100644
--- a/hw/vfio/dirty-tracking.c
+++ b/hw/vfio/dirty-tracking.c
@@ -35,8 +35,6 @@
 #include "system/runstate.h"
 #include "trace.h"
 #include "qapi/error.h"
-#include "migration/misc.h"
-#include "migration/qemu-file.h"
 #include "system/tcg.h"
 #include "system/tpm.h"
 #include "migration.h"
@@ -47,13 +45,6 @@
  * Device state interfaces
  */
 
-static void vfio_set_migration_error(int ret)
-{
-    if (migration_is_running()) {
-        migration_file_set_error(ret, NULL);
-    }
-}
-
 static bool vfio_devices_all_device_dirty_tracking_started(
     const VFIOContainerBase *bcontainer)
 {
@@ -175,7 +166,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
     if (iotlb->target_as != &address_space_memory) {
         error_report("Wrong target AS \"%s\", only system memory is allowed",
                      iotlb->target_as->name ? iotlb->target_as->name : "none");
-        vfio_set_migration_error(-EINVAL);
+        vfio_migration_set_error(-EINVAL);
         return;
     }
 
@@ -212,7 +203,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
                          "0x%"HWADDR_PRIx") = %d (%s)",
                          bcontainer, iova,
                          iotlb->addr_mask + 1, ret, strerror(-ret));
-            vfio_set_migration_error(ret);
+            vfio_migration_set_error(ret);
         }
     }
 out:
@@ -995,7 +986,7 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)
         error_prepend(&local_err,
                       "vfio: Could not stop dirty page tracking - ");
         error_report_err(local_err);
-        vfio_set_migration_error(ret);
+        vfio_migration_set_error(ret);
     }
 }
 
@@ -1137,7 +1128,7 @@ out_unlock:
 
 out:
     if (ret) {
-        vfio_set_migration_error(ret);
+        vfio_migration_set_error(ret);
     }
 }
 
@@ -1271,7 +1262,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,
         ret = vfio_sync_dirty_bitmap(bcontainer, section, &local_err);
         if (ret) {
             error_report_err(local_err);
-            vfio_set_migration_error(ret);
+            vfio_migration_set_error(ret);
         }
     }
 }
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 46c4cfecce25ba1146a1d8f2de0d7c51425afe8e..6fd825e435bde96d1008ec03dfaba25db3b616fc 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -1239,3 +1239,10 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
     return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
            migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
 }
+
+void vfio_migration_set_error(int ret)
+{
+    if (migration_is_running()) {
+        migration_file_set_error(ret, NULL);
+    }
+}
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (24 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 14:27   ` Avihai Horon
  2025-03-19 16:56   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 27/32] vfio: Rename VFIODevice related services Cédric Le Goater
                   ` (5 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

"hw/vfio/vfio-common.h" has been emptied of most of its declarations
by the previous changes and the only declarations left are related to
VFIODevice. Rename it to "hw/vfio/vfio-device.h" and make the
necessary adjustments.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/migration-multifd.h                      | 2 +-
 hw/vfio/pci.h                                    | 2 +-
 include/hw/s390x/vfio-ccw.h                      | 2 +-
 include/hw/vfio/{vfio-common.h => vfio-device.h} | 0
 include/hw/vfio/vfio-platform.h                  | 2 +-
 backends/iommufd.c                               | 2 +-
 hw/vfio/ap.c                                     | 2 +-
 hw/vfio/ccw.c                                    | 2 +-
 hw/vfio/container-base.c                         | 2 +-
 hw/vfio/container.c                              | 2 +-
 hw/vfio/cpr.c                                    | 2 +-
 hw/vfio/device.c                                 | 2 +-
 hw/vfio/dirty-tracking.c                         | 2 +-
 hw/vfio/helpers.c                                | 2 +-
 hw/vfio/iommufd.c                                | 2 +-
 hw/vfio/migration-multifd.c                      | 2 +-
 hw/vfio/migration.c                              | 2 +-
 hw/vfio/region.c                                 | 4 ++--
 18 files changed, 18 insertions(+), 18 deletions(-)
 rename include/hw/vfio/{vfio-common.h => vfio-device.h} (100%)

diff --git a/hw/vfio/migration-multifd.h b/hw/vfio/migration-multifd.h
index a664051eb8ae03bc41cb7f9362ace840f41066ff..0bab63211d30cef04c50e50b3ea57840915ffc2a 100644
--- a/hw/vfio/migration-multifd.h
+++ b/hw/vfio/migration-multifd.h
@@ -12,7 +12,7 @@
 #ifndef HW_VFIO_MIGRATION_MULTIFD_H
 #define HW_VFIO_MIGRATION_MULTIFD_H
 
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 
 bool vfio_multifd_setup(VFIODevice *vbasedev, bool alloc_multifd, Error **errp);
 void vfio_multifd_cleanup(VFIODevice *vbasedev);
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index c84bba81487136d205ca30049c812d00e832c377..d33237c275551897164878705d44e7881c372ab0 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -14,7 +14,7 @@
 
 #include "exec/memory.h"
 #include "hw/pci/pci_device.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "qemu/event_notifier.h"
 #include "qemu/queue.h"
 #include "qemu/timer.h"
diff --git a/include/hw/s390x/vfio-ccw.h b/include/hw/s390x/vfio-ccw.h
index 4209d27657c1fbde44c160445396bcab3f3fd2b0..1e0922dca11e6caada08c2aae82bd3462ace35f5 100644
--- a/include/hw/s390x/vfio-ccw.h
+++ b/include/hw/s390x/vfio-ccw.h
@@ -14,7 +14,7 @@
 #ifndef HW_VFIO_CCW_H
 #define HW_VFIO_CCW_H
 
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "hw/s390x/s390-ccw.h"
 #include "hw/s390x/ccw-device.h"
 #include "qom/object.h"
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-device.h
similarity index 100%
rename from include/hw/vfio/vfio-common.h
rename to include/hw/vfio/vfio-device.h
diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h
index 3191545717da51abc41d10cd3646cd047b4a676c..256d8500b70a2e985e975b0895e3cfca435ed8ed 100644
--- a/include/hw/vfio/vfio-platform.h
+++ b/include/hw/vfio/vfio-platform.h
@@ -17,7 +17,7 @@
 #define HW_VFIO_VFIO_PLATFORM_H
 
 #include "hw/sysbus.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "qemu/event_notifier.h"
 #include "qemu/queue.h"
 #include "qom/object.h"
diff --git a/backends/iommufd.c b/backends/iommufd.c
index d57da44755be3d7fdba74f7dbecfe6d1c89921ba..9587e4d99b131e88674326a5196cfd2079560430 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -18,7 +18,7 @@
 #include "qemu/error-report.h"
 #include "monitor/monitor.h"
 #include "trace.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include <sys/ioctl.h>
 #include <linux/iommufd.h>
 
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index c7ab4ff57ada0ed0e5a76f52b5a05c86ca4fe0b4..4fdb74e33c427595a9b0a4d28b2b5a70df951e4e 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -15,7 +15,7 @@
 #include <linux/vfio.h>
 #include <sys/ioctl.h>
 #include "qapi/error.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "system/iommufd.h"
 #include "hw/s390x/ap-device.h"
 #include "qemu/error-report.h"
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index e5e0d9e3e7ed124f242b3eda345bc973e418a64c..a40169bc85e51406822247f5b3ef6da1f7f92881 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -21,7 +21,7 @@
 #include <sys/ioctl.h>
 
 #include "qapi/error.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "system/iommufd.h"
 #include "hw/s390x/s390-ccw.h"
 #include "hw/s390x/vfio-ccw.h"
diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
index 83e83ab9e67de8b004dfaf0067e4c466a6c88451..ace9de18103e8c1ed9f7a51adbf16c36be01bd7c 100644
--- a/hw/vfio/container-base.c
+++ b/hw/vfio/container-base.c
@@ -15,7 +15,7 @@
 #include "qemu/error-report.h"
 #include "system/reset.h"
 #include "hw/vfio/vfio-container-base.h"
-#include "hw/vfio/vfio-common.h" /* for vfio_device_list */
+#include "hw/vfio/vfio-device.h" /* for vfio_device_list */
 #include "trace.h"
 
 static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7..e300d2d90f2fbde329609b7c63245c523766fb60 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -22,7 +22,7 @@
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
 
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "exec/address-spaces.h"
 #include "exec/memory.h"
 #include "exec/ram_addr.h"
diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
index e1bba1726402f41ee394f25b6e613d27f44b2a2c..43b99680f6d7db27c4d7e518520aef5ade2ebcf4 100644
--- a/hw/vfio/cpr.c
+++ b/hw/vfio/cpr.c
@@ -6,7 +6,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "migration/misc.h"
 #include "qapi/error.h"
 #include "system/runstate.h"
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index e6a1bbcda2297f9e6272fff9b1c228b6772457ce..0d443b53d23d392729cef84e419d3e089fe64298 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -22,7 +22,7 @@
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
 
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "hw/vfio/pci.h"
 #include "hw/hw.h"
 #include "trace.h"
diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
index 447e09ed84993e3fbe1ed9b27a8269a9f0f46339..143cc5cf62b0165565e91f8a2ca166026f16b1eb 100644
--- a/hw/vfio/dirty-tracking.c
+++ b/hw/vfio/dirty-tracking.c
@@ -22,7 +22,7 @@
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
 
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "hw/vfio/pci.h"
 #include "exec/memory.h"
 #include "exec/ram_addr.h"
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index e99d312a9f5c7462644ea3d0de2e9de38979f851..b7907aab80f8adb308ebae60baa20c911d9393d7 100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -23,7 +23,7 @@
 #include <sys/ioctl.h>
 
 #include "system/kvm.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "hw/hw.h"
 #include "qapi/error.h"
 #include "helpers.h"
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8..7f354d86cd14270a70dc990860ad5b69f0310719 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -15,7 +15,7 @@
 #include <linux/vfio.h>
 #include <linux/iommufd.h>
 
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "qemu/error-report.h"
 #include "trace.h"
 #include "qapi/error.h"
diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
index 285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db..1ba703e595db99f3786bfc1a2edeb0e061f9e01b 100644
--- a/hw/vfio/migration-multifd.c
+++ b/hw/vfio/migration-multifd.c
@@ -10,7 +10,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "hw/vfio/vfio-migration.h"
 #include "migration/misc.h"
 #include "qapi/error.h"
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 6fd825e435bde96d1008ec03dfaba25db3b616fc..338fafb83f41460e0c244dcc27524198322eec67 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -16,7 +16,7 @@
 #include <sys/ioctl.h>
 
 #include "system/runstate.h"
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-device.h"
 #include "hw/vfio/vfio-migration.h"
 #include "migration/misc.h"
 #include "migration/savevm.h"
diff --git a/hw/vfio/region.c b/hw/vfio/region.c
index 87bf5e046a432dfedf3be3c1c7e8f33e006da004..ade4466eb622248b5aa50f9df7e5c683bfa78a11 100644
--- a/hw/vfio/region.c
+++ b/hw/vfio/region.c
@@ -22,8 +22,8 @@
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
 
-#include "hw/vfio/vfio-common.h"
-#include "hw/vfio/pci.h"
+#include "hw/vfio/vfio-region.h"
+#include "hw/vfio/vfio-device.h"
 #include "hw/hw.h"
 #include "trace.h"
 #include "qapi/error.h"
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 27/32] vfio: Rename VFIODevice related services
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (25 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-20  9:35   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static Cédric Le Goater
                   ` (4 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Rename these routines :

  vfio_disable_irqindex       -> vfio_device_irq_disable
  vfio_unmask_single_irqindex -> vfio_device_irq_unmask
  vfio_mask_single_irqindex   -> vfio_device_irq_mask
  vfio_set_irq_signaling      -> vfio_device_irq_set_signaling
  vfio_attach_device          -> vfio_device_attach
  vfio_detach_device          -> vfio_device_detach
  vfio_get_region_info        -> vfio_device_get_region_info
  vfio_get_dev_region_info    -> vfio_device_get_region_info_type
  vfio_has_region_cap         -> vfio_device_has_region_cap

to better reflect the namespace they belong to.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-device.h | 18 ++++++-------
 hw/vfio/ap.c                  |  8 +++---
 hw/vfio/ccw.c                 | 18 ++++++-------
 hw/vfio/container.c           |  6 ++---
 hw/vfio/device.c              | 24 +++++++++---------
 hw/vfio/display.c             |  2 +-
 hw/vfio/igd.c                 |  8 +++---
 hw/vfio/pci.c                 | 48 +++++++++++++++++------------------
 hw/vfio/platform.c            | 10 ++++----
 hw/vfio/region.c              |  2 +-
 hw/vfio/trace-events          |  6 ++---
 11 files changed, 75 insertions(+), 75 deletions(-)

diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index cc20110d9de8ac173b67e6e878d4d61818497426..9566b42f335ca683db668ec9167b94a187eb67fc 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -115,28 +115,28 @@ struct VFIODeviceOps {
     int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f);
 };
 
-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);
-bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
+void vfio_device_irq_disable(VFIODevice *vbasedev, int index);
+void vfio_device_irq_unmask(VFIODevice *vbasedev, int index);
+void vfio_device_irq_mask(VFIODevice *vbasedev, int index);
+bool vfio_device_irq_set_signaling(VFIODevice *vbasedev, int index, int subindex,
                             int action, int fd, Error **errp);
 
 bool vfio_device_is_mdev(VFIODevice *vbasedev);
 bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
-bool vfio_attach_device(char *name, VFIODevice *vbasedev,
+bool vfio_device_attach(char *name, VFIODevice *vbasedev,
                         AddressSpace *as, Error **errp);
-void vfio_detach_device(VFIODevice *vbasedev);
+void vfio_device_detach(VFIODevice *vbasedev);
 VFIODevice *vfio_get_vfio_device(Object *obj);
 
 typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
 extern VFIODeviceList vfio_device_list;
 
 #ifdef CONFIG_LINUX
-int vfio_get_region_info(VFIODevice *vbasedev, int index,
+int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
                          struct vfio_region_info **info);
-int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
+int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,
                              uint32_t subtype, struct vfio_region_info **info);
-bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
+bool vfio_device_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
 #endif
 
 /* Returns 0 on success, or a negative errno. */
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
index 4fdb74e33c427595a9b0a4d28b2b5a70df951e4e..9000702aed960ccb69ca67ec052f1ebe11ee1919 100644
--- a/hw/vfio/ap.c
+++ b/hw/vfio/ap.c
@@ -117,7 +117,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
     fd = event_notifier_get_fd(notifier);
     qemu_set_fd_handler(fd, fd_read, NULL, vapdev);
 
-    if (!vfio_set_irq_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd,
+    if (!vfio_device_irq_set_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd,
                                 errp)) {
         qemu_set_fd_handler(fd, NULL, NULL, vapdev);
         event_notifier_cleanup(notifier);
@@ -141,7 +141,7 @@ static void vfio_ap_unregister_irq_notifier(VFIOAPDevice *vapdev,
         return;
     }
 
-    if (!vfio_set_irq_signaling(&vapdev->vdev, irq, 0,
+    if (!vfio_device_irq_set_signaling(&vapdev->vdev, irq, 0,
                                 VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) {
         warn_reportf_err(err, VFIO_MSG_PREFIX, vapdev->vdev.name);
     }
@@ -162,7 +162,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (!vfio_attach_device(vbasedev->name, vbasedev,
+    if (!vfio_device_attach(vbasedev->name, vbasedev,
                             &address_space_memory, errp)) {
         goto error;
     }
@@ -187,7 +187,7 @@ static void vfio_ap_unrealize(DeviceState *dev)
     VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);
 
     vfio_ap_unregister_irq_notifier(vapdev, VFIO_AP_REQ_IRQ_INDEX);
-    vfio_detach_device(&vapdev->vdev);
+    vfio_device_detach(&vapdev->vdev);
     g_free(vapdev->vdev.name);
 }
 
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index a40169bc85e51406822247f5b3ef6da1f7f92881..490871c075f8db6c8a4a706b22eba966d84f2945 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -426,7 +426,7 @@ static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
     fd = event_notifier_get_fd(notifier);
     qemu_set_fd_handler(fd, fd_read, NULL, vcdev);
 
-    if (!vfio_set_irq_signaling(vdev, irq, 0,
+    if (!vfio_device_irq_set_signaling(vdev, irq, 0,
                                 VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) {
         qemu_set_fd_handler(fd, NULL, NULL, vcdev);
         event_notifier_cleanup(notifier);
@@ -456,7 +456,7 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
         return;
     }
 
-    if (!vfio_set_irq_signaling(&vcdev->vdev, irq, 0,
+    if (!vfio_device_irq_set_signaling(&vcdev->vdev, irq, 0,
                                 VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) {
         warn_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name);
     }
@@ -488,7 +488,7 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
         return false;
     }
 
-    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
+    ret = vfio_device_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
     if (ret) {
         error_setg_errno(errp, -ret, "vfio: Error getting config info");
         return false;
@@ -505,7 +505,7 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
     g_free(info);
 
     /* check for the optional async command region */
-    ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
+    ret = vfio_device_get_region_info_type(vdev, VFIO_REGION_TYPE_CCW,
                                    VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD, &info);
     if (!ret) {
         vcdev->async_cmd_region_size = info->size;
@@ -518,7 +518,7 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
         g_free(info);
     }
 
-    ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
+    ret = vfio_device_get_region_info_type(vdev, VFIO_REGION_TYPE_CCW,
                                    VFIO_REGION_SUBTYPE_CCW_SCHIB, &info);
     if (!ret) {
         vcdev->schib_region_size = info->size;
@@ -531,7 +531,7 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
         g_free(info);
     }
 
-    ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
+    ret = vfio_device_get_region_info_type(vdev, VFIO_REGION_TYPE_CCW,
                                    VFIO_REGION_SUBTYPE_CCW_CRW, &info);
 
     if (!ret) {
@@ -583,7 +583,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
         goto out_unrealize;
     }
 
-    if (!vfio_attach_device(cdev->mdevid, vbasedev,
+    if (!vfio_device_attach(cdev->mdevid, vbasedev,
                             &address_space_memory, errp)) {
         goto out_attach_dev_err;
     }
@@ -620,7 +620,7 @@ out_irq_notifier_err:
 out_io_notifier_err:
     vfio_ccw_put_region(vcdev);
 out_region_err:
-    vfio_detach_device(vbasedev);
+    vfio_device_detach(vbasedev);
 out_attach_dev_err:
     g_free(vbasedev->name);
 out_unrealize:
@@ -639,7 +639,7 @@ static void vfio_ccw_unrealize(DeviceState *dev)
     vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX);
     vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
     vfio_ccw_put_region(vcdev);
-    vfio_detach_device(&vcdev->vdev);
+    vfio_device_detach(&vcdev->vdev);
     g_free(vcdev->vdev.name);
 
     if (cdc->unrealize) {
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index e300d2d90f2fbde329609b7c63245c523766fb60..77e2934511a2917f6f7cf13f60c8f3ce4a493035 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -870,7 +870,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp)
 }
 
 /*
- * vfio_attach_device: attach a device to a security context
+ * vfio_device_attach: attach a device to a security context
  * @name and @vbasedev->name are likely to be different depending
  * on the type of the device, hence the need for passing @name
  */
@@ -886,7 +886,7 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
         return false;
     }
 
-    trace_vfio_attach_device(vbasedev->name, groupid);
+    trace_vfio_device_attach(vbasedev->name, groupid);
 
     if (!vfio_device_hiod_realize(vbasedev, errp)) {
         return false;
@@ -924,7 +924,7 @@ static void vfio_legacy_detach_device(VFIODevice *vbasedev)
     QLIST_REMOVE(vbasedev, global_next);
     QLIST_REMOVE(vbasedev, container_next);
     vbasedev->bcontainer = NULL;
-    trace_vfio_detach_device(vbasedev->name, group->groupid);
+    trace_vfio_device_detach(vbasedev->name, group->groupid);
     vfio_put_base_device(vbasedev);
     vfio_put_group(group);
 }
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 0d443b53d23d392729cef84e419d3e089fe64298..22b4310b76a7df4864096be188a4b611bac10645 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -38,7 +38,7 @@ VFIODeviceList vfio_device_list =
 /*
  * Common VFIO interrupt disable
  */
-void vfio_disable_irqindex(VFIODevice *vbasedev, int index)
+void vfio_device_irq_disable(VFIODevice *vbasedev, int index)
 {
     struct vfio_irq_set irq_set = {
         .argsz = sizeof(irq_set),
@@ -51,7 +51,7 @@ void vfio_disable_irqindex(VFIODevice *vbasedev, int index)
     ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
 }
 
-void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index)
+void vfio_device_irq_unmask(VFIODevice *vbasedev, int index)
 {
     struct vfio_irq_set irq_set = {
         .argsz = sizeof(irq_set),
@@ -64,7 +64,7 @@ void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index)
     ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
 }
 
-void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index)
+void vfio_device_irq_mask(VFIODevice *vbasedev, int index)
 {
     struct vfio_irq_set irq_set = {
         .argsz = sizeof(irq_set),
@@ -113,7 +113,7 @@ static const char *index_to_str(VFIODevice *vbasedev, int index)
     }
 }
 
-bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
+bool vfio_device_irq_set_signaling(VFIODevice *vbasedev, int index, int subindex,
                             int action, int fd, Error **errp)
 {
     ERRP_GUARD();
@@ -151,7 +151,7 @@ bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
     return false;
 }
 
-int vfio_get_region_info(VFIODevice *vbasedev, int index,
+int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
                          struct vfio_region_info **info)
 {
     size_t argsz = sizeof(struct vfio_region_info);
@@ -178,7 +178,7 @@ retry:
     return 0;
 }
 
-int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
+int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,
                              uint32_t subtype, struct vfio_region_info **info)
 {
     int i;
@@ -187,7 +187,7 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
         struct vfio_info_cap_header *hdr;
         struct vfio_region_info_cap_type *cap_type;
 
-        if (vfio_get_region_info(vbasedev, i, info)) {
+        if (vfio_device_get_region_info(vbasedev, i, info)) {
             continue;
         }
 
@@ -199,7 +199,7 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
 
         cap_type = container_of(hdr, struct vfio_region_info_cap_type, header);
 
-        trace_vfio_get_dev_region(vbasedev->name, i,
+        trace_vfio_device_get_region_info_type(vbasedev->name, i,
                                   cap_type->type, cap_type->subtype);
 
         if (cap_type->type == type && cap_type->subtype == subtype) {
@@ -213,12 +213,12 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
     return -ENODEV;
 }
 
-bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
+bool vfio_device_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
 {
     g_autofree struct vfio_region_info *info = NULL;
     bool ret = false;
 
-    if (!vfio_get_region_info(vbasedev, region, &info)) {
+    if (!vfio_device_get_region_info(vbasedev, region, &info)) {
         if (vfio_get_region_info_cap(info, cap_type)) {
             ret = true;
         }
@@ -333,7 +333,7 @@ VFIODevice *vfio_get_vfio_device(Object *obj)
     }
 }
 
-bool vfio_attach_device(char *name, VFIODevice *vbasedev,
+bool vfio_device_attach(char *name, VFIODevice *vbasedev,
                         AddressSpace *as, Error **errp)
 {
     const VFIOIOMMUClass *ops =
@@ -361,7 +361,7 @@ bool vfio_attach_device(char *name, VFIODevice *vbasedev,
     return true;
 }
 
-void vfio_detach_device(VFIODevice *vbasedev)
+void vfio_device_detach(VFIODevice *vbasedev)
 {
     if (!vbasedev->bcontainer) {
         return;
diff --git a/hw/vfio/display.c b/hw/vfio/display.c
index 2c06361c67cb074b88f2649b3b9fd21b7bacf07c..dd12c2aa6042a5ad3a1610b83bbde1d58b732a8c 100644
--- a/hw/vfio/display.c
+++ b/hw/vfio/display.c
@@ -130,7 +130,7 @@ static bool vfio_display_edid_init(VFIOPCIDevice *vdev, Error **errp)
     int fd = vdev->vbasedev.fd;
     int ret;
 
-    ret = vfio_get_dev_region_info(&vdev->vbasedev,
+    ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                                    VFIO_REGION_TYPE_GFX,
                                    VFIO_REGION_SUBTYPE_GFX_EDID,
                                    &dpy->edid_info);
diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index 265fffc2aa52d032ba619b1c3759ecebad438033..7ecbb0e672879987c9603a44b3380519b84bdc0e 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -200,7 +200,7 @@ static bool vfio_pci_igd_setup_opregion(VFIOPCIDevice *vdev, Error **errp)
         return false;
     }
 
-    ret = vfio_get_dev_region_info(&vdev->vbasedev,
+    ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                     VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
                     VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
     if (ret) {
@@ -385,7 +385,7 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
      * Check whether we have all the vfio device specific regions to
      * support LPC quirk (added in Linux v4.6).
      */
-    ret = vfio_get_dev_region_info(&vdev->vbasedev,
+    ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                         VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
                         VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG, &lpc);
     if (ret) {
@@ -393,7 +393,7 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
         return false;
     }
 
-    ret = vfio_get_dev_region_info(&vdev->vbasedev,
+    ret = vfio_device_get_region_info_type(&vdev->vbasedev,
                         VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
                         VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG, &host);
     if (ret) {
@@ -542,7 +542,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
          * there's no ROM, there's no point in setting up this quirk.
          * NB. We only seem to get BIOS ROMs, so UEFI VM would need CSM support.
          */
-        ret = vfio_get_region_info(&vdev->vbasedev,
+        ret = vfio_device_get_region_info(&vdev->vbasedev,
                                    VFIO_PCI_ROM_REGION_INDEX, &rom);
         if ((ret || !rom->size) && !vdev->pdev.romfile) {
             error_setg(&err, "Device has no ROM");
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index c0d314265836759beaf65afd85153b465179ecce..e6abc25413c5be66afc25f8b882236696b3f834d 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -116,7 +116,7 @@ static void vfio_intx_eoi(VFIODevice *vbasedev)
 
     vdev->intx.pending = false;
     pci_irq_deassert(&vdev->pdev);
-    vfio_unmask_single_irqindex(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+    vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
 }
 
 static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
@@ -132,7 +132,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
 
     /* Get to a known interrupt state */
     qemu_set_fd_handler(irq_fd, NULL, NULL, vdev);
-    vfio_mask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+    vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
     vdev->intx.pending = false;
     pci_irq_deassert(&vdev->pdev);
 
@@ -150,7 +150,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
         goto fail_irqfd;
     }
 
-    if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0,
+    if (!vfio_device_irq_set_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0,
                                 VFIO_IRQ_SET_ACTION_UNMASK,
                                 event_notifier_get_fd(&vdev->intx.unmask),
                                 errp)) {
@@ -158,7 +158,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
     }
 
     /* Let'em rip */
-    vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+    vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
 
     vdev->intx.kvm_accel = true;
 
@@ -173,7 +173,7 @@ fail_irqfd:
     event_notifier_cleanup(&vdev->intx.unmask);
 fail:
     qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev);
-    vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+    vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
     return false;
 #else
     return true;
@@ -191,7 +191,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
      * Get to a known state, hardware masked, QEMU ready to accept new
      * interrupts, QEMU IRQ de-asserted.
      */
-    vfio_mask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+    vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
     vdev->intx.pending = false;
     pci_irq_deassert(&vdev->pdev);
 
@@ -211,7 +211,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
     vdev->intx.kvm_accel = false;
 
     /* If we've missed an event, let it re-fire through QEMU */
-    vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+    vfio_device_irq_unmask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
 
     trace_vfio_intx_disable_kvm(vdev->vbasedev.name);
 #endif
@@ -300,7 +300,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
     fd = event_notifier_get_fd(&vdev->intx.interrupt);
     qemu_set_fd_handler(fd, vfio_intx_interrupt, NULL, vdev);
 
-    if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX, 0,
+    if (!vfio_device_irq_set_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);
@@ -323,7 +323,7 @@ static void vfio_intx_disable(VFIOPCIDevice *vdev)
 
     timer_del(vdev->intx.mmap_timer);
     vfio_intx_disable_kvm(vdev);
-    vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+    vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
     vdev->intx.pending = false;
     pci_irq_deassert(&vdev->pdev);
     vfio_mmap_set_enabled(vdev, true);
@@ -579,7 +579,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
 
     if (!vdev->defer_kvm_irq_routing) {
         if (vdev->msix->noresize && resizing) {
-            vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
+            vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
             ret = vfio_enable_vectors(vdev, true);
             if (ret) {
                 error_report("vfio: failed to enable vectors, %d", ret);
@@ -594,7 +594,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
                 fd = event_notifier_get_fd(&vector->interrupt);
             }
 
-            if (!vfio_set_irq_signaling(&vdev->vbasedev,
+            if (!vfio_device_irq_set_signaling(&vdev->vbasedev,
                                         VFIO_PCI_MSIX_IRQ_INDEX, nr,
                                         VFIO_IRQ_SET_ACTION_TRIGGER, fd,
                                         &err)) {
@@ -639,7 +639,7 @@ static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr)
         int32_t fd = event_notifier_get_fd(&vector->interrupt);
         Error *err = NULL;
 
-        if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX,
+        if (!vfio_device_irq_set_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.name);
@@ -836,7 +836,7 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
      * Always clear MSI-X IRQ index. A PF device could have enabled
      * MSI-X with no vectors. See vfio_msix_enable().
      */
-    vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
+    vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
 
     vfio_msi_disable_common(vdev);
     if (!vfio_intx_enable(vdev, &err)) {
@@ -853,7 +853,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev)
 {
     Error *err = NULL;
 
-    vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSI_IRQ_INDEX);
+    vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_MSI_IRQ_INDEX);
     vfio_msi_disable_common(vdev);
     vfio_intx_enable(vdev, &err);
     if (err) {
@@ -887,7 +887,7 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
     off_t off = 0;
     ssize_t bytes;
 
-    if (vfio_get_region_info(&vdev->vbasedev,
+    if (vfio_device_get_region_info(&vdev->vbasedev,
                              VFIO_PCI_ROM_REGION_INDEX, &reg_info)) {
         error_report("vfio: Error getting ROM info: %m");
         return;
@@ -1381,7 +1381,7 @@ static void vfio_pci_fixup_msix_region(VFIOPCIDevice *vdev)
      * If the host driver allows mapping of a MSIX data, we are going to
      * do map the entire BAR and emulate MSIX table on top of that.
      */
-    if (vfio_has_region_cap(&vdev->vbasedev, region->nr,
+    if (vfio_device_has_region_cap(&vdev->vbasedev, region->nr,
                             VFIO_REGION_INFO_CAP_MSIX_MAPPABLE)) {
         return;
     }
@@ -2675,7 +2675,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
     g_autofree struct vfio_region_info *reg_info = NULL;
     int ret;
 
-    ret = vfio_get_region_info(vbasedev, VFIO_PCI_VGA_REGION_INDEX, &reg_info);
+    ret = vfio_device_get_region_info(vbasedev, VFIO_PCI_VGA_REGION_INDEX, &reg_info);
     if (ret) {
         error_setg_errno(errp, -ret,
                          "failed getting region info for VGA region index %d",
@@ -2773,7 +2773,7 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
         QLIST_INIT(&vdev->bars[i].quirks);
     }
 
-    ret = vfio_get_region_info(vbasedev,
+    ret = vfio_device_get_region_info(vbasedev,
                                VFIO_PCI_CONFIG_REGION_INDEX, &reg_info);
     if (ret) {
         error_setg_errno(errp, -ret, "failed to get config info");
@@ -2818,7 +2818,7 @@ static bool vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
 
 static void vfio_pci_put_device(VFIOPCIDevice *vdev)
 {
-    vfio_detach_device(&vdev->vbasedev);
+    vfio_device_detach(&vdev->vbasedev);
 
     g_free(vdev->vbasedev.name);
     g_free(vdev->msix);
@@ -2870,7 +2870,7 @@ static void vfio_register_err_notifier(VFIOPCIDevice *vdev)
     fd = event_notifier_get_fd(&vdev->err_notifier);
     qemu_set_fd_handler(fd, vfio_err_notifier_handler, NULL, vdev);
 
-    if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0,
+    if (!vfio_device_irq_set_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);
@@ -2887,7 +2887,7 @@ static void vfio_unregister_err_notifier(VFIOPCIDevice *vdev)
         return;
     }
 
-    if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_ERR_IRQ_INDEX, 0,
+    if (!vfio_device_irq_set_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);
     }
@@ -2935,7 +2935,7 @@ static void vfio_register_req_notifier(VFIOPCIDevice *vdev)
     fd = event_notifier_get_fd(&vdev->req_notifier);
     qemu_set_fd_handler(fd, vfio_req_notifier_handler, NULL, vdev);
 
-    if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0,
+    if (!vfio_device_irq_set_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);
@@ -2953,7 +2953,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
         return;
     }
 
-    if (!vfio_set_irq_signaling(&vdev->vbasedev, VFIO_PCI_REQ_IRQ_INDEX, 0,
+    if (!vfio_device_irq_set_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);
     }
@@ -3017,7 +3017,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
         name = g_strdup(vbasedev->name);
     }
 
-    if (!vfio_attach_device(name, vbasedev,
+    if (!vfio_device_attach(name, vbasedev,
                             pci_device_iommu_address_space(pdev), errp)) {
         goto error;
     }
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 83b53d57149a343a00eb6d6f78c1cbea004dbaa2..4217e870063593a5be840047adf2870e9b2b89e4 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -119,7 +119,7 @@ static int vfio_set_trigger_eventfd(VFIOINTp *intp,
 
     qemu_set_fd_handler(fd, (IOHandler *)handler, NULL, intp);
 
-    if (!vfio_set_irq_signaling(vbasedev, intp->pin, 0,
+    if (!vfio_device_irq_set_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);
@@ -301,7 +301,7 @@ static void vfio_platform_eoi(VFIODevice *vbasedev)
 
             if (vfio_irq_is_automasked(intp)) {
                 /* unmasks the physical level-sensitive IRQ */
-                vfio_unmask_single_irqindex(vbasedev, intp->pin);
+                vfio_device_irq_unmask(vbasedev, intp->pin);
             }
 
             /* a single IRQ can be active at a time */
@@ -357,7 +357,7 @@ static int vfio_set_resample_eventfd(VFIOINTp *intp)
     Error *err = NULL;
 
     qemu_set_fd_handler(fd, NULL, NULL, NULL);
-    if (!vfio_set_irq_signaling(vbasedev, intp->pin, 0,
+    if (!vfio_device_irq_set_signaling(vbasedev, intp->pin, 0,
                                 VFIO_IRQ_SET_ACTION_UNMASK, fd, &err)) {
         error_reportf_err(err, VFIO_MSG_PREFIX, vbasedev->name);
         return -EINVAL;
@@ -547,7 +547,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev, Error **errp)
         return false;
     }
 
-    if (!vfio_attach_device(vbasedev->name, vbasedev,
+    if (!vfio_device_attach(vbasedev->name, vbasedev,
                             &address_space_memory, errp)) {
         return false;
     }
@@ -556,7 +556,7 @@ static bool vfio_base_device_init(VFIODevice *vbasedev, Error **errp)
         return true;
     }
 
-    vfio_detach_device(vbasedev);
+    vfio_device_detach(vbasedev);
     return false;
 }
 
diff --git a/hw/vfio/region.c b/hw/vfio/region.c
index ade4466eb622248b5aa50f9df7e5c683bfa78a11..669dc098357050932b9e74ad213ff56b62a0b88e 100644
--- a/hw/vfio/region.c
+++ b/hw/vfio/region.c
@@ -186,7 +186,7 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev, VFIORegion *region,
     g_autofree struct vfio_region_info *info = NULL;
     int ret;
 
-    ret = vfio_get_region_info(vbasedev, index, &info);
+    ret = vfio_device_get_region_info(vbasedev, index, &info);
     if (ret) {
         return ret;
     }
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index f3bdcebe938dcca77b913ef81a74644c622b5d8a..39d4947f94dc61e4cff06fe1a6181066e7fc4dc3 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -37,8 +37,6 @@ vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, int
 vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot reset: %s"
 vfio_populate_device_config(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device '%s' config: size: 0x%lx, offset: 0x%lx, flags: 0x%lx"
 vfio_populate_device_get_irq_info_failure(const char *errstr) "VFIO_DEVICE_GET_IRQ_INFO failure: %s"
-vfio_attach_device(const char *name, int group_id) " (%s) group %d"
-vfio_detach_device(const char *name, int group_id) " (%s) group %d"
 vfio_mdev(const char *name, bool is_mdev) " (%s) is_mdev %d"
 vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) "%s 0x%x@0x%x"
 vfio_pci_reset(const char *name) " (%s)"
@@ -197,4 +195,6 @@ iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int functi
 vfio_reset_handler(void) ""
 
 # device.c
-vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%08x"
+vfio_device_get_region_info_type(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%08x"
+vfio_device_attach(const char *name, int group_id) " (%s) group %d"
+vfio_device_detach(const char *name, int group_id) " (%s) group %d"
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (26 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 27/32] vfio: Rename VFIODevice related services Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 12:14   ` Joao Martins
  2025-03-19 16:54   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 29/32] vfio: Rename VFIOContainer related services Cédric Le Goater
                   ` (3 subsequent siblings)
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

vfio_devices_query_dirty_bitmap() is only used in "dirty-tracking.c".

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/dirty-tracking.h | 3 ---
 hw/vfio/dirty-tracking.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
index 4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a..322af30b0d5370600719594d4aed4c407f7d2295 100644
--- a/hw/vfio/dirty-tracking.h
+++ b/hw/vfio/dirty-tracking.h
@@ -13,9 +13,6 @@ extern const MemoryListener vfio_memory_listener;
 
 bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *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,
-                                    Error **errp);
 int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
                           uint64_t size, ram_addr_t ram_addr, Error **errp);
 
diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
index 143cc5cf62b0165565e91f8a2ca166026f16b1eb..9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1 100644
--- a/hw/vfio/dirty-tracking.c
+++ b/hw/vfio/dirty-tracking.c
@@ -1016,7 +1016,7 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova,
     return 0;
 }
 
-int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
+static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
                  VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
 {
     VFIODevice *vbasedev;
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 29/32] vfio: Rename VFIOContainer related services
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (27 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-20  9:38   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services Cédric Le Goater
                   ` (2 subsequent siblings)
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Rename these routines :

  vfio_put_group -> vfio_group_put
  vfio_get_group -> vfio_group_get
  vfio_kvm_device_del_group -> vfio_group_del_kvm_device
  vfio_kvm_device_add_group -> vfio_group_add_kvm_device
  vfio_get_device -> vfio_device_get
  vfio_put_base_device -> vfio_device_put
  vfio_device_groupid -> vfio_device_get_groupid
  vfio_connect_container -> vfio_container_connect
  vfio_disconnect_container -> vfio_container_disconnect

to better reflect the namespace they belong to.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/container.c  | 52 ++++++++++++++++++++++----------------------
 hw/vfio/trace-events | 10 +++++----
 2 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 77e2934511a2917f6f7cf13f60c8f3ce4a493035..40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -306,7 +306,7 @@ static bool vfio_get_info_iova_range(struct vfio_iommu_type1_info *info,
     return true;
 }
 
-static void vfio_kvm_device_add_group(VFIOGroup *group)
+static void vfio_group_add_kvm_device(VFIOGroup *group)
 {
     Error *err = NULL;
 
@@ -315,7 +315,7 @@ static void vfio_kvm_device_add_group(VFIOGroup *group)
     }
 }
 
-static void vfio_kvm_device_del_group(VFIOGroup *group)
+static void vfio_group_del_kvm_device(VFIOGroup *group)
 {
     Error *err = NULL;
 
@@ -511,7 +511,7 @@ static bool vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp)
     return true;
 }
 
-static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
+static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
                                    Error **errp)
 {
     VFIOContainer *container;
@@ -569,7 +569,7 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
             }
             group->container = container;
             QLIST_INSERT_HEAD(&container->group_list, group, container_next);
-            vfio_kvm_device_add_group(group);
+            vfio_group_add_kvm_device(group);
             return true;
         }
     }
@@ -609,7 +609,7 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
         goto enable_discards_exit;
     }
 
-    vfio_kvm_device_add_group(group);
+    vfio_group_add_kvm_device(group);
 
     vfio_address_space_insert(space, bcontainer);
 
@@ -630,7 +630,7 @@ static bool vfio_connect_container(VFIOGroup *group, AddressSpace *as,
     return true;
 listener_release_exit:
     QLIST_REMOVE(group, container_next);
-    vfio_kvm_device_del_group(group);
+    vfio_group_del_kvm_device(group);
     memory_listener_unregister(&bcontainer->listener);
     if (vioc->release) {
         vioc->release(bcontainer);
@@ -654,7 +654,7 @@ put_space_exit:
     return false;
 }
 
-static void vfio_disconnect_container(VFIOGroup *group)
+static void vfio_container_disconnect(VFIOGroup *group)
 {
     VFIOContainer *container = group->container;
     VFIOContainerBase *bcontainer = &container->bcontainer;
@@ -683,7 +683,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
     if (QLIST_EMPTY(&container->group_list)) {
         VFIOAddressSpace *space = bcontainer->space;
 
-        trace_vfio_disconnect_container(container->fd);
+        trace_vfio_container_disconnect(container->fd);
         vfio_cpr_unregister_container(bcontainer);
         close(container->fd);
         object_unref(container);
@@ -692,7 +692,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
     }
 }
 
-static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
+static VFIOGroup *vfio_group_get(int groupid, AddressSpace *as, Error **errp)
 {
     ERRP_GUARD();
     VFIOGroup *group;
@@ -736,7 +736,7 @@ static VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
     group->groupid = groupid;
     QLIST_INIT(&group->device_list);
 
-    if (!vfio_connect_container(group, as, errp)) {
+    if (!vfio_container_connect(group, as, errp)) {
         error_prepend(errp, "failed to setup container for group %d: ",
                       groupid);
         goto close_fd_exit;
@@ -755,7 +755,7 @@ free_group_exit:
     return NULL;
 }
 
-static void vfio_put_group(VFIOGroup *group)
+static void vfio_group_put(VFIOGroup *group)
 {
     if (!group || !QLIST_EMPTY(&group->device_list)) {
         return;
@@ -764,15 +764,15 @@ static void vfio_put_group(VFIOGroup *group)
     if (!group->ram_block_discard_allowed) {
         vfio_ram_block_discard_disable(group->container, false);
     }
-    vfio_kvm_device_del_group(group);
-    vfio_disconnect_container(group);
+    vfio_group_del_kvm_device(group);
+    vfio_container_disconnect(group);
     QLIST_REMOVE(group, next);
-    trace_vfio_put_group(group->fd);
+    trace_vfio_group_put(group->fd);
     close(group->fd);
     g_free(group);
 }
 
-static bool vfio_get_device(VFIOGroup *group, const char *name,
+static bool vfio_device_get(VFIOGroup *group, const char *name,
                             VFIODevice *vbasedev, Error **errp)
 {
     g_autofree struct vfio_device_info *info = NULL;
@@ -824,25 +824,25 @@ static bool vfio_get_device(VFIOGroup *group, const char *name,
     vbasedev->num_regions = info->num_regions;
     vbasedev->flags = info->flags;
 
-    trace_vfio_get_device(name, info->flags, info->num_regions, info->num_irqs);
+    trace_vfio_device_get(name, info->flags, info->num_regions, info->num_irqs);
 
     vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET);
 
     return true;
 }
 
-static void vfio_put_base_device(VFIODevice *vbasedev)
+static void vfio_device_put(VFIODevice *vbasedev)
 {
     if (!vbasedev->group) {
         return;
     }
     QLIST_REMOVE(vbasedev, next);
     vbasedev->group = NULL;
-    trace_vfio_put_base_device(vbasedev->fd);
+    trace_vfio_device_put(vbasedev->fd);
     close(vbasedev->fd);
 }
 
-static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp)
+static int vfio_device_get_groupid(VFIODevice *vbasedev, Error **errp)
 {
     char *tmp, group_path[PATH_MAX];
     g_autofree char *group_name = NULL;
@@ -877,7 +877,7 @@ static int vfio_device_groupid(VFIODevice *vbasedev, Error **errp)
 static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
                                       AddressSpace *as, Error **errp)
 {
-    int groupid = vfio_device_groupid(vbasedev, errp);
+    int groupid = vfio_device_get_groupid(vbasedev, errp);
     VFIODevice *vbasedev_iter;
     VFIOGroup *group;
     VFIOContainerBase *bcontainer;
@@ -892,7 +892,7 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
         return false;
     }
 
-    group = vfio_get_group(groupid, as, errp);
+    group = vfio_group_get(groupid, as, errp);
     if (!group) {
         return false;
     }
@@ -900,12 +900,12 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
     QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
         if (strcmp(vbasedev_iter->name, vbasedev->name) == 0) {
             error_setg(errp, "device is already attached");
-            vfio_put_group(group);
+            vfio_group_put(group);
             return false;
         }
     }
-    if (!vfio_get_device(group, name, vbasedev, errp)) {
-        vfio_put_group(group);
+    if (!vfio_device_get(group, name, vbasedev, errp)) {
+        vfio_group_put(group);
         return false;
     }
 
@@ -925,8 +925,8 @@ static void vfio_legacy_detach_device(VFIODevice *vbasedev)
     QLIST_REMOVE(vbasedev, container_next);
     vbasedev->bcontainer = NULL;
     trace_vfio_device_detach(vbasedev->name, group->groupid);
-    vfio_put_base_device(vbasedev);
-    vfio_put_group(group);
+    vfio_device_put(vbasedev);
+    vfio_group_put(group);
 }
 
 static int vfio_legacy_pci_hot_reset(VFIODevice *vbasedev, bool single)
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index 39d4947f94dc61e4cff06fe1a6181066e7fc4dc3..512f4913b72d9a1e8a04df24318a4947fa361e28 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -99,10 +99,6 @@ vfio_listener_region_add_no_dma_map(const char *name, uint64_t iova, uint64_t si
 vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRIx64" - 0x%"PRIx64
 vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64" - 0x%"PRIx64"]"
 vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci) "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"], pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
-vfio_disconnect_container(int fd) "close container->fd=%d"
-vfio_put_group(int fd) "close group->fd=%d"
-vfio_get_device(const char * name, unsigned int flags, unsigned int num_regions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u"
-vfio_put_base_device(int fd) "close vdev->fd=%d"
 vfio_legacy_dma_unmap_overflow_workaround(void) ""
 vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
@@ -194,6 +190,12 @@ iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int functi
 # container-base.c
 vfio_reset_handler(void) ""
 
+# container.c
+vfio_container_disconnect(int fd) "close container->fd=%d"
+vfio_group_put(int fd) "close group->fd=%d"
+vfio_device_get(const char * name, unsigned int flags, unsigned int num_regions, unsigned int num_irqs) "Device %s flags: %u, regions: %u, irqs: %u"
+vfio_device_put(int fd) "close vdev->fd=%d"
+
 # device.c
 vfio_device_get_region_info_type(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%08x"
 vfio_device_attach(const char *name, int group_id) " (%s) group %d"
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (28 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 29/32] vfio: Rename VFIOContainer related services Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 12:21   ` Joao Martins
  2025-03-20  9:42   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines Cédric Le Goater
  2025-03-18  9:54 ` [PATCH for-10.1 32/32] vfio: Rename RAM discard related services Cédric Le Goater
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Rename these routines :

  vfio_devices_all_device_dirty_tracking_started -> vfio_dirty_tracking_devices_is_started_all
  vfio_devices_all_dirty_tracking_started        -> vfio_dirty_tracking_devices_is_started
  vfio_devices_all_device_dirty_tracking         -> vfio_dirty_tracking_devices_is_supported
  vfio_devices_dma_logging_start                 -> vfio_dirty_tracking_devices_dma_logging_start
  vfio_devices_dma_logging_stop                  -> vfio_dirty_tracking_devices_dma_logging_stop
  vfio_devices_query_dirty_bitmap                -> vfio_dirty_tracking_devices_query_dirty_bitmap
  vfio_get_dirty_bitmap                          -> vfio_dirty_tracking_query_dirty_bitmap

to better reflect the namespace they belong to.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/dirty-tracking.h |  6 +++---
 hw/vfio/container.c      |  6 +++---
 hw/vfio/dirty-tracking.c | 44 ++++++++++++++++++++--------------------
 hw/vfio/trace-events     |  2 +-
 4 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
--- a/hw/vfio/dirty-tracking.h
+++ b/hw/vfio/dirty-tracking.h
@@ -11,9 +11,9 @@
 
 extern const MemoryListener vfio_memory_listener;
 
-bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *bcontainer);
-bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);
-int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
+bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer);
+bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer);
+int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
                           uint64_t size, ram_addr_t ram_addr, Error **errp);
 
 #endif /* HW_VFIO_DIRTY_TRACKING_H */
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -138,8 +138,8 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
     int ret;
     Error *local_err = NULL;
 
-    if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
-        if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
+    if (iotlb && vfio_dirty_tracking_devices_is_started(bcontainer)) {
+        if (!vfio_dirty_tracking_devices_is_supported(bcontainer) &&
             bcontainer->dirty_pages_supported) {
             return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
         }
@@ -170,7 +170,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
     }
 
     if (need_dirty_sync) {
-        ret = vfio_get_dirty_bitmap(bcontainer, iova, size,
+        ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, size,
                                     iotlb->translated_addr, &local_err);
         if (ret) {
             error_report_err(local_err);
diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
--- a/hw/vfio/dirty-tracking.c
+++ b/hw/vfio/dirty-tracking.c
@@ -45,7 +45,7 @@
  * Device state interfaces
  */
 
-static bool vfio_devices_all_device_dirty_tracking_started(
+static bool vfio_dirty_tracking_devices_is_started_all(
     const VFIOContainerBase *bcontainer)
 {
     VFIODevice *vbasedev;
@@ -59,10 +59,9 @@ static bool vfio_devices_all_device_dirty_tracking_started(
     return true;
 }
 
-bool vfio_devices_all_dirty_tracking_started(
-    const VFIOContainerBase *bcontainer)
+bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer)
 {
-    return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
+    return vfio_dirty_tracking_devices_is_started_all(bcontainer) ||
            bcontainer->dirty_pages_started;
 }
 
@@ -70,7 +69,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase *bcontainer)
 {
     VFIODevice *vbasedev;
 
-    if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
+    if (!vfio_dirty_tracking_devices_is_started(bcontainer)) {
         return false;
     }
 
@@ -90,7 +89,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase *bcontainer)
     return true;
 }
 
-bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)
+bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer)
 {
     VFIODevice *vbasedev;
 
@@ -809,7 +808,7 @@ static void vfio_dirty_tracking_init(VFIOContainerBase *bcontainer,
     memory_listener_unregister(&dirty.listener);
 }
 
-static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
+static void vfio_dirty_tracking_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
 {
     uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
                               sizeof(uint64_t))] = {};
@@ -907,7 +906,7 @@ static void vfio_device_feature_dma_logging_start_destroy(
     g_free(feature);
 }
 
-static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
+static bool vfio_dirty_tracking_devices_dma_logging_start(VFIOContainerBase *bcontainer,
                                           Error **errp)
 {
     struct vfio_device_feature *feature;
@@ -940,7 +939,7 @@ static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
 
 out:
     if (ret) {
-        vfio_devices_dma_logging_stop(bcontainer);
+        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
     }
 
     vfio_device_feature_dma_logging_start_destroy(feature);
@@ -956,8 +955,8 @@ static bool vfio_listener_log_global_start(MemoryListener *listener,
                                                  listener);
     bool ret;
 
-    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
-        ret = vfio_devices_dma_logging_start(bcontainer, errp);
+    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
+        ret = vfio_dirty_tracking_devices_dma_logging_start(bcontainer, errp);
     } else {
         ret = vfio_container_set_dirty_page_tracking(bcontainer, true, errp) == 0;
     }
@@ -975,8 +974,8 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)
     Error *local_err = NULL;
     int ret = 0;
 
-    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
-        vfio_devices_dma_logging_stop(bcontainer);
+    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
+        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
     } else {
         ret = vfio_container_set_dirty_page_tracking(bcontainer, false,
                                                      &local_err);
@@ -1016,7 +1015,7 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova,
     return 0;
 }
 
-static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
+static int vfio_dirty_tracking_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
                  VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
 {
     VFIODevice *vbasedev;
@@ -1038,11 +1037,11 @@ static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
     return 0;
 }
 
-int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
+int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
                           uint64_t size, ram_addr_t ram_addr, Error **errp)
 {
     bool all_device_dirty_tracking =
-        vfio_devices_all_device_dirty_tracking(bcontainer);
+        vfio_dirty_tracking_devices_is_supported(bcontainer);
     uint64_t dirty_pages;
     VFIOBitmap vbmap;
     int ret;
@@ -1062,8 +1061,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
     }
 
     if (all_device_dirty_tracking) {
-        ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
-                                              errp);
+        ret = vfio_dirty_tracking_devices_query_dirty_bitmap(bcontainer, &vbmap,
+                                                             iova, size, errp);
     } else {
         ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
                                                 errp);
@@ -1076,7 +1075,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
     dirty_pages = cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap, ram_addr,
                                                          vbmap.pages);
 
-    trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pages);
+    trace_vfio_dirty_tracking_query_dirty_bitmap(iova, size, vbmap.size, ram_addr,
+                                                 dirty_pages);
 out:
     g_free(vbmap.bitmap);
 
@@ -1113,7 +1113,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
         goto out_unlock;
     }
 
-    ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
+    ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
                                 translated_addr, &local_err);
     if (ret) {
         error_prepend(&local_err,
@@ -1147,7 +1147,7 @@ static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
      * Sync the whole mapped region (spanning multiple individual mappings)
      * in one go.
      */
-    ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
+    ret = vfio_dirty_tracking_query_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
                                 &local_err);
     if (ret) {
         error_report_err(local_err);
@@ -1241,7 +1241,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer,
     ram_addr = memory_region_get_ram_addr(section->mr) +
                section->offset_within_region;
 
-    return vfio_get_dirty_bitmap(bcontainer,
+    return vfio_dirty_tracking_query_dirty_bitmap(bcontainer,
                    REAL_HOST_PAGE_ALIGN(section->offset_within_address_space),
                                  int128_get64(section->size), ram_addr, errp);
 }
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -100,7 +100,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRIx64" -
 vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64" - 0x%"PRIx64"]"
 vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci) "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"], pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
 vfio_legacy_dma_unmap_overflow_workaround(void) ""
-vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
+vfio_dirty_tracking_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
 
 # region.c
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (29 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 13:24   ` Joao Martins
  2025-03-20  9:49   ` John Levon
  2025-03-18  9:54 ` [PATCH for-10.1 32/32] vfio: Rename RAM discard related services Cédric Le Goater
  31 siblings, 2 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

This hides the MemoryListener implementation and makes the code common
to both IOMMU backends, legacy and IOMMUFD.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/dirty-tracking.h |  4 ++--
 hw/vfio/container.c      | 11 +++--------
 hw/vfio/dirty-tracking.c | 21 ++++++++++++++++++++-
 hw/vfio/iommufd.c        |  9 ++-------
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
index db9494202a780108ce78b642950bfed78ba3f253..6d717f0e918e47e341114c82ffc2cf520fc7b079 100644
--- a/hw/vfio/dirty-tracking.h
+++ b/hw/vfio/dirty-tracking.h
@@ -9,11 +9,11 @@
 #ifndef HW_VFIO_DIRTY_TRACKING_H
 #define HW_VFIO_DIRTY_TRACKING_H
 
-extern const MemoryListener vfio_memory_listener;
-
 bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer);
 bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer);
 int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
                           uint64_t size, ram_addr_t ram_addr, Error **errp);
+bool vfio_dirty_tracking_register(VFIOContainerBase *bcontainer, Error **errp);
+void vfio_dirty_tracking_unregister(VFIOContainerBase *bcontainer);
 
 #endif /* HW_VFIO_DIRTY_TRACKING_H */
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 7b3ec798a77052b8cb0b47d3dceaca1428cb50bd..1fcca75caba19353ad3063ae97b20c15f61564e9 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -616,12 +616,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
     group->container = container;
     QLIST_INSERT_HEAD(&container->group_list, group, container_next);
 
-    bcontainer->listener = 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_dirty_tracking_register(bcontainer, errp)) {
         goto listener_release_exit;
     }
 
@@ -631,7 +626,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
 listener_release_exit:
     QLIST_REMOVE(group, container_next);
     vfio_group_del_kvm_device(group);
-    memory_listener_unregister(&bcontainer->listener);
+    vfio_dirty_tracking_unregister(bcontainer);
     if (vioc->release) {
         vioc->release(bcontainer);
     }
@@ -669,7 +664,7 @@ static void vfio_container_disconnect(VFIOGroup *group)
      * group.
      */
     if (QLIST_EMPTY(&container->group_list)) {
-        memory_listener_unregister(&bcontainer->listener);
+        vfio_dirty_tracking_unregister(bcontainer);
         if (vioc->release) {
             vioc->release(bcontainer);
         }
diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644
--- a/hw/vfio/dirty-tracking.c
+++ b/hw/vfio/dirty-tracking.c
@@ -1267,7 +1267,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,
     }
 }
 
-const MemoryListener vfio_memory_listener = {
+static const MemoryListener vfio_memory_listener = {
     .name = "vfio",
     .region_add = vfio_listener_region_add,
     .region_del = vfio_listener_region_del,
@@ -1275,3 +1275,22 @@ const MemoryListener vfio_memory_listener = {
     .log_global_stop = vfio_listener_log_global_stop,
     .log_sync = vfio_listener_log_sync,
 };
+
+bool vfio_dirty_tracking_register(VFIOContainerBase *bcontainer, Error **errp)
+{
+    bcontainer->listener = 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_dirty_tracking_unregister(VFIOContainerBase *bcontainer)
+{
+    memory_listener_unregister(&bcontainer->listener);
+}
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 7f354d86cd14270a70dc990860ad5b69f0310719..7737d552f310c54ae2e035198a1a83da8c3199dd 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -411,7 +411,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDContainer *container)
     if (!QLIST_EMPTY(&bcontainer->device_list)) {
         return;
     }
-    memory_listener_unregister(&bcontainer->listener);
+    vfio_dirty_tracking_unregister(bcontainer);
     iommufd_backend_free_id(container->be, container->ioas_id);
     object_unref(container);
 }
@@ -563,12 +563,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
         bcontainer->pgsizes = qemu_real_host_page_size();
     }
 
-    bcontainer->listener = 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_dirty_tracking_register(bcontainer, errp)) {
         goto err_listener_register;
     }
 
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* [PATCH for-10.1 32/32] vfio: Rename RAM discard related services
  2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
                   ` (30 preceding siblings ...)
  2025-03-18  9:54 ` [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines Cédric Le Goater
@ 2025-03-18  9:54 ` Cédric Le Goater
  2025-03-19 16:57   ` John Levon
  31 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-18  9:54 UTC (permalink / raw)
  To: qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, Cédric Le Goater

Rename some routines to better reflect the namespace they belong to.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/dirty-tracking.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
index d7827f7b64adf3e2b41fafd59aab71e0b28c1567..50699a411de3ecd7424a48c7bb583ce39370a296 100644
--- a/hw/vfio/dirty-tracking.c
+++ b/hw/vfio/dirty-tracking.c
@@ -262,7 +262,7 @@ static int vfio_ram_discard_notify_populate(RamDiscardListener *rdl,
     return 0;
 }
 
-static void vfio_register_ram_discard_listener(VFIOContainerBase *bcontainer,
+static void  vfio_ram_discard_register_listener(VFIOContainerBase *bcontainer,
                                                MemoryRegionSection *section)
 {
     RamDiscardManager *rdm = memory_region_get_ram_discard_manager(section->mr);
@@ -337,7 +337,7 @@ static void vfio_register_ram_discard_listener(VFIOContainerBase *bcontainer,
     }
 }
 
-static void vfio_unregister_ram_discard_listener(VFIOContainerBase *bcontainer,
+static void  vfio_ram_discard_unregister_listener(VFIOContainerBase *bcontainer,
                                                  MemoryRegionSection *section)
 {
     RamDiscardManager *rdm = memory_region_get_ram_discard_manager(section->mr);
@@ -524,7 +524,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
      * about changes.
      */
     if (memory_region_has_ram_discard_manager(section->mr)) {
-        vfio_register_ram_discard_listener(bcontainer, section);
+        vfio_ram_discard_register_listener(bcontainer, section);
         return;
     }
 
@@ -647,7 +647,7 @@ static void vfio_listener_region_del(MemoryListener *listener,
         pgmask = (1ULL << ctz64(bcontainer->pgsizes)) - 1;
         try_unmap = !((iova & pgmask) || (int128_get64(llsize) & pgmask));
     } else if (memory_region_has_ram_discard_manager(section->mr)) {
-        vfio_unregister_ram_discard_listener(bcontainer, section);
+        vfio_ram_discard_unregister_listener(bcontainer, section);
         /* Unregistering will trigger an unmap. */
         try_unmap = false;
     }
@@ -1132,7 +1132,7 @@ out:
     }
 }
 
-static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
+static int vfio_ram_discard_query_dirty_bitmap(MemoryRegionSection *section,
                                              void *opaque)
 {
     const hwaddr size = int128_get64(section->size);
@@ -1179,7 +1179,7 @@ vfio_sync_ram_discard_listener_dirty_bitmap(VFIOContainerBase *bcontainer,
      * which correspond to populated parts. Replay all populated parts.
      */
     return ram_discard_manager_replay_populated(rdm, section,
-                                              vfio_ram_discard_get_dirty_bitmap,
+                                                vfio_ram_discard_query_dirty_bitmap,
                                                 &vrdl);
 }
 
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred()
  2025-03-18  9:53 ` [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred() Cédric Le Goater
@ 2025-03-19  7:33   ` Philippe Mathieu-Daudé
  2025-03-19  9:10   ` John Levon
  2025-03-19 12:07   ` Avihai Horon
  2 siblings, 0 replies; 114+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-03-19  7:33 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan

On 18/3/25 10:53, Cédric Le Goater wrote:
> Enforce a 'vfio_mig_' prefix for the VFIO migration API to better
> reflect the namespace these routines belong to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   include/hw/vfio/vfio-common.h | 2 +-
>   hw/vfio/migration.c           | 2 +-
>   migration/target.c            | 2 +-
>   3 files changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations
  2025-03-18  9:53 ` [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations Cédric Le Goater
@ 2025-03-19  9:09   ` John Levon
  2025-03-20  9:18   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19  9:09 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:52AM +0100, Cédric Le Goater wrote:

> Gather all VFIOIOMMUFD related declarations into "iommufd.h" to
> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c
  2025-03-18  9:53 ` [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c Cédric Le Goater
@ 2025-03-19  9:10   ` John Levon
  2025-03-19 11:54   ` Avihai Horon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19  9:10 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:44AM +0100, Cédric Le Goater wrote:

> vfio_mig_active() is part of the VFIO migration API. Move the
> definitions where VFIO migration is implemented.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred()
  2025-03-18  9:53 ` [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred() Cédric Le Goater
  2025-03-19  7:33   ` Philippe Mathieu-Daudé
@ 2025-03-19  9:10   ` John Levon
  2025-03-19 12:07   ` Avihai Horon
  2 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19  9:10 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:45AM +0100, Cédric Le Goater wrote:

> Enforce a 'vfio_mig_' prefix for the VFIO migration API to better
> reflect the namespace these routines belong to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files
  2025-03-18  9:53 ` [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files Cédric Le Goater
@ 2025-03-19  9:10   ` John Levon
  2025-03-20  9:36   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19  9:10 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:57AM +0100, Cédric Le Goater wrote:

> These definitions don't have any use outside of their respective
> submodules. There is no need to expose them externally. Keep them
> private.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services
  2025-03-18  9:53 ` [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services Cédric Le Goater
@ 2025-03-19 11:48   ` Prasad Pandit
  2025-03-19 12:37   ` Avihai Horon
  1 sibling, 0 replies; 114+ messages in thread
From: Prasad Pandit @ 2025-03-19 11:48 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, 18 Mar 2025 at 15:29, Cédric Le Goater <clg@redhat.com> wrote:
> The migration core subsytem makes uses of the VFIO migration API to

* subsytem -> subsystem
* uses -> use

> collect statistics on the number of bytes transferred.

* statistics on the bytes transferred  (number of seems redundant)  OR
 statistics of bytes transferred.

> These services are declared in "hw/vfio/vfio-common.h" which also
> contains VFIO internal declarations. Move the migration declarations
> into a new header file "hw/vfio/vfio-migration.h" to reduce the exposure
> of VFIO internals.
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>  include/hw/vfio/vfio-common.h    |  4 ----
>  include/hw/vfio/vfio-migration.h | 17 +++++++++++++++++
>  hw/vfio/migration-multifd.c      |  1 +
>  hw/vfio/migration.c              |  1 +
>  migration/target.c               |  2 +-
>  5 files changed, 20 insertions(+), 5 deletions(-)
>  create mode 100644 include/hw/vfio/vfio-migration.h
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -290,13 +290,9 @@ extern VFIODeviceList vfio_device_list;
>  extern const MemoryListener vfio_memory_listener;
>  extern int vfio_kvm_device_fd;
>
> -bool vfio_mig_active(void);
>  int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
>  void vfio_unblock_multiple_devices_migration(void);
>  bool vfio_viommu_preset(VFIODevice *vbasedev);
> -int64_t vfio_mig_bytes_transferred(void);
> -void vfio_mig_reset_bytes_transferred(void);
> -void vfio_mig_add_bytes_transferred(unsigned long val);
>  bool vfio_device_state_is_running(VFIODevice *vbasedev);
>  bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
>
> diff --git a/include/hw/vfio/vfio-migration.h b/include/hw/vfio/vfio-migration.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
> --- /dev/null
> +++ b/include/hw/vfio/vfio-migration.h
> @@ -0,0 +1,17 @@
> +/*
> + * VFIO migration interface
> + *
> + * Copyright Red Hat, Inc. 2025
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef HW_VFIO_VFIO_MIGRATION_H
> +#define HW_VFIO_VFIO_MIGRATION_H
> +
> +bool vfio_mig_active(void);
> +int64_t vfio_mig_bytes_transferred(void);
> +void vfio_mig_reset_bytes_transferred(void);
> +void vfio_mig_add_bytes_transferred(unsigned long val);
> +
> +#endif /* HW_VFIO_VFIO_MIGRATION_H */
> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
> index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
> --- a/hw/vfio/migration-multifd.c
> +++ b/hw/vfio/migration-multifd.c
> @@ -11,6 +11,7 @@
>
>  #include "qemu/osdep.h"
>  #include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-migration.h"
>  #include "migration/misc.h"
>  #include "qapi/error.h"
>  #include "qemu/bswap.h"
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -17,6 +17,7 @@
>
>  #include "system/runstate.h"
>  #include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-migration.h"
>  #include "migration/misc.h"
>  #include "migration/savevm.h"
>  #include "migration/vmstate.h"
> diff --git a/migration/target.c b/migration/target.c
> index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
> --- a/migration/target.c
> +++ b/migration/target.c
> @@ -11,7 +11,7 @@
>  #include CONFIG_DEVICES
>
>  #ifdef CONFIG_VFIO
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-migration.h"
>  #endif
>
>  #ifdef CONFIG_VFIO
> --
> 2.48.1

* Looks okay. With above text corrections, reviewed by:  Prasad Pandit
<pjp@fedoraproject.org>

Thank you.
---
  - Prasad



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c
  2025-03-18  9:53 ` [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c Cédric Le Goater
  2025-03-19  9:10   ` John Levon
@ 2025-03-19 11:54   ` Avihai Horon
  2025-03-19 16:38     ` Cédric Le Goater
  1 sibling, 1 reply; 114+ messages in thread
From: Avihai Horon @ 2025-03-19 11:54 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Eric Auger, Zhenzhong Duan


On 18/03/2025 11:53, Cédric Le Goater wrote:
> External email: Use caution opening links or attachments
>
>
> vfio_mig_active() is part of the VFIO migration API. Move the
> definitions where VFIO migration is implemented.
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Avihai Horon <avihaih@nvidia.com>

One nit below though.

> ---
>   hw/vfio/common.c    | 16 ----------------
>   hw/vfio/migration.c | 16 ++++++++++++++++
>   2 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 1a0d9290f88c9774a98f65087a36b86922b21a73..4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -66,22 +66,6 @@ int vfio_kvm_device_fd = -1;
>    * Device state interfaces
>    */
>
> -bool vfio_mig_active(void)
> -{
> -    VFIODevice *vbasedev;
> -
> -    if (QLIST_EMPTY(&vfio_device_list)) {
> -        return false;
> -    }
> -
> -    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
> -        if (vbasedev->migration_blocker) {
> -            return false;
> -        }
> -    }
> -    return true;
> -}
> -
>   static Error *multiple_devices_migration_blocker;
>
>   /*
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index fbff46cfc35e0ee69e9599c9f8efc7437bbe3370..b5fb0d218808d010d8210612d3182dde8f33514b 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -1062,6 +1062,22 @@ void vfio_mig_add_bytes_transferred(unsigned long val)
>       qatomic_add(&bytes_transferred, val);
>   }
>
> +bool vfio_mig_active(void)

We already have vfio_migration_* prefix in this file.
I'd say let's use it and rename to vfio_migration_is_active?

Thanks.

> +{
> +    VFIODevice *vbasedev;
> +
> +    if (QLIST_EMPTY(&vfio_device_list)) {
> +        return false;
> +    }
> +
> +    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
> +        if (vbasedev->migration_blocker) {
> +            return false;
> +        }
> +    }
> +    return true;
> +}
> +
>   /*
>    * Return true when either migration initialized or blocker registered.
>    * Currently only return false when adding blocker fails which will
> --
> 2.48.1
>


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred()
  2025-03-18  9:53 ` [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred() Cédric Le Goater
  2025-03-19  7:33   ` Philippe Mathieu-Daudé
  2025-03-19  9:10   ` John Levon
@ 2025-03-19 12:07   ` Avihai Horon
  2 siblings, 0 replies; 114+ messages in thread
From: Avihai Horon @ 2025-03-19 12:07 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Eric Auger, Zhenzhong Duan


On 18/03/2025 11:53, Cédric Le Goater wrote:
> External email: Use caution opening links or attachments
>
>
> Enforce a 'vfio_mig_' prefix for the VFIO migration API to better
> reflect the namespace these routines belong to.
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Avihai Horon <avihaih@nvidia.com>

Same nit as patch #1, maybe use vfio_migration_* prefix instead of vfio_mig_*?

Thanks.

> ---
>   include/hw/vfio/vfio-common.h | 2 +-
>   hw/vfio/migration.c           | 2 +-
>   migration/target.c            | 2 +-
>   3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 04b123a6c929a8f47d740fc5433b54dadd32f731..9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -295,7 +295,7 @@ int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
>   void vfio_unblock_multiple_devices_migration(void);
>   bool vfio_viommu_preset(VFIODevice *vbasedev);
>   int64_t vfio_mig_bytes_transferred(void);
> -void vfio_reset_bytes_transferred(void);
> +void vfio_mig_reset_bytes_transferred(void);
>   void vfio_mig_add_bytes_transferred(unsigned long val);
>   bool vfio_device_state_is_running(VFIODevice *vbasedev);
>   bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index b5fb0d218808d010d8210612d3182dde8f33514b..8bf65b8e11094b8363692dba3084b762362c7dd6 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -1052,7 +1052,7 @@ int64_t vfio_mig_bytes_transferred(void)
>       return MIN(qatomic_read(&bytes_transferred), INT64_MAX);
>   }
>
> -void vfio_reset_bytes_transferred(void)
> +void vfio_mig_reset_bytes_transferred(void)
>   {
>       qatomic_set(&bytes_transferred, 0);
>   }
> diff --git a/migration/target.c b/migration/target.c
> index a6ffa9a5ce312d1e64157b650827aa726eb4d364..f5d8cfe7c2a3473f4bd3f5068145598c60973c58 100644
> --- a/migration/target.c
> +++ b/migration/target.c
> @@ -25,7 +25,7 @@ void migration_populate_vfio_info(MigrationInfo *info)
>
>   void migration_reset_vfio_bytes_transferred(void)
>   {
> -    vfio_reset_bytes_transferred();
> +    vfio_mig_reset_bytes_transferred();
>   }
>   #else
>   void migration_populate_vfio_info(MigrationInfo *info)
> --
> 2.48.1
>


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c
  2025-03-18  9:54 ` [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c Cédric Le Goater
@ 2025-03-19 12:12   ` Prasad Pandit
  2025-03-21 10:19     ` Cédric Le Goater
  2025-03-19 17:00   ` John Levon
  1 sibling, 1 reply; 114+ messages in thread
From: Prasad Pandit @ 2025-03-19 12:12 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, 18 Mar 2025 at 15:29, Cédric Le Goater <clg@redhat.com> wrote:
> This routine is related to VFIO migration. It belongs to "migration.c".
> While at it, rename it to better reflect the namespace it belongs to.
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>  hw/vfio/migration.h      |  1 +
>  hw/vfio/dirty-tracking.c | 19 +++++--------------
>  hw/vfio/migration.c      |  7 +++++++
>  3 files changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/hw/vfio/migration.h b/hw/vfio/migration.h
> index 7ad2141d06a7c97f034db908f9ce19fd06f415b9..9b57d7dc1a6c6143c19e1ee85807d036b1363624 100644
> --- a/hw/vfio/migration.h
> +++ b/hw/vfio/migration.h
> @@ -68,5 +68,6 @@ int vfio_migration_set_state(VFIODevice *vbasedev,
>                               enum vfio_device_mig_state recover_state,
>                               Error **errp);
>  #endif
> +void vfio_migration_set_error(int ret);
>
>  #endif /* HW_VFIO_MIGRATION_H */
> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
> index 441f9d9a08c06a88dda44ef143dcee5f0a89a900..447e09ed84993e3fbe1ed9b27a8269a9f0f46339 100644
> --- a/hw/vfio/dirty-tracking.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -35,8 +35,6 @@
>  #include "system/runstate.h"
>  #include "trace.h"
>  #include "qapi/error.h"
> -#include "migration/misc.h"
> -#include "migration/qemu-file.h"
>  #include "system/tcg.h"
>  #include "system/tpm.h"
>  #include "migration.h"
> @@ -47,13 +45,6 @@
>   * Device state interfaces
>   */
>
> -static void vfio_set_migration_error(int ret)
> -{
> -    if (migration_is_running()) {
> -        migration_file_set_error(ret, NULL);
> -    }
> -}
> -
>  static bool vfio_devices_all_device_dirty_tracking_started(
>      const VFIOContainerBase *bcontainer)
>  {
> @@ -175,7 +166,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>      if (iotlb->target_as != &address_space_memory) {
>          error_report("Wrong target AS \"%s\", only system memory is allowed",
>                       iotlb->target_as->name ? iotlb->target_as->name : "none");
> -        vfio_set_migration_error(-EINVAL);
> +        vfio_migration_set_error(-EINVAL);
>          return;
>      }
>
> @@ -212,7 +203,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>                           "0x%"HWADDR_PRIx") = %d (%s)",
>                           bcontainer, iova,
>                           iotlb->addr_mask + 1, ret, strerror(-ret));
> -            vfio_set_migration_error(ret);
> +            vfio_migration_set_error(ret);
>          }
>      }
>  out:
> @@ -995,7 +986,7 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)
>          error_prepend(&local_err,
>                        "vfio: Could not stop dirty page tracking - ");
>          error_report_err(local_err);
> -        vfio_set_migration_error(ret);
> +        vfio_migration_set_error(ret);
>      }
>  }
>
> @@ -1137,7 +1128,7 @@ out_unlock:
>
>  out:
>      if (ret) {
> -        vfio_set_migration_error(ret);
> +        vfio_migration_set_error(ret);
>      }
>  }
>
> @@ -1271,7 +1262,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,
>          ret = vfio_sync_dirty_bitmap(bcontainer, section, &local_err);
>          if (ret) {
>              error_report_err(local_err);
> -            vfio_set_migration_error(ret);
> +            vfio_migration_set_error(ret);
>          }
>      }
>  }
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 46c4cfecce25ba1146a1d8f2de0d7c51425afe8e..6fd825e435bde96d1008ec03dfaba25db3b616fc 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -1239,3 +1239,10 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
>      return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
>             migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
>  }
> +
> +void vfio_migration_set_error(int ret)
> +{
> +    if (migration_is_running()) {
> +        migration_file_set_error(ret, NULL);
> +    }
> +}
> --

* The change looks okay. But with the 'Error *err = NULL' parameter,
the error (ret) is also not passed on. Could we call
migration_file_set_error(ret, errp), instead of defining
'vfio_migration_set_error'? Because currently it accepts only one
'ret' parameter, later adding *errp to it would entail changing all
call sites.

Thank you.
---
  - Prasad



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static
  2025-03-18  9:54 ` [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static Cédric Le Goater
@ 2025-03-19 12:14   ` Joao Martins
  2025-03-19 16:54   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: Joao Martins @ 2025-03-19 12:14 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan

On 18/03/2025 09:54, Cédric Le Goater wrote:
> vfio_devices_query_dirty_bitmap() is only used in "dirty-tracking.c".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

> ---
>  hw/vfio/dirty-tracking.h | 3 ---
>  hw/vfio/dirty-tracking.c | 2 +-
>  2 files changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
> index 4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a..322af30b0d5370600719594d4aed4c407f7d2295 100644
> --- a/hw/vfio/dirty-tracking.h
> +++ b/hw/vfio/dirty-tracking.h
> @@ -13,9 +13,6 @@ extern const MemoryListener vfio_memory_listener;
>  
>  bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *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,
> -                                    Error **errp);
>  int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>                            uint64_t size, ram_addr_t ram_addr, Error **errp);
>  
> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
> index 143cc5cf62b0165565e91f8a2ca166026f16b1eb..9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1 100644
> --- a/hw/vfio/dirty-tracking.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -1016,7 +1016,7 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova,
>      return 0;
>  }
>  
> -int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
> +static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>                   VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>  {
>      VFIODevice *vbasedev;



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-18  9:54 ` [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services Cédric Le Goater
@ 2025-03-19 12:21   ` Joao Martins
  2025-03-20 11:13     ` Avihai Horon
  2025-03-21 11:22     ` Cédric Le Goater
  2025-03-20  9:42   ` John Levon
  1 sibling, 2 replies; 114+ messages in thread
From: Joao Martins @ 2025-03-19 12:21 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 18/03/2025 09:54, Cédric Le Goater wrote:
> Rename these routines :
> 
>   vfio_devices_all_device_dirty_tracking_started -> vfio_dirty_tracking_devices_is_started_all
>   vfio_devices_all_dirty_tracking_started        -> vfio_dirty_tracking_devices_is_started
>   vfio_devices_all_device_dirty_tracking         -> vfio_dirty_tracking_devices_is_supported
>   vfio_devices_dma_logging_start                 -> vfio_dirty_tracking_devices_dma_logging_start
>   vfio_devices_dma_logging_stop                  -> vfio_dirty_tracking_devices_dma_logging_stop
>   vfio_devices_query_dirty_bitmap                -> vfio_dirty_tracking_devices_query_dirty_bitmap
>   vfio_get_dirty_bitmap                          -> vfio_dirty_tracking_query_dirty_bitmap
> 
> to better reflect the namespace they belong to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

The change itself is fine.

But on the other hand, it looks relatively long names, no? I am bit at two minds
(as I generally prefer shorter code), but I can't find any alternatives if you
really wanna have one namespaces associated with the subsystem:file as a C
namespace.

Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
when talking about this stuff, but it seems a detour from the code style to
abbreviate namespaces into acronyms.

Having said that:

	Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
shorter.

> ---
>  hw/vfio/dirty-tracking.h |  6 +++---
>  hw/vfio/container.c      |  6 +++---
>  hw/vfio/dirty-tracking.c | 44 ++++++++++++++++++++--------------------
>  hw/vfio/trace-events     |  2 +-
>  4 files changed, 29 insertions(+), 29 deletions(-)
> 
> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
> index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
> --- a/hw/vfio/dirty-tracking.h
> +++ b/hw/vfio/dirty-tracking.h
> @@ -11,9 +11,9 @@
>  
>  extern const MemoryListener vfio_memory_listener;
>  
> -bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *bcontainer);
> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);
> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer);
> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer);
> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>                            uint64_t size, ram_addr_t ram_addr, Error **errp);
>  
>  #endif /* HW_VFIO_DIRTY_TRACKING_H */
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -138,8 +138,8 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
>      int ret;
>      Error *local_err = NULL;
>  
> -    if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
> -        if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
> +    if (iotlb && vfio_dirty_tracking_devices_is_started(bcontainer)) {
> +        if (!vfio_dirty_tracking_devices_is_supported(bcontainer) &&
>              bcontainer->dirty_pages_supported) {
>              return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
>          }
> @@ -170,7 +170,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
>      }
>  
>      if (need_dirty_sync) {
> -        ret = vfio_get_dirty_bitmap(bcontainer, iova, size,
> +        ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, size,
>                                      iotlb->translated_addr, &local_err);
>          if (ret) {
>              error_report_err(local_err);
> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
> index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
> --- a/hw/vfio/dirty-tracking.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -45,7 +45,7 @@
>   * Device state interfaces
>   */
>  
> -static bool vfio_devices_all_device_dirty_tracking_started(
> +static bool vfio_dirty_tracking_devices_is_started_all(
>      const VFIOContainerBase *bcontainer)
>  {
>      VFIODevice *vbasedev;
> @@ -59,10 +59,9 @@ static bool vfio_devices_all_device_dirty_tracking_started(
>      return true;
>  }
>  
> -bool vfio_devices_all_dirty_tracking_started(
> -    const VFIOContainerBase *bcontainer)
> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer)
>  {
> -    return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
> +    return vfio_dirty_tracking_devices_is_started_all(bcontainer) ||
>             bcontainer->dirty_pages_started;
>  }
>  
> @@ -70,7 +69,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase *bcontainer)
>  {
>      VFIODevice *vbasedev;
>  
> -    if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
> +    if (!vfio_dirty_tracking_devices_is_started(bcontainer)) {
>          return false;
>      }
>  
> @@ -90,7 +89,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase *bcontainer)
>      return true;
>  }
>  
> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)
> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer)
>  {
>      VFIODevice *vbasedev;
>  
> @@ -809,7 +808,7 @@ static void vfio_dirty_tracking_init(VFIOContainerBase *bcontainer,
>      memory_listener_unregister(&dirty.listener);
>  }
>  
> -static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
> +static void vfio_dirty_tracking_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
>  {
>      uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
>                                sizeof(uint64_t))] = {};
> @@ -907,7 +906,7 @@ static void vfio_device_feature_dma_logging_start_destroy(
>      g_free(feature);
>  }
>  
> -static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
> +static bool vfio_dirty_tracking_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>                                            Error **errp)
>  {
>      struct vfio_device_feature *feature;
> @@ -940,7 +939,7 @@ static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>  
>  out:
>      if (ret) {
> -        vfio_devices_dma_logging_stop(bcontainer);
> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>      }
>  
>      vfio_device_feature_dma_logging_start_destroy(feature);
> @@ -956,8 +955,8 @@ static bool vfio_listener_log_global_start(MemoryListener *listener,
>                                                   listener);
>      bool ret;
>  
> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
> -        ret = vfio_devices_dma_logging_start(bcontainer, errp);
> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
> +        ret = vfio_dirty_tracking_devices_dma_logging_start(bcontainer, errp);
>      } else {
>          ret = vfio_container_set_dirty_page_tracking(bcontainer, true, errp) == 0;
>      }
> @@ -975,8 +974,8 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)
>      Error *local_err = NULL;
>      int ret = 0;
>  
> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
> -        vfio_devices_dma_logging_stop(bcontainer);
> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>      } else {
>          ret = vfio_container_set_dirty_page_tracking(bcontainer, false,
>                                                       &local_err);
> @@ -1016,7 +1015,7 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova,
>      return 0;
>  }
>  
> -static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
> +static int vfio_dirty_tracking_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>                   VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>  {
>      VFIODevice *vbasedev;
> @@ -1038,11 +1037,11 @@ static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>      return 0;
>  }
>  
> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>                            uint64_t size, ram_addr_t ram_addr, Error **errp)
>  {
>      bool all_device_dirty_tracking =
> -        vfio_devices_all_device_dirty_tracking(bcontainer);
> +        vfio_dirty_tracking_devices_is_supported(bcontainer);
>      uint64_t dirty_pages;
>      VFIOBitmap vbmap;
>      int ret;
> @@ -1062,8 +1061,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>      }
>  
>      if (all_device_dirty_tracking) {
> -        ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
> -                                              errp);
> +        ret = vfio_dirty_tracking_devices_query_dirty_bitmap(bcontainer, &vbmap,
> +                                                             iova, size, errp);
>      } else {
>          ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
>                                                  errp);
> @@ -1076,7 +1075,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>      dirty_pages = cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap, ram_addr,
>                                                           vbmap.pages);
>  
> -    trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pages);
> +    trace_vfio_dirty_tracking_query_dirty_bitmap(iova, size, vbmap.size, ram_addr,
> +                                                 dirty_pages);
>  out:
>      g_free(vbmap.bitmap);
>  
> @@ -1113,7 +1113,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>          goto out_unlock;
>      }
>  
> -    ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
> +    ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
>                                  translated_addr, &local_err);
>      if (ret) {
>          error_prepend(&local_err,
> @@ -1147,7 +1147,7 @@ static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
>       * Sync the whole mapped region (spanning multiple individual mappings)
>       * in one go.
>       */
> -    ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
> +    ret = vfio_dirty_tracking_query_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
>                                  &local_err);
>      if (ret) {
>          error_report_err(local_err);
> @@ -1241,7 +1241,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer,
>      ram_addr = memory_region_get_ram_addr(section->mr) +
>                 section->offset_within_region;
>  
> -    return vfio_get_dirty_bitmap(bcontainer,
> +    return vfio_dirty_tracking_query_dirty_bitmap(bcontainer,
>                     REAL_HOST_PAGE_ALIGN(section->offset_within_address_space),
>                                   int128_get64(section->size), ram_addr, errp);
>  }
> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
> index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
> --- a/hw/vfio/trace-events
> +++ b/hw/vfio/trace-events
> @@ -100,7 +100,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRIx64" -
>  vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64" - 0x%"PRIx64"]"
>  vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci) "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"], pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
>  vfio_legacy_dma_unmap_overflow_workaround(void) ""
> -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
> +vfio_dirty_tracking_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>  vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
>  
>  # region.c



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static
  2025-03-18  9:53 ` [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static Cédric Le Goater
@ 2025-03-19 12:26   ` Joao Martins
  2025-03-19 16:50   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: Joao Martins @ 2025-03-19 12:26 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 18/03/2025 09:53, Cédric Le Goater wrote:
> This routine is only used in file "migration.c". Move it there.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

> ---
>  include/hw/vfio/vfio-common.h | 1 -
>  hw/vfio/common.c              | 6 ------
>  hw/vfio/migration.c           | 5 +++++
>  3 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 5f082e5a321d97e90066d48cd3c1eaad56912ccb..0aae88131cffda1a90b8ccd0224387133c0fa83a 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -290,7 +290,6 @@ extern VFIODeviceList vfio_device_list;
>  extern const MemoryListener vfio_memory_listener;
>  extern int vfio_kvm_device_fd;
>  
> -bool vfio_viommu_preset(VFIODevice *vbasedev);
>  bool vfio_device_state_is_running(VFIODevice *vbasedev);
>  bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
>  
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index ace7a4403bd49f35cf85009015b3ba315f80cd30..0b9b071cd0490867bb6aa4ceb261350ccd6e1125 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -65,12 +65,6 @@ int vfio_kvm_device_fd = -1;
>   * Device state interfaces
>   */
>  
> -
> -bool vfio_viommu_preset(VFIODevice *vbasedev)
> -{
> -    return vbasedev->bcontainer->space->as != &address_space_memory;
> -}
> -
>  static void vfio_set_migration_error(int ret)
>  {
>      if (migration_is_running()) {
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 951e073a20287c46ca199b1648782b59415d0d2a..a1ba993ce549fce0d2a9a60ba07d4782c87c0c09 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -1141,6 +1141,11 @@ bool vfio_mig_active(void)
>      return true;
>  }
>  
> +static bool vfio_viommu_preset(VFIODevice *vbasedev)
> +{
> +    return vbasedev->bcontainer->space->as != &address_space_memory;
> +}
> +
>  /*
>   * Return true when either migration initialized or blocker registered.
>   * Currently only return false when adding blocker fails which will



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services
  2025-03-18  9:53 ` [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services Cédric Le Goater
@ 2025-03-19 12:29   ` Prasad Pandit
  2025-03-19 17:26     ` Cédric Le Goater
  2025-03-19 14:05   ` Avihai Horon
  2025-03-19 16:55   ` John Levon
  2 siblings, 1 reply; 114+ messages in thread
From: Prasad Pandit @ 2025-03-19 12:29 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, 18 Mar 2025 at 15:26, Cédric Le Goater <clg@redhat.com> wrote:
> Gather all VFIO migration related declarations into "migration.h" to
> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>  hw/vfio/migration.h           | 72 +++++++++++++++++++++++++++++++++++
>  include/hw/vfio/vfio-common.h | 54 +-------------------------
>  hw/vfio/common.c              | 17 +--------
>  hw/vfio/iommufd.c             |  1 +
>  hw/vfio/migration-multifd.c   |  1 +
>  hw/vfio/migration.c           | 17 +++++++++
>  hw/vfio/pci.c                 |  1 +
>  7 files changed, 94 insertions(+), 69 deletions(-)
>  create mode 100644 hw/vfio/migration.h
>
> diff --git a/hw/vfio/migration.h b/hw/vfio/migration.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
> --- /dev/null
> +++ b/hw/vfio/migration.h
> @@ -0,0 +1,72 @@
> +/*
> + * VFIO migration
> + *
> + * Copyright Red Hat, Inc. 2025
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef HW_VFIO_MIGRATION_H
> +#define HW_VFIO_MIGRATION_H
> +
> +#ifdef CONFIG_LINUX
> +#include <linux/vfio.h>
> +#endif
> +
> +#include "qemu/notify.h"
> +
> +/*
> + * Flags to be used as unique delimiters for VFIO devices in the migration
> + * stream. These flags are composed as:
> + * 0xffffffff => MSB 32-bit all 1s
> + * 0xef10     => Magic ID, represents emulated (virtual) function IO
> + * 0x0000     => 16-bits reserved for flags
> + *
> + * The beginning of state information is marked by _DEV_CONFIG_STATE,
> + * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
> + * certain state information is marked by _END_OF_STATE.
> + */
> +#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
> +#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
> +#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
> +#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
> +#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
> +
> +typedef struct VFIODevice VFIODevice;
> +typedef struct VFIOMultifd VFIOMultifd;
> +
> +typedef struct VFIOMigration {
> +    struct VFIODevice *vbasedev;
> +    VMChangeStateEntry *vm_state;
> +    NotifierWithReturn migration_state;
> +    uint32_t device_state;
> +    int data_fd;
> +    void *data_buffer;
> +    size_t data_buffer_size;
> +    uint64_t mig_flags;
> +    uint64_t precopy_init_size;
> +    uint64_t precopy_dirty_size;
> +    bool multifd_transfer;
> +    VFIOMultifd *multifd;
> +    bool initial_data_sent;
> +
> +    bool event_save_iterate_started;
> +    bool event_precopy_empty_hit;
> +} VFIOMigration;
> +
> +
> +bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
> +void vfio_migration_exit(VFIODevice *vbasedev);
> +bool vfio_device_state_is_running(VFIODevice *vbasedev);
> +bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
> +int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
> +int vfio_load_device_config_state(QEMUFile *f, void *opaque);
> +
> +#ifdef CONFIG_LINUX
> +int vfio_migration_set_state(VFIODevice *vbasedev,
> +                             enum vfio_device_mig_state new_state,
> +                             enum vfio_device_mig_state recover_state,
> +                             Error **errp);
> +#endif
> +
> +#endif /* HW_VFIO_MIGRATION_H */
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 0aae88131cffda1a90b8ccd0224387133c0fa83a..799e12d43747addbf444c15052f629b65978322f 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -23,7 +23,6 @@
>
>  #include "exec/memory.h"
>  #include "qemu/queue.h"
> -#include "qemu/notify.h"
>  #include "ui/console.h"
>  #include "hw/display/ramfb.h"
>  #ifdef CONFIG_LINUX
> @@ -36,23 +35,6 @@
>
>  #define VFIO_MSG_PREFIX "vfio %s: "
>
> -/*
> - * Flags to be used as unique delimiters for VFIO devices in the migration
> - * stream. These flags are composed as:
> - * 0xffffffff => MSB 32-bit all 1s
> - * 0xef10     => Magic ID, represents emulated (virtual) function IO
> - * 0x0000     => 16-bits reserved for flags
> - *
> - * The beginning of state information is marked by _DEV_CONFIG_STATE,
> - * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
> - * certain state information is marked by _END_OF_STATE.
> - */
> -#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
> -#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
> -#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
> -#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
> -#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
> -
>  enum {
>      VFIO_DEVICE_TYPE_PCI = 0,
>      VFIO_DEVICE_TYPE_PLATFORM = 1,
> @@ -78,27 +60,6 @@ typedef struct VFIORegion {
>      uint8_t nr; /* cache the region number for debug */
>  } VFIORegion;
>
> -typedef struct VFIOMultifd VFIOMultifd;
> -
> -typedef struct VFIOMigration {
> -    struct VFIODevice *vbasedev;
> -    VMChangeStateEntry *vm_state;
> -    NotifierWithReturn migration_state;
> -    uint32_t device_state;
> -    int data_fd;
> -    void *data_buffer;
> -    size_t data_buffer_size;
> -    uint64_t mig_flags;
> -    uint64_t precopy_init_size;
> -    uint64_t precopy_dirty_size;
> -    bool multifd_transfer;
> -    VFIOMultifd *multifd;
> -    bool initial_data_sent;
> -
> -    bool event_save_iterate_started;
> -    bool event_precopy_empty_hit;
> -} VFIOMigration;
> -
>  struct VFIOGroup;
>
>  typedef struct VFIOContainer {
> @@ -136,6 +97,7 @@ typedef struct VFIOIOMMUFDContainer {
>  OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD);
>
>  typedef struct VFIODeviceOps VFIODeviceOps;
> +typedef struct VFIOMigration VFIOMigration;
>
>  typedef struct VFIODevice {
>      QLIST_ENTRY(VFIODevice) next;
> @@ -290,12 +252,6 @@ extern VFIODeviceList vfio_device_list;
>  extern const MemoryListener vfio_memory_listener;
>  extern int vfio_kvm_device_fd;
>
> -bool vfio_device_state_is_running(VFIODevice *vbasedev);
> -bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
> -
> -int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
> -int vfio_load_device_config_state(QEMUFile *f, void *opaque);
> -
>  #ifdef CONFIG_LINUX
>  int vfio_get_region_info(VFIODevice *vbasedev, int index,
>                           struct vfio_region_info **info);
> @@ -310,16 +266,8 @@ struct vfio_info_cap_header *
>  vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
>  struct vfio_info_cap_header *
>  vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
> -
> -int vfio_migration_set_state(VFIODevice *vbasedev,
> -                             enum vfio_device_mig_state new_state,
> -                             enum vfio_device_mig_state recover_state,
> -                             Error **errp);
>  #endif
>
> -bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
> -void vfio_migration_exit(VFIODevice *vbasedev);
> -
>  int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
>  bool vfio_devices_all_dirty_tracking_started(
>      const VFIOContainerBase *bcontainer);
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -44,6 +44,7 @@
>  #include "migration/qemu-file.h"
>  #include "system/tcg.h"
>  #include "system/tpm.h"
> +#include "migration.h"
>
>  VFIODeviceList vfio_device_list =
>      QLIST_HEAD_INITIALIZER(vfio_device_list);
> @@ -72,22 +73,6 @@ static void vfio_set_migration_error(int ret)
>      }
>  }
>
> -bool vfio_device_state_is_running(VFIODevice *vbasedev)
> -{
> -    VFIOMigration *migration = vbasedev->migration;
> -
> -    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
> -           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
> -}
> -
> -bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
> -{
> -    VFIOMigration *migration = vbasedev->migration;
> -
> -    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
> -           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
> -}
> -
>  static bool vfio_devices_all_device_dirty_tracking_started(
>      const VFIOContainerBase *bcontainer)
>  {
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -25,6 +25,7 @@
>  #include "qemu/cutils.h"
>  #include "qemu/chardev_open.h"
>  #include "pci.h"
> +#include "migration.h"
>
>  static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
>                              ram_addr_t size, void *vaddr, bool readonly)
> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
> index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
> --- a/hw/vfio/migration-multifd.c
> +++ b/hw/vfio/migration-multifd.c
> @@ -22,6 +22,7 @@
>  #include "io/channel-buffer.h"
>  #include "migration/qemu-file.h"
>  #include "migration-multifd.h"
> +#include "migration.h"
>  #include "trace.h"
>
>  #define VFIO_DEVICE_STATE_CONFIG_STATE (1)
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -31,6 +31,7 @@
>  #include "pci.h"
>  #include "trace.h"
>  #include "hw/hw.h"
> +#include "migration.h"
>
>  /*
>   * This is an arbitrary size based on migration of mlx5 devices, where typically
> @@ -1222,3 +1223,19 @@ void vfio_migration_exit(VFIODevice *vbasedev)
>
>      migrate_del_blocker(&vbasedev->migration_blocker);
>  }
> +
> +bool vfio_device_state_is_running(VFIODevice *vbasedev)
> +{
> +    VFIOMigration *migration = vbasedev->migration;
> +
> +    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
> +           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
> +}
> +
> +bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
> +{
> +    VFIOMigration *migration = vbasedev->migration;
> +
> +    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
> +           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
> +}
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -44,6 +44,7 @@
>  #include "migration/blocker.h"
>  #include "migration/qemu-file.h"
>  #include "system/iommufd.h"
> +#include "migration.h"
>
>  #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
>

* Change looks okay. The header name 'migration.h' is rather generic,
vfio-migration.h could be better. Looking at - #include "migration.h"
- it is not clear which migration.h is being included. There is also a
migration/migration.h header. But I'll leave that to you. (just
sharing thoughts)

Reviewed by: Prasad Pandit <pjp@fedoraproject.org>

Thank you.
---
  - Prasad



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services
  2025-03-18  9:53 ` [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services Cédric Le Goater
  2025-03-19 11:48   ` Prasad Pandit
@ 2025-03-19 12:37   ` Avihai Horon
  2025-03-19 16:49     ` Cédric Le Goater
  1 sibling, 1 reply; 114+ messages in thread
From: Avihai Horon @ 2025-03-19 12:37 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Eric Auger, Zhenzhong Duan


On 18/03/2025 11:53, Cédric Le Goater wrote:
> External email: Use caution opening links or attachments
>
>
> The migration core subsytem makes uses of the VFIO migration API to
> collect statistics on the number of bytes transferred. These services
> are declared in "hw/vfio/vfio-common.h" which also contains VFIO
> internal declarations. Move the migration declarations into a new
> header file "hw/vfio/vfio-migration.h" to reduce the exposure of VFIO
> internals.
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   include/hw/vfio/vfio-common.h    |  4 ----
>   include/hw/vfio/vfio-migration.h | 17 +++++++++++++++++
>   hw/vfio/migration-multifd.c      |  1 +
>   hw/vfio/migration.c              |  1 +
>   migration/target.c               |  2 +-
>   5 files changed, 20 insertions(+), 5 deletions(-)
>   create mode 100644 include/hw/vfio/vfio-migration.h
>
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -290,13 +290,9 @@ extern VFIODeviceList vfio_device_list;
>   extern const MemoryListener vfio_memory_listener;
>   extern int vfio_kvm_device_fd;
>
> -bool vfio_mig_active(void);
>   int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
>   void vfio_unblock_multiple_devices_migration(void);
>   bool vfio_viommu_preset(VFIODevice *vbasedev);
> -int64_t vfio_mig_bytes_transferred(void);
> -void vfio_mig_reset_bytes_transferred(void);
> -void vfio_mig_add_bytes_transferred(unsigned long val);
>   bool vfio_device_state_is_running(VFIODevice *vbasedev);
>   bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
>
> diff --git a/include/hw/vfio/vfio-migration.h b/include/hw/vfio/vfio-migration.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
> --- /dev/null
> +++ b/include/hw/vfio/vfio-migration.h
> @@ -0,0 +1,17 @@
> +/*
> + * VFIO migration interface
> + *
> + * Copyright Red Hat, Inc. 2025
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef HW_VFIO_VFIO_MIGRATION_H
> +#define HW_VFIO_VFIO_MIGRATION_H
> +
> +bool vfio_mig_active(void);
> +int64_t vfio_mig_bytes_transferred(void);
> +void vfio_mig_reset_bytes_transferred(void);
> +void vfio_mig_add_bytes_transferred(unsigned long val);

IIUC, vfio_mig_add_bytes_transferred is not used externally. Maybe move 
it to the internal migration header?

Thanks.

> +
> +#endif /* HW_VFIO_VFIO_MIGRATION_H */
> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
> index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
> --- a/hw/vfio/migration-multifd.c
> +++ b/hw/vfio/migration-multifd.c
> @@ -11,6 +11,7 @@
>
>   #include "qemu/osdep.h"
>   #include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-migration.h"
>   #include "migration/misc.h"
>   #include "qapi/error.h"
>   #include "qemu/bswap.h"
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -17,6 +17,7 @@
>
>   #include "system/runstate.h"
>   #include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-migration.h"
>   #include "migration/misc.h"
>   #include "migration/savevm.h"
>   #include "migration/vmstate.h"
> diff --git a/migration/target.c b/migration/target.c
> index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
> --- a/migration/target.c
> +++ b/migration/target.c
> @@ -11,7 +11,7 @@
>   #include CONFIG_DEVICES
>
>   #ifdef CONFIG_VFIO
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-migration.h"
>   #endif
>
>   #ifdef CONFIG_VFIO
> --
> 2.48.1
>


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 04/32] vfio: Make vfio_un/block_multiple_devices_migration() static
  2025-03-18  9:53 ` [PATCH for-10.1 04/32] vfio: Make vfio_un/block_multiple_devices_migration() static Cédric Le Goater
@ 2025-03-19 12:38   ` Joao Martins
  0 siblings, 0 replies; 114+ messages in thread
From: Joao Martins @ 2025-03-19 12:38 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan

On 18/03/2025 09:53, Cédric Le Goater wrote:
> Both of these routines are only used in file "migration.c". Move them
> there.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

> ---
>  include/hw/vfio/vfio-common.h |  2 --
>  hw/vfio/common.c              | 62 -----------------------------------
>  hw/vfio/migration.c           | 62 +++++++++++++++++++++++++++++++++++
>  3 files changed, 62 insertions(+), 64 deletions(-)
> 
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 5fc7ee76573375bc8464baee29ab88974fac3d3b..5f082e5a321d97e90066d48cd3c1eaad56912ccb 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -290,8 +290,6 @@ extern VFIODeviceList vfio_device_list;
>  extern const MemoryListener vfio_memory_listener;
>  extern int vfio_kvm_device_fd;
>  
> -int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
> -void vfio_unblock_multiple_devices_migration(void);
>  bool vfio_viommu_preset(VFIODevice *vbasedev);
>  bool vfio_device_state_is_running(VFIODevice *vbasedev);
>  bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f..ace7a4403bd49f35cf85009015b3ba315f80cd30 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -41,7 +41,6 @@
>  #include "trace.h"
>  #include "qapi/error.h"
>  #include "migration/misc.h"
> -#include "migration/blocker.h"
>  #include "migration/qemu-file.h"
>  #include "system/tcg.h"
>  #include "system/tpm.h"
> @@ -66,67 +65,6 @@ int vfio_kvm_device_fd = -1;
>   * Device state interfaces
>   */
>  
> -static Error *multiple_devices_migration_blocker;
> -
> -/*
> - * Multiple devices migration is allowed only if all devices support P2P
> - * migration. Single device migration is allowed regardless of P2P migration
> - * support.
> - */
> -static bool vfio_multiple_devices_migration_is_supported(void)
> -{
> -    VFIODevice *vbasedev;
> -    unsigned int device_num = 0;
> -    bool all_support_p2p = true;
> -
> -    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
> -        if (vbasedev->migration) {
> -            device_num++;
> -
> -            if (!(vbasedev->migration->mig_flags & VFIO_MIGRATION_P2P)) {
> -                all_support_p2p = false;
> -            }
> -        }
> -    }
> -
> -    return all_support_p2p || device_num <= 1;
> -}
> -
> -int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp)
> -{
> -    int ret;
> -
> -    if (vfio_multiple_devices_migration_is_supported()) {
> -        return 0;
> -    }
> -
> -    if (vbasedev->enable_migration == ON_OFF_AUTO_ON) {
> -        error_setg(errp, "Multiple VFIO devices migration is supported only if "
> -                         "all of them support P2P migration");
> -        return -EINVAL;
> -    }
> -
> -    if (multiple_devices_migration_blocker) {
> -        return 0;
> -    }
> -
> -    error_setg(&multiple_devices_migration_blocker,
> -               "Multiple VFIO devices migration is supported only if all of "
> -               "them support P2P migration");
> -    ret = migrate_add_blocker_normal(&multiple_devices_migration_blocker, errp);
> -
> -    return ret;
> -}
> -
> -void vfio_unblock_multiple_devices_migration(void)
> -{
> -    if (!multiple_devices_migration_blocker ||
> -        !vfio_multiple_devices_migration_is_supported()) {
> -        return;
> -    }
> -
> -    migrate_del_blocker(&multiple_devices_migration_blocker);
> -}
>  
>  bool vfio_viommu_preset(VFIODevice *vbasedev)
>  {
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 75096377ffecf62b3bab91102a00d723827ea4c7..951e073a20287c46ca199b1648782b59415d0d2a 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -1022,6 +1022,68 @@ static int vfio_migration_init(VFIODevice *vbasedev)
>      return 0;
>  }
>  
> +static Error *multiple_devices_migration_blocker;
> +
> +/*
> + * Multiple devices migration is allowed only if all devices support P2P
> + * migration. Single device migration is allowed regardless of P2P migration
> + * support.
> + */
> +static bool vfio_multiple_devices_migration_is_supported(void)
> +{
> +    VFIODevice *vbasedev;
> +    unsigned int device_num = 0;
> +    bool all_support_p2p = true;
> +
> +    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
> +        if (vbasedev->migration) {
> +            device_num++;
> +
> +            if (!(vbasedev->migration->mig_flags & VFIO_MIGRATION_P2P)) {
> +                all_support_p2p = false;
> +            }
> +        }
> +    }
> +
> +    return all_support_p2p || device_num <= 1;
> +}
> +
> +static int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp)
> +{
> +    int ret;
> +
> +    if (vfio_multiple_devices_migration_is_supported()) {
> +        return 0;
> +    }
> +
> +    if (vbasedev->enable_migration == ON_OFF_AUTO_ON) {
> +        error_setg(errp, "Multiple VFIO devices migration is supported only if "
> +                         "all of them support P2P migration");
> +        return -EINVAL;
> +    }
> +
> +    if (multiple_devices_migration_blocker) {
> +        return 0;
> +    }
> +
> +    error_setg(&multiple_devices_migration_blocker,
> +               "Multiple VFIO devices migration is supported only if all of "
> +               "them support P2P migration");
> +    ret = migrate_add_blocker_normal(&multiple_devices_migration_blocker, errp);
> +
> +    return ret;
> +}
> +
> +static void vfio_unblock_multiple_devices_migration(void)
> +{
> +    if (!multiple_devices_migration_blocker ||
> +        !vfio_multiple_devices_migration_is_supported()) {
> +        return;
> +    }
> +
> +    migrate_del_blocker(&multiple_devices_migration_blocker);
> +}
> +
>  static void vfio_migration_deinit(VFIODevice *vbasedev)
>  {
>      VFIOMigration *migration = vbasedev->migration;



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-18  9:54 ` [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations Cédric Le Goater
@ 2025-03-19 13:23   ` Joao Martins
  2025-03-20  9:46   ` John Levon
  2025-03-20  9:52   ` Duan, Zhenzhong
  2 siblings, 0 replies; 114+ messages in thread
From: Joao Martins @ 2025-03-19 13:23 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 18/03/2025 09:54, Cédric Le Goater wrote:
> File "common.c" has been emptied of most of its definitions by the
> previous changes and the only definitions left are related to dirty
> tracking. Rename it to "dirty-tracking.c" and introduce its associated
> "dirty-tracking.h" header file for the declarations.
> 
> Cleanup a little the includes while at it.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

> ---
>  hw/vfio/dirty-tracking.h               | 22 ++++++++++++++++++++++
>  include/hw/vfio/vfio-common.h          | 10 ----------
>  hw/vfio/container.c                    |  1 +
>  hw/vfio/{common.c => dirty-tracking.c} |  5 +----
>  hw/vfio/iommufd.c                      |  1 +
>  hw/vfio/meson.build                    |  2 +-
>  hw/vfio/trace-events                   |  2 +-
>  7 files changed, 27 insertions(+), 16 deletions(-)
>  create mode 100644 hw/vfio/dirty-tracking.h
>  rename hw/vfio/{common.c => dirty-tracking.c} (99%)
> 
> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a
> --- /dev/null
> +++ b/hw/vfio/dirty-tracking.h
> @@ -0,0 +1,22 @@
> +/*
> + * VFIO dirty page tracking routines
> + *
> + * Copyright Red Hat, Inc. 2025
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef HW_VFIO_DIRTY_TRACKING_H
> +#define HW_VFIO_DIRTY_TRACKING_H
> +
> +extern const MemoryListener vfio_memory_listener;
> +
> +bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *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,
> +                                    Error **errp);
> +int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
> +                          uint64_t size, ram_addr_t ram_addr, Error **errp);
> +
> +#endif /* HW_VFIO_DIRTY_TRACKING_H */
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878d4d61818497426 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -130,7 +130,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj);
>  
>  typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
>  extern VFIODeviceList vfio_device_list;
> -extern const MemoryListener vfio_memory_listener;
>  
>  #ifdef CONFIG_LINUX
>  int vfio_get_region_info(VFIODevice *vbasedev, int index,
> @@ -140,15 +139,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
>  bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
>  #endif
>  
> -bool vfio_devices_all_dirty_tracking_started(
> -    const VFIOContainerBase *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, Error **errp);
> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
> -                          uint64_t size, ram_addr_t ram_addr, Error **errp);
> -
>  /* Returns 0 on success, or a negative errno. */
>  bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
>  void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -35,6 +35,7 @@
>  #include "hw/vfio/vfio-container.h"
>  #include "helpers.h"
>  #include "cpr.h"
> +#include "dirty-tracking.h"
>  
>  #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
>  
> diff --git a/hw/vfio/common.c b/hw/vfio/dirty-tracking.c
> similarity index 99%
> rename from hw/vfio/common.c
> rename to hw/vfio/dirty-tracking.c
> index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -20,14 +20,10 @@
>  
>  #include "qemu/osdep.h"
>  #include <sys/ioctl.h>
> -#ifdef CONFIG_KVM
> -#include <linux/kvm.h>
> -#endif
>  #include <linux/vfio.h>
>  
>  #include "hw/vfio/vfio-common.h"
>  #include "hw/vfio/pci.h"
> -#include "exec/address-spaces.h"
>  #include "exec/memory.h"
>  #include "exec/ram_addr.h"
>  #include "exec/target_page.h"
> @@ -45,6 +41,7 @@
>  #include "system/tpm.h"
>  #include "migration.h"
>  #include "helpers.h"
> +#include "dirty-tracking.h"
>  
>  /*
>   * Device state interfaces
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index b25f3b4086d7b7fc6fcd519a9b8b2904513a655f..9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -29,6 +29,7 @@
>  #include "iommufd.h"
>  #include "helpers.h"
>  #include "cpr.h"
> +#include "dirty-tracking.h"
>  
>  #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO             \
>              TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
> diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
> index 1f89bd28c13dea55bcfff476ce99d51b453d8533..b6f5a7eeeda035b5872c2a19f8086384e000f420 100644
> --- a/hw/vfio/meson.build
> +++ b/hw/vfio/meson.build
> @@ -1,6 +1,6 @@
>  vfio_ss = ss.source_set()
>  vfio_ss.add(files(
> -  'common.c',
> +  'dirty-tracking.c',
>    'container.c',
>    'helpers.c',
>  ))
> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
> index a1d01e9dde6ec52964d4804e9cbce5a6a32b7879..f3bdcebe938dcca77b913ef81a74644c622b5d8a 100644
> --- a/hw/vfio/trace-events
> +++ b/hw/vfio/trace-events
> @@ -89,7 +89,7 @@ vfio_pci_igd_bdsm_enabled(const char *name, int size) "%s %dMB"
>  vfio_pci_igd_host_bridge_enabled(const char *name) "%s"
>  vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s"
>  
> -# common.c
> +# dirty-tracking.c
>  vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_end) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64
>  vfio_listener_region_skip(const char *name, uint64_t start, uint64_t end) "SKIPPING %s 0x%"PRIx64" - 0x%"PRIx64
>  vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to liobn fd %d"



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines
  2025-03-18  9:54 ` [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines Cédric Le Goater
@ 2025-03-19 13:24   ` Joao Martins
  2025-03-20 12:28     ` Joao Martins
  2025-03-20  9:49   ` John Levon
  1 sibling, 1 reply; 114+ messages in thread
From: Joao Martins @ 2025-03-19 13:24 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 18/03/2025 09:54, Cédric Le Goater wrote:
> This hides the MemoryListener implementation and makes the code common
> to both IOMMU backends, legacy and IOMMUFD.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

> ---
>  hw/vfio/dirty-tracking.h |  4 ++--
>  hw/vfio/container.c      | 11 +++--------
>  hw/vfio/dirty-tracking.c | 21 ++++++++++++++++++++-
>  hw/vfio/iommufd.c        |  9 ++-------
>  4 files changed, 27 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
> index db9494202a780108ce78b642950bfed78ba3f253..6d717f0e918e47e341114c82ffc2cf520fc7b079 100644
> --- a/hw/vfio/dirty-tracking.h
> +++ b/hw/vfio/dirty-tracking.h
> @@ -9,11 +9,11 @@
>  #ifndef HW_VFIO_DIRTY_TRACKING_H
>  #define HW_VFIO_DIRTY_TRACKING_H
>  
> -extern const MemoryListener vfio_memory_listener;
> -
>  bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer);
>  bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer);
>  int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>                            uint64_t size, ram_addr_t ram_addr, Error **errp);
> +bool vfio_dirty_tracking_register(VFIOContainerBase *bcontainer, Error **errp);
> +void vfio_dirty_tracking_unregister(VFIOContainerBase *bcontainer);
>  
>  #endif /* HW_VFIO_DIRTY_TRACKING_H */
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 7b3ec798a77052b8cb0b47d3dceaca1428cb50bd..1fcca75caba19353ad3063ae97b20c15f61564e9 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -616,12 +616,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
>      group->container = container;
>      QLIST_INSERT_HEAD(&container->group_list, group, container_next);
>  
> -    bcontainer->listener = 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_dirty_tracking_register(bcontainer, errp)) {
>          goto listener_release_exit;
>      }
>  
> @@ -631,7 +626,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
>  listener_release_exit:
>      QLIST_REMOVE(group, container_next);
>      vfio_group_del_kvm_device(group);
> -    memory_listener_unregister(&bcontainer->listener);
> +    vfio_dirty_tracking_unregister(bcontainer);
>      if (vioc->release) {
>          vioc->release(bcontainer);
>      }
> @@ -669,7 +664,7 @@ static void vfio_container_disconnect(VFIOGroup *group)
>       * group.
>       */
>      if (QLIST_EMPTY(&container->group_list)) {
> -        memory_listener_unregister(&bcontainer->listener);
> +        vfio_dirty_tracking_unregister(bcontainer);
>          if (vioc->release) {
>              vioc->release(bcontainer);
>          }
> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
> index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644
> --- a/hw/vfio/dirty-tracking.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -1267,7 +1267,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,
>      }
>  }
>  
> -const MemoryListener vfio_memory_listener = {
> +static const MemoryListener vfio_memory_listener = {
>      .name = "vfio",
>      .region_add = vfio_listener_region_add,
>      .region_del = vfio_listener_region_del,
> @@ -1275,3 +1275,22 @@ const MemoryListener vfio_memory_listener = {
>      .log_global_stop = vfio_listener_log_global_stop,
>      .log_sync = vfio_listener_log_sync,
>  };
> +
> +bool vfio_dirty_tracking_register(VFIOContainerBase *bcontainer, Error **errp)
> +{
> +    bcontainer->listener = 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_dirty_tracking_unregister(VFIOContainerBase *bcontainer)
> +{
> +    memory_listener_unregister(&bcontainer->listener);
> +}
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 7f354d86cd14270a70dc990860ad5b69f0310719..7737d552f310c54ae2e035198a1a83da8c3199dd 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -411,7 +411,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDContainer *container)
>      if (!QLIST_EMPTY(&bcontainer->device_list)) {
>          return;
>      }
> -    memory_listener_unregister(&bcontainer->listener);
> +    vfio_dirty_tracking_unregister(bcontainer);
>      iommufd_backend_free_id(container->be, container->ioas_id);
>      object_unref(container);
>  }
> @@ -563,12 +563,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
>          bcontainer->pgsizes = qemu_real_host_page_size();
>      }
>  
> -    bcontainer->listener = 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_dirty_tracking_register(bcontainer, errp)) {
>          goto err_listener_register;
>      }
>  



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services
  2025-03-18  9:53 ` [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services Cédric Le Goater
  2025-03-19 12:29   ` Prasad Pandit
@ 2025-03-19 14:05   ` Avihai Horon
  2025-03-19 17:33     ` Cédric Le Goater
  2025-03-19 16:55   ` John Levon
  2 siblings, 1 reply; 114+ messages in thread
From: Avihai Horon @ 2025-03-19 14:05 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Eric Auger, Zhenzhong Duan


On 18/03/2025 11:53, Cédric Le Goater wrote:
> External email: Use caution opening links or attachments
>
>
> Gather all VFIO migration related declarations into "migration.h" to
> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".

Reviewed-by: Avihai Horon <avihaih@nvidia.com>

Two nits below.

>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   hw/vfio/migration.h           | 72 +++++++++++++++++++++++++++++++++++
>   include/hw/vfio/vfio-common.h | 54 +-------------------------
>   hw/vfio/common.c              | 17 +--------
>   hw/vfio/iommufd.c             |  1 +
>   hw/vfio/migration-multifd.c   |  1 +
>   hw/vfio/migration.c           | 17 +++++++++
>   hw/vfio/pci.c                 |  1 +
>   7 files changed, 94 insertions(+), 69 deletions(-)
>   create mode 100644 hw/vfio/migration.h
>
> diff --git a/hw/vfio/migration.h b/hw/vfio/migration.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
> --- /dev/null
> +++ b/hw/vfio/migration.h
> @@ -0,0 +1,72 @@
> +/*
> + * VFIO migration
> + *
> + * Copyright Red Hat, Inc. 2025
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#ifndef HW_VFIO_MIGRATION_H
> +#define HW_VFIO_MIGRATION_H
> +
> +#ifdef CONFIG_LINUX
> +#include <linux/vfio.h>
> +#endif
> +
> +#include "qemu/notify.h"
> +
> +/*
> + * Flags to be used as unique delimiters for VFIO devices in the migration
> + * stream. These flags are composed as:
> + * 0xffffffff => MSB 32-bit all 1s
> + * 0xef10     => Magic ID, represents emulated (virtual) function IO
> + * 0x0000     => 16-bits reserved for flags
> + *
> + * The beginning of state information is marked by _DEV_CONFIG_STATE,
> + * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
> + * certain state information is marked by _END_OF_STATE.
> + */
> +#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
> +#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
> +#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
> +#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
> +#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
> +
> +typedef struct VFIODevice VFIODevice;
> +typedef struct VFIOMultifd VFIOMultifd;
> +
> +typedef struct VFIOMigration {
> +    struct VFIODevice *vbasedev;
> +    VMChangeStateEntry *vm_state;
> +    NotifierWithReturn migration_state;
> +    uint32_t device_state;
> +    int data_fd;
> +    void *data_buffer;
> +    size_t data_buffer_size;
> +    uint64_t mig_flags;
> +    uint64_t precopy_init_size;
> +    uint64_t precopy_dirty_size;
> +    bool multifd_transfer;
> +    VFIOMultifd *multifd;
> +    bool initial_data_sent;
> +
> +    bool event_save_iterate_started;
> +    bool event_precopy_empty_hit;
> +} VFIOMigration;
> +
> +

Extra line break.

> +bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
> +void vfio_migration_exit(VFIODevice *vbasedev);
> +bool vfio_device_state_is_running(VFIODevice *vbasedev);
> +bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
> +int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
> +int vfio_load_device_config_state(QEMUFile *f, void *opaque);
> +
> +#ifdef CONFIG_LINUX
> +int vfio_migration_set_state(VFIODevice *vbasedev,
> +                             enum vfio_device_mig_state new_state,
> +                             enum vfio_device_mig_state recover_state,
> +                             Error **errp);
> +#endif
> +
> +#endif /* HW_VFIO_MIGRATION_H */
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index 0aae88131cffda1a90b8ccd0224387133c0fa83a..799e12d43747addbf444c15052f629b65978322f 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -23,7 +23,6 @@
>
>   #include "exec/memory.h"
>   #include "qemu/queue.h"
> -#include "qemu/notify.h"
>   #include "ui/console.h"
>   #include "hw/display/ramfb.h"
>   #ifdef CONFIG_LINUX
> @@ -36,23 +35,6 @@
>
>   #define VFIO_MSG_PREFIX "vfio %s: "
>
> -/*
> - * Flags to be used as unique delimiters for VFIO devices in the migration
> - * stream. These flags are composed as:
> - * 0xffffffff => MSB 32-bit all 1s
> - * 0xef10     => Magic ID, represents emulated (virtual) function IO
> - * 0x0000     => 16-bits reserved for flags
> - *
> - * The beginning of state information is marked by _DEV_CONFIG_STATE,
> - * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
> - * certain state information is marked by _END_OF_STATE.
> - */
> -#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
> -#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
> -#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
> -#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
> -#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
> -
>   enum {
>       VFIO_DEVICE_TYPE_PCI = 0,
>       VFIO_DEVICE_TYPE_PLATFORM = 1,
> @@ -78,27 +60,6 @@ typedef struct VFIORegion {
>       uint8_t nr; /* cache the region number for debug */
>   } VFIORegion;
>
> -typedef struct VFIOMultifd VFIOMultifd;
> -
> -typedef struct VFIOMigration {
> -    struct VFIODevice *vbasedev;
> -    VMChangeStateEntry *vm_state;
> -    NotifierWithReturn migration_state;
> -    uint32_t device_state;
> -    int data_fd;
> -    void *data_buffer;
> -    size_t data_buffer_size;
> -    uint64_t mig_flags;
> -    uint64_t precopy_init_size;
> -    uint64_t precopy_dirty_size;
> -    bool multifd_transfer;
> -    VFIOMultifd *multifd;
> -    bool initial_data_sent;
> -
> -    bool event_save_iterate_started;
> -    bool event_precopy_empty_hit;
> -} VFIOMigration;
> -
>   struct VFIOGroup;
>
>   typedef struct VFIOContainer {
> @@ -136,6 +97,7 @@ typedef struct VFIOIOMMUFDContainer {
>   OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD);
>
>   typedef struct VFIODeviceOps VFIODeviceOps;
> +typedef struct VFIOMigration VFIOMigration;
>
>   typedef struct VFIODevice {
>       QLIST_ENTRY(VFIODevice) next;
> @@ -290,12 +252,6 @@ extern VFIODeviceList vfio_device_list;
>   extern const MemoryListener vfio_memory_listener;
>   extern int vfio_kvm_device_fd;
>
> -bool vfio_device_state_is_running(VFIODevice *vbasedev);
> -bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
> -
> -int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
> -int vfio_load_device_config_state(QEMUFile *f, void *opaque);
> -
>   #ifdef CONFIG_LINUX
>   int vfio_get_region_info(VFIODevice *vbasedev, int index,
>                            struct vfio_region_info **info);
> @@ -310,16 +266,8 @@ struct vfio_info_cap_header *
>   vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
>   struct vfio_info_cap_header *
>   vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
> -
> -int vfio_migration_set_state(VFIODevice *vbasedev,
> -                             enum vfio_device_mig_state new_state,
> -                             enum vfio_device_mig_state recover_state,
> -                             Error **errp);
>   #endif
>
> -bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
> -void vfio_migration_exit(VFIODevice *vbasedev);
> -
>   int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
>   bool vfio_devices_all_dirty_tracking_started(
>       const VFIOContainerBase *bcontainer);
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -44,6 +44,7 @@
>   #include "migration/qemu-file.h"
>   #include "system/tcg.h"
>   #include "system/tpm.h"
> +#include "migration.h"
>
>   VFIODeviceList vfio_device_list =
>       QLIST_HEAD_INITIALIZER(vfio_device_list);
> @@ -72,22 +73,6 @@ static void vfio_set_migration_error(int ret)
>       }
>   }
>
> -bool vfio_device_state_is_running(VFIODevice *vbasedev)
> -{
> -    VFIOMigration *migration = vbasedev->migration;
> -
> -    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
> -           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
> -}
> -
> -bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
> -{
> -    VFIOMigration *migration = vbasedev->migration;
> -
> -    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
> -           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
> -}
> -
>   static bool vfio_devices_all_device_dirty_tracking_started(
>       const VFIOContainerBase *bcontainer)
>   {
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -25,6 +25,7 @@
>   #include "qemu/cutils.h"
>   #include "qemu/chardev_open.h"
>   #include "pci.h"
> +#include "migration.h"

I think iommufd.c doesn't need migration.h.

Thanks.

>
>   static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
>                               ram_addr_t size, void *vaddr, bool readonly)
> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
> index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
> --- a/hw/vfio/migration-multifd.c
> +++ b/hw/vfio/migration-multifd.c
> @@ -22,6 +22,7 @@
>   #include "io/channel-buffer.h"
>   #include "migration/qemu-file.h"
>   #include "migration-multifd.h"
> +#include "migration.h"
>   #include "trace.h"
>
>   #define VFIO_DEVICE_STATE_CONFIG_STATE (1)
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -31,6 +31,7 @@
>   #include "pci.h"
>   #include "trace.h"
>   #include "hw/hw.h"
> +#include "migration.h"
>
>   /*
>    * This is an arbitrary size based on migration of mlx5 devices, where typically
> @@ -1222,3 +1223,19 @@ void vfio_migration_exit(VFIODevice *vbasedev)
>
>       migrate_del_blocker(&vbasedev->migration_blocker);
>   }
> +
> +bool vfio_device_state_is_running(VFIODevice *vbasedev)
> +{
> +    VFIOMigration *migration = vbasedev->migration;
> +
> +    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
> +           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
> +}
> +
> +bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
> +{
> +    VFIOMigration *migration = vbasedev->migration;
> +
> +    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
> +           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
> +}
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -44,6 +44,7 @@
>   #include "migration/blocker.h"
>   #include "migration/qemu-file.h"
>   #include "system/iommufd.h"
> +#include "migration.h"
>
>   #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
>
> --
> 2.48.1
>


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h
  2025-03-18  9:54 ` [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h Cédric Le Goater
@ 2025-03-19 14:27   ` Avihai Horon
  2025-03-21 11:03     ` Cédric Le Goater
  2025-03-19 16:56   ` John Levon
  1 sibling, 1 reply; 114+ messages in thread
From: Avihai Horon @ 2025-03-19 14:27 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel, Alex Williamson
  Cc: Eric Auger, Zhenzhong Duan


On 18/03/2025 11:54, Cédric Le Goater wrote:
> External email: Use caution opening links or attachments
>
>
> "hw/vfio/vfio-common.h" has been emptied of most of its declarations
> by the previous changes and the only declarations left are related to
> VFIODevice. Rename it to "hw/vfio/vfio-device.h" and make the
> necessary adjustments.
>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>   hw/vfio/migration-multifd.h                      | 2 +-
>   hw/vfio/pci.h                                    | 2 +-
>   include/hw/s390x/vfio-ccw.h                      | 2 +-
>   include/hw/vfio/{vfio-common.h => vfio-device.h} | 0
>   include/hw/vfio/vfio-platform.h                  | 2 +-
>   backends/iommufd.c                               | 2 +-
>   hw/vfio/ap.c                                     | 2 +-
>   hw/vfio/ccw.c                                    | 2 +-
>   hw/vfio/container-base.c                         | 2 +-
>   hw/vfio/container.c                              | 2 +-
>   hw/vfio/cpr.c                                    | 2 +-
>   hw/vfio/device.c                                 | 2 +-
>   hw/vfio/dirty-tracking.c                         | 2 +-
>   hw/vfio/helpers.c                                | 2 +-
>   hw/vfio/iommufd.c                                | 2 +-
>   hw/vfio/migration-multifd.c                      | 2 +-
>   hw/vfio/migration.c                              | 2 +-
>   hw/vfio/region.c                                 | 4 ++--
>   18 files changed, 18 insertions(+), 18 deletions(-)
>   rename include/hw/vfio/{vfio-common.h => vfio-device.h} (100%)
>
> diff --git a/hw/vfio/migration-multifd.h b/hw/vfio/migration-multifd.h
> index a664051eb8ae03bc41cb7f9362ace840f41066ff..0bab63211d30cef04c50e50b3ea57840915ffc2a 100644
> --- a/hw/vfio/migration-multifd.h
> +++ b/hw/vfio/migration-multifd.h
> @@ -12,7 +12,7 @@
>   #ifndef HW_VFIO_MIGRATION_MULTIFD_H
>   #define HW_VFIO_MIGRATION_MULTIFD_H
>
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>
>   bool vfio_multifd_setup(VFIODevice *vbasedev, bool alloc_multifd, Error **errp);
>   void vfio_multifd_cleanup(VFIODevice *vbasedev);
> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
> index c84bba81487136d205ca30049c812d00e832c377..d33237c275551897164878705d44e7881c372ab0 100644
> --- a/hw/vfio/pci.h
> +++ b/hw/vfio/pci.h
> @@ -14,7 +14,7 @@
>
>   #include "exec/memory.h"
>   #include "hw/pci/pci_device.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "qemu/event_notifier.h"
>   #include "qemu/queue.h"
>   #include "qemu/timer.h"
> diff --git a/include/hw/s390x/vfio-ccw.h b/include/hw/s390x/vfio-ccw.h
> index 4209d27657c1fbde44c160445396bcab3f3fd2b0..1e0922dca11e6caada08c2aae82bd3462ace35f5 100644
> --- a/include/hw/s390x/vfio-ccw.h
> +++ b/include/hw/s390x/vfio-ccw.h
> @@ -14,7 +14,7 @@
>   #ifndef HW_VFIO_CCW_H
>   #define HW_VFIO_CCW_H
>
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "hw/s390x/s390-ccw.h"
>   #include "hw/s390x/ccw-device.h"
>   #include "qom/object.h"
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-device.h
> similarity index 100%
> rename from include/hw/vfio/vfio-common.h
> rename to include/hw/vfio/vfio-device.h
> diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h
> index 3191545717da51abc41d10cd3646cd047b4a676c..256d8500b70a2e985e975b0895e3cfca435ed8ed 100644
> --- a/include/hw/vfio/vfio-platform.h
> +++ b/include/hw/vfio/vfio-platform.h
> @@ -17,7 +17,7 @@
>   #define HW_VFIO_VFIO_PLATFORM_H
>
>   #include "hw/sysbus.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "qemu/event_notifier.h"
>   #include "qemu/queue.h"
>   #include "qom/object.h"
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index d57da44755be3d7fdba74f7dbecfe6d1c89921ba..9587e4d99b131e88674326a5196cfd2079560430 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -18,7 +18,7 @@
>   #include "qemu/error-report.h"
>   #include "monitor/monitor.h"
>   #include "trace.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include <sys/ioctl.h>
>   #include <linux/iommufd.h>
>
> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
> index c7ab4ff57ada0ed0e5a76f52b5a05c86ca4fe0b4..4fdb74e33c427595a9b0a4d28b2b5a70df951e4e 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -15,7 +15,7 @@
>   #include <linux/vfio.h>
>   #include <sys/ioctl.h>
>   #include "qapi/error.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "system/iommufd.h"
>   #include "hw/s390x/ap-device.h"
>   #include "qemu/error-report.h"
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index e5e0d9e3e7ed124f242b3eda345bc973e418a64c..a40169bc85e51406822247f5b3ef6da1f7f92881 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -21,7 +21,7 @@
>   #include <sys/ioctl.h>
>
>   #include "qapi/error.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "system/iommufd.h"
>   #include "hw/s390x/s390-ccw.h"
>   #include "hw/s390x/vfio-ccw.h"
> diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
> index 83e83ab9e67de8b004dfaf0067e4c466a6c88451..ace9de18103e8c1ed9f7a51adbf16c36be01bd7c 100644
> --- a/hw/vfio/container-base.c
> +++ b/hw/vfio/container-base.c
> @@ -15,7 +15,7 @@
>   #include "qemu/error-report.h"
>   #include "system/reset.h"
>   #include "hw/vfio/vfio-container-base.h"
> -#include "hw/vfio/vfio-common.h" /* for vfio_device_list */
> +#include "hw/vfio/vfio-device.h" /* for vfio_device_list */
>   #include "trace.h"
>
>   static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7..e300d2d90f2fbde329609b7c63245c523766fb60 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -22,7 +22,7 @@
>   #include <sys/ioctl.h>
>   #include <linux/vfio.h>
>
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "exec/address-spaces.h"
>   #include "exec/memory.h"
>   #include "exec/ram_addr.h"
> diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
> index e1bba1726402f41ee394f25b6e613d27f44b2a2c..43b99680f6d7db27c4d7e518520aef5ade2ebcf4 100644
> --- a/hw/vfio/cpr.c
> +++ b/hw/vfio/cpr.c
> @@ -6,7 +6,7 @@
>    */
>
>   #include "qemu/osdep.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "migration/misc.h"
>   #include "qapi/error.h"
>   #include "system/runstate.h"
> diff --git a/hw/vfio/device.c b/hw/vfio/device.c
> index e6a1bbcda2297f9e6272fff9b1c228b6772457ce..0d443b53d23d392729cef84e419d3e089fe64298 100644
> --- a/hw/vfio/device.c
> +++ b/hw/vfio/device.c
> @@ -22,7 +22,7 @@
>   #include "qemu/osdep.h"
>   #include <sys/ioctl.h>
>
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "hw/vfio/pci.h"
>   #include "hw/hw.h"
>   #include "trace.h"
> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
> index 447e09ed84993e3fbe1ed9b27a8269a9f0f46339..143cc5cf62b0165565e91f8a2ca166026f16b1eb 100644
> --- a/hw/vfio/dirty-tracking.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -22,7 +22,7 @@
>   #include <sys/ioctl.h>
>   #include <linux/vfio.h>
>
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "hw/vfio/pci.h"
>   #include "exec/memory.h"
>   #include "exec/ram_addr.h"
> diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
> index e99d312a9f5c7462644ea3d0de2e9de38979f851..b7907aab80f8adb308ebae60baa20c911d9393d7 100644
> --- a/hw/vfio/helpers.c
> +++ b/hw/vfio/helpers.c
> @@ -23,7 +23,7 @@
>   #include <sys/ioctl.h>
>
>   #include "system/kvm.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "hw/hw.h"
>   #include "qapi/error.h"
>   #include "helpers.h"
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8..7f354d86cd14270a70dc990860ad5b69f0310719 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -15,7 +15,7 @@
>   #include <linux/vfio.h>
>   #include <linux/iommufd.h>
>
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "qemu/error-report.h"
>   #include "trace.h"
>   #include "qapi/error.h"
> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
> index 285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db..1ba703e595db99f3786bfc1a2edeb0e061f9e01b 100644
> --- a/hw/vfio/migration-multifd.c
> +++ b/hw/vfio/migration-multifd.c
> @@ -10,7 +10,7 @@
>    */
>
>   #include "qemu/osdep.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "hw/vfio/vfio-migration.h"
>   #include "migration/misc.h"
>   #include "qapi/error.h"
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index 6fd825e435bde96d1008ec03dfaba25db3b616fc..338fafb83f41460e0c244dcc27524198322eec67 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -16,7 +16,7 @@
>   #include <sys/ioctl.h>
>
>   #include "system/runstate.h"
> -#include "hw/vfio/vfio-common.h"
> +#include "hw/vfio/vfio-device.h"
>   #include "hw/vfio/vfio-migration.h"
>   #include "migration/misc.h"
>   #include "migration/savevm.h"
> diff --git a/hw/vfio/region.c b/hw/vfio/region.c
> index 87bf5e046a432dfedf3be3c1c7e8f33e006da004..ade4466eb622248b5aa50f9df7e5c683bfa78a11 100644
> --- a/hw/vfio/region.c
> +++ b/hw/vfio/region.c
> @@ -22,8 +22,8 @@
>   #include "qemu/osdep.h"
>   #include <sys/ioctl.h>
>
> -#include "hw/vfio/vfio-common.h"
> -#include "hw/vfio/pci.h"
> +#include "hw/vfio/vfio-region.h"

Doesn't the above belong to patch #10?

Thanks.

> +#include "hw/vfio/vfio-device.h"
>   #include "hw/hw.h"
>   #include "trace.h"
>   #include "qapi/error.h"
> --
> 2.48.1
>


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c
  2025-03-19 11:54   ` Avihai Horon
@ 2025-03-19 16:38     ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-19 16:38 UTC (permalink / raw)
  To: Avihai Horon, qemu-devel, Alex Williamson; +Cc: Eric Auger, Zhenzhong Duan

On 3/19/25 12:54, Avihai Horon wrote:
> 
> On 18/03/2025 11:53, Cédric Le Goater wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> vfio_mig_active() is part of the VFIO migration API. Move the
>> definitions where VFIO migration is implemented.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> 
> Reviewed-by: Avihai Horon <avihaih@nvidia.com>
> 
> One nit below though.
> 
>> ---
>>   hw/vfio/common.c    | 16 ----------------
>>   hw/vfio/migration.c | 16 ++++++++++++++++
>>   2 files changed, 16 insertions(+), 16 deletions(-)
>>
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index 1a0d9290f88c9774a98f65087a36b86922b21a73..4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -66,22 +66,6 @@ int vfio_kvm_device_fd = -1;
>>    * Device state interfaces
>>    */
>>
>> -bool vfio_mig_active(void)
>> -{
>> -    VFIODevice *vbasedev;
>> -
>> -    if (QLIST_EMPTY(&vfio_device_list)) {
>> -        return false;
>> -    }
>> -
>> -    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>> -        if (vbasedev->migration_blocker) {
>> -            return false;
>> -        }
>> -    }
>> -    return true;
>> -}
>> -
>>   static Error *multiple_devices_migration_blocker;
>>
>>   /*
>> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
>> index fbff46cfc35e0ee69e9599c9f8efc7437bbe3370..b5fb0d218808d010d8210612d3182dde8f33514b 100644
>> --- a/hw/vfio/migration.c
>> +++ b/hw/vfio/migration.c
>> @@ -1062,6 +1062,22 @@ void vfio_mig_add_bytes_transferred(unsigned long val)
>>       qatomic_add(&bytes_transferred, val);
>>   }
>>
>> +bool vfio_mig_active(void)
> 
> We already have vfio_migration_* prefix in this file.
> I'd say let's use it and rename to vfio_migration_is_active?

yeah. I've been lazy there. I will change vfio_mig_ to vfio_migration_.

Thanks,

C.


  
> 
> Thanks.
> 
>> +{
>> +    VFIODevice *vbasedev;
>> +
>> +    if (QLIST_EMPTY(&vfio_device_list)) {
>> +        return false;
>> +    }
>> +
>> +    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>> +        if (vbasedev->migration_blocker) {
>> +            return false;
>> +        }
>> +    }
>> +    return true;
>> +}
>> +
>>   /*
>>    * Return true when either migration initialized or blocker registered.
>>    * Currently only return false when adding blocker fails which will
>> -- 
>> 2.48.1
>>
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions
  2025-03-18  9:54 ` [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions Cédric Le Goater
@ 2025-03-19 16:42   ` John Levon
  2025-03-20  9:01     ` Cédric Le Goater
  0 siblings, 1 reply; 114+ messages in thread
From: John Levon @ 2025-03-19 16:42 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:02AM +0100, Cédric Le Goater wrote:

> diff --git a/hw/vfio/device.c b/hw/vfio/device.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..daa5bae59ca9c65ef23aa193d4e63976fcefdde0
> --- /dev/null
> +++ b/hw/vfio/device.c
> @@ -0,0 +1,331 @@
> +/*
> + * low level and IOMMU backend agnostic helpers used by VFIO devices,
> + * related to regions, interrupts, capabilities

This same comment is still at the top of helpers.c - and I'm not sure what
*does* belong still in helpers.c ?

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c
  2025-03-18  9:53 ` [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c Cédric Le Goater
@ 2025-03-19 16:45   ` John Levon
  2025-03-20  9:36   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:45 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:56AM +0100, Cédric Le Goater wrote:

> VFIOAddressSpace is a common object used by VFIOContainerBase which is
> declared in "hw/vfio/vfio-container-base.h". Move the VFIOAddressSpace
> related services into "container-base.c".
> 
> While at it, rename :
> 
>   vfio_get_address_space -> vfio_address_space_get
>   vfio_put_address_space -> vfio_address_space_put
> 
> to better reflect the namespace these routines belong to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

OK but I'm not clear about vfio_reset_handler() here - it's not related to
address spaces, and there's still code in common.c that relates to the
vfio_device_list etc.

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c
  2025-03-18  9:54 ` [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c Cédric Le Goater
@ 2025-03-19 16:46   ` John Levon
  2025-03-20  9:40   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:46 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:00AM +0100, Cédric Le Goater wrote:

> vfio_kvm_device_add/del_fd() are low level routines. Move them with
> the other helpers.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services
  2025-03-19 12:37   ` Avihai Horon
@ 2025-03-19 16:49     ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-19 16:49 UTC (permalink / raw)
  To: Avihai Horon, qemu-devel, Alex Williamson; +Cc: Eric Auger, Zhenzhong Duan

On 3/19/25 13:37, Avihai Horon wrote:
> 
> On 18/03/2025 11:53, Cédric Le Goater wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> The migration core subsytem makes uses of the VFIO migration API to
>> collect statistics on the number of bytes transferred. These services
>> are declared in "hw/vfio/vfio-common.h" which also contains VFIO
>> internal declarations. Move the migration declarations into a new
>> header file "hw/vfio/vfio-migration.h" to reduce the exposure of VFIO
>> internals.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>>   include/hw/vfio/vfio-common.h    |  4 ----
>>   include/hw/vfio/vfio-migration.h | 17 +++++++++++++++++
>>   hw/vfio/migration-multifd.c      |  1 +
>>   hw/vfio/migration.c              |  1 +
>>   migration/target.c               |  2 +-
>>   5 files changed, 20 insertions(+), 5 deletions(-)
>>   create mode 100644 include/hw/vfio/vfio-migration.h
>>
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>> index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -290,13 +290,9 @@ extern VFIODeviceList vfio_device_list;
>>   extern const MemoryListener vfio_memory_listener;
>>   extern int vfio_kvm_device_fd;
>>
>> -bool vfio_mig_active(void);
>>   int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
>>   void vfio_unblock_multiple_devices_migration(void);
>>   bool vfio_viommu_preset(VFIODevice *vbasedev);
>> -int64_t vfio_mig_bytes_transferred(void);
>> -void vfio_mig_reset_bytes_transferred(void);
>> -void vfio_mig_add_bytes_transferred(unsigned long val);
>>   bool vfio_device_state_is_running(VFIODevice *vbasedev);
>>   bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
>>
>> diff --git a/include/hw/vfio/vfio-migration.h b/include/hw/vfio/vfio-migration.h
>> new file mode 100644
>> index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
>> --- /dev/null
>> +++ b/include/hw/vfio/vfio-migration.h
>> @@ -0,0 +1,17 @@
>> +/*
>> + * VFIO migration interface
>> + *
>> + * Copyright Red Hat, Inc. 2025
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +
>> +#ifndef HW_VFIO_VFIO_MIGRATION_H
>> +#define HW_VFIO_VFIO_MIGRATION_H
>> +
>> +bool vfio_mig_active(void);
>> +int64_t vfio_mig_bytes_transferred(void);
>> +void vfio_mig_reset_bytes_transferred(void);
>> +void vfio_mig_add_bytes_transferred(unsigned long val);
> 
> IIUC, vfio_mig_add_bytes_transferred is not used externally. Maybe move it to the internal migration header?

sure. let's do that.

Thanks,

C.



> 
> Thanks.
> 
>> +
>> +#endif /* HW_VFIO_VFIO_MIGRATION_H */
>> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
>> index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
>> --- a/hw/vfio/migration-multifd.c
>> +++ b/hw/vfio/migration-multifd.c
>> @@ -11,6 +11,7 @@
>>
>>   #include "qemu/osdep.h"
>>   #include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-migration.h"
>>   #include "migration/misc.h"
>>   #include "qapi/error.h"
>>   #include "qemu/bswap.h"
>> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
>> index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
>> --- a/hw/vfio/migration.c
>> +++ b/hw/vfio/migration.c
>> @@ -17,6 +17,7 @@
>>
>>   #include "system/runstate.h"
>>   #include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-migration.h"
>>   #include "migration/misc.h"
>>   #include "migration/savevm.h"
>>   #include "migration/vmstate.h"
>> diff --git a/migration/target.c b/migration/target.c
>> index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
>> --- a/migration/target.c
>> +++ b/migration/target.c
>> @@ -11,7 +11,7 @@
>>   #include CONFIG_DEVICES
>>
>>   #ifdef CONFIG_VFIO
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-migration.h"
>>   #endif
>>
>>   #ifdef CONFIG_VFIO
>> -- 
>> 2.48.1
>>
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 16/32] vfio: Move vfio_get_info_dma_avail() into helpers.c
  2025-03-18  9:53 ` [PATCH for-10.1 16/32] vfio: Move vfio_get_info_dma_avail() into helpers.c Cédric Le Goater
@ 2025-03-19 16:50   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:50 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:59AM +0100, Cédric Le Goater wrote:

> vfio_get_info_dma_avail() is a low level routine similar to the other
> routines extracting capabilities from 'struct vfio_iommu_type1_info'.
> It belongs to file "helpers.c".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static
  2025-03-18  9:53 ` [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static Cédric Le Goater
  2025-03-19 12:26   ` Joao Martins
@ 2025-03-19 16:50   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:50 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:48AM +0100, Cédric Le Goater wrote:

> This routine is only used in file "migration.c". Move it there.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 10/32] vfio: Introduce new files for VFIORegion definitions and declarations
  2025-03-18  9:53 ` [PATCH for-10.1 10/32] vfio: Introduce new files for VFIORegion definitions and declarations Cédric Le Goater
@ 2025-03-19 16:54   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:54 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:53AM +0100, Cédric Le Goater wrote:

> Gather all VFIORegion related declarations and definitions into their
> own files to reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> These declarations are made available externally (for "sysbus-fdt.c").
> This is for 'vfio-platform' devices which have been deprecated and
> will be removed in QEMU 10.2.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

> diff --git a/hw/vfio/region.c b/hw/vfio/region.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..3e174c3dcb0b699fd0cee00d104250d8ae97f698
> --- /dev/null
> +++ b/hw/vfio/region.c
> @@ -0,0 +1,395 @@
> +/*
> + * low level and IOMMU backend agnostic helpers used by VFIO devices,
> + * related to regions, interrupts, capabilities

This file comment should just refer to regions now.

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static
  2025-03-18  9:54 ` [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static Cédric Le Goater
  2025-03-19 12:14   ` Joao Martins
@ 2025-03-19 16:54   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:54 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:11AM +0100, Cédric Le Goater wrote:

> vfio_devices_query_dirty_bitmap() is only used in "dirty-tracking.c".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services
  2025-03-18  9:53 ` [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services Cédric Le Goater
  2025-03-19 12:29   ` Prasad Pandit
  2025-03-19 14:05   ` Avihai Horon
@ 2025-03-19 16:55   ` John Levon
  2 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:55 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:49AM +0100, Cédric Le Goater wrote:

> Gather all VFIO migration related declarations into "migration.h" to
> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

LGTM modulo the other's comments.

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h
  2025-03-18  9:54 ` [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h Cédric Le Goater
  2025-03-19 14:27   ` Avihai Horon
@ 2025-03-19 16:56   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:56 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:09AM +0100, Cédric Le Goater wrote:

> "hw/vfio/vfio-common.h" has been emptied of most of its declarations
> by the previous changes and the only declarations left are related to
> VFIODevice. Rename it to "hw/vfio/vfio-device.h" and make the
> necessary adjustments.

>  include/hw/vfio/{vfio-common.h => vfio-device.h} | 0

Do you want to update this comment too:

    2  * common header for vfio based device assignment support                        

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 32/32] vfio: Rename RAM discard related services
  2025-03-18  9:54 ` [PATCH for-10.1 32/32] vfio: Rename RAM discard related services Cédric Le Goater
@ 2025-03-19 16:57   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:57 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:15AM +0100, Cédric Le Goater wrote:

> Rename some routines to better reflect the namespace they belong to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>  hw/vfio/dirty-tracking.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
> index d7827f7b64adf3e2b41fafd59aab71e0b28c1567..50699a411de3ecd7424a48c7bb583ce39370a296 100644
> --- a/hw/vfio/dirty-tracking.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -262,7 +262,7 @@ static int vfio_ram_discard_notify_populate(RamDiscardListener *rdl,
>      return 0;
>  }
>  
> -static void vfio_register_ram_discard_listener(VFIOContainerBase *bcontainer,
> +static void  vfio_ram_discard_register_listener(VFIOContainerBase *bcontainer,
>                                                 MemoryRegionSection *section)
>  {
>      RamDiscardManager *rdm = memory_region_get_ram_discard_manager(section->mr);
> @@ -337,7 +337,7 @@ static void vfio_register_ram_discard_listener(VFIOContainerBase *bcontainer,
>      }
>  }
>  
> -static void vfio_unregister_ram_discard_listener(VFIOContainerBase *bcontainer,
> +static void  vfio_ram_discard_unregister_listener(VFIOContainerBase *bcontainer,
>                                                   MemoryRegionSection *section)

Hyper-nit: these grew an additional space after the void.

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 23/32] vfio: Move vfio_de/attach_device() into device.c
  2025-03-18  9:54 ` [PATCH for-10.1 23/32] vfio: Move vfio_de/attach_device() " Cédric Le Goater
@ 2025-03-19 16:58   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 16:58 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:06AM +0100, Cédric Le Goater wrote:

> These routines are VFIODevice related. Move their definitions into
> "device.c".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations
  2025-03-18  9:53 ` [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations Cédric Le Goater
@ 2025-03-19 17:00   ` John Levon
  2025-03-20  9:24   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 17:00 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:54AM +0100, Cédric Le Goater wrote:

> Gather all VFIOcontainer related declarations into "container.h" to
> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> These declarations are made available externally for PPC and s390x.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c
  2025-03-18  9:54 ` [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c Cédric Le Goater
  2025-03-19 12:12   ` Prasad Pandit
@ 2025-03-19 17:00   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 17:00 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:08AM +0100, Cédric Le Goater wrote:

> This routine is related to VFIO migration. It belongs to "migration.c".
> While at it, rename it to better reflect the namespace it belongs to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 20/32] vfio: Introduce new files for CPR definitions and declarations
  2025-03-18  9:54 ` [PATCH for-10.1 20/32] vfio: Introduce new files for CPR definitions and declarations Cédric Le Goater
@ 2025-03-19 17:01   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-19 17:01 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:03AM +0100, Cédric Le Goater wrote:

> Gather all CPR related declarations into "cpr.h" to reduce exposure
> of VFIO internals in "hw/vfio/vfio-common.h".
> 
> Order file list in meson.build while at it.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
>  hw/vfio/cpr.h                 | 15 +++++++++++++++
>  include/hw/vfio/vfio-common.h |  3 ---
>  hw/vfio/container.c           |  1 +
>  hw/vfio/cpr.c                 |  1 +
>  hw/vfio/iommufd.c             |  1 +
>  hw/vfio/meson.build           |  2 +-
>  6 files changed, 19 insertions(+), 4 deletions(-)
>  create mode 100644 hw/vfio/cpr.h
> 
> diff --git a/hw/vfio/cpr.h b/hw/vfio/cpr.h
> new file mode 100644
> index 0000000000000000000000000000000000000000..88a5e7f878a3e01df3410f6f0a9c8b5ccddefe28
> --- /dev/null
> +++ b/hw/vfio/cpr.h
> @@ -0,0 +1,15 @@
> +/*
> + * VFIO display

Copy-paste error?

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services
  2025-03-19 12:29   ` Prasad Pandit
@ 2025-03-19 17:26     ` Cédric Le Goater
  2025-03-20  6:19       ` Prasad Pandit
  0 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-19 17:26 UTC (permalink / raw)
  To: Prasad Pandit
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

[ .. ]

> * Change looks okay. The header name 'migration.h' is rather generic,
> vfio-migration.h could be better. Looking at - #include "migration.h"
> - it is not clear which migration.h is being included. There is also a
> migration/migration.h header. But I'll leave that to you. (just
> sharing thoughts)

you are right. I am not satisfied with the header file names.

It has been problematic and I would prefer all header files to have
a "vfio-" prefix. Sadly, the gcc command line is making it difficult,
or I misunderstood some parts.

When using :

   #include "hw/vfio/foo.h"

"hw/vfio/foo.h" could refer to either :

   ./hw/vfio/foo.h

or

   ./include/hw/vfio/foo.h

I find it confusing that we can include files from anywhere in
the directory tree :/

May be call it "vfio-migration-internal.h" ?

or use always : #include "hw/vfio/migration.h" (and remove -I .) ?

Or rename the "include/hw/vfio/vfio-migration.h" file introduced
in patch 3 for external migration services to some other name.

Proposals welcome !

Thanks,

C.




^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services
  2025-03-19 14:05   ` Avihai Horon
@ 2025-03-19 17:33     ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-19 17:33 UTC (permalink / raw)
  To: Avihai Horon, qemu-devel, Alex Williamson; +Cc: Eric Auger, Zhenzhong Duan

On 3/19/25 15:05, Avihai Horon wrote:
> 
> On 18/03/2025 11:53, Cédric Le Goater wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> Gather all VFIO migration related declarations into "migration.h" to
>> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> Reviewed-by: Avihai Horon <avihaih@nvidia.com>
> 
> Two nits below.


I will add a third. Moving the vfio_device_state_is_* routines could be
done in separate change.



> 
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>>   hw/vfio/migration.h           | 72 +++++++++++++++++++++++++++++++++++
>>   include/hw/vfio/vfio-common.h | 54 +-------------------------
>>   hw/vfio/common.c              | 17 +--------
>>   hw/vfio/iommufd.c             |  1 +
>>   hw/vfio/migration-multifd.c   |  1 +
>>   hw/vfio/migration.c           | 17 +++++++++
>>   hw/vfio/pci.c                 |  1 +
>>   7 files changed, 94 insertions(+), 69 deletions(-)
>>   create mode 100644 hw/vfio/migration.h
>>
>> diff --git a/hw/vfio/migration.h b/hw/vfio/migration.h
>> new file mode 100644
>> index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
>> --- /dev/null
>> +++ b/hw/vfio/migration.h
>> @@ -0,0 +1,72 @@
>> +/*
>> + * VFIO migration
>> + *
>> + * Copyright Red Hat, Inc. 2025
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +
>> +#ifndef HW_VFIO_MIGRATION_H
>> +#define HW_VFIO_MIGRATION_H
>> +
>> +#ifdef CONFIG_LINUX
>> +#include <linux/vfio.h>
>> +#endif
>> +
>> +#include "qemu/notify.h"
>> +
>> +/*
>> + * Flags to be used as unique delimiters for VFIO devices in the migration
>> + * stream. These flags are composed as:
>> + * 0xffffffff => MSB 32-bit all 1s
>> + * 0xef10     => Magic ID, represents emulated (virtual) function IO
>> + * 0x0000     => 16-bits reserved for flags
>> + *
>> + * The beginning of state information is marked by _DEV_CONFIG_STATE,
>> + * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
>> + * certain state information is marked by _END_OF_STATE.
>> + */
>> +#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
>> +#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
>> +#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
>> +#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
>> +#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
>> +
>> +typedef struct VFIODevice VFIODevice;
>> +typedef struct VFIOMultifd VFIOMultifd;
>> +
>> +typedef struct VFIOMigration {
>> +    struct VFIODevice *vbasedev;
>> +    VMChangeStateEntry *vm_state;
>> +    NotifierWithReturn migration_state;
>> +    uint32_t device_state;
>> +    int data_fd;
>> +    void *data_buffer;
>> +    size_t data_buffer_size;
>> +    uint64_t mig_flags;
>> +    uint64_t precopy_init_size;
>> +    uint64_t precopy_dirty_size;
>> +    bool multifd_transfer;
>> +    VFIOMultifd *multifd;
>> +    bool initial_data_sent;
>> +
>> +    bool event_save_iterate_started;
>> +    bool event_precopy_empty_hit;
>> +} VFIOMigration;
>> +
>> +
> 
> Extra line break.
> 
>> +bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
>> +void vfio_migration_exit(VFIODevice *vbasedev);
>> +bool vfio_device_state_is_running(VFIODevice *vbasedev);
>> +bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
>> +int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
>> +int vfio_load_device_config_state(QEMUFile *f, void *opaque);
>> +
>> +#ifdef CONFIG_LINUX
>> +int vfio_migration_set_state(VFIODevice *vbasedev,
>> +                             enum vfio_device_mig_state new_state,
>> +                             enum vfio_device_mig_state recover_state,
>> +                             Error **errp);
>> +#endif
>> +
>> +#endif /* HW_VFIO_MIGRATION_H */
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>> index 0aae88131cffda1a90b8ccd0224387133c0fa83a..799e12d43747addbf444c15052f629b65978322f 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -23,7 +23,6 @@
>>
>>   #include "exec/memory.h"
>>   #include "qemu/queue.h"
>> -#include "qemu/notify.h"
>>   #include "ui/console.h"
>>   #include "hw/display/ramfb.h"
>>   #ifdef CONFIG_LINUX
>> @@ -36,23 +35,6 @@
>>
>>   #define VFIO_MSG_PREFIX "vfio %s: "
>>
>> -/*
>> - * Flags to be used as unique delimiters for VFIO devices in the migration
>> - * stream. These flags are composed as:
>> - * 0xffffffff => MSB 32-bit all 1s
>> - * 0xef10     => Magic ID, represents emulated (virtual) function IO
>> - * 0x0000     => 16-bits reserved for flags
>> - *
>> - * The beginning of state information is marked by _DEV_CONFIG_STATE,
>> - * _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
>> - * certain state information is marked by _END_OF_STATE.
>> - */
>> -#define VFIO_MIG_FLAG_END_OF_STATE      (0xffffffffef100001ULL)
>> -#define VFIO_MIG_FLAG_DEV_CONFIG_STATE  (0xffffffffef100002ULL)
>> -#define VFIO_MIG_FLAG_DEV_SETUP_STATE   (0xffffffffef100003ULL)
>> -#define VFIO_MIG_FLAG_DEV_DATA_STATE    (0xffffffffef100004ULL)
>> -#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)
>> -
>>   enum {
>>       VFIO_DEVICE_TYPE_PCI = 0,
>>       VFIO_DEVICE_TYPE_PLATFORM = 1,
>> @@ -78,27 +60,6 @@ typedef struct VFIORegion {
>>       uint8_t nr; /* cache the region number for debug */
>>   } VFIORegion;
>>
>> -typedef struct VFIOMultifd VFIOMultifd;
>> -
>> -typedef struct VFIOMigration {
>> -    struct VFIODevice *vbasedev;
>> -    VMChangeStateEntry *vm_state;
>> -    NotifierWithReturn migration_state;
>> -    uint32_t device_state;
>> -    int data_fd;
>> -    void *data_buffer;
>> -    size_t data_buffer_size;
>> -    uint64_t mig_flags;
>> -    uint64_t precopy_init_size;
>> -    uint64_t precopy_dirty_size;
>> -    bool multifd_transfer;
>> -    VFIOMultifd *multifd;
>> -    bool initial_data_sent;
>> -
>> -    bool event_save_iterate_started;
>> -    bool event_precopy_empty_hit;
>> -} VFIOMigration;
>> -
>>   struct VFIOGroup;
>>
>>   typedef struct VFIOContainer {
>> @@ -136,6 +97,7 @@ typedef struct VFIOIOMMUFDContainer {
>>   OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer, VFIO_IOMMU_IOMMUFD);
>>
>>   typedef struct VFIODeviceOps VFIODeviceOps;
>> +typedef struct VFIOMigration VFIOMigration;
>>
>>   typedef struct VFIODevice {
>>       QLIST_ENTRY(VFIODevice) next;
>> @@ -290,12 +252,6 @@ extern VFIODeviceList vfio_device_list;
>>   extern const MemoryListener vfio_memory_listener;
>>   extern int vfio_kvm_device_fd;
>>
>> -bool vfio_device_state_is_running(VFIODevice *vbasedev);
>> -bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
>> -
>> -int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
>> -int vfio_load_device_config_state(QEMUFile *f, void *opaque);
>> -
>>   #ifdef CONFIG_LINUX
>>   int vfio_get_region_info(VFIODevice *vbasedev, int index,
>>                            struct vfio_region_info **info);
>> @@ -310,16 +266,8 @@ struct vfio_info_cap_header *
>>   vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
>>   struct vfio_info_cap_header *
>>   vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id);
>> -
>> -int vfio_migration_set_state(VFIODevice *vbasedev,
>> -                             enum vfio_device_mig_state new_state,
>> -                             enum vfio_device_mig_state recover_state,
>> -                             Error **errp);
>>   #endif
>>
>> -bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
>> -void vfio_migration_exit(VFIODevice *vbasedev);
>> -
>>   int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size);
>>   bool vfio_devices_all_dirty_tracking_started(
>>       const VFIOContainerBase *bcontainer);
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -44,6 +44,7 @@
>>   #include "migration/qemu-file.h"
>>   #include "system/tcg.h"
>>   #include "system/tpm.h"
>> +#include "migration.h"
>>
>>   VFIODeviceList vfio_device_list =
>>       QLIST_HEAD_INITIALIZER(vfio_device_list);
>> @@ -72,22 +73,6 @@ static void vfio_set_migration_error(int ret)
>>       }
>>   }
>>
>> -bool vfio_device_state_is_running(VFIODevice *vbasedev)
>> -{
>> -    VFIOMigration *migration = vbasedev->migration;
>> -
>> -    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
>> -           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
>> -}
>> -
>> -bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
>> -{
>> -    VFIOMigration *migration = vbasedev->migration;
>> -
>> -    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
>> -           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
>> -}
>> -
>>   static bool vfio_devices_all_device_dirty_tracking_started(
>>       const VFIOContainerBase *bcontainer)
>>   {
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -25,6 +25,7 @@
>>   #include "qemu/cutils.h"
>>   #include "qemu/chardev_open.h"
>>   #include "pci.h"
>> +#include "migration.h"
> 
> I think iommufd.c doesn't need migration.h.

Indeed !


Thanks,

C.


> 
> Thanks.
> 
>>
>>   static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
>>                               ram_addr_t size, void *vaddr, bool readonly)
>> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
>> index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
>> --- a/hw/vfio/migration-multifd.c
>> +++ b/hw/vfio/migration-multifd.c
>> @@ -22,6 +22,7 @@
>>   #include "io/channel-buffer.h"
>>   #include "migration/qemu-file.h"
>>   #include "migration-multifd.h"
>> +#include "migration.h"
>>   #include "trace.h"
>>
>>   #define VFIO_DEVICE_STATE_CONFIG_STATE (1)
>> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
>> index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
>> --- a/hw/vfio/migration.c
>> +++ b/hw/vfio/migration.c
>> @@ -31,6 +31,7 @@
>>   #include "pci.h"
>>   #include "trace.h"
>>   #include "hw/hw.h"
>> +#include "migration.h"
>>
>>   /*
>>    * This is an arbitrary size based on migration of mlx5 devices, where typically
>> @@ -1222,3 +1223,19 @@ void vfio_migration_exit(VFIODevice *vbasedev)
>>
>>       migrate_del_blocker(&vbasedev->migration_blocker);
>>   }
>> +
>> +bool vfio_device_state_is_running(VFIODevice *vbasedev)
>> +{
>> +    VFIOMigration *migration = vbasedev->migration;
>> +
>> +    return migration->device_state == VFIO_DEVICE_STATE_RUNNING ||
>> +           migration->device_state == VFIO_DEVICE_STATE_RUNNING_P2P;
>> +}
>> +
>> +bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
>> +{
>> +    VFIOMigration *migration = vbasedev->migration;
>> +
>> +    return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||
>> +           migration->device_state == VFIO_DEVICE_STATE_PRE_COPY_P2P;
>> +}
>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644
>> --- a/hw/vfio/pci.c
>> +++ b/hw/vfio/pci.c
>> @@ -44,6 +44,7 @@
>>   #include "migration/blocker.h"
>>   #include "migration/qemu-file.h"
>>   #include "system/iommufd.h"
>> +#include "migration.h"
>>
>>   #define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
>>
>> -- 
>> 2.48.1
>>
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services
  2025-03-19 17:26     ` Cédric Le Goater
@ 2025-03-20  6:19       ` Prasad Pandit
  0 siblings, 0 replies; 114+ messages in thread
From: Prasad Pandit @ 2025-03-20  6:19 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Wed, 19 Mar 2025 at 22:57, Cédric Le Goater <clg@redhat.com> wrote:
> you are right. I am not satisfied with the header file names.
>
> It has been problematic and I would prefer all header files to have
> a "vfio-" prefix. Sadly, the gcc command line is making it difficult,
> or I misunderstood some parts.
>
> When using :
>
>    #include "hw/vfio/foo.h"
>
> "hw/vfio/foo.h" could refer to either :
>
>    ./hw/vfio/foo.h
>
> or
>
>    ./include/hw/vfio/foo.h
>
> I find it confusing that we can include files from anywhere in
> the directory tree :/

* IIUC, gcc(1) picks the _first_ matching header (name) it finds
across listed (with -I) include directories. When the header name is
quoted ("foo.h"), the search begins from the directory where the
source file resides. In the above example, if the command line was: ..
-I ./hw/vfio/  -I ./include/hw/vfio/  then foo.h from './hw/vfio/'
gets used. If the command line was: -I ./include/hw/vfio/  -I
./hw/vfio/  then foo.h from './include/hw/vfio/' gets used.

> May be call it "vfio-migration-internal.h" ?
>
> or use always : #include "hw/vfio/migration.h" (and remove -I .) ?
>
> Or rename the "include/hw/vfio/vfio-migration.h" file introduced
> in patch 3 for external migration services to some other name.

* It helps to have a unique header (file) name across the project. I
don't see any vfio-migration.h in the current git master.

Thank you.
---
  - Prasad



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions
  2025-03-19 16:42   ` John Levon
@ 2025-03-20  9:01     ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-20  9:01 UTC (permalink / raw)
  To: John Levon
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On 3/19/25 17:42, John Levon wrote:
> On Tue, Mar 18, 2025 at 10:54:02AM +0100, Cédric Le Goater wrote:
> 
>> diff --git a/hw/vfio/device.c b/hw/vfio/device.c
>> new file mode 100644
>> index 0000000000000000000000000000000000000000..daa5bae59ca9c65ef23aa193d4e63976fcefdde0
>> --- /dev/null
>> +++ b/hw/vfio/device.c
>> @@ -0,0 +1,331 @@
>> +/*
>> + * low level and IOMMU backend agnostic helpers used by VFIO devices,
>> + * related to regions, interrupts, capabilities
> 
> This same comment is still at the top of helpers.c - and I'm not sure what
> *does* belong still in helpers.c ?
After this series, mostly low level stuff analyzing vfio_region/device_info
and KVM device related services:

vfio_bitmap_alloc
vfio_get_cap
vfio_get_device_info
vfio_get_device_info_cap
vfio_get_info_dma_avail
vfio_get_iommu_type1_info_cap
vfio_get_region_info_cap
vfio_kvm_device_add_fd
vfio_kvm_device_del_fd
vfio_kvm_device_fd



Thanks,

C.




^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations
  2025-03-18  9:53 ` [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations Cédric Le Goater
  2025-03-19  9:09   ` John Levon
@ 2025-03-20  9:18   ` Duan, Zhenzhong
  2025-03-20 13:37     ` Cédric Le Goater
  1 sibling, 1 reply; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:18 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 09/32] vfio: Introduce a new header file for
>VFIOIOMMUFD declarations
>
>Gather all VFIOIOMMUFD related declarations into "iommufd.h" to
>reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>
>---
> hw/vfio/iommufd.h             | 29 +++++++++++++++++++++++++++++
> include/hw/vfio/vfio-common.h | 21 +++------------------
> hw/vfio/iommufd.c             |  1 +
> 3 files changed, 33 insertions(+), 18 deletions(-)
> create mode 100644 hw/vfio/iommufd.h
>
>diff --git a/hw/vfio/iommufd.h b/hw/vfio/iommufd.h
>new file mode 100644
>index
>0000000000000000000000000000000000000000..7d87994c4fadbc328b6ac7f9ae
>e00469dd8808b0
>--- /dev/null
>+++ b/hw/vfio/iommufd.h
>@@ -0,0 +1,29 @@
>+/*
>+ * VFIO iommufd
>+ *
>+ * Copyright Red Hat, Inc. 2025
>+ *
>+ * SPDX-License-Identifier: GPL-2.0-or-later
>+ */
>+
>+#ifndef HW_VFIO_IOMMUFD_H
>+#define HW_VFIO_IOMMUFD_H
>+
>+
>+typedef struct VFIOIOASHwpt {
>+    uint32_t hwpt_id;
>+    uint32_t hwpt_flags;
>+    QLIST_HEAD(, VFIODevice) device_list;
>+    QLIST_ENTRY(VFIOIOASHwpt) next;
>+} VFIOIOASHwpt;
>+
>+typedef struct VFIOIOMMUFDContainer {
>+    VFIOContainerBase bcontainer;
>+    IOMMUFDBackend *be;

Do we need to add 'typedef struct IOMMUFDBackend IOMMUFDBackend;' for above line?

Thanks
Zhenzhong

>+    uint32_t ioas_id;
>+    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
>+} VFIOIOMMUFDContainer;
>+
>+OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer,
>VFIO_IOMMU_IOMMUFD);
>+
>+#endif /* HW_VFIO_IOMMUFD_H */
>diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>index
>3355c2d4e57569d7bb01b4d9378fb49a807335e8..8d48f5300a791d8858fe29d1bb
>905f814ef11990 100644
>--- a/include/hw/vfio/vfio-common.h
>+++ b/include/hw/vfio/vfio-common.h
>@@ -69,27 +69,12 @@ typedef struct VFIOContainer {
>
> OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
>
>-typedef struct IOMMUFDBackend IOMMUFDBackend;
>-
>-typedef struct VFIOIOASHwpt {
>-    uint32_t hwpt_id;
>-    uint32_t hwpt_flags;
>-    QLIST_HEAD(, VFIODevice) device_list;
>-    QLIST_ENTRY(VFIOIOASHwpt) next;
>-} VFIOIOASHwpt;
>-
>-typedef struct VFIOIOMMUFDContainer {
>-    VFIOContainerBase bcontainer;
>-    IOMMUFDBackend *be;
>-    uint32_t ioas_id;
>-    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
>-} VFIOIOMMUFDContainer;
>-
>-OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer,
>VFIO_IOMMU_IOMMUFD);
>-
> typedef struct VFIODeviceOps VFIODeviceOps;
> typedef struct VFIOMigration VFIOMigration;
>
>+typedef struct IOMMUFDBackend IOMMUFDBackend;
>+typedef struct VFIOIOASHwpt VFIOIOASHwpt;
>+
> typedef struct VFIODevice {
>     QLIST_ENTRY(VFIODevice) next;
>     QLIST_ENTRY(VFIODevice) container_next;
>diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>index
>2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0..a219b6453037e2d4e0d12800ea
>25678885af98f8 100644
>--- a/hw/vfio/iommufd.c
>+++ b/hw/vfio/iommufd.c
>@@ -26,6 +26,7 @@
> #include "qemu/chardev_open.h"
> #include "pci.h"
> #include "migration.h"
>+#include "iommufd.h"
>
> static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr
>iova,
>                             ram_addr_t size, void *vaddr, bool readonly)
>--
>2.48.1


^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations
  2025-03-18  9:53 ` [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations Cédric Le Goater
  2025-03-19 17:00   ` John Levon
@ 2025-03-20  9:24   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:24 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 11/32] vfio: Introduce a new header file for
>VFIOcontainer declarations
>
>Gather all VFIOcontainer related declarations into "container.h" to
>reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
>
>These declarations are made available externally for PPC and s390x.
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Thanks
Zhenzhong

^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 12/32] vfio: Make vfio_group_list static
  2025-03-18  9:53 ` [PATCH for-10.1 12/32] vfio: Make vfio_group_list static Cédric Le Goater
@ 2025-03-20  9:28   ` Duan, Zhenzhong
  2025-03-20  9:38   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:28 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger

>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 12/32] vfio: Make vfio_group_list static
>
>vfio_group_list is only used in file "container.c".
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Thanks
Zhenzhong


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 22/32] vfio: Move vfio_device_list into device.c
  2025-03-18  9:54 ` [PATCH for-10.1 22/32] vfio: Move vfio_device_list into device.c Cédric Le Goater
@ 2025-03-20  9:29   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:29 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:05AM +0100, Cédric Le Goater wrote:

> 'vfio_device_list' is VFIODevice related. Move its definitions into
> "device.c".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 27/32] vfio: Rename VFIODevice related services
  2025-03-18  9:54 ` [PATCH for-10.1 27/32] vfio: Rename VFIODevice related services Cédric Le Goater
@ 2025-03-20  9:35   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:35 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:10AM +0100, Cédric Le Goater wrote:

> index 4fdb74e33c427595a9b0a4d28b2b5a70df951e4e..9000702aed960ccb69ca67ec052f1ebe11ee1919 100644
> --- a/hw/vfio/ap.c
> +++ b/hw/vfio/ap.c
> @@ -117,7 +117,7 @@ static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev,
>      fd = event_notifier_get_fd(notifier);
>      qemu_set_fd_handler(fd, fd_read, NULL, vapdev);
>  
> -    if (!vfio_set_irq_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd,
> +    if (!vfio_device_irq_set_signaling(vdev, irq, 0, VFIO_IRQ_SET_ACTION_TRIGGER, fd,
>                                  errp)) {

Nit here, below - indentation is now off.

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c
  2025-03-18  9:53 ` [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c Cédric Le Goater
  2025-03-19 16:45   ` John Levon
@ 2025-03-20  9:36   ` Duan, Zhenzhong
  2025-03-20 19:26     ` Cédric Le Goater
  1 sibling, 1 reply; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:36 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into
>container-base.c
>
>VFIOAddressSpace is a common object used by VFIOContainerBase which is
>declared in "hw/vfio/vfio-container-base.h". Move the VFIOAddressSpace
>related services into "container-base.c".
>
>While at it, rename :
>
>  vfio_get_address_space -> vfio_address_space_get
>  vfio_put_address_space -> vfio_address_space_put
>
>to better reflect the namespace these routines belong to.
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>
>---
> include/hw/vfio/vfio-common.h         |  6 ---
> include/hw/vfio/vfio-container-base.h |  5 ++
> hw/ppc/spapr_pci_vfio.c               |  5 +-
> hw/vfio/common.c                      | 66 -------------------------
> hw/vfio/container-base.c              | 69 +++++++++++++++++++++++++++
> hw/vfio/container.c                   |  6 +--
> hw/vfio/iommufd.c                     |  6 +--
> hw/vfio/trace-events                  |  4 +-
> 8 files changed, 85 insertions(+), 82 deletions(-)
>
>diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>index
>e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236
>cac0bbe834b39 100644
>--- a/include/hw/vfio/vfio-common.h
>+++ b/include/hw/vfio/vfio-common.h
>@@ -120,18 +120,12 @@ struct VFIODeviceOps {
> #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \
>             TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
>
>-VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
>-void vfio_put_address_space(VFIOAddressSpace *space);
>-void vfio_address_space_insert(VFIOAddressSpace *space,
>-                               VFIOContainerBase *bcontainer);
>-
> 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);
> bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
>                             int action, int fd, Error **errp);
>
>-void vfio_reset_handler(void *opaque);
> struct vfio_device_info *vfio_get_device_info(int fd);
> bool vfio_device_is_mdev(VFIODevice *vbasedev);
> bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
>diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-
>container-base.h
>index
>4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda954
>8c8e60afefe794 100644
>--- a/include/hw/vfio/vfio-container-base.h
>+++ b/include/hw/vfio/vfio-container-base.h
>@@ -71,6 +71,11 @@ typedef struct VFIORamDiscardListener {
>     QLIST_ENTRY(VFIORamDiscardListener) next;
> } VFIORamDiscardListener;
>
>+VFIOAddressSpace *vfio_address_space_get(AddressSpace *as);
>+void vfio_address_space_put(VFIOAddressSpace *space);
>+void vfio_address_space_insert(VFIOAddressSpace *space,
>+                               VFIOContainerBase *bcontainer);
>+
> int vfio_container_dma_map(VFIOContainerBase *bcontainer,
>                            hwaddr iova, ram_addr_t size,
>                            void *vaddr, bool readonly);
>diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
>index
>1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc21
>95bf68418e5206 100644
>--- a/hw/ppc/spapr_pci_vfio.c
>+++ b/hw/ppc/spapr_pci_vfio.c
>@@ -24,7 +24,6 @@
> #include "hw/pci-host/spapr.h"
> #include "hw/pci/msix.h"
> #include "hw/pci/pci_device.h"
>-#include "hw/vfio/vfio-common.h"
> #include "hw/vfio/vfio-container.h"
> #include "qemu/error-report.h"
> #include CONFIG_DEVICES /* CONFIG_VFIO_PCI */
>@@ -86,7 +85,7 @@ static int vfio_eeh_container_op(VFIOContainer *container,
>uint32_t op)
>
> static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
> {
>-    VFIOAddressSpace *space = vfio_get_address_space(as);
>+    VFIOAddressSpace *space = vfio_address_space_get(as);
>     VFIOContainerBase *bcontainer = NULL;
>
>     if (QLIST_EMPTY(&space->containers)) {
>@@ -106,7 +105,7 @@ static VFIOContainer
>*vfio_eeh_as_container(AddressSpace *as)
>     }
>
> out:
>-    vfio_put_address_space(space);
>+    vfio_address_space_put(space);
>     return container_of(bcontainer, VFIOContainer, bcontainer);
> }
>
>diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>index
>0e3746eddd1c08e98bf57a59d542e158487d346e..08e2494d7c4a9858657724730
>b2829290fb3f197 100644
>--- a/hw/vfio/common.c
>+++ b/hw/vfio/common.c
>@@ -36,7 +36,6 @@
> #include "qemu/main-loop.h"
> #include "qemu/range.h"
> #include "system/kvm.h"
>-#include "system/reset.h"
> #include "system/runstate.h"
> #include "trace.h"
> #include "qapi/error.h"
>@@ -48,8 +47,6 @@
>
> VFIODeviceList vfio_device_list =
>     QLIST_HEAD_INITIALIZER(vfio_device_list);
>-static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
>-    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
>
> #ifdef CONFIG_KVM
> /*
>@@ -1304,24 +1301,6 @@ const MemoryListener vfio_memory_listener = {
>     .log_sync = vfio_listener_log_sync,
> };
>
>-void vfio_reset_handler(void *opaque)
>-{
>-    VFIODevice *vbasedev;
>-
>-    trace_vfio_reset_handler();
>-    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>-        if (vbasedev->dev->realized) {
>-            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
>-        }
>-    }
>-
>-    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>-        if (vbasedev->dev->realized && vbasedev->needs_reset) {
>-            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
>-        }
>-    }
>-}
>-
> int vfio_kvm_device_add_fd(int fd, Error **errp)
> {
> #ifdef CONFIG_KVM
>@@ -1380,51 +1359,6 @@ int vfio_kvm_device_del_fd(int fd, Error **errp)
>     return 0;
> }
>
>-VFIOAddressSpace *vfio_get_address_space(AddressSpace *as)
>-{
>-    VFIOAddressSpace *space;
>-
>-    QLIST_FOREACH(space, &vfio_address_spaces, list) {
>-        if (space->as == as) {
>-            return space;
>-        }
>-    }
>-
>-    /* No suitable VFIOAddressSpace, create a new one */
>-    space = g_malloc0(sizeof(*space));
>-    space->as = as;
>-    QLIST_INIT(&space->containers);
>-
>-    if (QLIST_EMPTY(&vfio_address_spaces)) {
>-        qemu_register_reset(vfio_reset_handler, NULL);
>-    }
>-
>-    QLIST_INSERT_HEAD(&vfio_address_spaces, space, list);
>-
>-    return space;
>-}
>-
>-void vfio_put_address_space(VFIOAddressSpace *space)
>-{
>-    if (!QLIST_EMPTY(&space->containers)) {
>-        return;
>-    }
>-
>-    QLIST_REMOVE(space, list);
>-    g_free(space);
>-
>-    if (QLIST_EMPTY(&vfio_address_spaces)) {
>-        qemu_unregister_reset(vfio_reset_handler, NULL);
>-    }
>-}
>-
>-void vfio_address_space_insert(VFIOAddressSpace *space,
>-                               VFIOContainerBase *bcontainer)
>-{
>-    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>-    bcontainer->space = space;
>-}
>-
> struct vfio_device_info *vfio_get_device_info(int fd)
> {
>     struct vfio_device_info *info;
>diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
>index
>749a3fd29dd6fc9143f14edf7e4ac6238315fcce..83e83ab9e67de8b004dfaf0067e
>4c466a6c88451 100644
>--- a/hw/vfio/container-base.c
>+++ b/hw/vfio/container-base.c
>@@ -13,7 +13,76 @@
> #include "qemu/osdep.h"
> #include "qapi/error.h"
> #include "qemu/error-report.h"
>+#include "system/reset.h"
> #include "hw/vfio/vfio-container-base.h"
>+#include "hw/vfio/vfio-common.h" /* for vfio_device_list */
>+#include "trace.h"
>+
>+static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
>+    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
>+
>+static void vfio_reset_handler(void *opaque)
>+{
>+    VFIODevice *vbasedev;
>+
>+    trace_vfio_reset_handler();
>+    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>+        if (vbasedev->dev->realized) {
>+            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
>+        }
>+    }
>+
>+    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>+        if (vbasedev->dev->realized && vbasedev->needs_reset) {
>+            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
>+        }
>+    }
>+}

This is not an address space scoped function, no sure if better to move to helper.c or common.c

Thanks
Zhenzhong

>+
>+VFIOAddressSpace *vfio_address_space_get(AddressSpace *as)
>+{
>+    VFIOAddressSpace *space;
>+
>+    QLIST_FOREACH(space, &vfio_address_spaces, list) {
>+        if (space->as == as) {
>+            return space;
>+        }
>+    }
>+
>+    /* No suitable VFIOAddressSpace, create a new one */
>+    space = g_malloc0(sizeof(*space));
>+    space->as = as;
>+    QLIST_INIT(&space->containers);
>+
>+    if (QLIST_EMPTY(&vfio_address_spaces)) {
>+        qemu_register_reset(vfio_reset_handler, NULL);
>+    }
>+
>+    QLIST_INSERT_HEAD(&vfio_address_spaces, space, list);
>+
>+    return space;
>+}
>+
>+void vfio_address_space_put(VFIOAddressSpace *space)
>+{
>+    if (!QLIST_EMPTY(&space->containers)) {
>+        return;
>+    }
>+
>+    QLIST_REMOVE(space, list);
>+    g_free(space);
>+
>+    if (QLIST_EMPTY(&vfio_address_spaces)) {
>+        qemu_unregister_reset(vfio_reset_handler, NULL);
>+    }
>+}
>+
>+void vfio_address_space_insert(VFIOAddressSpace *space,
>+                               VFIOContainerBase *bcontainer)
>+{
>+    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>+    bcontainer->space = space;
>+}
>
> int vfio_container_dma_map(VFIOContainerBase *bcontainer,
>                            hwaddr iova, ram_addr_t size,
>diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>index
>8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb..9b86e24a4072e579bcdc2c060c
>e42608ee44ee2e 100644
>--- a/hw/vfio/container.c
>+++ b/hw/vfio/container.c
>@@ -546,7 +546,7 @@ static bool vfio_connect_container(VFIOGroup *group,
>AddressSpace *as,
>     VFIOAddressSpace *space;
>     VFIOIOMMUClass *vioc;
>
>-    space = vfio_get_address_space(as);
>+    space = vfio_address_space_get(as);
>
>     /*
>      * VFIO is currently incompatible with discarding of RAM insofar as the
>@@ -675,7 +675,7 @@ close_fd_exit:
>     close(fd);
>
> put_space_exit:
>-    vfio_put_address_space(space);
>+    vfio_address_space_put(space);
>
>     return false;
> }
>@@ -714,7 +714,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
>         close(container->fd);
>         object_unref(container);
>
>-        vfio_put_address_space(space);
>+        vfio_address_space_put(space);
>     }
> }
>
>diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>index
>a219b6453037e2d4e0d12800ea25678885af98f8..a170f5c71218db8c9b2f00b1a4
>5ee900b6b21346 100644
>--- a/hw/vfio/iommufd.c
>+++ b/hw/vfio/iommufd.c
>@@ -487,7 +487,7 @@ static bool iommufd_cdev_attach(const char *name,
>VFIODevice *vbasedev,
>         goto err_connect_bind;
>     }
>
>-    space = vfio_get_address_space(as);
>+    space = vfio_address_space_get(as);
>
>     /*
>      * The HostIOMMUDevice data from legacy backend is static and doesn't need
>@@ -607,7 +607,7 @@ err_discard_disable:
> err_attach_container:
>     iommufd_cdev_container_destroy(container);
> err_alloc_ioas:
>-    vfio_put_address_space(space);
>+    vfio_address_space_put(space);
>     iommufd_cdev_unbind_and_disconnect(vbasedev);
> err_connect_bind:
>     close(vbasedev->fd);
>@@ -632,7 +632,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev)
>     vfio_cpr_unregister_container(bcontainer);
>     iommufd_cdev_detach_container(vbasedev, container);
>     iommufd_cdev_container_destroy(container);
>-    vfio_put_address_space(space);
>+    vfio_address_space_put(space);
>
>     iommufd_cdev_unbind_and_disconnect(vbasedev);
>     close(vbasedev->fd);
>diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>index
>81f4130100c48012c15b5b4858446149a7eaf5b6..c3691c1a172c31c5b10bfd6967
>c32fd32b65d0f7 100644
>--- a/hw/vfio/trace-events
>+++ b/hw/vfio/trace-events
>@@ -109,7 +109,6 @@ vfio_get_dev_region(const char *name, int index,
>uint32_t type, uint32_t subtype
> vfio_legacy_dma_unmap_overflow_workaround(void) ""
> vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size,
>uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64"
>bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
> vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu
>dirty @ 0x%"PRIx64" - 0x%"PRIx64
>-vfio_reset_handler(void) ""
>
> # region.c
> vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data,
>unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
>@@ -194,3 +193,6 @@ iommufd_cdev_fail_attach_existing_container(const
>char *msg) " %s"
> iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [iommufd=%d] new
>IOMMUFD container with ioasid=%d"
> iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int
>num_regions, int flags) " %s (%d) num_irqs=%d num_regions=%d flags=%d"
> iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int
>function, int dev_id) "\t%04x:%02x:%02x.%x devid %d"
>+
>+# container-base.c
>+vfio_reset_handler(void) ""
>--
>2.48.1


^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files
  2025-03-18  9:53 ` [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files Cédric Le Goater
  2025-03-19  9:10   ` John Levon
@ 2025-03-20  9:36   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:36 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into
>their respective files
>
>These definitions don't have any use outside of their respective
>submodules. There is no need to expose them externally. Keep them
>private.
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Thanks
Zhenzhong


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 29/32] vfio: Rename VFIOContainer related services
  2025-03-18  9:54 ` [PATCH for-10.1 29/32] vfio: Rename VFIOContainer related services Cédric Le Goater
@ 2025-03-20  9:38   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:38 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:12AM +0100, Cédric Le Goater wrote:

> Rename these routines :
> 
>   vfio_put_group -> vfio_group_put
>   vfio_get_group -> vfio_group_get
>   vfio_kvm_device_del_group -> vfio_group_del_kvm_device
>   vfio_kvm_device_add_group -> vfio_group_add_kvm_device
>   vfio_get_device -> vfio_device_get
>   vfio_put_base_device -> vfio_device_put
>   vfio_device_groupid -> vfio_device_get_groupid
>   vfio_connect_container -> vfio_container_connect
>   vfio_disconnect_container -> vfio_container_disconnect
> 
> to better reflect the namespace they belong to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 12/32] vfio: Make vfio_group_list static
  2025-03-18  9:53 ` [PATCH for-10.1 12/32] vfio: Make vfio_group_list static Cédric Le Goater
  2025-03-20  9:28   ` Duan, Zhenzhong
@ 2025-03-20  9:38   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:38 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:55AM +0100, Cédric Le Goater wrote:

> vfio_group_list is only used in file "container.c".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c
  2025-03-18  9:54 ` [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c Cédric Le Goater
  2025-03-19 16:46   ` John Levon
@ 2025-03-20  9:40   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:40 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to
>helpers.c
>
>vfio_kvm_device_add/del_fd() are low level routines. Move them with
>the other helpers.
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Thanks
Zhenzhong

^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services
  2025-03-18  9:53 ` [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services Cédric Le Goater
@ 2025-03-20  9:40   ` John Levon
  2025-03-21  9:25     ` Cédric Le Goater
  0 siblings, 1 reply; 114+ messages in thread
From: John Levon @ 2025-03-20  9:40 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:58AM +0100, Cédric Le Goater wrote:

> Gather all helper routine declarations into "helpers.h" to reduce
> exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

but

> +struct vfio_info_cap_header *
> +vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);

This can be static in fact.

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() to helpers.c
  2025-03-18  9:54 ` [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() " Cédric Le Goater
@ 2025-03-20  9:41   ` John Levon
  2025-03-20  9:42   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:41 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:01AM +0100, Cédric Le Goater wrote:

> vfio_get_device_info() is a low level routine. Move it with the other
> helpers.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() to helpers.c
  2025-03-18  9:54 ` [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() " Cédric Le Goater
  2025-03-20  9:41   ` John Levon
@ 2025-03-20  9:42   ` Duan, Zhenzhong
  1 sibling, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:42 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() to helpers.c
>
>vfio_get_device_info() is a low level routine. Move it with the other
>helpers.
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

Thanks
Zhenzhong

^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-18  9:54 ` [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services Cédric Le Goater
  2025-03-19 12:21   ` Joao Martins
@ 2025-03-20  9:42   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:42 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:13AM +0100, Cédric Le Goater wrote:

> Rename these routines :
> 
>   vfio_devices_all_device_dirty_tracking_started -> vfio_dirty_tracking_devices_is_started_all
>   vfio_devices_all_dirty_tracking_started        -> vfio_dirty_tracking_devices_is_started
>   vfio_devices_all_device_dirty_tracking         -> vfio_dirty_tracking_devices_is_supported
>   vfio_devices_dma_logging_start                 -> vfio_dirty_tracking_devices_dma_logging_start
>   vfio_devices_dma_logging_stop                  -> vfio_dirty_tracking_devices_dma_logging_stop
>   vfio_devices_query_dirty_bitmap                -> vfio_dirty_tracking_devices_query_dirty_bitmap
>   vfio_get_dirty_bitmap                          -> vfio_dirty_tracking_query_dirty_bitmap
> 
> to better reflect the namespace they belong to.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 08/32] vfio: Move VFIOHostDMAWindow definition into spapr.c
  2025-03-18  9:53 ` [PATCH for-10.1 08/32] vfio: Move VFIOHostDMAWindow definition into spapr.c Cédric Le Goater
@ 2025-03-20  9:43   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:43 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:51AM +0100, Cédric Le Goater wrote:

> VFIOHostDMAWindow is only used in file "spapr.c". Move it there.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 21/32] vfio: Move vfio_kvm_device_fd() into helpers.c
  2025-03-18  9:54 ` [PATCH for-10.1 21/32] vfio: Move vfio_kvm_device_fd() into helpers.c Cédric Le Goater
@ 2025-03-20  9:44   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:44 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:04AM +0100, Cédric Le Goater wrote:

> The vfio_kvm_device_add/del_fd() routines opening the VFIO pseudo
> device are defined in "helpers.c". Move 'vfio_kvm_device_fd'
> definition there and its declaration into "helpers.h" to reduce
> exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-18  9:54 ` [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations Cédric Le Goater
  2025-03-19 13:23   ` Joao Martins
@ 2025-03-20  9:46   ` John Levon
  2025-03-21  9:29     ` Cédric Le Goater
  2025-03-20  9:52   ` Duan, Zhenzhong
  2 siblings, 1 reply; 114+ messages in thread
From: John Levon @ 2025-03-20  9:46 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:07AM +0100, Cédric Le Goater wrote:

> File "common.c" has been emptied of most of its definitions by the
> previous changes and the only definitions left are related to dirty
> tracking. Rename it to "dirty-tracking.c" and introduce its associated
> "dirty-tracking.h" header file for the declarations.
> 
> Cleanup a little the includes while at it.
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

> rename from hw/vfio/common.c
> rename to hw/vfio/dirty-tracking.c
> index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -20,14 +20,10 @@

I think you might want to update the file comment from "generic functions used
by VFIO devices".

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines
  2025-03-18  9:54 ` [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines Cédric Le Goater
  2025-03-19 13:24   ` Joao Martins
@ 2025-03-20  9:49   ` John Levon
  1 sibling, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:49 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:54:14AM +0100, Cédric Le Goater wrote:

> This hides the MemoryListener implementation and makes the code common
> to both IOMMU backends, legacy and IOMMUFD.

Patch itself seems fine but

> index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644
> --- a/hw/vfio/dirty-tracking.c
> +++ b/hw/vfio/dirty-tracking.c
> @@ -1267,7 +1267,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,
>      }
>  }
>  
> -const MemoryListener vfio_memory_listener = {
> +static const MemoryListener vfio_memory_listener = {

In vfio-user, we register new begin/commit callbacks for non-dirty-tracking
purposes, making this location a little bit odd. But not for now I suppose.

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 07/32] vfio: Introduce a new header file for VFIOdisplay declarations
  2025-03-18  9:53 ` [PATCH for-10.1 07/32] vfio: Introduce a new header file for VFIOdisplay declarations Cédric Le Goater
@ 2025-03-20  9:50   ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-20  9:50 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Tue, Mar 18, 2025 at 10:53:50AM +0100, Cédric Le Goater wrote:

> Gather all VFIOdisplay related declarations into "display.h" to
> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
> 
> Signed-off-by: Cédric Le Goater <clg@redhat.com>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-18  9:54 ` [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations Cédric Le Goater
  2025-03-19 13:23   ` Joao Martins
  2025-03-20  9:46   ` John Levon
@ 2025-03-20  9:52   ` Duan, Zhenzhong
  2025-03-20 11:00     ` Joao Martins
  2025-03-21  9:31     ` Cédric Le Goater
  2 siblings, 2 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-20  9:52 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking
>definitions and declarations
>
>File "common.c" has been emptied of most of its definitions by the
>previous changes and the only definitions left are related to dirty
>tracking. Rename it to "dirty-tracking.c" and introduce its associated
>"dirty-tracking.h" header file for the declarations.
>
>Cleanup a little the includes while at it.
>
>Signed-off-by: Cédric Le Goater <clg@redhat.com>
>---
> hw/vfio/dirty-tracking.h               | 22 ++++++++++++++++++++++
> include/hw/vfio/vfio-common.h          | 10 ----------
> hw/vfio/container.c                    |  1 +
> hw/vfio/{common.c => dirty-tracking.c} |  5 +----
> hw/vfio/iommufd.c                      |  1 +
> hw/vfio/meson.build                    |  2 +-
> hw/vfio/trace-events                   |  2 +-
> 7 files changed, 27 insertions(+), 16 deletions(-)
> create mode 100644 hw/vfio/dirty-tracking.h
> rename hw/vfio/{common.c => dirty-tracking.c} (99%)
>
>diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>new file mode 100644
>index
>0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3
>db27b80bfe2d3a
>--- /dev/null
>+++ b/hw/vfio/dirty-tracking.h
>@@ -0,0 +1,22 @@
>+/*
>+ * VFIO dirty page tracking routines
>+ *
>+ * Copyright Red Hat, Inc. 2025
>+ *
>+ * SPDX-License-Identifier: GPL-2.0-or-later
>+ */
>+
>+#ifndef HW_VFIO_DIRTY_TRACKING_H
>+#define HW_VFIO_DIRTY_TRACKING_H
>+
>+extern const MemoryListener vfio_memory_listener;
>+
>+bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase
>*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,
>+                                    Error **errp);
>+int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>+                          uint64_t size, ram_addr_t ram_addr, Error **errp);
>+
>+#endif /* HW_VFIO_DIRTY_TRACKING_H */
>diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>index
>184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878
>d4d61818497426 100644
>--- a/include/hw/vfio/vfio-common.h
>+++ b/include/hw/vfio/vfio-common.h
>@@ -130,7 +130,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj);
>
> typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
> extern VFIODeviceList vfio_device_list;
>-extern const MemoryListener vfio_memory_listener;
>
> #ifdef CONFIG_LINUX
> int vfio_get_region_info(VFIODevice *vbasedev, int index,
>@@ -140,15 +139,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev,
>uint32_t type,
> bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
> #endif
>
>-bool vfio_devices_all_dirty_tracking_started(
>-    const VFIOContainerBase *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, Error **errp);
>-int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>-                          uint64_t size, ram_addr_t ram_addr, Error **errp);
>-
> /* Returns 0 on success, or a negative errno. */
> bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
> void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
>diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>index
>4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e
>46ab9c8b5019ae7 100644
>--- a/hw/vfio/container.c
>+++ b/hw/vfio/container.c
>@@ -35,6 +35,7 @@
> #include "hw/vfio/vfio-container.h"
> #include "helpers.h"
> #include "cpr.h"
>+#include "dirty-tracking.h"
>
> #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO
>TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
>
>diff --git a/hw/vfio/common.c b/hw/vfio/dirty-tracking.c
>similarity index 99%
>rename from hw/vfio/common.c
>rename to hw/vfio/dirty-tracking.c
>index
>ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143d
>cee5f0a89a900 100644
>--- a/hw/vfio/common.c
>+++ b/hw/vfio/dirty-tracking.c
>@@ -20,14 +20,10 @@
>
> #include "qemu/osdep.h"
> #include <sys/ioctl.h>
>-#ifdef CONFIG_KVM
>-#include <linux/kvm.h>
>-#endif

It looks this change unrelated to this patch?

> #include <linux/vfio.h>
>
> #include "hw/vfio/vfio-common.h"
> #include "hw/vfio/pci.h"
>-#include "exec/address-spaces.h"

Same here.

Thanks
Zhenzhong

> #include "exec/memory.h"
> #include "exec/ram_addr.h"
> #include "exec/target_page.h"
>@@ -45,6 +41,7 @@
> #include "system/tpm.h"
> #include "migration.h"
> #include "helpers.h"
>+#include "dirty-tracking.h"
>
> /*
>  * Device state interfaces
>diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>index
>b25f3b4086d7b7fc6fcd519a9b8b2904513a655f..9335a17920b32dc2bf9cb4eeb2b
>8f57382f14ac8 100644
>--- a/hw/vfio/iommufd.c
>+++ b/hw/vfio/iommufd.c
>@@ -29,6 +29,7 @@
> #include "iommufd.h"
> #include "helpers.h"
> #include "cpr.h"
>+#include "dirty-tracking.h"
>
> #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO             \
>             TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
>diff --git a/hw/vfio/meson.build b/hw/vfio/meson.build
>index
>1f89bd28c13dea55bcfff476ce99d51b453d8533..b6f5a7eeeda035b5872c2a19f80
>86384e000f420 100644
>--- a/hw/vfio/meson.build
>+++ b/hw/vfio/meson.build
>@@ -1,6 +1,6 @@
> vfio_ss = ss.source_set()
> vfio_ss.add(files(
>-  'common.c',
>+  'dirty-tracking.c',
>   'container.c',
>   'helpers.c',
> ))
>diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>index
>a1d01e9dde6ec52964d4804e9cbce5a6a32b7879..f3bdcebe938dcca77b913ef81a
>74644c622b5d8a 100644
>--- a/hw/vfio/trace-events
>+++ b/hw/vfio/trace-events
>@@ -89,7 +89,7 @@ vfio_pci_igd_bdsm_enabled(const char *name, int size)
>"%s %dMB"
> vfio_pci_igd_host_bridge_enabled(const char *name) "%s"
> vfio_pci_igd_lpc_bridge_enabled(const char *name) "%s"
>
>-# common.c
>+# dirty-tracking.c
> vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_end)
>"iommu %s @ 0x%"PRIx64" - 0x%"PRIx64
> vfio_listener_region_skip(const char *name, uint64_t start, uint64_t end)
>"SKIPPING %s 0x%"PRIx64" - 0x%"PRIx64
> vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to liobn
>fd %d"
>--
>2.48.1


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-20  9:52   ` Duan, Zhenzhong
@ 2025-03-20 11:00     ` Joao Martins
  2025-03-21  6:24       ` Duan, Zhenzhong
  2025-03-21  9:31     ` Cédric Le Goater
  1 sibling, 1 reply; 114+ messages in thread
From: Joao Martins @ 2025-03-20 11:00 UTC (permalink / raw)
  To: Duan, Zhenzhong
  Cc: Avihai Horon, Eric Auger, qemu-devel@nongnu.org,
	Cédric Le Goater, Alex Williamson

On 20/03/2025 09:52, Duan, Zhenzhong wrote:
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Subject: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking
>> definitions and declarations
>>
>> File "common.c" has been emptied of most of its definitions by the
>> previous changes and the only definitions left are related to dirty
>> tracking. Rename it to "dirty-tracking.c" and introduce its associated
>> "dirty-tracking.h" header file for the declarations.
>>
>> Cleanup a little the includes while at it.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/dirty-tracking.c
>> @@ -20,14 +20,10 @@
>>
>> #include "qemu/osdep.h"
>> #include <sys/ioctl.h>
>> -#ifdef CONFIG_KVM
>> -#include <linux/kvm.h>
>> -#endif
> 
> It looks this change unrelated to this patch?
> 
>> #include <linux/vfio.h>
>>
>> #include "hw/vfio/vfio-common.h"
>> #include "hw/vfio/pci.h"
>> -#include "exec/address-spaces.h"
> 
> Same here.
> 

It's written in the commit message:

	"Cleanup a little the includes while at it."


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-19 12:21   ` Joao Martins
@ 2025-03-20 11:13     ` Avihai Horon
  2025-03-20 11:18       ` Joao Martins
  2025-03-21 11:22     ` Cédric Le Goater
  1 sibling, 1 reply; 114+ messages in thread
From: Avihai Horon @ 2025-03-20 11:13 UTC (permalink / raw)
  To: Joao Martins, Cédric Le Goater
  Cc: Eric Auger, Zhenzhong Duan, qemu-devel, Alex Williamson


On 19/03/2025 14:21, Joao Martins wrote:
> External email: Use caution opening links or attachments
>
>
> On 18/03/2025 09:54, Cédric Le Goater wrote:
>> Rename these routines :
>>
>>    vfio_devices_all_device_dirty_tracking_started -> vfio_dirty_tracking_devices_is_started_all
>>    vfio_devices_all_dirty_tracking_started        -> vfio_dirty_tracking_devices_is_started
>>    vfio_devices_all_device_dirty_tracking         -> vfio_dirty_tracking_devices_is_supported
>>    vfio_devices_dma_logging_start                 -> vfio_dirty_tracking_devices_dma_logging_start
>>    vfio_devices_dma_logging_stop                  -> vfio_dirty_tracking_devices_dma_logging_stop
>>    vfio_devices_query_dirty_bitmap                -> vfio_dirty_tracking_devices_query_dirty_bitmap
>>    vfio_get_dirty_bitmap                          -> vfio_dirty_tracking_query_dirty_bitmap
>>
>> to better reflect the namespace they belong to.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> The change itself is fine.
>
> But on the other hand, it looks relatively long names, no? I am bit at two minds
> (as I generally prefer shorter code), but I can't find any alternatives if you
> really wanna have one namespaces associated with the subsystem:file as a C
> namespace.
>
> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
> when talking about this stuff, but it seems a detour from the code style to
> abbreviate namespaces into acronyms.
>
> Having said that:
>
>          Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
>
> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
> shorter.

This file is not related only to dirty tracking, but to memory in general.
Maybe a better naming would be memory.{c,h}?
Then we can have vfio_memory_* or vfio_mem_* prefix and rename to the below:

vfio_devices_all_device_dirty_tracking_started -> 
vfio_mem_device_dpt_is_started
vfio_devices_all_dirty_tracking_started        -> vfio_mem_dpt_is_started
vfio_devices_all_device_dirty_tracking         -> 
vfio_mem_device_dpt_is_supported
vfio_devices_dma_logging_start                 -> vfio_mem_device_dpt_start
vfio_devices_dma_logging_stop                  -> vfio_mem_device_dpt_stop
vfio_devices_query_dirty_bitmap                -> vfio_mem_device_dpt_query
vfio_get_dirty_bitmap                          -> vfio_mem_dpt_query

dpt can be changed to dirty_tracking if that's clearer and not too long.
In patch #31 we can rename to vfio_mem_{register,unregister} or 
vfio_mem_listener_{register,unregister}.
More internal functions can be gradually renamed and added the 
vfio_mem_* prefix.

Will that work?

Thanks.

>> ---
>>   hw/vfio/dirty-tracking.h |  6 +++---
>>   hw/vfio/container.c      |  6 +++---
>>   hw/vfio/dirty-tracking.c | 44 ++++++++++++++++++++--------------------
>>   hw/vfio/trace-events     |  2 +-
>>   4 files changed, 29 insertions(+), 29 deletions(-)
>>
>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>> index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
>> --- a/hw/vfio/dirty-tracking.h
>> +++ b/hw/vfio/dirty-tracking.h
>> @@ -11,9 +11,9 @@
>>
>>   extern const MemoryListener vfio_memory_listener;
>>
>> -bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase *bcontainer);
>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);
>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer);
>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer);
>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>                             uint64_t size, ram_addr_t ram_addr, Error **errp);
>>
>>   #endif /* HW_VFIO_DIRTY_TRACKING_H */
>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>> index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
>> --- a/hw/vfio/container.c
>> +++ b/hw/vfio/container.c
>> @@ -138,8 +138,8 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
>>       int ret;
>>       Error *local_err = NULL;
>>
>> -    if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
>> -        if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
>> +    if (iotlb && vfio_dirty_tracking_devices_is_started(bcontainer)) {
>> +        if (!vfio_dirty_tracking_devices_is_supported(bcontainer) &&
>>               bcontainer->dirty_pages_supported) {
>>               return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
>>           }
>> @@ -170,7 +170,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase *bcontainer,
>>       }
>>
>>       if (need_dirty_sync) {
>> -        ret = vfio_get_dirty_bitmap(bcontainer, iova, size,
>> +        ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, size,
>>                                       iotlb->translated_addr, &local_err);
>>           if (ret) {
>>               error_report_err(local_err);
>> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
>> index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
>> --- a/hw/vfio/dirty-tracking.c
>> +++ b/hw/vfio/dirty-tracking.c
>> @@ -45,7 +45,7 @@
>>    * Device state interfaces
>>    */
>>
>> -static bool vfio_devices_all_device_dirty_tracking_started(
>> +static bool vfio_dirty_tracking_devices_is_started_all(
>>       const VFIOContainerBase *bcontainer)
>>   {
>>       VFIODevice *vbasedev;
>> @@ -59,10 +59,9 @@ static bool vfio_devices_all_device_dirty_tracking_started(
>>       return true;
>>   }
>>
>> -bool vfio_devices_all_dirty_tracking_started(
>> -    const VFIOContainerBase *bcontainer)
>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer)
>>   {
>> -    return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
>> +    return vfio_dirty_tracking_devices_is_started_all(bcontainer) ||
>>              bcontainer->dirty_pages_started;
>>   }
>>
>> @@ -70,7 +69,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase *bcontainer)
>>   {
>>       VFIODevice *vbasedev;
>>
>> -    if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
>> +    if (!vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>           return false;
>>       }
>>
>> @@ -90,7 +89,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase *bcontainer)
>>       return true;
>>   }
>>
>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer)
>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer)
>>   {
>>       VFIODevice *vbasedev;
>>
>> @@ -809,7 +808,7 @@ static void vfio_dirty_tracking_init(VFIOContainerBase *bcontainer,
>>       memory_listener_unregister(&dirty.listener);
>>   }
>>
>> -static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
>> +static void vfio_dirty_tracking_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
>>   {
>>       uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
>>                                 sizeof(uint64_t))] = {};
>> @@ -907,7 +906,7 @@ static void vfio_device_feature_dma_logging_start_destroy(
>>       g_free(feature);
>>   }
>>
>> -static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>> +static bool vfio_dirty_tracking_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>                                             Error **errp)
>>   {
>>       struct vfio_device_feature *feature;
>> @@ -940,7 +939,7 @@ static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>
>>   out:
>>       if (ret) {
>> -        vfio_devices_dma_logging_stop(bcontainer);
>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>       }
>>
>>       vfio_device_feature_dma_logging_start_destroy(feature);
>> @@ -956,8 +955,8 @@ static bool vfio_listener_log_global_start(MemoryListener *listener,
>>                                                    listener);
>>       bool ret;
>>
>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>> -        ret = vfio_devices_dma_logging_start(bcontainer, errp);
>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>> +        ret = vfio_dirty_tracking_devices_dma_logging_start(bcontainer, errp);
>>       } else {
>>           ret = vfio_container_set_dirty_page_tracking(bcontainer, true, errp) == 0;
>>       }
>> @@ -975,8 +974,8 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)
>>       Error *local_err = NULL;
>>       int ret = 0;
>>
>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>> -        vfio_devices_dma_logging_stop(bcontainer);
>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>       } else {
>>           ret = vfio_container_set_dirty_page_tracking(bcontainer, false,
>>                                                        &local_err);
>> @@ -1016,7 +1015,7 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova,
>>       return 0;
>>   }
>>
>> -static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>> +static int vfio_dirty_tracking_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>>                    VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>>   {
>>       VFIODevice *vbasedev;
>> @@ -1038,11 +1037,11 @@ static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>>       return 0;
>>   }
>>
>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>                             uint64_t size, ram_addr_t ram_addr, Error **errp)
>>   {
>>       bool all_device_dirty_tracking =
>> -        vfio_devices_all_device_dirty_tracking(bcontainer);
>> +        vfio_dirty_tracking_devices_is_supported(bcontainer);
>>       uint64_t dirty_pages;
>>       VFIOBitmap vbmap;
>>       int ret;
>> @@ -1062,8 +1061,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>       }
>>
>>       if (all_device_dirty_tracking) {
>> -        ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
>> -                                              errp);
>> +        ret = vfio_dirty_tracking_devices_query_dirty_bitmap(bcontainer, &vbmap,
>> +                                                             iova, size, errp);
>>       } else {
>>           ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
>>                                                   errp);
>> @@ -1076,7 +1075,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>       dirty_pages = cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap, ram_addr,
>>                                                            vbmap.pages);
>>
>> -    trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pages);
>> +    trace_vfio_dirty_tracking_query_dirty_bitmap(iova, size, vbmap.size, ram_addr,
>> +                                                 dirty_pages);
>>   out:
>>       g_free(vbmap.bitmap);
>>
>> @@ -1113,7 +1113,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier *n, IOMMUTLBEntry *iotlb)
>>           goto out_unlock;
>>       }
>>
>> -    ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
>>                                   translated_addr, &local_err);
>>       if (ret) {
>>           error_prepend(&local_err,
>> @@ -1147,7 +1147,7 @@ static int vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
>>        * Sync the whole mapped region (spanning multiple individual mappings)
>>        * in one go.
>>        */
>> -    ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
>>                                   &local_err);
>>       if (ret) {
>>           error_report_err(local_err);
>> @@ -1241,7 +1241,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer,
>>       ram_addr = memory_region_get_ram_addr(section->mr) +
>>                  section->offset_within_region;
>>
>> -    return vfio_get_dirty_bitmap(bcontainer,
>> +    return vfio_dirty_tracking_query_dirty_bitmap(bcontainer,
>>                      REAL_HOST_PAGE_ALIGN(section->offset_within_address_space),
>>                                    int128_get64(section->size), ram_addr, errp);
>>   }
>> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>> index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
>> --- a/hw/vfio/trace-events
>> +++ b/hw/vfio/trace-events
>> @@ -100,7 +100,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRIx64" -
>>   vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64" - 0x%"PRIx64"]"
>>   vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci) "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"], pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
>>   vfio_legacy_dma_unmap_overflow_workaround(void) ""
>> -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>> +vfio_dirty_tracking_query_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>>   vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
>>
>>   # region.c


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-20 11:13     ` Avihai Horon
@ 2025-03-20 11:18       ` Joao Martins
  2025-03-20 11:45         ` Avihai Horon
  0 siblings, 1 reply; 114+ messages in thread
From: Joao Martins @ 2025-03-20 11:18 UTC (permalink / raw)
  To: Avihai Horon, Cédric Le Goater
  Cc: Eric Auger, Zhenzhong Duan, qemu-devel, Alex Williamson

On 20/03/2025 11:13, Avihai Horon wrote:
> 
> On 19/03/2025 14:21, Joao Martins wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> On 18/03/2025 09:54, Cédric Le Goater wrote:
>>> Rename these routines :
>>>
>>>    vfio_devices_all_device_dirty_tracking_started ->
>>> vfio_dirty_tracking_devices_is_started_all
>>>    vfio_devices_all_dirty_tracking_started        ->
>>> vfio_dirty_tracking_devices_is_started
>>>    vfio_devices_all_device_dirty_tracking         ->
>>> vfio_dirty_tracking_devices_is_supported
>>>    vfio_devices_dma_logging_start                 ->
>>> vfio_dirty_tracking_devices_dma_logging_start
>>>    vfio_devices_dma_logging_stop                  ->
>>> vfio_dirty_tracking_devices_dma_logging_stop
>>>    vfio_devices_query_dirty_bitmap                ->
>>> vfio_dirty_tracking_devices_query_dirty_bitmap
>>>    vfio_get_dirty_bitmap                          ->
>>> vfio_dirty_tracking_query_dirty_bitmap
>>>
>>> to better reflect the namespace they belong to.
>>>
>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> The change itself is fine.
>>
>> But on the other hand, it looks relatively long names, no? I am bit at two minds
>> (as I generally prefer shorter code), but I can't find any alternatives if you
>> really wanna have one namespaces associated with the subsystem:file as a C
>> namespace.
>>
>> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
>> when talking about this stuff, but it seems a detour from the code style to
>> abbreviate namespaces into acronyms.
>>
>> Having said that:
>>
>>          Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
>>
>> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
>> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
>> shorter.
> 
> This file is not related only to dirty tracking, but to memory in general.
> Maybe a better naming would be memory.{c,h}?
> Then we can have vfio_memory_* or vfio_mem_* prefix and rename to the below:>
> vfio_devices_all_device_dirty_tracking_started -> vfio_mem_device_dpt_is_started
> vfio_devices_all_dirty_tracking_started        -> vfio_mem_dpt_is_started
> vfio_devices_all_device_dirty_tracking         -> vfio_mem_device_dpt_is_supported
> vfio_devices_dma_logging_start                 -> vfio_mem_device_dpt_start
> vfio_devices_dma_logging_stop                  -> vfio_mem_device_dpt_stop
> vfio_devices_query_dirty_bitmap                -> vfio_mem_device_dpt_query
> vfio_get_dirty_bitmap                          -> vfio_mem_dpt_query
> 
> dpt can be changed to dirty_tracking if that's clearer and not too long.
> In patch #31 we can rename to vfio_mem_{register,unregister} or
> vfio_mem_listener_{register,unregister}.
> More internal functions can be gradually renamed and added the vfio_mem_* prefix.
> 
> Will that work?
> 

I would associate to memory if we were talking about Host windows, DMA mapping
and etc. I believe that's more fundamentally related to memory handling of VFIO
to justify said prefix.

Here the code Cedric moved is really about dirty page tracking, or tracking
changes made by VFs to memory. Calling it memory.c would be a bit of a misnomer
 IMHO :(

> Thanks.
> 
>>> ---
>>>   hw/vfio/dirty-tracking.h |  6 +++---
>>>   hw/vfio/container.c      |  6 +++---
>>>   hw/vfio/dirty-tracking.c | 44 ++++++++++++++++++++--------------------
>>>   hw/vfio/trace-events     |  2 +-
>>>   4 files changed, 29 insertions(+), 29 deletions(-)
>>>
>>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>>> index
>>> 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
>>> --- a/hw/vfio/dirty-tracking.h
>>> +++ b/hw/vfio/dirty-tracking.h
>>> @@ -11,9 +11,9 @@
>>>
>>>   extern const MemoryListener vfio_memory_listener;
>>>
>>> -bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase
>>> *bcontainer);
>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>> *bcontainer);
>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>> *bcontainer);
>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>> *bcontainer);
>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>> *bcontainer, uint64_t iova,
>>>                             uint64_t size, ram_addr_t ram_addr, Error **errp);
>>>
>>>   #endif /* HW_VFIO_DIRTY_TRACKING_H */
>>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>>> index
>>> 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
>>> --- a/hw/vfio/container.c
>>> +++ b/hw/vfio/container.c
>>> @@ -138,8 +138,8 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>> *bcontainer,
>>>       int ret;
>>>       Error *local_err = NULL;
>>>
>>> -    if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>> -        if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
>>> +    if (iotlb && vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>> +        if (!vfio_dirty_tracking_devices_is_supported(bcontainer) &&
>>>               bcontainer->dirty_pages_supported) {
>>>               return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
>>>           }
>>> @@ -170,7 +170,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>> *bcontainer,
>>>       }
>>>
>>>       if (need_dirty_sync) {
>>> -        ret = vfio_get_dirty_bitmap(bcontainer, iova, size,
>>> +        ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, size,
>>>                                       iotlb->translated_addr, &local_err);
>>>           if (ret) {
>>>               error_report_err(local_err);
>>> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
>>> index
>>> 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
>>> --- a/hw/vfio/dirty-tracking.c
>>> +++ b/hw/vfio/dirty-tracking.c
>>> @@ -45,7 +45,7 @@
>>>    * Device state interfaces
>>>    */
>>>
>>> -static bool vfio_devices_all_device_dirty_tracking_started(
>>> +static bool vfio_dirty_tracking_devices_is_started_all(
>>>       const VFIOContainerBase *bcontainer)
>>>   {
>>>       VFIODevice *vbasedev;
>>> @@ -59,10 +59,9 @@ static bool vfio_devices_all_device_dirty_tracking_started(
>>>       return true;
>>>   }
>>>
>>> -bool vfio_devices_all_dirty_tracking_started(
>>> -    const VFIOContainerBase *bcontainer)
>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>> *bcontainer)
>>>   {
>>> -    return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
>>> +    return vfio_dirty_tracking_devices_is_started_all(bcontainer) ||
>>>              bcontainer->dirty_pages_started;
>>>   }
>>>
>>> @@ -70,7 +69,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>> *bcontainer)
>>>   {
>>>       VFIODevice *vbasedev;
>>>
>>> -    if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>> +    if (!vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>>           return false;
>>>       }
>>>
>>> @@ -90,7 +89,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>> *bcontainer)
>>>       return true;
>>>   }
>>>
>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>> *bcontainer)
>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>> *bcontainer)
>>>   {
>>>       VFIODevice *vbasedev;
>>>
>>> @@ -809,7 +808,7 @@ static void vfio_dirty_tracking_init(VFIOContainerBase
>>> *bcontainer,
>>>       memory_listener_unregister(&dirty.listener);
>>>   }
>>>
>>> -static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
>>> +static void vfio_dirty_tracking_devices_dma_logging_stop(VFIOContainerBase
>>> *bcontainer)
>>>   {
>>>       uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
>>>                                 sizeof(uint64_t))] = {};
>>> @@ -907,7 +906,7 @@ static void vfio_device_feature_dma_logging_start_destroy(
>>>       g_free(feature);
>>>   }
>>>
>>> -static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>> +static bool vfio_dirty_tracking_devices_dma_logging_start(VFIOContainerBase
>>> *bcontainer,
>>>                                             Error **errp)
>>>   {
>>>       struct vfio_device_feature *feature;
>>> @@ -940,7 +939,7 @@ static bool
>>> vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>>
>>>   out:
>>>       if (ret) {
>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>       }
>>>
>>>       vfio_device_feature_dma_logging_start_destroy(feature);
>>> @@ -956,8 +955,8 @@ static bool vfio_listener_log_global_start(MemoryListener
>>> *listener,
>>>                                                    listener);
>>>       bool ret;
>>>
>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>> -        ret = vfio_devices_dma_logging_start(bcontainer, errp);
>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>> +        ret = vfio_dirty_tracking_devices_dma_logging_start(bcontainer, errp);
>>>       } else {
>>>           ret = vfio_container_set_dirty_page_tracking(bcontainer, true,
>>> errp) == 0;
>>>       }
>>> @@ -975,8 +974,8 @@ static void vfio_listener_log_global_stop(MemoryListener
>>> *listener)
>>>       Error *local_err = NULL;
>>>       int ret = 0;
>>>
>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>       } else {
>>>           ret = vfio_container_set_dirty_page_tracking(bcontainer, false,
>>>                                                        &local_err);
>>> @@ -1016,7 +1015,7 @@ static int vfio_device_dma_logging_report(VFIODevice
>>> *vbasedev, hwaddr iova,
>>>       return 0;
>>>   }
>>>
>>> -static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>>> +static int vfio_dirty_tracking_devices_query_dirty_bitmap(const
>>> VFIOContainerBase *bcontainer,
>>>                    VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>>>   {
>>>       VFIODevice *vbasedev;
>>> @@ -1038,11 +1037,11 @@ static int vfio_devices_query_dirty_bitmap(const
>>> VFIOContainerBase *bcontainer,
>>>       return 0;
>>>   }
>>>
>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>> *bcontainer, uint64_t iova,
>>>                             uint64_t size, ram_addr_t ram_addr, Error **errp)
>>>   {
>>>       bool all_device_dirty_tracking =
>>> -        vfio_devices_all_device_dirty_tracking(bcontainer);
>>> +        vfio_dirty_tracking_devices_is_supported(bcontainer);
>>>       uint64_t dirty_pages;
>>>       VFIOBitmap vbmap;
>>>       int ret;
>>> @@ -1062,8 +1061,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>> *bcontainer, uint64_t iova,
>>>       }
>>>
>>>       if (all_device_dirty_tracking) {
>>> -        ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
>>> -                                              errp);
>>> +        ret = vfio_dirty_tracking_devices_query_dirty_bitmap(bcontainer,
>>> &vbmap,
>>> +                                                             iova, size, errp);
>>>       } else {
>>>           ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova,
>>> size,
>>>                                                   errp);
>>> @@ -1076,7 +1075,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>> *bcontainer, uint64_t iova,
>>>       dirty_pages = cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap,
>>> ram_addr,
>>>                                                            vbmap.pages);
>>>
>>> -    trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pages);
>>> +    trace_vfio_dirty_tracking_query_dirty_bitmap(iova, size, vbmap.size,
>>> ram_addr,
>>> +                                                 dirty_pages);
>>>   out:
>>>       g_free(vbmap.bitmap);
>>>
>>> @@ -1113,7 +1113,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier
>>> *n, IOMMUTLBEntry *iotlb)
>>>           goto out_unlock;
>>>       }
>>>
>>> -    ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, iotlb-
>>> >addr_mask + 1,
>>>                                   translated_addr, &local_err);
>>>       if (ret) {
>>>           error_prepend(&local_err,
>>> @@ -1147,7 +1147,7 @@ static int
>>> vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
>>>        * Sync the whole mapped region (spanning multiple individual mappings)
>>>        * in one go.
>>>        */
>>> -    ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(vrdl->bcontainer, iova,
>>> size, ram_addr,
>>>                                   &local_err);
>>>       if (ret) {
>>>           error_report_err(local_err);
>>> @@ -1241,7 +1241,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase
>>> *bcontainer,
>>>       ram_addr = memory_region_get_ram_addr(section->mr) +
>>>                  section->offset_within_region;
>>>
>>> -    return vfio_get_dirty_bitmap(bcontainer,
>>> +    return vfio_dirty_tracking_query_dirty_bitmap(bcontainer,
>>>                      REAL_HOST_PAGE_ALIGN(section->offset_within_address_space),
>>>                                    int128_get64(section->size), ram_addr, errp);
>>>   }
>>> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>>> index
>>> 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
>>> --- a/hw/vfio/trace-events
>>> +++ b/hw/vfio/trace-events
>>> @@ -100,7 +100,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end)
>>> "region_del 0x%"PRIx64" -
>>>   vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t
>>> min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64"
>>> - 0x%"PRIx64"]"
>>>   vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t
>>> max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci)
>>> "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"],
>>> pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
>>>   vfio_legacy_dma_unmap_overflow_workaround(void) ""
>>> -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size,
>>> uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64"
>>> bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>>> +vfio_dirty_tracking_query_dirty_bitmap(uint64_t iova, uint64_t size,
>>> uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64"
>>> size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>>>   vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu
>>> dirty @ 0x%"PRIx64" - 0x%"PRIx64
>>>
>>>   # region.c



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-20 11:18       ` Joao Martins
@ 2025-03-20 11:45         ` Avihai Horon
  2025-03-20 11:56           ` Joao Martins
  0 siblings, 1 reply; 114+ messages in thread
From: Avihai Horon @ 2025-03-20 11:45 UTC (permalink / raw)
  To: Joao Martins, Cédric Le Goater
  Cc: Eric Auger, Zhenzhong Duan, qemu-devel, Alex Williamson


On 20/03/2025 13:18, Joao Martins wrote:
> External email: Use caution opening links or attachments
>
>
> On 20/03/2025 11:13, Avihai Horon wrote:
>> On 19/03/2025 14:21, Joao Martins wrote:
>>> External email: Use caution opening links or attachments
>>>
>>>
>>> On 18/03/2025 09:54, Cédric Le Goater wrote:
>>>> Rename these routines :
>>>>
>>>>     vfio_devices_all_device_dirty_tracking_started ->
>>>> vfio_dirty_tracking_devices_is_started_all
>>>>     vfio_devices_all_dirty_tracking_started        ->
>>>> vfio_dirty_tracking_devices_is_started
>>>>     vfio_devices_all_device_dirty_tracking         ->
>>>> vfio_dirty_tracking_devices_is_supported
>>>>     vfio_devices_dma_logging_start                 ->
>>>> vfio_dirty_tracking_devices_dma_logging_start
>>>>     vfio_devices_dma_logging_stop                  ->
>>>> vfio_dirty_tracking_devices_dma_logging_stop
>>>>     vfio_devices_query_dirty_bitmap                ->
>>>> vfio_dirty_tracking_devices_query_dirty_bitmap
>>>>     vfio_get_dirty_bitmap                          ->
>>>> vfio_dirty_tracking_query_dirty_bitmap
>>>>
>>>> to better reflect the namespace they belong to.
>>>>
>>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>> The change itself is fine.
>>>
>>> But on the other hand, it looks relatively long names, no? I am bit at two minds
>>> (as I generally prefer shorter code), but I can't find any alternatives if you
>>> really wanna have one namespaces associated with the subsystem:file as a C
>>> namespace.
>>>
>>> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
>>> when talking about this stuff, but it seems a detour from the code style to
>>> abbreviate namespaces into acronyms.
>>>
>>> Having said that:
>>>
>>>           Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
>>>
>>> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
>>> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
>>> shorter.
>> This file is not related only to dirty tracking, but to memory in general.
>> Maybe a better naming would be memory.{c,h}?
>> Then we can have vfio_memory_* or vfio_mem_* prefix and rename to the below:>
>> vfio_devices_all_device_dirty_tracking_started -> vfio_mem_device_dpt_is_started
>> vfio_devices_all_dirty_tracking_started        -> vfio_mem_dpt_is_started
>> vfio_devices_all_device_dirty_tracking         -> vfio_mem_device_dpt_is_supported
>> vfio_devices_dma_logging_start                 -> vfio_mem_device_dpt_start
>> vfio_devices_dma_logging_stop                  -> vfio_mem_device_dpt_stop
>> vfio_devices_query_dirty_bitmap                -> vfio_mem_device_dpt_query
>> vfio_get_dirty_bitmap                          -> vfio_mem_dpt_query
>>
>> dpt can be changed to dirty_tracking if that's clearer and not too long.
>> In patch #31 we can rename to vfio_mem_{register,unregister} or
>> vfio_mem_listener_{register,unregister}.
>> More internal functions can be gradually renamed and added the vfio_mem_* prefix.
>>
>> Will that work?
>>
> I would associate to memory if we were talking about Host windows, DMA mapping
> and etc. I believe that's more fundamentally related to memory handling of VFIO
> to justify said prefix.
>
> Here the code Cedric moved is really about dirty page tracking, or tracking
> changes made by VFs to memory. Calling it memory.c would be a bit of a misnomer
>   IMHO :(

Hmm, yes, the majority of the code is related to dirty tracking, but 
maybe we can view dirty tracking as a sub-field of memory.
Dirty tracking doesn't seem the perfect fit IMHO, as this file also 
contains vfio_dirty_tracking_register and .region_add/.region_del which 
are not entirely related to dirty tracking.

>
>> Thanks.
>>
>>>> ---
>>>>    hw/vfio/dirty-tracking.h |  6 +++---
>>>>    hw/vfio/container.c      |  6 +++---
>>>>    hw/vfio/dirty-tracking.c | 44 ++++++++++++++++++++--------------------
>>>>    hw/vfio/trace-events     |  2 +-
>>>>    4 files changed, 29 insertions(+), 29 deletions(-)
>>>>
>>>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>>>> index
>>>> 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
>>>> --- a/hw/vfio/dirty-tracking.h
>>>> +++ b/hw/vfio/dirty-tracking.h
>>>> @@ -11,9 +11,9 @@
>>>>
>>>>    extern const MemoryListener vfio_memory_listener;
>>>>
>>>> -bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase
>>>> *bcontainer);
>>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>>> *bcontainer);
>>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>>> *bcontainer);
>>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>>> *bcontainer);
>>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>>> *bcontainer, uint64_t iova,
>>>>                              uint64_t size, ram_addr_t ram_addr, Error **errp);
>>>>
>>>>    #endif /* HW_VFIO_DIRTY_TRACKING_H */
>>>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>>>> index
>>>> 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
>>>> --- a/hw/vfio/container.c
>>>> +++ b/hw/vfio/container.c
>>>> @@ -138,8 +138,8 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>>> *bcontainer,
>>>>        int ret;
>>>>        Error *local_err = NULL;
>>>>
>>>> -    if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>>> -        if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
>>>> +    if (iotlb && vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>>> +        if (!vfio_dirty_tracking_devices_is_supported(bcontainer) &&
>>>>                bcontainer->dirty_pages_supported) {
>>>>                return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
>>>>            }
>>>> @@ -170,7 +170,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>>> *bcontainer,
>>>>        }
>>>>
>>>>        if (need_dirty_sync) {
>>>> -        ret = vfio_get_dirty_bitmap(bcontainer, iova, size,
>>>> +        ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, size,
>>>>                                        iotlb->translated_addr, &local_err);
>>>>            if (ret) {
>>>>                error_report_err(local_err);
>>>> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
>>>> index
>>>> 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
>>>> --- a/hw/vfio/dirty-tracking.c
>>>> +++ b/hw/vfio/dirty-tracking.c
>>>> @@ -45,7 +45,7 @@
>>>>     * Device state interfaces
>>>>     */
>>>>
>>>> -static bool vfio_devices_all_device_dirty_tracking_started(
>>>> +static bool vfio_dirty_tracking_devices_is_started_all(
>>>>        const VFIOContainerBase *bcontainer)
>>>>    {
>>>>        VFIODevice *vbasedev;
>>>> @@ -59,10 +59,9 @@ static bool vfio_devices_all_device_dirty_tracking_started(
>>>>        return true;
>>>>    }
>>>>
>>>> -bool vfio_devices_all_dirty_tracking_started(
>>>> -    const VFIOContainerBase *bcontainer)
>>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>>> *bcontainer)
>>>>    {
>>>> -    return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
>>>> +    return vfio_dirty_tracking_devices_is_started_all(bcontainer) ||
>>>>               bcontainer->dirty_pages_started;
>>>>    }
>>>>
>>>> @@ -70,7 +69,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>>> *bcontainer)
>>>>    {
>>>>        VFIODevice *vbasedev;
>>>>
>>>> -    if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>>> +    if (!vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>>>            return false;
>>>>        }
>>>>
>>>> @@ -90,7 +89,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>>> *bcontainer)
>>>>        return true;
>>>>    }
>>>>
>>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>>> *bcontainer)
>>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>>> *bcontainer)
>>>>    {
>>>>        VFIODevice *vbasedev;
>>>>
>>>> @@ -809,7 +808,7 @@ static void vfio_dirty_tracking_init(VFIOContainerBase
>>>> *bcontainer,
>>>>        memory_listener_unregister(&dirty.listener);
>>>>    }
>>>>
>>>> -static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
>>>> +static void vfio_dirty_tracking_devices_dma_logging_stop(VFIOContainerBase
>>>> *bcontainer)
>>>>    {
>>>>        uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
>>>>                                  sizeof(uint64_t))] = {};
>>>> @@ -907,7 +906,7 @@ static void vfio_device_feature_dma_logging_start_destroy(
>>>>        g_free(feature);
>>>>    }
>>>>
>>>> -static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>>> +static bool vfio_dirty_tracking_devices_dma_logging_start(VFIOContainerBase
>>>> *bcontainer,
>>>>                                              Error **errp)
>>>>    {
>>>>        struct vfio_device_feature *feature;
>>>> @@ -940,7 +939,7 @@ static bool
>>>> vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>>>
>>>>    out:
>>>>        if (ret) {
>>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>>        }
>>>>
>>>>        vfio_device_feature_dma_logging_start_destroy(feature);
>>>> @@ -956,8 +955,8 @@ static bool vfio_listener_log_global_start(MemoryListener
>>>> *listener,
>>>>                                                     listener);
>>>>        bool ret;
>>>>
>>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>>> -        ret = vfio_devices_dma_logging_start(bcontainer, errp);
>>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>>> +        ret = vfio_dirty_tracking_devices_dma_logging_start(bcontainer, errp);
>>>>        } else {
>>>>            ret = vfio_container_set_dirty_page_tracking(bcontainer, true,
>>>> errp) == 0;
>>>>        }
>>>> @@ -975,8 +974,8 @@ static void vfio_listener_log_global_stop(MemoryListener
>>>> *listener)
>>>>        Error *local_err = NULL;
>>>>        int ret = 0;
>>>>
>>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>>        } else {
>>>>            ret = vfio_container_set_dirty_page_tracking(bcontainer, false,
>>>>                                                         &local_err);
>>>> @@ -1016,7 +1015,7 @@ static int vfio_device_dma_logging_report(VFIODevice
>>>> *vbasedev, hwaddr iova,
>>>>        return 0;
>>>>    }
>>>>
>>>> -static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>>>> +static int vfio_dirty_tracking_devices_query_dirty_bitmap(const
>>>> VFIOContainerBase *bcontainer,
>>>>                     VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>>>>    {
>>>>        VFIODevice *vbasedev;
>>>> @@ -1038,11 +1037,11 @@ static int vfio_devices_query_dirty_bitmap(const
>>>> VFIOContainerBase *bcontainer,
>>>>        return 0;
>>>>    }
>>>>
>>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>>> *bcontainer, uint64_t iova,
>>>>                              uint64_t size, ram_addr_t ram_addr, Error **errp)
>>>>    {
>>>>        bool all_device_dirty_tracking =
>>>> -        vfio_devices_all_device_dirty_tracking(bcontainer);
>>>> +        vfio_dirty_tracking_devices_is_supported(bcontainer);
>>>>        uint64_t dirty_pages;
>>>>        VFIOBitmap vbmap;
>>>>        int ret;
>>>> @@ -1062,8 +1061,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>>> *bcontainer, uint64_t iova,
>>>>        }
>>>>
>>>>        if (all_device_dirty_tracking) {
>>>> -        ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
>>>> -                                              errp);
>>>> +        ret = vfio_dirty_tracking_devices_query_dirty_bitmap(bcontainer,
>>>> &vbmap,
>>>> +                                                             iova, size, errp);
>>>>        } else {
>>>>            ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova,
>>>> size,
>>>>                                                    errp);
>>>> @@ -1076,7 +1075,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>>> *bcontainer, uint64_t iova,
>>>>        dirty_pages = cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap,
>>>> ram_addr,
>>>>                                                             vbmap.pages);
>>>>
>>>> -    trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr, dirty_pages);
>>>> +    trace_vfio_dirty_tracking_query_dirty_bitmap(iova, size, vbmap.size,
>>>> ram_addr,
>>>> +                                                 dirty_pages);
>>>>    out:
>>>>        g_free(vbmap.bitmap);
>>>>
>>>> @@ -1113,7 +1113,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier
>>>> *n, IOMMUTLBEntry *iotlb)
>>>>            goto out_unlock;
>>>>        }
>>>>
>>>> -    ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
>>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, iotlb-
>>>>> addr_mask + 1,
>>>>                                    translated_addr, &local_err);
>>>>        if (ret) {
>>>>            error_prepend(&local_err,
>>>> @@ -1147,7 +1147,7 @@ static int
>>>> vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
>>>>         * Sync the whole mapped region (spanning multiple individual mappings)
>>>>         * in one go.
>>>>         */
>>>> -    ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
>>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(vrdl->bcontainer, iova,
>>>> size, ram_addr,
>>>>                                    &local_err);
>>>>        if (ret) {
>>>>            error_report_err(local_err);
>>>> @@ -1241,7 +1241,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase
>>>> *bcontainer,
>>>>        ram_addr = memory_region_get_ram_addr(section->mr) +
>>>>                   section->offset_within_region;
>>>>
>>>> -    return vfio_get_dirty_bitmap(bcontainer,
>>>> +    return vfio_dirty_tracking_query_dirty_bitmap(bcontainer,
>>>>                       REAL_HOST_PAGE_ALIGN(section->offset_within_address_space),
>>>>                                     int128_get64(section->size), ram_addr, errp);
>>>>    }
>>>> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>>>> index
>>>> 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
>>>> --- a/hw/vfio/trace-events
>>>> +++ b/hw/vfio/trace-events
>>>> @@ -100,7 +100,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end)
>>>> "region_del 0x%"PRIx64" -
>>>>    vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t
>>>> min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64"
>>>> - 0x%"PRIx64"]"
>>>>    vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t
>>>> max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci)
>>>> "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"],
>>>> pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
>>>>    vfio_legacy_dma_unmap_overflow_workaround(void) ""
>>>> -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size,
>>>> uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64"
>>>> bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>>>> +vfio_dirty_tracking_query_dirty_bitmap(uint64_t iova, uint64_t size,
>>>> uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64"
>>>> size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>>>>    vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu
>>>> dirty @ 0x%"PRIx64" - 0x%"PRIx64
>>>>
>>>>    # region.c


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-20 11:45         ` Avihai Horon
@ 2025-03-20 11:56           ` Joao Martins
  2025-03-20 12:24             ` Avihai Horon
  0 siblings, 1 reply; 114+ messages in thread
From: Joao Martins @ 2025-03-20 11:56 UTC (permalink / raw)
  To: Avihai Horon, Cédric Le Goater
  Cc: Eric Auger, Zhenzhong Duan, qemu-devel, Alex Williamson

On 20/03/2025 11:45, Avihai Horon wrote:
> 
> On 20/03/2025 13:18, Joao Martins wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> On 20/03/2025 11:13, Avihai Horon wrote:
>>> On 19/03/2025 14:21, Joao Martins wrote:
>>>> External email: Use caution opening links or attachments
>>>>
>>>>
>>>> On 18/03/2025 09:54, Cédric Le Goater wrote:
>>>>> Rename these routines :
>>>>>
>>>>>     vfio_devices_all_device_dirty_tracking_started ->
>>>>> vfio_dirty_tracking_devices_is_started_all
>>>>>     vfio_devices_all_dirty_tracking_started        ->
>>>>> vfio_dirty_tracking_devices_is_started
>>>>>     vfio_devices_all_device_dirty_tracking         ->
>>>>> vfio_dirty_tracking_devices_is_supported
>>>>>     vfio_devices_dma_logging_start                 ->
>>>>> vfio_dirty_tracking_devices_dma_logging_start
>>>>>     vfio_devices_dma_logging_stop                  ->
>>>>> vfio_dirty_tracking_devices_dma_logging_stop
>>>>>     vfio_devices_query_dirty_bitmap                ->
>>>>> vfio_dirty_tracking_devices_query_dirty_bitmap
>>>>>     vfio_get_dirty_bitmap                          ->
>>>>> vfio_dirty_tracking_query_dirty_bitmap
>>>>>
>>>>> to better reflect the namespace they belong to.
>>>>>
>>>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>>> The change itself is fine.
>>>>
>>>> But on the other hand, it looks relatively long names, no? I am bit at two
>>>> minds
>>>> (as I generally prefer shorter code), but I can't find any alternatives if you
>>>> really wanna have one namespaces associated with the subsystem:file as a C
>>>> namespace.
>>>>
>>>> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
>>>> when talking about this stuff, but it seems a detour from the code style to
>>>> abbreviate namespaces into acronyms.
>>>>
>>>> Having said that:
>>>>
>>>>           Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
>>>>
>>>> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
>>>> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
>>>> shorter.
>>> This file is not related only to dirty tracking, but to memory in general.
>>> Maybe a better naming would be memory.{c,h}?
>>> Then we can have vfio_memory_* or vfio_mem_* prefix and rename to the below:>
>>> vfio_devices_all_device_dirty_tracking_started -> vfio_mem_device_dpt_is_started
>>> vfio_devices_all_dirty_tracking_started        -> vfio_mem_dpt_is_started
>>> vfio_devices_all_device_dirty_tracking         ->
>>> vfio_mem_device_dpt_is_supported
>>> vfio_devices_dma_logging_start                 -> vfio_mem_device_dpt_start
>>> vfio_devices_dma_logging_stop                  -> vfio_mem_device_dpt_stop
>>> vfio_devices_query_dirty_bitmap                -> vfio_mem_device_dpt_query
>>> vfio_get_dirty_bitmap                          -> vfio_mem_dpt_query
>>>
>>> dpt can be changed to dirty_tracking if that's clearer and not too long.
>>> In patch #31 we can rename to vfio_mem_{register,unregister} or
>>> vfio_mem_listener_{register,unregister}.
>>> More internal functions can be gradually renamed and added the vfio_mem_*
>>> prefix.
>>>
>>> Will that work?
>>>
>> I would associate to memory if we were talking about Host windows, DMA mapping
>> and etc. I believe that's more fundamentally related to memory handling of VFIO
>> to justify said prefix.
>>
>> Here the code Cedric moved is really about dirty page tracking, or tracking
>> changes made by VFs to memory. Calling it memory.c would be a bit of a misnomer
>>   IMHO :(
> 
> Hmm, yes, the majority of the code is related to dirty tracking, but maybe we
> can view dirty tracking as a sub-field of memory.
> Dirty tracking doesn't seem the perfect fit IMHO, as this file also
> contains vfio_dirty_tracking_register and .region_add/.region_del which are not
> entirely related to dirty tracking.
> 

Ah yes, it's a small portion but still region_{add,del} is indeed about DMA
mapping and not at all related to dirty tracking.

It's almost as if we should be moving ::region_add/region_del alongside
vfio_dirty_tracking_{un,}register into a memory.c file and leave this one as
dirty_tracking.c / dpt.c

Which reminds me that perhaps vfio_dirty_tracking_register() and the name might
be misleading and should instead me vfio_memory_register() /
vfio_memory_unregister().

>>
>>> Thanks.
>>>
>>>>> ---
>>>>>    hw/vfio/dirty-tracking.h |  6 +++---
>>>>>    hw/vfio/container.c      |  6 +++---
>>>>>    hw/vfio/dirty-tracking.c | 44 ++++++++++++++++++++--------------------
>>>>>    hw/vfio/trace-events     |  2 +-
>>>>>    4 files changed, 29 insertions(+), 29 deletions(-)
>>>>>
>>>>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>>>>> index
>>>>> 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
>>>>> --- a/hw/vfio/dirty-tracking.h
>>>>> +++ b/hw/vfio/dirty-tracking.h
>>>>> @@ -11,9 +11,9 @@
>>>>>
>>>>>    extern const MemoryListener vfio_memory_listener;
>>>>>
>>>>> -bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase
>>>>> *bcontainer);
>>>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>>>> *bcontainer);
>>>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>>>> *bcontainer);
>>>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>>>> *bcontainer);
>>>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>>>> *bcontainer, uint64_t iova,
>>>>>                              uint64_t size, ram_addr_t ram_addr, Error
>>>>> **errp);
>>>>>
>>>>>    #endif /* HW_VFIO_DIRTY_TRACKING_H */
>>>>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>>>>> index
>>>>> 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
>>>>> --- a/hw/vfio/container.c
>>>>> +++ b/hw/vfio/container.c
>>>>> @@ -138,8 +138,8 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>>>> *bcontainer,
>>>>>        int ret;
>>>>>        Error *local_err = NULL;
>>>>>
>>>>> -    if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>>>> -        if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
>>>>> +    if (iotlb && vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>>>> +        if (!vfio_dirty_tracking_devices_is_supported(bcontainer) &&
>>>>>                bcontainer->dirty_pages_supported) {
>>>>>                return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
>>>>>            }
>>>>> @@ -170,7 +170,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>>>> *bcontainer,
>>>>>        }
>>>>>
>>>>>        if (need_dirty_sync) {
>>>>> -        ret = vfio_get_dirty_bitmap(bcontainer, iova, size,
>>>>> +        ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, size,
>>>>>                                        iotlb->translated_addr, &local_err);
>>>>>            if (ret) {
>>>>>                error_report_err(local_err);
>>>>> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
>>>>> index
>>>>> 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
>>>>> --- a/hw/vfio/dirty-tracking.c
>>>>> +++ b/hw/vfio/dirty-tracking.c
>>>>> @@ -45,7 +45,7 @@
>>>>>     * Device state interfaces
>>>>>     */
>>>>>
>>>>> -static bool vfio_devices_all_device_dirty_tracking_started(
>>>>> +static bool vfio_dirty_tracking_devices_is_started_all(
>>>>>        const VFIOContainerBase *bcontainer)
>>>>>    {
>>>>>        VFIODevice *vbasedev;
>>>>> @@ -59,10 +59,9 @@ static bool vfio_devices_all_device_dirty_tracking_started(
>>>>>        return true;
>>>>>    }
>>>>>
>>>>> -bool vfio_devices_all_dirty_tracking_started(
>>>>> -    const VFIOContainerBase *bcontainer)
>>>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>>>> *bcontainer)
>>>>>    {
>>>>> -    return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
>>>>> +    return vfio_dirty_tracking_devices_is_started_all(bcontainer) ||
>>>>>               bcontainer->dirty_pages_started;
>>>>>    }
>>>>>
>>>>> @@ -70,7 +69,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>>>> *bcontainer)
>>>>>    {
>>>>>        VFIODevice *vbasedev;
>>>>>
>>>>> -    if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>>>> +    if (!vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>>>>            return false;
>>>>>        }
>>>>>
>>>>> @@ -90,7 +89,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>>>> *bcontainer)
>>>>>        return true;
>>>>>    }
>>>>>
>>>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>>>> *bcontainer)
>>>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>>>> *bcontainer)
>>>>>    {
>>>>>        VFIODevice *vbasedev;
>>>>>
>>>>> @@ -809,7 +808,7 @@ static void vfio_dirty_tracking_init(VFIOContainerBase
>>>>> *bcontainer,
>>>>>        memory_listener_unregister(&dirty.listener);
>>>>>    }
>>>>>
>>>>> -static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
>>>>> +static void vfio_dirty_tracking_devices_dma_logging_stop(VFIOContainerBase
>>>>> *bcontainer)
>>>>>    {
>>>>>        uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
>>>>>                                  sizeof(uint64_t))] = {};
>>>>> @@ -907,7 +906,7 @@ static void vfio_device_feature_dma_logging_start_destroy(
>>>>>        g_free(feature);
>>>>>    }
>>>>>
>>>>> -static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>>>> +static bool vfio_dirty_tracking_devices_dma_logging_start(VFIOContainerBase
>>>>> *bcontainer,
>>>>>                                              Error **errp)
>>>>>    {
>>>>>        struct vfio_device_feature *feature;
>>>>> @@ -940,7 +939,7 @@ static bool
>>>>> vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>>>>
>>>>>    out:
>>>>>        if (ret) {
>>>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>>>        }
>>>>>
>>>>>        vfio_device_feature_dma_logging_start_destroy(feature);
>>>>> @@ -956,8 +955,8 @@ static bool vfio_listener_log_global_start(MemoryListener
>>>>> *listener,
>>>>>                                                     listener);
>>>>>        bool ret;
>>>>>
>>>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>>>> -        ret = vfio_devices_dma_logging_start(bcontainer, errp);
>>>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>>>> +        ret = vfio_dirty_tracking_devices_dma_logging_start(bcontainer,
>>>>> errp);
>>>>>        } else {
>>>>>            ret = vfio_container_set_dirty_page_tracking(bcontainer, true,
>>>>> errp) == 0;
>>>>>        }
>>>>> @@ -975,8 +974,8 @@ static void vfio_listener_log_global_stop(MemoryListener
>>>>> *listener)
>>>>>        Error *local_err = NULL;
>>>>>        int ret = 0;
>>>>>
>>>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>>>        } else {
>>>>>            ret = vfio_container_set_dirty_page_tracking(bcontainer, false,
>>>>>                                                         &local_err);
>>>>> @@ -1016,7 +1015,7 @@ static int vfio_device_dma_logging_report(VFIODevice
>>>>> *vbasedev, hwaddr iova,
>>>>>        return 0;
>>>>>    }
>>>>>
>>>>> -static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase
>>>>> *bcontainer,
>>>>> +static int vfio_dirty_tracking_devices_query_dirty_bitmap(const
>>>>> VFIOContainerBase *bcontainer,
>>>>>                     VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>>>>>    {
>>>>>        VFIODevice *vbasedev;
>>>>> @@ -1038,11 +1037,11 @@ static int vfio_devices_query_dirty_bitmap(const
>>>>> VFIOContainerBase *bcontainer,
>>>>>        return 0;
>>>>>    }
>>>>>
>>>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>>>> *bcontainer, uint64_t iova,
>>>>>                              uint64_t size, ram_addr_t ram_addr, Error **errp)
>>>>>    {
>>>>>        bool all_device_dirty_tracking =
>>>>> -        vfio_devices_all_device_dirty_tracking(bcontainer);
>>>>> +        vfio_dirty_tracking_devices_is_supported(bcontainer);
>>>>>        uint64_t dirty_pages;
>>>>>        VFIOBitmap vbmap;
>>>>>        int ret;
>>>>> @@ -1062,8 +1061,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>>>> *bcontainer, uint64_t iova,
>>>>>        }
>>>>>
>>>>>        if (all_device_dirty_tracking) {
>>>>> -        ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
>>>>> -                                              errp);
>>>>> +        ret = vfio_dirty_tracking_devices_query_dirty_bitmap(bcontainer,
>>>>> &vbmap,
>>>>> +                                                             iova, size,
>>>>> errp);
>>>>>        } else {
>>>>>            ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova,
>>>>> size,
>>>>>                                                    errp);
>>>>> @@ -1076,7 +1075,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>>>> *bcontainer, uint64_t iova,
>>>>>        dirty_pages = cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap,
>>>>> ram_addr,
>>>>>                                                             vbmap.pages);
>>>>>
>>>>> -    trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr,
>>>>> dirty_pages);
>>>>> +    trace_vfio_dirty_tracking_query_dirty_bitmap(iova, size, vbmap.size,
>>>>> ram_addr,
>>>>> +                                                 dirty_pages);
>>>>>    out:
>>>>>        g_free(vbmap.bitmap);
>>>>>
>>>>> @@ -1113,7 +1113,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier
>>>>> *n, IOMMUTLBEntry *iotlb)
>>>>>            goto out_unlock;
>>>>>        }
>>>>>
>>>>> -    ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
>>>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, iotlb-
>>>>>> addr_mask + 1,
>>>>>                                    translated_addr, &local_err);
>>>>>        if (ret) {
>>>>>            error_prepend(&local_err,
>>>>> @@ -1147,7 +1147,7 @@ static int
>>>>> vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
>>>>>         * Sync the whole mapped region (spanning multiple individual mappings)
>>>>>         * in one go.
>>>>>         */
>>>>> -    ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
>>>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(vrdl->bcontainer, iova,
>>>>> size, ram_addr,
>>>>>                                    &local_err);
>>>>>        if (ret) {
>>>>>            error_report_err(local_err);
>>>>> @@ -1241,7 +1241,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase
>>>>> *bcontainer,
>>>>>        ram_addr = memory_region_get_ram_addr(section->mr) +
>>>>>                   section->offset_within_region;
>>>>>
>>>>> -    return vfio_get_dirty_bitmap(bcontainer,
>>>>> +    return vfio_dirty_tracking_query_dirty_bitmap(bcontainer,
>>>>>                       REAL_HOST_PAGE_ALIGN(section-
>>>>> >offset_within_address_space),
>>>>>                                     int128_get64(section->size), ram_addr,
>>>>> errp);
>>>>>    }
>>>>> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>>>>> index
>>>>> 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
>>>>> --- a/hw/vfio/trace-events
>>>>> +++ b/hw/vfio/trace-events
>>>>> @@ -100,7 +100,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end)
>>>>> "region_del 0x%"PRIx64" -
>>>>>    vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t
>>>>> min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64"
>>>>> - 0x%"PRIx64"]"
>>>>>    vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t
>>>>> max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci)
>>>>> "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"],
>>>>> pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
>>>>>    vfio_legacy_dma_unmap_overflow_workaround(void) ""
>>>>> -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size,
>>>>> uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64"
>>>>> bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>>>>> +vfio_dirty_tracking_query_dirty_bitmap(uint64_t iova, uint64_t size,
>>>>> uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64"
>>>>> size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64"
>>>>> dirty_pages=%"PRIu64
>>>>>    vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu
>>>>> dirty @ 0x%"PRIx64" - 0x%"PRIx64
>>>>>
>>>>>    # region.c



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-20 11:56           ` Joao Martins
@ 2025-03-20 12:24             ` Avihai Horon
  0 siblings, 0 replies; 114+ messages in thread
From: Avihai Horon @ 2025-03-20 12:24 UTC (permalink / raw)
  To: Joao Martins, Cédric Le Goater
  Cc: Eric Auger, Zhenzhong Duan, qemu-devel, Alex Williamson


On 20/03/2025 13:56, Joao Martins wrote:
> External email: Use caution opening links or attachments
>
>
> On 20/03/2025 11:45, Avihai Horon wrote:
>> On 20/03/2025 13:18, Joao Martins wrote:
>>> External email: Use caution opening links or attachments
>>>
>>>
>>> On 20/03/2025 11:13, Avihai Horon wrote:
>>>> On 19/03/2025 14:21, Joao Martins wrote:
>>>>> External email: Use caution opening links or attachments
>>>>>
>>>>>
>>>>> On 18/03/2025 09:54, Cédric Le Goater wrote:
>>>>>> Rename these routines :
>>>>>>
>>>>>>      vfio_devices_all_device_dirty_tracking_started ->
>>>>>> vfio_dirty_tracking_devices_is_started_all
>>>>>>      vfio_devices_all_dirty_tracking_started        ->
>>>>>> vfio_dirty_tracking_devices_is_started
>>>>>>      vfio_devices_all_device_dirty_tracking         ->
>>>>>> vfio_dirty_tracking_devices_is_supported
>>>>>>      vfio_devices_dma_logging_start                 ->
>>>>>> vfio_dirty_tracking_devices_dma_logging_start
>>>>>>      vfio_devices_dma_logging_stop                  ->
>>>>>> vfio_dirty_tracking_devices_dma_logging_stop
>>>>>>      vfio_devices_query_dirty_bitmap                ->
>>>>>> vfio_dirty_tracking_devices_query_dirty_bitmap
>>>>>>      vfio_get_dirty_bitmap                          ->
>>>>>> vfio_dirty_tracking_query_dirty_bitmap
>>>>>>
>>>>>> to better reflect the namespace they belong to.
>>>>>>
>>>>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>>>> The change itself is fine.
>>>>>
>>>>> But on the other hand, it looks relatively long names, no? I am bit at two
>>>>> minds
>>>>> (as I generally prefer shorter code), but I can't find any alternatives if you
>>>>> really wanna have one namespaces associated with the subsystem:file as a C
>>>>> namespace.
>>>>>
>>>>> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
>>>>> when talking about this stuff, but it seems a detour from the code style to
>>>>> abbreviate namespaces into acronyms.
>>>>>
>>>>> Having said that:
>>>>>
>>>>>            Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
>>>>>
>>>>> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
>>>>> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
>>>>> shorter.
>>>> This file is not related only to dirty tracking, but to memory in general.
>>>> Maybe a better naming would be memory.{c,h}?
>>>> Then we can have vfio_memory_* or vfio_mem_* prefix and rename to the below:>
>>>> vfio_devices_all_device_dirty_tracking_started -> vfio_mem_device_dpt_is_started
>>>> vfio_devices_all_dirty_tracking_started        -> vfio_mem_dpt_is_started
>>>> vfio_devices_all_device_dirty_tracking         ->
>>>> vfio_mem_device_dpt_is_supported
>>>> vfio_devices_dma_logging_start                 -> vfio_mem_device_dpt_start
>>>> vfio_devices_dma_logging_stop                  -> vfio_mem_device_dpt_stop
>>>> vfio_devices_query_dirty_bitmap                -> vfio_mem_device_dpt_query
>>>> vfio_get_dirty_bitmap                          -> vfio_mem_dpt_query
>>>>
>>>> dpt can be changed to dirty_tracking if that's clearer and not too long.
>>>> In patch #31 we can rename to vfio_mem_{register,unregister} or
>>>> vfio_mem_listener_{register,unregister}.
>>>> More internal functions can be gradually renamed and added the vfio_mem_*
>>>> prefix.
>>>>
>>>> Will that work?
>>>>
>>> I would associate to memory if we were talking about Host windows, DMA mapping
>>> and etc. I believe that's more fundamentally related to memory handling of VFIO
>>> to justify said prefix.
>>>
>>> Here the code Cedric moved is really about dirty page tracking, or tracking
>>> changes made by VFs to memory. Calling it memory.c would be a bit of a misnomer
>>>    IMHO :(
>> Hmm, yes, the majority of the code is related to dirty tracking, but maybe we
>> can view dirty tracking as a sub-field of memory.
>> Dirty tracking doesn't seem the perfect fit IMHO, as this file also
>> contains vfio_dirty_tracking_register and .region_add/.region_del which are not
>> entirely related to dirty tracking.
>>
> Ah yes, it's a small portion but still region_{add,del} is indeed about DMA
> mapping and not at all related to dirty tracking.
>
> It's almost as if we should be moving ::region_add/region_del alongside
> vfio_dirty_tracking_{un,}register into a memory.c file and leave this one as
> dirty_tracking.c / dpt.c

Yes, this could also work.
Need to consider if it's worth the additional split churn. I have no 
strong opinion.

>
> Which reminds me that perhaps vfio_dirty_tracking_register() and the name might
> be misleading and should instead me vfio_memory_register() /
> vfio_memory_unregister().

Indeed.

>
>>>> Thanks.
>>>>
>>>>>> ---
>>>>>>     hw/vfio/dirty-tracking.h |  6 +++---
>>>>>>     hw/vfio/container.c      |  6 +++---
>>>>>>     hw/vfio/dirty-tracking.c | 44 ++++++++++++++++++++--------------------
>>>>>>     hw/vfio/trace-events     |  2 +-
>>>>>>     4 files changed, 29 insertions(+), 29 deletions(-)
>>>>>>
>>>>>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>>>>>> index
>>>>>> 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
>>>>>> --- a/hw/vfio/dirty-tracking.h
>>>>>> +++ b/hw/vfio/dirty-tracking.h
>>>>>> @@ -11,9 +11,9 @@
>>>>>>
>>>>>>     extern const MemoryListener vfio_memory_listener;
>>>>>>
>>>>>> -bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase
>>>>>> *bcontainer);
>>>>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>>>>> *bcontainer);
>>>>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>>>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>>>>> *bcontainer);
>>>>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>>>>> *bcontainer);
>>>>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>>>>> *bcontainer, uint64_t iova,
>>>>>>                               uint64_t size, ram_addr_t ram_addr, Error
>>>>>> **errp);
>>>>>>
>>>>>>     #endif /* HW_VFIO_DIRTY_TRACKING_H */
>>>>>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>>>>>> index
>>>>>> 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
>>>>>> --- a/hw/vfio/container.c
>>>>>> +++ b/hw/vfio/container.c
>>>>>> @@ -138,8 +138,8 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>>>>> *bcontainer,
>>>>>>         int ret;
>>>>>>         Error *local_err = NULL;
>>>>>>
>>>>>> -    if (iotlb && vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>>>>> -        if (!vfio_devices_all_device_dirty_tracking(bcontainer) &&
>>>>>> +    if (iotlb && vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>>>>> +        if (!vfio_dirty_tracking_devices_is_supported(bcontainer) &&
>>>>>>                 bcontainer->dirty_pages_supported) {
>>>>>>                 return vfio_dma_unmap_bitmap(container, iova, size, iotlb);
>>>>>>             }
>>>>>> @@ -170,7 +170,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBase
>>>>>> *bcontainer,
>>>>>>         }
>>>>>>
>>>>>>         if (need_dirty_sync) {
>>>>>> -        ret = vfio_get_dirty_bitmap(bcontainer, iova, size,
>>>>>> +        ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, size,
>>>>>>                                         iotlb->translated_addr, &local_err);
>>>>>>             if (ret) {
>>>>>>                 error_report_err(local_err);
>>>>>> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
>>>>>> index
>>>>>> 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
>>>>>> --- a/hw/vfio/dirty-tracking.c
>>>>>> +++ b/hw/vfio/dirty-tracking.c
>>>>>> @@ -45,7 +45,7 @@
>>>>>>      * Device state interfaces
>>>>>>      */
>>>>>>
>>>>>> -static bool vfio_devices_all_device_dirty_tracking_started(
>>>>>> +static bool vfio_dirty_tracking_devices_is_started_all(
>>>>>>         const VFIOContainerBase *bcontainer)
>>>>>>     {
>>>>>>         VFIODevice *vbasedev;
>>>>>> @@ -59,10 +59,9 @@ static bool vfio_devices_all_device_dirty_tracking_started(
>>>>>>         return true;
>>>>>>     }
>>>>>>
>>>>>> -bool vfio_devices_all_dirty_tracking_started(
>>>>>> -    const VFIOContainerBase *bcontainer)
>>>>>> +bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase
>>>>>> *bcontainer)
>>>>>>     {
>>>>>> -    return vfio_devices_all_device_dirty_tracking_started(bcontainer) ||
>>>>>> +    return vfio_dirty_tracking_devices_is_started_all(bcontainer) ||
>>>>>>                bcontainer->dirty_pages_started;
>>>>>>     }
>>>>>>
>>>>>> @@ -70,7 +69,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>>>>> *bcontainer)
>>>>>>     {
>>>>>>         VFIODevice *vbasedev;
>>>>>>
>>>>>> -    if (!vfio_devices_all_dirty_tracking_started(bcontainer)) {
>>>>>> +    if (!vfio_dirty_tracking_devices_is_started(bcontainer)) {
>>>>>>             return false;
>>>>>>         }
>>>>>>
>>>>>> @@ -90,7 +89,7 @@ static bool vfio_log_sync_needed(const VFIOContainerBase
>>>>>> *bcontainer)
>>>>>>         return true;
>>>>>>     }
>>>>>>
>>>>>> -bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase
>>>>>> *bcontainer)
>>>>>> +bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase
>>>>>> *bcontainer)
>>>>>>     {
>>>>>>         VFIODevice *vbasedev;
>>>>>>
>>>>>> @@ -809,7 +808,7 @@ static void vfio_dirty_tracking_init(VFIOContainerBase
>>>>>> *bcontainer,
>>>>>>         memory_listener_unregister(&dirty.listener);
>>>>>>     }
>>>>>>
>>>>>> -static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer)
>>>>>> +static void vfio_dirty_tracking_devices_dma_logging_stop(VFIOContainerBase
>>>>>> *bcontainer)
>>>>>>     {
>>>>>>         uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature),
>>>>>>                                   sizeof(uint64_t))] = {};
>>>>>> @@ -907,7 +906,7 @@ static void vfio_device_feature_dma_logging_start_destroy(
>>>>>>         g_free(feature);
>>>>>>     }
>>>>>>
>>>>>> -static bool vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>>>>> +static bool vfio_dirty_tracking_devices_dma_logging_start(VFIOContainerBase
>>>>>> *bcontainer,
>>>>>>                                               Error **errp)
>>>>>>     {
>>>>>>         struct vfio_device_feature *feature;
>>>>>> @@ -940,7 +939,7 @@ static bool
>>>>>> vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer,
>>>>>>
>>>>>>     out:
>>>>>>         if (ret) {
>>>>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>>>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>>>>         }
>>>>>>
>>>>>>         vfio_device_feature_dma_logging_start_destroy(feature);
>>>>>> @@ -956,8 +955,8 @@ static bool vfio_listener_log_global_start(MemoryListener
>>>>>> *listener,
>>>>>>                                                      listener);
>>>>>>         bool ret;
>>>>>>
>>>>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>>>>> -        ret = vfio_devices_dma_logging_start(bcontainer, errp);
>>>>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>>>>> +        ret = vfio_dirty_tracking_devices_dma_logging_start(bcontainer,
>>>>>> errp);
>>>>>>         } else {
>>>>>>             ret = vfio_container_set_dirty_page_tracking(bcontainer, true,
>>>>>> errp) == 0;
>>>>>>         }
>>>>>> @@ -975,8 +974,8 @@ static void vfio_listener_log_global_stop(MemoryListener
>>>>>> *listener)
>>>>>>         Error *local_err = NULL;
>>>>>>         int ret = 0;
>>>>>>
>>>>>> -    if (vfio_devices_all_device_dirty_tracking(bcontainer)) {
>>>>>> -        vfio_devices_dma_logging_stop(bcontainer);
>>>>>> +    if (vfio_dirty_tracking_devices_is_supported(bcontainer)) {
>>>>>> +        vfio_dirty_tracking_devices_dma_logging_stop(bcontainer);
>>>>>>         } else {
>>>>>>             ret = vfio_container_set_dirty_page_tracking(bcontainer, false,
>>>>>>                                                          &local_err);
>>>>>> @@ -1016,7 +1015,7 @@ static int vfio_device_dma_logging_report(VFIODevice
>>>>>> *vbasedev, hwaddr iova,
>>>>>>         return 0;
>>>>>>     }
>>>>>>
>>>>>> -static int vfio_devices_query_dirty_bitmap(const VFIOContainerBase
>>>>>> *bcontainer,
>>>>>> +static int vfio_dirty_tracking_devices_query_dirty_bitmap(const
>>>>>> VFIOContainerBase *bcontainer,
>>>>>>                      VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>>>>>>     {
>>>>>>         VFIODevice *vbasedev;
>>>>>> @@ -1038,11 +1037,11 @@ static int vfio_devices_query_dirty_bitmap(const
>>>>>> VFIOContainerBase *bcontainer,
>>>>>>         return 0;
>>>>>>     }
>>>>>>
>>>>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>>>>> +int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase
>>>>>> *bcontainer, uint64_t iova,
>>>>>>                               uint64_t size, ram_addr_t ram_addr, Error **errp)
>>>>>>     {
>>>>>>         bool all_device_dirty_tracking =
>>>>>> -        vfio_devices_all_device_dirty_tracking(bcontainer);
>>>>>> +        vfio_dirty_tracking_devices_is_supported(bcontainer);
>>>>>>         uint64_t dirty_pages;
>>>>>>         VFIOBitmap vbmap;
>>>>>>         int ret;
>>>>>> @@ -1062,8 +1061,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>>>>> *bcontainer, uint64_t iova,
>>>>>>         }
>>>>>>
>>>>>>         if (all_device_dirty_tracking) {
>>>>>> -        ret = vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, size,
>>>>>> -                                              errp);
>>>>>> +        ret = vfio_dirty_tracking_devices_query_dirty_bitmap(bcontainer,
>>>>>> &vbmap,
>>>>>> +                                                             iova, size,
>>>>>> errp);
>>>>>>         } else {
>>>>>>             ret = vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova,
>>>>>> size,
>>>>>>                                                     errp);
>>>>>> @@ -1076,7 +1075,8 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase
>>>>>> *bcontainer, uint64_t iova,
>>>>>>         dirty_pages = cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap,
>>>>>> ram_addr,
>>>>>>                                                              vbmap.pages);
>>>>>>
>>>>>> -    trace_vfio_get_dirty_bitmap(iova, size, vbmap.size, ram_addr,
>>>>>> dirty_pages);
>>>>>> +    trace_vfio_dirty_tracking_query_dirty_bitmap(iova, size, vbmap.size,
>>>>>> ram_addr,
>>>>>> +                                                 dirty_pages);
>>>>>>     out:
>>>>>>         g_free(vbmap.bitmap);
>>>>>>
>>>>>> @@ -1113,7 +1113,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier
>>>>>> *n, IOMMUTLBEntry *iotlb)
>>>>>>             goto out_unlock;
>>>>>>         }
>>>>>>
>>>>>> -    ret = vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1,
>>>>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(bcontainer, iova, iotlb-
>>>>>>> addr_mask + 1,
>>>>>>                                     translated_addr, &local_err);
>>>>>>         if (ret) {
>>>>>>             error_prepend(&local_err,
>>>>>> @@ -1147,7 +1147,7 @@ static int
>>>>>> vfio_ram_discard_get_dirty_bitmap(MemoryRegionSection *section,
>>>>>>          * Sync the whole mapped region (spanning multiple individual mappings)
>>>>>>          * in one go.
>>>>>>          */
>>>>>> -    ret = vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr,
>>>>>> +    ret = vfio_dirty_tracking_query_dirty_bitmap(vrdl->bcontainer, iova,
>>>>>> size, ram_addr,
>>>>>>                                     &local_err);
>>>>>>         if (ret) {
>>>>>>             error_report_err(local_err);
>>>>>> @@ -1241,7 +1241,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase
>>>>>> *bcontainer,
>>>>>>         ram_addr = memory_region_get_ram_addr(section->mr) +
>>>>>>                    section->offset_within_region;
>>>>>>
>>>>>> -    return vfio_get_dirty_bitmap(bcontainer,
>>>>>> +    return vfio_dirty_tracking_query_dirty_bitmap(bcontainer,
>>>>>>                        REAL_HOST_PAGE_ALIGN(section-
>>>>>>> offset_within_address_space),
>>>>>>                                      int128_get64(section->size), ram_addr,
>>>>>> errp);
>>>>>>     }
>>>>>> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>>>>>> index
>>>>>> 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
>>>>>> --- a/hw/vfio/trace-events
>>>>>> +++ b/hw/vfio/trace-events
>>>>>> @@ -100,7 +100,7 @@ vfio_listener_region_del(uint64_t start, uint64_t end)
>>>>>> "region_del 0x%"PRIx64" -
>>>>>>     vfio_device_dirty_tracking_update(uint64_t start, uint64_t end, uint64_t
>>>>>> min, uint64_t max) "section 0x%"PRIx64" - 0x%"PRIx64" -> update [0x%"PRIx64"
>>>>>> - 0x%"PRIx64"]"
>>>>>>     vfio_device_dirty_tracking_start(int nr_ranges, uint64_t min32, uint64_t
>>>>>> max32, uint64_t min64, uint64_t max64, uint64_t minpci, uint64_t maxpci)
>>>>>> "nr_ranges %d 32:[0x%"PRIx64" - 0x%"PRIx64"], 64:[0x%"PRIx64" - 0x%"PRIx64"],
>>>>>> pci64:[0x%"PRIx64" - 0x%"PRIx64"]"
>>>>>>     vfio_legacy_dma_unmap_overflow_workaround(void) ""
>>>>>> -vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size,
>>>>>> uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64"
>>>>>> bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>>>>>> +vfio_dirty_tracking_query_dirty_bitmap(uint64_t iova, uint64_t size,
>>>>>> uint64_t bitmap_size, uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64"
>>>>>> size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64"
>>>>>> dirty_pages=%"PRIu64
>>>>>>     vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu
>>>>>> dirty @ 0x%"PRIx64" - 0x%"PRIx64
>>>>>>
>>>>>>     # region.c


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines
  2025-03-19 13:24   ` Joao Martins
@ 2025-03-20 12:28     ` Joao Martins
  0 siblings, 0 replies; 114+ messages in thread
From: Joao Martins @ 2025-03-20 12:28 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 19/03/2025 13:24, Joao Martins wrote:
> On 18/03/2025 09:54, Cédric Le Goater wrote:
>> This hides the MemoryListener implementation and makes the code common
>> to both IOMMU backends, legacy and IOMMUFD.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> 
> Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
> 

After discussing with Avihai, maybe the routine should be representative on what
it does and not so much on the namespace i.e.

	vfio_dirty_tracking_register -> vfio_memory_register
	vfio_dirty_tracking_unregister -> vfio_memory_unregister

Given that these have nothing to do with dirty tracking.

In terms of memory listeners the only function relevant in this area is:

	vfio_dirty_tracking_init
	vfio_dirty_tracking_update

Which have different purpose where we parse the memory ranges to construct 32/64
bit ranges for VF trackers.

>> ---
>>  hw/vfio/dirty-tracking.h |  4 ++--
>>  hw/vfio/container.c      | 11 +++--------
>>  hw/vfio/dirty-tracking.c | 21 ++++++++++++++++++++-
>>  hw/vfio/iommufd.c        |  9 ++-------
>>  4 files changed, 27 insertions(+), 18 deletions(-)
>>
>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>> index db9494202a780108ce78b642950bfed78ba3f253..6d717f0e918e47e341114c82ffc2cf520fc7b079 100644
>> --- a/hw/vfio/dirty-tracking.h
>> +++ b/hw/vfio/dirty-tracking.h
>> @@ -9,11 +9,11 @@
>>  #ifndef HW_VFIO_DIRTY_TRACKING_H
>>  #define HW_VFIO_DIRTY_TRACKING_H
>>  
>> -extern const MemoryListener vfio_memory_listener;
>> -
>>  bool vfio_dirty_tracking_devices_is_started(const VFIOContainerBase *bcontainer);
>>  bool vfio_dirty_tracking_devices_is_supported(const VFIOContainerBase *bcontainer);
>>  int vfio_dirty_tracking_query_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>>                            uint64_t size, ram_addr_t ram_addr, Error **errp);
>> +bool vfio_dirty_tracking_register(VFIOContainerBase *bcontainer, Error **errp);
>> +void vfio_dirty_tracking_unregister(VFIOContainerBase *bcontainer);
>>  
>>  #endif /* HW_VFIO_DIRTY_TRACKING_H */
>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>> index 7b3ec798a77052b8cb0b47d3dceaca1428cb50bd..1fcca75caba19353ad3063ae97b20c15f61564e9 100644
>> --- a/hw/vfio/container.c
>> +++ b/hw/vfio/container.c
>> @@ -616,12 +616,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
>>      group->container = container;
>>      QLIST_INSERT_HEAD(&container->group_list, group, container_next);
>>  
>> -    bcontainer->listener = 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_dirty_tracking_register(bcontainer, errp)) {
>>          goto listener_release_exit;
>>      }
>>  
>> @@ -631,7 +626,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
>>  listener_release_exit:
>>      QLIST_REMOVE(group, container_next);
>>      vfio_group_del_kvm_device(group);
>> -    memory_listener_unregister(&bcontainer->listener);
>> +    vfio_dirty_tracking_unregister(bcontainer);
>>      if (vioc->release) {
>>          vioc->release(bcontainer);
>>      }
>> @@ -669,7 +664,7 @@ static void vfio_container_disconnect(VFIOGroup *group)
>>       * group.
>>       */
>>      if (QLIST_EMPTY(&container->group_list)) {
>> -        memory_listener_unregister(&bcontainer->listener);
>> +        vfio_dirty_tracking_unregister(bcontainer);
>>          if (vioc->release) {
>>              vioc->release(bcontainer);
>>          }
>> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
>> index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644
>> --- a/hw/vfio/dirty-tracking.c
>> +++ b/hw/vfio/dirty-tracking.c
>> @@ -1267,7 +1267,7 @@ static void vfio_listener_log_sync(MemoryListener *listener,
>>      }
>>  }
>>  
>> -const MemoryListener vfio_memory_listener = {
>> +static const MemoryListener vfio_memory_listener = {
>>      .name = "vfio",
>>      .region_add = vfio_listener_region_add,
>>      .region_del = vfio_listener_region_del,
>> @@ -1275,3 +1275,22 @@ const MemoryListener vfio_memory_listener = {
>>      .log_global_stop = vfio_listener_log_global_stop,
>>      .log_sync = vfio_listener_log_sync,
>>  };
>> +
>> +bool vfio_dirty_tracking_register(VFIOContainerBase *bcontainer, Error **errp)
>> +{
>> +    bcontainer->listener = 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_dirty_tracking_unregister(VFIOContainerBase *bcontainer)
>> +{
>> +    memory_listener_unregister(&bcontainer->listener);
>> +}
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index 7f354d86cd14270a70dc990860ad5b69f0310719..7737d552f310c54ae2e035198a1a83da8c3199dd 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -411,7 +411,7 @@ static void iommufd_cdev_container_destroy(VFIOIOMMUFDContainer *container)
>>      if (!QLIST_EMPTY(&bcontainer->device_list)) {
>>          return;
>>      }
>> -    memory_listener_unregister(&bcontainer->listener);
>> +    vfio_dirty_tracking_unregister(bcontainer);
>>      iommufd_backend_free_id(container->be, container->ioas_id);
>>      object_unref(container);
>>  }
>> @@ -563,12 +563,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
>>          bcontainer->pgsizes = qemu_real_host_page_size();
>>      }
>>  
>> -    bcontainer->listener = 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_dirty_tracking_register(bcontainer, errp)) {
>>          goto err_listener_register;
>>      }
>>  
> 
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations
  2025-03-20  9:18   ` Duan, Zhenzhong
@ 2025-03-20 13:37     ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-20 13:37 UTC (permalink / raw)
  To: Duan, Zhenzhong, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger

On 3/20/25 10:18, Duan, Zhenzhong wrote:
> 
> 
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Subject: [PATCH for-10.1 09/32] vfio: Introduce a new header file for
>> VFIOIOMMUFD declarations
>>
>> Gather all VFIOIOMMUFD related declarations into "iommufd.h" to
>> reduce exposure of VFIO internals in "hw/vfio/vfio-common.h".
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>> hw/vfio/iommufd.h             | 29 +++++++++++++++++++++++++++++
>> include/hw/vfio/vfio-common.h | 21 +++------------------
>> hw/vfio/iommufd.c             |  1 +
>> 3 files changed, 33 insertions(+), 18 deletions(-)
>> create mode 100644 hw/vfio/iommufd.h
>>
>> diff --git a/hw/vfio/iommufd.h b/hw/vfio/iommufd.h
>> new file mode 100644
>> index
>> 0000000000000000000000000000000000000000..7d87994c4fadbc328b6ac7f9ae
>> e00469dd8808b0
>> --- /dev/null
>> +++ b/hw/vfio/iommufd.h
>> @@ -0,0 +1,29 @@
>> +/*
>> + * VFIO iommufd
>> + *
>> + * Copyright Red Hat, Inc. 2025
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +
>> +#ifndef HW_VFIO_IOMMUFD_H
>> +#define HW_VFIO_IOMMUFD_H
>> +
>> +
>> +typedef struct VFIOIOASHwpt {
>> +    uint32_t hwpt_id;
>> +    uint32_t hwpt_flags;
>> +    QLIST_HEAD(, VFIODevice) device_list;
>> +    QLIST_ENTRY(VFIOIOASHwpt) next;
>> +} VFIOIOASHwpt;
>> +
>> +typedef struct VFIOIOMMUFDContainer {
>> +    VFIOContainerBase bcontainer;
>> +    IOMMUFDBackend *be;
> 
> Do we need to add 'typedef struct IOMMUFDBackend IOMMUFDBackend;' for above line?

yes and we need a few more includes too (VFIODevice , VFIOContainerBase).


Thanks,

C.



> 
> Thanks
> Zhenzhong
> 
>> +    uint32_t ioas_id;
>> +    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
>> +} VFIOIOMMUFDContainer;
>> +
>> +OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer,
>> VFIO_IOMMU_IOMMUFD);
>> +
>> +#endif /* HW_VFIO_IOMMUFD_H */
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>> index
>> 3355c2d4e57569d7bb01b4d9378fb49a807335e8..8d48f5300a791d8858fe29d1bb
>> 905f814ef11990 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -69,27 +69,12 @@ typedef struct VFIOContainer {
>>
>> OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
>>
>> -typedef struct IOMMUFDBackend IOMMUFDBackend;
>> -
>> -typedef struct VFIOIOASHwpt {
>> -    uint32_t hwpt_id;
>> -    uint32_t hwpt_flags;
>> -    QLIST_HEAD(, VFIODevice) device_list;
>> -    QLIST_ENTRY(VFIOIOASHwpt) next;
>> -} VFIOIOASHwpt;
>> -
>> -typedef struct VFIOIOMMUFDContainer {
>> -    VFIOContainerBase bcontainer;
>> -    IOMMUFDBackend *be;
>> -    uint32_t ioas_id;
>> -    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
>> -} VFIOIOMMUFDContainer;
>> -
>> -OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer,
>> VFIO_IOMMU_IOMMUFD);
>> -
>> typedef struct VFIODeviceOps VFIODeviceOps;
>> typedef struct VFIOMigration VFIOMigration;
>>
>> +typedef struct IOMMUFDBackend IOMMUFDBackend;
>> +typedef struct VFIOIOASHwpt VFIOIOASHwpt;
>> +
>> typedef struct VFIODevice {
>>      QLIST_ENTRY(VFIODevice) next;
>>      QLIST_ENTRY(VFIODevice) container_next;
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index
>> 2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0..a219b6453037e2d4e0d12800ea
>> 25678885af98f8 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -26,6 +26,7 @@
>> #include "qemu/chardev_open.h"
>> #include "pci.h"
>> #include "migration.h"
>> +#include "iommufd.h"
>>
>> static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr
>> iova,
>>                              ram_addr_t size, void *vaddr, bool readonly)
>> --
>> 2.48.1
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c
  2025-03-20  9:36   ` Duan, Zhenzhong
@ 2025-03-20 19:26     ` Cédric Le Goater
  2025-03-21  7:18       ` Duan, Zhenzhong
  0 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-20 19:26 UTC (permalink / raw)
  To: Duan, Zhenzhong, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger, John Levon

+John

On 3/20/25 10:36, Duan, Zhenzhong wrote:
> 
> 
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Subject: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into
>> container-base.c
>>
>> VFIOAddressSpace is a common object used by VFIOContainerBase which is
>> declared in "hw/vfio/vfio-container-base.h". Move the VFIOAddressSpace
>> related services into "container-base.c".
>>
>> While at it, rename :
>>
>>   vfio_get_address_space -> vfio_address_space_get
>>   vfio_put_address_space -> vfio_address_space_put
>>
>> to better reflect the namespace these routines belong to.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>> include/hw/vfio/vfio-common.h         |  6 ---
>> include/hw/vfio/vfio-container-base.h |  5 ++
>> hw/ppc/spapr_pci_vfio.c               |  5 +-
>> hw/vfio/common.c                      | 66 -------------------------
>> hw/vfio/container-base.c              | 69 +++++++++++++++++++++++++++
>> hw/vfio/container.c                   |  6 +--
>> hw/vfio/iommufd.c                     |  6 +--
>> hw/vfio/trace-events                  |  4 +-
>> 8 files changed, 85 insertions(+), 82 deletions(-)
>>
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>> index
>> e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236
>> cac0bbe834b39 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -120,18 +120,12 @@ struct VFIODeviceOps {
>> #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \
>>              TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
>>
>> -VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
>> -void vfio_put_address_space(VFIOAddressSpace *space);
>> -void vfio_address_space_insert(VFIOAddressSpace *space,
>> -                               VFIOContainerBase *bcontainer);
>> -
>> 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);
>> bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
>>                              int action, int fd, Error **errp);
>>
>> -void vfio_reset_handler(void *opaque);
>> struct vfio_device_info *vfio_get_device_info(int fd);
>> bool vfio_device_is_mdev(VFIODevice *vbasedev);
>> bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
>> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-
>> container-base.h
>> index
>> 4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda954
>> 8c8e60afefe794 100644
>> --- a/include/hw/vfio/vfio-container-base.h
>> +++ b/include/hw/vfio/vfio-container-base.h
>> @@ -71,6 +71,11 @@ typedef struct VFIORamDiscardListener {
>>      QLIST_ENTRY(VFIORamDiscardListener) next;
>> } VFIORamDiscardListener;
>>
>> +VFIOAddressSpace *vfio_address_space_get(AddressSpace *as);
>> +void vfio_address_space_put(VFIOAddressSpace *space);
>> +void vfio_address_space_insert(VFIOAddressSpace *space,
>> +                               VFIOContainerBase *bcontainer);
>> +
>> int vfio_container_dma_map(VFIOContainerBase *bcontainer,
>>                             hwaddr iova, ram_addr_t size,
>>                             void *vaddr, bool readonly);
>> diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
>> index
>> 1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc21
>> 95bf68418e5206 100644
>> --- a/hw/ppc/spapr_pci_vfio.c
>> +++ b/hw/ppc/spapr_pci_vfio.c
>> @@ -24,7 +24,6 @@
>> #include "hw/pci-host/spapr.h"
>> #include "hw/pci/msix.h"
>> #include "hw/pci/pci_device.h"
>> -#include "hw/vfio/vfio-common.h"
>> #include "hw/vfio/vfio-container.h"
>> #include "qemu/error-report.h"
>> #include CONFIG_DEVICES /* CONFIG_VFIO_PCI */
>> @@ -86,7 +85,7 @@ static int vfio_eeh_container_op(VFIOContainer *container,
>> uint32_t op)
>>
>> static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
>> {
>> -    VFIOAddressSpace *space = vfio_get_address_space(as);
>> +    VFIOAddressSpace *space = vfio_address_space_get(as);
>>      VFIOContainerBase *bcontainer = NULL;
>>
>>      if (QLIST_EMPTY(&space->containers)) {
>> @@ -106,7 +105,7 @@ static VFIOContainer
>> *vfio_eeh_as_container(AddressSpace *as)
>>      }
>>
>> out:
>> -    vfio_put_address_space(space);
>> +    vfio_address_space_put(space);
>>      return container_of(bcontainer, VFIOContainer, bcontainer);
>> }
>>
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index
>> 0e3746eddd1c08e98bf57a59d542e158487d346e..08e2494d7c4a9858657724730
>> b2829290fb3f197 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -36,7 +36,6 @@
>> #include "qemu/main-loop.h"
>> #include "qemu/range.h"
>> #include "system/kvm.h"
>> -#include "system/reset.h"
>> #include "system/runstate.h"
>> #include "trace.h"
>> #include "qapi/error.h"
>> @@ -48,8 +47,6 @@
>>
>> VFIODeviceList vfio_device_list =
>>      QLIST_HEAD_INITIALIZER(vfio_device_list);
>> -static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
>> -    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
>>
>> #ifdef CONFIG_KVM
>> /*
>> @@ -1304,24 +1301,6 @@ const MemoryListener vfio_memory_listener = {
>>      .log_sync = vfio_listener_log_sync,
>> };
>>
>> -void vfio_reset_handler(void *opaque)
>> -{
>> -    VFIODevice *vbasedev;
>> -
>> -    trace_vfio_reset_handler();
>> -    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>> -        if (vbasedev->dev->realized) {
>> -            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
>> -        }
>> -    }
>> -
>> -    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>> -        if (vbasedev->dev->realized && vbasedev->needs_reset) {
>> -            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
>> -        }
>> -    }
>> -}
>> -
>> int vfio_kvm_device_add_fd(int fd, Error **errp)
>> {
>> #ifdef CONFIG_KVM
>> @@ -1380,51 +1359,6 @@ int vfio_kvm_device_del_fd(int fd, Error **errp)
>>      return 0;
>> }
>>
>> -VFIOAddressSpace *vfio_get_address_space(AddressSpace *as)
>> -{
>> -    VFIOAddressSpace *space;
>> -
>> -    QLIST_FOREACH(space, &vfio_address_spaces, list) {
>> -        if (space->as == as) {
>> -            return space;
>> -        }
>> -    }
>> -
>> -    /* No suitable VFIOAddressSpace, create a new one */
>> -    space = g_malloc0(sizeof(*space));
>> -    space->as = as;
>> -    QLIST_INIT(&space->containers);
>> -
>> -    if (QLIST_EMPTY(&vfio_address_spaces)) {
>> -        qemu_register_reset(vfio_reset_handler, NULL);
>> -    }
>> -
>> -    QLIST_INSERT_HEAD(&vfio_address_spaces, space, list);
>> -
>> -    return space;
>> -}
>> -
>> -void vfio_put_address_space(VFIOAddressSpace *space)
>> -{
>> -    if (!QLIST_EMPTY(&space->containers)) {
>> -        return;
>> -    }
>> -
>> -    QLIST_REMOVE(space, list);
>> -    g_free(space);
>> -
>> -    if (QLIST_EMPTY(&vfio_address_spaces)) {
>> -        qemu_unregister_reset(vfio_reset_handler, NULL);
>> -    }
>> -}
>> -
>> -void vfio_address_space_insert(VFIOAddressSpace *space,
>> -                               VFIOContainerBase *bcontainer)
>> -{
>> -    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>> -    bcontainer->space = space;
>> -}
>> -
>> struct vfio_device_info *vfio_get_device_info(int fd)
>> {
>>      struct vfio_device_info *info;
>> diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
>> index
>> 749a3fd29dd6fc9143f14edf7e4ac6238315fcce..83e83ab9e67de8b004dfaf0067e
>> 4c466a6c88451 100644
>> --- a/hw/vfio/container-base.c
>> +++ b/hw/vfio/container-base.c
>> @@ -13,7 +13,76 @@
>> #include "qemu/osdep.h"
>> #include "qapi/error.h"
>> #include "qemu/error-report.h"
>> +#include "system/reset.h"
>> #include "hw/vfio/vfio-container-base.h"
>> +#include "hw/vfio/vfio-common.h" /* for vfio_device_list */
>> +#include "trace.h"
>> +
>> +static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
>> +    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
>> +
>> +static void vfio_reset_handler(void *opaque)
>> +{
>> +    VFIODevice *vbasedev;
>> +
>> +    trace_vfio_reset_handler();
>> +    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>> +        if (vbasedev->dev->realized) {
>> +            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
>> +        }
>> +    }
>> +
>> +    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>> +        if (vbasedev->dev->realized && vbasedev->needs_reset) {
>> +            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
>> +        }
>> +    }
>> +}
> 
> This is not an address space scoped function, 

yep.

AIUI, pass-through devices of a VM are not necessarily in the same
group and we need to scan all groups/address_spaces when the machine
is reset.

There use to be a long comment explaining the context but we lost it
along the way. I will add it back :

   /*
    * We want to differentiate hot reset of mulitple in-use devices vs hot reset
    * of a single in-use device.  VFIO_DEVICE_RESET will already handle the case
    * of doing hot resets when there is only a single device per bus.  The in-use
    * here refers to how many VFIODevices are affected.  A hot reset that affects
    * multiple devices, but only a single in-use device, means that we can call
    * it from our bus ->reset() callback since the extent is effectively a single
    * device.  This allows us to make use of it in the hotplug path.  When there
    * are multiple in-use devices, we can only trigger the hot reset during a
    * system reset and thus from our reset handler.  We separate _one vs _multi
    * here so that we don't overlap and do a double reset on the system reset
    * path where both our reset handler and ->reset() callback are used.  Calling
    * _one() will only do a hot reset for the one in-use devices case, calling
    * _multi() will do nothing if a _one() would have been sufficient.
    */

See commit f16f39c3fc97 ("Implement PCI hot reset").

> no sure if better to move to helper.c or common.c

This is a machine scope "helper" calling VFIODevice handlers, may be in
device.c  ?


Thanks,

C.


  
> Thanks
> Zhenzhong
> 
>> +
>> +VFIOAddressSpace *vfio_address_space_get(AddressSpace *as)
>> +{
>> +    VFIOAddressSpace *space;
>> +
>> +    QLIST_FOREACH(space, &vfio_address_spaces, list) {
>> +        if (space->as == as) {
>> +            return space;
>> +        }
>> +    }
>> +
>> +    /* No suitable VFIOAddressSpace, create a new one */
>> +    space = g_malloc0(sizeof(*space));
>> +    space->as = as;
>> +    QLIST_INIT(&space->containers);
>> +
>> +    if (QLIST_EMPTY(&vfio_address_spaces)) {
>> +        qemu_register_reset(vfio_reset_handler, NULL);
>> +    }
>> +
>> +    QLIST_INSERT_HEAD(&vfio_address_spaces, space, list);
>> +
>> +    return space;
>> +}
>> +
>> +void vfio_address_space_put(VFIOAddressSpace *space)
>> +{
>> +    if (!QLIST_EMPTY(&space->containers)) {
>> +        return;
>> +    }
>> +
>> +    QLIST_REMOVE(space, list);
>> +    g_free(space);
>> +
>> +    if (QLIST_EMPTY(&vfio_address_spaces)) {
>> +        qemu_unregister_reset(vfio_reset_handler, NULL);
>> +    }
>> +}
>> +
>> +void vfio_address_space_insert(VFIOAddressSpace *space,
>> +                               VFIOContainerBase *bcontainer)
>> +{
>> +    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>> +    bcontainer->space = space;
>> +}
>>
>> int vfio_container_dma_map(VFIOContainerBase *bcontainer,
>>                             hwaddr iova, ram_addr_t size,
>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>> index
>> 8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb..9b86e24a4072e579bcdc2c060c
>> e42608ee44ee2e 100644
>> --- a/hw/vfio/container.c
>> +++ b/hw/vfio/container.c
>> @@ -546,7 +546,7 @@ static bool vfio_connect_container(VFIOGroup *group,
>> AddressSpace *as,
>>      VFIOAddressSpace *space;
>>      VFIOIOMMUClass *vioc;
>>
>> -    space = vfio_get_address_space(as);
>> +    space = vfio_address_space_get(as);
>>
>>      /*
>>       * VFIO is currently incompatible with discarding of RAM insofar as the
>> @@ -675,7 +675,7 @@ close_fd_exit:
>>      close(fd);
>>
>> put_space_exit:
>> -    vfio_put_address_space(space);
>> +    vfio_address_space_put(space);
>>
>>      return false;
>> }
>> @@ -714,7 +714,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
>>          close(container->fd);
>>          object_unref(container);
>>
>> -        vfio_put_address_space(space);
>> +        vfio_address_space_put(space);
>>      }
>> }
>>
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index
>> a219b6453037e2d4e0d12800ea25678885af98f8..a170f5c71218db8c9b2f00b1a4
>> 5ee900b6b21346 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -487,7 +487,7 @@ static bool iommufd_cdev_attach(const char *name,
>> VFIODevice *vbasedev,
>>          goto err_connect_bind;
>>      }
>>
>> -    space = vfio_get_address_space(as);
>> +    space = vfio_address_space_get(as);
>>
>>      /*
>>       * The HostIOMMUDevice data from legacy backend is static and doesn't need
>> @@ -607,7 +607,7 @@ err_discard_disable:
>> err_attach_container:
>>      iommufd_cdev_container_destroy(container);
>> err_alloc_ioas:
>> -    vfio_put_address_space(space);
>> +    vfio_address_space_put(space);
>>      iommufd_cdev_unbind_and_disconnect(vbasedev);
>> err_connect_bind:
>>      close(vbasedev->fd);
>> @@ -632,7 +632,7 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev)
>>      vfio_cpr_unregister_container(bcontainer);
>>      iommufd_cdev_detach_container(vbasedev, container);
>>      iommufd_cdev_container_destroy(container);
>> -    vfio_put_address_space(space);
>> +    vfio_address_space_put(space);
>>
>>      iommufd_cdev_unbind_and_disconnect(vbasedev);
>>      close(vbasedev->fd);
>> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
>> index
>> 81f4130100c48012c15b5b4858446149a7eaf5b6..c3691c1a172c31c5b10bfd6967
>> c32fd32b65d0f7 100644
>> --- a/hw/vfio/trace-events
>> +++ b/hw/vfio/trace-events
>> @@ -109,7 +109,6 @@ vfio_get_dev_region(const char *name, int index,
>> uint32_t type, uint32_t subtype
>> vfio_legacy_dma_unmap_overflow_workaround(void) ""
>> vfio_get_dirty_bitmap(uint64_t iova, uint64_t size, uint64_t bitmap_size,
>> uint64_t start, uint64_t dirty_pages) "iova=0x%"PRIx64" size= 0x%"PRIx64"
>> bitmap_size=0x%"PRIx64" start=0x%"PRIx64" dirty_pages=%"PRIu64
>> vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu
>> dirty @ 0x%"PRIx64" - 0x%"PRIx64
>> -vfio_reset_handler(void) ""
>>
>> # region.c
>> vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data,
>> unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
>> @@ -194,3 +193,6 @@ iommufd_cdev_fail_attach_existing_container(const
>> char *msg) " %s"
>> iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [iommufd=%d] new
>> IOMMUFD container with ioasid=%d"
>> iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int
>> num_regions, int flags) " %s (%d) num_irqs=%d num_regions=%d flags=%d"
>> iommufd_cdev_pci_hot_reset_dep_devices(int domain, int bus, int slot, int
>> function, int dev_id) "\t%04x:%02x:%02x.%x devid %d"
>> +
>> +# container-base.c
>> +vfio_reset_handler(void) ""
>> --
>> 2.48.1
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-20 11:00     ` Joao Martins
@ 2025-03-21  6:24       ` Duan, Zhenzhong
  0 siblings, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-21  6:24 UTC (permalink / raw)
  To: Joao Martins
  Cc: Avihai Horon, Eric Auger, qemu-devel@nongnu.org,
	Cédric Le Goater, Alex Williamson



>-----Original Message-----
>From: Joao Martins <joao.m.martins@oracle.com>
>Subject: Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking
>definitions and declarations
>
>On 20/03/2025 09:52, Duan, Zhenzhong wrote:
>>> -----Original Message-----
>>> From: Cédric Le Goater <clg@redhat.com>
>>> Subject: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking
>>> definitions and declarations
>>>
>>> File "common.c" has been emptied of most of its definitions by the
>>> previous changes and the only definitions left are related to dirty
>>> tracking. Rename it to "dirty-tracking.c" and introduce its associated
>>> "dirty-tracking.h" header file for the declarations.
>>>
>>> Cleanup a little the includes while at it.
>>>
>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>> --- a/hw/vfio/common.c
>>> +++ b/hw/vfio/dirty-tracking.c
>>> @@ -20,14 +20,10 @@
>>>
>>> #include "qemu/osdep.h"
>>> #include <sys/ioctl.h>
>>> -#ifdef CONFIG_KVM
>>> -#include <linux/kvm.h>
>>> -#endif
>>
>> It looks this change unrelated to this patch?
>>
>>> #include <linux/vfio.h>
>>>
>>> #include "hw/vfio/vfio-common.h"
>>> #include "hw/vfio/pci.h"
>>> -#include "exec/address-spaces.h"
>>
>> Same here.
>>
>
>It's written in the commit message:
>
>	"Cleanup a little the includes while at it."

Oh yes, I missed it, no problem here.

Thanks
Zhenzhong 


^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c
  2025-03-20 19:26     ` Cédric Le Goater
@ 2025-03-21  7:18       ` Duan, Zhenzhong
  0 siblings, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-21  7:18 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger, John Levon



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: Re: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into
>container-base.c
>
>+John
>
>On 3/20/25 10:36, Duan, Zhenzhong wrote:
>>
>>
>>> -----Original Message-----
>>> From: Cédric Le Goater <clg@redhat.com>
>>> Subject: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into
>>> container-base.c
>>>
>>> VFIOAddressSpace is a common object used by VFIOContainerBase which is
>>> declared in "hw/vfio/vfio-container-base.h". Move the VFIOAddressSpace
>>> related services into "container-base.c".
>>>
>>> While at it, rename :
>>>
>>>   vfio_get_address_space -> vfio_address_space_get
>>>   vfio_put_address_space -> vfio_address_space_put
>>>
>>> to better reflect the namespace these routines belong to.
>>>
>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>> ---
>>> include/hw/vfio/vfio-common.h         |  6 ---
>>> include/hw/vfio/vfio-container-base.h |  5 ++
>>> hw/ppc/spapr_pci_vfio.c               |  5 +-
>>> hw/vfio/common.c                      | 66 -------------------------
>>> hw/vfio/container-base.c              | 69 +++++++++++++++++++++++++++
>>> hw/vfio/container.c                   |  6 +--
>>> hw/vfio/iommufd.c                     |  6 +--
>>> hw/vfio/trace-events                  |  4 +-
>>> 8 files changed, 85 insertions(+), 82 deletions(-)
>>>
>>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>>> index
>>>
>e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236
>>> cac0bbe834b39 100644
>>> --- a/include/hw/vfio/vfio-common.h
>>> +++ b/include/hw/vfio/vfio-common.h
>>> @@ -120,18 +120,12 @@ struct VFIODeviceOps {
>>> #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD_VFIO \
>>>              TYPE_HOST_IOMMU_DEVICE_IOMMUFD "-vfio"
>>>
>>> -VFIOAddressSpace *vfio_get_address_space(AddressSpace *as);
>>> -void vfio_put_address_space(VFIOAddressSpace *space);
>>> -void vfio_address_space_insert(VFIOAddressSpace *space,
>>> -                               VFIOContainerBase *bcontainer);
>>> -
>>> 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);
>>> bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex,
>>>                              int action, int fd, Error **errp);
>>>
>>> -void vfio_reset_handler(void *opaque);
>>> struct vfio_device_info *vfio_get_device_info(int fd);
>>> bool vfio_device_is_mdev(VFIODevice *vbasedev);
>>> bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp);
>>> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-
>>> container-base.h
>>> index
>>>
>4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda954
>>> 8c8e60afefe794 100644
>>> --- a/include/hw/vfio/vfio-container-base.h
>>> +++ b/include/hw/vfio/vfio-container-base.h
>>> @@ -71,6 +71,11 @@ typedef struct VFIORamDiscardListener {
>>>      QLIST_ENTRY(VFIORamDiscardListener) next;
>>> } VFIORamDiscardListener;
>>>
>>> +VFIOAddressSpace *vfio_address_space_get(AddressSpace *as);
>>> +void vfio_address_space_put(VFIOAddressSpace *space);
>>> +void vfio_address_space_insert(VFIOAddressSpace *space,
>>> +                               VFIOContainerBase *bcontainer);
>>> +
>>> int vfio_container_dma_map(VFIOContainerBase *bcontainer,
>>>                             hwaddr iova, ram_addr_t size,
>>>                             void *vaddr, bool readonly);
>>> diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
>>> index
>>>
>1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc21
>>> 95bf68418e5206 100644
>>> --- a/hw/ppc/spapr_pci_vfio.c
>>> +++ b/hw/ppc/spapr_pci_vfio.c
>>> @@ -24,7 +24,6 @@
>>> #include "hw/pci-host/spapr.h"
>>> #include "hw/pci/msix.h"
>>> #include "hw/pci/pci_device.h"
>>> -#include "hw/vfio/vfio-common.h"
>>> #include "hw/vfio/vfio-container.h"
>>> #include "qemu/error-report.h"
>>> #include CONFIG_DEVICES /* CONFIG_VFIO_PCI */
>>> @@ -86,7 +85,7 @@ static int vfio_eeh_container_op(VFIOContainer
>*container,
>>> uint32_t op)
>>>
>>> static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
>>> {
>>> -    VFIOAddressSpace *space = vfio_get_address_space(as);
>>> +    VFIOAddressSpace *space = vfio_address_space_get(as);
>>>      VFIOContainerBase *bcontainer = NULL;
>>>
>>>      if (QLIST_EMPTY(&space->containers)) {
>>> @@ -106,7 +105,7 @@ static VFIOContainer
>>> *vfio_eeh_as_container(AddressSpace *as)
>>>      }
>>>
>>> out:
>>> -    vfio_put_address_space(space);
>>> +    vfio_address_space_put(space);
>>>      return container_of(bcontainer, VFIOContainer, bcontainer);
>>> }
>>>
>>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>>> index
>>>
>0e3746eddd1c08e98bf57a59d542e158487d346e..08e2494d7c4a9858657724730
>>> b2829290fb3f197 100644
>>> --- a/hw/vfio/common.c
>>> +++ b/hw/vfio/common.c
>>> @@ -36,7 +36,6 @@
>>> #include "qemu/main-loop.h"
>>> #include "qemu/range.h"
>>> #include "system/kvm.h"
>>> -#include "system/reset.h"
>>> #include "system/runstate.h"
>>> #include "trace.h"
>>> #include "qapi/error.h"
>>> @@ -48,8 +47,6 @@
>>>
>>> VFIODeviceList vfio_device_list =
>>>      QLIST_HEAD_INITIALIZER(vfio_device_list);
>>> -static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
>>> -    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
>>>
>>> #ifdef CONFIG_KVM
>>> /*
>>> @@ -1304,24 +1301,6 @@ const MemoryListener vfio_memory_listener = {
>>>      .log_sync = vfio_listener_log_sync,
>>> };
>>>
>>> -void vfio_reset_handler(void *opaque)
>>> -{
>>> -    VFIODevice *vbasedev;
>>> -
>>> -    trace_vfio_reset_handler();
>>> -    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>>> -        if (vbasedev->dev->realized) {
>>> -            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
>>> -        }
>>> -    }
>>> -
>>> -    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>>> -        if (vbasedev->dev->realized && vbasedev->needs_reset) {
>>> -            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
>>> -        }
>>> -    }
>>> -}
>>> -
>>> int vfio_kvm_device_add_fd(int fd, Error **errp)
>>> {
>>> #ifdef CONFIG_KVM
>>> @@ -1380,51 +1359,6 @@ int vfio_kvm_device_del_fd(int fd, Error **errp)
>>>      return 0;
>>> }
>>>
>>> -VFIOAddressSpace *vfio_get_address_space(AddressSpace *as)
>>> -{
>>> -    VFIOAddressSpace *space;
>>> -
>>> -    QLIST_FOREACH(space, &vfio_address_spaces, list) {
>>> -        if (space->as == as) {
>>> -            return space;
>>> -        }
>>> -    }
>>> -
>>> -    /* No suitable VFIOAddressSpace, create a new one */
>>> -    space = g_malloc0(sizeof(*space));
>>> -    space->as = as;
>>> -    QLIST_INIT(&space->containers);
>>> -
>>> -    if (QLIST_EMPTY(&vfio_address_spaces)) {
>>> -        qemu_register_reset(vfio_reset_handler, NULL);
>>> -    }
>>> -
>>> -    QLIST_INSERT_HEAD(&vfio_address_spaces, space, list);
>>> -
>>> -    return space;
>>> -}
>>> -
>>> -void vfio_put_address_space(VFIOAddressSpace *space)
>>> -{
>>> -    if (!QLIST_EMPTY(&space->containers)) {
>>> -        return;
>>> -    }
>>> -
>>> -    QLIST_REMOVE(space, list);
>>> -    g_free(space);
>>> -
>>> -    if (QLIST_EMPTY(&vfio_address_spaces)) {
>>> -        qemu_unregister_reset(vfio_reset_handler, NULL);
>>> -    }
>>> -}
>>> -
>>> -void vfio_address_space_insert(VFIOAddressSpace *space,
>>> -                               VFIOContainerBase *bcontainer)
>>> -{
>>> -    QLIST_INSERT_HEAD(&space->containers, bcontainer, next);
>>> -    bcontainer->space = space;
>>> -}
>>> -
>>> struct vfio_device_info *vfio_get_device_info(int fd)
>>> {
>>>      struct vfio_device_info *info;
>>> diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
>>> index
>>>
>749a3fd29dd6fc9143f14edf7e4ac6238315fcce..83e83ab9e67de8b004dfaf0067e
>>> 4c466a6c88451 100644
>>> --- a/hw/vfio/container-base.c
>>> +++ b/hw/vfio/container-base.c
>>> @@ -13,7 +13,76 @@
>>> #include "qemu/osdep.h"
>>> #include "qapi/error.h"
>>> #include "qemu/error-report.h"
>>> +#include "system/reset.h"
>>> #include "hw/vfio/vfio-container-base.h"
>>> +#include "hw/vfio/vfio-common.h" /* for vfio_device_list */
>>> +#include "trace.h"
>>> +
>>> +static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
>>> +    QLIST_HEAD_INITIALIZER(vfio_address_spaces);
>>> +
>>> +static void vfio_reset_handler(void *opaque)
>>> +{
>>> +    VFIODevice *vbasedev;
>>> +
>>> +    trace_vfio_reset_handler();
>>> +    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>>> +        if (vbasedev->dev->realized) {
>>> +            vbasedev->ops->vfio_compute_needs_reset(vbasedev);
>>> +        }
>>> +    }
>>> +
>>> +    QLIST_FOREACH(vbasedev, &vfio_device_list, global_next) {
>>> +        if (vbasedev->dev->realized && vbasedev->needs_reset) {
>>> +            vbasedev->ops->vfio_hot_reset_multi(vbasedev);
>>> +        }
>>> +    }
>>> +}
>>
>> This is not an address space scoped function,
>
>yep.
>
>AIUI, pass-through devices of a VM are not necessarily in the same
>group and we need to scan all groups/address_spaces when the machine
>is reset.

Yes, before introducing vfio_device_list, we scan vfio_group_list.

>
>There use to be a long comment explaining the context but we lost it
>along the way. I will add it back :
>
>   /*
>    * We want to differentiate hot reset of mulitple in-use devices vs hot reset
>    * of a single in-use device.  VFIO_DEVICE_RESET will already handle the case
>    * of doing hot resets when there is only a single device per bus.  The in-use
>    * here refers to how many VFIODevices are affected.  A hot reset that affects
>    * multiple devices, but only a single in-use device, means that we can call
>    * it from our bus ->reset() callback since the extent is effectively a single
>    * device.  This allows us to make use of it in the hotplug path.  When there
>    * are multiple in-use devices, we can only trigger the hot reset during a
>    * system reset and thus from our reset handler.  We separate _one vs _multi
>    * here so that we don't overlap and do a double reset on the system reset
>    * path where both our reset handler and ->reset() callback are used.  Calling
>    * _one() will only do a hot reset for the one in-use devices case, calling
>    * _multi() will do nothing if a _one() would have been sufficient.
>    */
>
>See commit f16f39c3fc97 ("Implement PCI hot reset").
>
>> no sure if better to move to helper.c or common.c
>
>This is a machine scope "helper" calling VFIODevice handlers, may be in
>device.c  ?

Sounds good.

Thanks
Zhenzhong

^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services
  2025-03-20  9:40   ` John Levon
@ 2025-03-21  9:25     ` Cédric Le Goater
  2025-03-21 11:17       ` John Levon
  0 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-21  9:25 UTC (permalink / raw)
  To: John Levon
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On 3/20/25 10:40, John Levon wrote:
> On Tue, Mar 18, 2025 at 10:53:58AM +0100, Cédric Le Goater wrote:
> 
>> Gather all helper routine declarations into "helpers.h" to reduce
>> exposure of VFIO internals in "hw/vfio/vfio-common.h".
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> 
> Reviewed-by: John Levon <john.levon@nutanix.com>
> 
> but
> 
>> +struct vfio_info_cap_header *
>> +vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
> 
> This can be static in fact.

It is used by vfio_device_get_region_info_type() and
vfio_device_has_region_cap().


Thanks,

C.


> 
> regards
> john
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-20  9:46   ` John Levon
@ 2025-03-21  9:29     ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-21  9:29 UTC (permalink / raw)
  To: John Levon
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On 3/20/25 10:46, John Levon wrote:
> On Tue, Mar 18, 2025 at 10:54:07AM +0100, Cédric Le Goater wrote:
> 
>> File "common.c" has been emptied of most of its definitions by the
>> previous changes and the only definitions left are related to dirty
>> tracking. Rename it to "dirty-tracking.c" and introduce its associated
>> "dirty-tracking.h" header file for the declarations.
>>
>> Cleanup a little the includes while at it.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> 
>> rename from hw/vfio/common.c
>> rename to hw/vfio/dirty-tracking.c
>> index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/dirty-tracking.c
>> @@ -20,14 +20,10 @@
> 
> I think you might want to update the file comment from "generic functions used
> by VFIO devices".

Yes.

next respin will have to take a closer look at the top of the files:
comments, copyrights, includes.

Thanks,

C.

  




^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-20  9:52   ` Duan, Zhenzhong
  2025-03-20 11:00     ` Joao Martins
@ 2025-03-21  9:31     ` Cédric Le Goater
  2025-03-21  9:44       ` Duan, Zhenzhong
  1 sibling, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-21  9:31 UTC (permalink / raw)
  To: Duan, Zhenzhong, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger

On 3/20/25 10:52, Duan, Zhenzhong wrote:
> 
> 
>> -----Original Message-----
>> From: Cédric Le Goater <clg@redhat.com>
>> Subject: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking
>> definitions and declarations
>>
>> File "common.c" has been emptied of most of its definitions by the
>> previous changes and the only definitions left are related to dirty
>> tracking. Rename it to "dirty-tracking.c" and introduce its associated
>> "dirty-tracking.h" header file for the declarations.
>>
>> Cleanup a little the includes while at it.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>> hw/vfio/dirty-tracking.h               | 22 ++++++++++++++++++++++
>> include/hw/vfio/vfio-common.h          | 10 ----------
>> hw/vfio/container.c                    |  1 +
>> hw/vfio/{common.c => dirty-tracking.c} |  5 +----
>> hw/vfio/iommufd.c                      |  1 +
>> hw/vfio/meson.build                    |  2 +-
>> hw/vfio/trace-events                   |  2 +-
>> 7 files changed, 27 insertions(+), 16 deletions(-)
>> create mode 100644 hw/vfio/dirty-tracking.h
>> rename hw/vfio/{common.c => dirty-tracking.c} (99%)
>>
>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>> new file mode 100644
>> index
>> 0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3
>> db27b80bfe2d3a
>> --- /dev/null
>> +++ b/hw/vfio/dirty-tracking.h
>> @@ -0,0 +1,22 @@
>> +/*
>> + * VFIO dirty page tracking routines
>> + *
>> + * Copyright Red Hat, Inc. 2025
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +
>> +#ifndef HW_VFIO_DIRTY_TRACKING_H
>> +#define HW_VFIO_DIRTY_TRACKING_H
>> +
>> +extern const MemoryListener vfio_memory_listener;
>> +
>> +bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase
>> *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,
>> +                                    Error **errp);
>> +int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>> +                          uint64_t size, ram_addr_t ram_addr, Error **errp);
>> +
>> +#endif /* HW_VFIO_DIRTY_TRACKING_H */
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>> index
>> 184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878
>> d4d61818497426 100644
>> --- a/include/hw/vfio/vfio-common.h
>> +++ b/include/hw/vfio/vfio-common.h
>> @@ -130,7 +130,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj);
>>
>> typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
>> extern VFIODeviceList vfio_device_list;
>> -extern const MemoryListener vfio_memory_listener;
>>
>> #ifdef CONFIG_LINUX
>> int vfio_get_region_info(VFIODevice *vbasedev, int index,
>> @@ -140,15 +139,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev,
>> uint32_t type,
>> bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
>> #endif
>>
>> -bool vfio_devices_all_dirty_tracking_started(
>> -    const VFIOContainerBase *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, Error **errp);
>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t iova,
>> -                          uint64_t size, ram_addr_t ram_addr, Error **errp);
>> -
>> /* Returns 0 on success, or a negative errno. */
>> bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
>> void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>> index
>> 4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e
>> 46ab9c8b5019ae7 100644
>> --- a/hw/vfio/container.c
>> +++ b/hw/vfio/container.c
>> @@ -35,6 +35,7 @@
>> #include "hw/vfio/vfio-container.h"
>> #include "helpers.h"
>> #include "cpr.h"
>> +#include "dirty-tracking.h"
>>
>> #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO
>> TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
>>
>> diff --git a/hw/vfio/common.c b/hw/vfio/dirty-tracking.c
>> similarity index 99%
>> rename from hw/vfio/common.c
>> rename to hw/vfio/dirty-tracking.c
>> index
>> ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143d
>> cee5f0a89a900 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/dirty-tracking.c
>> @@ -20,14 +20,10 @@
>>
>> #include "qemu/osdep.h"
>> #include <sys/ioctl.h>
>> -#ifdef CONFIG_KVM
>> -#include <linux/kvm.h>
>> -#endif
> 
> It looks this change unrelated to this patch?
> 
>> #include <linux/vfio.h>
>>
>> #include "hw/vfio/vfio-common.h"
>> #include "hw/vfio/pci.h"
>> -#include "exec/address-spaces.h"
> 
> Same here.

yes and no. Commit log says :

   Cleanup a little the includes while at it.

but if you prefer we can address the include proliferation in a patch
of its own ?


Thanks,

C.




^ permalink raw reply	[flat|nested] 114+ messages in thread

* RE: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations
  2025-03-21  9:31     ` Cédric Le Goater
@ 2025-03-21  9:44       ` Duan, Zhenzhong
  0 siblings, 0 replies; 114+ messages in thread
From: Duan, Zhenzhong @ 2025-03-21  9:44 UTC (permalink / raw)
  To: Cédric Le Goater, qemu-devel@nongnu.org, Alex Williamson
  Cc: Avihai Horon, Eric Auger



>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking
>definitions and declarations
>
>On 3/20/25 10:52, Duan, Zhenzhong wrote:
>>
>>
>>> -----Original Message-----
>>> From: Cédric Le Goater <clg@redhat.com>
>>> Subject: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking
>>> definitions and declarations
>>>
>>> File "common.c" has been emptied of most of its definitions by the
>>> previous changes and the only definitions left are related to dirty
>>> tracking. Rename it to "dirty-tracking.c" and introduce its associated
>>> "dirty-tracking.h" header file for the declarations.
>>>
>>> Cleanup a little the includes while at it.
>>>
>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>> ---
>>> hw/vfio/dirty-tracking.h               | 22 ++++++++++++++++++++++
>>> include/hw/vfio/vfio-common.h          | 10 ----------
>>> hw/vfio/container.c                    |  1 +
>>> hw/vfio/{common.c => dirty-tracking.c} |  5 +----
>>> hw/vfio/iommufd.c                      |  1 +
>>> hw/vfio/meson.build                    |  2 +-
>>> hw/vfio/trace-events                   |  2 +-
>>> 7 files changed, 27 insertions(+), 16 deletions(-)
>>> create mode 100644 hw/vfio/dirty-tracking.h
>>> rename hw/vfio/{common.c => dirty-tracking.c} (99%)
>>>
>>> diff --git a/hw/vfio/dirty-tracking.h b/hw/vfio/dirty-tracking.h
>>> new file mode 100644
>>> index
>>>
>0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3
>>> db27b80bfe2d3a
>>> --- /dev/null
>>> +++ b/hw/vfio/dirty-tracking.h
>>> @@ -0,0 +1,22 @@
>>> +/*
>>> + * VFIO dirty page tracking routines
>>> + *
>>> + * Copyright Red Hat, Inc. 2025
>>> + *
>>> + * SPDX-License-Identifier: GPL-2.0-or-later
>>> + */
>>> +
>>> +#ifndef HW_VFIO_DIRTY_TRACKING_H
>>> +#define HW_VFIO_DIRTY_TRACKING_H
>>> +
>>> +extern const MemoryListener vfio_memory_listener;
>>> +
>>> +bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase
>>> *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,
>>> +                                    Error **errp);
>>> +int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t
>iova,
>>> +                          uint64_t size, ram_addr_t ram_addr, Error **errp);
>>> +
>>> +#endif /* HW_VFIO_DIRTY_TRACKING_H */
>>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
>>> index
>>>
>184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878
>>> d4d61818497426 100644
>>> --- a/include/hw/vfio/vfio-common.h
>>> +++ b/include/hw/vfio/vfio-common.h
>>> @@ -130,7 +130,6 @@ VFIODevice *vfio_get_vfio_device(Object *obj);
>>>
>>> typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
>>> extern VFIODeviceList vfio_device_list;
>>> -extern const MemoryListener vfio_memory_listener;
>>>
>>> #ifdef CONFIG_LINUX
>>> int vfio_get_region_info(VFIODevice *vbasedev, int index,
>>> @@ -140,15 +139,6 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev,
>>> uint32_t type,
>>> bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t
>cap_type);
>>> #endif
>>>
>>> -bool vfio_devices_all_dirty_tracking_started(
>>> -    const VFIOContainerBase *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, Error **errp);
>>> -int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t
>iova,
>>> -                          uint64_t size, ram_addr_t ram_addr, Error **errp);
>>> -
>>> /* Returns 0 on success, or a negative errno. */
>>> bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp);
>>> void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp);
>>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>>> index
>>>
>4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e
>>> 46ab9c8b5019ae7 100644
>>> --- a/hw/vfio/container.c
>>> +++ b/hw/vfio/container.c
>>> @@ -35,6 +35,7 @@
>>> #include "hw/vfio/vfio-container.h"
>>> #include "helpers.h"
>>> #include "cpr.h"
>>> +#include "dirty-tracking.h"
>>>
>>> #define TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO
>>> TYPE_HOST_IOMMU_DEVICE "-legacy-vfio"
>>>
>>> diff --git a/hw/vfio/common.c b/hw/vfio/dirty-tracking.c
>>> similarity index 99%
>>> rename from hw/vfio/common.c
>>> rename to hw/vfio/dirty-tracking.c
>>> index
>>>
>ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143d
>>> cee5f0a89a900 100644
>>> --- a/hw/vfio/common.c
>>> +++ b/hw/vfio/dirty-tracking.c
>>> @@ -20,14 +20,10 @@
>>>
>>> #include "qemu/osdep.h"
>>> #include <sys/ioctl.h>
>>> -#ifdef CONFIG_KVM
>>> -#include <linux/kvm.h>
>>> -#endif
>>
>> It looks this change unrelated to this patch?
>>
>>> #include <linux/vfio.h>
>>>
>>> #include "hw/vfio/vfio-common.h"
>>> #include "hw/vfio/pci.h"
>>> -#include "exec/address-spaces.h"
>>
>> Same here.
>
>yes and no. Commit log says :
>
>   Cleanup a little the includes while at it.
>
>but if you prefer we can address the include proliferation in a patch
>of its own ?

No need, this is fine already.
Previously I thought better to move into '[PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c',
but I'm wrong, it's just purely useless code.

Thanks
Zhenzhong

^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c
  2025-03-19 12:12   ` Prasad Pandit
@ 2025-03-21 10:19     ` Cédric Le Goater
  2025-03-24  4:40       ` Prasad Pandit
  0 siblings, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-21 10:19 UTC (permalink / raw)
  To: Prasad Pandit
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan


>> +void vfio_migration_set_error(int ret)
>> +{
>> +    if (migration_is_running()) {
>> +        migration_file_set_error(ret, NULL);
>> +    }
>> +}
>> --
> 
> * The change looks okay. But with the 'Error *err = NULL' parameter,
> the error (ret) is also not passed on. Could we call
> migration_file_set_error(ret, errp), instead of defining
> 'vfio_migration_set_error'? 

So you mean open coding :
  
     if (migration_is_running()) {
         migration_file_set_error(ret, errp);
     }

?

Yes. I think it is a good idea to limit proliferation of this wrapper.
Ideally, we wouldn't need to use migration_file_set_error() at all but
we still have some callback routines not taking an Error **parameter
unfortunately.

IOMMU notifiers :

   vfio_iommu_map_notify
   vfio_iommu_map_dirty_notify


MemoryListener handlers :

   vfio_listener_log_global_stop
   vfio_listener_log_sync


I will send a series removing vfio_migration_set_error() to improve
error reporting in the dirty tracking handlers. This makes sense,
thanks for reminding me.

C.





> Because currently it accepts only one
> 'ret' parameter, later adding *errp to it would entail changing all
> call sites.
> 
> Thank you.
> ---
>    - Prasad
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h
  2025-03-19 14:27   ` Avihai Horon
@ 2025-03-21 11:03     ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-21 11:03 UTC (permalink / raw)
  To: Avihai Horon, qemu-devel, Alex Williamson; +Cc: Eric Auger, Zhenzhong Duan

On 3/19/25 15:27, Avihai Horon wrote:
> 
> On 18/03/2025 11:54, Cédric Le Goater wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> "hw/vfio/vfio-common.h" has been emptied of most of its declarations
>> by the previous changes and the only declarations left are related to
>> VFIODevice. Rename it to "hw/vfio/vfio-device.h" and make the
>> necessary adjustments.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>> ---
>>   hw/vfio/migration-multifd.h                      | 2 +-
>>   hw/vfio/pci.h                                    | 2 +-
>>   include/hw/s390x/vfio-ccw.h                      | 2 +-
>>   include/hw/vfio/{vfio-common.h => vfio-device.h} | 0
>>   include/hw/vfio/vfio-platform.h                  | 2 +-
>>   backends/iommufd.c                               | 2 +-
>>   hw/vfio/ap.c                                     | 2 +-
>>   hw/vfio/ccw.c                                    | 2 +-
>>   hw/vfio/container-base.c                         | 2 +-
>>   hw/vfio/container.c                              | 2 +-
>>   hw/vfio/cpr.c                                    | 2 +-
>>   hw/vfio/device.c                                 | 2 +-
>>   hw/vfio/dirty-tracking.c                         | 2 +-
>>   hw/vfio/helpers.c                                | 2 +-
>>   hw/vfio/iommufd.c                                | 2 +-
>>   hw/vfio/migration-multifd.c                      | 2 +-
>>   hw/vfio/migration.c                              | 2 +-
>>   hw/vfio/region.c                                 | 4 ++--
>>   18 files changed, 18 insertions(+), 18 deletions(-)
>>   rename include/hw/vfio/{vfio-common.h => vfio-device.h} (100%)
>>
>> diff --git a/hw/vfio/migration-multifd.h b/hw/vfio/migration-multifd.h
>> index a664051eb8ae03bc41cb7f9362ace840f41066ff..0bab63211d30cef04c50e50b3ea57840915ffc2a 100644
>> --- a/hw/vfio/migration-multifd.h
>> +++ b/hw/vfio/migration-multifd.h
>> @@ -12,7 +12,7 @@
>>   #ifndef HW_VFIO_MIGRATION_MULTIFD_H
>>   #define HW_VFIO_MIGRATION_MULTIFD_H
>>
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>
>>   bool vfio_multifd_setup(VFIODevice *vbasedev, bool alloc_multifd, Error **errp);
>>   void vfio_multifd_cleanup(VFIODevice *vbasedev);
>> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
>> index c84bba81487136d205ca30049c812d00e832c377..d33237c275551897164878705d44e7881c372ab0 100644
>> --- a/hw/vfio/pci.h
>> +++ b/hw/vfio/pci.h
>> @@ -14,7 +14,7 @@
>>
>>   #include "exec/memory.h"
>>   #include "hw/pci/pci_device.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "qemu/event_notifier.h"
>>   #include "qemu/queue.h"
>>   #include "qemu/timer.h"
>> diff --git a/include/hw/s390x/vfio-ccw.h b/include/hw/s390x/vfio-ccw.h
>> index 4209d27657c1fbde44c160445396bcab3f3fd2b0..1e0922dca11e6caada08c2aae82bd3462ace35f5 100644
>> --- a/include/hw/s390x/vfio-ccw.h
>> +++ b/include/hw/s390x/vfio-ccw.h
>> @@ -14,7 +14,7 @@
>>   #ifndef HW_VFIO_CCW_H
>>   #define HW_VFIO_CCW_H
>>
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "hw/s390x/s390-ccw.h"
>>   #include "hw/s390x/ccw-device.h"
>>   #include "qom/object.h"
>> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-device.h
>> similarity index 100%
>> rename from include/hw/vfio/vfio-common.h
>> rename to include/hw/vfio/vfio-device.h
>> diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h
>> index 3191545717da51abc41d10cd3646cd047b4a676c..256d8500b70a2e985e975b0895e3cfca435ed8ed 100644
>> --- a/include/hw/vfio/vfio-platform.h
>> +++ b/include/hw/vfio/vfio-platform.h
>> @@ -17,7 +17,7 @@
>>   #define HW_VFIO_VFIO_PLATFORM_H
>>
>>   #include "hw/sysbus.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "qemu/event_notifier.h"
>>   #include "qemu/queue.h"
>>   #include "qom/object.h"
>> diff --git a/backends/iommufd.c b/backends/iommufd.c
>> index d57da44755be3d7fdba74f7dbecfe6d1c89921ba..9587e4d99b131e88674326a5196cfd2079560430 100644
>> --- a/backends/iommufd.c
>> +++ b/backends/iommufd.c
>> @@ -18,7 +18,7 @@
>>   #include "qemu/error-report.h"
>>   #include "monitor/monitor.h"
>>   #include "trace.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include <sys/ioctl.h>
>>   #include <linux/iommufd.h>
>>
>> diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
>> index c7ab4ff57ada0ed0e5a76f52b5a05c86ca4fe0b4..4fdb74e33c427595a9b0a4d28b2b5a70df951e4e 100644
>> --- a/hw/vfio/ap.c
>> +++ b/hw/vfio/ap.c
>> @@ -15,7 +15,7 @@
>>   #include <linux/vfio.h>
>>   #include <sys/ioctl.h>
>>   #include "qapi/error.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "system/iommufd.h"
>>   #include "hw/s390x/ap-device.h"
>>   #include "qemu/error-report.h"
>> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
>> index e5e0d9e3e7ed124f242b3eda345bc973e418a64c..a40169bc85e51406822247f5b3ef6da1f7f92881 100644
>> --- a/hw/vfio/ccw.c
>> +++ b/hw/vfio/ccw.c
>> @@ -21,7 +21,7 @@
>>   #include <sys/ioctl.h>
>>
>>   #include "qapi/error.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "system/iommufd.h"
>>   #include "hw/s390x/s390-ccw.h"
>>   #include "hw/s390x/vfio-ccw.h"
>> diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
>> index 83e83ab9e67de8b004dfaf0067e4c466a6c88451..ace9de18103e8c1ed9f7a51adbf16c36be01bd7c 100644
>> --- a/hw/vfio/container-base.c
>> +++ b/hw/vfio/container-base.c
>> @@ -15,7 +15,7 @@
>>   #include "qemu/error-report.h"
>>   #include "system/reset.h"
>>   #include "hw/vfio/vfio-container-base.h"
>> -#include "hw/vfio/vfio-common.h" /* for vfio_device_list */
>> +#include "hw/vfio/vfio-device.h" /* for vfio_device_list */
>>   #include "trace.h"
>>
>>   static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
>> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
>> index e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7..e300d2d90f2fbde329609b7c63245c523766fb60 100644
>> --- a/hw/vfio/container.c
>> +++ b/hw/vfio/container.c
>> @@ -22,7 +22,7 @@
>>   #include <sys/ioctl.h>
>>   #include <linux/vfio.h>
>>
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "exec/address-spaces.h"
>>   #include "exec/memory.h"
>>   #include "exec/ram_addr.h"
>> diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
>> index e1bba1726402f41ee394f25b6e613d27f44b2a2c..43b99680f6d7db27c4d7e518520aef5ade2ebcf4 100644
>> --- a/hw/vfio/cpr.c
>> +++ b/hw/vfio/cpr.c
>> @@ -6,7 +6,7 @@
>>    */
>>
>>   #include "qemu/osdep.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "migration/misc.h"
>>   #include "qapi/error.h"
>>   #include "system/runstate.h"
>> diff --git a/hw/vfio/device.c b/hw/vfio/device.c
>> index e6a1bbcda2297f9e6272fff9b1c228b6772457ce..0d443b53d23d392729cef84e419d3e089fe64298 100644
>> --- a/hw/vfio/device.c
>> +++ b/hw/vfio/device.c
>> @@ -22,7 +22,7 @@
>>   #include "qemu/osdep.h"
>>   #include <sys/ioctl.h>
>>
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "hw/vfio/pci.h"
>>   #include "hw/hw.h"
>>   #include "trace.h"
>> diff --git a/hw/vfio/dirty-tracking.c b/hw/vfio/dirty-tracking.c
>> index 447e09ed84993e3fbe1ed9b27a8269a9f0f46339..143cc5cf62b0165565e91f8a2ca166026f16b1eb 100644
>> --- a/hw/vfio/dirty-tracking.c
>> +++ b/hw/vfio/dirty-tracking.c
>> @@ -22,7 +22,7 @@
>>   #include <sys/ioctl.h>
>>   #include <linux/vfio.h>
>>
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "hw/vfio/pci.h"
>>   #include "exec/memory.h"
>>   #include "exec/ram_addr.h"
>> diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
>> index e99d312a9f5c7462644ea3d0de2e9de38979f851..b7907aab80f8adb308ebae60baa20c911d9393d7 100644
>> --- a/hw/vfio/helpers.c
>> +++ b/hw/vfio/helpers.c
>> @@ -23,7 +23,7 @@
>>   #include <sys/ioctl.h>
>>
>>   #include "system/kvm.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "hw/hw.h"
>>   #include "qapi/error.h"
>>   #include "helpers.h"
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index 9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8..7f354d86cd14270a70dc990860ad5b69f0310719 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -15,7 +15,7 @@
>>   #include <linux/vfio.h>
>>   #include <linux/iommufd.h>
>>
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "qemu/error-report.h"
>>   #include "trace.h"
>>   #include "qapi/error.h"
>> diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
>> index 285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db..1ba703e595db99f3786bfc1a2edeb0e061f9e01b 100644
>> --- a/hw/vfio/migration-multifd.c
>> +++ b/hw/vfio/migration-multifd.c
>> @@ -10,7 +10,7 @@
>>    */
>>
>>   #include "qemu/osdep.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "hw/vfio/vfio-migration.h"
>>   #include "migration/misc.h"
>>   #include "qapi/error.h"
>> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
>> index 6fd825e435bde96d1008ec03dfaba25db3b616fc..338fafb83f41460e0c244dcc27524198322eec67 100644
>> --- a/hw/vfio/migration.c
>> +++ b/hw/vfio/migration.c
>> @@ -16,7 +16,7 @@
>>   #include <sys/ioctl.h>
>>
>>   #include "system/runstate.h"
>> -#include "hw/vfio/vfio-common.h"
>> +#include "hw/vfio/vfio-device.h"
>>   #include "hw/vfio/vfio-migration.h"
>>   #include "migration/misc.h"
>>   #include "migration/savevm.h"
>> diff --git a/hw/vfio/region.c b/hw/vfio/region.c
>> index 87bf5e046a432dfedf3be3c1c7e8f33e006da004..ade4466eb622248b5aa50f9df7e5c683bfa78a11 100644
>> --- a/hw/vfio/region.c
>> +++ b/hw/vfio/region.c
>> @@ -22,8 +22,8 @@
>>   #include "qemu/osdep.h"
>>   #include <sys/ioctl.h>
>>
>> -#include "hw/vfio/vfio-common.h"
>> -#include "hw/vfio/pci.h"
>> +#include "hw/vfio/vfio-region.h"
> 
> Doesn't the above belong to patch #10?


maybe. I will check for v2.


Thanks,

C.


> Thanks.
> 
>> +#include "hw/vfio/vfio-device.h"
>>   #include "hw/hw.h"
>>   #include "trace.h"
>>   #include "qapi/error.h"
>> -- 
>> 2.48.1
>>
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services
  2025-03-21  9:25     ` Cédric Le Goater
@ 2025-03-21 11:17       ` John Levon
  0 siblings, 0 replies; 114+ messages in thread
From: John Levon @ 2025-03-21 11:17 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Fri, Mar 21, 2025 at 10:25:15AM +0100, Cédric Le Goater wrote:

> > > +struct vfio_info_cap_header *
> > > +vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
> > 
> > This can be static in fact.
> 
> It is used by vfio_device_get_region_info_type() and
> vfio_device_has_region_cap().

OK; I was being lazy and didn't check the source tree at this point.

thanks
john


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-19 12:21   ` Joao Martins
  2025-03-20 11:13     ` Avihai Horon
@ 2025-03-21 11:22     ` Cédric Le Goater
  2025-03-31 12:49       ` Joao Martins
  1 sibling, 1 reply; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-21 11:22 UTC (permalink / raw)
  To: Joao Martins
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 3/19/25 13:21, Joao Martins wrote:
> On 18/03/2025 09:54, Cédric Le Goater wrote:
>> Rename these routines :
>>
>>    vfio_devices_all_device_dirty_tracking_started -> vfio_dirty_tracking_devices_is_started_all
>>    vfio_devices_all_dirty_tracking_started        -> vfio_dirty_tracking_devices_is_started
>>    vfio_devices_all_device_dirty_tracking         -> vfio_dirty_tracking_devices_is_supported
>>    vfio_devices_dma_logging_start                 -> vfio_dirty_tracking_devices_dma_logging_start
>>    vfio_devices_dma_logging_stop                  -> vfio_dirty_tracking_devices_dma_logging_stop
>>    vfio_devices_query_dirty_bitmap                -> vfio_dirty_tracking_devices_query_dirty_bitmap
>>    vfio_get_dirty_bitmap                          -> vfio_dirty_tracking_query_dirty_bitmap
>>
>> to better reflect the namespace they belong to.
>>
>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> 
> The change itself is fine.
> 
> But on the other hand, it looks relatively long names, no? 

I agree.

> I am bit at two minds
> (as I generally prefer shorter code), but I can't find any alternatives if you
> really wanna have one namespaces associated with the subsystem:file as a C
> namespace.
> 
> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
> when talking about this stuff, but it seems a detour from the code style to
> abbreviate namespaces into acronyms.

I am ok to use a TLA for Dirty Page Tracking. Would DPT statisfy everyone ?

> 
> Having said that:
> 
> 	Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
> 
> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
> shorter.

Could you please send your proposal as a list, like the commit log does
and let's discuss.


Thanks,

C.





^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c
  2025-03-21 10:19     ` Cédric Le Goater
@ 2025-03-24  4:40       ` Prasad Pandit
  0 siblings, 0 replies; 114+ messages in thread
From: Prasad Pandit @ 2025-03-24  4:40 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: qemu-devel, Alex Williamson, Avihai Horon, Eric Auger,
	Zhenzhong Duan

On Fri, 21 Mar 2025 at 15:49, Cédric Le Goater <clg@redhat.com> wrote:
> So you mean open coding :
>      if (migration_is_running()) {
>          migration_file_set_error(ret, errp);
>      }
> ?

* Yes.

> Yes. I think it is a good idea to limit proliferation of this wrapper.
> Ideally, we wouldn't need to use migration_file_set_error() at all but
> we still have some callback routines not taking an Error **parameter
> unfortunately.
>
> IOMMU notifiers :
>
>    vfio_iommu_map_notify
>    vfio_iommu_map_dirty_notify
>
> MemoryListener handlers :
>
>    vfio_listener_log_global_stop
>    vfio_listener_log_sync
>
> I will send a series removing vfio_migration_set_error() to improve
> error reporting in the dirty tracking handlers. This makes sense,
> thanks for reminding me.

Thank you.
---
  - Prasad



^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-21 11:22     ` Cédric Le Goater
@ 2025-03-31 12:49       ` Joao Martins
  2025-03-31 13:14         ` Cédric Le Goater
  0 siblings, 1 reply; 114+ messages in thread
From: Joao Martins @ 2025-03-31 12:49 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 21/03/2025 11:22, Cédric Le Goater wrote:
> On 3/19/25 13:21, Joao Martins wrote:
>> On 18/03/2025 09:54, Cédric Le Goater wrote:
>>> Rename these routines :
>>>
>>>    vfio_devices_all_device_dirty_tracking_started ->
>>> vfio_dirty_tracking_devices_is_started_all
>>>    vfio_devices_all_dirty_tracking_started        ->
>>> vfio_dirty_tracking_devices_is_started
>>>    vfio_devices_all_device_dirty_tracking         ->
>>> vfio_dirty_tracking_devices_is_supported
>>>    vfio_devices_dma_logging_start                 ->
>>> vfio_dirty_tracking_devices_dma_logging_start
>>>    vfio_devices_dma_logging_stop                  ->
>>> vfio_dirty_tracking_devices_dma_logging_stop
>>>    vfio_devices_query_dirty_bitmap                ->
>>> vfio_dirty_tracking_devices_query_dirty_bitmap
>>>    vfio_get_dirty_bitmap                          ->
>>> vfio_dirty_tracking_query_dirty_bitmap
>>>
>>> to better reflect the namespace they belong to.
>>>
>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>
>> The change itself is fine.
>>
>> But on the other hand, it looks relatively long names, no? 
> 
> I agree.
> 
>> I am bit at two minds
>> (as I generally prefer shorter code), but I can't find any alternatives if you
>> really wanna have one namespaces associated with the subsystem:file as a C
>> namespace.
>>
>> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
>> when talking about this stuff, but it seems a detour from the code style to
>> abbreviate namespaces into acronyms.
> 
> I am ok to use a TLA for Dirty Page Tracking. Would DPT statisfy everyone ?
> 

It would, but the new version looks shorter so maybe we don't need to go against
style with TLAs.

>>
>> Having said that:
>>
>>     Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
>>
>> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
>> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
>> shorter.
> 
> Could you please send your proposal as a list, like the commit log does
> and let's discuss.

The idea was :

vfio_dirty_tracking_devices_dma_logging_start ->
	vfio_container_dma_logging_start
vfio_dirty_tracking_devices_dma_logging_stop ->
	vfio_container_dma_logging_stop

But honestly, doesn't make that much of the difference.

I'll have a look at your v2 hopefully tomorrow or Wednesday on the device dirty
tracking parts and iommufd dirty tracking.


^ permalink raw reply	[flat|nested] 114+ messages in thread

* Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services
  2025-03-31 12:49       ` Joao Martins
@ 2025-03-31 13:14         ` Cédric Le Goater
  0 siblings, 0 replies; 114+ messages in thread
From: Cédric Le Goater @ 2025-03-31 13:14 UTC (permalink / raw)
  To: Joao Martins
  Cc: Avihai Horon, Eric Auger, Zhenzhong Duan, qemu-devel,
	Alex Williamson

On 3/31/25 14:49, Joao Martins wrote:
> On 21/03/2025 11:22, Cédric Le Goater wrote:
>> On 3/19/25 13:21, Joao Martins wrote:
>>> On 18/03/2025 09:54, Cédric Le Goater wrote:
>>>> Rename these routines :
>>>>
>>>>     vfio_devices_all_device_dirty_tracking_started ->
>>>> vfio_dirty_tracking_devices_is_started_all
>>>>     vfio_devices_all_dirty_tracking_started        ->
>>>> vfio_dirty_tracking_devices_is_started
>>>>     vfio_devices_all_device_dirty_tracking         ->
>>>> vfio_dirty_tracking_devices_is_supported
>>>>     vfio_devices_dma_logging_start                 ->
>>>> vfio_dirty_tracking_devices_dma_logging_start
>>>>     vfio_devices_dma_logging_stop                  ->
>>>> vfio_dirty_tracking_devices_dma_logging_stop
>>>>     vfio_devices_query_dirty_bitmap                ->
>>>> vfio_dirty_tracking_devices_query_dirty_bitmap
>>>>     vfio_get_dirty_bitmap                          ->
>>>> vfio_dirty_tracking_query_dirty_bitmap
>>>>
>>>> to better reflect the namespace they belong to.
>>>>
>>>> Signed-off-by: Cédric Le Goater <clg@redhat.com>
>>>
>>> The change itself is fine.
>>>
>>> But on the other hand, it looks relatively long names, no?
>>
>> I agree.
>>
>>> I am bit at two minds
>>> (as I generally prefer shorter code), but I can't find any alternatives if you
>>> really wanna have one namespaces associated with the subsystem:file as a C
>>> namespace.
>>>
>>> Every once and a while me and Avihai use the acronym DPT (Dirty Page Tracking)
>>> when talking about this stuff, but it seems a detour from the code style to
>>> abbreviate namespaces into acronyms.
>>
>> I am ok to use a TLA for Dirty Page Tracking. Would DPT statisfy everyone ?
>>
> 
> It would, but the new version looks shorter so maybe we don't need to go against
> style with TLAs.
> 
>>>
>>> Having said that:
>>>
>>>      Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
>>>
>>> P.S. We could also remove 'devices' as the prefix for VF dirty tracking after
>>> namespace, and thus drop 'dma logging'. That should put 'start/stop' a little
>>> shorter.
>>
>> Could you please send your proposal as a list, like the commit log does
>> and let's discuss.
> 
> The idea was :
> 
> vfio_dirty_tracking_devices_dma_logging_start ->
> 	vfio_container_dma_logging_start
> vfio_dirty_tracking_devices_dma_logging_stop ->
> 	vfio_container_dma_logging_stop
> 
> But honestly, doesn't make that much of the difference.
> 
> I'll have a look at your v2 hopefully tomorrow or Wednesday on the device dirty
> tracking parts and iommufd dirty tracking.


Thanks, there should be progress in v2.

Patch 1~25 should be ready for vfio-next. I can just apply them and
we can continue working on the final part. Feel free to propose changes.

C.

  
> 



^ permalink raw reply	[flat|nested] 114+ messages in thread

end of thread, other threads:[~2025-03-31 13:15 UTC | newest]

Thread overview: 114+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-18  9:53 [PATCH for-10.1 00/32] vfio: Spring cleanup Cédric Le Goater
2025-03-18  9:53 ` [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c Cédric Le Goater
2025-03-19  9:10   ` John Levon
2025-03-19 11:54   ` Avihai Horon
2025-03-19 16:38     ` Cédric Le Goater
2025-03-18  9:53 ` [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred() Cédric Le Goater
2025-03-19  7:33   ` Philippe Mathieu-Daudé
2025-03-19  9:10   ` John Levon
2025-03-19 12:07   ` Avihai Horon
2025-03-18  9:53 ` [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services Cédric Le Goater
2025-03-19 11:48   ` Prasad Pandit
2025-03-19 12:37   ` Avihai Horon
2025-03-19 16:49     ` Cédric Le Goater
2025-03-18  9:53 ` [PATCH for-10.1 04/32] vfio: Make vfio_un/block_multiple_devices_migration() static Cédric Le Goater
2025-03-19 12:38   ` Joao Martins
2025-03-18  9:53 ` [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static Cédric Le Goater
2025-03-19 12:26   ` Joao Martins
2025-03-19 16:50   ` John Levon
2025-03-18  9:53 ` [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services Cédric Le Goater
2025-03-19 12:29   ` Prasad Pandit
2025-03-19 17:26     ` Cédric Le Goater
2025-03-20  6:19       ` Prasad Pandit
2025-03-19 14:05   ` Avihai Horon
2025-03-19 17:33     ` Cédric Le Goater
2025-03-19 16:55   ` John Levon
2025-03-18  9:53 ` [PATCH for-10.1 07/32] vfio: Introduce a new header file for VFIOdisplay declarations Cédric Le Goater
2025-03-20  9:50   ` John Levon
2025-03-18  9:53 ` [PATCH for-10.1 08/32] vfio: Move VFIOHostDMAWindow definition into spapr.c Cédric Le Goater
2025-03-20  9:43   ` John Levon
2025-03-18  9:53 ` [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations Cédric Le Goater
2025-03-19  9:09   ` John Levon
2025-03-20  9:18   ` Duan, Zhenzhong
2025-03-20 13:37     ` Cédric Le Goater
2025-03-18  9:53 ` [PATCH for-10.1 10/32] vfio: Introduce new files for VFIORegion definitions and declarations Cédric Le Goater
2025-03-19 16:54   ` John Levon
2025-03-18  9:53 ` [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations Cédric Le Goater
2025-03-19 17:00   ` John Levon
2025-03-20  9:24   ` Duan, Zhenzhong
2025-03-18  9:53 ` [PATCH for-10.1 12/32] vfio: Make vfio_group_list static Cédric Le Goater
2025-03-20  9:28   ` Duan, Zhenzhong
2025-03-20  9:38   ` John Levon
2025-03-18  9:53 ` [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c Cédric Le Goater
2025-03-19 16:45   ` John Levon
2025-03-20  9:36   ` Duan, Zhenzhong
2025-03-20 19:26     ` Cédric Le Goater
2025-03-21  7:18       ` Duan, Zhenzhong
2025-03-18  9:53 ` [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files Cédric Le Goater
2025-03-19  9:10   ` John Levon
2025-03-20  9:36   ` Duan, Zhenzhong
2025-03-18  9:53 ` [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services Cédric Le Goater
2025-03-20  9:40   ` John Levon
2025-03-21  9:25     ` Cédric Le Goater
2025-03-21 11:17       ` John Levon
2025-03-18  9:53 ` [PATCH for-10.1 16/32] vfio: Move vfio_get_info_dma_avail() into helpers.c Cédric Le Goater
2025-03-19 16:50   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c Cédric Le Goater
2025-03-19 16:46   ` John Levon
2025-03-20  9:40   ` Duan, Zhenzhong
2025-03-18  9:54 ` [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() " Cédric Le Goater
2025-03-20  9:41   ` John Levon
2025-03-20  9:42   ` Duan, Zhenzhong
2025-03-18  9:54 ` [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions Cédric Le Goater
2025-03-19 16:42   ` John Levon
2025-03-20  9:01     ` Cédric Le Goater
2025-03-18  9:54 ` [PATCH for-10.1 20/32] vfio: Introduce new files for CPR definitions and declarations Cédric Le Goater
2025-03-19 17:01   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 21/32] vfio: Move vfio_kvm_device_fd() into helpers.c Cédric Le Goater
2025-03-20  9:44   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 22/32] vfio: Move vfio_device_list into device.c Cédric Le Goater
2025-03-20  9:29   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 23/32] vfio: Move vfio_de/attach_device() " Cédric Le Goater
2025-03-19 16:58   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations Cédric Le Goater
2025-03-19 13:23   ` Joao Martins
2025-03-20  9:46   ` John Levon
2025-03-21  9:29     ` Cédric Le Goater
2025-03-20  9:52   ` Duan, Zhenzhong
2025-03-20 11:00     ` Joao Martins
2025-03-21  6:24       ` Duan, Zhenzhong
2025-03-21  9:31     ` Cédric Le Goater
2025-03-21  9:44       ` Duan, Zhenzhong
2025-03-18  9:54 ` [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c Cédric Le Goater
2025-03-19 12:12   ` Prasad Pandit
2025-03-21 10:19     ` Cédric Le Goater
2025-03-24  4:40       ` Prasad Pandit
2025-03-19 17:00   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h Cédric Le Goater
2025-03-19 14:27   ` Avihai Horon
2025-03-21 11:03     ` Cédric Le Goater
2025-03-19 16:56   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 27/32] vfio: Rename VFIODevice related services Cédric Le Goater
2025-03-20  9:35   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static Cédric Le Goater
2025-03-19 12:14   ` Joao Martins
2025-03-19 16:54   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 29/32] vfio: Rename VFIOContainer related services Cédric Le Goater
2025-03-20  9:38   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services Cédric Le Goater
2025-03-19 12:21   ` Joao Martins
2025-03-20 11:13     ` Avihai Horon
2025-03-20 11:18       ` Joao Martins
2025-03-20 11:45         ` Avihai Horon
2025-03-20 11:56           ` Joao Martins
2025-03-20 12:24             ` Avihai Horon
2025-03-21 11:22     ` Cédric Le Goater
2025-03-31 12:49       ` Joao Martins
2025-03-31 13:14         ` Cédric Le Goater
2025-03-20  9:42   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines Cédric Le Goater
2025-03-19 13:24   ` Joao Martins
2025-03-20 12:28     ` Joao Martins
2025-03-20  9:49   ` John Levon
2025-03-18  9:54 ` [PATCH for-10.1 32/32] vfio: Rename RAM discard related services Cédric Le Goater
2025-03-19 16:57   ` John Levon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).