Skip to contentSkip to conversation

hw/vfio: Build various objects once

PATCH Superseded Philippe Mathieu-Daudé 7 participants 54 messages Mar 8, 2025 – Mar 11, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

Since v1:
- Added R-b tags
- Introduce type_is_registered()
- Split builtin check VS meson changes (rth)
- Consider IGD

Philippe Mathieu-Daudé (21):
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
qom: Introduce type_is_registered()
hw/vfio/igd: Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin() hw/vfio/igd: Compile once
system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/pci: Compile once
hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/s390x: Compile AP and CCW once
hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using
iommufd_builtin
hw/vfio/platform: Compile once

 docs/devel/vfio-iommufd.rst  |  2 +-
 hw/vfio/pci-quirks.h         |  8 +++++
 include/exec/ram_addr.h      |  3 --
 include/qom/object.h         |  8 +++++
 include/system/hostmem.h     |  3 ++
 include/system/iommufd.h     |  6 ++++
 include/system/kvm.h         |  8 ++---
 target/s390x/kvm/kvm_s390x.h |  2 +-
 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/igd-stubs.c          | 20 +++++++++++++
 hw/vfio/igd.c                |  4 +--
 hw/vfio/iommufd.c            |  1 -
 hw/vfio/migration.c          |  1 -
 hw/vfio/pci-quirks.c         |  9 +++---
 hw/vfio/pci.c                | 57 +++++++++++++++++-------------------
 hw/vfio/platform.c           | 25 ++++++++--------
 hw/vfio/spapr.c              |  4 +--
 qom/object.c                 |  5 ++++
 hw/vfio/meson.build          | 35 +++++++++++++---------
 23 files changed, 152 insertions(+), 106 deletions(-)
 create mode 100644 hw/vfio/igd-stubs.c
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 1/21 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 v2 1/21
#2 lore raw

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

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 :
        |                                             ^~~~~~~~~~~

Eric

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 =
#3 lore raw

PATCH v2 2/21 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 v2 2/21
#4 lore raw

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

Quoted 1 line · Philippe Mathieu-Daudé

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

included

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

Eric

Quoted 3 lines
hw/vfio/spapr.c +0 -0
 #include "system/kvm.h"
 #include "exec/address-spaces.h"
 
#5 lore raw

PATCH v2 3/21 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 v2 3/21
#6 lore raw

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

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

Eric

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',
+))
#7 lore raw

PATCH v2 4/21 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 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/vfio/meson.build +2 -2
index 8e376cfcbf8..784eae4b559 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', if_true: files(
   'helpers.c',
   'container-base.c',
Signature · 1 line
2.47.1
Reviewed-by on v2 4/21
#8 lore raw

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

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.

Eric

Quoted 24 lines
---
 hw/vfio/meson.build | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/vfio/meson.build +2 -2
index 8e376cfcbf8..784eae4b559 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', if_true: files(
   'helpers.c',
   'container-base.c',
#9 lore raw

PATCH v2 5/21 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 784eae4b559..5c9ec7e8971 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 v2 5/21
#10 lore raw

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

Quoted 7 lines · Philippe Mathieu-Daudé

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

Eric

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 784eae4b559..5c9ec7e8971 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',
+))
#11 lore raw

PATCH v2 6/21 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, having the following call stack:

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 TYPE_MEMORY_BACKEND defined in "system/hostmem.h":

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

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 v2 6/21
#12 lore raw

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

Quoted 12 lines · Philippe Mathieu-Daudé

Both qemu_minrampagesize() and qemu_maxrampagesize() are related to host memory backends, having the following call stack:

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

Having TYPE_MEMORY_BACKEND defined in "system/hostmem.h":

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

Move their prototype declaration to "system/hostmem.h".

Eric

Quoted 70 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(-)
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"
#13 lore raw

PATCH v2 7/21 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 5c9ec7e8971..a8939c83865 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 v2 7/21
#14 lore raw

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

Quoted 7 lines · Philippe Mathieu-Daudé

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

Eric

Quoted 23 lines
---
 hw/vfio/meson.build | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/meson.build +3 -1
index 5c9ec7e8971..a8939c83865 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',
+))
#15 lore raw

PATCH v2 8/21 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, otherwise the next commit would trigger:

hw/vfio/pci.c: In function ‘vfio_realize’:
hw/vfio/pci.c:3178:9: error: implicit declaration of function ‘kvm_irqchip_add_change_notifier’

   3178 |         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |         kvm_irqchip_add_irqfd_notifier
  hw/vfio/pci.c:3236:9: error: implicit declaration of function ‘kvm_irqchip_remove_change_notifier’
   3236 |         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |         kvm_irqchip_remove_irqfd_notifier
---
 include/system/kvm.h | 8 ++++----
 1 file changed, 4 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,
Signature · 1 line
2.47.1
Reviewed-by on v2 8/21
#16 lore raw

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

Quoted 18 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, otherwise the next commit would trigger:

   hw/vfio/pci.c: In function ‘vfio_realize’:
   hw/vfio/pci.c:3178:9: error: implicit declaration of function ‘kvm_irqchip_add_change_notifier’
    3178 |         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |         kvm_irqchip_add_irqfd_notifier
   hw/vfio/pci.c:3236:9: error: implicit declaration of function ‘kvm_irqchip_remove_change_notifier’
    3236 |         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |         kvm_irqchip_remove_irqfd_notifier
Quoted 5 lines
---
  include/system/kvm.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

r~

Reviewed-by on v2 8/21
#17 lore raw

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

In reply to Philippe Mathieu-Daudé
Quoted 18 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, otherwise the next commit would trigger:

hw/vfio/pci.c: In function ‘vfio_realize’:
hw/vfio/pci.c:3178:9: error: implicit declaration of function ‘kvm_irqchip_add_change_notifier’

   3178 |         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |         kvm_irqchip_add_irqfd_notifier
  hw/vfio/pci.c:3236:9: error: implicit declaration of function ‘kvm_irqchip_remove_change_notifier’
   3236 |         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |         kvm_irqchip_remove_irqfd_notifier
Quoted 2 lines

Eric

Quoted 30 lines
---
 include/system/kvm.h | 8 ++++----
 1 file changed, 4 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,
#18 lore raw

PATCH v2 9/21 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
#19 lore raw

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

Hi Philippe,

Quoted 2 lines · Philippe Mathieu-Daudé

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

Miss the "why" of this patch.

By the way I fail to remember/see where kvm_allowed is set.

I am also confused because we still have some code, like in vfio/common.c which does both checks:
#ifdef CONFIG_KVM
        if (kvm_enabled()) {
            max_memslots = kvm_get_max_memslots(); }
#endif

Thanks

Eric

Quoted 72 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) {
#20 lore raw

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

Quoted 9 lines · Eric Auger

Hi Philippe,

Quoted 2 lines · Philippe Mathieu-Daudé

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

Miss the "why" of this patch.

By the way I fail to remember/see where kvm_allowed is set.

It's in include/system/kvm.h

Quoted 7 lines

I am also confused because we still have some code, like in vfio/common.c which does both checks:
#ifdef CONFIG_KVM
        if (kvm_enabled()) {
            max_memslots = kvm_get_max_memslots(); }
#endif

I think this is because if KVM is not available the if cannot be true so it can be left out altogether. This may make sense on platforms like Windows and macOS where QEMU is compiled without KVM so basically everywhere except Linux.

Regards,
BALATON Zoltan

#21 lore raw

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

Hi,

Quoted 4 lines · BALATON Zoltan
Quoted 3 lines · Eric Auger

Hi Philippe,

On 3/9/25 12:09 AM, Philippe Mathieu-Daudé wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

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

Miss the "why" of this patch.

By the way I fail to remember/see where kvm_allowed is set.

It's in include/system/kvm.h

There you can only find the kvm_enabled() macro definition.

I was eventually able to locate it:
accel/accel-system.c:    *(acc->allowed) = true;
in accel_init_machine()

Quoted 9 lines
Quoted 8 lines

I am also confused because we still have some code, like in vfio/common.c which does both checks:
#ifdef CONFIG_KVM
        if (kvm_enabled()) {
            max_memslots = kvm_get_max_memslots(); }
#endif

Quoted 4 lines

I think this is because if KVM is not available the if cannot be true so it can be left out altogether. This may make sense on platforms like Windows and macOS where QEMU is compiled without KVM so basically everywhere except Linux.

But in practice we have a stub for kvm_get_max_memslots in accel/stubs/kvm-stub.c.

Eric

Quoted 3 lines

Regards,
BALATON Zoltan

#22 lore raw

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

In reply to BALATON Zoltan
Quoted 10 lines · BALATON Zoltan
Quoted 9 lines · Eric Auger

Hi Philippe,

Quoted 2 lines · Philippe Mathieu-Daudé

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

Miss the "why" of this patch.

By the way I fail to remember/see where kvm_allowed is set.

In accel/accel-system.c:

    int accel_init_machine(AccelState *accel, MachineState *ms)
    {
        AccelClass *acc = ACCEL_GET_CLASS(accel);
        int ret;
        ms->accelerator = accel;
        *(acc->allowed) = true;
        ret = acc->init_machine(ms);
        if (ret < 0) {
            ms->accelerator = NULL;
            *(acc->allowed) = false;
            object_unref(OBJECT(accel));
        } else {
            object_set_accelerator_compat_props(acc->compat_props);
        }
        return ret;
    }
Quoted 10 lines

It's in include/system/kvm.h

Quoted 7 lines

I am also confused because we still have some code, like in vfio/common.c which does both checks:
#ifdef CONFIG_KVM
        if (kvm_enabled()) {
            max_memslots = kvm_get_max_memslots(); }
#endif

We should prefer kvm_enabled() over CONFIG_KVM, but for kvm_enabled() we need the prototypes declared, which sometimes aren't.

#23 lore raw

PATCH v2 10/21 qom: Introduce type_is_registered()

In reply to Philippe Mathieu-Daudé

In order to be able to check whether a QOM type has been registered, introduce the type_is_registered() helper.

---
 include/qom/object.h | 8 ++++++++
 qom/object.c         | 5 +++++
 2 files changed, 13 insertions(+)
include/qom/object.h +8 -0
index 9192265db76..5b5333017e0 100644
@@ -898,6 +898,14 @@ Type type_register_static(const TypeInfo *info);
  */
 void type_register_static_array(const TypeInfo *infos, int nr_infos);
 
+/**
+ * type_is_registered:
+ * @typename: The @typename to check.
+ *
+ * Returns: %true if @typename has been registered, %false otherwise.
+ */
+bool type_is_registered(const char *typename);
+
 /**
  * DEFINE_TYPES:
  * @type_array: The array containing #TypeInfo structures to register
qom/object.c +5 -0
index 01618d06bd8..be442980049 100644
@@ -100,6 +100,11 @@ static TypeImpl *type_table_lookup(const char *name)
     return g_hash_table_lookup(type_table_get(), name);
 }
 
+bool type_is_registered(const char *typename)
+{
+    return !!type_table_lookup(typename);
+}
+
 static TypeImpl *type_new(const TypeInfo *info)
 {
     TypeImpl *ti = g_malloc0(sizeof(*ti));
Signature · 1 line
2.47.1
Reviewed-by on v2 10/21
#24 lore raw

Re: [PATCH v2 10/21] qom: Introduce type_is_registered()

Quoted 8 lines · Philippe Mathieu-Daudé

In order to be able to check whether a QOM type has been registered, introduce the type_is_registered() helper.

---
  include/qom/object.h | 8 ++++++++
  qom/object.c         | 5 +++++
  2 files changed, 13 insertions(+)

Does the non-initialization of the type matter for your usage? In other words, would object_class_by_name() do the job just as well?

But seems reasonable, anyway.

r~

Reviewed-by on v2 10/21
#25 lore raw

Re: [PATCH v2 10/21] qom: Introduce type_is_registered()

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

In order to be able to check whether a QOM type has been registered, introduce the type_is_registered() helper.

FWIW,

Thanks,

C.

Quoted 40 lines
---
  include/qom/object.h | 8 ++++++++
  qom/object.c         | 5 +++++
  2 files changed, 13 insertions(+)
include/qom/object.h +8 -0
index 9192265db76..5b5333017e0 100644
@@ -898,6 +898,14 @@ Type type_register_static(const TypeInfo *info);
   */
  void type_register_static_array(const TypeInfo *infos, int nr_infos);
 
+/**
+ * type_is_registered:
+ * @typename: The @typename to check.
+ *
+ * Returns: %true if @typename has been registered, %false otherwise.
+ */
+bool type_is_registered(const char *typename);
+
  /**
   * DEFINE_TYPES:
   * @type_array: The array containing #TypeInfo structures to register
qom/object.c +5 -0
index 01618d06bd8..be442980049 100644
@@ -100,6 +100,11 @@ static TypeImpl *type_table_lookup(const char *name)
      return g_hash_table_lookup(type_table_get(), name);
  }
 
+bool type_is_registered(const char *typename)
+{
+    return !!type_table_lookup(typename);
+}
+
  static TypeImpl *type_new(const TypeInfo *info)
  {
      TypeImpl *ti = g_malloc0(sizeof(*ti));
Reviewed-by on v2 10/21
#26 lore raw

Re: [PATCH v2 10/21] qom: Introduce type_is_registered()

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

In order to be able to check whether a QOM type has been registered, introduce the type_is_registered() helper.

Eric

Quoted 40 lines
---
 include/qom/object.h | 8 ++++++++
 qom/object.c         | 5 +++++
 2 files changed, 13 insertions(+)
include/qom/object.h +8 -0
index 9192265db76..5b5333017e0 100644
@@ -898,6 +898,14 @@ Type type_register_static(const TypeInfo *info);
  */
 void type_register_static_array(const TypeInfo *infos, int nr_infos);
 
+/**
+ * type_is_registered:
+ * @typename: The @typename to check.
+ *
+ * Returns: %true if @typename has been registered, %false otherwise.
+ */
+bool type_is_registered(const char *typename);
+
 /**
  * DEFINE_TYPES:
  * @type_array: The array containing #TypeInfo structures to register
qom/object.c +5 -0
index 01618d06bd8..be442980049 100644
@@ -100,6 +100,11 @@ static TypeImpl *type_table_lookup(const char *name)
     return g_hash_table_lookup(type_table_get(), name);
 }
 
+bool type_is_registered(const char *typename)
+{
+    return !!type_table_lookup(typename);
+}
+
 static TypeImpl *type_new(const TypeInfo *info)
 {
     TypeImpl *ti = g_malloc0(sizeof(*ti));
#27 lore raw

PATCH v2 11/21 hw/vfio/igd: Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE

In reply to Philippe Mathieu-Daudé

Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE once to help
following where the QOM type is used in the code.
We'll use it once more in the next commit.

---
 hw/vfio/pci-quirks.h | 2 ++
 hw/vfio/igd.c        | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/vfio/pci-quirks.h +2 -0
index d1532e379b1..fdaa81f00aa 100644
@@ -69,4 +69,6 @@ typedef struct VFIOConfigMirrorQuirk {
 
 extern const MemoryRegionOps vfio_generic_mirror_quirk;
 
+#define TYPE_VFIO_PCI_IGD_LPC_BRIDGE "vfio-pci-igd-lpc-bridge"
+
 #endif /* HW_VFIO_VFIO_PCI_QUIRKS_H */
hw/vfio/igd.c +2 -2
index b1a237edd66..1fd3c4ef1d0 100644
@@ -262,7 +262,7 @@ static void vfio_pci_igd_lpc_bridge_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo vfio_pci_igd_lpc_bridge_info = {
-    .name = "vfio-pci-igd-lpc-bridge",
+    .name = TYPE_VFIO_PCI_IGD_LPC_BRIDGE,
     .parent = TYPE_PCI_DEVICE,
     .class_init = vfio_pci_igd_lpc_bridge_class_init,
     .interfaces = (InterfaceInfo[]) {
@@ -524,7 +524,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
     lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
                                  0, PCI_DEVFN(0x1f, 0));
     if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
-                                           "vfio-pci-igd-lpc-bridge")) {
+                                           TYPE_VFIO_PCI_IGD_LPC_BRIDGE)) {
         error_report("IGD device %s cannot support legacy mode due to existing "
                      "devices at address 1f.0", vdev->vbasedev.name);
         return;
Signature · 1 line
2.47.1
Reviewed-by on v2 11/21
#28 lore raw

Re: [PATCH v2 11/21] hw/vfio/igd: Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE

Quoted 5 lines · Philippe Mathieu-Daudé

Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE once to help
following where the QOM type is used in the code.
We'll use it once more in the next commit.

Thanks,

C.

Quoted 38 lines
---
  hw/vfio/pci-quirks.h | 2 ++
  hw/vfio/igd.c        | 4 ++--
  2 files changed, 4 insertions(+), 2 deletions(-)
hw/vfio/pci-quirks.h +2 -0
index d1532e379b1..fdaa81f00aa 100644
@@ -69,4 +69,6 @@ typedef struct VFIOConfigMirrorQuirk {
 
  extern const MemoryRegionOps vfio_generic_mirror_quirk;
 
+#define TYPE_VFIO_PCI_IGD_LPC_BRIDGE "vfio-pci-igd-lpc-bridge"
+
  #endif /* HW_VFIO_VFIO_PCI_QUIRKS_H */
hw/vfio/igd.c +2 -2
index b1a237edd66..1fd3c4ef1d0 100644
@@ -262,7 +262,7 @@ static void vfio_pci_igd_lpc_bridge_class_init(ObjectClass *klass, void *data)
  }
 
  static const TypeInfo vfio_pci_igd_lpc_bridge_info = {
-    .name = "vfio-pci-igd-lpc-bridge",
+    .name = TYPE_VFIO_PCI_IGD_LPC_BRIDGE,
      .parent = TYPE_PCI_DEVICE,
      .class_init = vfio_pci_igd_lpc_bridge_class_init,
      .interfaces = (InterfaceInfo[]) {
@@ -524,7 +524,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
      lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
                                   0, PCI_DEVFN(0x1f, 0));
      if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
-                                           "vfio-pci-igd-lpc-bridge")) {
+                                           TYPE_VFIO_PCI_IGD_LPC_BRIDGE)) {
          error_report("IGD device %s cannot support legacy mode due to existing "
                       "devices at address 1f.0", vdev->vbasedev.name);
          return;
Reviewed-by on v2 11/21
#29 lore raw

Re: [PATCH v2 11/21] hw/vfio/igd: Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE

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

Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE once to help
following where the QOM type is used in the code.
We'll use it once more in the next commit.

Eric

Quoted 38 lines
---
 hw/vfio/pci-quirks.h | 2 ++
 hw/vfio/igd.c        | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/vfio/pci-quirks.h +2 -0
index d1532e379b1..fdaa81f00aa 100644
@@ -69,4 +69,6 @@ typedef struct VFIOConfigMirrorQuirk {
 
 extern const MemoryRegionOps vfio_generic_mirror_quirk;
 
+#define TYPE_VFIO_PCI_IGD_LPC_BRIDGE "vfio-pci-igd-lpc-bridge"
+
 #endif /* HW_VFIO_VFIO_PCI_QUIRKS_H */
hw/vfio/igd.c +2 -2
index b1a237edd66..1fd3c4ef1d0 100644
@@ -262,7 +262,7 @@ static void vfio_pci_igd_lpc_bridge_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo vfio_pci_igd_lpc_bridge_info = {
-    .name = "vfio-pci-igd-lpc-bridge",
+    .name = TYPE_VFIO_PCI_IGD_LPC_BRIDGE,
     .parent = TYPE_PCI_DEVICE,
     .class_init = vfio_pci_igd_lpc_bridge_class_init,
     .interfaces = (InterfaceInfo[]) {
@@ -524,7 +524,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
     lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
                                  0, PCI_DEVFN(0x1f, 0));
     if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
-                                           "vfio-pci-igd-lpc-bridge")) {
+                                           TYPE_VFIO_PCI_IGD_LPC_BRIDGE)) {
         error_report("IGD device %s cannot support legacy mode due to existing "
                      "devices at address 1f.0", vdev->vbasedev.name);
         return;
#30 lore raw

PATCH v2 12/21 hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin()

In reply to Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_VFIO_IGD definition by a runtime one by calling vfio_igd_builtin(), which check whether VFIO_IGD is built in a qemu-system binary.

Add stubs to avoid when VFIO_IGD is not built in:

/usr/bin/ld: libqemu-x86_64-softmmu.a.p/hw_vfio_pci-quirks.c.o: in function `vfio_bar_quirk_setup':
/usr/bin/ld: ../hw/vfio/pci-quirks.c:1216: undefined reference to vfio_probe_igd_bar0_quirk' /usr/bin/ld: ../hw/vfio/pci-quirks.c:1217: undefined reference to vfio_probe_igd_bar4_quirk'

---
 hw/vfio/pci-quirks.h |  6 ++++++
 hw/vfio/igd-stubs.c  | 20 ++++++++++++++++++++
 hw/vfio/pci-quirks.c |  9 ++++-----
 hw/vfio/meson.build  |  3 +++
 4 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 hw/vfio/igd-stubs.c
hw/vfio/pci-quirks.h +6 -0
index fdaa81f00aa..dcdb1962600 100644
@@ -13,6 +13,7 @@
 #define HW_VFIO_VFIO_PCI_QUIRKS_H
 
 #include "qemu/osdep.h"
+#include "qom/object.h"
 #include "exec/memop.h"
 
 /*
@@ -71,4 +72,9 @@ extern const MemoryRegionOps vfio_generic_mirror_quirk;
 
 #define TYPE_VFIO_PCI_IGD_LPC_BRIDGE "vfio-pci-igd-lpc-bridge"
 
+static inline bool vfio_igd_builtin(void)
+{
+    return type_is_registered(TYPE_VFIO_PCI_IGD_LPC_BRIDGE);
+}
+
 #endif /* HW_VFIO_VFIO_PCI_QUIRKS_H */
hw/vfio/igd-stubs.c new file +20 -0
new file mode 100644
index 00000000000..5d4e88aeb1b
@@ -0,0 +1,20 @@
+/*
+ * IGD device quirk stubs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (C) Linaro, Ltd.
+ */
+
+#include "qemu/osdep.h"
+#include "pci.h"
+
+void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
+{
+    g_assert_not_reached();
+}
+
+void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
+{
+    g_assert_not_reached();
+}
hw/vfio/pci-quirks.c +4 -5
index c53591fe2ba..22cb35af8cc 100644
@@ -11,7 +11,6 @@
  */
 
 #include "qemu/osdep.h"
-#include CONFIG_DEVICES
 #include "exec/memop.h"
 #include "qemu/units.h"
 #include "qemu/log.h"
@@ -1213,10 +1212,10 @@ void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr)
     vfio_probe_nvidia_bar5_quirk(vdev, nr);
     vfio_probe_nvidia_bar0_quirk(vdev, nr);
     vfio_probe_rtl8168_bar2_quirk(vdev, nr);
-#ifdef CONFIG_VFIO_IGD
-    vfio_probe_igd_bar0_quirk(vdev, nr);
-    vfio_probe_igd_bar4_quirk(vdev, nr);
-#endif
+    if (vfio_igd_builtin()) {
+        vfio_probe_igd_bar0_quirk(vdev, nr);
+        vfio_probe_igd_bar4_quirk(vdev, nr);
+    }
 }
 
 void vfio_bar_quirk_exit(VFIOPCIDevice *vdev, int nr)
hw/vfio/meson.build +3 -0
index a8939c83865..6ab711d0539 100644
@@ -17,6 +17,9 @@ 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_false: files(
+  'igd-stubs.c',
+))
 system_ss.add(when: 'CONFIG_VFIO', if_true: files(
   'helpers.c',
   'container-base.c',
Signature · 1 line
2.47.1
#31 lore raw

Re: [PATCH v2 12/21] hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin()

Quoted 5 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_VFIO_IGD definition by a runtime one by calling vfio_igd_builtin(), which check whether VFIO_IGD is built in a qemu-system binary.

Add stubs to avoid when VFIO_IGD is not built in:

I thought we were trying to avoid stubs in QEMU build. Did that change ?

Thanks,

C.

Quoted 103 lines
   /usr/bin/ld: libqemu-x86_64-softmmu.a.p/hw_vfio_pci-quirks.c.o: in function `vfio_bar_quirk_setup':
   /usr/bin/ld: ../hw/vfio/pci-quirks.c:1216: undefined reference to `vfio_probe_igd_bar0_quirk'
   /usr/bin/ld: ../hw/vfio/pci-quirks.c:1217: undefined reference to `vfio_probe_igd_bar4_quirk'
---
  hw/vfio/pci-quirks.h |  6 ++++++
  hw/vfio/igd-stubs.c  | 20 ++++++++++++++++++++
  hw/vfio/pci-quirks.c |  9 ++++-----
  hw/vfio/meson.build  |  3 +++
  4 files changed, 33 insertions(+), 5 deletions(-)

create mode 100644 hw/vfio/igd-stubs.c

hw/vfio/pci-quirks.h +6 -0
index fdaa81f00aa..dcdb1962600 100644
@@ -13,6 +13,7 @@
  #define HW_VFIO_VFIO_PCI_QUIRKS_H
 
  #include "qemu/osdep.h"
+#include "qom/object.h"
  #include "exec/memop.h"
 
  /*
@@ -71,4 +72,9 @@ extern const MemoryRegionOps vfio_generic_mirror_quirk;
 
  #define TYPE_VFIO_PCI_IGD_LPC_BRIDGE "vfio-pci-igd-lpc-bridge"
 
+static inline bool vfio_igd_builtin(void)
+{
+    return type_is_registered(TYPE_VFIO_PCI_IGD_LPC_BRIDGE);
+}
+
  #endif /* HW_VFIO_VFIO_PCI_QUIRKS_H */
hw/vfio/igd-stubs.c new file +20 -0
new file mode 100644
index 00000000000..5d4e88aeb1b
@@ -0,0 +1,20 @@
+/*
+ * IGD device quirk stubs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (C) Linaro, Ltd.
+ */
+
+#include "qemu/osdep.h"
+#include "pci.h"
+
+void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
+{
+    g_assert_not_reached();
+}
+
+void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
+{
+    g_assert_not_reached();
+}
hw/vfio/pci-quirks.c +4 -5
index c53591fe2ba..22cb35af8cc 100644
@@ -11,7 +11,6 @@
   */
 
  #include "qemu/osdep.h"
-#include CONFIG_DEVICES
  #include "exec/memop.h"
  #include "qemu/units.h"
  #include "qemu/log.h"
@@ -1213,10 +1212,10 @@ void vfio_bar_quirk_setup(VFIOPCIDevice *vdev, int nr)
      vfio_probe_nvidia_bar5_quirk(vdev, nr);
      vfio_probe_nvidia_bar0_quirk(vdev, nr);
      vfio_probe_rtl8168_bar2_quirk(vdev, nr);
-#ifdef CONFIG_VFIO_IGD
-    vfio_probe_igd_bar0_quirk(vdev, nr);
-    vfio_probe_igd_bar4_quirk(vdev, nr);
-#endif
+    if (vfio_igd_builtin()) {
+        vfio_probe_igd_bar0_quirk(vdev, nr);
+        vfio_probe_igd_bar4_quirk(vdev, nr);
+    }
  }
 
  void vfio_bar_quirk_exit(VFIOPCIDevice *vdev, int nr)
hw/vfio/meson.build +3 -0
index a8939c83865..6ab711d0539 100644
@@ -17,6 +17,9 @@ 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_false: files(
+  'igd-stubs.c',
+))
  system_ss.add(when: 'CONFIG_VFIO', if_true: files(
    'helpers.c',
    'container-base.c',
#32 lore raw

Re: [PATCH v2 12/21] hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin()

Quoted 8 lines · Cédric Le Goater
Quoted 5 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_VFIO_IGD definition by a runtime one by calling vfio_igd_builtin(), which check whether VFIO_IGD is built in a qemu-system binary.

Add stubs to avoid when VFIO_IGD is not built in:

I thought we were trying to avoid stubs in QEMU build. Did that change ?

Hmm so you want remove the VFIO_IGD Kconfig symbol and have it always builtin with VFIO. It might make sense for quirks, since vfio_realize() already checks for the VFIO_FEATURE_ENABLE_IGD_OPREGION feature.

I'll see if there aren't other implications I missed.

Thanks,

Phil.

#33 lore raw

Re: [PATCH v2 12/21] hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin()

Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Cédric Le Goater
Quoted 4 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_VFIO_IGD definition by a runtime one by calling vfio_igd_builtin(), which check whether VFIO_IGD is built in a qemu-system binary.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Add stubs to avoid when VFIO_IGD is not built in:

I thought we were trying to avoid stubs in QEMU build. Did that change ?

Hmm so you want remove the VFIO_IGD Kconfig symbol and have it always builtin with VFIO. It might make sense for quirks, since vfio_realize() already checks for the VFIO_FEATURE_ENABLE_IGD_OPREGION feature.

I have explored this option in the past and it's much more work. Stubs are fine IMO, if we can have them, but I remember someone telling me (you ?) that we were trying to remove them.

Thanks,

C.

Quoted 6 lines

I'll see if there aren't other implications I missed.

Thanks,

Phil.

#34 lore raw

Re: [PATCH v2 12/21] hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin()

Quoted 11 lines · Cédric Le Goater
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Cédric Le Goater
Quoted 5 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_VFIO_IGD definition by a runtime one by calling vfio_igd_builtin(), which check whether VFIO_IGD is built in a qemu-system binary.

Add stubs to avoid when VFIO_IGD is not built in:

I thought we were trying to avoid stubs in QEMU build. Did that change ?

Quoted 7 lines
Quoted 3 lines

Hmm so you want remove the VFIO_IGD Kconfig symbol and have it always builtin with VFIO. It might make sense for quirks, since vfio_realize() already checks for the VFIO_FEATURE_ENABLE_IGD_OPREGION feature.

I have explored this option in the past and it's much more work. Stubs are fine IMO, if we can have them, but I remember someone telling me (you ?) that we were trying to remove them.

We shouldn't have target-specific stubs. (currently CONFIG_DEVICES::VFIO_IGD is target specific).

I don't think we can avoid host-specific stubs.

In unified binary, CONFIG_DEVICES disappears, VFIO_IGD will be handled like host configuration. Although if possible I'd rather remove VFIO_IGD, unconditionally including all quirks.

#35 lore raw

Re: [PATCH v2 12/21] hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin()

In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Cédric Le Goater
Quoted 5 lines · Philippe Mathieu-Daudé

Convert the compile time check on the CONFIG_VFIO_IGD definition by a runtime one by calling vfio_igd_builtin(), which check whether VFIO_IGD is built in a qemu-system binary.

Add stubs to avoid when VFIO_IGD is not built in:

I thought we were trying to avoid stubs in QEMU build. Did that change ?

Hmm so you want remove the VFIO_IGD Kconfig symbol and have it always builtin with VFIO. It might make sense for quirks, since vfio_realize() already checks for the VFIO_FEATURE_ENABLE_IGD_OPREGION feature.

Quoted 5 lines

I'll see if there aren't other implications I missed.

Thanks,

Phil.

I personally suggest keeping the VFIO_IGD Kconfig symbol to prevent building IGD-specific code into non x86 target. The change Cedric mentioned in another reply [1] moves VFIO_FEATURE_ENABLE_IGD_OPREGION from vfio_realize() to igd.c.

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

Thanks,
Moeko

#36 lore raw

PATCH v2 13/21 hw/vfio/igd: Compile once

In reply to Philippe Mathieu-Daudé

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

---
 hw/vfio/meson.build | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/meson.build +3 -2
index 6ab711d0539..21c9cd6d2eb 100644
@@ -11,13 +11,14 @@ 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'))
-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_false: files(
+system_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files(
+  'igd.c',
+), if_false: files(
   'igd-stubs.c',
 ))
 system_ss.add(when: 'CONFIG_VFIO', if_true: files(
Signature · 1 line
2.47.1
Reviewed-by on v2 13/21
#37 lore raw

Re: [PATCH v2 13/21] hw/vfio/igd: Compile once

Quoted 4 lines · Philippe Mathieu-Daudé

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

Thanks,

C.

Quoted 25 lines
---
  hw/vfio/meson.build | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/meson.build +3 -2
index 6ab711d0539..21c9cd6d2eb 100644
@@ -11,13 +11,14 @@ 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'))
-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_false: files(
+system_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files(
+  'igd.c',
+), if_false: files(
    'igd-stubs.c',
  ))
  system_ss.add(when: 'CONFIG_VFIO', if_true: files(
#38 lore raw

Re: [PATCH v2 13/21] hw/vfio/igd: Compile once

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

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

There are conflicts with series [1] modifying igd. I think it would be better to wait after it's merged, unless you have time to rebase on top of [1]

Thanks,

C.

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

Quoted 25 lines
---
  hw/vfio/meson.build | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/meson.build +3 -2
index 6ab711d0539..21c9cd6d2eb 100644
@@ -11,13 +11,14 @@ 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'))
-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_false: files(
+system_ss.add(when: 'CONFIG_VFIO_IGD', if_true: files(
+  'igd.c',
+), if_false: files(
    'igd-stubs.c',
  ))
  system_ss.add(when: 'CONFIG_VFIO', if_true: files(
#39 lore raw

PATCH v2 14/21 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    | 6 ++++++
 2 files changed, 7 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 +6 -0
index cbab75bfbf6..3fedf8cfb63 100644
@@ -63,4 +63,10 @@ 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)
+{
+    return type_is_registered(TYPE_IOMMUFD_BACKEND);
+}
+
 #endif
Signature · 1 line
2.47.1
#40 lore raw

PATCH v2 15/21 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().

---
 hw/vfio/pci.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 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 "
Signature · 1 line
2.47.1
#41 lore raw

RE: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Hi Philippe,

Quoted 71 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

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

---
hw/vfio/pci.c | 38 ++++++++++++++++++--------------------

1 file changed, 18 insertions(+), 20 deletions(-)
hw/vfio/pci.c +4 -6
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 =
hw/vfio/pci.c +5 -6
@@ -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)

{

hw/vfio/pci.c static void vfio_pci_dev_class_init(ObjectClass *klass, · line 3435

Quoted 9 lines
hw/vfio/pci.c +2 -3
@@ -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);

device_class_set_props() is called twice. Won't it break qdev_print_props() and qdev_prop_walk()?

Thanks
Zhenzhong

#42 lore raw

Re: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 23 lines · Zhenzhong

Hi Philippe,

Quoted 21 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

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

---
hw/vfio/pci.c | 38 ++++++++++++++++++--------------------

1 file changed, 18 insertions(+), 20 deletions(-)

static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) {

(quoted diff) +0 -0
@@ -3433,9 +3430,10 @@ static void vfio_pci_dev_class_init(ObjectClass *klass,
 void *data)
 
Quoted 9 lines

hw/vfio/pci.c static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) · line 3434

Quoted 7 lines
hw/vfio/pci.c +2 -3
     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);

device_class_set_props() is called twice. Won't it break qdev_print_props() and qdev_prop_walk()?

device_class_set_props() is misnamed, as it doesn't SET an array of properties, but ADD them (or 'register') to the class.

See device_class_set_props_n() in hw/core/qdev-properties.c.

I'll see to rename the QDev methods for clarity.

Regards,

Phil.

#43 lore raw

RE: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 41 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 18 lines · Zhenzhong

Hi Philippe,

Quoted 14 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

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

---
hw/vfio/pci.c | 38 ++++++++++++++++++--------------------

1 file changed, 18 insertions(+), 20 deletions(-)
Quoted 3 lines

Review static void vfio_pci_dev_class_init(ObjectClass

Quoted 3 lines

static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) {

(quoted diff) +0 -0
@@ -3433,9 +3430,10 @@ static void vfio_pci_dev_class_init(ObjectClass

*klass,

Quoted 11 lines

hw/vfio/pci.c static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) · line 3434

Quoted 9 lines
hw/vfio/pci.c +2 -3
 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);

device_class_set_props() is called twice. Won't it break qdev_print_props() and

Quoted 6 lines

qdev_prop_walk()?

device_class_set_props() is misnamed, as it doesn't SET an array of properties, but ADD them (or 'register') to the class.

See device_class_set_props_n() in hw/core/qdev-properties.c.

But it set dc->props_ and dc->props_count_, first to vfio_pci_dev_properties and then vfio_pci_dev_iommufd_properties, this will make qdev_prop_walk() find only iommufd property and miss others. Do I misunderstand?

Thanks
Zhenzhong

Quoted 6 lines

I'll see to rename the QDev methods for clarity.

Regards,

Phil.

#44 lore raw

Re: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 43 lines · Zhenzhong
Quoted 43 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

Quoted 18 lines · Zhenzhong

Hi Philippe,

Quoted 14 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v2 15/21] hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin()

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

---
hw/vfio/pci.c | 38 ++++++++++++++++++--------------------

1 file changed, 18 insertions(+), 20 deletions(-)
Quoted 3 lines

Review static void vfio_pci_dev_class_init(ObjectClass

Quoted 3 lines

static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) {

(quoted diff) +0 -0
@@ -3433,9 +3430,10 @@ static void vfio_pci_dev_class_init(ObjectClass

*klass,

Quoted 11 lines

hw/vfio/pci.c static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) · line 3434

Quoted 9 lines
hw/vfio/pci.c +2 -3
 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);

device_class_set_props() is called twice. Won't it break qdev_print_props() and

qdev_prop_walk()?

Quoted 8 lines
Quoted 4 lines

device_class_set_props() is misnamed, as it doesn't SET an array of properties, but ADD them (or 'register') to the class.

See device_class_set_props_n() in hw/core/qdev-properties.c.

But it set dc->props_ and dc->props_count_, first to vfio_pci_dev_properties and then vfio_pci_dev_iommufd_properties, this will make qdev_prop_walk() find only iommufd property and miss others. Do I misunderstand?

You are right! And I thought I was understanding what this code does...

#45 lore raw

PATCH v2 16/21 hw/vfio/pci: Compile once

In reply to Philippe Mathieu-Daudé

Since the files don't use any target-specific knowledge anymore, move them to system_ss[] to build them once.

---
 hw/vfio/meson.build | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/vfio/meson.build +2 -4
index 21c9cd6d2eb..ff9bd4f2e35 100644
@@ -4,10 +4,6 @@ vfio_ss.add(files(
   'container.c',
 ))
 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'))
 vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
@@ -33,4 +29,6 @@ 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',
+  'pci-quirks.c',
 ))
Signature · 1 line
2.47.1
#46 lore raw

PATCH v2 17/21 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().

---
 hw/vfio/ap.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
hw/vfio/ap.c +12 -13
index c7ab4ff57ad..a4ec2b5f9ac 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"
@@ -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 = {
Signature · 1 line
2.47.1
#47 lore raw

PATCH v2 18/21 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().

---
 hw/vfio/ccw.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 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");
Signature · 1 line
2.47.1
#48 lore raw

PATCH v2 19/21 hw/vfio/s390x: Compile AP and CCW once

In reply to Philippe Mathieu-Daudé

Since the files don't use any target-specific knowledge anymore, move them to system_ss[] to build them once, even if they are only used for one unique binary (qemu-system-s390x).

Because files in system_ss[] don't get the target/foo/ path in their CPPFLAGS, use header paths relative to the root directory.

---
 target/s390x/kvm/kvm_s390x.h | 2 +-
 hw/vfio/ap.c                 | 2 +-
 hw/vfio/meson.build          | 4 ++--
 3 files changed, 4 insertions(+), 4 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 +1 -1
index a4ec2b5f9ac..832b98532ea 100644
@@ -23,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"
hw/vfio/meson.build +2 -2
index ff9bd4f2e35..3119c841ed9 100644
@@ -4,9 +4,7 @@ vfio_ss.add(files(
   'container.c',
 ))
 vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.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'))
-vfio_ss.add(when: 'CONFIG_VFIO_AP', if_true: files('ap.c'))
 
 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 
@@ -27,6 +25,8 @@ 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_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
#49 lore raw

PATCH v2 20/21 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().

---
 hw/vfio/platform.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 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 = {
Signature · 1 line
2.47.1
#50 lore raw

PATCH v2 21/21 hw/vfio/platform: Compile once

In reply to Philippe Mathieu-Daudé

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

---
 hw/vfio/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/meson.build +1 -1
index 3119c841ed9..2bcbd052950 100644
@@ -4,7 +4,6 @@ vfio_ss.add(files(
   'container.c',
 ))
 vfio_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr.c'))
-vfio_ss.add(when: 'CONFIG_VFIO_PLATFORM', if_true: files('platform.c'))
 
 specific_ss.add_all(when: 'CONFIG_VFIO', if_true: vfio_ss)
 
@@ -27,6 +26,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
#51 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 60 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.

Since v1:
- Added R-b tags
- Introduce type_is_registered()
- Split builtin check VS meson changes (rth)
- Consider IGD

Philippe Mathieu-Daudé (21):
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
qom: Introduce type_is_registered()
hw/vfio/igd: Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin() hw/vfio/igd: Compile once
system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/pci: Compile once
hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/s390x: Compile AP and CCW once
hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using
iommufd_builtin
hw/vfio/platform: Compile once

  docs/devel/vfio-iommufd.rst  |  2 +-
  hw/vfio/pci-quirks.h         |  8 +++++
  include/exec/ram_addr.h      |  3 --
  include/qom/object.h         |  8 +++++
  include/system/hostmem.h     |  3 ++
  include/system/iommufd.h     |  6 ++++
  include/system/kvm.h         |  8 ++---
  target/s390x/kvm/kvm_s390x.h |  2 +-
  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/igd-stubs.c          | 20 +++++++++++++
  hw/vfio/igd.c                |  4 +--
  hw/vfio/iommufd.c            |  1 -
  hw/vfio/migration.c          |  1 -
  hw/vfio/pci-quirks.c         |  9 +++---
  hw/vfio/pci.c                | 57 +++++++++++++++++-------------------
  hw/vfio/platform.c           | 25 ++++++++--------
  hw/vfio/spapr.c              |  4 +--
  qom/object.c                 |  5 ++++
  hw/vfio/meson.build          | 35 +++++++++++++---------
  23 files changed, 152 insertions(+), 106 deletions(-)
Quoted 2 lines

create mode 100644 hw/vfio/igd-stubs.c

Patches 1-9 still look ok and could be merged through the vfio tree if maintainers ack patch 6 and 8.

The rest, depending on type_is_registered(), would be nice to have, but since there are conflicts and soft freeze is scheduled for tomorrow, we would probably have to wait QEMU 10.1.

Thanks,

C.

#52 lore raw
Quoted 64 lines · Cédric Le Goater
Quoted 59 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.

Since v1:
- Added R-b tags
- Introduce type_is_registered()
- Split builtin check VS meson changes (rth)
- Consider IGD

Philippe Mathieu-Daudé (21):
   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
   qom: Introduce type_is_registered()
   hw/vfio/igd: Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin() hw/vfio/igd: Compile once
   system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/pci: Compile once
   hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/s390x: Compile AP and CCW once
   hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using iommufd_builtin
   hw/vfio/platform: Compile once

  docs/devel/vfio-iommufd.rst  |  2 +-
  hw/vfio/pci-quirks.h         |  8 +++++ include/exec/ram_addr.h      |  3 --
  include/qom/object.h         |  8 +++++ include/system/hostmem.h     |  3 ++ include/system/iommufd.h     |  6 ++++ include/system/kvm.h         |  8 ++--- target/s390x/kvm/kvm_s390x.h |  2 +-
  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/igd-stubs.c          | 20 +++++++++++++ hw/vfio/igd.c                |  4 +--
  hw/vfio/iommufd.c            |  1 -
  hw/vfio/migration.c          |  1 -
  hw/vfio/pci-quirks.c         |  9 +++---
  hw/vfio/pci.c                | 57 +++++++++++++++++------------------- hw/vfio/platform.c           | 25 ++++++++-------- hw/vfio/spapr.c              |  4 +--
  qom/object.c                 |  5 ++++
  hw/vfio/meson.build          | 35 +++++++++++++---------

Quoted 3 lines
  23 files changed, 152 insertions(+), 106 deletions(-)

  create mode 100644 hw/vfio/igd-stubs.c

Quoted 6 lines

Patches 1-9 still look ok and could be merged through the vfio tree if maintainers ack patch 6 and 8.

The rest, depending on type_is_registered(), would be nice to have, but since there are conflicts and soft freeze is scheduled for tomorrow, we would probably have to wait QEMU 10.1.

No particular rush for the 10.0 release.

#53 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 60 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.

Since v1:
- Added R-b tags
- Introduce type_is_registered()
- Split builtin check VS meson changes (rth)
- Consider IGD

Philippe Mathieu-Daudé (21):
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
qom: Introduce type_is_registered()
hw/vfio/igd: Define TYPE_VFIO_PCI_IGD_LPC_BRIDGE hw/vfio/igd: Check CONFIG_VFIO_IGD at runtime using vfio_igd_builtin() hw/vfio/igd: Compile once
system/iommufd: Introduce iommufd_builtin() helper hw/vfio/pci: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/pci: Compile once
hw/vfio/ap: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/ccw: Check CONFIG_IOMMUFD at runtime using iommufd_builtin() hw/vfio/s390x: Compile AP and CCW once
hw/vfio/platform: Check CONFIG_IOMMUFD at runtime using
iommufd_builtin
hw/vfio/platform: Compile once

  docs/devel/vfio-iommufd.rst  |  2 +-
  hw/vfio/pci-quirks.h         |  8 +++++
  include/exec/ram_addr.h      |  3 --
  include/qom/object.h         |  8 +++++
  include/system/hostmem.h     |  3 ++
  include/system/iommufd.h     |  6 ++++
  include/system/kvm.h         |  8 ++---
  target/s390x/kvm/kvm_s390x.h |  2 +-
  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/igd-stubs.c          | 20 +++++++++++++
  hw/vfio/igd.c                |  4 +--
  hw/vfio/iommufd.c            |  1 -
  hw/vfio/migration.c          |  1 -
  hw/vfio/pci-quirks.c         |  9 +++---
  hw/vfio/pci.c                | 57 +++++++++++++++++-------------------
  hw/vfio/platform.c           | 25 ++++++++--------
  hw/vfio/spapr.c              |  4 +--
  qom/object.c                 |  5 ++++
  hw/vfio/meson.build          | 35 +++++++++++++---------
  23 files changed, 152 insertions(+), 106 deletions(-)
Quoted 2 lines

create mode 100644 hw/vfio/igd-stubs.c

Applied 1-9 to vfio-next.

Thanks,

C.