Skip to contentSkip to conversation

hw/vfio/migration: Check base architecture at runtime

PATCH In review Philippe Mathieu-Daudé 4 participants 7 messages Oct 21, 2025 – Jan 12

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/vfio/migration: Check base architecture at runtime

Inline vfio_arch_wants_loading_config_after_iter() and replace the compile time check of the TARGET_ARM definition by a runtime call to target_base_arm().

---
Supersedes: <[email protected]>
Based-on: <[email protected]>
https://lore.kernel.org/qemu-devel/[email protected]/

---
 hw/vfio/vfio-helpers.h      |  2 --
 hw/vfio/helpers.c           | 17 -----------------
 hw/vfio/migration-multifd.c | 12 +++++++++++-
 3 files changed, 11 insertions(+), 20 deletions(-)
hw/vfio/vfio-helpers.h +0 -2
index ce317580800..54a327ffbc0 100644
@@ -32,6 +32,4 @@ 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);
 
-bool vfio_arch_wants_loading_config_after_iter(void);
-
 #endif /* HW_VFIO_VFIO_HELPERS_H */
hw/vfio/helpers.c +0 -17
index 23d13e5db5f..9a5f6215455 100644
@@ -209,20 +209,3 @@ retry:
 
     return info;
 }
-
-bool vfio_arch_wants_loading_config_after_iter(void)
-{
-    /*
-     * Starting the config load only after all iterables were loaded (during
-     * non-iterables loading phase) is required for ARM64 due to this platform
-     * VFIO dependency on interrupt controller being loaded first.
-     *
-     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
-     * the right place in VFIO migration").
-     */
-#if defined(TARGET_ARM)
-    return true;
-#else
-    return false;
-#endif
-}
hw/vfio/migration-multifd.c +11 -1
index e4785031a73..b0eea0de678 100644
@@ -16,6 +16,7 @@
 #include "qemu/error-report.h"
 #include "qemu/lockable.h"
 #include "qemu/main-loop.h"
+#include "qemu/target-info.h"
 #include "qemu/thread.h"
 #include "io/channel-buffer.h"
 #include "migration/qemu-file.h"
@@ -44,7 +45,16 @@ bool vfio_load_config_after_iter(VFIODevice *vbasedev)
     }
 
     assert(vbasedev->migration_load_config_after_iter == ON_OFF_AUTO_AUTO);
-    return vfio_arch_wants_loading_config_after_iter();
+
+    /*
+     * Starting the config load only after all iterables were loaded (during
+     * non-iterables loading phase) is required for ARM64 due to this platform
+     * VFIO dependency on interrupt controller being loaded first.
+     *
+     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
+     * the right place in VFIO migration").
+     */
+    return target_base_arm();
 }
 
 /* type safety */
Signature · 1 line
2.51.0
#1 lore raw
Quoted 3 lines · Philippe Mathieu-Daudé

Inline vfio_arch_wants_loading_config_after_iter() and replace the compile time check of the TARGET_ARM definition by a runtime call to target_base_arm().

What's the value of a runtime check of target ARM ? Please explain.

Quoted 5 lines

---
Supersedes: <[email protected]>
Based-on: <[email protected]>

OK. Will consider when this is merged.

Thanks,

C.

Quoted 73 lines

https://lore.kernel.org/qemu-devel/[email protected]/

---
  hw/vfio/vfio-helpers.h      |  2 --
  hw/vfio/helpers.c           | 17 -----------------
  hw/vfio/migration-multifd.c | 12 +++++++++++-
  3 files changed, 11 insertions(+), 20 deletions(-)
hw/vfio/vfio-helpers.h +0 -2
index ce317580800..54a327ffbc0 100644
@@ -32,6 +32,4 @@ 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);
 
-bool vfio_arch_wants_loading_config_after_iter(void);
-
  #endif /* HW_VFIO_VFIO_HELPERS_H */
hw/vfio/helpers.c +0 -17
index 23d13e5db5f..9a5f6215455 100644
@@ -209,20 +209,3 @@ retry:
 
      return info;
  }
-
-bool vfio_arch_wants_loading_config_after_iter(void)
-{
-    /*
-     * Starting the config load only after all iterables were loaded (during
-     * non-iterables loading phase) is required for ARM64 due to this platform
-     * VFIO dependency on interrupt controller being loaded first.
-     *
-     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
-     * the right place in VFIO migration").
-     */
-#if defined(TARGET_ARM)
-    return true;
-#else
-    return false;
-#endif
-}
hw/vfio/migration-multifd.c +11 -1
index e4785031a73..b0eea0de678 100644
@@ -16,6 +16,7 @@
  #include "qemu/error-report.h"
  #include "qemu/lockable.h"
  #include "qemu/main-loop.h"
+#include "qemu/target-info.h"
  #include "qemu/thread.h"
  #include "io/channel-buffer.h"
  #include "migration/qemu-file.h"
@@ -44,7 +45,16 @@ bool vfio_load_config_after_iter(VFIODevice *vbasedev)
      }
 
      assert(vbasedev->migration_load_config_after_iter == ON_OFF_AUTO_AUTO);
-    return vfio_arch_wants_loading_config_after_iter();
+
+    /*
+     * Starting the config load only after all iterables were loaded (during
+     * non-iterables loading phase) is required for ARM64 due to this platform
+     * VFIO dependency on interrupt controller being loaded first.
+     *
+     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
+     * the right place in VFIO migration").
+     */
+    return target_base_arm();
  }
 
  /* type safety */
#2 lore raw
Quoted 6 lines · Cédric Le Goater
Quoted 3 lines · Philippe Mathieu-Daudé

Inline vfio_arch_wants_loading_config_after_iter() and replace the compile time check of the TARGET_ARM definition by a runtime call to target_base_arm().

What's the value of a runtime check of target ARM ? Please explain.

target_base_arm() returns %true when the ARM and AArch64 targets are used.

Runtime check allow compiling this file once for all targets, allowing to eventually have a single binary targetting them once.

Still I expect this function to be problematic on heterogenous emulation, but we are not quite there yet.

Quoted 92 lines
Quoted 6 lines

---
Supersedes: <[email protected]>
Based-on: <[email protected]>

OK. Will consider when this is merged.

Thanks,

C.

Quoted 75 lines

https://lore.kernel.org/qemu-devel/20251020221508.67413-5- [email protected]/
---
  hw/vfio/vfio-helpers.h      |  2 --
  hw/vfio/helpers.c           | 17 ----------------- hw/vfio/migration-multifd.c | 12 +++++++++++-

  3 files changed, 11 insertions(+), 20 deletions(-)
hw/vfio/vfio-helpers.h +0 -2
index ce317580800..54a327ffbc0 100644
@@ -32,6 +32,4 @@ 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);
-bool vfio_arch_wants_loading_config_after_iter(void);
-
   #endif /* HW_VFIO_VFIO_HELPERS_H */
hw/vfio/helpers.c +0 -5
index 23d13e5db5f..9a5f6215455 100644
@@ -209,20 +209,3 @@ retry:
       return info;
   }
-
-bool vfio_arch_wants_loading_config_after_iter(void)
-{
-    /*
-     * Starting the config load only after all iterables were loaded 

(during
-     * non-iterables loading phase) is required for ARM64 due to this platform
-     * VFIO dependency on interrupt controller being loaded first. -     *
-     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
-     * the right place in VFIO migration").
-     */

hw/vfio/helpers.c +0 -6
-#if defined(TARGET_ARM)
-    return true;
-#else
-    return false;
-#endif
-}
hw/vfio/migration-multifd.c +4 -1
index e4785031a73..b0eea0de678 100644
@@ -16,6 +16,7 @@
   #include "qemu/error-report.h"
   #include "qemu/lockable.h"
   #include "qemu/main-loop.h"
+#include "qemu/target-info.h"
   #include "qemu/thread.h"
   #include "io/channel-buffer.h"
   #include "migration/qemu-file.h"
@@ -44,7 +45,16 @@ bool vfio_load_config_after_iter(VFIODevice *vbasedev)
       }
       assert(vbasedev->migration_load_config_after_iter == ON_OFF_AUTO_AUTO);
-    return vfio_arch_wants_loading_config_after_iter();
+
+    /*
+     * Starting the config load only after all iterables were loaded 

(during
+     * non-iterables loading phase) is required for ARM64 due to this platform
+     * VFIO dependency on interrupt controller being loaded first. +     *
+     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
+     * the right place in VFIO migration").
+     */
+    return target_base_arm();
  }
  /* type safety */

#3 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Cédric Le Goater
Quoted 3 lines · Philippe Mathieu-Daudé

Inline vfio_arch_wants_loading_config_after_iter() and replace the compile time check of the TARGET_ARM definition by a runtime call to target_base_arm().

Quoted 7 lines
Quoted 1 line

What's the value of a runtime check of target ARM ? Please explain.

target_base_arm() returns %true when the ARM and AArch64 targets are used.

Runtime check allow compiling this file once for all targets, allowing to eventually have a single binary targetting them once.

Do you want to update the commit log ?

Quoted 2 lines

Still I expect this function to be problematic on heterogenous emulation, but we are not quite there yet.

ok. So we can still take the patch I guess.

Thanks,

C.

#4 lore raw
In reply to Philippe Mathieu-Daudé

Maciej,

Could we have a Ack from you ?

Thanks,

C.

Quoted 81 lines · Philippe Mathieu-Daudé

Inline vfio_arch_wants_loading_config_after_iter() and replace the compile time check of the TARGET_ARM definition by a runtime call to target_base_arm().

---
Supersedes: <[email protected]>
Based-on: <[email protected]>
https://lore.kernel.org/qemu-devel/[email protected]/

---
  hw/vfio/vfio-helpers.h      |  2 --
  hw/vfio/helpers.c           | 17 -----------------
  hw/vfio/migration-multifd.c | 12 +++++++++++-
  3 files changed, 11 insertions(+), 20 deletions(-)
hw/vfio/vfio-helpers.h +0 -2
index ce317580800..54a327ffbc0 100644
@@ -32,6 +32,4 @@ 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);
 
-bool vfio_arch_wants_loading_config_after_iter(void);
-
  #endif /* HW_VFIO_VFIO_HELPERS_H */
hw/vfio/helpers.c +0 -17
index 23d13e5db5f..9a5f6215455 100644
@@ -209,20 +209,3 @@ retry:
 
      return info;
  }
-
-bool vfio_arch_wants_loading_config_after_iter(void)
-{
-    /*
-     * Starting the config load only after all iterables were loaded (during
-     * non-iterables loading phase) is required for ARM64 due to this platform
-     * VFIO dependency on interrupt controller being loaded first.
-     *
-     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
-     * the right place in VFIO migration").
-     */
-#if defined(TARGET_ARM)
-    return true;
-#else
-    return false;
-#endif
-}
hw/vfio/migration-multifd.c +11 -1
index e4785031a73..b0eea0de678 100644
@@ -16,6 +16,7 @@
  #include "qemu/error-report.h"
  #include "qemu/lockable.h"
  #include "qemu/main-loop.h"
+#include "qemu/target-info.h"
  #include "qemu/thread.h"
  #include "io/channel-buffer.h"
  #include "migration/qemu-file.h"
@@ -44,7 +45,16 @@ bool vfio_load_config_after_iter(VFIODevice *vbasedev)
      }
 
      assert(vbasedev->migration_load_config_after_iter == ON_OFF_AUTO_AUTO);
-    return vfio_arch_wants_loading_config_after_iter();
+
+    /*
+     * Starting the config load only after all iterables were loaded (during
+     * non-iterables loading phase) is required for ARM64 due to this platform
+     * VFIO dependency on interrupt controller being loaded first.
+     *
+     * See commit d329f5032e17 ("vfio: Move the saving of the config space to
+     * the right place in VFIO migration").
+     */
+    return target_base_arm();
  }
 
  /* type safety */
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

Date: Tue, 21 Oct 2025 18:17:07 +0200
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v2] hw/vfio/migration: Check base architecture at runtime
X-Mailer: git-send-email 2.51.0

Inline vfio_arch_wants_loading_config_after_iter() and replace the compile time check of the TARGET_ARM definition by a runtime call to target_base_arm().

---
Supersedes: <[email protected]>
Based-on: <[email protected]>
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 5 lines
---
 hw/vfio/vfio-helpers.h      |  2 --
 hw/vfio/helpers.c           | 17 -----------------
 hw/vfio/migration-multifd.c | 12 +++++++++++-
 3 files changed, 11 insertions(+), 20 deletions(-)

(Checked with [email protected])

LGTM, so,

Zhao Liu <[email protected]>