Skip to contentSkip to conversation

vfio: Spring cleanup

PATCH Superseded Cédric Le Goater 7 participants 114 messages Mar 18, 2025 – Mar 31, 2025 Arm/Amlogic Meson SoC support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover vfio: Spring cleanup

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
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/32 vfio: Move vfio_mig_active() into migration.c

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

---
 hw/vfio/common.c    | 16 ----------------
 hw/vfio/migration.c | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)
hw/vfio/common.c +0 -16
index 1a0d9290f88c9774a98f65087a36b86922b21a73..4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f 100644
@@ -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;
 
 /*
hw/vfio/migration.c +16 -0
index fbff46cfc35e0ee69e9599c9f8efc7437bbe3370..b5fb0d218808d010d8210612d3182dde8f33514b 100644
@@ -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
Signature · 1 line
2.48.1
Reviewed-by on v1 1/32
#3 lore raw

Re: [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c

In reply to Cédric Le Goater
Quoted 7 lines · Cédric Le Goater

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.

One nit below though.

Quoted 37 lines
---
  hw/vfio/common.c    | 16 ----------------
  hw/vfio/migration.c | 16 ++++++++++++++++
  2 files changed, 16 insertions(+), 16 deletions(-)
hw/vfio/common.c +0 -16
index 1a0d9290f88c9774a98f65087a36b86922b21a73..4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f 100644
@@ -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;
 
  /*
hw/vfio/migration.c +0 -0
index fbff46cfc35e0ee69e9599c9f8efc7437bbe3370..b5fb0d218808d010d8210612d3182dde8f33514b 100644

hw/vfio/migration.c void vfio_mig_add_bytes_transferred(unsigned long val) · line 1065

Quoted 4 lines
hw/vfio/migration.c +1 -0
@@ -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.

Quoted 21 lines
hw/vfio/migration.c +15 -1
+{
+    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

#4 lore raw

Re: [PATCH for-10.1 01/32] vfio: Move vfio_mig_active() into migration.c

Quoted 54 lines · Avihai Horon
Quoted 7 lines · Cédric Le Goater

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.

One nit below though.

Quoted 40 lines

---
  hw/vfio/common.c    | 16 ----------------
  hw/vfio/migration.c | 16 ++++++++++++++++

  2 files changed, 16 insertions(+), 16 deletions(-)
hw/vfio/common.c +0 -16
index 1a0d9290f88c9774a98f65087a36b86922b21a73..4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f 100644
@@ -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;
 
   /*
hw/vfio/migration.c +0 -0
index fbff46cfc35e0ee69e9599c9f8efc7437bbe3370..b5fb0d218808d010d8210612d3182dde8f33514b 100644
@@ -1062,6 +1062,22 @@ void vfio_mig_add_bytes_transferred(unsigned long val)
       qatomic_add(&bytes_transferred, val);
   }
 
Quoted 4 lines

hw/vfio/migration.c void vfio_mig_add_bytes_transferred(unsigned long val) · line 1065

Quoted 1 line
hw/vfio/migration.c +1 -0
+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.

Quoted 25 lines

Thanks.

Quoted 21 lines
hw/vfio/migration.c +15 -0
+{
+    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
Signature · 1 line
2.48.1
#5 lore raw

PATCH 2/32 vfio: Rename vfio_reset_bytes_transferred()

In reply to Cédric Le Goater

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

---
 include/hw/vfio/vfio-common.h | 2 +-
 hw/vfio/migration.c           | 2 +-
 migration/target.c            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/hw/vfio/vfio-common.h +1 -1
index 04b123a6c929a8f47d740fc5433b54dadd32f731..9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc 100644
@@ -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);
hw/vfio/migration.c +1 -1
index b5fb0d218808d010d8210612d3182dde8f33514b..8bf65b8e11094b8363692dba3084b762362c7dd6 100644
@@ -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);
 }
migration/target.c +1 -1
index a6ffa9a5ce312d1e64157b650827aa726eb4d364..f5d8cfe7c2a3473f4bd3f5068145598c60973c58 100644
@@ -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)
Signature · 1 line
2.48.1
Reviewed-by on v1 2/32
#6 lore raw

Re: [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred()

Quoted 9 lines · Cédric Le Goater

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

---
  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 on v1 2/32
#8 lore raw

Re: [PATCH for-10.1 02/32] vfio: Rename vfio_reset_bytes_transferred()

In reply to Cédric Le Goater
Quoted 7 lines · Cédric Le Goater

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.

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

Thanks.

Quoted 48 lines
---
  include/hw/vfio/vfio-common.h | 2 +-
  hw/vfio/migration.c           | 2 +-
  migration/target.c            | 2 +-
  3 files changed, 3 insertions(+), 3 deletions(-)
include/hw/vfio/vfio-common.h +1 -1
index 04b123a6c929a8f47d740fc5433b54dadd32f731..9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc 100644
@@ -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);
hw/vfio/migration.c +1 -1
index b5fb0d218808d010d8210612d3182dde8f33514b..8bf65b8e11094b8363692dba3084b762362c7dd6 100644
@@ -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);
  }
migration/target.c +1 -2
index a6ffa9a5ce312d1e64157b650827aa726eb4d364..f5d8cfe7c2a3473f4bd3f5068145598c60973c58 100644
@@ -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

#9 lore raw

PATCH 3/32 vfio: Introduce a new header file for external migration services

In reply to 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.

---
 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
include/hw/vfio/vfio-common.h +0 -4
index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
@@ -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);
 
include/hw/vfio/vfio-migration.h new file +17 -0
new file mode 100644
index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
@@ -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 */
hw/vfio/migration-multifd.c +1 -0
index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
@@ -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"
hw/vfio/migration.c +1 -0
index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
@@ -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"
migration/target.c +1 -1
index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
@@ -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
Signature · 1 line
2.48.1
#10 lore raw

Re: [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services

Quoted 1 line · Cédric Le Goater

The migration core subsytem makes uses of the VFIO migration API to

* subsytem -> subsystem
* uses -> use

Quoted 1 line

collect statistics on the number of bytes transferred.

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

Quoted 94 lines

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.

---
 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
include/hw/vfio/vfio-common.h +0 -4
index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
@@ -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);
 
include/hw/vfio/vfio-migration.h new file +17 -0
new file mode 100644
index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
@@ -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 */
hw/vfio/migration-multifd.c +1 -0
index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
@@ -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"
hw/vfio/migration.c +1 -0
index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
@@ -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"
migration/target.c +1 -2
index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
@@ -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
--
Quoted 1 line

2.48.1

* Looks okay. With above text corrections, reviewed by: Prasad Pandit <[email protected]>

Thank you.
---
- Prasad

#11 lore raw

Re: [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services

In reply to Cédric Le Goater
Quoted 49 lines · Cédric Le Goater

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.

---
  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

include/hw/vfio/vfio-common.h +0 -4
index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
@@ -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);
 
include/hw/vfio/vfio-migration.h new file +5 -0
new file mode 100644
index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
@@ -0,0 +1,17 @@
+/*
+ * VFIO migration interface
+ *
+ * Copyright Red Hat, Inc. 2025
+ *

include/hw/vfio/vfio-migration.h line 15

Quoted 10 lines
include/hw/vfio/vfio-migration.h new file +10 -0
+ * 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.

Quoted 42 lines
include/hw/vfio/vfio-migration.h new file +2 -0
+
+#endif /* HW_VFIO_VFIO_MIGRATION_H */
hw/vfio/migration-multifd.c +1 -0
index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
@@ -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"
hw/vfio/migration.c +1 -0
index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
@@ -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"
migration/target.c +1 -2
index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
@@ -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

#12 lore raw

Re: [PATCH for-10.1 03/32] vfio: Introduce a new header file for external migration services

Quoted 55 lines · Avihai Horon
Quoted 53 lines · Cédric Le Goater

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.

---
  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

include/hw/vfio/vfio-common.h +0 -4
index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..5fc7ee76573375bc8464baee29ab88974fac3d3b 100644
@@ -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);
 
include/hw/vfio/vfio-migration.h new file +9 -0
new file mode 100644
index 0000000000000000000000000000000000000000..259c532f64bdd002d512375df3140f291a0ade85
@@ -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
Quoted 8 lines

include/hw/vfio/vfio-migration.h line 15

Quoted 6 lines
include/hw/vfio/vfio-migration.h new file +6 -0
+#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.

Quoted 46 lines

Thanks.

Quoted 42 lines
include/hw/vfio/vfio-migration.h new file +2 -0
+
+#endif /* HW_VFIO_VFIO_MIGRATION_H */
hw/vfio/migration-multifd.c +1 -0
index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..fe84735ec2c7bd085820d25c06be558761fbe0d5 100644
@@ -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"
hw/vfio/migration.c +1 -0
index 8bf65b8e11094b8363692dba3084b762362c7dd6..75096377ffecf62b3bab91102a00d723827ea4c7 100644
@@ -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"
migration/target.c +1 -1
index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..e1eacd1db7a471cba51b4e257a834eb7581f9671 100644
@@ -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
Signature · 1 line
2.48.1
#13 lore raw

PATCH 4/32 vfio: Make vfio_un/block_multiple_devices_migration() static

In reply to Cédric Le Goater

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

---
 include/hw/vfio/vfio-common.h |  2 --
 hw/vfio/common.c              | 62 -----------------------------------
 hw/vfio/migration.c           | 62 +++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 64 deletions(-)
include/hw/vfio/vfio-common.h +0 -2
index 5fc7ee76573375bc8464baee29ab88974fac3d3b..5f082e5a321d97e90066d48cd3c1eaad56912ccb 100644
@@ -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);
hw/vfio/common.c +0 -62

74 lines not on this page · raw message

hw/vfio/migration.c +62 -0

68 lines not on this page · raw message

Signature · 1 line
2.48.1
Reviewed-by on v1 4/32
#14 lore raw

Re: [PATCH for-10.1 04/32] vfio: Make vfio_un/block_multiple_devices_migration() static

Quoted 4 lines · Cédric Le Goater

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

Quoted 172 lines
---
 include/hw/vfio/vfio-common.h |  2 --
 hw/vfio/common.c              | 62 -----------------------------------
 hw/vfio/migration.c           | 62 +++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 64 deletions(-)
include/hw/vfio/vfio-common.h +0 -2
index 5fc7ee76573375bc8464baee29ab88974fac3d3b..5f082e5a321d97e90066d48cd3c1eaad56912ccb 100644
@@ -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);
hw/vfio/common.c +0 -62
index 4205f4f7ec87e1a2a5e4110eabc8fde835d39c7f..ace7a4403bd49f35cf85009015b3ba315f80cd30 100644
@@ -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)
 {
hw/vfio/migration.c +62 -0
index 75096377ffecf62b3bab91102a00d723827ea4c7..951e073a20287c46ca199b1648782b59415d0d2a 100644
@@ -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;
#15 lore raw

PATCH 5/32 vfio: Make vfio_viommu_preset() static

In reply to Cédric Le Goater

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

---
 include/hw/vfio/vfio-common.h | 1 -
 hw/vfio/common.c              | 6 ------
 hw/vfio/migration.c           | 5 +++++
 3 files changed, 5 insertions(+), 7 deletions(-)
include/hw/vfio/vfio-common.h +0 -1
index 5f082e5a321d97e90066d48cd3c1eaad56912ccb..0aae88131cffda1a90b8ccd0224387133c0fa83a 100644
@@ -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);
 
hw/vfio/common.c +0 -6
index ace7a4403bd49f35cf85009015b3ba315f80cd30..0b9b071cd0490867bb6aa4ceb261350ccd6e1125 100644
@@ -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()) {
hw/vfio/migration.c +5 -0
index 951e073a20287c46ca199b1648782b59415d0d2a..a1ba993ce549fce0d2a9a60ba07d4782c87c0c09 100644
@@ -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
Signature · 1 line
2.48.1
Reviewed-by on v1 5/32
#16 lore raw

Re: [PATCH for-10.1 05/32] vfio: Make vfio_viommu_preset() static

Quoted 3 lines · Cédric Le Goater

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

Quoted 51 lines
---
 include/hw/vfio/vfio-common.h | 1 -
 hw/vfio/common.c              | 6 ------
 hw/vfio/migration.c           | 5 +++++
 3 files changed, 5 insertions(+), 7 deletions(-)
include/hw/vfio/vfio-common.h +0 -1
index 5f082e5a321d97e90066d48cd3c1eaad56912ccb..0aae88131cffda1a90b8ccd0224387133c0fa83a 100644
@@ -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);
 
hw/vfio/common.c +0 -6
index ace7a4403bd49f35cf85009015b3ba315f80cd30..0b9b071cd0490867bb6aa4ceb261350ccd6e1125 100644
@@ -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()) {
hw/vfio/migration.c +5 -0
index 951e073a20287c46ca199b1648782b59415d0d2a..a1ba993ce549fce0d2a9a60ba07d4782c87c0c09 100644
@@ -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
#18 lore raw

PATCH 6/32 vfio: Introduce a new header file for internal migration services

In reply to 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".

---
 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
hw/vfio/migration.h new file +72 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
@@ -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 */
include/hw/vfio/vfio-common.h +1 -53

92 lines not on this page · raw message

hw/vfio/common.c +1 -16
index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
@@ -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)
 {
hw/vfio/iommufd.c +1 -0
index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644
@@ -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)
hw/vfio/migration-multifd.c +1 -0
index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
@@ -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)
hw/vfio/migration.c +17 -0
index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
@@ -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;
+}
hw/vfio/pci.c +1 -0
index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644
@@ -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"
 
Signature · 1 line
2.48.1
#19 lore raw

Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services

Quoted 291 lines · 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".

---
 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
hw/vfio/migration.h new file +72 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
@@ -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 */
include/hw/vfio/vfio-common.h +1 -53
index 0aae88131cffda1a90b8ccd0224387133c0fa83a..799e12d43747addbf444c15052f629b65978322f 100644
@@ -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);
hw/vfio/common.c +1 -16
index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
@@ -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)
 {
hw/vfio/iommufd.c +1 -0
index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644
@@ -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)
hw/vfio/migration-multifd.c +1 -0
index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
@@ -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)
hw/vfio/migration.c +17 -0
index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
@@ -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;
+}
hw/vfio/pci.c +0 -0
index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644

hw/vfio/pci.c line 50

Quoted 7 lines
hw/vfio/pci.c +1 -0
@@ -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 <[email protected]>

Thank you.
---
- Prasad

#20 lore raw

Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services

[ .. ]

Quoted 5 lines

* 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.

#21 lore raw

Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services

Quoted 12 lines · Cédric Le Goater

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 :

Quoted 8 lines
   ./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.

Quoted 6 lines

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

Reviewed-by on v1 6/32
#22 lore raw

Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services

In reply to Cédric Le Goater
Quoted 5 lines · Cédric Le Goater

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".

Two nits below.

Quoted 66 lines
---
  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

hw/vfio/migration.h new file +47 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
@@ -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;

hw/vfio/migration.h line 57

Quoted 10 lines
hw/vfio/migration.h new file +10 -0
+    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.

Quoted 157 lines
hw/vfio/migration.h new file +15 -0
+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 */
include/hw/vfio/vfio-common.h +1 -53
index 0aae88131cffda1a90b8ccd0224387133c0fa83a..799e12d43747addbf444c15052f629b65978322f 100644
@@ -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);
hw/vfio/common.c +1 -16
index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
@@ -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)
  {
hw/vfio/iommufd.c +0 -0
index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644

hw/vfio/iommufd.c line 28

Quoted 4 lines
hw/vfio/iommufd.c +1 -0
@@ -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.

Quoted 62 lines
hw/vfio/iommufd.c +0 -0
  static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                              ram_addr_t size, void *vaddr, bool readonly)
hw/vfio/migration-multifd.c +1 -0
index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
@@ -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)
hw/vfio/migration.c +17 -0
index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
@@ -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;
+}
hw/vfio/pci.c +1 -1
index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644
@@ -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

#23 lore raw

Re: [PATCH for-10.1 06/32] vfio: Introduce a new header file for internal migration services

Quoted 11 lines · Avihai Horon
Quoted 5 lines · Cédric Le Goater

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".

Two nits below.

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

Quoted 235 lines
Quoted 67 lines

---
  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

hw/vfio/migration.h new file +47 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7ad2141d06a7c97f034db908f9ce19fd06f415b9
@@ -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;

hw/vfio/migration.h line 57

Quoted 10 lines
hw/vfio/migration.h new file +10 -0
+    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.

Quoted 155 lines
hw/vfio/migration.h new file +15 -0
+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 */
include/hw/vfio/vfio-common.h +0 -18
index 0aae88131cffda1a90b8ccd0224387133c0fa83a..799e12d43747addbf444c15052f629b65978322f 100644
@@ -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;

include/hw/vfio/vfio-common.h +0 -21
-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 {

include/hw/vfio/vfio-common.h +1 -6
@@ -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);

include/hw/vfio/vfio-common.h +0 -5
-
-int vfio_migration_set_state(VFIODevice *vbasedev,
-                             enum vfio_device_mig_state new_state,
-                             enum vfio_device_mig_state recover_state,
-                             Error **errp);

  #endif

include/hw/vfio/vfio-common.h +0 -3
-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);

hw/vfio/common.c +1 -0
index 0b9b071cd0490867bb6aa4ceb261350ccd6e1125..0e3746eddd1c08e98bf57a59d542e158487d346e 100644
@@ -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);

hw/vfio/common.c +0 -16
@@ -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)
  {

hw/vfio/iommufd.c +0 -1
index 42c8412bbf50724dddb43f9b19a3aa40c8bc311d..2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0 100644
--- a/hw/vfio/iommufd.c
Quoted 8 lines

hw/vfio/iommufd.c line 28

Quoted 6 lines

+++ b/hw/vfio/iommufd.c

hw/vfio/iommufd.c +1 -0
@@ -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.

Quoted 66 lines

Thanks.

Quoted 62 lines
hw/vfio/iommufd.c +0 -0
   static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                               ram_addr_t size, void *vaddr, bool readonly)
hw/vfio/migration-multifd.c +1 -0
index fe84735ec2c7bd085820d25c06be558761fbe0d5..285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db 100644
@@ -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)
hw/vfio/migration.c +17 -0
index a1ba993ce549fce0d2a9a60ba07d4782c87c0c09..46c4cfecce25ba1146a1d8f2de0d7c51425afe8e 100644
@@ -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;
+}
hw/vfio/pci.c +1 -0
index 7f1532fbed9aed2eae2c98f6fd79a9056ff1e84f..3612f6fe7d0864fe3789f4ea221da01ef87d0664 100644
@@ -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"
 
Signature · 1 line
2.48.1
#25 lore raw

PATCH 7/32 vfio: Introduce a new header file for VFIOdisplay declarations

In reply to Cédric Le Goater

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

---
 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
hw/vfio/display.h new file +41 -0
new file mode 100644
index 0000000000000000000000000000000000000000..93a4df2dfa5b39946d700b3df76233f0d7b0343f
@@ -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 */
hw/vfio/pci.h +1 -0
index d94ecaba689c4681687c0a6796ffbcda522ae179..c84bba81487136d205ca30049c812d00e832c377 100644
@@ -20,6 +20,7 @@
 #include "qemu/timer.h"
 #include "qom/object.h"
 #include "system/kvm.h"
+#include "display.h"
 
 #define PCI_ANY_ID (~0)
 
include/hw/vfio/vfio-common.h +0 -28
index 799e12d43747addbf444c15052f629b65978322f..288c2fb3d0e792427c0e7655002248829b4d189a 100644
@@ -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,
hw/vfio/display.c +1 -1
index ea87830fe0d5fc66f3f27a16bde5d75b7b6280c0..2c06361c67cb074b88f2649b3b9fd21b7bacf07c 100644
@@ -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
Signature · 1 line
2.48.1
#27 lore raw

PATCH 8/32 vfio: Move VFIOHostDMAWindow definition into spapr.c

In reply to Cédric Le Goater

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

---
 include/hw/vfio/vfio-common.h | 7 -------
 hw/vfio/spapr.c               | 7 +++++++
 2 files changed, 7 insertions(+), 7 deletions(-)
include/hw/vfio/vfio-common.h +0 -7
index 288c2fb3d0e792427c0e7655002248829b4d189a..3355c2d4e57569d7bb01b4d9378fb49a807335e8 100644
@@ -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 {
hw/vfio/spapr.c +7 -0
index 1a5d1611f2cdc8fa6254a77b8ec3d1f56d28e3a6..021cdedbfa483f0599ad3c858a77fc6570f1ace8 100644
@@ -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;
Signature · 1 line
2.48.1
#29 lore raw

PATCH 9/32 vfio: Introduce a new header file for VFIOIOMMUFD declarations

In reply to Cédric Le Goater

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

---
 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
hw/vfio/iommufd.h new file +29 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7d87994c4fadbc328b6ac7f9aee00469dd8808b0
@@ -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 */
include/hw/vfio/vfio-common.h +3 -18
index 3355c2d4e57569d7bb01b4d9378fb49a807335e8..8d48f5300a791d8858fe29d1bb905f814ef11990 100644
@@ -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;
hw/vfio/iommufd.c +1 -0
index 2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0..a219b6453037e2d4e0d12800ea25678885af98f8 100644
@@ -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)
Signature · 1 line
2.48.1
#31 lore raw

RE: [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations

In reply to Cédric Le Goater
Quoted 38 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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".

---

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

hw/vfio/iommufd.h new file +0 -0
new file mode 100644

index 0000000000000000000000000000000000000000..7d87994c4fadbc328b6ac7f9ae e00469dd8808b0

hw/vfio/iommufd.h new file +12 -0
@@ -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
+
+

hw/vfio/iommufd.h line 22

Quoted 10 lines
hw/vfio/iommufd.h new file +10 -0
+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

Quoted 63 lines
hw/vfio/iommufd.h new file +5 -0
+    uint32_t ioas_id;
+    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
+} VFIOIOMMUFDContainer;
+
+OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer,

VFIO_IOMMU_IOMMUFD);

hw/vfio/iommufd.h new file +2 -0
+
+#endif /* HW_VFIO_IOMMUFD_H */
include/hw/vfio/vfio-common.h +0 -0

index 3355c2d4e57569d7bb01b4d9378fb49a807335e8..8d48f5300a791d8858fe29d1bb 905f814ef11990 100644

include/hw/vfio/vfio-common.h +3 -18
@@ -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;
hw/vfio/iommufd.c +0 -0

index 2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0..a219b6453037e2d4e0d12800ea 25678885af98f8 100644

hw/vfio/iommufd.c +1 -0
@@ -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

#32 lore raw

Re: [PATCH for-10.1 09/32] vfio: Introduce a new header file for VFIOIOMMUFD declarations

Quoted 42 lines · Zhenzhong
Quoted 42 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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".

---

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

hw/vfio/iommufd.h new file +0 -0
new file mode 100644

index 0000000000000000000000000000000000000000..7d87994c4fadbc328b6ac7f9ae e00469dd8808b0

hw/vfio/iommufd.h new file +16 -0
@@ -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;
Quoted 8 lines

hw/vfio/iommufd.h line 22

Quoted 6 lines
hw/vfio/iommufd.h new file +6 -0
+    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.

Quoted 68 lines

Thanks
Zhenzhong

Quoted 63 lines
hw/vfio/iommufd.h new file +5 -0
+    uint32_t ioas_id;
+    QLIST_HEAD(, VFIOIOASHwpt) hwpt_list;
+} VFIOIOMMUFDContainer;
+
+OBJECT_DECLARE_SIMPLE_TYPE(VFIOIOMMUFDContainer,

VFIO_IOMMU_IOMMUFD);

hw/vfio/iommufd.h new file +2 -0
+
+#endif /* HW_VFIO_IOMMUFD_H */
include/hw/vfio/vfio-common.h +0 -0

index 3355c2d4e57569d7bb01b4d9378fb49a807335e8..8d48f5300a791d8858fe29d1bb 905f814ef11990 100644

include/hw/vfio/vfio-common.h +3 -18
@@ -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;
hw/vfio/iommufd.c +0 -0

index 2fb2a01ec6d29dbc284cfd9830c24e78ce560dd0..a219b6453037e2d4e0d12800ea 25678885af98f8 100644

hw/vfio/iommufd.c +1 -0
@@ -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

#33 lore raw

PATCH 10/32 vfio: Introduce new files for VFIORegion definitions and declarations

In reply to 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.

---
 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
hw/vfio/display.h +1 -0
index 93a4df2dfa5b39946d700b3df76233f0d7b0343f..34c2b3a6b797ee25d2f3d89ed78293ed2430ad94 100644
@@ -11,6 +11,7 @@
 
 #include "ui/console.h"
 #include "hw/display/ramfb.h"
+#include "hw/vfio/vfio-region.h"
 
 typedef struct VFIODMABuf {
     QemuDmaBuf *buf;
include/hw/vfio/vfio-common.h +1 -31
index 8d48f5300a791d8858fe29d1bb905f814ef11990..3d470d79325526e0508683c445a7635c78a57e34 100644
@@ -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;
include/hw/vfio/vfio-platform.h +2 -0
index c414c3dffcc840a2f40a1b252d0f7b4e309c78d4..3191545717da51abc41d10cd3646cd047b4a676c 100644
@@ -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 */
include/hw/vfio/vfio-region.h new file +47 -0

47 lines not on this page · raw message

hw/core/sysbus-fdt.c +1 -0
index e85066b905637b1ca34b5965f383df341f3a4eb7..c339a27875cbee8131b064674aa09adf4b9efa25 100644
@@ -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"
hw/vfio/helpers.c +0 -363

375 lines not on this page · raw message

hw/vfio/pci-quirks.c +1 -0
index 3f002252acfb7ac809107c99bdbdbaf66d56a50d..4591ec68da877b307f43ea1a830c315721b57e9e 100644
@@ -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"
 
 /*
hw/vfio/pci.c +1 -0
index 3612f6fe7d0864fe3789f4ea221da01ef87d0664..6bf5a4dc720f717b2593b1b272927a13f2932d27 100644
@@ -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"
 
hw/vfio/platform.c +1 -0
index 67bc57409c1f5a6978690c3dc07d249ea0248aa0..83b53d57149a343a00eb6d6f78c1cbea004dbaa2 100644
@@ -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
hw/vfio/region.c new file +395 -0

395 lines not on this page · raw message

hw/vfio/meson.build +1 -0
index a8939c838657b09c38f93ad69d541df5aea30a6f..07010c7c9e01a39ae3449c54d2027a2cdd0a7a4d 100644
@@ -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',
hw/vfio/trace-events +9 -7
index 9347e3a5f6607ec6907f9b426da9ab90553292cf..81f4130100c48012c15b5b4858446149a7eaf5b6 100644
@@ -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"
Signature · 1 line
2.48.1
#34 lore raw

Re: [PATCH for-10.1 10/32] vfio: Introduce new files for VFIORegion definitions and declarations

Quoted 15 lines · 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.

hw/vfio/region.c new file +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..3e174c3dcb0b699fd0cee00d104250d8ae97f698

hw/vfio/region.c line 3

Quoted 3 lines
hw/vfio/region.c new file +3 -0
@@ -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

#35 lore raw

PATCH 11/32 vfio: Introduce a new header file for VFIOcontainer declarations

In reply to 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.

---
 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
include/hw/vfio/vfio-common.h +0 -19
index 3d470d79325526e0508683c445a7635c78a57e34..aebce091088f5027c31c7782a1683e763bd766ec 100644
@@ -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 \
include/hw/vfio/vfio-container.h new file +35 -0
new file mode 100644
index 0000000000000000000000000000000000000000..fe1a849f884968c47a6ea876fc37b2842cb025da
@@ -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 */
hw/ppc/spapr_pci_vfio.c +1 -0
index 76b2a3487b5d6f21528e9c301341eb27bc8fec1d..1722a5bfa3983d42baac558f22410e36eed375f5 100644
@@ -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 */
 
hw/s390x/s390-pci-vfio.c +1 -1
index 6236ac7f1e686c9774ade172bf57a1e526b59939..88d4c5b3ecc617c5b93ca53cba0850666db3a67b 100644
@@ -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
hw/vfio/container.c +1 -0
index 7c57bdd27b72731db5cf4f9446d954e143b4747e..75b5ebf4716c55d8c32a845c875981cef8fb5610 100644
@@ -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);
hw/vfio/spapr.c +1 -0
index 021cdedbfa483f0599ad3c858a77fc6570f1ace8..4adfd50967313d1a5c3c4033a57c37eeb3a779a7 100644
@@ -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"
Signature · 1 line
2.48.1
Reviewed-by on v1 11/32
#36 lore raw

Re: [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations

Quoted 6 lines · 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.

regards
john

Reviewed-by on v1 11/32
#37 lore raw

RE: [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations

In reply to Cédric Le Goater
Quoted 7 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: [PATCH for-10.1 11/32] vfio: Introduce a new header file for VFIOcontainer declarations

Quoted 6 lines

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.

Thanks
Zhenzhong

#38 lore raw

PATCH 12/32 vfio: Make vfio_group_list static

In reply to Cédric Le Goater

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

---
 include/hw/vfio/vfio-common.h | 2 --
 hw/vfio/container.c           | 3 ++-
 2 files changed, 2 insertions(+), 3 deletions(-)
include/hw/vfio/vfio-common.h +0 -2
index aebce091088f5027c31c7782a1683e763bd766ec..e23626856e6ff96939a4660f059833f166aa88e9 100644
@@ -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;
hw/vfio/container.c +2 -1
index 75b5ebf4716c55d8c32a845c875981cef8fb5610..8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb 100644
@@ -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)
Signature · 1 line
2.48.1
#41 lore raw

PATCH 13/32 vfio: Move VFIOAddressSpace helpers into container-base.c

In reply to 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.

---
 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(-)
include/hw/vfio/vfio-common.h +0 -6
index e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236cac0bbe834b39 100644
@@ -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);
include/hw/vfio/vfio-container-base.h +5 -0
index 4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda9548c8e60afefe794 100644
@@ -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);
hw/ppc/spapr_pci_vfio.c +2 -3
index 1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc2195bf68418e5206 100644
@@ -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);
 }
 
hw/vfio/common.c +0 -66

90 lines not on this page · raw message

hw/vfio/container-base.c +69 -0

76 lines not on this page · raw message

hw/vfio/container.c +3 -3
index 8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb..9b86e24a4072e579bcdc2c060ce42608ee44ee2e 100644
@@ -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);
     }
 }
 
hw/vfio/iommufd.c +3 -3
index a219b6453037e2d4e0d12800ea25678885af98f8..a170f5c71218db8c9b2f00b1a45ee900b6b21346 100644
@@ -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);
hw/vfio/trace-events +3 -1
index 81f4130100c48012c15b5b4858446149a7eaf5b6..c3691c1a172c31c5b10bfd6967c32fd32b65d0f7 100644
@@ -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) ""
Signature · 1 line
2.48.1
#42 lore raw

Re: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c

Quoted 4 lines · 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".

Quoted 8 lines

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.

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

#43 lore raw

RE: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c

In reply to Cédric Le Goater
Quoted 233 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

---

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(-)
include/hw/vfio/vfio-common.h +0 -0

index e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236 cac0bbe834b39 100644

include/hw/vfio/vfio-common.h +0 -6
@@ -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);
include/hw/vfio/vfio- renamed from include/hw/vfio/vfio-container-base.h +0 -0

container-base.h
index 4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda954 8c8e60afefe794 100644

include/hw/vfio/vfio-container-base.h +5 -0
@@ -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);
hw/ppc/spapr_pci_vfio.c +0 -0

index 1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc21 95bf68418e5206 100644

hw/ppc/spapr_pci_vfio.c +1 -2
@@ -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)) {
hw/ppc/spapr_pci_vfio.c +0 -0
@@ -106,7 +105,7 @@ static VFIOContainer
 *vfio_eeh_as_container(AddressSpace *as)
    }
 

out:

hw/ppc/spapr_pci_vfio.c +1 -1
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
    return container_of(bcontainer, VFIOContainer, bcontainer);

}

hw/vfio/common.c +0 -0

index 0e3746eddd1c08e98bf57a59d542e158487d346e..08e2494d7c4a9858657724730 b2829290fb3f197 100644

hw/vfio/common.c +0 -1
@@ -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);
hw/vfio/common.c +0 -2
-static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
-    QLIST_HEAD_INITIALIZER(vfio_address_spaces);

#ifdef CONFIG_KVM
/*

hw/vfio/common.c +0 -63
@@ -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;
hw/vfio/container-base.c +0 -0

index 749a3fd29dd6fc9143f14edf7e4ac6238315fcce..83e83ab9e67de8b004dfaf0067e 4c466a6c88451 100644

hw/vfio/container-base.c +14 -0
@@ -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) {

hw/vfio/container-base.c line 40

Quoted 10 lines
hw/vfio/container-base.c +10 -0
+            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

Quoted 148 lines
hw/vfio/container-base.c +45 -0
+
+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,
hw/vfio/container.c +0 -0

index 8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb..9b86e24a4072e579bcdc2c060c e42608ee44ee2e 100644

hw/vfio/container.c +1 -1
@@ -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

hw/vfio/container.c +0 -0
@@ -675,7 +675,7 @@ close_fd_exit:
    close(fd);
 

put_space_exit:

hw/vfio/container.c +1 -1
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
 
    return false;

}

hw/vfio/container.c +1 -1
@@ -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);
    }
 }
 
hw/vfio/iommufd.c +0 -0

index a219b6453037e2d4e0d12800ea25678885af98f8..a170f5c71218db8c9b2f00b1a4 5ee900b6b21346 100644

hw/vfio/iommufd.c +1 -1
@@ -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

hw/vfio/iommufd.c +0 -0
@@ -607,7 +607,7 @@ err_discard_disable:

err_attach_container:

    iommufd_cdev_container_destroy(container);

err_alloc_ioas:

hw/vfio/iommufd.c +1 -1
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
    iommufd_cdev_unbind_and_disconnect(vbasedev);

err_connect_bind:

    close(vbasedev->fd);
hw/vfio/iommufd.c +1 -1
@@ -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);
hw/vfio/trace-events +0 -0

index 81f4130100c48012c15b5b4858446149a7eaf5b6..c3691c1a172c31c5b10bfd6967 c32fd32b65d0f7 100644

hw/vfio/trace-events +0 -0
@@ -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)"
hw/vfio/trace-events +0 -0
@@ -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"

hw/vfio/trace-events +3 -1
+
+# container-base.c
+vfio_reset_handler(void) ""
--

2.48.1

#44 lore raw

Re: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c

+John

Quoted 237 lines · Zhenzhong
Quoted 237 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

---

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(-)
include/hw/vfio/vfio-common.h +0 -0

index e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236 cac0bbe834b39 100644

include/hw/vfio/vfio-common.h +0 -6
@@ -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);
include/hw/vfio/vfio- renamed from include/hw/vfio/vfio-container-base.h +0 -0

container-base.h
index 4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda954 8c8e60afefe794 100644

include/hw/vfio/vfio-container-base.h +5 -0
@@ -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);
hw/ppc/spapr_pci_vfio.c +0 -0

index 1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc21 95bf68418e5206 100644

hw/ppc/spapr_pci_vfio.c +1 -2
@@ -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)) {
hw/ppc/spapr_pci_vfio.c +0 -0
@@ -106,7 +105,7 @@ static VFIOContainer
 *vfio_eeh_as_container(AddressSpace *as)
     }
 

out:

hw/ppc/spapr_pci_vfio.c +1 -1
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
     return container_of(bcontainer, VFIOContainer, bcontainer);

}

hw/vfio/common.c +0 -0

index 0e3746eddd1c08e98bf57a59d542e158487d346e..08e2494d7c4a9858657724730 b2829290fb3f197 100644

hw/vfio/common.c +0 -1
@@ -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);
hw/vfio/common.c +0 -2
-static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
-    QLIST_HEAD_INITIALIZER(vfio_address_spaces);

#ifdef CONFIG_KVM
/*

hw/vfio/common.c +0 -63
@@ -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;
hw/vfio/container-base.c +0 -0

index 749a3fd29dd6fc9143f14edf7e4ac6238315fcce..83e83ab9e67de8b004dfaf0067e 4c466a6c88451 100644

hw/vfio/container-base.c +18 -0
@@ -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);
+        }
+    }
+
Quoted 8 lines

hw/vfio/container-base.c line 40

Quoted 6 lines
hw/vfio/container-base.c +6 -0
+    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").

Quoted 1 line

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.

Quoted 152 lines

Thanks
Zhenzhong

Quoted 148 lines
hw/vfio/container-base.c +45 -0
+
+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,
hw/vfio/container.c +0 -0

index 8badeb98ec052ad1fa7b5d45bb1733b1184bc6fb..9b86e24a4072e579bcdc2c060c e42608ee44ee2e 100644

hw/vfio/container.c +1 -1
@@ -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

hw/vfio/container.c +0 -0
@@ -675,7 +675,7 @@ close_fd_exit:
     close(fd);
 

put_space_exit:

hw/vfio/container.c +1 -1
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
 
     return false;

}

hw/vfio/container.c +1 -1
@@ -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);
     }
 }
 
hw/vfio/iommufd.c +0 -0

index a219b6453037e2d4e0d12800ea25678885af98f8..a170f5c71218db8c9b2f00b1a4 5ee900b6b21346 100644

hw/vfio/iommufd.c +1 -1
@@ -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

hw/vfio/iommufd.c +0 -0
@@ -607,7 +607,7 @@ err_discard_disable:

err_attach_container:

     iommufd_cdev_container_destroy(container);

err_alloc_ioas:

hw/vfio/iommufd.c +1 -1
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
     iommufd_cdev_unbind_and_disconnect(vbasedev);

err_connect_bind:

     close(vbasedev->fd);
hw/vfio/iommufd.c +1 -1
@@ -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);
hw/vfio/trace-events +0 -0

index 81f4130100c48012c15b5b4858446149a7eaf5b6..c3691c1a172c31c5b10bfd6967 c32fd32b65d0f7 100644

hw/vfio/trace-events +0 -0
@@ -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)"
hw/vfio/trace-events +0 -0
@@ -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"

hw/vfio/trace-events +3 -1
+
+# container-base.c
+vfio_reset_handler(void) ""
--

2.48.1

#45 lore raw

RE: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c

Quoted 262 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCH for-10.1 13/32] vfio: Move VFIOAddressSpace helpers into container-base.c

+John

Quoted 30 lines · Zhenzhong
Quoted 30 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

---

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(-)
Quoted 3 lines
Quoted 3 lines
include/hw/vfio/vfio-common.h +0 -0

index

e23626856e6ff96939a4660f059833f166aa88e9..2ea7f9c6f6e7e752699954ac236

Quoted 18 lines
Quoted 18 lines

cac0bbe834b39 100644

include/hw/vfio/vfio-common.h +0 -5
@@ -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);
 
Quoted 8 lines
Quoted 8 lines
include/hw/vfio/vfio-common.h +0 -1
-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);
include/hw/vfio/vfio- renamed from include/hw/vfio/vfio-container-base.h +0 -0

container-base.h
index

4cff9943ab4861a25d07b5ebd1200509ebfab12d..27668879f5ca77e558a2bda954

Quoted 7 lines
Quoted 7 lines

8c8e60afefe794 100644

include/hw/vfio/vfio-container-base.h +0 -0
@@ -71,6 +71,11 @@ typedef struct VFIORamDiscardListener {
     QLIST_ENTRY(VFIORamDiscardListener) next;
 } VFIORamDiscardListener;
 
Quoted 11 lines
Quoted 11 lines
include/hw/vfio/vfio-container-base.h +5 -0
+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);
hw/ppc/spapr_pci_vfio.c +0 -0

index

1722a5bfa3983d42baac558f22410e36eed375f5..e318d0d912f3e90d1289e4bc21

Quoted 4 lines
Quoted 4 lines

95bf68418e5206 100644

hw/ppc/spapr_pci_vfio.c +0 -0
@@ -24,7 +24,6 @@
Quoted 8 lines

hw/ppc/spapr_pci_vfio.c static int vfio_eeh_container_op(VFIOContainer

Quoted 8 lines
hw/ppc/spapr_pci_vfio.c +0 -1
 #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,

Quoted 19 lines
Quoted 19 lines
hw/ppc/spapr_pci_vfio.c +1 -1
 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)) {
hw/ppc/spapr_pci_vfio.c +0 -0
@@ -106,7 +105,7 @@ static VFIOContainer
 *vfio_eeh_as_container(AddressSpace *as)
     }
 

out:

hw/ppc/spapr_pci_vfio.c +1 -1
-    vfio_put_address_space(space);
+    vfio_address_space_put(space);
     return container_of(bcontainer, VFIOContainer, bcontainer);

}

Quoted 3 lines
Quoted 3 lines
hw/vfio/common.c +0 -0

index

0e3746eddd1c08e98bf57a59d542e158487d346e..08e2494d7c4a9858657724730

Quoted 92 lines
Quoted 92 lines

b2829290fb3f197 100644

hw/vfio/common.c +0 -1
@@ -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);
hw/vfio/common.c +0 -2
-static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
-    QLIST_HEAD_INITIALIZER(vfio_address_spaces);

#ifdef CONFIG_KVM
/*

hw/vfio/common.c +0 -61
@@ -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;
Quoted 8 lines
Quoted 8 lines
hw/vfio/common.c +0 -2
-}
-
 struct vfio_device_info *vfio_get_device_info(int fd)
 {
     struct vfio_device_info *info;
hw/vfio/container-base.c +0 -0

index

749a3fd29dd6fc9143f14edf7e4ac6238315fcce..83e83ab9e67de8b004dfaf0067e

Quoted 26 lines
Quoted 26 lines

4c466a6c88451 100644

hw/vfio/container-base.c +18 -0
@@ -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);
+        }
+    }
+
Quoted 8 lines

hw/vfio/container-base.c line 40

Quoted 6 lines
hw/vfio/container-base.c +6 -0
+    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,

Quoted 5 lines

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.

Quoted 20 lines

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. */

Quoted 6 lines

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

Quoted 1 line

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

#46 lore raw

PATCH 14/32 vfio: Move Host IOMMU type declarations into their respective files

In reply to 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.

---
 include/hw/vfio/vfio-common.h | 5 -----
 hw/vfio/container.c           | 2 ++
 hw/vfio/iommufd.c             | 3 +++
 3 files changed, 5 insertions(+), 5 deletions(-)
include/hw/vfio/vfio-common.h +0 -5
index 2ea7f9c6f6e7e752699954ac236cac0bbe834b39..c45a18ab3af7d0b55a41d607a17d93079ae445d7 100644
@@ -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);
hw/vfio/container.c +2 -0
index 9b86e24a4072e579bcdc2c060ce42608ee44ee2e..9aa9f6931f591211e46f57029df2ca194f9c3eaf 100644
@@ -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);
hw/vfio/iommufd.c +3 -0
index a170f5c71218db8c9b2f00b1a45ee900b6b21346..ce47c85c0dde424b36b482344ff8c92fc2485f9f 100644
@@ -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)
 {
Signature · 1 line
2.48.1
Reviewed-by on v1 14/32
#47 lore raw

Re: [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files

Quoted 5 lines · 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.

regards
john

Reviewed-by on v1 14/32
#48 lore raw

RE: [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files

In reply to Cédric Le Goater
Quoted 7 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: [PATCH for-10.1 14/32] vfio: Move Host IOMMU type declarations into their respective files

Quoted 5 lines

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

Thanks
Zhenzhong

#49 lore raw

PATCH 15/32 vfio: Introduce a new header file for helper services

In reply to Cédric Le Goater

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

---
 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
hw/vfio/helpers.h new file +26 -0
new file mode 100644
index 0000000000000000000000000000000000000000..b70f7082562dedff9d97db80d2eecc7ddf71e2af
@@ -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 */
include/hw/vfio/vfio-common.h +0 -7
index c45a18ab3af7d0b55a41d607a17d93079ae445d7..0fe424633c9cb94195c08d0b62ca4fb8ffccd79c 100644
@@ -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
hw/s390x/s390-pci-vfio.c +1 -0
index 88d4c5b3ecc617c5b93ca53cba0850666db3a67b..83c8e84919aecf2a8581205f3de5061aceb20ea8 100644
@@ -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
hw/vfio/common.c +1 -0
index 08e2494d7c4a9858657724730b2829290fb3f197..3a20b121fcaf361596bc975437f9a358effc7f88 100644
@@ -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);
hw/vfio/container.c +1 -0
index 9aa9f6931f591211e46f57029df2ca194f9c3eaf..a6f7359faefc02b01ca05f76b4c1f8a9934a9091 100644
@@ -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"
 
hw/vfio/helpers.c +1 -0
index 89403943a7a219e491b6812d50b27b7f1fd7b4a4..9d635c18156d3271bad824b74fbc5b6f1f810a95 100644
@@ -30,6 +30,7 @@
 #include "qemu/error-report.h"
 #include "qemu/units.h"
 #include "monitor/monitor.h"
+#include "helpers.h"
 
 /*
  * Common VFIO interrupt disable
hw/vfio/pci.c +1 -0
index 6bf5a4dc720f717b2593b1b272927a13f2932d27..c0d314265836759beaf65afd85153b465179ecce 100644
@@ -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"
 
hw/vfio/region.c +1 -0
index 3e174c3dcb0b699fd0cee00d104250d8ae97f698..87bf5e046a432dfedf3be3c1c7e8f33e006da004 100644
@@ -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
Signature · 1 line
2.48.1
Reviewed-by on v1 15/32
#50 lore raw

Re: [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services

Quoted 4 lines · Cédric Le Goater

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

but

Review

Quoted 2 lines
(quoted diff) +2 -0
+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

#51 lore raw

Re: [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services

Quoted 7 lines · John Levon
Quoted 4 lines · Cédric Le Goater

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

Quoted 8 lines

but

Review

Quoted 2 lines
(quoted diff) +2 -0
+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.

Quoted 4 lines

regards
john

#52 lore raw

Re: [PATCH for-10.1 15/32] vfio: Introduce a new header file for helper services

Quoted 7 lines · Cédric Le Goater
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+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

#53 lore raw

PATCH 16/32 vfio: Move vfio_get_info_dma_avail() into helpers.c

In reply to 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".

---
 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(-)
hw/vfio/helpers.h +4 -1
index b70f7082562dedff9d97db80d2eecc7ddf71e2af..c70eef4fd6f98fc1df9bc8ecbf72fa1ea484e3c0 100644
@@ -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);
include/hw/vfio/vfio-common.h +0 -2
index 0fe424633c9cb94195c08d0b62ca4fb8ffccd79c..b7c1f049582c07aefdc2a0cef2805e7b478ffe84 100644
@@ -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(
hw/vfio/container.c +0 -31
index a6f7359faefc02b01ca05f76b4c1f8a9934a9091..e1b06e71c47ab8d24e7da878f801020b22936430 100644
@@ -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)
 {
hw/vfio/helpers.c +31 -0
index 9d635c18156d3271bad824b74fbc5b6f1f810a95..f42dcf82c58c978a45975eb1d015d64f4e39b3cf 100644
@@ -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)
 {
Signature · 1 line
2.48.1
Reviewed-by on v1 16/32
#54 lore raw

Re: [PATCH for-10.1 16/32] vfio: Move vfio_get_info_dma_avail() into helpers.c

Quoted 5 lines · 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".

regards
john

#55 lore raw

PATCH 17/32 vfio: Move vfio_kvm_device_add/del_fd() to helpers.c

In reply to Cédric Le Goater

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

---
 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(-)
hw/vfio/helpers.h +3 -0
index c70eef4fd6f98fc1df9bc8ecbf72fa1ea484e3c0..397908735c6b285d3d9e012f30488589408235ae 100644
@@ -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 */
include/hw/vfio/vfio-common.h +0 -3
index b7c1f049582c07aefdc2a0cef2805e7b478ffe84..35b765357f85346ecfabfae782f3aa8d83d9e7ae 100644
@@ -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);
 
hw/vfio/common.c +0 -58

64 lines not on this page · raw message

hw/vfio/helpers.c +59 -0

71 lines not on this page · raw message

hw/vfio/iommufd.c +1 -0
index ce47c85c0dde424b36b482344ff8c92fc2485f9f..bc586e02803af984d1801159eb427d3415e373ab 100644
@@ -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"
hw/vfio/meson.build +1 -1
index 07010c7c9e01a39ae3449c54d2027a2cdd0a7a4d..21795b3d19e5db0c93993c0cb4a951a70d260f10 100644
@@ -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',
Signature · 1 line
2.48.1
Reviewed-by on v1 17/32
#57 lore raw

RE: [PATCH for-10.1 17/32] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c

In reply to Cédric Le Goater
Quoted 11 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

Thanks
Zhenzhong

#58 lore raw

PATCH 18/32 vfio: Move vfio_get_device_info() to helpers.c

In reply to Cédric Le Goater

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

---
 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(-)
hw/vfio/helpers.h +1 -0
index 397908735c6b285d3d9e012f30488589408235ae..8ac1f13c6e2a51983f69f81072cb134ff8969c70 100644
@@ -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);
include/hw/vfio/vfio-common.h +0 -1
index 35b765357f85346ecfabfae782f3aa8d83d9e7ae..848412ea53ccd903313855fd30490d897c8681c0 100644
@@ -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,
hw/vfio/common.c +0 -24
index 9c1b635a813ffff97426d2c3beec84de1b9afe63..e70e4c077ca27ce0d2f990d684196f2f74f6f07a 100644
@@ -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)
 {
hw/vfio/helpers.c +24 -0
index cec9e2008ba146c15e54a2865d5a40984e7dfc8c..e9ad0c6792558a00f316baab40bf857c3306faaa 100644
@@ -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)
 {
Signature · 1 line
2.48.1
Reviewed-by on v1 18/32
#60 lore raw

RE: [PATCH for-10.1 18/32] vfio: Move vfio_get_device_info() to helpers.c

In reply to Cédric Le Goater
Quoted 10 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

Thanks
Zhenzhong

#61 lore raw

PATCH 19/32 vfio: Introduce a new file for VFIODevice definitions

In reply to Cédric Le Goater

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

---
 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
hw/vfio/device.c new file +331 -0
new file mode 100644
index 0000000000000000000000000000000000000000..daa5bae59ca9c65ef23aa193d4e63976fcefdde0
@@ -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 <[email protected]>
+ *
+ * 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 ([email protected])
+ *  Copyright (c) 2007, Neocleus, Guy Zana ([email protected])
+ *  Copyright (C) 2008, Qumranet, Amit Shah ([email protected])
+ *  Copyright (C) 2008, Red Hat, Amit Shah ([email protected])
+ *  Copyright (C) 2008, IBM, Muli Ben-Yehuda ([email protected])
+ */
+
+#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;
+    }
+}
hw/vfio/helpers.c +0 -303

322 lines not on this page · raw message

hw/vfio/meson.build +1 -0
index 21795b3d19e5db0c93993c0cb4a951a70d260f10..60caa366175edee6bc69c0febebaef84e752e346 100644
@@ -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',
hw/vfio/trace-events +3 -1
index c3691c1a172c31c5b10bfd6967c32fd32b65d0f7..a1d01e9dde6ec52964d4804e9cbce5a6a32b7879 100644
@@ -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"
Signature · 1 line
2.48.1
#62 lore raw

Re: [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions

hw/vfio/device.c line 3

Quoted 9 lines · Cédric Le Goater
hw/vfio/device.c new file +3 -0
new file mode 100644
index 0000000000000000000000000000000000000000..daa5bae59ca9c65ef23aa193d4e63976fcefdde0
@@ -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

#63 lore raw

Re: [PATCH for-10.1 19/32] vfio: Introduce a new file for VFIODevice definitions

Quoted 14 lines · John Levon

hw/vfio/device.c line 3

Quoted 9 lines · Cédric Le Goater
hw/vfio/device.c new file +3 -0
new file mode 100644
index 0000000000000000000000000000000000000000..daa5bae59ca9c65ef23aa193d4e63976fcefdde0
@@ -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.

#64 lore raw

PATCH 20/32 vfio: Introduce new files for CPR definitions and declarations

In reply to 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.

---
 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
hw/vfio/cpr.h new file +15 -0
new file mode 100644
index 0000000000000000000000000000000000000000..88a5e7f878a3e01df3410f6f0a9c8b5ccddefe28
@@ -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 */
include/hw/vfio/vfio-common.h +0 -3
index 848412ea53ccd903313855fd30490d897c8681c0..7f1df4fc0c545ceb117ad6c090bd3f701456a70c 100644
@@ -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;
hw/vfio/container.c +1 -0
index e1b06e71c47ab8d24e7da878f801020b22936430..4e41a7476549a0c5e464e499d059db5aca6e3470 100644
@@ -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"
 
hw/vfio/cpr.c +1 -0
index 3d1c8d290a5e6b6d67e244931a9ef8c194a0b574..e1bba1726402f41ee394f25b6e613d27f44b2a2c 100644
@@ -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)
hw/vfio/iommufd.c +1 -0
index bc586e02803af984d1801159eb427d3415e373ab..b25f3b4086d7b7fc6fcd519a9b8b2904513a655f 100644
@@ -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"
hw/vfio/meson.build +1 -1
index 60caa366175edee6bc69c0febebaef84e752e346..1f89bd28c13dea55bcfff476ce99d51b453d8533 100644
@@ -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(
Signature · 1 line
2.48.1
#65 lore raw

Re: [PATCH for-10.1 20/32] vfio: Introduce new files for CPR definitions and declarations

Quoted 22 lines · 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.

---
 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
hw/vfio/cpr.h new file +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..88a5e7f878a3e01df3410f6f0a9c8b5ccddefe28

hw/vfio/cpr.h line 2

Quoted 2 lines
hw/vfio/cpr.h new file +2 -0
@@ -0,0 +1,15 @@
+/*
+ * VFIO display

Copy-paste error?

regards
john

#66 lore raw

PATCH 21/32 vfio: Move vfio_kvm_device_fd() into helpers.c

In reply to 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".

---
 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(-)
hw/vfio/helpers.h +2 -0
index 8ac1f13c6e2a51983f69f81072cb134ff8969c70..416b045c6aacd4b6186fc86c4e38be80cad81bbe 100644
@@ -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 *
include/hw/vfio/vfio-common.h +0 -1
index 7f1df4fc0c545ceb117ad6c090bd3f701456a70c..184a422916f62259158e8759efc473a5efb2b2f7 100644
@@ -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,
hw/vfio/common.c +0 -11
index e70e4c077ca27ce0d2f990d684196f2f74f6f07a..52f440c0d05fa9f781221032442b6118ef898a10 100644
@@ -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
  */
hw/vfio/helpers.c +11 -0
index ffc40ff43c8b614f044d6131562e5837cd932aa5..e99d312a9f5c7462644ea3d0de2e9de38979f851 100644
@@ -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
hw/vfio/spapr.c +1 -1
index 4adfd50967313d1a5c3c4033a57c37eeb3a779a7..e9c954352857ab4a437b84eeda6b5a95ce285472 100644
@@ -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;
Signature · 1 line
2.48.1
Reviewed-by on v1 21/32
#67 lore raw

Re: [PATCH for-10.1 21/32] vfio: Move vfio_kvm_device_fd() into helpers.c

Quoted 6 lines · 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".

regards
john

#68 lore raw

PATCH 22/32 vfio: Move vfio_device_list into device.c

In reply to Cédric Le Goater

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

---
 hw/vfio/common.c | 3 ---
 hw/vfio/device.c | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/vfio/common.c +0 -3
index 52f440c0d05fa9f781221032442b6118ef898a10..df9585d1a471f893da072068f6056bbc6731d448 100644
@@ -46,9 +46,6 @@
 #include "migration.h"
 #include "helpers.h"
 
-VFIODeviceList vfio_device_list =
-    QLIST_HEAD_INITIALIZER(vfio_device_list);
-
 /*
  * Device state interfaces
  */
hw/vfio/device.c +3 -0
index daa5bae59ca9c65ef23aa193d4e63976fcefdde0..2e0ddec942690514e692b2380a909f15ece430f5 100644
@@ -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
  */
Signature · 1 line
2.48.1
#70 lore raw

PATCH 23/32 vfio: Move vfio_de/attach_device() into device.c

In reply to Cédric Le Goater

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

---
 hw/vfio/common.c | 37 -------------------------------------
 hw/vfio/device.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 37 deletions(-)
hw/vfio/common.c +0 -37
index df9585d1a471f893da072068f6056bbc6731d448..ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67 100644
@@ -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);
-}
hw/vfio/device.c +37 -0
index 2e0ddec942690514e692b2380a909f15ece430f5..e6a1bbcda2297f9e6272fff9b1c228b6772457ce 100644
@@ -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);
+}
Signature · 1 line
2.48.1
#72 lore raw

PATCH 24/32 vfio: Introduce new files for dirty tracking definitions and declarations

In reply to 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.

---
 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%)
hw/vfio/dirty-tracking.h new file +22 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a
@@ -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 */
include/hw/vfio/vfio-common.h +0 -10
index 184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878d4d61818497426 100644
@@ -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);
hw/vfio/container.c +1 -0
index 4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7 100644
@@ -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"
 
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +1 -4
similarity index 99%
rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c
index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644
@@ -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
hw/vfio/iommufd.c +1 -0
index b25f3b4086d7b7fc6fcd519a9b8b2904513a655f..9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8 100644
@@ -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"
hw/vfio/meson.build +1 -1
index 1f89bd28c13dea55bcfff476ce99d51b453d8533..b6f5a7eeeda035b5872c2a19f8086384e000f420 100644
@@ -1,6 +1,6 @@
 vfio_ss = ss.source_set()
 vfio_ss.add(files(
-  'common.c',
+  'dirty-tracking.c',
   'container.c',
   'helpers.c',
 ))
hw/vfio/trace-events +1 -1
index a1d01e9dde6ec52964d4804e9cbce5a6a32b7879..f3bdcebe938dcca77b913ef81a74644c622b5d8a 100644
@@ -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"
Signature · 1 line
2.48.1
Reviewed-by on v1 24/32
#73 lore raw

Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

Quoted 8 lines · 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.

Quoted 147 lines
---
 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%)
hw/vfio/dirty-tracking.h new file +22 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a
@@ -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 */
include/hw/vfio/vfio-common.h +0 -10
index 184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878d4d61818497426 100644
@@ -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);
hw/vfio/container.c +1 -0
index 4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7 100644
@@ -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"
 
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +1 -4
similarity index 99%
rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c
index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644
@@ -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
hw/vfio/iommufd.c +1 -0
index b25f3b4086d7b7fc6fcd519a9b8b2904513a655f..9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8 100644
@@ -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"
hw/vfio/meson.build +1 -1
index 1f89bd28c13dea55bcfff476ce99d51b453d8533..b6f5a7eeeda035b5872c2a19f8086384e000f420 100644
@@ -1,6 +1,6 @@
 vfio_ss = ss.source_set()
 vfio_ss.add(files(
-  'common.c',
+  'dirty-tracking.c',
   'container.c',
   'helpers.c',
 ))
hw/vfio/trace-events +1 -1
index a1d01e9dde6ec52964d4804e9cbce5a6a32b7879..f3bdcebe938dcca77b913ef81a74644c622b5d8a 100644
@@ -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"
#74 lore raw

Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

In reply to Cédric Le Goater

hw/vfio/dirty-tracking.c

Quoted 15 lines · 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.

rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c
index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644

hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -0
@@ -20,14 +20,10 @@

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

regards
john

#75 lore raw

Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

Quoted 11 lines · John Levon
Quoted 8 lines · 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.

Quoted 9 lines

hw/vfio/dirty-tracking.c

Quoted 6 lines

rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c
index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143dcee5f0a89a900 100644

hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -0
@@ -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.

#76 lore raw

RE: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

In reply to Cédric Le Goater
Quoted 115 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

---

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%)

hw/vfio/dirty-tracking.h new file +0 -0
new file mode 100644

index 0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3 db27b80bfe2d3a

hw/vfio/dirty-tracking.h new file +14 -0
@@ -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);

hw/vfio/dirty-tracking.h new file +7 -0
+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 */
include/hw/vfio/vfio-common.h +0 -0

index 184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878 d4d61818497426 100644

include/hw/vfio/vfio-common.h +0 -10
@@ -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);

hw/vfio/container.c +0 -0

index 4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e 46ab9c8b5019ae7 100644

hw/vfio/container.c +1 -0
@@ -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"

hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -0
similarity index 99%
rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c

index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143d cee5f0a89a900 100644

hw/vfio/dirty-tracking.c line 25

Quoted 6 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -3
@@ -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?

hw/vfio/dirty-tracking.c line 30

Quoted 5 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -1
 #include <linux/vfio.h>
 
 #include "hw/vfio/vfio-common.h"
 #include "hw/vfio/pci.h"
-#include "exec/address-spaces.h"

Same here.

Thanks
Zhenzhong

Quoted 60 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +1 -0
 #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
hw/vfio/iommufd.c +0 -0

index b25f3b4086d7b7fc6fcd519a9b8b2904513a655f..9335a17920b32dc2bf9cb4eeb2b 8f57382f14ac8 100644

hw/vfio/iommufd.c +1 -0
@@ -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"
hw/vfio/meson.build +0 -0

index 1f89bd28c13dea55bcfff476ce99d51b453d8533..b6f5a7eeeda035b5872c2a19f80 86384e000f420 100644

hw/vfio/meson.build +0 -0
@@ -1,6 +1,6 @@
 vfio_ss = ss.source_set()

vfio_ss.add(files(

hw/vfio/meson.build +1 -1
-  'common.c',
+  'dirty-tracking.c',
  'container.c',
  'helpers.c',

))

hw/vfio/trace-events +0 -0

index a1d01e9dde6ec52964d4804e9cbce5a6a32b7879..f3bdcebe938dcca77b913ef81a 74644c622b5d8a 100644

hw/vfio/trace-events +0 -0
@@ -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"

hw/vfio/trace-events +1 -1
-# 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

#77 lore raw

Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

Quoted 25 lines · Zhenzhong
Quoted 16 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

hw/vfio/dirty-tracking.c line 25

Quoted 6 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -3
@@ -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?

Quoted 8 lines

hw/vfio/dirty-tracking.c line 30

Quoted 5 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -1
 #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."

#78 lore raw

RE: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

Quoted 39 lines

-----Original Message-----
From: Joao Martins <[email protected]>
Subject: Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

Quoted 31 lines · Zhenzhong
Quoted 16 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

hw/vfio/dirty-tracking.c line 25

Quoted 6 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -3
@@ -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?

Quoted 5 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -1
 #include <linux/vfio.h>
 
 #include "hw/vfio/vfio-common.h"
 #include "hw/vfio/pci.h"
-#include "exec/address-spaces.h"
Quoted 6 lines
Quoted 2 lines

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

#79 lore raw

Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

In reply to Duan, Zhenzhong
Quoted 124 lines · Zhenzhong
Quoted 115 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

---

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%)

hw/vfio/dirty-tracking.h new file +0 -0
new file mode 100644

index 0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3 db27b80bfe2d3a

hw/vfio/dirty-tracking.h new file +14 -0
@@ -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);

hw/vfio/dirty-tracking.h new file +7 -0
+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 */
include/hw/vfio/vfio-common.h +0 -0

index 184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878 d4d61818497426 100644

include/hw/vfio/vfio-common.h +0 -10
@@ -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);

hw/vfio/container.c +0 -0

index 4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e 46ab9c8b5019ae7 100644

hw/vfio/container.c +1 -0
@@ -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"

hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -0
similarity index 99%
rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c

index ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143d cee5f0a89a900 100644

hw/vfio/dirty-tracking.c line 25

Quoted 6 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -3
@@ -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?

Quoted 7 lines

hw/vfio/dirty-tracking.c line 30

Quoted 5 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -1
 #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.

#80 lore raw

RE: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

Quoted 146 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCH for-10.1 24/32] vfio: Introduce new files for dirty tracking definitions and declarations

Quoted 27 lines · Zhenzhong
Quoted 27 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
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.

---

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%)

Quoted 4 lines
Quoted 4 lines
hw/vfio/dirty-tracking.h new file +0 -0
new file mode 100644

index

0000000000000000000000000000000000000000..4b83dc54ab50dabfff040d7cc3

Quoted 17 lines
Quoted 17 lines

db27b80bfe2d3a

hw/vfio/dirty-tracking.h new file +13 -0
@@ -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;
+
Quoted 8 lines

hw/vfio/dirty-tracking.h

Quoted 8 lines
hw/vfio/dirty-tracking.h new file +1 -0
+bool vfio_devices_all_dirty_tracking_started(const VFIOContainerBase

*bcontainer);
+bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer);

hw/vfio/dirty-tracking.h new file +4 -0
+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,

Quoted 6 lines
Quoted 6 lines
hw/vfio/dirty-tracking.h new file +3 -0
+                          uint64_t size, ram_addr_t ram_addr, Error **errp);
+
+#endif /* HW_VFIO_DIRTY_TRACKING_H */
include/hw/vfio/vfio-common.h +0 -0

index

184a422916f62259158e8759efc473a5efb2b2f7..cc20110d9de8ac173b67e6e878

Quoted 9 lines
Quoted 9 lines

d4d61818497426 100644

include/hw/vfio/vfio-common.h +0 -1
@@ -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;
 
Quoted 5 lines
Quoted 5 lines
include/hw/vfio/vfio-common.h +0 -0
 #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);

Quoted 6 lines

include/hw/vfio/vfio-common.h int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,

Quoted 6 lines

#endif

include/hw/vfio/vfio-common.h +0 -4
-bool vfio_devices_all_dirty_tracking_started(
-    const VFIOContainerBase *bcontainer);
-bool
-vfio_devices_all_device_dirty_tracking(const VFIOContainerBase

*bcontainer);

Quoted 3 lines

include/hw/vfio/vfio-common.h int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,

Quoted 3 lines
include/hw/vfio/vfio-common.h +0 -3
-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,

Quoted 8 lines
Quoted 8 lines
include/hw/vfio/vfio-common.h +0 -2
-                          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);

hw/vfio/container.c +0 -0

index

4e41a7476549a0c5e464e499d059db5aca6e3470..e88dfe12edd6dee469c06ee2e

Quoted 12 lines
Quoted 12 lines

46ab9c8b5019ae7 100644

hw/vfio/container.c +1 -0
@@ -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"

Quoted 6 lines
Quoted 6 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -0
similarity index 99%
rename from hw/vfio/common.c
rename to hw/vfio/dirty-tracking.c

index

ed2f2ed8839caaf40fabb0cbbcaa1df2c5b70d67..441f9d9a08c06a88dda44ef143d

Quoted 19 lines

hw/vfio/dirty-tracking.c line 25

Quoted 10 lines

cee5f0a89a900 100644

hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -3
@@ -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?

Quoted 5 lines
hw/vfio/dirty-tracking.c renamed from hw/vfio/common.c +0 -1
 #include <linux/vfio.h>
 
 #include "hw/vfio/vfio-common.h"
 #include "hw/vfio/pci.h"
-#include "exec/address-spaces.h"
Quoted 8 lines
Quoted 1 line

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

#81 lore raw

PATCH 25/32 vfio: Move vfio_set_migration_error() into migration.c

In reply to 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.

---
 hw/vfio/migration.h      |  1 +
 hw/vfio/dirty-tracking.c | 19 +++++--------------
 hw/vfio/migration.c      |  7 +++++++
 3 files changed, 13 insertions(+), 14 deletions(-)
hw/vfio/migration.h +1 -0
index 7ad2141d06a7c97f034db908f9ce19fd06f415b9..9b57d7dc1a6c6143c19e1ee85807d036b1363624 100644
@@ -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 */
hw/vfio/dirty-tracking.c +5 -14
index 441f9d9a08c06a88dda44ef143dcee5f0a89a900..447e09ed84993e3fbe1ed9b27a8269a9f0f46339 100644
@@ -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);
         }
     }
 }
hw/vfio/migration.c +7 -0
index 46c4cfecce25ba1146a1d8f2de0d7c51425afe8e..6fd825e435bde96d1008ec03dfaba25db3b616fc 100644
@@ -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);
+    }
+}
Signature · 1 line
2.48.1
#82 lore raw

Re: [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c

Quoted 99 lines · 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.

---
 hw/vfio/migration.h      |  1 +
 hw/vfio/dirty-tracking.c | 19 +++++--------------
 hw/vfio/migration.c      |  7 +++++++
 3 files changed, 13 insertions(+), 14 deletions(-)
hw/vfio/migration.h +1 -0
index 7ad2141d06a7c97f034db908f9ce19fd06f415b9..9b57d7dc1a6c6143c19e1ee85807d036b1363624 100644
@@ -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 */
hw/vfio/dirty-tracking.c +5 -14
index 441f9d9a08c06a88dda44ef143dcee5f0a89a900..447e09ed84993e3fbe1ed9b27a8269a9f0f46339 100644
@@ -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);
         }
     }
 }
hw/vfio/migration.c +0 -0
index 46c4cfecce25ba1146a1d8f2de0d7c51425afe8e..6fd825e435bde96d1008ec03dfaba25db3b616fc 100644
@@ -1239,3 +1239,10 @@ bool vfio_device_state_is_precopy(VFIODevice *vbasedev)
     return migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ||

hw/vfio/migration.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev)

Quoted 10 lines
hw/vfio/migration.c +7 -1
            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

#83 lore raw

Re: [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c

Quoted 13 lines

hw/vfio/migration.c bool vfio_device_state_is_precopy(VFIODevice *vbasedev)

Quoted 8 lines
hw/vfio/migration.c +6 -1
+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.

Quoted 8 lines

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

Thank you.
---
- Prasad

#84 lore raw

Re: [PATCH for-10.1 25/32] vfio: Move vfio_set_migration_error() into migration.c

Quoted 5 lines · Cédric Le Goater

So you mean open coding :

     if (migration_is_running()) {
         migration_file_set_error(ret, errp);
     }

?

* Yes.

Quoted 10 lines

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

Quoted 8 lines

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

#86 lore raw

PATCH 26/32 vfio: Rename vfio-common.h to vfio-device.h

In reply to 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.

---
 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%)
hw/vfio/migration-multifd.h +1 -1
index a664051eb8ae03bc41cb7f9362ace840f41066ff..0bab63211d30cef04c50e50b3ea57840915ffc2a 100644
@@ -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);
hw/vfio/pci.h +1 -1
index c84bba81487136d205ca30049c812d00e832c377..d33237c275551897164878705d44e7881c372ab0 100644
@@ -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"
include/hw/s390x/vfio-ccw.h +1 -1
index 4209d27657c1fbde44c160445396bcab3f3fd2b0..1e0922dca11e6caada08c2aae82bd3462ace35f5 100644
@@ -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"
include/hw/vfio/vfio-device.h renamed from include/hw/vfio/vfio-common.h +0 -0
similarity index 100%
rename from include/hw/vfio/vfio-common.h
rename to include/hw/vfio/vfio-device.h
include/hw/vfio/vfio-platform.h +1 -1
index 3191545717da51abc41d10cd3646cd047b4a676c..256d8500b70a2e985e975b0895e3cfca435ed8ed 100644
@@ -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"
backends/iommufd.c +1 -1
index d57da44755be3d7fdba74f7dbecfe6d1c89921ba..9587e4d99b131e88674326a5196cfd2079560430 100644
@@ -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>
 
hw/vfio/ap.c +1 -1
index c7ab4ff57ada0ed0e5a76f52b5a05c86ca4fe0b4..4fdb74e33c427595a9b0a4d28b2b5a70df951e4e 100644
@@ -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"
hw/vfio/ccw.c +1 -1
index e5e0d9e3e7ed124f242b3eda345bc973e418a64c..a40169bc85e51406822247f5b3ef6da1f7f92881 100644
@@ -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"
hw/vfio/container-base.c +1 -1
index 83e83ab9e67de8b004dfaf0067e4c466a6c88451..ace9de18103e8c1ed9f7a51adbf16c36be01bd7c 100644
@@ -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 =
hw/vfio/container.c +1 -1
index e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7..e300d2d90f2fbde329609b7c63245c523766fb60 100644
@@ -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"
hw/vfio/cpr.c +1 -1
index e1bba1726402f41ee394f25b6e613d27f44b2a2c..43b99680f6d7db27c4d7e518520aef5ade2ebcf4 100644
@@ -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"
hw/vfio/device.c +1 -1
index e6a1bbcda2297f9e6272fff9b1c228b6772457ce..0d443b53d23d392729cef84e419d3e089fe64298 100644
@@ -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"
hw/vfio/dirty-tracking.c +1 -1
index 447e09ed84993e3fbe1ed9b27a8269a9f0f46339..143cc5cf62b0165565e91f8a2ca166026f16b1eb 100644
@@ -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"
hw/vfio/helpers.c +1 -1
index e99d312a9f5c7462644ea3d0de2e9de38979f851..b7907aab80f8adb308ebae60baa20c911d9393d7 100644
@@ -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"
hw/vfio/iommufd.c +1 -1
index 9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8..7f354d86cd14270a70dc990860ad5b69f0310719 100644
@@ -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"
hw/vfio/migration-multifd.c +1 -1
index 285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db..1ba703e595db99f3786bfc1a2edeb0e061f9e01b 100644
@@ -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"
hw/vfio/migration.c +1 -1
index 6fd825e435bde96d1008ec03dfaba25db3b616fc..338fafb83f41460e0c244dcc27524198322eec67 100644
@@ -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"
hw/vfio/region.c +2 -2
index 87bf5e046a432dfedf3be3c1c7e8f33e006da004..ade4466eb622248b5aa50f9df7e5c683bfa78a11 100644
@@ -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"
Signature · 1 line
2.48.1
#87 lore raw

Re: [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h

Quoted 248 lines · Cédric Le Goater

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.

---
  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%)

hw/vfio/migration-multifd.h +1 -1
index a664051eb8ae03bc41cb7f9362ace840f41066ff..0bab63211d30cef04c50e50b3ea57840915ffc2a 100644
@@ -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);
hw/vfio/pci.h +1 -1
index c84bba81487136d205ca30049c812d00e832c377..d33237c275551897164878705d44e7881c372ab0 100644
@@ -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"
include/hw/s390x/vfio-ccw.h +1 -1
index 4209d27657c1fbde44c160445396bcab3f3fd2b0..1e0922dca11e6caada08c2aae82bd3462ace35f5 100644
@@ -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"
include/hw/vfio/vfio-device.h renamed from include/hw/vfio/vfio-common.h +0 -0
similarity index 100%
rename from include/hw/vfio/vfio-common.h
rename to include/hw/vfio/vfio-device.h
include/hw/vfio/vfio-platform.h +1 -1
index 3191545717da51abc41d10cd3646cd047b4a676c..256d8500b70a2e985e975b0895e3cfca435ed8ed 100644
@@ -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"
backends/iommufd.c +1 -1
index d57da44755be3d7fdba74f7dbecfe6d1c89921ba..9587e4d99b131e88674326a5196cfd2079560430 100644
@@ -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>
 
hw/vfio/ap.c +1 -1
index c7ab4ff57ada0ed0e5a76f52b5a05c86ca4fe0b4..4fdb74e33c427595a9b0a4d28b2b5a70df951e4e 100644
@@ -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"
hw/vfio/ccw.c +1 -1
index e5e0d9e3e7ed124f242b3eda345bc973e418a64c..a40169bc85e51406822247f5b3ef6da1f7f92881 100644
@@ -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"
hw/vfio/container-base.c +1 -1
index 83e83ab9e67de8b004dfaf0067e4c466a6c88451..ace9de18103e8c1ed9f7a51adbf16c36be01bd7c 100644
@@ -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 =
hw/vfio/container.c +1 -1
index e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7..e300d2d90f2fbde329609b7c63245c523766fb60 100644
@@ -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"
hw/vfio/cpr.c +1 -1
index e1bba1726402f41ee394f25b6e613d27f44b2a2c..43b99680f6d7db27c4d7e518520aef5ade2ebcf4 100644
@@ -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"
hw/vfio/device.c +1 -1
index e6a1bbcda2297f9e6272fff9b1c228b6772457ce..0d443b53d23d392729cef84e419d3e089fe64298 100644
@@ -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"
hw/vfio/dirty-tracking.c +1 -1
index 447e09ed84993e3fbe1ed9b27a8269a9f0f46339..143cc5cf62b0165565e91f8a2ca166026f16b1eb 100644
@@ -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"
hw/vfio/helpers.c +1 -1
index e99d312a9f5c7462644ea3d0de2e9de38979f851..b7907aab80f8adb308ebae60baa20c911d9393d7 100644
@@ -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"
hw/vfio/iommufd.c +1 -1
index 9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8..7f354d86cd14270a70dc990860ad5b69f0310719 100644
@@ -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"
hw/vfio/migration-multifd.c +1 -1
index 285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db..1ba703e595db99f3786bfc1a2edeb0e061f9e01b 100644
@@ -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"
hw/vfio/migration.c +1 -1
index 6fd825e435bde96d1008ec03dfaba25db3b616fc..338fafb83f41460e0c244dcc27524198322eec67 100644
@@ -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"
hw/vfio/region.c +0 -0
index 87bf5e046a432dfedf3be3c1c7e8f33e006da004..ade4466eb622248b5aa50f9df7e5c683bfa78a11 100644

hw/vfio/region.c line 25

Quoted 6 lines
hw/vfio/region.c +1 -2
@@ -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.

Quoted 7 lines
hw/vfio/region.c +1 -1
+#include "hw/vfio/vfio-device.h"
  #include "hw/hw.h"
  #include "trace.h"
  #include "qapi/error.h"
--

2.48.1

#88 lore raw

Re: [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h

Quoted 253 lines · Avihai Horon
Quoted 251 lines · Cédric Le Goater

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.

---
  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%)

hw/vfio/migration-multifd.h +1 -1
index a664051eb8ae03bc41cb7f9362ace840f41066ff..0bab63211d30cef04c50e50b3ea57840915ffc2a 100644
@@ -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);
hw/vfio/pci.h +1 -1
index c84bba81487136d205ca30049c812d00e832c377..d33237c275551897164878705d44e7881c372ab0 100644
@@ -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"
include/hw/s390x/vfio-ccw.h +1 -1
index 4209d27657c1fbde44c160445396bcab3f3fd2b0..1e0922dca11e6caada08c2aae82bd3462ace35f5 100644
@@ -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"
include/hw/vfio/vfio-device.h renamed from include/hw/vfio/vfio-common.h +0 -0
similarity index 100%
rename from include/hw/vfio/vfio-common.h
rename to include/hw/vfio/vfio-device.h
include/hw/vfio/vfio-platform.h +1 -1
index 3191545717da51abc41d10cd3646cd047b4a676c..256d8500b70a2e985e975b0895e3cfca435ed8ed 100644
@@ -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"
backends/iommufd.c +1 -1
index d57da44755be3d7fdba74f7dbecfe6d1c89921ba..9587e4d99b131e88674326a5196cfd2079560430 100644
@@ -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>
 
hw/vfio/ap.c +1 -1
index c7ab4ff57ada0ed0e5a76f52b5a05c86ca4fe0b4..4fdb74e33c427595a9b0a4d28b2b5a70df951e4e 100644
@@ -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"
hw/vfio/ccw.c +1 -1
index e5e0d9e3e7ed124f242b3eda345bc973e418a64c..a40169bc85e51406822247f5b3ef6da1f7f92881 100644
@@ -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"
hw/vfio/container-base.c +1 -1
index 83e83ab9e67de8b004dfaf0067e4c466a6c88451..ace9de18103e8c1ed9f7a51adbf16c36be01bd7c 100644
@@ -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 =

hw/vfio/container.c +1 -1
index e88dfe12edd6dee469c06ee2e46ab9c8b5019ae7..e300d2d90f2fbde329609b7c63245c523766fb60 100644
@@ -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"
hw/vfio/cpr.c +1 -1
index e1bba1726402f41ee394f25b6e613d27f44b2a2c..43b99680f6d7db27c4d7e518520aef5ade2ebcf4 100644
@@ -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"
hw/vfio/device.c +1 -1
index e6a1bbcda2297f9e6272fff9b1c228b6772457ce..0d443b53d23d392729cef84e419d3e089fe64298 100644
@@ -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"
hw/vfio/dirty-tracking.c +1 -1
index 447e09ed84993e3fbe1ed9b27a8269a9f0f46339..143cc5cf62b0165565e91f8a2ca166026f16b1eb 100644
@@ -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"
hw/vfio/helpers.c +1 -1
index e99d312a9f5c7462644ea3d0de2e9de38979f851..b7907aab80f8adb308ebae60baa20c911d9393d7 100644
@@ -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"
hw/vfio/iommufd.c +1 -1
index 9335a17920b32dc2bf9cb4eeb2b8f57382f14ac8..7f354d86cd14270a70dc990860ad5b69f0310719 100644
@@ -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"
hw/vfio/migration-multifd.c +1 -1
index 285f9a9a18dd8f0847ac5ac3fdaa304779a2d0db..1ba703e595db99f3786bfc1a2edeb0e061f9e01b 100644
@@ -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"
hw/vfio/migration.c +1 -1
index 6fd825e435bde96d1008ec03dfaba25db3b616fc..338fafb83f41460e0c244dcc27524198322eec67 100644
@@ -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"
hw/vfio/region.c +0 -0
index 87bf5e046a432dfedf3be3c1c7e8f33e006da004..ade4466eb622248b5aa50f9df7e5c683bfa78a11 100644
@@ -22,8 +22,8 @@
   #include "qemu/osdep.h"
   #include <sys/ioctl.h>
 
Quoted 5 lines

hw/vfio/region.c line 25

Quoted 3 lines
hw/vfio/region.c +1 -2
-#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.

Quoted 10 lines

Thanks.

Quoted 7 lines
hw/vfio/region.c +1 -0
+#include "hw/vfio/vfio-device.h"
   #include "hw/hw.h"
   #include "trace.h"
   #include "qapi/error.h"
Signature · 1 line
2.48.1
#89 lore raw

Re: [PATCH for-10.1 26/32] vfio: Rename vfio-common.h to vfio-device.h

In reply to Cédric Le Goater
Quoted 6 lines · 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.

 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

#90 lore raw

PATCH 27/32 vfio: Rename VFIODevice related services

In reply to 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.

---
 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(-)
include/hw/vfio/vfio-device.h +9 -9
index cc20110d9de8ac173b67e6e878d4d61818497426..9566b42f335ca683db668ec9167b94a187eb67fc 100644
@@ -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. */
hw/vfio/ap.c +4 -4
index 4fdb74e33c427595a9b0a4d28b2b5a70df951e4e..9000702aed960ccb69ca67ec052f1ebe11ee1919 100644
@@ -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);
 }
 
hw/vfio/ccw.c +9 -9
index a40169bc85e51406822247f5b3ef6da1f7f92881..490871c075f8db6c8a4a706b22eba966d84f2945 100644
@@ -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) {
hw/vfio/container.c +3 -3
index e300d2d90f2fbde329609b7c63245c523766fb60..77e2934511a2917f6f7cf13f60c8f3ce4a493035 100644
@@ -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);
 }
hw/vfio/device.c +12 -12
index 0d443b53d23d392729cef84e419d3e089fe64298..22b4310b76a7df4864096be188a4b611bac10645 100644
@@ -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;
hw/vfio/display.c +1 -1
index 2c06361c67cb074b88f2649b3b9fd21b7bacf07c..dd12c2aa6042a5ad3a1610b83bbde1d58b732a8c 100644
@@ -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);
hw/vfio/igd.c +4 -4
index 265fffc2aa52d032ba619b1c3759ecebad438033..7ecbb0e672879987c9603a44b3380519b84bdc0e 100644
@@ -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");
hw/vfio/pci.c +24 -24

192 lines not on this page · raw message

hw/vfio/platform.c +5 -5
index 83b53d57149a343a00eb6d6f78c1cbea004dbaa2..4217e870063593a5be840047adf2870e9b2b89e4 100644
@@ -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;
 }
 
hw/vfio/region.c +1 -1
index ade4466eb622248b5aa50f9df7e5c683bfa78a11..669dc098357050932b9e74ad213ff56b62a0b88e 100644
@@ -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;
     }
hw/vfio/trace-events +3 -3
index f3bdcebe938dcca77b913ef81a74644c622b5d8a..39d4947f94dc61e4cff06fe1a6181066e7fc4dc3 100644
@@ -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"
Signature · 1 line
2.48.1
#91 lore raw

Re: [PATCH for-10.1 27/32] vfio: Rename VFIODevice related services

hw/vfio/ap.c static bool vfio_ap_register_irq_notifier(VFIOAPDevice *vapdev, · line 121

Quoted 10 lines · Cédric Le Goater

index 4fdb74e33c427595a9b0a4d28b2b5a70df951e4e..9000702aed960ccb69ca67ec052f1ebe11ee1919 100644

hw/vfio/ap.c +1 -1
@@ -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

#92 lore raw

PATCH 28/32 vfio: Make vfio_devices_query_dirty_bitmap() static

In reply to Cédric Le Goater

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

---
 hw/vfio/dirty-tracking.h | 3 ---
 hw/vfio/dirty-tracking.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
hw/vfio/dirty-tracking.h +0 -3
index 4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a..322af30b0d5370600719594d4aed4c407f7d2295 100644
@@ -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);
 
hw/vfio/dirty-tracking.c +1 -1
index 143cc5cf62b0165565e91f8a2ca166026f16b1eb..9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1 100644
@@ -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;
Signature · 1 line
2.48.1
Reviewed-by on v1 28/32
#93 lore raw

Re: [PATCH for-10.1 28/32] vfio: Make vfio_devices_query_dirty_bitmap() static

Quoted 3 lines · Cédric Le Goater

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

Quoted 32 lines
---
 hw/vfio/dirty-tracking.h | 3 ---
 hw/vfio/dirty-tracking.c | 2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
hw/vfio/dirty-tracking.h +0 -3
index 4b83dc54ab50dabfff040d7cc3db27b80bfe2d3a..322af30b0d5370600719594d4aed4c407f7d2295 100644
@@ -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);
 
hw/vfio/dirty-tracking.c +1 -1
index 143cc5cf62b0165565e91f8a2ca166026f16b1eb..9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1 100644
@@ -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;
#95 lore raw

PATCH 29/32 vfio: Rename VFIOContainer related services

In reply to 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.

---
 hw/vfio/container.c  | 52 ++++++++++++++++++++++----------------------
 hw/vfio/trace-events | 10 +++++----
 2 files changed, 32 insertions(+), 30 deletions(-)
hw/vfio/container.c +26 -26
index 77e2934511a2917f6f7cf13f60c8f3ce4a493035..40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249 100644
@@ -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)
hw/vfio/trace-events +6 -4
index 39d4947f94dc61e4cff06fe1a6181066e7fc4dc3..512f4913b72d9a1e8a04df24318a4947fa361e28 100644
@@ -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"
Signature · 1 line
2.48.1
Reviewed-by on v1 29/32
#96 lore raw

Re: [PATCH for-10.1 29/32] vfio: Rename VFIOContainer related services

Quoted 12 lines · 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

Quoted 3 lines

to better reflect the namespace they belong to.

regards
john

#97 lore raw

PATCH 30/32 vfio: Rename VFIO dirty tracking services

In reply to 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.

---
 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(-)
hw/vfio/dirty-tracking.h +3 -3
index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
@@ -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 */
hw/vfio/container.c +3 -3
index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
@@ -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);
hw/vfio/dirty-tracking.c +22 -22

144 lines not on this page · raw message

hw/vfio/trace-events +1 -1
index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
@@ -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
Signature · 1 line
2.48.1
Reviewed-by on v1 30/32
#98 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 10 lines · 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
Quoted 3 lines

to better reflect the namespace they belong to.

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:

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.

Quoted 225 lines
---
 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(-)
hw/vfio/dirty-tracking.h +3 -3
index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
@@ -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 */
hw/vfio/container.c +3 -3
index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
@@ -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);
hw/vfio/dirty-tracking.c +22 -22
index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
@@ -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);
 }
hw/vfio/trace-events +1 -1
index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
@@ -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
#99 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 28 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 10 lines · 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
Quoted 3 lines

to better reflect the namespace they belong to.

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.

Quoted 7 lines

Having said that:

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.

Quoted 225 lines
Quoted 225 lines
---
  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(-)
hw/vfio/dirty-tracking.h +3 -3
index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644
@@ -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 */
hw/vfio/container.c +3 -3
index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644
@@ -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);
hw/vfio/dirty-tracking.c +22 -22
index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644
@@ -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);
  }
hw/vfio/trace-events +1 -1
index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644
@@ -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
#100 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 56 lines · Avihai Horon
Quoted 35 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 17 lines · 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

Quoted 3 lines

to better reflect the namespace they belong to.

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.

Quoted 7 lines

Having said that:

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

Quoted 7 lines

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 :(

Quoted 276 lines

Thanks.

Quoted 274 lines
Quoted 274 lines

---
  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(-)
hw/vfio/dirty-tracking.h +0 -0

index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644

hw/vfio/dirty-tracking.h +2 -3
@@ -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 */

hw/vfio/container.c +0 -0

index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644

hw/vfio/container.c +2 -2
@@ -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);

          }

hw/vfio/container.c +1 -1
@@ -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);

hw/vfio/dirty-tracking.c +0 -0

index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644

hw/vfio/dirty-tracking.c +5 -6
@@ -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;

hw/vfio/dirty-tracking.c +1 -1
@@ -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))] = {};

hw/vfio/dirty-tracking.c +1 -1
@@ -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;

hw/vfio/dirty-tracking.c +0 -0
@@ -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);

hw/vfio/dirty-tracking.c +2 -2
@@ -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;
      }

hw/vfio/dirty-tracking.c +2 -2
@@ -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);

hw/vfio/dirty-tracking.c +1 -1
@@ -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;

hw/vfio/dirty-tracking.c +1 -1
@@ -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;

hw/vfio/dirty-tracking.c +2 -2
@@ -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);

hw/vfio/dirty-tracking.c +2 -1
@@ -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);

hw/vfio/dirty-tracking.c +1 -1
@@ -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,

hw/vfio/dirty-tracking.c +1 -1
@@ -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);

hw/vfio/dirty-tracking.c +0 -0
@@ -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); }

hw/vfio/trace-events +0 -0

index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644

hw/vfio/trace-events +0 -0
@@ -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
#101 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 65 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 54 lines · Avihai Horon
Quoted 35 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 15 lines · 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                          ->
Quoted 5 lines

vfio_dirty_tracking_query_dirty_bitmap

to better reflect the namespace they belong to.

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.

Quoted 7 lines

Having said that:

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
Quoted 7 lines

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?

Quoted 7 lines

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.

Quoted 277 lines
Quoted 277 lines

Thanks.

Quoted 274 lines
Quoted 274 lines
---
   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(-)
hw/vfio/dirty-tracking.h +0 -0

index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644

hw/vfio/dirty-tracking.h +2 -3
@@ -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 */
hw/vfio/container.c +0 -0

index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644

hw/vfio/container.c +2 -2
@@ -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);
           }
hw/vfio/container.c +1 -1
@@ -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);
hw/vfio/dirty-tracking.c +0 -0

index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644

hw/vfio/dirty-tracking.c +5 -6
@@ -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;
hw/vfio/dirty-tracking.c +1 -1
@@ -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))] = {};

hw/vfio/dirty-tracking.c +1 -1
@@ -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;
hw/vfio/dirty-tracking.c +1 -1
@@ -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);
hw/vfio/dirty-tracking.c +2 -2
@@ -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;
       }
hw/vfio/dirty-tracking.c +2 -2
@@ -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);
hw/vfio/dirty-tracking.c +1 -1
@@ -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;
hw/vfio/dirty-tracking.c +2 -2
@@ -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;
hw/vfio/dirty-tracking.c +2 -2
@@ -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);
hw/vfio/dirty-tracking.c +2 -1
@@ -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);
hw/vfio/dirty-tracking.c +1 -1
@@ -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,
hw/vfio/dirty-tracking.c +1 -1
@@ -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);
hw/vfio/dirty-tracking.c +1 -1
@@ -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);
   }
hw/vfio/trace-events +0 -0

index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644

hw/vfio/trace-events +0 -0
@@ -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
#102 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 78 lines · Avihai Horon
Quoted 68 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 56 lines · Avihai Horon
Quoted 36 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 17 lines · 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

Quoted 3 lines

to better reflect the namespace they belong to.

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.

Quoted 7 lines

Having said that:

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

Quoted 8 lines

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?

Quoted 7 lines

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 :(

Quoted 6 lines

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().

Quoted 285 lines
Quoted 285 lines
Quoted 285 lines

Thanks.

Quoted 282 lines
Quoted 282 lines

---
   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(-)
hw/vfio/dirty-tracking.h +0 -0

index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644

hw/vfio/dirty-tracking.h +2 -3
@@ -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 */

hw/vfio/container.c +0 -0

index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644

hw/vfio/container.c +2 -2
@@ -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);

           }

hw/vfio/container.c +1 -1
@@ -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);

hw/vfio/dirty-tracking.c +0 -0

index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644

hw/vfio/dirty-tracking.c +5 -6
@@ -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;

hw/vfio/dirty-tracking.c +1 -1
@@ -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))] = {};

hw/vfio/dirty-tracking.c +1 -1
@@ -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;

hw/vfio/dirty-tracking.c +0 -0
@@ -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);

hw/vfio/dirty-tracking.c +2 -2
@@ -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;
       }

hw/vfio/dirty-tracking.c +2 -2
@@ -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);

hw/vfio/dirty-tracking.c +1 -1
@@ -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;

hw/vfio/dirty-tracking.c +1 -1
@@ -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;

hw/vfio/dirty-tracking.c +2 -2
@@ -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);

hw/vfio/dirty-tracking.c +1 -1
@@ -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);

hw/vfio/dirty-tracking.c +1 -1
@@ -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,

hw/vfio/dirty-tracking.c +1 -1
@@ -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);

hw/vfio/dirty-tracking.c +0 -0
@@ -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-

Quoted 1 line

offset_within_address_space),

                                    int128_get64(section->size), ram_addr, errp);
   }

hw/vfio/trace-events +0 -0

index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644

hw/vfio/trace-events +0 -0
@@ -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
#103 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 86 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 73 lines · Avihai Horon
Quoted 72 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 56 lines · Avihai Horon
Quoted 36 lines · Joao Martins

External email: Use caution opening links or attachments

Quoted 15 lines · 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                          ->
Quoted 5 lines

vfio_dirty_tracking_query_dirty_bitmap

to better reflect the namespace they belong to.

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.

Quoted 7 lines

Having said that:

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
Quoted 8 lines

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.

Quoted 9 lines
Quoted 3 lines

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.

Quoted 6 lines

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.

Quoted 4 lines

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.

Quoted 285 lines
Quoted 285 lines
Quoted 285 lines
Quoted 285 lines

Thanks.

Quoted 282 lines
Quoted 282 lines
---
    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(-)
hw/vfio/dirty-tracking.h +0 -0

index 322af30b0d5370600719594d4aed4c407f7d2295..db9494202a780108ce78b642950bfed78ba3f253 100644

hw/vfio/dirty-tracking.h +2 -3
@@ -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 */
hw/vfio/container.c +0 -0

index 40d6c1fecbf9c37c22b8c19f8e9e8b6c5c381249..7b3ec798a77052b8cb0b47d3dceaca1428cb50bd 100644

hw/vfio/container.c +2 -2
@@ -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);
            }
hw/vfio/container.c +1 -1
@@ -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);
hw/vfio/dirty-tracking.c +0 -0

index 9b20668a6d0df93a2cfde12d9a5cd7c223ae3ca1..8e47ccbb9aea748e57271508ddcd10e394abf16c 100644

hw/vfio/dirty-tracking.c +5 -6
@@ -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;
hw/vfio/dirty-tracking.c +1 -1
@@ -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))] = {};

hw/vfio/dirty-tracking.c +1 -1
@@ -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;
hw/vfio/dirty-tracking.c +1 -1
@@ -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);
hw/vfio/dirty-tracking.c +2 -2
@@ -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;
        }
hw/vfio/dirty-tracking.c +2 -2
@@ -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);
hw/vfio/dirty-tracking.c +1 -1
@@ -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;
hw/vfio/dirty-tracking.c +2 -2
@@ -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;
hw/vfio/dirty-tracking.c +2 -2
@@ -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);
hw/vfio/dirty-tracking.c +1 -1
@@ -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,

hw/vfio/dirty-tracking.c +2 -1
+                                                 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,
hw/vfio/dirty-tracking.c +1 -1
@@ -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);
hw/vfio/dirty-tracking.c +1 -1
@@ -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);
    }
hw/vfio/trace-events +0 -0

index 512f4913b72d9a1e8a04df24318a4947fa361e28..6cf8ec3530c68e7528eefa80b7c8ecb401319f88 100644

hw/vfio/trace-events +0 -0
@@ -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
#104 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

In reply to Joao Martins
Quoted 11 lines · Joao Martins
Quoted 10 lines · 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
Quoted 7 lines
Quoted 3 lines

to better reflect the namespace they belong to.

The change itself is fine.

But on the other hand, it looks relatively long names, no?

I agree.

Quoted 8 lines

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 ?

Quoted 8 lines

Having said that:

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.

#105 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 34 lines · Cédric Le Goater
Quoted 18 lines · Joao Martins
Quoted 17 lines · 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

Quoted 7 lines
Quoted 3 lines

to better reflect the namespace they belong to.

The change itself is fine.

But on the other hand, it looks relatively long names, no?

I agree.

Quoted 5 lines

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.

Quoted 6 lines
Quoted 3 lines

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.

Quoted 11 lines
Quoted 8 lines

Having said that:

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.

#106 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

Quoted 64 lines · Joao Martins
Quoted 34 lines · Cédric Le Goater
Quoted 18 lines · Joao Martins
Quoted 17 lines · 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

Quoted 7 lines
Quoted 3 lines

to better reflect the namespace they belong to.

The change itself is fine.

But on the other hand, it looks relatively long names, no?

I agree.

Quoted 5 lines

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.

Quoted 6 lines
Quoted 3 lines

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.

Quoted 11 lines
Quoted 8 lines

Having said that:

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

Quoted 4 lines

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.

Quoted 1 line
Reviewed-by on v1 30/32
#107 lore raw

Re: [PATCH for-10.1 30/32] vfio: Rename VFIO dirty tracking services

In reply to Cédric Le Goater
Quoted 10 lines · 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
Quoted 3 lines

to better reflect the namespace they belong to.

regards
john

#108 lore raw

PATCH 31/32 vfio: Introduce vfio_dirty_tracking_un/register() routines

In reply to Cédric Le Goater

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

---
 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(-)
hw/vfio/dirty-tracking.h +2 -2
index db9494202a780108ce78b642950bfed78ba3f253..6d717f0e918e47e341114c82ffc2cf520fc7b079 100644
@@ -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 */
hw/vfio/container.c +3 -8
index 7b3ec798a77052b8cb0b47d3dceaca1428cb50bd..1fcca75caba19353ad3063ae97b20c15f61564e9 100644
@@ -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);
         }
hw/vfio/dirty-tracking.c +20 -1
index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644
@@ -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);
+}
hw/vfio/iommufd.c +2 -7
index 7f354d86cd14270a70dc990860ad5b69f0310719..7737d552f310c54ae2e035198a1a83da8c3199dd 100644
@@ -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;
     }
 
Signature · 1 line
2.48.1
Reviewed-by on v1 31/32
#109 lore raw

Re: [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines

Quoted 4 lines · Cédric Le Goater

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

Quoted 124 lines
---
 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(-)
hw/vfio/dirty-tracking.h +2 -2
index db9494202a780108ce78b642950bfed78ba3f253..6d717f0e918e47e341114c82ffc2cf520fc7b079 100644
@@ -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 */
hw/vfio/container.c +3 -8
index 7b3ec798a77052b8cb0b47d3dceaca1428cb50bd..1fcca75caba19353ad3063ae97b20c15f61564e9 100644
@@ -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);
         }
hw/vfio/dirty-tracking.c +20 -1
index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644
@@ -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);
+}
hw/vfio/iommufd.c +2 -7
index 7f354d86cd14270a70dc990860ad5b69f0310719..7737d552f310c54ae2e035198a1a83da8c3199dd 100644
@@ -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;
     }
 
#110 lore raw

Re: [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines

Quoted 8 lines · Joao Martins
Quoted 4 lines · Cédric Le Goater

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

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.

Quoted 126 lines
Quoted 124 lines
---
 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(-)
hw/vfio/dirty-tracking.h +2 -2
index db9494202a780108ce78b642950bfed78ba3f253..6d717f0e918e47e341114c82ffc2cf520fc7b079 100644
@@ -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 */
hw/vfio/container.c +3 -8
index 7b3ec798a77052b8cb0b47d3dceaca1428cb50bd..1fcca75caba19353ad3063ae97b20c15f61564e9 100644
@@ -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);
         }
hw/vfio/dirty-tracking.c +20 -1
index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644
@@ -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);
+}
hw/vfio/iommufd.c +2 -7
index 7f354d86cd14270a70dc990860ad5b69f0310719..7737d552f310c54ae2e035198a1a83da8c3199dd 100644
@@ -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;
     }
 
#111 lore raw

Re: [PATCH for-10.1 31/32] vfio: Introduce vfio_dirty_tracking_un/register() routines

In reply to Cédric Le Goater
Quoted 2 lines · Cédric Le Goater

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

Patch itself seems fine but

hw/vfio/dirty-tracking.c static void vfio_listener_log_sync(MemoryListener *listener, · line 1270

Quoted 9 lines

index 8e47ccbb9aea748e57271508ddcd10e394abf16c..d7827f7b64adf3e2b41fafd59aab71e0b28c1567 100644

hw/vfio/dirty-tracking.c +1 -1
@@ -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

#112 lore raw

PATCH 32/32 vfio: Rename RAM discard related services

In reply to Cédric Le Goater

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

---
 hw/vfio/dirty-tracking.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/vfio/dirty-tracking.c +6 -6
index d7827f7b64adf3e2b41fafd59aab71e0b28c1567..50699a411de3ecd7424a48c7bb583ce39370a296 100644
@@ -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);
 }
 
Signature · 1 line
2.48.1
#113 lore raw

Re: [PATCH for-10.1 32/32] vfio: Rename RAM discard related services

Quoted 21 lines · Cédric Le Goater

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

---
 hw/vfio/dirty-tracking.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/vfio/dirty-tracking.c +1 -1
index d7827f7b64adf3e2b41fafd59aab71e0b28c1567..50699a411de3ecd7424a48c7bb583ce39370a296 100644
@@ -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);

hw/vfio/dirty-tracking.c static void vfio_register_ram_discard_listener(VFIOContainerBase *bcontainer, · line 341

Quoted 6 lines
hw/vfio/dirty-tracking.c +1 -1
@@ -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