Skip to contentSkip to conversation

hw/vfio: Build various objects once

PATCH Superseded Philippe Mathieu-Daudé 5 participants 57 messages Mar 7, 2025 – Mar 8, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover hw/vfio: Build various objects once

By doing the following changes:
- Clean some headers up
- Replace compile-time CONFIG_KVM check by kvm_enabled()
- Replace compile-time CONFIG_IOMMUFD check by iommufd_builtin() we can build less vfio objects.

Philippe Mathieu-Daudé (14):
hw/vfio/common: Include missing 'system/tcg.h' header hw/vfio/spapr: Do not include <linux/kvm.h>
hw/vfio: Compile some common objects once
hw/vfio: Compile more objects once
hw/vfio: Compile iommufd.c once
system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h' hw/vfio: Compile display.c once
system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier() hw/vfio/pci: Convert CONFIG_KVM check to runtime one system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using
iommufd_builtin

 docs/devel/vfio-iommufd.rst  |  2 +-
 include/exec/ram_addr.h      |  3 --
 include/system/hostmem.h     |  3 ++
 include/system/iommufd.h     |  8 +++++
 include/system/kvm.h         |  8 ++---
 target/s390x/kvm/kvm_s390x.h |  2 +-
 accel/stubs/kvm-stub.c       | 12 ++++++++
 hw/ppc/spapr_caps.c          |  1 +
 hw/s390x/s390-virtio-ccw.c   |  1 +
 hw/vfio/ap.c                 | 27 ++++++++---------
 hw/vfio/ccw.c                | 27 ++++++++---------
 hw/vfio/common.c             |  1 +
 hw/vfio/iommufd.c            |  1 -
 hw/vfio/migration.c          |  1 -
 hw/vfio/pci.c                | 57 +++++++++++++++++-------------------
 hw/vfio/platform.c           | 25 ++++++++--------
 hw/vfio/spapr.c              |  4 +--
 hw/vfio/meson.build          | 33 ++++++++++++---------
 18 files changed, 117 insertions(+), 99 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/14 hw/vfio/common: Include missing 'system/tcg.h' header

Always include necessary headers explicitly, to avoid when refactoring unrelated ones:

hw/vfio/common.c:1176:45: error: implicit declaration of function ‘tcg_enabled’;

   1176 |                                             tcg_enabled() ? DIRTY_CLIENTS_ALL :
        |                                             ^~~~~~~~~~~
---
 hw/vfio/common.c | 1 +
 1 file changed, 1 insertion(+)
hw/vfio/common.c +1 -0
index 7a4010ef4ee..b1596b6bf64 100644
@@ -42,6 +42,7 @@
 #include "migration/misc.h"
 #include "migration/blocker.h"
 #include "migration/qemu-file.h"
+#include "system/tcg.h"
 #include "system/tpm.h"
 
 VFIODeviceList vfio_device_list =
Signature · 1 line
2.47.1
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] hw/vfio/common: Include missing 'system/tcg.h' header

Quoted 17 lines · Philippe Mathieu-Daudé

Always include necessary headers explicitly, to avoid when refactoring unrelated ones:

hw/vfio/common.c:1176:45: error: implicit declaration of function ‘tcg_enabled’;

    1176 |                                             tcg_enabled() ? DIRTY_CLIENTS_ALL :
         |                                             ^~~~~~~~~~~
---
  hw/vfio/common.c | 1 +
  1 file changed, 1 insertion(+)
hw/vfio/common.c +0 -0
index 7a4010ef4ee..b1596b6bf64 100644

hw/vfio/common.c line 48

Quoted 7 lines
hw/vfio/common.c +1 -0
@@ -42,6 +42,7 @@
  #include "migration/misc.h"
  #include "migration/blocker.h"
  #include "migration/qemu-file.h"
+#include "system/tcg.h"
  #include "system/tpm.h"
 
  VFIODeviceList vfio_device_list =
Reviewed-by on v1 1/14
#3 lore raw

Re: [PATCH 01/14] hw/vfio/common: Include missing 'system/tcg.h' header

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Always include necessary headers explicitly, to avoid when refactoring unrelated ones:

hw/vfio/common.c:1176:45: error: implicit declaration of function ‘tcg_enabled’;

    1176 |                                             tcg_enabled() ? DIRTY_CLIENTS_ALL :
         |                                             ^~~~~~~~~~~
---
  hw/vfio/common.c | 1 +
  1 file changed, 1 insertion(+)

r~

Reviewed-by on v1 1/14
#4 lore raw

Re: [PATCH 01/14] hw/vfio/common: Include missing 'system/tcg.h' header

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Always include necessary headers explicitly, to avoid when refactoring unrelated ones:

hw/vfio/common.c:1176:45: error: implicit declaration of function ‘tcg_enabled’;

    1176 |                                             tcg_enabled() ? DIRTY_CLIENTS_ALL :
         |                                             ^~~~~~~~~~~

Thanks,

C.

Quoted 16 lines
---
  hw/vfio/common.c | 1 +
  1 file changed, 1 insertion(+)
hw/vfio/common.c +1 -0
index 7a4010ef4ee..b1596b6bf64 100644
@@ -42,6 +42,7 @@
  #include "migration/misc.h"
  #include "migration/blocker.h"
  #include "migration/qemu-file.h"
+#include "system/tcg.h"
  #include "system/tpm.h"
 
  VFIODeviceList vfio_device_list =
#5 lore raw

PATCH 2/14 hw/vfio/spapr: Do not include <linux/kvm.h>

In reply to Philippe Mathieu-Daudé

<linux/kvm.h> is already include by "system/kvm.h" in the next line.

---
 hw/vfio/spapr.c | 3 ---
 1 file changed, 3 deletions(-)
hw/vfio/spapr.c +0 -3
index ad4c499eafe..9b5ad05bb1c 100644
@@ -11,9 +11,6 @@
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
-#ifdef CONFIG_KVM
-#include <linux/kvm.h>
-#endif
 #include "system/kvm.h"
 #include "exec/address-spaces.h"
 
Signature · 1 line
2.47.1
Reviewed-by on v1 2/14
#6 lore raw

Re: [PATCH 02/14] hw/vfio/spapr: Do not include <linux/kvm.h>

Quoted 12 lines · Philippe Mathieu-Daudé

<linux/kvm.h> is already include by "system/kvm.h" in the next line.

---
  hw/vfio/spapr.c | 3 ---
  1 file changed, 3 deletions(-)
hw/vfio/spapr.c +0 -0
index ad4c499eafe..9b5ad05bb1c 100644

hw/vfio/spapr.c line 16

Quoted 9 lines
hw/vfio/spapr.c +0 -3
@@ -11,9 +11,6 @@
  #include "qemu/osdep.h"
  #include <sys/ioctl.h>
  #include <linux/vfio.h>
-#ifdef CONFIG_KVM
-#include <linux/kvm.h>
-#endif
  #include "system/kvm.h"
  #include "exec/address-spaces.h"
 
Reviewed-by on v1 2/14
#8 lore raw

Re: [PATCH 02/14] hw/vfio/spapr: Do not include <linux/kvm.h>

In reply to Philippe Mathieu-Daudé
Quoted 3 lines · Philippe Mathieu-Daudé

<linux/kvm.h> is already include by "system/kvm.h" in the next line.

Thanks,

C.

Quoted 18 lines
---
  hw/vfio/spapr.c | 3 ---
  1 file changed, 3 deletions(-)
hw/vfio/spapr.c +0 -3
index ad4c499eafe..9b5ad05bb1c 100644
@@ -11,9 +11,6 @@
  #include "qemu/osdep.h"
  #include <sys/ioctl.h>
  #include <linux/vfio.h>
-#ifdef CONFIG_KVM
-#include <linux/kvm.h>
-#endif
  #include "system/kvm.h"
  #include "exec/address-spaces.h"
 
#9 lore raw

PATCH 3/14 hw/vfio: Compile some common objects once

In reply to Philippe Mathieu-Daudé

Some files don't rely on any target-specific knowledge and can be compiled once:

- helpers.c
- container-base.c
- migration.c (removing unnecessary "exec/ram_addr.h")
- migration-multifd.c
- cpr.c

---
 hw/vfio/migration.c |  1 -
 hw/vfio/meson.build | 13 ++++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
hw/vfio/migration.c +0 -1
index 416643ddd69..fbff46cfc35 100644
@@ -27,7 +27,6 @@
 #include "qapi/error.h"
 #include "qapi/qapi-events-vfio.h"
 #include "exec/ramlist.h"
-#include "exec/ram_addr.h"
 #include "pci.h"
 #include "trace.h"
 #include "hw/hw.h"
hw/vfio/meson.build +8 -5
index 260d65febd6..8e376cfcbf8 100644
@@ -1,12 +1,7 @@
 vfio_ss = ss.source_set()
 vfio_ss.add(files(
-  'helpers.c',
   'common.c',
-  'container-base.c',
   'container.c',
-  'migration.c',
-  'migration-multifd.c',
-  'cpr.c',
 ))
 vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
 vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
@@ -25,3 +20,11 @@ vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c'))
 
 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
+
+system_ss.add(when: 'CONFIG_VFIO', if_true: files(
+  'helpers.c',
+  'container-base.c',
+  'migration.c',
+  'migration-multifd.c',
+  'cpr.c',
+))
Signature · 1 line
2.47.1
Reviewed-by on v1 3/14
#10 lore raw

Re: [PATCH 03/14] hw/vfio: Compile some common objects once

Quoted 46 lines · Philippe Mathieu-Daudé

Some files don't rely on any target-specific knowledge and can be compiled once:

- helpers.c
- container-base.c
- migration.c (removing unnecessary "exec/ram_addr.h")
- migration-multifd.c
- cpr.c

---
  hw/vfio/migration.c |  1 -
  hw/vfio/meson.build | 13 ++++++++-----
  2 files changed, 8 insertions(+), 6 deletions(-)
hw/vfio/migration.c +0 -1
index 416643ddd69..fbff46cfc35 100644
@@ -27,7 +27,6 @@
  #include "qapi/error.h"
  #include "qapi/qapi-events-vfio.h"
  #include "exec/ramlist.h"
-#include "exec/ram_addr.h"
  #include "pci.h"
  #include "trace.h"
  #include "hw/hw.h"
hw/vfio/meson.build +0 -5
index 260d65febd6..8e376cfcbf8 100644
@@ -1,12 +1,7 @@
  vfio_ss = ss.source_set()
  vfio_ss.add(files(
-  'helpers.c',
    'common.c',
-  'container-base.c',
    'container.c',
-  'migration.c',
-  'migration-multifd.c',
-  'cpr.c',
  ))
  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
  vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
@@ -25,3 +20,11 @@ vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c'))

hw/vfio/meson.build vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c')) · line 30

Quoted 10 lines
hw/vfio/meson.build +8 -0
 
  specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
+
+system_ss.add(when: 'CONFIG_VFIO', if_true: files(
+  'helpers.c',
+  'container-base.c',
+  'migration.c',
+  'migration-multifd.c',
+  'cpr.c',
+))
Reviewed-by on v1 3/14
#11 lore raw

Re: [PATCH 03/14] hw/vfio: Compile some common objects once

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Some files don't rely on any target-specific knowledge and can be compiled once:

- helpers.c
- container-base.c
- migration.c (removing unnecessary "exec/ram_addr.h")
- migration-multifd.c
- cpr.c

Quoted 5 lines
---
  hw/vfio/migration.c |  1 -
  hw/vfio/meson.build | 13 ++++++++-----
  2 files changed, 8 insertions(+), 6 deletions(-)

r~

Reviewed-by on v1 3/14
#12 lore raw

Re: [PATCH 03/14] hw/vfio: Compile some common objects once

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Some files don't rely on any target-specific knowledge and can be compiled once:

- helpers.c
- container-base.c
- migration.c (removing unnecessary "exec/ram_addr.h")
- migration-multifd.c
- cpr.c

Thanks,

C.

Quoted 46 lines
---
  hw/vfio/migration.c |  1 -
  hw/vfio/meson.build | 13 ++++++++-----
  2 files changed, 8 insertions(+), 6 deletions(-)
hw/vfio/migration.c +0 -1
index 416643ddd69..fbff46cfc35 100644
@@ -27,7 +27,6 @@
  #include "qapi/error.h"
  #include "qapi/qapi-events-vfio.h"
  #include "exec/ramlist.h"
-#include "exec/ram_addr.h"
  #include "pci.h"
  #include "trace.h"
  #include "hw/hw.h"
hw/vfio/meson.build +8 -5
index 260d65febd6..8e376cfcbf8 100644
@@ -1,12 +1,7 @@
  vfio_ss = ss.source_set()
  vfio_ss.add(files(
-  'helpers.c',
    'common.c',
-  'container-base.c',
    'container.c',
-  'migration.c',
-  'migration-multifd.c',
-  'cpr.c',
  ))
  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
  vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
@@ -25,3 +20,11 @@ vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c'))
 
  specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
+
+system_ss.add(when: 'CONFIG_VFIO', if_true: files(
+  'helpers.c',
+  'container-base.c',
+  'migration.c',
+  'migration-multifd.c',
+  'cpr.c',
+))
#13 lore raw

PATCH 4/14 hw/vfio: Compile more objects once

In reply to Philippe Mathieu-Daudé

These files depend on the VFIO symbol in their Kconfig definition. They don't rely on target specific definitions, move them to system_ss[] to build them once.

---
 hw/vfio/meson.build | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/vfio/meson.build +3 -3
index 8e376cfcbf8..2972c6ff8de 100644
@@ -14,13 +14,13 @@ vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
 ))
 vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c'))
 
 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_IGD', if_true: files('igd.c'))
 system_ss.add(when: 'CONFIG_VFIO', if_true: files(
   'helpers.c',
   'container-base.c',
Signature · 1 line
2.47.1
Reviewed-by on v1 4/14
#14 lore raw

Re: [PATCH 04/14] hw/vfio: Compile more objects once

Quoted 20 lines · Philippe Mathieu-Daudé

These files depend on the VFIO symbol in their Kconfig definition. They don't rely on target specific definitions, move them to system_ss[] to build them once.

---
  hw/vfio/meson.build | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
hw/vfio/meson.build +0 -2
index 8e376cfcbf8..2972c6ff8de 100644
@@ -14,13 +14,13 @@ vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
  ))
  vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))

hw/vfio/meson.build vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( · line 26

Quoted 10 lines
hw/vfio/meson.build +3 -1
-vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c'))
 
  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_IGD', if_true: files('igd.c'))
  system_ss.add(when: 'CONFIG_VFIO', if_true: files(
    'helpers.c',
    'container-base.c',
Reviewed-by on v1 4/14
#15 lore raw

Re: [PATCH 04/14] hw/vfio: Compile more objects once

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

These files depend on the VFIO symbol in their Kconfig definition. They don't rely on target specific definitions, move them to system_ss[] to build them once.

---
  hw/vfio/meson.build | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

r~

Reviewed-by on v1 4/14
#16 lore raw

Re: [PATCH 04/14] hw/vfio: Compile more objects once

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

These files depend on the VFIO symbol in their Kconfig definition. They don't rely on target specific definitions, move them to system_ss[] to build them once.

Thanks,

C.

Quoted 25 lines
---
  hw/vfio/meson.build | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
hw/vfio/meson.build +3 -3
index 8e376cfcbf8..2972c6ff8de 100644
@@ -14,13 +14,13 @@ vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
  ))
  vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_XGMAC', if_true: files('calxeda-xgmac.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_AMD_XGBE', if_true: files('amd-xgbe.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files('igd.c'))
 
  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_IGD', if_true: files('igd.c'))
  system_ss.add(when: 'CONFIG_VFIO', if_true: files(
    'helpers.c',
    'container-base.c',
#17 lore raw

PATCH 5/14 hw/vfio: Compile iommufd.c once

In reply to Philippe Mathieu-Daudé

Removing unused "exec/ram_addr.h" header allow to compile iommufd.c once for all targets.

---
 hw/vfio/iommufd.c   | 1 -
 hw/vfio/meson.build | 6 +++---
 2 files changed, 3 insertions(+), 4 deletions(-)
hw/vfio/iommufd.c +0 -1
index df61edffc08..42c8412bbf5 100644
@@ -25,7 +25,6 @@
 #include "qemu/cutils.h"
 #include "qemu/chardev_open.h"
 #include "pci.h"
-#include "exec/ram_addr.h"
 
 static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                             ram_addr_t size, void *vaddr, bool readonly)
hw/vfio/meson.build +3 -3
index 2972c6ff8de..fea6dbe88cd 100644
@@ -4,9 +4,6 @@ vfio_ss.add(files(
   'container.c',
 ))
 vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
-vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
-  'iommufd.c',
-))
 vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'display.c',
   'pci-quirks.c',
@@ -28,3 +25,6 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
   'migration-multifd.c',
   'cpr.c',
 ))
+system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
+  'iommufd.c',
+))
Signature · 1 line
2.47.1
Reviewed-by on v1 5/14
#18 lore raw

Re: [PATCH 05/14] hw/vfio: Compile iommufd.c once

Quoted 36 lines · Philippe Mathieu-Daudé

Removing unused "exec/ram_addr.h" header allow to compile iommufd.c once for all targets.

---
  hw/vfio/iommufd.c   | 1 -
  hw/vfio/meson.build | 6 +++---
  2 files changed, 3 insertions(+), 4 deletions(-)
hw/vfio/iommufd.c +0 -1
index df61edffc08..42c8412bbf5 100644
@@ -25,7 +25,6 @@
  #include "qemu/cutils.h"
  #include "qemu/chardev_open.h"
  #include "pci.h"
-#include "exec/ram_addr.h"
 
  static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                              ram_addr_t size, void *vaddr, bool readonly)
hw/vfio/meson.build +0 -3
index 2972c6ff8de..fea6dbe88cd 100644
@@ -4,9 +4,6 @@ vfio_ss.add(files(
    'container.c',
  ))
  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
-vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
-  'iommufd.c',
-))
  vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'display.c',
    'pci-quirks.c',

hw/vfio/meson.build system_ss.add(when: 'CONFIG_VFIO', if_true: files( · line 30

Quoted 6 lines
hw/vfio/meson.build +3 -0
@@ -28,3 +25,6 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
    'migration-multifd.c',
    'cpr.c',
  ))
+system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
+  'iommufd.c',
+))
Reviewed-by on v1 5/14
#19 lore raw

Re: [PATCH 05/14] hw/vfio: Compile iommufd.c once

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Removing unused "exec/ram_addr.h" header allow to compile iommufd.c once for all targets.

---
  hw/vfio/iommufd.c   | 1 -
  hw/vfio/meson.build | 6 +++---
  2 files changed, 3 insertions(+), 4 deletions(-)

r~

Reviewed-by on v1 5/14
#20 lore raw

Re: [PATCH 05/14] hw/vfio: Compile iommufd.c once

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Removing unused "exec/ram_addr.h" header allow to compile iommufd.c once for all targets.

Thanks,

C.

Quoted 38 lines
---
  hw/vfio/iommufd.c   | 1 -
  hw/vfio/meson.build | 6 +++---
  2 files changed, 3 insertions(+), 4 deletions(-)
hw/vfio/iommufd.c +0 -1
index df61edffc08..42c8412bbf5 100644
@@ -25,7 +25,6 @@
  #include "qemu/cutils.h"
  #include "qemu/chardev_open.h"
  #include "pci.h"
-#include "exec/ram_addr.h"
 
  static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                              ram_addr_t size, void *vaddr, bool readonly)
hw/vfio/meson.build +3 -3
index 2972c6ff8de..fea6dbe88cd 100644
@@ -4,9 +4,6 @@ vfio_ss.add(files(
    'container.c',
  ))
  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
-vfio_ss.add(when: 'CONFIG_IOMMUFD', if_true: files(
-  'iommufd.c',
-))
  vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'display.c',
    'pci-quirks.c',
@@ -28,3 +25,6 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
    'migration-multifd.c',
    'cpr.c',
  ))
+system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
+  'iommufd.c',
+))
#21 lore raw

PATCH 6/14 system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h'

In reply to Philippe Mathieu-Daudé

Both qemu_minrampagesize() and qemu_maxrampagesize() are related to host memory backends. Move their prototype declaration to "system/hostmem.h".

---
 include/exec/ram_addr.h    | 3 ---
 include/system/hostmem.h   | 3 +++
 hw/ppc/spapr_caps.c        | 1 +
 hw/s390x/s390-virtio-ccw.c | 1 +
 hw/vfio/spapr.c            | 1 +
 5 files changed, 6 insertions(+), 3 deletions(-)
include/exec/ram_addr.h +0 -3
index 94bb3ccbe42..ccc8df561af 100644
@@ -101,9 +101,6 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
 
 bool ramblock_is_pmem(RAMBlock *rb);
 
-long qemu_minrampagesize(void);
-long qemu_maxrampagesize(void);
-
 /**
  * qemu_ram_alloc_from_file,
  * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
include/system/hostmem.h +3 -0
index 5c21ca55c01..62642e602ca 100644
@@ -93,4 +93,7 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
 size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
 char *host_memory_backend_get_name(HostMemoryBackend *backend);
 
+long qemu_minrampagesize(void);
+long qemu_maxrampagesize(void);
+
 #endif
hw/ppc/spapr_caps.c +1 -0
index 904bff87ce1..9e53d0c1fd1 100644
@@ -34,6 +34,7 @@
 #include "kvm_ppc.h"
 #include "migration/vmstate.h"
 #include "system/tcg.h"
+#include "system/hostmem.h"
 
 #include "hw/ppc/spapr.h"
 
hw/s390x/s390-virtio-ccw.c +1 -0
index 51ae0c133d8..1261d93b7ce 100644
@@ -41,6 +41,7 @@
 #include "hw/s390x/tod.h"
 #include "system/system.h"
 #include "system/cpus.h"
+#include "system/hostmem.h"
 #include "target/s390x/kvm/pv.h"
 #include "migration/blocker.h"
 #include "qapi/visitor.h"
hw/vfio/spapr.c +1 -0
index 9b5ad05bb1c..1a5d1611f2c 100644
@@ -12,6 +12,7 @@
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
 #include "system/kvm.h"
+#include "system/hostmem.h"
 #include "exec/address-spaces.h"
 
 #include "hw/vfio/vfio-common.h"
Signature · 1 line
2.47.1
Reviewed-by on v1 6/14
#22 lore raw

Re: [PATCH 06/14] system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h'

Quoted 68 lines · Philippe Mathieu-Daudé

Both qemu_minrampagesize() and qemu_maxrampagesize() are related to host memory backends. Move their prototype declaration to "system/hostmem.h".

---
  include/exec/ram_addr.h    | 3 ---
  include/system/hostmem.h   | 3 +++
  hw/ppc/spapr_caps.c        | 1 +
  hw/s390x/s390-virtio-ccw.c | 1 +
  hw/vfio/spapr.c            | 1 +
  5 files changed, 6 insertions(+), 3 deletions(-)
include/exec/ram_addr.h +0 -3
index 94bb3ccbe42..ccc8df561af 100644
@@ -101,9 +101,6 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
 
  bool ramblock_is_pmem(RAMBlock *rb);
 
-long qemu_minrampagesize(void);
-long qemu_maxrampagesize(void);
-
  /**
   * qemu_ram_alloc_from_file,
   * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified backing
include/system/hostmem.h +3 -0
index 5c21ca55c01..62642e602ca 100644
@@ -93,4 +93,7 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend);
  size_t host_memory_backend_pagesize(HostMemoryBackend *memdev);
  char *host_memory_backend_get_name(HostMemoryBackend *backend);
 
+long qemu_minrampagesize(void);
+long qemu_maxrampagesize(void);
+
  #endif
hw/ppc/spapr_caps.c +1 -0
index 904bff87ce1..9e53d0c1fd1 100644
@@ -34,6 +34,7 @@
  #include "kvm_ppc.h"
  #include "migration/vmstate.h"
  #include "system/tcg.h"
+#include "system/hostmem.h"
 
  #include "hw/ppc/spapr.h"
 
hw/s390x/s390-virtio-ccw.c +1 -0
index 51ae0c133d8..1261d93b7ce 100644
@@ -41,6 +41,7 @@
  #include "hw/s390x/tod.h"
  #include "system/system.h"
  #include "system/cpus.h"
+#include "system/hostmem.h"
  #include "target/s390x/kvm/pv.h"
  #include "migration/blocker.h"
  #include "qapi/visitor.h"
hw/vfio/spapr.c +0 -0
index 9b5ad05bb1c..1a5d1611f2c 100644

hw/vfio/spapr.c line 18

Quoted 7 lines
hw/vfio/spapr.c +1 -0
@@ -12,6 +12,7 @@
  #include <sys/ioctl.h>
  #include <linux/vfio.h>
  #include "system/kvm.h"
+#include "system/hostmem.h"
  #include "exec/address-spaces.h"
 
  #include "hw/vfio/vfio-common.h"
#23 lore raw

Re: [PATCH 06/14] system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h'

In reply to Philippe Mathieu-Daudé
Quoted 3 lines · Philippe Mathieu-Daudé

Both qemu_minrampagesize() and qemu_maxrampagesize() are related to host memory backends. Move their prototype declaration to "system/hostmem.h".

qemu_minrampagesize()

     -> find_min_backend_pagesize()
         -> object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)

qemu_maxrampagesize()

     -> find_max_backend_pagesize()
        -> object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)

Having:

include/system/hostmem.h:23:#define TYPE_MEMORY_BACKEND "memory-backend"

Quoted 8 lines
---
  include/exec/ram_addr.h    | 3 ---
  include/system/hostmem.h   | 3 +++
  hw/ppc/spapr_caps.c        | 1 +
  hw/s390x/s390-virtio-ccw.c | 1 +
  hw/vfio/spapr.c            | 1 +
  5 files changed, 6 insertions(+), 3 deletions(-)
#24 lore raw

PATCH 7/14 hw/vfio: Compile display.c once

In reply to Philippe Mathieu-Daudé

display.c doesn't rely on target specific definitions, move it to system_ss[] to build it once.

---
 hw/vfio/meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/meson.build +3 -1
index fea6dbe88cd..96e342aa8cb 100644
@@ -5,7 +5,6 @@ vfio_ss.add(files(
 ))
 vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
-  'display.c',
   'pci-quirks.c',
   'pci.c',
 ))
@@ -28,3 +27,6 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
 system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
   'iommufd.c',
 ))
+system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
+  'display.c',
+))
Signature · 1 line
2.47.1
Reviewed-by on v1 7/14
#25 lore raw

Re: [PATCH 07/14] hw/vfio: Compile display.c once

Quoted 21 lines · Philippe Mathieu-Daudé

display.c doesn't rely on target specific definitions, move it to system_ss[] to build it once.

---
  hw/vfio/meson.build | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/meson.build +0 -1
index fea6dbe88cd..96e342aa8cb 100644
@@ -5,7 +5,6 @@ vfio_ss.add(files(
  ))
  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
-  'display.c',
    'pci-quirks.c',
    'pci.c',
  ))

hw/vfio/meson.build system_ss.add(when: 'CONFIG_VFIO', if_true: files( · line 32

Quoted 6 lines
hw/vfio/meson.build +3 -0
@@ -28,3 +27,6 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
  system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
    'iommufd.c',
  ))
+system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
+  'display.c',
+))
Reviewed-by on v1 7/14
#27 lore raw

Re: [PATCH 07/14] hw/vfio: Compile display.c once

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

display.c doesn't rely on target specific definitions, move it to system_ss[] to build it once.

Thanks,

C.

Quoted 23 lines
---
  hw/vfio/meson.build | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/meson.build +3 -1
index fea6dbe88cd..96e342aa8cb 100644
@@ -5,7 +5,6 @@ vfio_ss.add(files(
  ))
  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
-  'display.c',
    'pci-quirks.c',
    'pci.c',
  ))
@@ -28,3 +27,6 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
  system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
    'iommufd.c',
  ))
+system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
+  'display.c',
+))
#28 lore raw

PATCH 8/14 system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier()

In reply to Philippe Mathieu-Daudé

Currently kvm_irqchip_add_irqfd_notifier() and kvm_irqchip_remove_irqfd_notifier() are only declared on target specific code. There is not particular reason to, as their prototypes don't use anything target related.

Move their declaration with common prototypes, and implement their stub.

---
 include/system/kvm.h   |  8 ++++----
 accel/stubs/kvm-stub.c | 12 ++++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)
include/system/kvm.h +4 -4
index ab17c09a551..75673fb794e 100644
@@ -412,10 +412,6 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg);
 
 void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin);
 
-void kvm_irqchip_add_change_notifier(Notifier *n);
-void kvm_irqchip_remove_change_notifier(Notifier *n);
-void kvm_irqchip_change_notify(void);
-
 struct kvm_guest_debug;
 struct kvm_debug_exit_arch;
 
@@ -517,6 +513,10 @@ void kvm_irqchip_release_virq(KVMState *s, int virq);
 void kvm_add_routing_entry(KVMState *s,
                            struct kvm_irq_routing_entry *entry);
 
+void kvm_irqchip_add_change_notifier(Notifier *n);
+void kvm_irqchip_remove_change_notifier(Notifier *n);
+void kvm_irqchip_change_notify(void);
+
 int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
                                        EventNotifier *rn, int virq);
 int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
accel/stubs/kvm-stub.c +12 -0
index ecfd7636f5f..a305b33d84d 100644
@@ -83,6 +83,18 @@ void kvm_irqchip_change_notify(void)
 {
 }
 
+int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
+                                   EventNotifier *rn, qemu_irq irq)
+{
+    return -ENOSYS;
+}
+
+int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n,
+                                      qemu_irq irq)
+{
+    return -ENOSYS;
+}
+
 int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
                                        EventNotifier *rn, int virq)
 {
Signature · 1 line
2.47.1
Reviewed-by on v1 8/14
#29 lore raw

Re: [PATCH 08/14] system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier()

Quoted 53 lines · Philippe Mathieu-Daudé

Currently kvm_irqchip_add_irqfd_notifier() and kvm_irqchip_remove_irqfd_notifier() are only declared on target specific code. There is not particular reason to, as their prototypes don't use anything target related.

Move their declaration with common prototypes, and implement their stub.

---
  include/system/kvm.h   |  8 ++++----
  accel/stubs/kvm-stub.c | 12 ++++++++++++
  2 files changed, 16 insertions(+), 4 deletions(-)
include/system/kvm.h +4 -4
index ab17c09a551..75673fb794e 100644
@@ -412,10 +412,6 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg);
 
  void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin);
 
-void kvm_irqchip_add_change_notifier(Notifier *n);
-void kvm_irqchip_remove_change_notifier(Notifier *n);
-void kvm_irqchip_change_notify(void);
-
  struct kvm_guest_debug;
  struct kvm_debug_exit_arch;
 
@@ -517,6 +513,10 @@ void kvm_irqchip_release_virq(KVMState *s, int virq);
  void kvm_add_routing_entry(KVMState *s,
                             struct kvm_irq_routing_entry *entry);
 
+void kvm_irqchip_add_change_notifier(Notifier *n);
+void kvm_irqchip_remove_change_notifier(Notifier *n);
+void kvm_irqchip_change_notify(void);
+
  int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
                                         EventNotifier *rn, int virq);
  int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
accel/stubs/kvm-stub.c +5 -0
index ecfd7636f5f..a305b33d84d 100644
@@ -83,6 +83,18 @@ void kvm_irqchip_change_notify(void)
  {
  }
 
+int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
+                                   EventNotifier *rn, qemu_irq irq)
+{
+    return -ENOSYS;
+}

accel/stubs/kvm-stub.c void kvm_irqchip_change_notify(void) · line 100

Quoted 10 lines
accel/stubs/kvm-stub.c +7 -0
+
+int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n,
+                                      qemu_irq irq)
+{
+    return -ENOSYS;
+}
+
  int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
                                         EventNotifier *rn, int virq)
  {
#30 lore raw

Re: [PATCH 08/14] system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Currently kvm_irqchip_add_irqfd_notifier() and kvm_irqchip_remove_irqfd_notifier() are only declared on target specific code. There is not particular reason to, as their prototypes don't use anything target related.

Move their declaration with common prototypes, and implement their stub.

The description is not accurate, because the new stubs are *not* for the functions whose declaration you move.

This feels like two different changes.

r~

#31 lore raw

Re: [PATCH 08/14] system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier()

Quoted 6 lines · Richard Henderson
Quoted 5 lines · Philippe Mathieu-Daudé

Currently kvm_irqchip_add_irqfd_notifier() and kvm_irqchip_remove_irqfd_notifier() are only declared on target specific code. There is not particular reason to, as their prototypes don't use anything target related.

Quoted 7 lines
Quoted 2 lines

Move their declaration with common prototypes, and implement their stub.

The description is not accurate, because the new stubs are *not* for the functions whose declaration you move.

This feels like two different changes.

Oops. I don't remember why I added the stubs, they are used in vfio-ap but I can't reproduce a build failure. I'll just remove them.

#32 lore raw

PATCH 9/14 hw/vfio/pci: Convert CONFIG_KVM check to runtime one

In reply to Philippe Mathieu-Daudé

Use the runtime kvm_enabled() helper to check whether KVM is available or not.

---
 hw/vfio/pci.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
hw/vfio/pci.c +9 -10
index fdbc15885d4..9872884ff8a 100644
@@ -118,8 +118,13 @@ static void vfio_intx_eoi(VFIODevice *vbasedev)
 
 static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
 {
-#ifdef CONFIG_KVM
-    int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
+    int irq_fd;
+
+    if (!kvm_enabled()) {
+        return true;
+    }
+
+    irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
 
     if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
         vdev->intx.route.mode != PCI_INTX_ENABLED ||
@@ -171,16 +176,13 @@ fail_irqfd:
 fail:
     qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev);
     vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+
     return false;
-#else
-    return true;
-#endif
 }
 
 static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
 {
-#ifdef CONFIG_KVM
-    if (!vdev->intx.kvm_accel) {
+    if (!kvm_enabled() || !vdev->intx.kvm_accel) {
         return;
     }
 
@@ -211,7 +213,6 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
     vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
 
     trace_vfio_intx_disable_kvm(vdev->vbasedev.name);
-#endif
 }
 
 static void vfio_intx_update(VFIOPCIDevice *vdev, PCIINTxRoute *route)
@@ -278,7 +279,6 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
     vdev->intx.pin = pin - 1; /* Pin A (1) -> irq[0] */
     pci_config_set_interrupt_pin(vdev->pdev.config, pin);
 
-#ifdef CONFIG_KVM
     /*
      * Only conditional to avoid generating error messages on platforms
      * where we won't actually use the result anyway.
@@ -287,7 +287,6 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
         vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
                                                         vdev->intx.pin);
     }
-#endif
 
     ret = event_notifier_init(&vdev->intx.interrupt, 0);
     if (ret) {
Signature · 1 line
2.47.1
Reviewed-by on v1 9/14
#33 lore raw

Re: [PATCH 09/14] hw/vfio/pci: Convert CONFIG_KVM check to runtime one

Quoted 64 lines · Philippe Mathieu-Daudé

Use the runtime kvm_enabled() helper to check whether KVM is available or not.

---
  hw/vfio/pci.c | 19 +++++++++----------
  1 file changed, 9 insertions(+), 10 deletions(-)
hw/vfio/pci.c +9 -9
index fdbc15885d4..9872884ff8a 100644
@@ -118,8 +118,13 @@ static void vfio_intx_eoi(VFIODevice *vbasedev)
 
  static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
  {
-#ifdef CONFIG_KVM
-    int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
+    int irq_fd;
+
+    if (!kvm_enabled()) {
+        return true;
+    }
+
+    irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
 
      if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
          vdev->intx.route.mode != PCI_INTX_ENABLED ||
@@ -171,16 +176,13 @@ fail_irqfd:
  fail:
      qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev);
      vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+
      return false;
-#else
-    return true;
-#endif
  }
 
  static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
  {
-#ifdef CONFIG_KVM
-    if (!vdev->intx.kvm_accel) {
+    if (!kvm_enabled() || !vdev->intx.kvm_accel) {
          return;
      }
 
@@ -211,7 +213,6 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
      vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
 
      trace_vfio_intx_disable_kvm(vdev->vbasedev.name);
-#endif
  }
 
  static void vfio_intx_update(VFIOPCIDevice *vdev, PCIINTxRoute *route)
@@ -278,7 +279,6 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
      vdev->intx.pin = pin - 1; /* Pin A (1) -> irq[0] */
      pci_config_set_interrupt_pin(vdev->pdev.config, pin);
 
-#ifdef CONFIG_KVM
      /*
       * Only conditional to avoid generating error messages on platforms
       * where we won't actually use the result anyway.

hw/vfio/pci.c static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) · line 292

Quoted 7 lines
hw/vfio/pci.c +0 -1
@@ -287,7 +287,6 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
          vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
                                                          vdev->intx.pin);
      }
-#endif
 
      ret = event_notifier_init(&vdev->intx.interrupt, 0);
      if (ret) {
Reviewed-by on v1 9/14
#34 lore raw

Re: [PATCH 09/14] hw/vfio/pci: Convert CONFIG_KVM check to runtime one

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Use the runtime kvm_enabled() helper to check whether KVM is available or not.

---
  hw/vfio/pci.c | 19 +++++++++----------
  1 file changed, 9 insertions(+), 10 deletions(-)

r~

Reviewed-by on v1 9/14
#35 lore raw

Re: [PATCH 09/14] hw/vfio/pci: Convert CONFIG_KVM check to runtime one

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Use the runtime kvm_enabled() helper to check whether KVM is available or not.

Thanks,

C.

Quoted 67 lines
---
  hw/vfio/pci.c | 19 +++++++++----------
  1 file changed, 9 insertions(+), 10 deletions(-)
hw/vfio/pci.c +9 -10
index fdbc15885d4..9872884ff8a 100644
@@ -118,8 +118,13 @@ static void vfio_intx_eoi(VFIODevice *vbasedev)
 
  static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
  {
-#ifdef CONFIG_KVM
-    int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
+    int irq_fd;
+
+    if (!kvm_enabled()) {
+        return true;
+    }
+
+    irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
 
      if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
          vdev->intx.route.mode != PCI_INTX_ENABLED ||
@@ -171,16 +176,13 @@ fail_irqfd:
  fail:
      qemu_set_fd_handler(irq_fd, vfio_intx_interrupt, NULL, vdev);
      vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
+
      return false;
-#else
-    return true;
-#endif
  }
 
  static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
  {
-#ifdef CONFIG_KVM
-    if (!vdev->intx.kvm_accel) {
+    if (!kvm_enabled() || !vdev->intx.kvm_accel) {
          return;
      }
 
@@ -211,7 +213,6 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
      vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
 
      trace_vfio_intx_disable_kvm(vdev->vbasedev.name);
-#endif
  }
 
  static void vfio_intx_update(VFIOPCIDevice *vdev, PCIINTxRoute *route)
@@ -278,7 +279,6 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
      vdev->intx.pin = pin - 1; /* Pin A (1) -> irq[0] */
      pci_config_set_interrupt_pin(vdev->pdev.config, pin);
 
-#ifdef CONFIG_KVM
      /*
       * Only conditional to avoid generating error messages on platforms
       * where we won't actually use the result anyway.
@@ -287,7 +287,6 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
          vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
                                                          vdev->intx.pin);
      }
-#endif
 
      ret = event_notifier_init(&vdev->intx.interrupt, 0);
      if (ret) {
#36 lore raw

PATCH 10/14 system/iommufd: Introduce iommufd_builtin() helper

In reply to Philippe Mathieu-Daudé

iommufd_builtin() can be used to check at runtime whether the IOMMUFD feature is built in a qemu-system binary.

---
 docs/devel/vfio-iommufd.rst | 2 +-
 include/system/iommufd.h    | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
docs/devel/vfio-iommufd.rst +1 -1
index 3d1c11f175e..08882094eee 100644
@@ -88,7 +88,7 @@ Step 2: configure QEMU
 ----------------------
 
 Interactions with the ``/dev/iommu`` are abstracted by a new iommufd
-object (compiled in with the ``CONFIG_IOMMUFD`` option).
+object (which availability can be checked at runtime using ``iommufd_builtin()``).
 
 Any QEMU device (e.g. VFIO device) wishing to use ``/dev/iommu`` must
 be linked with an iommufd object. It gets a new optional property
include/system/iommufd.h +8 -0
index cbab75bfbf6..ce459254025 100644
@@ -63,4 +63,12 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
                                       Error **errp);
 
 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
+
+static inline bool iommufd_builtin(void)
+{
+    bool ambig = false;
+
+    return object_resolve_path_type("", TYPE_IOMMUFD_BACKEND, &ambig) || ambig;
+}
+
 #endif
Signature · 1 line
2.47.1
Reviewed-by on v1 10/14
#37 lore raw

Re: [PATCH 10/14] system/iommufd: Introduce iommufd_builtin() helper

Quoted 29 lines · Philippe Mathieu-Daudé

iommufd_builtin() can be used to check at runtime whether the IOMMUFD feature is built in a qemu-system binary.

---
  docs/devel/vfio-iommufd.rst | 2 +-
  include/system/iommufd.h    | 8 ++++++++
  2 files changed, 9 insertions(+), 1 deletion(-)
docs/devel/vfio-iommufd.rst +1 -1
index 3d1c11f175e..08882094eee 100644
@@ -88,7 +88,7 @@ Step 2: configure QEMU
  ----------------------
 
  Interactions with the ``/dev/iommu`` are abstracted by a new iommufd
-object (compiled in with the ``CONFIG_IOMMUFD`` option).
+object (which availability can be checked at runtime using ``iommufd_builtin()``).
 
  Any QEMU device (e.g. VFIO device) wishing to use ``/dev/iommu`` must
  be linked with an iommufd object. It gets a new optional property
include/system/iommufd.h +0 -0
index cbab75bfbf6..ce459254025 100644
@@ -63,4 +63,12 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
                                        Error **errp);
 

include/system/iommufd.h bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id, · line 74

Quoted 10 lines
include/system/iommufd.h +8 -0
  #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
+
+static inline bool iommufd_builtin(void)
+{
+    bool ambig = false;
+
+    return object_resolve_path_type("", TYPE_IOMMUFD_BACKEND, &ambig) || ambig;
+}
+
  #endif
Reviewed-by on v1 10/14
#38 lore raw

Re: [PATCH 10/14] system/iommufd: Introduce iommufd_builtin() helper

In reply to Philippe Mathieu-Daudé
Quoted 29 lines · Philippe Mathieu-Daudé

iommufd_builtin() can be used to check at runtime whether the IOMMUFD feature is built in a qemu-system binary.

---
  docs/devel/vfio-iommufd.rst | 2 +-
  include/system/iommufd.h    | 8 ++++++++
  2 files changed, 9 insertions(+), 1 deletion(-)
docs/devel/vfio-iommufd.rst +1 -1
index 3d1c11f175e..08882094eee 100644
@@ -88,7 +88,7 @@ Step 2: configure QEMU
  ----------------------
 
  Interactions with the ``/dev/iommu`` are abstracted by a new iommufd
-object (compiled in with the ``CONFIG_IOMMUFD`` option).
+object (which availability can be checked at runtime using ``iommufd_builtin()``).
 
  Any QEMU device (e.g. VFIO device) wishing to use ``/dev/iommu`` must
  be linked with an iommufd object. It gets a new optional property
include/system/iommufd.h +0 -0
index cbab75bfbf6..ce459254025 100644
@@ -63,4 +63,12 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
                                        Error **errp);
 

include/system/iommufd.h bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id, · line 74

Quoted 10 lines
include/system/iommufd.h +8 -0
  #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
+
+static inline bool iommufd_builtin(void)
+{
+    bool ambig = false;
+
+    return object_resolve_path_type("", TYPE_IOMMUFD_BACKEND, &ambig) || ambig;
+}
+
  #endif

Interesting solution.

r~

#39 lore raw

Re: [PATCH 10/14] system/iommufd: Introduce iommufd_builtin() helper

Quoted 34 lines · Richard Henderson
Quoted 33 lines · Philippe Mathieu-Daudé

iommufd_builtin() can be used to check at runtime whether the IOMMUFD feature is built in a qemu-system binary.

---
  docs/devel/vfio-iommufd.rst | 2 +-
  include/system/iommufd.h    | 8 ++++++++

  2 files changed, 9 insertions(+), 1 deletion(-)
docs/devel/vfio-iommufd.rst +0 -0
index 3d1c11f175e..08882094eee 100644
@@ -88,7 +88,7 @@ Step 2: configure QEMU

  ----------------------
  Interactions with the ``/dev/iommu`` are abstracted by a new iommufd

docs/devel/vfio-iommufd.rst +1 -1
-object (compiled in with the ``CONFIG_IOMMUFD`` option).
+object (which availability can be checked at runtime using 

``iommufd_builtin()``).
  Any QEMU device (e.g. VFIO device) wishing to use ``/dev/iommu`` must be linked with an iommufd object. It gets a new optional property

include/system/iommufd.h +4 -0
index cbab75bfbf6..ce459254025 100644
@@ -63,4 +63,12 @@ bool 
 iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
                                         Error **errp);
   #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "- iommufd"
+
+static inline bool iommufd_builtin(void)
+{
+    bool ambig = false;
Quoted 8 lines
Quoted 6 lines
include/system/iommufd.h +4 -0
+
+    return object_resolve_path_type("", TYPE_IOMMUFD_BACKEND, &ambig) 
 || ambig;
+}
+

  #endif

Interesting solution.

Actually this isn't appropriate as this checks for an *instance*, while we only want the *class*.

I'll respin a different approach.

#40 lore raw

PATCH 11/14 hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

In reply to Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
 hw/vfio/pci.c       | 38 ++++++++++++++++++--------------------
 hw/vfio/meson.build |  2 +-
 2 files changed, 19 insertions(+), 21 deletions(-)
hw/vfio/pci.c +18 -20
index 9872884ff8a..e83252766d1 100644
@@ -19,7 +19,6 @@
  */
 
 #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
 #include <linux/vfio.h>
 #include <sys/ioctl.h>
 
@@ -2973,11 +2972,10 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
         if (!(~vdev->host.domain || ~vdev->host.bus ||
               ~vdev->host.slot || ~vdev->host.function)) {
             error_setg(errp, "No provided host device");
-            error_append_hint(errp, "Use -device vfio-pci,host=DDDD:BB:DD.F "
-#ifdef CONFIG_IOMMUFD
-                              "or -device vfio-pci,fd=DEVICE_FD "
-#endif
-                              "or -device vfio-pci,sysfsdev=PATH_TO_DEVICE\n");
+            error_append_hint(errp, "Use -device vfio-pci,host=DDDD:BB:DD.F %s"
+                              "or -device vfio-pci,sysfsdev=PATH_TO_DEVICE\n",
+                              iommufd_builtin()
+                              ? "or -device vfio-pci,fd=DEVICE_FD " : "");
             return;
         }
         vbasedev->sysfsdev =
@@ -3412,19 +3410,18 @@ static const Property vfio_pci_dev_properties[] = {
                                    qdev_prop_nv_gpudirect_clique, uint8_t),
     DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_relo,
                                 OFF_AUTO_PCIBAR_OFF),
-#ifdef CONFIG_IOMMUFD
-    DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd,
-                     TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
     DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true),
 };
 
-#ifdef CONFIG_IOMMUFD
+static const Property vfio_pci_dev_iommufd_properties[] = {
+    DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd,
+                     TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
+};
+
 static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp)
 {
     vfio_device_set_fd(&VFIO_PCI(obj)->vbasedev, str, errp);
 }
-#endif
 
 static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
 {
@@ -3433,9 +3430,10 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
 
     device_class_set_legacy_reset(dc, vfio_pci_reset);
     device_class_set_props(dc, vfio_pci_dev_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_pci_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_pci_dev_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_pci_set_fd);
+    }
     dc->desc = "VFIO-based PCI device assignment";
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     pdc->realize = vfio_realize;
@@ -3540,11 +3538,11 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
                                           "vf-token",
                                           "Specify UUID VF token. Required for VF when PF is owned "
                                           "by another VFIO driver");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
     object_class_property_set_description(klass, /* 9.1 */
                                           "x-device-dirty-page-tracking",
                                           "Disable device dirty page tracking and use "
hw/vfio/meson.build +1 -1
index 96e342aa8cb..9a004992c11 100644
@@ -6,7 +6,6 @@ vfio_ss.add(files(
 vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'pci-quirks.c',
-  'pci.c',
 ))
 vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
@@ -29,4 +28,5 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
 ))
 system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'display.c',
+  'pci.c',
 ))
Signature · 1 line
2.47.1
Reviewed-by on v1 11/14
#41 lore raw

Re: [PATCH 11/14] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 109 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  hw/vfio/pci.c       | 38 ++++++++++++++++++--------------------
  hw/vfio/meson.build |  2 +-
  2 files changed, 19 insertions(+), 21 deletions(-)
hw/vfio/pci.c +18 -20
index 9872884ff8a..e83252766d1 100644
@@ -19,7 +19,6 @@
   */
 
  #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
  #include <linux/vfio.h>
  #include <sys/ioctl.h>
 
@@ -2973,11 +2972,10 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
          if (!(~vdev->host.domain || ~vdev->host.bus ||
                ~vdev->host.slot || ~vdev->host.function)) {
              error_setg(errp, "No provided host device");
-            error_append_hint(errp, "Use -device vfio-pci,host=DDDD:BB:DD.F "
-#ifdef CONFIG_IOMMUFD
-                              "or -device vfio-pci,fd=DEVICE_FD "
-#endif
-                              "or -device vfio-pci,sysfsdev=PATH_TO_DEVICE\n");
+            error_append_hint(errp, "Use -device vfio-pci,host=DDDD:BB:DD.F %s"
+                              "or -device vfio-pci,sysfsdev=PATH_TO_DEVICE\n",
+                              iommufd_builtin()
+                              ? "or -device vfio-pci,fd=DEVICE_FD " : "");
              return;
          }
          vbasedev->sysfsdev =
@@ -3412,19 +3410,18 @@ static const Property vfio_pci_dev_properties[] = {
                                     qdev_prop_nv_gpudirect_clique, uint8_t),
      DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_relo,
                                  OFF_AUTO_PCIBAR_OFF),
-#ifdef CONFIG_IOMMUFD
-    DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd,
-                     TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
      DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true),
  };
 
-#ifdef CONFIG_IOMMUFD
+static const Property vfio_pci_dev_iommufd_properties[] = {
+    DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd,
+                     TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
+};
+
  static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp)
  {
      vfio_device_set_fd(&VFIO_PCI(obj)->vbasedev, str, errp);
  }
-#endif
 
  static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
  {
@@ -3433,9 +3430,10 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
 
      device_class_set_legacy_reset(dc, vfio_pci_reset);
      device_class_set_props(dc, vfio_pci_dev_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_pci_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_pci_dev_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_pci_set_fd);
+    }
      dc->desc = "VFIO-based PCI device assignment";
      set_bit(DEVICE_CATEGORY_MISC, dc->categories);
      pdc->realize = vfio_realize;
@@ -3540,11 +3538,11 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
                                            "vf-token",
                                            "Specify UUID VF token. Required for VF when PF is owned "
                                            "by another VFIO driver");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
      object_class_property_set_description(klass, /* 9.1 */
                                            "x-device-dirty-page-tracking",
                                            "Disable device dirty page tracking and use "
hw/vfio/meson.build +0 -1
index 96e342aa8cb..9a004992c11 100644
@@ -6,7 +6,6 @@ vfio_ss.add(files(
  vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'pci-quirks.c',
-  'pci.c',
  ))
  vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))

hw/vfio/meson.build system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files( · line 32

Quoted 5 lines
hw/vfio/meson.build +1 -0
@@ -29,4 +28,5 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
  ))
  system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'display.c',
+  'pci.c',
  ))
Reviewed-by on v1 11/14
#42 lore raw

Re: [PATCH 11/14] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  hw/vfio/pci.c       | 38 ++++++++++++++++++--------------------
  hw/vfio/meson.build |  2 +-
  2 files changed, 19 insertions(+), 21 deletions(-)

r~

#43 lore raw

PATCH 12/14 hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

In reply to Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
 target/s390x/kvm/kvm_s390x.h |  2 +-
 hw/vfio/ap.c                 | 27 +++++++++++++--------------
 hw/vfio/meson.build          |  2 +-
 3 files changed, 15 insertions(+), 16 deletions(-)
target/s390x/kvm/kvm_s390x.h +1 -1
index 649dae5948a..7b1cce3e60d 100644
@@ -10,7 +10,7 @@
 #ifndef KVM_S390X_H
 #define KVM_S390X_H
 
-#include "cpu-qom.h"
+#include "target/s390x/cpu-qom.h"
 
 struct kvm_s390_irq;
 
hw/vfio/ap.c +13 -14
index c7ab4ff57ad..832b98532ea 100644
@@ -11,7 +11,6 @@
  */
 
 #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
 #include <linux/vfio.h>
 #include <sys/ioctl.h>
 #include "qapi/error.h"
@@ -24,7 +23,7 @@
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
-#include "kvm/kvm_s390x.h"
+#include "target/s390x/kvm/kvm_s390x.h"
 #include "migration/vmstate.h"
 #include "hw/qdev-properties.h"
 #include "hw/s390x/ap-bridge.h"
@@ -193,10 +192,11 @@ static void vfio_ap_unrealize(DeviceState *dev)
 
 static const Property vfio_ap_properties[] = {
     DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
-#ifdef CONFIG_IOMMUFD
+};
+
+static const Property vfio_ap_iommufd_properties[] = {
     DEFINE_PROP_LINK("iommufd", VFIOAPDevice, vdev.iommufd,
                      TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
 };
 
 static void vfio_ap_reset(DeviceState *dev)
@@ -234,21 +234,20 @@ static void vfio_ap_instance_init(Object *obj)
     vbasedev->mdev = true;
 }
 
-#ifdef CONFIG_IOMMUFD
 static void vfio_ap_set_fd(Object *obj, const char *str, Error **errp)
 {
     vfio_device_set_fd(&VFIO_AP_DEVICE(obj)->vdev, str, errp);
 }
-#endif
 
 static void vfio_ap_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     device_class_set_props(dc, vfio_ap_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_ap_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_ap_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_ap_set_fd);
+    }
     dc->vmsd = &vfio_ap_vmstate;
     dc->desc = "VFIO-based AP device assignment";
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -261,11 +260,11 @@ static void vfio_ap_class_init(ObjectClass *klass, void *data)
     object_class_property_set_description(klass, /* 3.1 */
                                           "sysfsdev",
                                           "Host sysfs path of assigned device");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
 }
 
 static const TypeInfo vfio_ap_info = {
hw/vfio/meson.build +1 -1
index 9a004992c11..510ebe6d720 100644
@@ -9,7 +9,6 @@ vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
 ))
 vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
 
 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 
@@ -26,6 +25,7 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
 system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
   'iommufd.c',
 ))
+system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
 system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'display.c',
   'pci.c',
Signature · 1 line
2.47.1
Reviewed-by on v1 12/14
#44 lore raw

Re: [PATCH 12/14] hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 117 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  target/s390x/kvm/kvm_s390x.h |  2 +-
  hw/vfio/ap.c                 | 27 +++++++++++++--------------
  hw/vfio/meson.build          |  2 +-
  3 files changed, 15 insertions(+), 16 deletions(-)
target/s390x/kvm/kvm_s390x.h +1 -1
index 649dae5948a..7b1cce3e60d 100644
@@ -10,7 +10,7 @@
  #ifndef KVM_S390X_H
  #define KVM_S390X_H
 
-#include "cpu-qom.h"
+#include "target/s390x/cpu-qom.h"
 
  struct kvm_s390_irq;
 
hw/vfio/ap.c +13 -14
index c7ab4ff57ad..832b98532ea 100644
@@ -11,7 +11,6 @@
   */
 
  #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
  #include <linux/vfio.h>
  #include <sys/ioctl.h>
  #include "qapi/error.h"
@@ -24,7 +23,7 @@
  #include "qemu/module.h"
  #include "qemu/option.h"
  #include "qemu/config-file.h"
-#include "kvm/kvm_s390x.h"
+#include "target/s390x/kvm/kvm_s390x.h"
  #include "migration/vmstate.h"
  #include "hw/qdev-properties.h"
  #include "hw/s390x/ap-bridge.h"
@@ -193,10 +192,11 @@ static void vfio_ap_unrealize(DeviceState *dev)
 
  static const Property vfio_ap_properties[] = {
      DEFINE_PROP_STRING("sysfsdev", VFIOAPDevice, vdev.sysfsdev),
-#ifdef CONFIG_IOMMUFD
+};
+
+static const Property vfio_ap_iommufd_properties[] = {
      DEFINE_PROP_LINK("iommufd", VFIOAPDevice, vdev.iommufd,
                       TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
  };
 
  static void vfio_ap_reset(DeviceState *dev)
@@ -234,21 +234,20 @@ static void vfio_ap_instance_init(Object *obj)
      vbasedev->mdev = true;
  }
 
-#ifdef CONFIG_IOMMUFD
  static void vfio_ap_set_fd(Object *obj, const char *str, Error **errp)
  {
      vfio_device_set_fd(&VFIO_AP_DEVICE(obj)->vdev, str, errp);
  }
-#endif
 
  static void vfio_ap_class_init(ObjectClass *klass, void *data)
  {
      DeviceClass *dc = DEVICE_CLASS(klass);
 
      device_class_set_props(dc, vfio_ap_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_ap_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_ap_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_ap_set_fd);
+    }
      dc->vmsd = &vfio_ap_vmstate;
      dc->desc = "VFIO-based AP device assignment";
      set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -261,11 +260,11 @@ static void vfio_ap_class_init(ObjectClass *klass, void *data)
      object_class_property_set_description(klass, /* 3.1 */
                                            "sysfsdev",
                                            "Host sysfs path of assigned device");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
  }
 
  static const TypeInfo vfio_ap_info = {
hw/vfio/meson.build +0 -1
index 9a004992c11..510ebe6d720 100644
@@ -9,7 +9,6 @@ vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
  ))
  vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
 
  specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 

hw/vfio/meson.build system_ss.add(when: 'CONFIG_VFIO', if_true: files( · line 31

Quoted 7 lines
hw/vfio/meson.build +1 -0
@@ -26,6 +25,7 @@ system_ss.add(when: 'CONFIG_VFIO', if_true: files(
  system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
    'iommufd.c',
  ))
+system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
  system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'display.c',
    'pci.c',
#45 lore raw

Re: [PATCH 12/14] hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

In reply to Philippe Mathieu-Daudé
Quoted 39 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  target/s390x/kvm/kvm_s390x.h |  2 +-
  hw/vfio/ap.c                 | 27 +++++++++++++--------------
  hw/vfio/meson.build          |  2 +-
  3 files changed, 15 insertions(+), 16 deletions(-)
target/s390x/kvm/kvm_s390x.h +1 -1
index 649dae5948a..7b1cce3e60d 100644
@@ -10,7 +10,7 @@
  #ifndef KVM_S390X_H
  #define KVM_S390X_H
 
-#include "cpu-qom.h"
+#include "target/s390x/cpu-qom.h"
 
  struct kvm_s390_irq;
 
hw/vfio/ap.c +0 -1
index c7ab4ff57ad..832b98532ea 100644
@@ -11,7 +11,6 @@
   */
 
  #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
  #include <linux/vfio.h>
  #include <sys/ioctl.h>
  #include "qapi/error.h"

hw/vfio/ap.c line 26

Quoted 5 lines
hw/vfio/ap.c +1 -1
@@ -24,7 +23,7 @@
  #include "qemu/module.h"
  #include "qemu/option.h"
  #include "qemu/config-file.h"
-#include "kvm/kvm_s390x.h"
+#include "target/s390x/kvm/kvm_s390x.h"

Do I take from this that this is actually a target-specific device? Otherwise the two s390x changes are confusing.
Is it built once already, due to only being enabled for qemu-system-s390x? If so, I question the need to move it out of specific_ss at all.

Anyway, this is two changes -- one for iommufd_builtin and one for meson.build.

r~

#46 lore raw

Re: [PATCH 12/14] hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 38 lines · Richard Henderson
Quoted 37 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  target/s390x/kvm/kvm_s390x.h |  2 +-
  hw/vfio/ap.c                 | 27 +++++++++++++-------------- hw/vfio/meson.build          |  2 +-

  3 files changed, 15 insertions(+), 16 deletions(-)
target/s390x/kvm/kvm_s390x.h +1 -1
index 649dae5948a..7b1cce3e60d 100644
@@ -10,7 +10,7 @@
   #ifndef KVM_S390X_H
   #define KVM_S390X_H
-#include "cpu-qom.h"
+#include "target/s390x/cpu-qom.h"
   struct kvm_s390_irq;
hw/vfio/ap.c +0 -1
index c7ab4ff57ad..832b98532ea 100644
@@ -11,7 +11,6 @@
    */
   #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
   #include <linux/vfio.h>
   #include <sys/ioctl.h>
   #include "qapi/error.h"
@@ -24,7 +23,7 @@
   #include "qemu/module.h"
   #include "qemu/option.h"
Quoted 8 lines

hw/vfio/ap.c line 26

Quoted 3 lines
hw/vfio/ap.c +1 -1
   #include "qemu/config-file.h"
-#include "kvm/kvm_s390x.h"
+#include "target/s390x/kvm/kvm_s390x.h"

Do I take from this that this is actually a target-specific device? Otherwise the two s390x changes are confusing.
Is it built once already, due to only being enabled for qemu-system-s390x? If so, I question the need to move it out of specific_ss at all.

While it happens to be built once, we need to remove specific_ss[] to be sure everything eventually link, right?

More generally, I'd rather to remove CONFIG_DEVICES altogether.

Quoted 1 line

Anyway, this is two changes -- one for iommufd_builtin and one for meson.build.

OK.

#47 lore raw

PATCH 13/14 hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

In reply to Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
 hw/vfio/ccw.c       | 27 +++++++++++++--------------
 hw/vfio/meson.build |  2 +-
 2 files changed, 14 insertions(+), 15 deletions(-)
hw/vfio/ccw.c +13 -14
index e5e0d9e3e7e..84d1437a568 100644
@@ -15,7 +15,6 @@
  */
 
 #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
 #include <linux/vfio.h>
 #include <linux/vfio_ccw.h>
 #include <sys/ioctl.h>
@@ -650,11 +649,12 @@ static void vfio_ccw_unrealize(DeviceState *dev)
 static const Property vfio_ccw_properties[] = {
     DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice, vdev.sysfsdev),
     DEFINE_PROP_BOOL("force-orb-pfch", VFIOCCWDevice, force_orb_pfch, false),
-#ifdef CONFIG_IOMMUFD
+    DEFINE_PROP_CCW_LOADPARM("loadparm", CcwDevice, loadparm),
+};
+
+static const Property vfio_ccw_iommufd_properties[] = {
     DEFINE_PROP_LINK("iommufd", VFIOCCWDevice, vdev.iommufd,
                      TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
-    DEFINE_PROP_CCW_LOADPARM("loadparm", CcwDevice, loadparm),
 };
 
 static const VMStateDescription vfio_ccw_vmstate = {
@@ -682,12 +682,10 @@ static void vfio_ccw_instance_init(Object *obj)
                      DEVICE(vcdev), true);
 }
 
-#ifdef CONFIG_IOMMUFD
 static void vfio_ccw_set_fd(Object *obj, const char *str, Error **errp)
 {
     vfio_device_set_fd(&VFIO_CCW(obj)->vdev, str, errp);
 }
-#endif
 
 static void vfio_ccw_class_init(ObjectClass *klass, void *data)
 {
@@ -695,9 +693,10 @@ static void vfio_ccw_class_init(ObjectClass *klass, void *data)
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_CLASS(klass);
 
     device_class_set_props(dc, vfio_ccw_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_ccw_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd);
+    }
     dc->vmsd = &vfio_ccw_vmstate;
     dc->desc = "VFIO-based subchannel assignment";
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -716,11 +715,11 @@ static void vfio_ccw_class_init(ObjectClass *klass, void *data)
     object_class_property_set_description(klass, /* 3.0 */
                                           "force-orb-pfch",
                                           "Force unlimited prefetch");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
     object_class_property_set_description(klass, /* 9.2 */
                                           "loadparm",
                                           "Define which devices that can be used for booting");
hw/vfio/meson.build +1 -1
index 510ebe6d720..bd6e1d999e4 100644
@@ -7,7 +7,6 @@ vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'pci-quirks.c',
 ))
-vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 
 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
@@ -26,6 +25,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
   'iommufd.c',
 ))
 system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
+system_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
 system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'display.c',
   'pci.c',
Signature · 1 line
2.47.1
Reviewed-by on v1 13/14
#48 lore raw

Re: [PATCH 13/14] hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 97 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  hw/vfio/ccw.c       | 27 +++++++++++++--------------
  hw/vfio/meson.build |  2 +-
  2 files changed, 14 insertions(+), 15 deletions(-)
hw/vfio/ccw.c +13 -14
index e5e0d9e3e7e..84d1437a568 100644
@@ -15,7 +15,6 @@
   */
 
  #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
  #include <linux/vfio.h>
  #include <linux/vfio_ccw.h>
  #include <sys/ioctl.h>
@@ -650,11 +649,12 @@ static void vfio_ccw_unrealize(DeviceState *dev)
  static const Property vfio_ccw_properties[] = {
      DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice, vdev.sysfsdev),
      DEFINE_PROP_BOOL("force-orb-pfch", VFIOCCWDevice, force_orb_pfch, false),
-#ifdef CONFIG_IOMMUFD
+    DEFINE_PROP_CCW_LOADPARM("loadparm", CcwDevice, loadparm),
+};
+
+static const Property vfio_ccw_iommufd_properties[] = {
      DEFINE_PROP_LINK("iommufd", VFIOCCWDevice, vdev.iommufd,
                       TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
-    DEFINE_PROP_CCW_LOADPARM("loadparm", CcwDevice, loadparm),
  };
 
  static const VMStateDescription vfio_ccw_vmstate = {
@@ -682,12 +682,10 @@ static void vfio_ccw_instance_init(Object *obj)
                       DEVICE(vcdev), true);
  }
 
-#ifdef CONFIG_IOMMUFD
  static void vfio_ccw_set_fd(Object *obj, const char *str, Error **errp)
  {
      vfio_device_set_fd(&VFIO_CCW(obj)->vdev, str, errp);
  }
-#endif
 
  static void vfio_ccw_class_init(ObjectClass *klass, void *data)
  {
@@ -695,9 +693,10 @@ static void vfio_ccw_class_init(ObjectClass *klass, void *data)
      S390CCWDeviceClass *cdc = S390_CCW_DEVICE_CLASS(klass);
 
      device_class_set_props(dc, vfio_ccw_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_ccw_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd);
+    }
      dc->vmsd = &vfio_ccw_vmstate;
      dc->desc = "VFIO-based subchannel assignment";
      set_bit(DEVICE_CATEGORY_MISC, dc->categories);
@@ -716,11 +715,11 @@ static void vfio_ccw_class_init(ObjectClass *klass, void *data)
      object_class_property_set_description(klass, /* 3.0 */
                                            "force-orb-pfch",
                                            "Force unlimited prefetch");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
      object_class_property_set_description(klass, /* 9.2 */
                                            "loadparm",
                                            "Define which devices that can be used for booting");
hw/vfio/meson.build +0 -1
index 510ebe6d720..bd6e1d999e4 100644
@@ -7,7 +7,6 @@ vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'pci-quirks.c',
  ))
-vfio_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 
  specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)

hw/vfio/meson.build system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files( · line 31

Quoted 7 lines
hw/vfio/meson.build +1 -0
@@ -26,6 +25,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
    'iommufd.c',
  ))
  system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
+system_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
  system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'display.c',
    'pci.c',
#49 lore raw

Re: [PATCH 13/14] hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  hw/vfio/ccw.c       | 27 +++++++++++++--------------
  hw/vfio/meson.build |  2 +-
  2 files changed, 14 insertions(+), 15 deletions(-)

Again, separate the changes for iommufd_builtin and meson. This is an s390x specific device; it really can't be shared beyond.

r~

#50 lore raw

Re: [PATCH 13/14] hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 7 lines · Richard Henderson
Quoted 6 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

Quoted 8 lines
Quoted 5 lines

---
  hw/vfio/ccw.c       | 27 +++++++++++++-------------- hw/vfio/meson.build |  2 +-

  2 files changed, 14 insertions(+), 15 deletions(-)

Again, separate the changes for iommufd_builtin and meson. This is an s390x specific device; it really can't be shared beyond.

I wouldn't be surprised if someone try to emulate a s390x+riscv machine *and* use VFIO, human creativity is limitless!

#51 lore raw

PATCH 14/14 hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using iommufd_builtin

In reply to Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
 hw/vfio/platform.c  | 25 ++++++++++++-------------
 hw/vfio/meson.build |  2 +-
 2 files changed, 13 insertions(+), 14 deletions(-)
hw/vfio/platform.c +12 -13
index 67bc57409c1..265c550b747 100644
@@ -15,7 +15,6 @@
  */
 
 #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
 #include "qapi/error.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
@@ -637,10 +636,11 @@ static const Property vfio_platform_dev_properties[] = {
     DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
                        mmap_timeout, 1100),
     DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true),
-#ifdef CONFIG_IOMMUFD
+};
+
+static const Property vfio_platform_dev_iommufd_properties[] = {
     DEFINE_PROP_LINK("iommufd", VFIOPlatformDevice, vbasedev.iommufd,
                      TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
 };
 
 static void vfio_platform_instance_init(Object *obj)
@@ -652,12 +652,10 @@ static void vfio_platform_instance_init(Object *obj)
                      DEVICE(vdev), false);
 }
 
-#ifdef CONFIG_IOMMUFD
 static void vfio_platform_set_fd(Object *obj, const char *str, Error **errp)
 {
     vfio_device_set_fd(&VFIO_PLATFORM_DEVICE(obj)->vbasedev, str, errp);
 }
-#endif
 
 static void vfio_platform_class_init(ObjectClass *klass, void *data)
 {
@@ -666,9 +664,10 @@ static void vfio_platform_class_init(ObjectClass *klass, void *data)
 
     dc->realize = vfio_platform_realize;
     device_class_set_props(dc, vfio_platform_dev_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_platform_dev_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
+    }
     dc->vmsd = &vfio_platform_vmstate;
     dc->desc = "VFIO-based platform device assignment";
     sbc->connect_irq_notifier = vfio_start_irqfd_injection;
@@ -692,11 +691,11 @@ static void vfio_platform_class_init(ObjectClass *klass, void *data)
     object_class_property_set_description(klass, /* 2.6 */
                                           "sysfsdev",
                                           "Host sysfs path of assigned device");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
 }
 
 static const TypeInfo vfio_platform_dev_info = {
hw/vfio/meson.build +1 -1
index bd6e1d999e4..e5010db2c71 100644
@@ -7,7 +7,6 @@ vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
 vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'pci-quirks.c',
 ))
-vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 
 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 
@@ -26,6 +25,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
 ))
 system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
 system_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
+system_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
   'display.c',
   'pci.c',
Signature · 1 line
2.47.1
Reviewed-by on v1 14/14
#52 lore raw

Re: [PATCH 14/14] hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using iommufd_builtin

Quoted 95 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  hw/vfio/platform.c  | 25 ++++++++++++-------------
  hw/vfio/meson.build |  2 +-
  2 files changed, 13 insertions(+), 14 deletions(-)
hw/vfio/platform.c +12 -13
index 67bc57409c1..265c550b747 100644
@@ -15,7 +15,6 @@
   */
 
  #include "qemu/osdep.h"
-#include CONFIG_DEVICES /* CONFIG_IOMMUFD */
  #include "qapi/error.h"
  #include <sys/ioctl.h>
  #include <linux/vfio.h>
@@ -637,10 +636,11 @@ static const Property vfio_platform_dev_properties[] = {
      DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
                         mmap_timeout, 1100),
      DEFINE_PROP_BOOL("x-irqfd", VFIOPlatformDevice, irqfd_allowed, true),
-#ifdef CONFIG_IOMMUFD
+};
+
+static const Property vfio_platform_dev_iommufd_properties[] = {
      DEFINE_PROP_LINK("iommufd", VFIOPlatformDevice, vbasedev.iommufd,
                       TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
-#endif
  };
 
  static void vfio_platform_instance_init(Object *obj)
@@ -652,12 +652,10 @@ static void vfio_platform_instance_init(Object *obj)
                       DEVICE(vdev), false);
  }
 
-#ifdef CONFIG_IOMMUFD
  static void vfio_platform_set_fd(Object *obj, const char *str, Error **errp)
  {
      vfio_device_set_fd(&VFIO_PLATFORM_DEVICE(obj)->vbasedev, str, errp);
  }
-#endif
 
  static void vfio_platform_class_init(ObjectClass *klass, void *data)
  {
@@ -666,9 +664,10 @@ static void vfio_platform_class_init(ObjectClass *klass, void *data)
 
      dc->realize = vfio_platform_realize;
      device_class_set_props(dc, vfio_platform_dev_properties);
-#ifdef CONFIG_IOMMUFD
-    object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
-#endif
+    if (iommufd_builtin()) {
+        device_class_set_props(dc, vfio_platform_dev_iommufd_properties);
+        object_class_property_add_str(klass, "fd", NULL, vfio_platform_set_fd);
+    }
      dc->vmsd = &vfio_platform_vmstate;
      dc->desc = "VFIO-based platform device assignment";
      sbc->connect_irq_notifier = vfio_start_irqfd_injection;
@@ -692,11 +691,11 @@ static void vfio_platform_class_init(ObjectClass *klass, void *data)
      object_class_property_set_description(klass, /* 2.6 */
                                            "sysfsdev",
                                            "Host sysfs path of assigned device");
-#ifdef CONFIG_IOMMUFD
-    object_class_property_set_description(klass, /* 9.0 */
-                                          "iommufd",
-                                          "Set host IOMMUFD backend device");
-#endif
+    if (iommufd_builtin()) {
+        object_class_property_set_description(klass, /* 9.0 */
+                                              "iommufd",
+                                              "Set host IOMMUFD backend device");
+    }
  }
 
  static const TypeInfo vfio_platform_dev_info = {
hw/vfio/meson.build +0 -1
index bd6e1d999e4..e5010db2c71 100644
@@ -7,7 +7,6 @@ vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
  vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'pci-quirks.c',
  ))
-vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 
  specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 

hw/vfio/meson.build system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files( · line 31

Quoted 7 lines
hw/vfio/meson.build +1 -0
@@ -26,6 +25,7 @@ system_ss.add(when: ['CONFIG_VFIO', 'CONFIG_IOMMUFD'], if_true: files(
  ))
  system_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
  system_ss.add(when: 'CONFIG_VFIO_CCW', if_true: files('ccw.c'))
+system_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
  system_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files(
    'display.c',
    'pci.c',
Reviewed-by on v1 14/14
#53 lore raw

Re: [PATCH 14/14] hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using iommufd_builtin

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_IOMMUFD definition by a runtime one by calling iommufd_builtin().

Since the file doesn't use any target-specific knowledge anymore, move it to system_ss[] to build it once.

---
  hw/vfio/platform.c  | 25 ++++++++++++-------------
  hw/vfio/meson.build |  2 +-
  2 files changed, 13 insertions(+), 14 deletions(-)

r~

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

Hello,

Quoted 34 lines · Philippe Mathieu-Daudé

By doing the following changes:
- Clean some headers up
- Replace compile-time CONFIG_KVM check by kvm_enabled()
- Replace compile-time CONFIG_IOMMUFD check by iommufd_builtin() we can build less vfio objects.

Philippe Mathieu-Daudé (14):
hw/vfio/common: Include missing 'system/tcg.h' header hw/vfio/spapr: Do not include <linux/kvm.h>
hw/vfio: Compile some common objects once
hw/vfio: Compile more objects once
hw/vfio: Compile iommufd.c once
system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h' hw/vfio: Compile display.c once
system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier() hw/vfio/pci: Convert CONFIG_KVM check to runtime one system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using
iommufd_builtin

  docs/devel/vfio-iommufd.rst  |  2 +-
  include/exec/ram_addr.h      |  3 --
  include/system/hostmem.h     |  3 ++
  include/system/iommufd.h     |  8 +++++
  include/system/kvm.h         |  8 ++---
  target/s390x/kvm/kvm_s390x.h |  2 +-
  accel/stubs/kvm-stub.c       | 12 ++++++++
  hw/ppc/spapr_caps.c          |  1 +
  hw/s390x/s390-virtio-ccw.c   |  1 +
  hw/vfio/ap.c                 | 27 ++++++++---------
  hw/vfio/ccw.c                | 27 ++++++++---------
Quoted 9 lines
  hw/vfio/common.c             |  1 +
  hw/vfio/iommufd.c            |  1 -
  hw/vfio/migration.c          |  1 -
  hw/vfio/pci.c                | 57 +++++++++++++++++-------------------
  hw/vfio/platform.c           | 25 ++++++++--------
  hw/vfio/spapr.c              |  4 +--
  hw/vfio/meson.build          | 33 ++++++++++++---------
  18 files changed, 117 insertions(+), 99 deletions(-)

Patches 1-9 look ok and should be considered for the next PR if maintainers ack patch 6 and 8.

Some comments,

vfio-amd-xgbe and vfio-calxeda-xgmac should be treated like vfio-platform, and since vfio-platform was designed for aarch64, these devices should not be available on arm, ppc, ppc64, riscv*, loongarch. That said, vfio-platform and devices being deprecated in the QEMU 10.0 cycle, we could just wait for the removal in QEMU 10.2.

How could we (simply) remove CONFIG_VFIO_IGD in hw/vfio/pci-quirks.c ? and compile this file only once.

The vfio-pci devices are available in nearly all targets when it only makes sense to have them in i386, x86_64, aarch64, ppc64, where they are supported, and also possibly in ppc (tcg) and arm (tcg) for historical reasons and just because they happen to work. ppc (tcg) doesn't support MSIs with vfio-pci devices so I don't think we care much.

Patches 10-14 are wrong because they remove the "iommufd" property of the "vfio-*" devices. We can't take these.

Thanks,

C.

#55 lore raw
Quoted 62 lines · Cédric Le Goater

Hello,

Quoted 34 lines · Philippe Mathieu-Daudé

By doing the following changes:
- Clean some headers up
- Replace compile-time CONFIG_KVM check by kvm_enabled()
- Replace compile-time CONFIG_IOMMUFD check by iommufd_builtin() we can build less vfio objects.

Philippe Mathieu-Daudé (14):
hw/vfio/common: Include missing 'system/tcg.h' header hw/vfio/spapr: Do not include <linux/kvm.h>
hw/vfio: Compile some common objects once
hw/vfio: Compile more objects once
hw/vfio: Compile iommufd.c once
system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h' hw/vfio: Compile display.c once
system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier() hw/vfio/pci: Convert CONFIG_KVM check to runtime one system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using
iommufd_builtin

  docs/devel/vfio-iommufd.rst  |  2 +-
  include/exec/ram_addr.h      |  3 --
  include/system/hostmem.h     |  3 ++
  include/system/iommufd.h     |  8 +++++
  include/system/kvm.h         |  8 ++---
  target/s390x/kvm/kvm_s390x.h |  2 +-
  accel/stubs/kvm-stub.c       | 12 ++++++++
  hw/ppc/spapr_caps.c          |  1 +
  hw/s390x/s390-virtio-ccw.c   |  1 +
  hw/vfio/ap.c                 | 27 ++++++++---------
  hw/vfio/ccw.c                | 27 ++++++++---------
Quoted 9 lines
  hw/vfio/common.c             |  1 +
  hw/vfio/iommufd.c            |  1 -
  hw/vfio/migration.c          |  1 -
  hw/vfio/pci.c                | 57 +++++++++++++++++-------------------
  hw/vfio/platform.c           | 25 ++++++++--------
  hw/vfio/spapr.c              |  4 +--
  hw/vfio/meson.build          | 33 ++++++++++++---------
  18 files changed, 117 insertions(+), 99 deletions(-)

Patches 1-9 look ok and should be considered for the next PR if maintainers ack patch 6 and 8.

Some comments,

vfio-amd-xgbe and vfio-calxeda-xgmac should be treated like vfio-platform, and since vfio-platform was designed for aarch64, these devices should not be available on arm, ppc, ppc64, riscv*, loongarch. That said, vfio-platform and devices being deprecated in the QEMU 10.0 cycle, we could just wait for the removal in QEMU 10.2.

How could we (simply) remove CONFIG_VFIO_IGD in hw/vfio/pci-quirks.c ? and compile this file only once.

Quoted 6 lines

The vfio-pci devices are available in nearly all targets when it only makes sense to have them in i386, x86_64, aarch64, ppc64, where they are supported, and also possibly in ppc (tcg) and arm (tcg) for historical reasons and just because they happen to work. ppc (tcg) doesn't support MSIs with vfio-pci devices so I don't think we care much.

Maybe it does not support MSI yet but if it can be fixed I might be interested later. But I don't know how that should work and what's needed for it in QEMU. There are ppc machines with PCIe ports (like sam460ex but I did not implement PCIe on it yet) and some GPUs could be used on those so having MSI might help or be needed. If it works on the real machine it could work on QEMU too. Currently people who tried GPU pass through on ppc told that it works but slow. I don't know the why or how to debug that but could it be due to missing MSI support? If so we might be interested to solve that eventually if possible.

Regards,
BALATON Zoltan

#56 lore raw
In reply to Cédric Le Goater
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Philippe Mathieu-Daudé

By doing the following changes:
- Clean some headers up
- Replace compile-time CONFIG_KVM check by kvm_enabled()
- Replace compile-time CONFIG_IOMMUFD check by iommufd_builtin() we can build less vfio objects.

Philippe Mathieu-Daudé (14):
   hw/vfio/common: Include missing 'system/tcg.h' header hw/vfio/spapr: Do not include <linux/kvm.h>
   hw/vfio: Compile some common objects once
   hw/vfio: Compile more objects once
   hw/vfio: Compile iommufd.c once
   system: Declare qemu_[min/max]rampagesize() in 'system/hostmem.h' hw/vfio: Compile display.c once
   system/kvm: Expose kvm_irqchip_[add,remove]_change_notifier() hw/vfio/pci: Convert CONFIG_KVM check to runtime one system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using iommufd_builtin

  docs/devel/vfio-iommufd.rst  |  2 +- include/exec/ram_addr.h      |  3 -- include/system/hostmem.h     |  3 ++ include/system/iommufd.h     |  8 +++++ include/system/kvm.h         |  8 ++--- target/s390x/kvm/kvm_s390x.h |  2 +- accel/stubs/kvm-stub.c       | 12 ++++++++ hw/ppc/spapr_caps.c          |  1 + hw/s390x/s390-virtio-ccw.c   |  1 +
  hw/vfio/ap.c                 | 27 ++++++++--------- hw/vfio/ccw.c                | 27 ++++++++--------- hw/vfio/common.c             |  1 +
  hw/vfio/iommufd.c            |  1 -
  hw/vfio/migration.c          |  1 -
  hw/vfio/pci.c                | 57 +++++++++++++++++------------------- hw/vfio/platform.c           | 25 ++++++++-------- hw/vfio/spapr.c              |  4 +--
  hw/vfio/meson.build          | 33 ++++++++++++---------

Quoted 2 lines
  18 files changed, 117 insertions(+), 99 deletions(-)
Quoted 2 lines

Patches 1-9 look ok and should be considered for the next PR if maintainers ack patch 6 and 8.

OK.

Quoted 16 lines

vfio-amd-xgbe and vfio-calxeda-xgmac should be treated like vfio-platform, and since vfio-platform was designed for aarch64, these devices should not be available on arm, ppc, ppc64, riscv*, loongarch. That said, vfio-platform and devices being deprecated in the QEMU 10.0 cycle, we could just wait for the removal in QEMU 10.2.

How could we (simply) remove CONFIG_VFIO_IGD in hw/vfio/pci-quirks.c ? and compile this file only once.

The vfio-pci devices are available in nearly all targets when it only makes sense to have them in i386, x86_64, aarch64, ppc64, where they are supported, and also possibly in ppc (tcg) and arm (tcg) for historical reasons and just because they happen to work. ppc (tcg) doesn't support MSIs with vfio-pci devices so I don't think we care much.

Quoted 2 lines

Patches 10-14 are wrong because they remove the "iommufd" property of the "vfio-*" devices. We can't take these.

I suppose this is due to the wrong implementation of iommufd_builtin() I mentioned in patch #10, which check instance but not class.

Thanks!