qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/22] vfio: improve use of QOM and coding guidelines
@ 2025-07-15  9:25 Mark Cave-Ayland
  2025-07-15  9:25 ` [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration Mark Cave-Ayland
                   ` (22 more replies)
  0 siblings, 23 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

This series attempts to improve use of QOM within the vfio subsystem which
appears to have been added at a later date. It's mostly mechanical changes
that do the following:

  1) Format the QOM structs per our coding guidelines

  2) Ensure the parent object is called parent_obj

  3) Use QOM casts to access the parent object, instead of accessing
     the parent struct member directly

The benefits of this are that the QOM casts included type checking to help
ensure the right object is being passed into the cast, and it also becomes
much easier to infer the class hierarchy from reading the code.

Having produced this series, it feels to me that the readability could be
further improved by renaming the structs as follows:

   VFIOContainer     -> VFIOLegacyContainer
   VFIOContainerBase -> VFIOContainer

However I have left this for now given how close that we are to freeze.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Mark Cave-Ayland (22):
  vfio/vfio-container-base.h: update VFIOContainerBase declaration
  vfio/vfio-container.h: update VFIOContainer declaration
  hw/vfio/cpr-legacy.c: use QOM casts where appropriate
  hw/vfio/container.c: use QOM casts where appropriate
  ppc/spapr_pci_vfio.c: use QOM casts where appropriate
  vfio/spapr.c: use QOM casts where appropriate
  vfio/vfio-container.h: rename VFIOContainer bcontainer field to
    parent_obj
  vfio-user/container.h: update VFIOUserContainer declaration
  vfio/container.c: use QOM casts where appropriate
  vfio-user/container.h: rename VFIOUserContainer bcontainer field to
    parent_obj
  vfio-user/pci.c: update VFIOUserPCIDevice declaration
  vfio-user/pci.c: use QOM casts where appropriate
  vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj
  vfio/pci.h: update VFIOPCIDevice declaration
  vfio/pci.h: use QOM casts where appropriate
  vfio/pci.c: use QOM casts where appropriate
  vfio/pci-quirks.c: use QOM casts where appropriate
  vfio/cpr.c: use QOM casts where appropriate
  vfio/igd.c: use QOM casts where appropriate
  vfio-user/pci.c: use QOM casts where appropriate
  s390x/s390-pci-vfio.c: use QOM casts where appropriate
  vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj

 hw/ppc/spapr_pci_vfio.c               |   2 +-
 hw/s390x/s390-pci-vfio.c              |  14 +-
 hw/vfio-user/container.c              |  26 ++--
 hw/vfio-user/container.h              |   7 +-
 hw/vfio-user/pci.c                    |  16 +-
 hw/vfio/container.c                   |  31 ++--
 hw/vfio/cpr-legacy.c                  |  14 +-
 hw/vfio/cpr.c                         |  10 +-
 hw/vfio/igd.c                         |  38 ++---
 hw/vfio/pci-quirks.c                  |  48 +++---
 hw/vfio/pci.c                         | 206 +++++++++++++++-----------
 hw/vfio/pci.h                         |   5 +-
 hw/vfio/spapr.c                       |  16 +-
 include/hw/vfio/vfio-container-base.h |  13 +-
 include/hw/vfio/vfio-container.h      |   7 +-
 15 files changed, 249 insertions(+), 204 deletions(-)

-- 
2.43.0



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

* [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-08-11 11:45   ` Cédric Le Goater
  2025-08-11 11:56   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration Mark Cave-Ayland
                   ` (21 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Update the VFIOContainerBase declaration to match our current coding
guidelines: remove the explicit typedef (this is already handled by the
OBJECT_DECLARE_TYPE() macro), add a blank line after the parent object,
rename parent to parent_obj, and move the macro declaration next to the
VFIOContainerBase struct declaration.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 include/hw/vfio/vfio-container-base.h | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
index bded6e993f..acbd48a18a 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -33,8 +33,9 @@ typedef struct VFIOAddressSpace {
 /*
  * This is the base object for vfio container backends
  */
-typedef struct VFIOContainerBase {
-    Object parent;
+struct VFIOContainerBase {
+    Object parent_obj;
+
     VFIOAddressSpace *space;
     MemoryListener listener;
     Error *error;
@@ -51,7 +52,10 @@ typedef struct VFIOContainerBase {
     QLIST_HEAD(, VFIODevice) device_list;
     GList *iova_ranges;
     NotifierWithReturn cpr_reboot_notifier;
-} VFIOContainerBase;
+};
+
+#define TYPE_VFIO_IOMMU "vfio-iommu"
+OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass, VFIO_IOMMU)
 
 typedef struct VFIOGuestIOMMU {
     VFIOContainerBase *bcontainer;
@@ -105,14 +109,11 @@ vfio_container_get_page_size_mask(const VFIOContainerBase *bcontainer)
     return bcontainer->pgsizes;
 }
 
-#define TYPE_VFIO_IOMMU "vfio-iommu"
 #define TYPE_VFIO_IOMMU_LEGACY TYPE_VFIO_IOMMU "-legacy"
 #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
 #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
 #define TYPE_VFIO_IOMMU_USER TYPE_VFIO_IOMMU "-user"
 
-OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass, VFIO_IOMMU)
-
 struct VFIOIOMMUClass {
     ObjectClass parent_class;
 
-- 
2.43.0



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

* [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
  2025-07-15  9:25 ` [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:39   ` Philippe Mathieu-Daudé
  2025-08-11 11:45   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate Mark Cave-Ayland
                   ` (20 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Update the VFIOContainer declaration so that it is closer to our coding
guidelines: emove the explicit typedef (this is already handled by the
OBJECT_DECLARE_TYPE() macro) and add a blank line after the parent object.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 include/hw/vfio/vfio-container.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-container.h
index 21e5807e48..50c91788d5 100644
--- a/include/hw/vfio/vfio-container.h
+++ b/include/hw/vfio/vfio-container.h
@@ -25,13 +25,14 @@ typedef struct VFIOGroup {
     bool ram_block_discard_allowed;
 } VFIOGroup;
 
-typedef struct VFIOContainer {
+struct VFIOContainer {
     VFIOContainerBase bcontainer;
+
     int fd; /* /dev/vfio/vfio, empowered by the attached groups */
     unsigned iommu_type;
     QLIST_HEAD(, VFIOGroup) group_list;
     VFIOContainerCPR cpr;
-} VFIOContainer;
+};
 
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
 
-- 
2.43.0



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

* [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
  2025-07-15  9:25 ` [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration Mark Cave-Ayland
  2025-07-15  9:25 ` [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15 12:36   ` Steven Sistare
  2025-08-11 11:45   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 04/22] hw/vfio/container.c: " Mark Cave-Ayland
                   ` (19 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
of accessing bcontainer directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/cpr-legacy.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c
index 553b203e9b..8f437194fa 100644
--- a/hw/vfio/cpr-legacy.c
+++ b/hw/vfio/cpr-legacy.c
@@ -41,8 +41,8 @@ static int vfio_legacy_cpr_dma_map(const VFIOContainerBase *bcontainer,
                                    hwaddr iova, ram_addr_t size, void *vaddr,
                                    bool readonly, MemoryRegion *mr)
 {
-    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                                  bcontainer);
+    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
+
     struct vfio_iommu_type1_dma_map map = {
         .argsz = sizeof(map),
         .flags = VFIO_DMA_MAP_FLAG_VADDR,
@@ -65,7 +65,7 @@ static void vfio_region_remap(MemoryListener *listener,
 {
     VFIOContainer *container = container_of(listener, VFIOContainer,
                                             cpr.remap_listener);
-    vfio_container_region_add(&container->bcontainer, section, true);
+    vfio_container_region_add(VFIO_IOMMU(container), section, true);
 }
 
 static bool vfio_cpr_supported(VFIOContainer *container, Error **errp)
@@ -98,7 +98,7 @@ static int vfio_container_pre_save(void *opaque)
 static int vfio_container_post_load(void *opaque, int version_id)
 {
     VFIOContainer *container = opaque;
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
     dma_map_fn saved_dma_map = vioc->dma_map;
     Error *local_err = NULL;
@@ -135,7 +135,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *notifier,
 {
     VFIOContainer *container =
         container_of(notifier, VFIOContainer, cpr.transfer_notifier);
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
 
     if (e->type != MIG_EVENT_PRECOPY_FAILED) {
         return 0;
@@ -167,7 +167,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *notifier,
 
 bool vfio_legacy_cpr_register_container(VFIOContainer *container, Error **errp)
 {
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     Error **cpr_blocker = &container->cpr.blocker;
 
     migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier,
@@ -191,7 +191,7 @@ bool vfio_legacy_cpr_register_container(VFIOContainer *container, Error **errp)
 
 void vfio_legacy_cpr_unregister_container(VFIOContainer *container)
 {
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
 
     migration_remove_notifier(&bcontainer->cpr_reboot_notifier);
     migrate_del_blocker(&container->cpr.blocker);
-- 
2.43.0



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

* [PATCH 04/22] hw/vfio/container.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (2 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-08-11 12:19   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 05/22] ppc/spapr_pci_vfio.c: " Mark Cave-Ayland
                   ` (18 subsequent siblings)
  22 siblings, 1 reply; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
of accessing bcontainer directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/container.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index 3e13feaa74..f4337741b3 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -71,7 +71,7 @@ static int vfio_dma_unmap_bitmap(const VFIOContainer *container,
                                  hwaddr iova, ram_addr_t size,
                                  IOMMUTLBEntry *iotlb)
 {
-    const VFIOContainerBase *bcontainer = &container->bcontainer;
+    const VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     struct vfio_iommu_type1_dma_unmap *unmap;
     struct vfio_bitmap *bitmap;
     VFIOBitmap vbmap;
@@ -124,8 +124,7 @@ static int vfio_legacy_dma_unmap_one(const VFIOContainerBase *bcontainer,
                                      hwaddr iova, ram_addr_t size,
                                      IOMMUTLBEntry *iotlb)
 {
-    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                                  bcontainer);
+    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     struct vfio_iommu_type1_dma_unmap unmap = {
         .argsz = sizeof(unmap),
         .flags = 0,
@@ -213,8 +212,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                                ram_addr_t size, void *vaddr, bool readonly,
                                MemoryRegion *mr)
 {
-    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                                  bcontainer);
+    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     struct vfio_iommu_type1_dma_map map = {
         .argsz = sizeof(map),
         .flags = VFIO_DMA_MAP_FLAG_READ,
@@ -246,8 +244,7 @@ static int
 vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer,
                                     bool start, Error **errp)
 {
-    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                                  bcontainer);
+    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     int ret;
     struct vfio_iommu_type1_dirty_bitmap dirty = {
         .argsz = sizeof(dirty),
@@ -272,8 +269,7 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer,
 static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
                       VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
 {
-    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                                  bcontainer);
+    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     struct vfio_iommu_type1_dirty_bitmap *dbitmap;
     struct vfio_iommu_type1_dirty_bitmap_get *range;
     int ret;
@@ -495,7 +491,7 @@ static void vfio_get_iommu_info_migration(VFIOContainer *container,
 {
     struct vfio_info_cap_header *hdr;
     struct vfio_iommu_type1_info_cap_migration *cap_mig;
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
 
     hdr = vfio_get_iommu_info_cap(info, VFIO_IOMMU_TYPE1_INFO_CAP_MIGRATION);
     if (!hdr) {
@@ -518,8 +514,7 @@ static void vfio_get_iommu_info_migration(VFIOContainer *container,
 
 static bool vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp)
 {
-    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                            bcontainer);
+    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     g_autofree struct vfio_iommu_type1_info *info = NULL;
     int ret;
 
@@ -634,7 +629,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
 
     if (!cpr_is_incoming()) {
         QLIST_FOREACH(bcontainer, &space->containers, next) {
-            container = container_of(bcontainer, VFIOContainer, bcontainer);
+            container = VFIO_IOMMU_LEGACY(bcontainer);
             if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {
                 return vfio_container_group_add(container, group, errp);
             }
@@ -652,7 +647,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
          * create the container struct and group list.
          */
         QLIST_FOREACH(bcontainer, &space->containers, next) {
-            container = container_of(bcontainer, VFIOContainer, bcontainer);
+            container = VFIO_IOMMU_LEGACY(bcontainer);
 
             if (vfio_cpr_container_match(container, group, fd)) {
                 return vfio_container_group_add(container, group, errp);
@@ -672,7 +667,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
         goto fail;
     }
     new_container = true;
-    bcontainer = &container->bcontainer;
+    bcontainer = VFIO_IOMMU(container);
 
     if (!vfio_legacy_cpr_register_container(container, errp)) {
         goto fail;
@@ -735,7 +730,7 @@ fail:
 static void vfio_container_disconnect(VFIOGroup *group)
 {
     VFIOContainer *container = group->container;
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
 
     QLIST_REMOVE(group, container_next);
@@ -781,7 +776,7 @@ static VFIOGroup *vfio_group_get(int groupid, AddressSpace *as, Error **errp)
     QLIST_FOREACH(group, &vfio_group_list, next) {
         if (group->groupid == groupid) {
             /* Found it.  Now is it already in the right context? */
-            if (group->container->bcontainer.space->as == as) {
+            if (VFIO_IOMMU(group->container)->space->as == as) {
                 return group;
             } else {
                 error_setg(errp, "group %d used in multiple address spaces",
@@ -895,7 +890,7 @@ static bool vfio_device_get(VFIOGroup *group, const char *name,
         }
     }
 
-    vfio_device_prepare(vbasedev, &group->container->bcontainer, info);
+    vfio_device_prepare(vbasedev, VFIO_IOMMU(group->container), info);
 
     vbasedev->fd = fd;
     vbasedev->group = group;
-- 
2.43.0



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

* [PATCH 05/22] ppc/spapr_pci_vfio.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (3 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 04/22] hw/vfio/container.c: " Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-16  7:58   ` Harsh Prateek Bora
  2025-08-11 12:19   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 06/22] vfio/spapr.c: " Mark Cave-Ayland
                   ` (17 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use a QOM cast to convert to VFIOContainer instead of accessing bcontainer
directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/ppc/spapr_pci_vfio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
index e318d0d912..7e1c71ef59 100644
--- a/hw/ppc/spapr_pci_vfio.c
+++ b/hw/ppc/spapr_pci_vfio.c
@@ -106,7 +106,7 @@ static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
 
 out:
     vfio_address_space_put(space);
-    return container_of(bcontainer, VFIOContainer, bcontainer);
+    return VFIO_IOMMU_LEGACY(bcontainer);
 }
 
 static bool vfio_eeh_as_ok(AddressSpace *as)
-- 
2.43.0



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

* [PATCH 06/22] vfio/spapr.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (4 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 05/22] ppc/spapr_pci_vfio.c: " Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-16  8:01   ` Harsh Prateek Bora
  2025-08-11 12:20   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj Mark Cave-Ayland
                   ` (16 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
of accessing bcontainer directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/spapr.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 564b70ef97..c41e4588d6 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -62,7 +62,7 @@ static void vfio_prereg_listener_region_add(MemoryListener *listener,
     VFIOSpaprContainer *scontainer = container_of(listener, VFIOSpaprContainer,
                                                   prereg_listener);
     VFIOContainer *container = &scontainer->container;
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     const hwaddr gpa = section->offset_within_address_space;
     hwaddr end;
     int ret;
@@ -244,7 +244,7 @@ static bool vfio_spapr_create_window(VFIOContainer *container,
                                     hwaddr *pgsize, Error **errp)
 {
     int ret = 0;
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
                                                   container);
     IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
@@ -352,8 +352,7 @@ vfio_spapr_container_add_section_window(VFIOContainerBase *bcontainer,
                                         MemoryRegionSection *section,
                                         Error **errp)
 {
-    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                            bcontainer);
+    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
                                                   container);
     VFIOHostDMAWindow *hostwin;
@@ -443,8 +442,7 @@ static void
 vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
                                         MemoryRegionSection *section)
 {
-    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                            bcontainer);
+    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
                                                   container);
 
@@ -465,8 +463,7 @@ vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
 
 static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
 {
-    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                            bcontainer);
+    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
                                                   container);
     VFIOHostDMAWindow *hostwin, *next;
@@ -484,8 +481,7 @@ static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
 static bool vfio_spapr_container_setup(VFIOContainerBase *bcontainer,
                                        Error **errp)
 {
-    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
-                                            bcontainer);
+    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
     VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
                                                   container);
     struct vfio_iommu_spapr_tce_info info;
-- 
2.43.0



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

* [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (5 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 06/22] vfio/spapr.c: " Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:39   ` Philippe Mathieu-Daudé
  2025-08-11 12:23   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration Mark Cave-Ayland
                   ` (15 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Now that nothing accesses the bcontainer field directly, rename bcontainer to
parent_obj as per our current coding guidelines.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 include/hw/vfio/vfio-container.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-container.h
index 50c91788d5..240f566993 100644
--- a/include/hw/vfio/vfio-container.h
+++ b/include/hw/vfio/vfio-container.h
@@ -26,7 +26,7 @@ typedef struct VFIOGroup {
 } VFIOGroup;
 
 struct VFIOContainer {
-    VFIOContainerBase bcontainer;
+    VFIOContainerBase parent_obj;
 
     int fd; /* /dev/vfio/vfio, empowered by the attached groups */
     unsigned iommu_type;
-- 
2.43.0



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

* [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (6 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:39   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2025-07-15  9:25 ` [PATCH 09/22] vfio/container.c: use QOM casts where appropriate Mark Cave-Ayland
                   ` (14 subsequent siblings)
  22 siblings, 3 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Update the VFIOUserContainer declaration so that it is closer to our coding
guidelines: remove the explicit typedef (this is already handled by the
OBJECT_DECLARE_TYPE() macro) and add a blank line after the parent object.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/container.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/vfio-user/container.h b/hw/vfio-user/container.h
index 2bb1fa1343..d5d2275af7 100644
--- a/hw/vfio-user/container.h
+++ b/hw/vfio-user/container.h
@@ -13,10 +13,11 @@
 #include "hw/vfio-user/proxy.h"
 
 /* MMU container sub-class for vfio-user. */
-typedef struct VFIOUserContainer {
+struct VFIOUserContainer {
     VFIOContainerBase bcontainer;
+
     VFIOUserProxy *proxy;
-} VFIOUserContainer;
+};
 
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserContainer, VFIO_IOMMU_USER);
 
-- 
2.43.0



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

* [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (7 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15 14:13   ` John Levon
  2025-08-11 12:23   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj Mark Cave-Ayland
                   ` (13 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
of accessing bcontainer directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/container.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
index d318e6a339..025db93ff3 100644
--- a/hw/vfio-user/container.c
+++ b/hw/vfio-user/container.c
@@ -24,16 +24,14 @@
  */
 static void vfio_user_listener_begin(VFIOContainerBase *bcontainer)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                                 bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
 
     container->proxy->async_ops = true;
 }
 
 static void vfio_user_listener_commit(VFIOContainerBase *bcontainer)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                            bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
 
     /* wait here for any async requests sent during the transaction */
     container->proxy->async_ops = false;
@@ -44,8 +42,8 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
                                hwaddr iova, ram_addr_t size,
                                IOMMUTLBEntry *iotlb, bool unmap_all)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                            bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
+
     Error *local_err = NULL;
     int ret = 0;
 
@@ -88,8 +86,8 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                              ram_addr_t size, void *vaddr, bool readonly,
                              MemoryRegion *mrp)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                                bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
+
     int fd = memory_region_get_fd(mrp);
     Error *local_err = NULL;
     int ret;
@@ -177,8 +175,7 @@ static int vfio_user_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
 
 static bool vfio_user_setup(VFIOContainerBase *bcontainer, Error **errp)
 {
-    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
-                                                bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
 
     assert(container->proxy->dma_pgsizes != 0);
     bcontainer->pgsizes = container->proxy->dma_pgsizes;
@@ -222,7 +219,7 @@ vfio_user_container_connect(AddressSpace *as, VFIODevice *vbasedev,
         goto put_space_exit;
     }
 
-    bcontainer = &container->bcontainer;
+    bcontainer = VFIO_IOMMU(container);
 
     ret = ram_block_uncoordinated_discard_disable(true);
     if (ret) {
@@ -267,7 +264,7 @@ put_space_exit:
 
 static void vfio_user_container_disconnect(VFIOUserContainer *container)
 {
-    VFIOContainerBase *bcontainer = &container->bcontainer;
+    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
     VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
     VFIOAddressSpace *space = bcontainer->space;
 
@@ -295,7 +292,7 @@ static bool vfio_user_device_get(VFIOUserContainer *container,
 
     vbasedev->fd = -1;
 
-    vfio_device_prepare(vbasedev, &container->bcontainer, &info);
+    vfio_device_prepare(vbasedev, VFIO_IOMMU(container), &info);
 
     return true;
 }
@@ -319,8 +316,7 @@ static bool vfio_user_device_attach(const char *name, VFIODevice *vbasedev,
 
 static void vfio_user_device_detach(VFIODevice *vbasedev)
 {
-    VFIOUserContainer *container = container_of(vbasedev->bcontainer,
-                                                VFIOUserContainer, bcontainer);
+    VFIOUserContainer *container = VFIO_IOMMU_USER(vbasedev->bcontainer);
 
     vfio_device_unprepare(vbasedev);
 
-- 
2.43.0



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

* [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (8 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 09/22] vfio/container.c: use QOM casts where appropriate Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:41   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2025-07-15  9:25 ` [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration Mark Cave-Ayland
                   ` (12 subsequent siblings)
  22 siblings, 3 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Now that nothing accesses the bcontainer field directly, rename bcontainer to
parent_obj as per our current coding guidelines.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/container.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/vfio-user/container.h b/hw/vfio-user/container.h
index d5d2275af7..96aa6785d9 100644
--- a/hw/vfio-user/container.h
+++ b/hw/vfio-user/container.h
@@ -14,7 +14,7 @@
 
 /* MMU container sub-class for vfio-user. */
 struct VFIOUserContainer {
-    VFIOContainerBase bcontainer;
+    VFIOContainerBase parent_obj;
 
     VFIOUserProxy *proxy;
 };
-- 
2.43.0



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

* [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (9 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:42   ` Philippe Mathieu-Daudé
                     ` (3 more replies)
  2025-07-15  9:25 ` [PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate Mark Cave-Ayland
                   ` (11 subsequent siblings)
  22 siblings, 4 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Update the VFIOUserPCIDevice declaration so that it is closer to our coding
guidelines: add a blank line after the parent object.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
index be71c77729..da6fe51809 100644
--- a/hw/vfio-user/pci.c
+++ b/hw/vfio-user/pci.c
@@ -21,6 +21,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
 
 struct VFIOUserPCIDevice {
     VFIOPCIDevice device;
+
     SocketAddress *socket;
     bool send_queued;   /* all sends are queued */
     uint32_t wait_time; /* timeout for message replies */
-- 
2.43.0



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

* [PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (10 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15 14:15   ` John Levon
  2025-07-15  9:25 ` [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj Mark Cave-Ayland
                   ` (10 subsequent siblings)
  22 siblings, 1 reply; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOUserPCIDevice and VFIOPCIDevice instead
of accessing device directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/pci.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
index da6fe51809..e23a941605 100644
--- a/hw/vfio-user/pci.c
+++ b/hw/vfio-user/pci.c
@@ -214,8 +214,9 @@ static void vfio_user_compute_needs_reset(VFIODevice *vbasedev)
 
 static Object *vfio_user_pci_get_object(VFIODevice *vbasedev)
 {
-    VFIOUserPCIDevice *vdev = container_of(vbasedev, VFIOUserPCIDevice,
-                                           device.vbasedev);
+    VFIOUserPCIDevice *vdev = VFIO_USER_PCI(container_of(vbasedev,
+                                                         VFIOPCIDevice,
+                                                         vbasedev));
 
     return OBJECT(vdev);
 }
@@ -418,7 +419,7 @@ static void vfio_user_pci_set_socket(Object *obj, Visitor *v, const char *name,
     VFIOUserPCIDevice *udev = VFIO_USER_PCI(obj);
     bool success;
 
-    if (udev->device.vbasedev.proxy) {
+    if (VFIO_PCI_BASE(udev)->vbasedev.proxy) {
         error_setg(errp, "Proxy is connected");
         return;
     }
-- 
2.43.0



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

* [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (11 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:42   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2025-07-15  9:25 ` [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration Mark Cave-Ayland
                   ` (9 subsequent siblings)
  22 siblings, 3 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Now that nothing accesses the device field directly, rename device to
parent_obj as per our current coding guidelines.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
index e23a941605..9380766548 100644
--- a/hw/vfio-user/pci.c
+++ b/hw/vfio-user/pci.c
@@ -20,7 +20,7 @@
 OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
 
 struct VFIOUserPCIDevice {
-    VFIOPCIDevice device;
+    VFIOPCIDevice parent_obj;
 
     SocketAddress *socket;
     bool send_queued;   /* all sends are queued */
-- 
2.43.0



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

* [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (12 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:44   ` Philippe Mathieu-Daudé
  2025-08-11 12:25   ` Cédric Le Goater
  2025-07-15  9:25 ` [PATCH 15/22] vfio/pci.h: use QOM casts where appropriate Mark Cave-Ayland
                   ` (8 subsequent siblings)
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Update the VFIOPCIDevice declaration so that it is closer to our coding
guidelines: add a blank line after the parent object.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/pci.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 495fae737d..16f092a0c6 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -132,6 +132,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
 
 struct VFIOPCIDevice {
     PCIDevice pdev;
+
     VFIODevice vbasedev;
     VFIOINTx intx;
     unsigned int config_size;
-- 
2.43.0



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

* [PATCH 15/22] vfio/pci.h: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (13 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:25 ` [PATCH 16/22] vfio/pci.c: " Mark Cave-Ayland
                   ` (7 subsequent siblings)
  22 siblings, 0 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
accessing pdev directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/pci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index 16f092a0c6..c0c3d68742 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -206,7 +206,7 @@ static inline bool vfio_pci_is(VFIOPCIDevice *vdev, uint32_t vendor, uint32_t de
 
 static inline bool vfio_is_vga(VFIOPCIDevice *vdev)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint16_t class = pci_get_word(pdev->config + PCI_CLASS_DEVICE);
 
     return class == PCI_CLASS_DISPLAY_VGA;
-- 
2.43.0



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

* [PATCH 16/22] vfio/pci.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (14 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 15/22] vfio/pci.h: use QOM casts where appropriate Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15 13:38   ` BALATON Zoltan
  2025-07-15  9:25 ` [PATCH 17/22] vfio/pci-quirks.c: " Mark Cave-Ayland
                   ` (6 subsequent siblings)
  22 siblings, 1 reply; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
accessing pdev directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/pci.c | 202 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 120 insertions(+), 82 deletions(-)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 1093b28df7..fb9eb58da5 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -119,6 +119,7 @@ static void vfio_intx_mmap_enable(void *opaque)
 static void vfio_intx_interrupt(void *opaque)
 {
     VFIOPCIDevice *vdev = opaque;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     if (!event_notifier_test_and_clear(&vdev->intx.interrupt)) {
         return;
@@ -127,7 +128,7 @@ static void vfio_intx_interrupt(void *opaque)
     trace_vfio_intx_interrupt(vdev->vbasedev.name, 'A' + vdev->intx.pin);
 
     vdev->intx.pending = true;
-    pci_irq_assert(&vdev->pdev);
+    pci_irq_assert(pdev);
     vfio_mmap_set_enabled(vdev, false);
     if (vdev->intx.mmap_timeout) {
         timer_mod(vdev->intx.mmap_timer,
@@ -138,6 +139,7 @@ static void vfio_intx_interrupt(void *opaque)
 void vfio_pci_intx_eoi(VFIODevice *vbasedev)
 {
     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     if (!vdev->intx.pending) {
         return;
@@ -146,13 +148,14 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev)
     trace_vfio_pci_intx_eoi(vbasedev->name);
 
     vdev->intx.pending = false;
-    pci_irq_deassert(&vdev->pdev);
+    pci_irq_deassert(pdev);
     vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
 }
 
 static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
 {
 #ifdef CONFIG_KVM
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
 
     if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
@@ -165,7 +168,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
     qemu_set_fd_handler(irq_fd, NULL, NULL, vdev);
     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
     vdev->intx.pending = false;
-    pci_irq_deassert(&vdev->pdev);
+    pci_irq_deassert(pdev);
 
     /* Get an eventfd for resample/unmask */
     if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 0, errp)) {
@@ -243,6 +246,8 @@ static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
 static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
 {
 #ifdef CONFIG_KVM
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+
     if (!vdev->intx.kvm_accel) {
         return;
     }
@@ -253,7 +258,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
      */
     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
     vdev->intx.pending = false;
-    pci_irq_deassert(&vdev->pdev);
+    pci_irq_deassert(pdev);
 
     /* Tell KVM to stop listening for an INTx irqfd */
     if (kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.interrupt,
@@ -309,7 +314,7 @@ static void vfio_intx_routing_notifier(PCIDevice *pdev)
         return;
     }
 
-    route = pci_device_route_intx_to_irq(&vdev->pdev, vdev->intx.pin);
+    route = pci_device_route_intx_to_irq(pdev, vdev->intx.pin);
 
     if (pci_intx_route_changed(&vdev->intx.route, &route)) {
         vfio_intx_update(vdev, &route);
@@ -326,7 +331,8 @@ static void vfio_irqchip_change(Notifier *notify, void *data)
 
 static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
 {
-    uint8_t pin = vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+    uint8_t pin = vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1);
     Error *err = NULL;
     int32_t fd;
 
@@ -344,7 +350,7 @@ 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);
+    pci_config_set_interrupt_pin(pdev->config, pin);
 
 #ifdef CONFIG_KVM
     /*
@@ -352,7 +358,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
      * where we won't actually use the result anyway.
      */
     if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) {
-        vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
+        vdev->intx.route = pci_device_route_intx_to_irq(pdev,
                                                         vdev->intx.pin);
     }
 #endif
@@ -392,13 +398,14 @@ skip_signaling:
 
 static void vfio_intx_disable(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int fd;
 
     timer_del(vdev->intx.mmap_timer);
     vfio_intx_disable_kvm(vdev);
     vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
     vdev->intx.pending = false;
-    pci_irq_deassert(&vdev->pdev);
+    pci_irq_deassert(pdev);
     vfio_mmap_set_enabled(vdev, true);
 
     fd = event_notifier_get_fd(&vdev->intx.interrupt);
@@ -422,6 +429,7 @@ static void vfio_msi_interrupt(void *opaque)
 {
     VFIOMSIVector *vector = opaque;
     VFIOPCIDevice *vdev = vector->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     MSIMessage (*get_msg)(PCIDevice *dev, unsigned vector);
     void (*notify)(PCIDevice *dev, unsigned vector);
     MSIMessage msg;
@@ -436,9 +444,9 @@ static void vfio_msi_interrupt(void *opaque)
         notify = msix_notify;
 
         /* A masked vector firing needs to use the PBA, enable it */
-        if (msix_is_masked(&vdev->pdev, nr)) {
+        if (msix_is_masked(pdev, nr)) {
             set_bit(nr, vdev->msix->pending);
-            memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, true);
+            memory_region_set_enabled(&pdev->msix_pba_mmio, true);
             trace_vfio_msix_pba_enable(vdev->vbasedev.name);
         }
     } else if (vdev->interrupt == VFIO_INT_MSI) {
@@ -448,9 +456,9 @@ static void vfio_msi_interrupt(void *opaque)
         abort();
     }
 
-    msg = get_msg(&vdev->pdev, nr);
+    msg = get_msg(pdev, nr);
     trace_vfio_msi_interrupt(vdev->vbasedev.name, nr, msg.address, msg.data);
-    notify(&vdev->pdev, nr);
+    notify(pdev, nr);
 }
 
 void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr)
@@ -488,6 +496,7 @@ static int vfio_enable_msix_no_vec(VFIOPCIDevice *vdev)
 
 static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     struct vfio_irq_set *irq_set;
     int ret = 0, i, argsz;
     int32_t *fds;
@@ -530,7 +539,7 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
          */
         if (vdev->msi_vectors[i].use) {
             if (vdev->msi_vectors[i].virq < 0 ||
-                (msix && msix_is_masked(&vdev->pdev, i))) {
+                (msix && msix_is_masked(pdev, i))) {
                 fd = event_notifier_get_fd(&vdev->msi_vectors[i].interrupt);
             } else {
                 fd = event_notifier_get_fd(&vdev->msi_vectors[i].kvm_interrupt);
@@ -550,12 +559,14 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
 void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector,
                                int vector_n, bool msix)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+
     if ((msix && vdev->no_kvm_msix) || (!msix && vdev->no_kvm_msi)) {
         return;
     }
 
     vector->virq = kvm_irqchip_add_msi_route(&vfio_route_change,
-                                             vector_n, &vdev->pdev);
+                                             vector_n, pdev);
 }
 
 static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector, int nr)
@@ -624,7 +635,7 @@ static void set_irq_signalling(VFIODevice *vbasedev, VFIOMSIVector *vector,
 void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr)
 {
     VFIOMSIVector *vector = &vdev->msi_vectors[nr];
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     Error *local_err = NULL;
 
     vector->vdev = vdev;
@@ -713,7 +724,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
     clear_bit(nr, vdev->msix->pending);
     if (find_first_bit(vdev->msix->pending,
                        vdev->nr_vectors) == vdev->nr_vectors) {
-        memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
+        memory_region_set_enabled(&pdev->msix_pba_mmio, false);
         trace_vfio_msix_pba_disable(vdev->vbasedev.name);
     }
 
@@ -764,7 +775,9 @@ static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr)
 
 void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev)
 {
-    msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+
+    msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
                               vfio_msix_vector_release, NULL);
 }
 
@@ -791,6 +804,7 @@ void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev)
 
 static void vfio_msix_enable(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int ret;
 
     vfio_disable_interrupts(vdev);
@@ -807,7 +821,7 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
      */
     vfio_pci_prepare_kvm_msi_virq_batch(vdev);
 
-    if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
+    if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
                                   vfio_msix_vector_release, NULL)) {
         error_report("vfio: msix_set_vector_notifiers failed");
     }
@@ -845,11 +859,12 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
 
 static void vfio_msi_enable(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int ret, i;
 
     vfio_disable_interrupts(vdev);
 
-    vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev);
+    vdev->nr_vectors = msi_nr_vectors_allocated(pdev);
 retry:
     /*
      * Setting vector notifiers needs to enable route for each vector.
@@ -942,10 +957,11 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev)
 
 static void vfio_msix_disable(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     Error *err = NULL;
     int i;
 
-    msix_unset_vector_notifiers(&vdev->pdev);
+    msix_unset_vector_notifiers(pdev);
 
     /*
      * MSI-X will only release vectors if MSI-X is still enabled on the
@@ -953,8 +969,8 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
      */
     for (i = 0; i < vdev->nr_vectors; i++) {
         if (vdev->msi_vectors[i].use) {
-            vfio_msix_vector_release(&vdev->pdev, i);
-            msix_vector_unuse(&vdev->pdev, i);
+            vfio_msix_vector_release(pdev, i);
+            msix_vector_unuse(pdev, i);
         }
     }
 
@@ -991,6 +1007,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev)
 
 static void vfio_update_msi(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int i;
 
     for (i = 0; i < vdev->nr_vectors; i++) {
@@ -1001,8 +1018,8 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
             continue;
         }
 
-        msg = msi_get_message(&vdev->pdev, i);
-        vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev);
+        msg = msi_get_message(pdev, i);
+        vfio_update_kvm_msi_virq(vector, msg, pdev);
     }
 }
 
@@ -1164,13 +1181,14 @@ static const MemoryRegionOps vfio_rom_ops = {
 
 static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIODevice *vbasedev = &vdev->vbasedev;
     uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);
     char *name;
 
-    if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
+    if (pdev->romfile || !pdev->rom_bar) {
         /* Since pci handles romfile, just print a message and return */
-        if (vfio_opt_rom_in_denylist(vdev) && vdev->pdev.romfile) {
+        if (vfio_opt_rom_in_denylist(vdev) && pdev->romfile) {
             warn_report("Device at %s is known to cause system instability"
                         " issues during option rom execution",
                         vdev->vbasedev.name);
@@ -1199,7 +1217,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
     }
 
     if (vfio_opt_rom_in_denylist(vdev)) {
-        if (vdev->pdev.rom_bar > 0) {
+        if (pdev->rom_bar > 0) {
             warn_report("Device at %s is known to cause system instability"
                         " issues during option rom execution",
                         vdev->vbasedev.name);
@@ -1218,12 +1236,12 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
 
     name = g_strdup_printf("vfio[%s].rom", vdev->vbasedev.name);
 
-    memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),
+    memory_region_init_io(&pdev->rom, OBJECT(vdev),
                           &vfio_rom_ops, vdev, name, size);
     g_free(name);
 
-    pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,
-                     PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);
+    pci_register_bar(pdev, PCI_ROM_SLOT,
+                     PCI_BASE_ADDRESS_SPACE_MEMORY, &pdev->rom);
 
     vdev->rom_read_failed = false;
 }
@@ -1496,6 +1514,7 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vdev)
 
 static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint16_t ctrl;
     bool msi_64bit, msi_maskbit;
     int ret, entries;
@@ -1516,7 +1535,7 @@ static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
 
     trace_vfio_msi_setup(vdev->vbasedev.name, pos);
 
-    ret = msi_init(&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, &err);
+    ret = msi_init(pdev, pos, entries, msi_64bit, msi_maskbit, &err);
     if (ret < 0) {
         if (ret == -ENOTSUP) {
             return true;
@@ -1709,6 +1728,7 @@ static bool vfio_pci_relocate_msix(VFIOPCIDevice *vdev, Error **errp)
  */
 static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint8_t pos;
     uint16_t ctrl;
     uint32_t table, pba;
@@ -1716,7 +1736,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
     VFIOMSIXInfo *msix;
     int ret;
 
-    pos = pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX);
+    pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
     if (!pos) {
         return true;
     }
@@ -1808,12 +1828,13 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
 
 static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int ret;
     Error *err = NULL;
 
     vdev->msix->pending = g_new0(unsigned long,
                                  BITS_TO_LONGS(vdev->msix->entries));
-    ret = msix_init(&vdev->pdev, vdev->msix->entries,
+    ret = msix_init(pdev, vdev->msix->entries,
                     vdev->bars[vdev->msix->table_bar].mr,
                     vdev->msix->table_bar, vdev->msix->table_offset,
                     vdev->bars[vdev->msix->pba_bar].mr,
@@ -1845,7 +1866,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
      * vector-use notifier is called, which occurs on unmask, we test whether
      * PBA emulation is needed and again disable if not.
      */
-    memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
+    memory_region_set_enabled(&pdev->msix_pba_mmio, false);
 
     /*
      * The emulated machine may provide a paravirt interface for MSIX setup
@@ -1857,7 +1878,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
      */
     if (object_property_get_bool(OBJECT(qdev_get_machine()),
                                  "vfio-no-msix-emulation", NULL)) {
-        memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false);
+        memory_region_set_enabled(&pdev->msix_table_mmio, false);
     }
 
     return true;
@@ -1865,10 +1886,12 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
 
 void vfio_pci_teardown_msi(VFIOPCIDevice *vdev)
 {
-    msi_uninit(&vdev->pdev);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+
+    msi_uninit(pdev);
 
     if (vdev->msix) {
-        msix_uninit(&vdev->pdev,
+        msix_uninit(pdev,
                     vdev->bars[vdev->msix->table_bar].mr,
                     vdev->bars[vdev->msix->pba_bar].mr);
         g_free(vdev->msix->pending);
@@ -1929,6 +1952,7 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev)
 
 static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIOBAR *bar = &vdev->bars[nr];
     char *name;
 
@@ -1950,7 +1974,7 @@ static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
         }
     }
 
-    pci_register_bar(&vdev->pdev, nr, bar->type, bar->mr);
+    pci_register_bar(pdev, nr, bar->type, bar->mr);
 }
 
 static void vfio_bars_register(VFIOPCIDevice *vdev)
@@ -1964,6 +1988,7 @@ static void vfio_bars_register(VFIOPCIDevice *vdev)
 
 void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int i;
 
     for (i = 0; i < PCI_ROM_SLOT; i++) {
@@ -1977,7 +2002,7 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
     }
 
     if (vdev->vga) {
-        pci_unregister_vga(&vdev->pdev);
+        pci_unregister_vga(pdev);
         vfio_vga_quirk_exit(vdev);
     }
 }
@@ -2049,8 +2074,10 @@ static void vfio_set_word_bits(uint8_t *buf, uint16_t val, uint16_t mask)
 static void vfio_add_emulated_word(VFIOPCIDevice *vdev, int pos,
                                    uint16_t val, uint16_t mask)
 {
-    vfio_set_word_bits(vdev->pdev.config + pos, val, mask);
-    vfio_set_word_bits(vdev->pdev.wmask + pos, ~mask, mask);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+
+    vfio_set_word_bits(pdev->config + pos, val, mask);
+    vfio_set_word_bits(pdev->wmask + pos, ~mask, mask);
     vfio_set_word_bits(vdev->emulated_config_bits + pos, mask, mask);
 }
 
@@ -2062,8 +2089,10 @@ static void vfio_set_long_bits(uint8_t *buf, uint32_t val, uint32_t mask)
 static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos,
                                    uint32_t val, uint32_t mask)
 {
-    vfio_set_long_bits(vdev->pdev.config + pos, val, mask);
-    vfio_set_long_bits(vdev->pdev.wmask + pos, ~mask, mask);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+
+    vfio_set_long_bits(pdev->config + pos, val, mask);
+    vfio_set_long_bits(pdev->wmask + pos, ~mask, mask);
     vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask);
 }
 
@@ -2071,7 +2100,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
 {
     struct vfio_device_info_cap_pci_atomic_comp *cap;
     g_autofree struct vfio_device_info *info = NULL;
-    PCIBus *bus = pci_get_bus(&vdev->pdev);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+    PCIBus *bus = pci_get_bus(pdev);
     PCIDevice *parent = bus->parent_dev;
     struct vfio_info_cap_header *hdr;
     uint32_t mask = 0;
@@ -2087,8 +2117,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
     if (pci_bus_is_root(bus) || !parent || !parent->exp.exp_cap ||
         pcie_cap_get_type(parent) != PCI_EXP_TYPE_ROOT_PORT ||
         pcie_cap_get_version(parent) != PCI_EXP_FLAGS_VER2 ||
-        vdev->pdev.devfn ||
-        vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+        pdev->devfn ||
+        pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
         return;
     }
 
@@ -2132,8 +2162,10 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
 
 static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+
     if (vdev->clear_parent_atomics_on_exit) {
-        PCIDevice *parent = pci_get_bus(&vdev->pdev)->parent_dev;
+        PCIDevice *parent = pci_get_bus(pdev)->parent_dev;
         uint8_t *pos = parent->config + parent->exp.exp_cap + PCI_EXP_DEVCAP2;
 
         pci_long_test_and_clear_mask(pos, PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
@@ -2145,10 +2177,11 @@ static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
 static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
                                 Error **errp)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint16_t flags;
     uint8_t type;
 
-    flags = pci_get_word(vdev->pdev.config + pos + PCI_CAP_FLAGS);
+    flags = pci_get_word(pdev->config + pos + PCI_CAP_FLAGS);
     type = (flags & PCI_EXP_FLAGS_TYPE) >> 4;
 
     if (type != PCI_EXP_TYPE_ENDPOINT &&
@@ -2160,8 +2193,8 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
         return false;
     }
 
-    if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) {
-        PCIBus *bus = pci_get_bus(&vdev->pdev);
+    if (!pci_bus_is_express(pci_get_bus(pdev))) {
+        PCIBus *bus = pci_get_bus(pdev);
         PCIDevice *bridge;
 
         /*
@@ -2193,7 +2226,7 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
             return true;
         }
 
-    } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) {
+    } else if (pci_bus_is_root(pci_get_bus(pdev))) {
         /*
          * On a Root Complex bus Endpoints become Root Complex Integrated
          * Endpoints, which changes the type and clears the LNK & LNK2 fields.
@@ -2261,20 +2294,20 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
                                1, PCI_EXP_FLAGS_VERS);
     }
 
-    pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size,
-                             errp);
+    pos = pci_add_capability(pdev, PCI_CAP_ID_EXP, pos, size, errp);
     if (pos < 0) {
         return false;
     }
 
-    vdev->pdev.exp.exp_cap = pos;
+    pdev->exp.exp_cap = pos;
 
     return true;
 }
 
 static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
 {
-    uint32_t cap = pci_get_long(vdev->pdev.config + pos + PCI_EXP_DEVCAP);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+    uint32_t cap = pci_get_long(pdev->config + pos + PCI_EXP_DEVCAP);
 
     if (cap & PCI_EXP_DEVCAP_FLR) {
         trace_vfio_check_pcie_flr(vdev->vbasedev.name);
@@ -2284,7 +2317,8 @@ static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
 
 static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
 {
-    uint16_t csr = pci_get_word(vdev->pdev.config + pos + PCI_PM_CTRL);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+    uint16_t csr = pci_get_word(pdev->config + pos + PCI_PM_CTRL);
 
     if (!(csr & PCI_PM_CTRL_NO_SOFT_RESET)) {
         trace_vfio_check_pm_reset(vdev->vbasedev.name);
@@ -2294,7 +2328,8 @@ static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
 
 static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
 {
-    uint8_t cap = pci_get_byte(vdev->pdev.config + pos + PCI_AF_CAP);
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+    uint8_t cap = pci_get_byte(pdev->config + pos + PCI_AF_CAP);
 
     if ((cap & PCI_AF_CAP_TP) && (cap & PCI_AF_CAP_FLR)) {
         trace_vfio_check_af_flr(vdev->vbasedev.name);
@@ -2305,7 +2340,7 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
 static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
                                          uint8_t size, Error **errp)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     pos = pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp);
     if (pos < 0) {
@@ -2327,7 +2362,7 @@ static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
 static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)
 {
     ERRP_GUARD();
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint8_t cap_id, next, size;
     bool ret;
 
@@ -2413,17 +2448,18 @@ static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)
 
 static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint32_t ctrl;
     int i, nbar;
 
-    ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL);
+    ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL);
     nbar = (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> PCI_REBAR_CTRL_NBAR_SHIFT;
 
     for (i = 0; i < nbar; i++) {
         uint32_t cap;
         int size;
 
-        ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL + (i * 8));
+        ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL + (i * 8));
         size = (ctrl & PCI_REBAR_CTRL_BAR_SIZE) >> PCI_REBAR_CTRL_BAR_SHIFT;
 
         /* The cap register reports sizes 1MB to 128TB, with 4 reserved bits */
@@ -2461,7 +2497,7 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
 
 static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint32_t header;
     uint16_t cap_id, next, size;
     uint8_t cap_ver;
@@ -2555,7 +2591,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
 
 bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) ||
         !pdev->config[PCI_CAPABILITY_LIST]) {
@@ -2572,7 +2608,7 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
 
 void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint16_t cmd;
 
     vfio_disable_interrupts(vdev);
@@ -2789,7 +2825,7 @@ static int vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f, Error **errp)
 static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
 {
     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     pcibus_t old_addr[PCI_NUM_REGIONS - 1];
     int bar, ret;
 
@@ -2837,6 +2873,7 @@ static VFIODeviceOps vfio_pci_ops = {
 
 bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIODevice *vbasedev = &vdev->vbasedev;
     struct vfio_region_info *reg_info = NULL;
     int ret;
@@ -2893,7 +2930,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
                           "vfio-vga-io@0x3c0",
                           QEMU_PCI_VGA_IO_HI_SIZE);
 
-    pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
+    pci_register_vga(pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
                      &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
                      &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
 
@@ -2902,6 +2939,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
 
 bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIODevice *vbasedev = &vdev->vbasedev;
     struct vfio_region_info *reg_info = NULL;
     struct vfio_irq_info irq_info;
@@ -2953,7 +2991,7 @@ bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
 
     vdev->config_size = reg_info->size;
     if (vdev->config_size == PCI_CONFIG_SPACE_SIZE) {
-        vdev->pdev.cap_present &= ~QEMU_PCI_CAP_EXPRESS;
+        pdev->cap_present &= ~QEMU_PCI_CAP_EXPRESS;
     }
     vdev->config_offset = reg_info->offset;
 
@@ -3156,16 +3194,16 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
 
 bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIODevice *vbasedev = &vdev->vbasedev;
     uint32_t config_space_size;
     int ret;
 
-    config_space_size = MIN(pci_config_size(&vdev->pdev), vdev->config_size);
+    config_space_size = MIN(pci_config_size(pdev), vdev->config_size);
 
     /* Get a copy of config space */
     ret = vfio_pci_config_space_read(vdev, 0, config_space_size,
-                                     vdev->pdev.config);
+                                     pdev->config);
     if (ret < (int)config_space_size) {
         ret = ret < 0 ? -ret : EFAULT;
         error_setg_errno(errp, ret, "failed to read device config space");
@@ -3233,10 +3271,10 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
                                               PCI_HEADER_TYPE_MULTI_FUNCTION;
 
     /* Restore or clear multifunction, this is always controlled by QEMU */
-    if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
-        vdev->pdev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
+    if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
+        pdev->config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
     } else {
-        vdev->pdev.config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
+        pdev->config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
     }
 
     /*
@@ -3244,8 +3282,8 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
      * BAR, such as might be the case with the option ROM, we can get
      * confusing, unwritable, residual addresses from the host here.
      */
-    memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24);
-    memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4);
+    memset(&pdev->config[PCI_BASE_ADDRESS_0], 0, 24);
+    memset(&pdev->config[PCI_ROM_ADDRESS], 0, 4);
 
     vfio_pci_size_rom(vdev);
 
@@ -3262,7 +3300,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
 
 bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     /* QEMU emulates all of MSI & MSIX */
     if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
@@ -3275,10 +3313,10 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
                vdev->msi_cap_size);
     }
 
-    if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) {
+    if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) {
         vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
                                              vfio_intx_mmap_enable, vdev);
-        pci_device_set_intx_routing_notifier(&vdev->pdev,
+        pci_device_set_intx_routing_notifier(pdev,
                                              vfio_intx_routing_notifier);
         vdev->irqchip_change_notifier.notify = vfio_irqchip_change;
         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
@@ -3290,7 +3328,7 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
          */
         if (!cpr_is_incoming() && !vfio_intx_enable(vdev, errp)) {
             timer_free(vdev->intx.mmap_timer);
-            pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
+            pci_device_set_intx_routing_notifier(pdev, NULL);
             kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
             return false;
         }
@@ -3440,7 +3478,7 @@ out_deregister:
     if (vdev->interrupt == VFIO_INT_INTx) {
         vfio_intx_disable(vdev);
     }
-    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
+    pci_device_set_intx_routing_notifier(pdev, NULL);
     if (vdev->irqchip_change_notifier.notify) {
         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
     }
@@ -3472,7 +3510,7 @@ static void vfio_exitfn(PCIDevice *pdev)
 
     vfio_unregister_req_notifier(vdev);
     vfio_unregister_err_notifier(vdev);
-    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
+    pci_device_set_intx_routing_notifier(pdev, NULL);
     if (vdev->irqchip_change_notifier.notify) {
         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
     }
-- 
2.43.0



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

* [PATCH 17/22] vfio/pci-quirks.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (15 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 16/22] vfio/pci.c: " Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15  9:25 ` [PATCH 18/22] vfio/cpr.c: " Mark Cave-Ayland
                   ` (5 subsequent siblings)
  22 siblings, 0 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
accessing pdev directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/pci-quirks.c | 48 ++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index 3f002252ac..c97606dbf1 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -113,6 +113,7 @@ static uint64_t vfio_generic_window_quirk_data_read(void *opaque,
 {
     VFIOConfigWindowQuirk *window = opaque;
     VFIOPCIDevice *vdev = window->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint64_t data;
 
     /* Always read data reg, discard if window enabled */
@@ -120,7 +121,7 @@ static uint64_t vfio_generic_window_quirk_data_read(void *opaque,
                             addr + window->data_offset, size);
 
     if (window->window_enabled) {
-        data = vfio_pci_read_config(&vdev->pdev, window->address_val, size);
+        data = vfio_pci_read_config(pdev, window->address_val, size);
         trace_vfio_quirk_generic_window_data_read(vdev->vbasedev.name,
                                     memory_region_name(window->data_mem), data);
     }
@@ -133,9 +134,10 @@ static void vfio_generic_window_quirk_data_write(void *opaque, hwaddr addr,
 {
     VFIOConfigWindowQuirk *window = opaque;
     VFIOPCIDevice *vdev = window->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     if (window->window_enabled) {
-        vfio_pci_write_config(&vdev->pdev, window->address_val, data, size);
+        vfio_pci_write_config(pdev, window->address_val, data, size);
         trace_vfio_quirk_generic_window_data_write(vdev->vbasedev.name,
                                     memory_region_name(window->data_mem), data);
         return;
@@ -156,6 +158,7 @@ static uint64_t vfio_generic_quirk_mirror_read(void *opaque,
 {
     VFIOConfigMirrorQuirk *mirror = opaque;
     VFIOPCIDevice *vdev = mirror->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint64_t data;
 
     /* Read and discard in case the hardware cares */
@@ -163,7 +166,7 @@ static uint64_t vfio_generic_quirk_mirror_read(void *opaque,
                            addr + mirror->offset, size);
 
     addr += mirror->config_offset;
-    data = vfio_pci_read_config(&vdev->pdev, addr, size);
+    data = vfio_pci_read_config(pdev, addr, size);
     trace_vfio_quirk_generic_mirror_read(vdev->vbasedev.name,
                                          memory_region_name(mirror->mem),
                                          addr, data);
@@ -175,9 +178,10 @@ static void vfio_generic_quirk_mirror_write(void *opaque, hwaddr addr,
 {
     VFIOConfigMirrorQuirk *mirror = opaque;
     VFIOPCIDevice *vdev = mirror->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     addr += mirror->config_offset;
-    vfio_pci_write_config(&vdev->pdev, addr, data, size);
+    vfio_pci_write_config(pdev, addr, data, size);
     trace_vfio_quirk_generic_mirror_write(vdev->vbasedev.name,
                                           memory_region_name(mirror->mem),
                                           addr, data);
@@ -211,7 +215,8 @@ static uint64_t vfio_ati_3c3_quirk_read(void *opaque,
                                         hwaddr addr, unsigned size)
 {
     VFIOPCIDevice *vdev = opaque;
-    uint64_t data = vfio_pci_read_config(&vdev->pdev,
+    PCIDevice *pdev = PCI_DEVICE(vdev);
+    uint64_t data = vfio_pci_read_config(pdev,
                                          PCI_BASE_ADDRESS_4 + 1, size);
 
     trace_vfio_quirk_ati_3c3_read(vdev->vbasedev.name, data);
@@ -563,6 +568,7 @@ static uint64_t vfio_nvidia_3d0_quirk_read(void *opaque,
 {
     VFIONvidia3d0Quirk *quirk = opaque;
     VFIOPCIDevice *vdev = quirk->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIONvidia3d0State old_state = quirk->state;
     uint64_t data = vfio_vga_read(&vdev->vga->region[QEMU_PCI_VGA_IO_HI],
                                   addr + 0x10, size);
@@ -573,7 +579,7 @@ static uint64_t vfio_nvidia_3d0_quirk_read(void *opaque,
         (quirk->offset & ~(PCI_CONFIG_SPACE_SIZE - 1)) == 0x1800) {
         uint8_t offset = quirk->offset & (PCI_CONFIG_SPACE_SIZE - 1);
 
-        data = vfio_pci_read_config(&vdev->pdev, offset, size);
+        data = vfio_pci_read_config(pdev, offset, size);
         trace_vfio_quirk_nvidia_3d0_read(vdev->vbasedev.name,
                                          offset, size, data);
     }
@@ -586,6 +592,7 @@ static void vfio_nvidia_3d0_quirk_write(void *opaque, hwaddr addr,
 {
     VFIONvidia3d0Quirk *quirk = opaque;
     VFIOPCIDevice *vdev = quirk->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIONvidia3d0State old_state = quirk->state;
 
     quirk->state = NONE;
@@ -599,7 +606,7 @@ static void vfio_nvidia_3d0_quirk_write(void *opaque, hwaddr addr,
         if ((quirk->offset & ~(PCI_CONFIG_SPACE_SIZE - 1)) == 0x1800) {
             uint8_t offset = quirk->offset & (PCI_CONFIG_SPACE_SIZE - 1);
 
-            vfio_pci_write_config(&vdev->pdev, offset, data, size);
+            vfio_pci_write_config(pdev, offset, data, size);
             trace_vfio_quirk_nvidia_3d0_write(vdev->vbasedev.name,
                                               offset, data, size);
             return;
@@ -815,7 +822,7 @@ static void vfio_nvidia_quirk_mirror_write(void *opaque, hwaddr addr,
 {
     VFIOConfigMirrorQuirk *mirror = opaque;
     VFIOPCIDevice *vdev = mirror->vdev;
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     LastDataSet *last = (LastDataSet *)&mirror->data;
 
     vfio_generic_quirk_mirror_write(opaque, addr, data, size);
@@ -1005,6 +1012,7 @@ static void vfio_rtl8168_quirk_address_write(void *opaque, hwaddr addr,
 {
     VFIOrtl8168Quirk *rtl = opaque;
     VFIOPCIDevice *vdev = rtl->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     rtl->enabled = false;
 
@@ -1013,7 +1021,7 @@ static void vfio_rtl8168_quirk_address_write(void *opaque, hwaddr addr,
         rtl->addr = (uint32_t)data;
 
         if (data & 0x80000000U) { /* Do write */
-            if (vdev->pdev.cap_present & QEMU_PCI_CAP_MSIX) {
+            if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
                 hwaddr offset = data & 0xfff;
                 uint64_t val = rtl->data;
 
@@ -1021,7 +1029,7 @@ static void vfio_rtl8168_quirk_address_write(void *opaque, hwaddr addr,
                                                     (uint16_t)offset, val);
 
                 /* Write to the proper guest MSI-X table instead */
-                memory_region_dispatch_write(&vdev->pdev.msix_table_mmio,
+                memory_region_dispatch_write(&pdev->msix_table_mmio,
                                              offset, val,
                                              size_memop(size) | MO_LE,
                                              MEMTXATTRS_UNSPECIFIED);
@@ -1049,11 +1057,12 @@ static uint64_t vfio_rtl8168_quirk_data_read(void *opaque,
 {
     VFIOrtl8168Quirk *rtl = opaque;
     VFIOPCIDevice *vdev = rtl->vdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint64_t data = vfio_region_read(&vdev->bars[2].region, addr + 0x70, size);
 
-    if (rtl->enabled && (vdev->pdev.cap_present & QEMU_PCI_CAP_MSIX)) {
+    if (rtl->enabled && (pdev->cap_present & QEMU_PCI_CAP_MSIX)) {
         hwaddr offset = rtl->addr & 0xfff;
-        memory_region_dispatch_read(&vdev->pdev.msix_table_mmio, offset,
+        memory_region_dispatch_read(&pdev->msix_table_mmio, offset,
                                     &data, size_memop(size) | MO_LE,
                                     MEMTXATTRS_UNSPECIFIED);
         trace_vfio_quirk_rtl8168_msix_read(vdev->vbasedev.name, offset, data);
@@ -1297,7 +1306,7 @@ static void vfio_radeon_set_gfx_only_reset(VFIOPCIDevice *vdev)
 
 static int vfio_radeon_reset(VFIOPCIDevice *vdev)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int i, ret = 0;
     uint32_t data;
 
@@ -1454,7 +1463,7 @@ static bool is_valid_std_cap_offset(uint8_t pos)
 static bool vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
 {
     ERRP_GUARD();
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int ret, pos;
     bool c8_conflict = false, d4_conflict = false;
     uint8_t tmp;
@@ -1547,6 +1556,7 @@ static bool vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
 static bool vfio_add_vmd_shadow_cap(VFIOPCIDevice *vdev, Error **errp)
 {
     ERRP_GUARD();
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     uint8_t membar_phys[16];
     int ret, pos = 0xE8;
 
@@ -1565,7 +1575,7 @@ static bool vfio_add_vmd_shadow_cap(VFIOPCIDevice *vdev, Error **errp)
         return false;
     }
 
-    ret = pci_add_capability(&vdev->pdev, PCI_CAP_ID_VNDR, pos,
+    ret = pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos,
                              VMD_SHADOW_CAP_LEN, errp);
     if (ret < 0) {
         error_prepend(errp, "Failed to add VMD MEMBAR Shadow cap: ");
@@ -1574,10 +1584,10 @@ static bool vfio_add_vmd_shadow_cap(VFIOPCIDevice *vdev, Error **errp)
 
     memset(vdev->emulated_config_bits + pos, 0xFF, VMD_SHADOW_CAP_LEN);
     pos += PCI_CAP_FLAGS;
-    pci_set_byte(vdev->pdev.config + pos++, VMD_SHADOW_CAP_LEN);
-    pci_set_byte(vdev->pdev.config + pos++, VMD_SHADOW_CAP_VER);
-    pci_set_long(vdev->pdev.config + pos, 0x53484457); /* SHDW */
-    memcpy(vdev->pdev.config + pos + 4, membar_phys, 16);
+    pci_set_byte(pdev->config + pos++, VMD_SHADOW_CAP_LEN);
+    pci_set_byte(pdev->config + pos++, VMD_SHADOW_CAP_VER);
+    pci_set_long(pdev->config + pos, 0x53484457); /* SHDW */
+    memcpy(pdev->config + pos + 4, membar_phys, 16);
 
     return true;
 }
-- 
2.43.0



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

* [PATCH 18/22] vfio/cpr.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (16 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 17/22] vfio/pci-quirks.c: " Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-15 12:36   ` Steven Sistare
  2025-07-15  9:25 ` [PATCH 19/22] vfio/igd.c: " Mark Cave-Ayland
                   ` (4 subsequent siblings)
  22 siblings, 1 reply; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
accessing pdev directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/cpr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
index af0f12a7ad..3e3f4035ab 100644
--- a/hw/vfio/cpr.c
+++ b/hw/vfio/cpr.c
@@ -56,7 +56,7 @@ static void vfio_cpr_claim_vectors(VFIOPCIDevice *vdev, int nr_vectors,
 {
     int i, fd;
     bool pending = false;
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
 
     vdev->nr_vectors = nr_vectors;
     vdev->msi_vectors = g_new0(VFIOMSIVector, nr_vectors);
@@ -99,7 +99,7 @@ static void vfio_cpr_claim_vectors(VFIOPCIDevice *vdev, int nr_vectors,
 static int vfio_cpr_pci_pre_load(void *opaque)
 {
     VFIOPCIDevice *vdev = opaque;
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int size = MIN(pci_config_size(pdev), vdev->config_size);
     int i;
 
@@ -113,7 +113,7 @@ static int vfio_cpr_pci_pre_load(void *opaque)
 static int vfio_cpr_pci_post_load(void *opaque, int version_id)
 {
     VFIOPCIDevice *vdev = opaque;
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int nr_vectors;
 
     if (msix_enabled(pdev)) {
-- 
2.43.0



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

* [PATCH 19/22] vfio/igd.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (17 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 18/22] vfio/cpr.c: " Mark Cave-Ayland
@ 2025-07-15  9:25 ` Mark Cave-Ayland
  2025-07-18 15:26   ` Tomita Moeko
  2025-07-15  9:26 ` [PATCH 20/22] vfio-user/pci.c: " Mark Cave-Ayland
                   ` (3 subsequent siblings)
  22 siblings, 1 reply; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:25 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
accessing pdev directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/igd.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index e7a9d1ffc1..d3ffbe7db6 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -199,7 +199,7 @@ static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
     }
 
     /* Hotplugging is not supported for opregion access */
-    if (vdev->pdev.qdev.hotplugged) {
+    if (DEVICE(vdev)->hotplugged) {
         warn_report("IGD device detected, but OpRegion is not supported "
                     "on hotplugged device.");
         return false;
@@ -259,11 +259,12 @@ static int vfio_pci_igd_copy(VFIOPCIDevice *vdev, PCIDevice *pdev,
 static int vfio_pci_igd_host_init(VFIOPCIDevice *vdev,
                                   struct vfio_region_info *info)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     PCIBus *bus;
     PCIDevice *host_bridge;
     int ret;
 
-    bus = pci_device_root_bus(&vdev->pdev);
+    bus = pci_device_root_bus(pdev);
     host_bridge = pci_find_device(bus, 0, PCI_DEVFN(0, 0));
 
     if (!host_bridge) {
@@ -326,13 +327,14 @@ type_init(vfio_pci_igd_register_types)
 static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev,
                                  struct vfio_region_info *info)
 {
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     PCIDevice *lpc_bridge;
     int ret;
 
-    lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
+    lpc_bridge = pci_find_device(pci_device_root_bus(pdev),
                                  0, PCI_DEVFN(0x1f, 0));
     if (!lpc_bridge) {
-        lpc_bridge = pci_create_simple(pci_device_root_bus(&vdev->pdev),
+        lpc_bridge = pci_create_simple(pci_device_root_bus(pdev),
                                  PCI_DEVFN(0x1f, 0), "vfio-pci-igd-lpc-bridge");
     }
 
@@ -349,13 +351,14 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
 {
     struct vfio_region_info *host = NULL;
     struct vfio_region_info *lpc = NULL;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     PCIDevice *lpc_bridge;
     int ret;
 
     /*
      * Copying IDs or creating new devices are not supported on hotplug
      */
-    if (vdev->pdev.qdev.hotplugged) {
+    if (DEVICE(vdev)->hotplugged) {
         error_setg(errp, "IGD LPC is not supported on hotplugged device");
         return false;
     }
@@ -365,7 +368,7 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
      * can stuff host values into, so if there's already one there and it's not
      * one we can hack on, this quirk is no-go.  Sorry Q35.
      */
-    lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
+    lpc_bridge = pci_find_device(pci_device_root_bus(pdev),
                                  0, PCI_DEVFN(0x1f, 0));
     if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
                                            "vfio-pci-igd-lpc-bridge")) {
@@ -509,6 +512,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
 static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 {
     struct vfio_region_info *opregion = NULL;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     int ret, gen;
     uint64_t gms_size = 0;
     uint64_t *bdsm_size;
@@ -528,7 +532,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
     info_report("OpRegion detected on Intel display %x.", vdev->device_id);
 
     gen = igd_gen(vdev);
-    gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4);
+    gmch = vfio_pci_read_config(pdev, IGD_GMCH, 4);
 
     /*
      * For backward compatibility, enable legacy mode when
@@ -540,7 +544,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
     if ((vdev->igd_legacy_mode != ON_OFF_AUTO_OFF) &&
         (gen >= 6 && gen <= 9) &&
         !strcmp(MACHINE_GET_CLASS(qdev_get_machine())->family, "pc_piix") &&
-        (&vdev->pdev == pci_find_device(pci_device_root_bus(&vdev->pdev),
+        (pdev == pci_find_device(pci_device_root_bus(pdev),
         0, PCI_DEVFN(0x2, 0)))) {
         /*
          * IGD legacy mode requires:
@@ -562,7 +566,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
          */
         ret = vfio_device_get_region_info(&vdev->vbasedev,
                                           VFIO_PCI_ROM_REGION_INDEX, &rom);
-        if ((ret || !rom->size) && !vdev->pdev.romfile) {
+        if ((ret || !rom->size) && !pdev->romfile) {
             error_setg(&err, "Device has no ROM");
             goto error;
         }
@@ -605,8 +609,8 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
      * ASLS (OpRegion address) is read-only, emulated
      * It contains HPA, guest firmware need to reprogram it with GPA.
      */
-    pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
-    pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
+    pci_set_long(pdev->config + IGD_ASLS, 0);
+    pci_set_long(pdev->wmask + IGD_ASLS, ~0);
     pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
 
     /*
@@ -620,8 +624,8 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
         }
 
         /* GMCH is read-only, emulated */
-        pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
-        pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
+        pci_set_long(pdev->config + IGD_GMCH, gmch);
+        pci_set_long(pdev->wmask + IGD_GMCH, 0);
         pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
     }
 
@@ -630,12 +634,12 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
 
         /* BDSM is read-write, emulated. BIOS needs to be able to write it */
         if (gen < 11) {
-            pci_set_long(vdev->pdev.config + IGD_BDSM, 0);
-            pci_set_long(vdev->pdev.wmask + IGD_BDSM, ~0);
+            pci_set_long(pdev->config + IGD_BDSM, 0);
+            pci_set_long(pdev->wmask + IGD_BDSM, ~0);
             pci_set_long(vdev->emulated_config_bits + IGD_BDSM, ~0);
         } else {
-            pci_set_quad(vdev->pdev.config + IGD_BDSM_GEN11, 0);
-            pci_set_quad(vdev->pdev.wmask + IGD_BDSM_GEN11, ~0);
+            pci_set_quad(pdev->config + IGD_BDSM_GEN11, 0);
+            pci_set_quad(pdev->wmask + IGD_BDSM_GEN11, ~0);
             pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0);
         }
     }
-- 
2.43.0



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

* [PATCH 20/22] vfio-user/pci.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (18 preceding siblings ...)
  2025-07-15  9:25 ` [PATCH 19/22] vfio/igd.c: " Mark Cave-Ayland
@ 2025-07-15  9:26 ` Mark Cave-Ayland
  2025-07-15 14:17   ` John Levon
  2025-07-15  9:26 ` [PATCH 21/22] s390x/s390-pci-vfio.c: " Mark Cave-Ayland
                   ` (2 subsequent siblings)
  22 siblings, 1 reply; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:26 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
accessing pdev directly.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio-user/pci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
index 9380766548..25a1dc0529 100644
--- a/hw/vfio-user/pci.c
+++ b/hw/vfio-user/pci.c
@@ -65,7 +65,7 @@ static void vfio_user_msix_setup(VFIOPCIDevice *vdev)
     vdev->msix->pba_region = pba_reg;
 
     vfio_reg = vdev->bars[vdev->msix->pba_bar].mr;
-    msix_reg = &vdev->pdev.msix_pba_mmio;
+    msix_reg = &PCI_DEVICE(vdev)->msix_pba_mmio;
     memory_region_init_io(pba_reg, OBJECT(vdev), &vfio_user_pba_ops, vdev,
                           "VFIO MSIX PBA", int128_get64(msix_reg->size));
     memory_region_add_subregion_overlap(vfio_reg, vdev->msix->pba_offset,
@@ -86,7 +86,7 @@ static void vfio_user_msix_teardown(VFIOPCIDevice *vdev)
 
 static void vfio_user_dma_read(VFIOPCIDevice *vdev, VFIOUserDMARW *msg)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIOUserProxy *proxy = vdev->vbasedev.proxy;
     VFIOUserDMARW *res;
     MemTxResult r;
@@ -134,7 +134,7 @@ static void vfio_user_dma_read(VFIOPCIDevice *vdev, VFIOUserDMARW *msg)
 
 static void vfio_user_dma_write(VFIOPCIDevice *vdev, VFIOUserDMARW *msg)
 {
-    PCIDevice *pdev = &vdev->pdev;
+    PCIDevice *pdev = PCI_DEVICE(vdev);
     VFIOUserProxy *proxy = vdev->vbasedev.proxy;
     MemTxResult r;
 
-- 
2.43.0



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

* [PATCH 21/22] s390x/s390-pci-vfio.c: use QOM casts where appropriate
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (19 preceding siblings ...)
  2025-07-15  9:26 ` [PATCH 20/22] vfio-user/pci.c: " Mark Cave-Ayland
@ 2025-07-15  9:26 ` Mark Cave-Ayland
  2025-07-15 13:29   ` Eric Farman
  2025-07-15 14:19   ` Matthew Rosato
  2025-07-15  9:26 ` [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj Mark Cave-Ayland
  2025-07-15 14:31 ` [PATCH 00/22] vfio: improve use of QOM and coding guidelines Cédric Le Goater
  22 siblings, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:26 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Use QOM casts to cast to VFIOPCIDevice instead of using container_of().

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/s390x/s390-pci-vfio.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index aaf91319b4..938a551171 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -62,7 +62,7 @@ S390PCIDMACount *s390_pci_start_dma_count(S390pciState *s,
 {
     S390PCIDMACount *cnt;
     uint32_t avail;
-    VFIOPCIDevice *vpdev = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+    VFIOPCIDevice *vpdev = VFIO_PCI_BASE(pbdev->pdev);
     int id;
 
     assert(vpdev);
@@ -108,7 +108,7 @@ static void s390_pci_read_base(S390PCIBusDevice *pbdev,
 {
     struct vfio_info_cap_header *hdr;
     struct vfio_device_info_cap_zpci_base *cap;
-    VFIOPCIDevice *vpci =  container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+    VFIOPCIDevice *vpci = VFIO_PCI_BASE(pbdev->pdev);
     uint64_t vfio_size;
 
     hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_ZPCI_BASE);
@@ -162,7 +162,7 @@ static bool get_host_fh(S390PCIBusDevice *pbdev, struct vfio_device_info *info,
 {
     struct vfio_info_cap_header *hdr;
     struct vfio_device_info_cap_zpci_base *cap;
-    VFIOPCIDevice *vpci = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+    VFIOPCIDevice *vpci = VFIO_PCI_BASE(pbdev->pdev);
 
     hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_ZPCI_BASE);
 
@@ -185,7 +185,7 @@ static void s390_pci_read_group(S390PCIBusDevice *pbdev,
     struct vfio_device_info_cap_zpci_group *cap;
     S390pciState *s = s390_get_phb();
     ClpRspQueryPciGrp *resgrp;
-    VFIOPCIDevice *vpci =  container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+    VFIOPCIDevice *vpci = VFIO_PCI_BASE(pbdev->pdev);
     uint8_t start_gid = pbdev->zpci_fn.pfgid;
 
     hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_ZPCI_GROUP);
@@ -264,7 +264,7 @@ static void s390_pci_read_util(S390PCIBusDevice *pbdev,
 {
     struct vfio_info_cap_header *hdr;
     struct vfio_device_info_cap_zpci_util *cap;
-    VFIOPCIDevice *vpci =  container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+    VFIOPCIDevice *vpci = VFIO_PCI_BASE(pbdev->pdev);
 
     hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_ZPCI_UTIL);
 
@@ -291,7 +291,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
 {
     struct vfio_info_cap_header *hdr;
     struct vfio_device_info_cap_zpci_pfip *cap;
-    VFIOPCIDevice *vpci =  container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+    VFIOPCIDevice *vpci = VFIO_PCI_BASE(pbdev->pdev);
 
     hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_ZPCI_PFIP);
 
@@ -314,7 +314,7 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
 
 static struct vfio_device_info *get_device_info(S390PCIBusDevice *pbdev)
 {
-    VFIOPCIDevice *vfio_pci = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+    VFIOPCIDevice *vfio_pci = VFIO_PCI_BASE(pbdev->pdev);
 
     return vfio_get_device_info(vfio_pci->vbasedev.fd);
 }
-- 
2.43.0



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

* [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (20 preceding siblings ...)
  2025-07-15  9:26 ` [PATCH 21/22] s390x/s390-pci-vfio.c: " Mark Cave-Ayland
@ 2025-07-15  9:26 ` Mark Cave-Ayland
  2025-07-15  9:44   ` Philippe Mathieu-Daudé
                     ` (2 more replies)
  2025-07-15 14:31 ` [PATCH 00/22] vfio: improve use of QOM and coding guidelines Cédric Le Goater
  22 siblings, 3 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-07-15  9:26 UTC (permalink / raw)
  To: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

Now that nothing accesses the pdev field directly, rename pdev to
parent_obj as per our current coding guidelines.

Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
---
 hw/vfio/cpr.c | 4 ++--
 hw/vfio/pci.c | 4 ++--
 hw/vfio/pci.h | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
index 3e3f4035ab..366490c908 100644
--- a/hw/vfio/cpr.c
+++ b/hw/vfio/cpr.c
@@ -171,8 +171,8 @@ const VMStateDescription vfio_cpr_pci_vmstate = {
     .post_load = vfio_cpr_pci_post_load,
     .needed = cpr_incoming_needed,
     .fields = (VMStateField[]) {
-        VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice),
-        VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, pci_msix_present),
+        VMSTATE_PCI_DEVICE(parent_obj, VFIOPCIDevice),
+        VMSTATE_MSIX_TEST(parent_obj, VFIOPCIDevice, pci_msix_present),
         VMSTATE_VFIO_INTX(intx, VFIOPCIDevice),
         VMSTATE_END_OF_LIST()
     }
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index fb9eb58da5..1db6be8f21 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2804,8 +2804,8 @@ static const VMStateDescription vmstate_vfio_pci_config = {
     .version_id = 1,
     .minimum_version_id = 1,
     .fields = (const VMStateField[]) {
-        VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice),
-        VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, vfio_msix_present),
+        VMSTATE_PCI_DEVICE(parent_obj, VFIOPCIDevice),
+        VMSTATE_MSIX_TEST(parent_obj, VFIOPCIDevice, vfio_msix_present),
         VMSTATE_END_OF_LIST()
     },
     .subsections = (const VMStateDescription * const []) {
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index c0c3d68742..37d8b996f5 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -131,7 +131,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
 /* TYPE_VFIO_PCI shares struct VFIOPCIDevice. */
 
 struct VFIOPCIDevice {
-    PCIDevice pdev;
+    PCIDevice parent_obj;
 
     VFIODevice vbasedev;
     VFIOINTx intx;
-- 
2.43.0



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

* Re: [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration
  2025-07-15  9:25 ` [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration Mark Cave-Ayland
@ 2025-07-15  9:39   ` Philippe Mathieu-Daudé
  2025-08-11 11:45   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:39 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOContainer declaration so that it is closer to our coding
> guidelines: emove the explicit typedef (this is already handled by the
> OBJECT_DECLARE_TYPE() macro) and add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   include/hw/vfio/vfio-container.h | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)

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



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

* Re: [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj
  2025-07-15  9:25 ` [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj Mark Cave-Ayland
@ 2025-07-15  9:39   ` Philippe Mathieu-Daudé
  2025-08-11 12:23   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:39 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:25, Mark Cave-Ayland wrote:
> Now that nothing accesses the bcontainer field directly, rename bcontainer to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   include/hw/vfio/vfio-container.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

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



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

* Re: [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration
  2025-07-15  9:25 ` [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration Mark Cave-Ayland
@ 2025-07-15  9:39   ` Philippe Mathieu-Daudé
  2025-07-15 12:57   ` John Levon
  2025-08-11 12:23   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:39 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOUserContainer declaration so that it is closer to our coding
> guidelines: remove the explicit typedef (this is already handled by the
> OBJECT_DECLARE_TYPE() macro) and add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   hw/vfio-user/container.h | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)

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



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

* Re: [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj
  2025-07-15  9:25 ` [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj Mark Cave-Ayland
@ 2025-07-15  9:41   ` Philippe Mathieu-Daudé
  2025-07-15 14:13   ` John Levon
  2025-08-11 12:23   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:41 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:25, Mark Cave-Ayland wrote:
> Now that nothing accesses the bcontainer field directly, rename bcontainer to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   hw/vfio-user/container.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

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



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

* Re: [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration
  2025-07-15  9:25 ` [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration Mark Cave-Ayland
@ 2025-07-15  9:42   ` Philippe Mathieu-Daudé
  2025-07-15  9:43     ` Philippe Mathieu-Daudé
  2025-07-15 13:35   ` BALATON Zoltan
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:42 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOUserPCIDevice declaration so that it is closer to our coding
> guidelines: add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   hw/vfio-user/pci.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index be71c77729..da6fe51809 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -21,6 +21,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
>   
>   struct VFIOUserPCIDevice {
>       VFIOPCIDevice device;

s/device/parent_obj/?

> +
>       SocketAddress *socket;
>       bool send_queued;   /* all sends are queued */
>       uint32_t wait_time; /* timeout for message replies */

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



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

* Re: [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj
  2025-07-15  9:25 ` [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj Mark Cave-Ayland
@ 2025-07-15  9:42   ` Philippe Mathieu-Daudé
  2025-07-15 14:15   ` John Levon
  2025-08-11 12:25   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:42 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:25, Mark Cave-Ayland wrote:
> Now that nothing accesses the device field directly, rename device to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   hw/vfio-user/pci.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index e23a941605..9380766548 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -20,7 +20,7 @@
>   OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
>   
>   struct VFIOUserPCIDevice {
> -    VFIOPCIDevice device;
> +    VFIOPCIDevice parent_obj;

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



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

* Re: [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration
  2025-07-15  9:42   ` Philippe Mathieu-Daudé
@ 2025-07-15  9:43     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:43 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:42, Philippe Mathieu-Daudé wrote:
> On 15/7/25 11:25, Mark Cave-Ayland wrote:
>> Update the VFIOUserPCIDevice declaration so that it is closer to our 
>> coding
>> guidelines: add a blank line after the parent object.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>> ---
>>   hw/vfio-user/pci.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
>> index be71c77729..da6fe51809 100644
>> --- a/hw/vfio-user/pci.c
>> +++ b/hw/vfio-user/pci.c
>> @@ -21,6 +21,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, 
>> VFIO_USER_PCI)
>>   struct VFIOUserPCIDevice {
>>       VFIOPCIDevice device;
> 
> s/device/parent_obj/?

Patch #13, OK ;)

> 
>> +
>>       SocketAddress *socket;
>>       bool send_queued;   /* all sends are queued */
>>       uint32_t wait_time; /* timeout for message replies */
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 



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

* Re: [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration
  2025-07-15  9:25 ` [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration Mark Cave-Ayland
@ 2025-07-15  9:44   ` Philippe Mathieu-Daudé
  2025-08-11 12:25   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:44 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOPCIDevice declaration so that it is closer to our coding
> guidelines: add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   hw/vfio/pci.h | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
> index 495fae737d..16f092a0c6 100644
> --- a/hw/vfio/pci.h
> +++ b/hw/vfio/pci.h
> @@ -132,6 +132,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
>   
>   struct VFIOPCIDevice {
>       PCIDevice pdev;
> +

Could be squashed with #22, anyhow:

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

>       VFIODevice vbasedev;
>       VFIOINTx intx;
>       unsigned int config_size;



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

* Re: [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj
  2025-07-15  9:26 ` [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj Mark Cave-Ayland
@ 2025-07-15  9:44   ` Philippe Mathieu-Daudé
  2025-07-15 12:36   ` Steven Sistare
  2025-08-11 12:46   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-15  9:44 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 15/7/25 11:26, Mark Cave-Ayland wrote:
> Now that nothing accesses the pdev field directly, rename pdev to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>   hw/vfio/cpr.c | 4 ++--
>   hw/vfio/pci.c | 4 ++--
>   hw/vfio/pci.h | 2 +-
>   3 files changed, 5 insertions(+), 5 deletions(-)

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



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

* Re: [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate Mark Cave-Ayland
@ 2025-07-15 12:36   ` Steven Sistare
  2025-08-11 11:45   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Steven Sistare @ 2025-07-15 12:36 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 7/15/2025 5:25 AM, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Reviewed-by: Steve Sistare <steven.sistare@oracle.com>


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

* Re: [PATCH 18/22] vfio/cpr.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 18/22] vfio/cpr.c: " Mark Cave-Ayland
@ 2025-07-15 12:36   ` Steven Sistare
  0 siblings, 0 replies; 73+ messages in thread
From: Steven Sistare @ 2025-07-15 12:36 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 7/15/2025 5:25 AM, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
> accessing pdev directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Reviewed-by: Steve Sistare <steven.sistare@oracle.com>



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

* Re: [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj
  2025-07-15  9:26 ` [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj Mark Cave-Ayland
  2025-07-15  9:44   ` Philippe Mathieu-Daudé
@ 2025-07-15 12:36   ` Steven Sistare
  2025-08-11 12:46   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Steven Sistare @ 2025-07-15 12:36 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 7/15/2025 5:26 AM, Mark Cave-Ayland wrote:
> Now that nothing accesses the pdev field directly, rename pdev to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Reviewed-by: Steve Sistare <steven.sistare@oracle.com>



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

* Re: [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration
  2025-07-15  9:25 ` [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration Mark Cave-Ayland
  2025-07-15  9:39   ` Philippe Mathieu-Daudé
@ 2025-07-15 12:57   ` John Levon
  2025-08-11 12:23   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: John Levon @ 2025-07-15 12:57 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Tue, Jul 15, 2025 at 10:25:48AM +0100, Mark Cave-Ayland wrote:

> Update the VFIOUserContainer declaration so that it is closer to our coding
> guidelines: remove the explicit typedef (this is already handled by the
> OBJECT_DECLARE_TYPE() macro) and add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio-user/container.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/vfio-user/container.h b/hw/vfio-user/container.h
> index 2bb1fa1343..d5d2275af7 100644
> --- a/hw/vfio-user/container.h
> +++ b/hw/vfio-user/container.h
> @@ -13,10 +13,11 @@
>  #include "hw/vfio-user/proxy.h"
>  
>  /* MMU container sub-class for vfio-user. */
> -typedef struct VFIOUserContainer {
> +struct VFIOUserContainer {
>      VFIOContainerBase bcontainer;
> +
>      VFIOUserProxy *proxy;
> -} VFIOUserContainer;
> +};
>  
>  OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserContainer, VFIO_IOMMU_USER);
>  

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


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

* Re: [PATCH 21/22] s390x/s390-pci-vfio.c: use QOM casts where appropriate
  2025-07-15  9:26 ` [PATCH 21/22] s390x/s390-pci-vfio.c: " Mark Cave-Ayland
@ 2025-07-15 13:29   ` Eric Farman
  2025-07-15 14:19   ` Matthew Rosato
  1 sibling, 0 replies; 73+ messages in thread
From: Eric Farman @ 2025-07-15 13:29 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On Tue, 2025-07-15 at 10:26 +0100, Mark Cave-Ayland wrote:
> Use QOM casts to cast to VFIOPCIDevice instead of using container_of().
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/s390x/s390-pci-vfio.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

Reviewed-by: Eric Farman <farman@linux.ibm.com>


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

* Re: [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration
  2025-07-15  9:25 ` [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration Mark Cave-Ayland
  2025-07-15  9:42   ` Philippe Mathieu-Daudé
@ 2025-07-15 13:35   ` BALATON Zoltan
  2025-07-15 14:15   ` John Levon
  2025-08-11 12:24   ` Cédric Le Goater
  3 siblings, 0 replies; 73+ messages in thread
From: BALATON Zoltan @ 2025-07-15 13:35 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On Tue, 15 Jul 2025, Mark Cave-Ayland wrote:
> Update the VFIOUserPCIDevice declaration so that it is closer to our coding
> guidelines: add a blank line after the parent object.
>
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
> hw/vfio-user/pci.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index be71c77729..da6fe51809 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -21,6 +21,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
>
> struct VFIOUserPCIDevice {
>     VFIOPCIDevice device;
> +

This isn't worth a separate patch. Can be squashed in patch 13.

Regards,
BALATON Zoltan

>     SocketAddress *socket;
>     bool send_queued;   /* all sends are queued */
>     uint32_t wait_time; /* timeout for message replies */
>


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

* Re: [PATCH 16/22] vfio/pci.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 16/22] vfio/pci.c: " Mark Cave-Ayland
@ 2025-07-15 13:38   ` BALATON Zoltan
  2025-08-11 12:45     ` Cédric Le Goater
  2025-08-29 11:07     ` Mark Cave-Ayland
  0 siblings, 2 replies; 73+ messages in thread
From: BALATON Zoltan @ 2025-07-15 13:38 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On Tue, 15 Jul 2025, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
> accessing pdev directly.
>
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
> hw/vfio/pci.c | 202 ++++++++++++++++++++++++++++++--------------------
> 1 file changed, 120 insertions(+), 82 deletions(-)
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 1093b28df7..fb9eb58da5 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -119,6 +119,7 @@ static void vfio_intx_mmap_enable(void *opaque)
> static void vfio_intx_interrupt(void *opaque)
> {
>     VFIOPCIDevice *vdev = opaque;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);

Don't do that. Opaque data is already type checked when it is registered 
for the callback and cannot be changed so additional type checking here is 
just a performance hit without any advantage. It's OK to do it in less 
frequently called functions but don't add unnecessary casts to functions 
that can be called a lot.

Regards,
BALATON Zoltan

>     if (!event_notifier_test_and_clear(&vdev->intx.interrupt)) {
>         return;
> @@ -127,7 +128,7 @@ static void vfio_intx_interrupt(void *opaque)
>     trace_vfio_intx_interrupt(vdev->vbasedev.name, 'A' + vdev->intx.pin);
>
>     vdev->intx.pending = true;
> -    pci_irq_assert(&vdev->pdev);
> +    pci_irq_assert(pdev);
>     vfio_mmap_set_enabled(vdev, false);
>     if (vdev->intx.mmap_timeout) {
>         timer_mod(vdev->intx.mmap_timer,
> @@ -138,6 +139,7 @@ static void vfio_intx_interrupt(void *opaque)
> void vfio_pci_intx_eoi(VFIODevice *vbasedev)
> {
>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>
>     if (!vdev->intx.pending) {
>         return;
> @@ -146,13 +148,14 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev)
>     trace_vfio_pci_intx_eoi(vbasedev->name);
>
>     vdev->intx.pending = false;
> -    pci_irq_deassert(&vdev->pdev);
> +    pci_irq_deassert(pdev);
>     vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
> }
>
> static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
> {
> #ifdef CONFIG_KVM
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
>
>     if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
> @@ -165,7 +168,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
>     qemu_set_fd_handler(irq_fd, NULL, NULL, vdev);
>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>     vdev->intx.pending = false;
> -    pci_irq_deassert(&vdev->pdev);
> +    pci_irq_deassert(pdev);
>
>     /* Get an eventfd for resample/unmask */
>     if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 0, errp)) {
> @@ -243,6 +246,8 @@ static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
> static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
> {
> #ifdef CONFIG_KVM
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +
>     if (!vdev->intx.kvm_accel) {
>         return;
>     }
> @@ -253,7 +258,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
>      */
>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>     vdev->intx.pending = false;
> -    pci_irq_deassert(&vdev->pdev);
> +    pci_irq_deassert(pdev);
>
>     /* Tell KVM to stop listening for an INTx irqfd */
>     if (kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.interrupt,
> @@ -309,7 +314,7 @@ static void vfio_intx_routing_notifier(PCIDevice *pdev)
>         return;
>     }
>
> -    route = pci_device_route_intx_to_irq(&vdev->pdev, vdev->intx.pin);
> +    route = pci_device_route_intx_to_irq(pdev, vdev->intx.pin);
>
>     if (pci_intx_route_changed(&vdev->intx.route, &route)) {
>         vfio_intx_update(vdev, &route);
> @@ -326,7 +331,8 @@ static void vfio_irqchip_change(Notifier *notify, void *data)
>
> static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
> {
> -    uint8_t pin = vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +    uint8_t pin = vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1);
>     Error *err = NULL;
>     int32_t fd;
>
> @@ -344,7 +350,7 @@ 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);
> +    pci_config_set_interrupt_pin(pdev->config, pin);
>
> #ifdef CONFIG_KVM
>     /*
> @@ -352,7 +358,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
>      * where we won't actually use the result anyway.
>      */
>     if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) {
> -        vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
> +        vdev->intx.route = pci_device_route_intx_to_irq(pdev,
>                                                         vdev->intx.pin);
>     }
> #endif
> @@ -392,13 +398,14 @@ skip_signaling:
>
> static void vfio_intx_disable(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     int fd;
>
>     timer_del(vdev->intx.mmap_timer);
>     vfio_intx_disable_kvm(vdev);
>     vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>     vdev->intx.pending = false;
> -    pci_irq_deassert(&vdev->pdev);
> +    pci_irq_deassert(pdev);
>     vfio_mmap_set_enabled(vdev, true);
>
>     fd = event_notifier_get_fd(&vdev->intx.interrupt);
> @@ -422,6 +429,7 @@ static void vfio_msi_interrupt(void *opaque)
> {
>     VFIOMSIVector *vector = opaque;
>     VFIOPCIDevice *vdev = vector->vdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     MSIMessage (*get_msg)(PCIDevice *dev, unsigned vector);
>     void (*notify)(PCIDevice *dev, unsigned vector);
>     MSIMessage msg;
> @@ -436,9 +444,9 @@ static void vfio_msi_interrupt(void *opaque)
>         notify = msix_notify;
>
>         /* A masked vector firing needs to use the PBA, enable it */
> -        if (msix_is_masked(&vdev->pdev, nr)) {
> +        if (msix_is_masked(pdev, nr)) {
>             set_bit(nr, vdev->msix->pending);
> -            memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, true);
> +            memory_region_set_enabled(&pdev->msix_pba_mmio, true);
>             trace_vfio_msix_pba_enable(vdev->vbasedev.name);
>         }
>     } else if (vdev->interrupt == VFIO_INT_MSI) {
> @@ -448,9 +456,9 @@ static void vfio_msi_interrupt(void *opaque)
>         abort();
>     }
>
> -    msg = get_msg(&vdev->pdev, nr);
> +    msg = get_msg(pdev, nr);
>     trace_vfio_msi_interrupt(vdev->vbasedev.name, nr, msg.address, msg.data);
> -    notify(&vdev->pdev, nr);
> +    notify(pdev, nr);
> }
>
> void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr)
> @@ -488,6 +496,7 @@ static int vfio_enable_msix_no_vec(VFIOPCIDevice *vdev)
>
> static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     struct vfio_irq_set *irq_set;
>     int ret = 0, i, argsz;
>     int32_t *fds;
> @@ -530,7 +539,7 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
>          */
>         if (vdev->msi_vectors[i].use) {
>             if (vdev->msi_vectors[i].virq < 0 ||
> -                (msix && msix_is_masked(&vdev->pdev, i))) {
> +                (msix && msix_is_masked(pdev, i))) {
>                 fd = event_notifier_get_fd(&vdev->msi_vectors[i].interrupt);
>             } else {
>                 fd = event_notifier_get_fd(&vdev->msi_vectors[i].kvm_interrupt);
> @@ -550,12 +559,14 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
> void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector,
>                                int vector_n, bool msix)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +
>     if ((msix && vdev->no_kvm_msix) || (!msix && vdev->no_kvm_msi)) {
>         return;
>     }
>
>     vector->virq = kvm_irqchip_add_msi_route(&vfio_route_change,
> -                                             vector_n, &vdev->pdev);
> +                                             vector_n, pdev);
> }
>
> static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector, int nr)
> @@ -624,7 +635,7 @@ static void set_irq_signalling(VFIODevice *vbasedev, VFIOMSIVector *vector,
> void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr)
> {
>     VFIOMSIVector *vector = &vdev->msi_vectors[nr];
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     Error *local_err = NULL;
>
>     vector->vdev = vdev;
> @@ -713,7 +724,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
>     clear_bit(nr, vdev->msix->pending);
>     if (find_first_bit(vdev->msix->pending,
>                        vdev->nr_vectors) == vdev->nr_vectors) {
> -        memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
> +        memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>         trace_vfio_msix_pba_disable(vdev->vbasedev.name);
>     }
>
> @@ -764,7 +775,9 @@ static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr)
>
> void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev)
> {
> -    msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +
> +    msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>                               vfio_msix_vector_release, NULL);
> }
>
> @@ -791,6 +804,7 @@ void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev)
>
> static void vfio_msix_enable(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     int ret;
>
>     vfio_disable_interrupts(vdev);
> @@ -807,7 +821,7 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>      */
>     vfio_pci_prepare_kvm_msi_virq_batch(vdev);
>
> -    if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
> +    if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>                                   vfio_msix_vector_release, NULL)) {
>         error_report("vfio: msix_set_vector_notifiers failed");
>     }
> @@ -845,11 +859,12 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>
> static void vfio_msi_enable(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     int ret, i;
>
>     vfio_disable_interrupts(vdev);
>
> -    vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev);
> +    vdev->nr_vectors = msi_nr_vectors_allocated(pdev);
> retry:
>     /*
>      * Setting vector notifiers needs to enable route for each vector.
> @@ -942,10 +957,11 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev)
>
> static void vfio_msix_disable(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     Error *err = NULL;
>     int i;
>
> -    msix_unset_vector_notifiers(&vdev->pdev);
> +    msix_unset_vector_notifiers(pdev);
>
>     /*
>      * MSI-X will only release vectors if MSI-X is still enabled on the
> @@ -953,8 +969,8 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
>      */
>     for (i = 0; i < vdev->nr_vectors; i++) {
>         if (vdev->msi_vectors[i].use) {
> -            vfio_msix_vector_release(&vdev->pdev, i);
> -            msix_vector_unuse(&vdev->pdev, i);
> +            vfio_msix_vector_release(pdev, i);
> +            msix_vector_unuse(pdev, i);
>         }
>     }
>
> @@ -991,6 +1007,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev)
>
> static void vfio_update_msi(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     int i;
>
>     for (i = 0; i < vdev->nr_vectors; i++) {
> @@ -1001,8 +1018,8 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
>             continue;
>         }
>
> -        msg = msi_get_message(&vdev->pdev, i);
> -        vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev);
> +        msg = msi_get_message(pdev, i);
> +        vfio_update_kvm_msi_virq(vector, msg, pdev);
>     }
> }
>
> @@ -1164,13 +1181,14 @@ static const MemoryRegionOps vfio_rom_ops = {
>
> static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     VFIODevice *vbasedev = &vdev->vbasedev;
>     uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);
>     char *name;
>
> -    if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
> +    if (pdev->romfile || !pdev->rom_bar) {
>         /* Since pci handles romfile, just print a message and return */
> -        if (vfio_opt_rom_in_denylist(vdev) && vdev->pdev.romfile) {
> +        if (vfio_opt_rom_in_denylist(vdev) && pdev->romfile) {
>             warn_report("Device at %s is known to cause system instability"
>                         " issues during option rom execution",
>                         vdev->vbasedev.name);
> @@ -1199,7 +1217,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>     }
>
>     if (vfio_opt_rom_in_denylist(vdev)) {
> -        if (vdev->pdev.rom_bar > 0) {
> +        if (pdev->rom_bar > 0) {
>             warn_report("Device at %s is known to cause system instability"
>                         " issues during option rom execution",
>                         vdev->vbasedev.name);
> @@ -1218,12 +1236,12 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>
>     name = g_strdup_printf("vfio[%s].rom", vdev->vbasedev.name);
>
> -    memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),
> +    memory_region_init_io(&pdev->rom, OBJECT(vdev),
>                           &vfio_rom_ops, vdev, name, size);
>     g_free(name);
>
> -    pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,
> -                     PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);
> +    pci_register_bar(pdev, PCI_ROM_SLOT,
> +                     PCI_BASE_ADDRESS_SPACE_MEMORY, &pdev->rom);
>
>     vdev->rom_read_failed = false;
> }
> @@ -1496,6 +1514,7 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vdev)
>
> static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     uint16_t ctrl;
>     bool msi_64bit, msi_maskbit;
>     int ret, entries;
> @@ -1516,7 +1535,7 @@ static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>
>     trace_vfio_msi_setup(vdev->vbasedev.name, pos);
>
> -    ret = msi_init(&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, &err);
> +    ret = msi_init(pdev, pos, entries, msi_64bit, msi_maskbit, &err);
>     if (ret < 0) {
>         if (ret == -ENOTSUP) {
>             return true;
> @@ -1709,6 +1728,7 @@ static bool vfio_pci_relocate_msix(VFIOPCIDevice *vdev, Error **errp)
>  */
> static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     uint8_t pos;
>     uint16_t ctrl;
>     uint32_t table, pba;
> @@ -1716,7 +1736,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>     VFIOMSIXInfo *msix;
>     int ret;
>
> -    pos = pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX);
> +    pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
>     if (!pos) {
>         return true;
>     }
> @@ -1808,12 +1828,13 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>
> static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     int ret;
>     Error *err = NULL;
>
>     vdev->msix->pending = g_new0(unsigned long,
>                                  BITS_TO_LONGS(vdev->msix->entries));
> -    ret = msix_init(&vdev->pdev, vdev->msix->entries,
> +    ret = msix_init(pdev, vdev->msix->entries,
>                     vdev->bars[vdev->msix->table_bar].mr,
>                     vdev->msix->table_bar, vdev->msix->table_offset,
>                     vdev->bars[vdev->msix->pba_bar].mr,
> @@ -1845,7 +1866,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>      * vector-use notifier is called, which occurs on unmask, we test whether
>      * PBA emulation is needed and again disable if not.
>      */
> -    memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
> +    memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>
>     /*
>      * The emulated machine may provide a paravirt interface for MSIX setup
> @@ -1857,7 +1878,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>      */
>     if (object_property_get_bool(OBJECT(qdev_get_machine()),
>                                  "vfio-no-msix-emulation", NULL)) {
> -        memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false);
> +        memory_region_set_enabled(&pdev->msix_table_mmio, false);
>     }
>
>     return true;
> @@ -1865,10 +1886,12 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>
> void vfio_pci_teardown_msi(VFIOPCIDevice *vdev)
> {
> -    msi_uninit(&vdev->pdev);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +
> +    msi_uninit(pdev);
>
>     if (vdev->msix) {
> -        msix_uninit(&vdev->pdev,
> +        msix_uninit(pdev,
>                     vdev->bars[vdev->msix->table_bar].mr,
>                     vdev->bars[vdev->msix->pba_bar].mr);
>         g_free(vdev->msix->pending);
> @@ -1929,6 +1952,7 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev)
>
> static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     VFIOBAR *bar = &vdev->bars[nr];
>     char *name;
>
> @@ -1950,7 +1974,7 @@ static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
>         }
>     }
>
> -    pci_register_bar(&vdev->pdev, nr, bar->type, bar->mr);
> +    pci_register_bar(pdev, nr, bar->type, bar->mr);
> }
>
> static void vfio_bars_register(VFIOPCIDevice *vdev)
> @@ -1964,6 +1988,7 @@ static void vfio_bars_register(VFIOPCIDevice *vdev)
>
> void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     int i;
>
>     for (i = 0; i < PCI_ROM_SLOT; i++) {
> @@ -1977,7 +2002,7 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
>     }
>
>     if (vdev->vga) {
> -        pci_unregister_vga(&vdev->pdev);
> +        pci_unregister_vga(pdev);
>         vfio_vga_quirk_exit(vdev);
>     }
> }
> @@ -2049,8 +2074,10 @@ static void vfio_set_word_bits(uint8_t *buf, uint16_t val, uint16_t mask)
> static void vfio_add_emulated_word(VFIOPCIDevice *vdev, int pos,
>                                    uint16_t val, uint16_t mask)
> {
> -    vfio_set_word_bits(vdev->pdev.config + pos, val, mask);
> -    vfio_set_word_bits(vdev->pdev.wmask + pos, ~mask, mask);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +
> +    vfio_set_word_bits(pdev->config + pos, val, mask);
> +    vfio_set_word_bits(pdev->wmask + pos, ~mask, mask);
>     vfio_set_word_bits(vdev->emulated_config_bits + pos, mask, mask);
> }
>
> @@ -2062,8 +2089,10 @@ static void vfio_set_long_bits(uint8_t *buf, uint32_t val, uint32_t mask)
> static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos,
>                                    uint32_t val, uint32_t mask)
> {
> -    vfio_set_long_bits(vdev->pdev.config + pos, val, mask);
> -    vfio_set_long_bits(vdev->pdev.wmask + pos, ~mask, mask);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +
> +    vfio_set_long_bits(pdev->config + pos, val, mask);
> +    vfio_set_long_bits(pdev->wmask + pos, ~mask, mask);
>     vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask);
> }
>
> @@ -2071,7 +2100,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
> {
>     struct vfio_device_info_cap_pci_atomic_comp *cap;
>     g_autofree struct vfio_device_info *info = NULL;
> -    PCIBus *bus = pci_get_bus(&vdev->pdev);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +    PCIBus *bus = pci_get_bus(pdev);
>     PCIDevice *parent = bus->parent_dev;
>     struct vfio_info_cap_header *hdr;
>     uint32_t mask = 0;
> @@ -2087,8 +2117,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>     if (pci_bus_is_root(bus) || !parent || !parent->exp.exp_cap ||
>         pcie_cap_get_type(parent) != PCI_EXP_TYPE_ROOT_PORT ||
>         pcie_cap_get_version(parent) != PCI_EXP_FLAGS_VER2 ||
> -        vdev->pdev.devfn ||
> -        vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
> +        pdev->devfn ||
> +        pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>         return;
>     }
>
> @@ -2132,8 +2162,10 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>
> static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +
>     if (vdev->clear_parent_atomics_on_exit) {
> -        PCIDevice *parent = pci_get_bus(&vdev->pdev)->parent_dev;
> +        PCIDevice *parent = pci_get_bus(pdev)->parent_dev;
>         uint8_t *pos = parent->config + parent->exp.exp_cap + PCI_EXP_DEVCAP2;
>
>         pci_long_test_and_clear_mask(pos, PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
> @@ -2145,10 +2177,11 @@ static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
> static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>                                 Error **errp)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     uint16_t flags;
>     uint8_t type;
>
> -    flags = pci_get_word(vdev->pdev.config + pos + PCI_CAP_FLAGS);
> +    flags = pci_get_word(pdev->config + pos + PCI_CAP_FLAGS);
>     type = (flags & PCI_EXP_FLAGS_TYPE) >> 4;
>
>     if (type != PCI_EXP_TYPE_ENDPOINT &&
> @@ -2160,8 +2193,8 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>         return false;
>     }
>
> -    if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) {
> -        PCIBus *bus = pci_get_bus(&vdev->pdev);
> +    if (!pci_bus_is_express(pci_get_bus(pdev))) {
> +        PCIBus *bus = pci_get_bus(pdev);
>         PCIDevice *bridge;
>
>         /*
> @@ -2193,7 +2226,7 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>             return true;
>         }
>
> -    } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) {
> +    } else if (pci_bus_is_root(pci_get_bus(pdev))) {
>         /*
>          * On a Root Complex bus Endpoints become Root Complex Integrated
>          * Endpoints, which changes the type and clears the LNK & LNK2 fields.
> @@ -2261,20 +2294,20 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>                                1, PCI_EXP_FLAGS_VERS);
>     }
>
> -    pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size,
> -                             errp);
> +    pos = pci_add_capability(pdev, PCI_CAP_ID_EXP, pos, size, errp);
>     if (pos < 0) {
>         return false;
>     }
>
> -    vdev->pdev.exp.exp_cap = pos;
> +    pdev->exp.exp_cap = pos;
>
>     return true;
> }
>
> static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
> {
> -    uint32_t cap = pci_get_long(vdev->pdev.config + pos + PCI_EXP_DEVCAP);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +    uint32_t cap = pci_get_long(pdev->config + pos + PCI_EXP_DEVCAP);
>
>     if (cap & PCI_EXP_DEVCAP_FLR) {
>         trace_vfio_check_pcie_flr(vdev->vbasedev.name);
> @@ -2284,7 +2317,8 @@ static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
>
> static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
> {
> -    uint16_t csr = pci_get_word(vdev->pdev.config + pos + PCI_PM_CTRL);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +    uint16_t csr = pci_get_word(pdev->config + pos + PCI_PM_CTRL);
>
>     if (!(csr & PCI_PM_CTRL_NO_SOFT_RESET)) {
>         trace_vfio_check_pm_reset(vdev->vbasedev.name);
> @@ -2294,7 +2328,8 @@ static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
>
> static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
> {
> -    uint8_t cap = pci_get_byte(vdev->pdev.config + pos + PCI_AF_CAP);
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> +    uint8_t cap = pci_get_byte(pdev->config + pos + PCI_AF_CAP);
>
>     if ((cap & PCI_AF_CAP_TP) && (cap & PCI_AF_CAP_FLR)) {
>         trace_vfio_check_af_flr(vdev->vbasedev.name);
> @@ -2305,7 +2340,7 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
> static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
>                                          uint8_t size, Error **errp)
> {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>
>     pos = pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp);
>     if (pos < 0) {
> @@ -2327,7 +2362,7 @@ static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
> static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)
> {
>     ERRP_GUARD();
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     uint8_t cap_id, next, size;
>     bool ret;
>
> @@ -2413,17 +2448,18 @@ static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)
>
> static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     uint32_t ctrl;
>     int i, nbar;
>
> -    ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL);
> +    ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL);
>     nbar = (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> PCI_REBAR_CTRL_NBAR_SHIFT;
>
>     for (i = 0; i < nbar; i++) {
>         uint32_t cap;
>         int size;
>
> -        ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL + (i * 8));
> +        ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL + (i * 8));
>         size = (ctrl & PCI_REBAR_CTRL_BAR_SIZE) >> PCI_REBAR_CTRL_BAR_SHIFT;
>
>         /* The cap register reports sizes 1MB to 128TB, with 4 reserved bits */
> @@ -2461,7 +2497,7 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
>
> static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
> {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     uint32_t header;
>     uint16_t cap_id, next, size;
>     uint8_t cap_ver;
> @@ -2555,7 +2591,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
>
> bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
> {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>
>     if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) ||
>         !pdev->config[PCI_CAPABILITY_LIST]) {
> @@ -2572,7 +2608,7 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
>
> void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
> {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     uint16_t cmd;
>
>     vfio_disable_interrupts(vdev);
> @@ -2789,7 +2825,7 @@ static int vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f, Error **errp)
> static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
> {
>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     pcibus_t old_addr[PCI_NUM_REGIONS - 1];
>     int bar, ret;
>
> @@ -2837,6 +2873,7 @@ static VFIODeviceOps vfio_pci_ops = {
>
> bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     VFIODevice *vbasedev = &vdev->vbasedev;
>     struct vfio_region_info *reg_info = NULL;
>     int ret;
> @@ -2893,7 +2930,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
>                           "vfio-vga-io@0x3c0",
>                           QEMU_PCI_VGA_IO_HI_SIZE);
>
> -    pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
> +    pci_register_vga(pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
>                      &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
>                      &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
>
> @@ -2902,6 +2939,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
>
> bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
> {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     VFIODevice *vbasedev = &vdev->vbasedev;
>     struct vfio_region_info *reg_info = NULL;
>     struct vfio_irq_info irq_info;
> @@ -2953,7 +2991,7 @@ bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
>
>     vdev->config_size = reg_info->size;
>     if (vdev->config_size == PCI_CONFIG_SPACE_SIZE) {
> -        vdev->pdev.cap_present &= ~QEMU_PCI_CAP_EXPRESS;
> +        pdev->cap_present &= ~QEMU_PCI_CAP_EXPRESS;
>     }
>     vdev->config_offset = reg_info->offset;
>
> @@ -3156,16 +3194,16 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
>
> bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
> {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>     VFIODevice *vbasedev = &vdev->vbasedev;
>     uint32_t config_space_size;
>     int ret;
>
> -    config_space_size = MIN(pci_config_size(&vdev->pdev), vdev->config_size);
> +    config_space_size = MIN(pci_config_size(pdev), vdev->config_size);
>
>     /* Get a copy of config space */
>     ret = vfio_pci_config_space_read(vdev, 0, config_space_size,
> -                                     vdev->pdev.config);
> +                                     pdev->config);
>     if (ret < (int)config_space_size) {
>         ret = ret < 0 ? -ret : EFAULT;
>         error_setg_errno(errp, ret, "failed to read device config space");
> @@ -3233,10 +3271,10 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>                                               PCI_HEADER_TYPE_MULTI_FUNCTION;
>
>     /* Restore or clear multifunction, this is always controlled by QEMU */
> -    if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
> -        vdev->pdev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
> +    if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
> +        pdev->config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
>     } else {
> -        vdev->pdev.config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
> +        pdev->config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>     }
>
>     /*
> @@ -3244,8 +3282,8 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>      * BAR, such as might be the case with the option ROM, we can get
>      * confusing, unwritable, residual addresses from the host here.
>      */
> -    memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24);
> -    memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4);
> +    memset(&pdev->config[PCI_BASE_ADDRESS_0], 0, 24);
> +    memset(&pdev->config[PCI_ROM_ADDRESS], 0, 4);
>
>     vfio_pci_size_rom(vdev);
>
> @@ -3262,7 +3300,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>
> bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
> {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>
>     /* QEMU emulates all of MSI & MSIX */
>     if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
> @@ -3275,10 +3313,10 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
>                vdev->msi_cap_size);
>     }
>
> -    if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) {
> +    if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) {
>         vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
>                                              vfio_intx_mmap_enable, vdev);
> -        pci_device_set_intx_routing_notifier(&vdev->pdev,
> +        pci_device_set_intx_routing_notifier(pdev,
>                                              vfio_intx_routing_notifier);
>         vdev->irqchip_change_notifier.notify = vfio_irqchip_change;
>         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
> @@ -3290,7 +3328,7 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
>          */
>         if (!cpr_is_incoming() && !vfio_intx_enable(vdev, errp)) {
>             timer_free(vdev->intx.mmap_timer);
> -            pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
> +            pci_device_set_intx_routing_notifier(pdev, NULL);
>             kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
>             return false;
>         }
> @@ -3440,7 +3478,7 @@ out_deregister:
>     if (vdev->interrupt == VFIO_INT_INTx) {
>         vfio_intx_disable(vdev);
>     }
> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>     if (vdev->irqchip_change_notifier.notify) {
>         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
>     }
> @@ -3472,7 +3510,7 @@ static void vfio_exitfn(PCIDevice *pdev)
>
>     vfio_unregister_req_notifier(vdev);
>     vfio_unregister_err_notifier(vdev);
> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>     if (vdev->irqchip_change_notifier.notify) {
>         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
>     }
>


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

* Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 09/22] vfio/container.c: use QOM casts where appropriate Mark Cave-Ayland
@ 2025-07-15 14:13   ` John Levon
  2025-08-28 15:14     ` Mark Cave-Ayland
  2025-08-11 12:23   ` Cédric Le Goater
  1 sibling, 1 reply; 73+ messages in thread
From: John Levon @ 2025-07-15 14:13 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Tue, Jul 15, 2025 at 10:25:49AM +0100, Mark Cave-Ayland wrote:

> Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Patch subject should be  "vfio-user/container.c" not vfio/container.c

regards
john


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

* Re: [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj
  2025-07-15  9:25 ` [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj Mark Cave-Ayland
  2025-07-15  9:41   ` Philippe Mathieu-Daudé
@ 2025-07-15 14:13   ` John Levon
  2025-08-11 12:23   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: John Levon @ 2025-07-15 14:13 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Tue, Jul 15, 2025 at 10:25:50AM +0100, Mark Cave-Ayland wrote:

> Now that nothing accesses the bcontainer field directly, rename bcontainer to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio-user/container.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/vfio-user/container.h b/hw/vfio-user/container.h
> index d5d2275af7..96aa6785d9 100644
> --- a/hw/vfio-user/container.h
> +++ b/hw/vfio-user/container.h
> @@ -14,7 +14,7 @@
>  
>  /* MMU container sub-class for vfio-user. */
>  struct VFIOUserContainer {
> -    VFIOContainerBase bcontainer;
> +    VFIOContainerBase parent_obj;
>  
>      VFIOUserProxy *proxy;
>  };

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


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

* Re: [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration
  2025-07-15  9:25 ` [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration Mark Cave-Ayland
  2025-07-15  9:42   ` Philippe Mathieu-Daudé
  2025-07-15 13:35   ` BALATON Zoltan
@ 2025-07-15 14:15   ` John Levon
  2025-08-11 12:24   ` Cédric Le Goater
  3 siblings, 0 replies; 73+ messages in thread
From: John Levon @ 2025-07-15 14:15 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Tue, Jul 15, 2025 at 10:25:51AM +0100, Mark Cave-Ayland wrote:

> Update the VFIOUserPCIDevice declaration so that it is closer to our coding
> guidelines: add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio-user/pci.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index be71c77729..da6fe51809 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -21,6 +21,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
>  
>  struct VFIOUserPCIDevice {
>      VFIOPCIDevice device;
> +
>      SocketAddress *socket;
>      bool send_queued;   /* all sends are queued */
>      uint32_t wait_time; /* timeout for message replies */

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



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

* Re: [PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate Mark Cave-Ayland
@ 2025-07-15 14:15   ` John Levon
  0 siblings, 0 replies; 73+ messages in thread
From: John Levon @ 2025-07-15 14:15 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Tue, Jul 15, 2025 at 10:25:52AM +0100, Mark Cave-Ayland wrote:

> Use QOM casts to convert between VFIOUserPCIDevice and VFIOPCIDevice instead
> of accessing device directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio-user/pci.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index da6fe51809..e23a941605 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -214,8 +214,9 @@ static void vfio_user_compute_needs_reset(VFIODevice *vbasedev)
>  
>  static Object *vfio_user_pci_get_object(VFIODevice *vbasedev)
>  {
> -    VFIOUserPCIDevice *vdev = container_of(vbasedev, VFIOUserPCIDevice,
> -                                           device.vbasedev);
> +    VFIOUserPCIDevice *vdev = VFIO_USER_PCI(container_of(vbasedev,
> +                                                         VFIOPCIDevice,
> +                                                         vbasedev));
>  
>      return OBJECT(vdev);
>  }
> @@ -418,7 +419,7 @@ static void vfio_user_pci_set_socket(Object *obj, Visitor *v, const char *name,
>      VFIOUserPCIDevice *udev = VFIO_USER_PCI(obj);
>      bool success;
>  
> -    if (udev->device.vbasedev.proxy) {
> +    if (VFIO_PCI_BASE(udev)->vbasedev.proxy) {
>          error_setg(errp, "Proxy is connected");
>          return;
>      }

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


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

* Re: [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj
  2025-07-15  9:25 ` [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj Mark Cave-Ayland
  2025-07-15  9:42   ` Philippe Mathieu-Daudé
@ 2025-07-15 14:15   ` John Levon
  2025-08-11 12:25   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: John Levon @ 2025-07-15 14:15 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Tue, Jul 15, 2025 at 10:25:53AM +0100, Mark Cave-Ayland wrote:

> Now that nothing accesses the device field directly, rename device to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio-user/pci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index e23a941605..9380766548 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -20,7 +20,7 @@
>  OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
>  
>  struct VFIOUserPCIDevice {
> -    VFIOPCIDevice device;
> +    VFIOPCIDevice parent_obj;
>  
>      SocketAddress *socket;
>      bool send_queued;   /* all sends are queued */

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



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

* Re: [PATCH 20/22] vfio-user/pci.c: use QOM casts where appropriate
  2025-07-15  9:26 ` [PATCH 20/22] vfio-user/pci.c: " Mark Cave-Ayland
@ 2025-07-15 14:17   ` John Levon
  0 siblings, 0 replies; 73+ messages in thread
From: John Levon @ 2025-07-15 14:17 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Tue, Jul 15, 2025 at 10:26:00AM +0100, Mark Cave-Ayland wrote:

> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
> accessing pdev directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio-user/pci.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index 9380766548..25a1dc0529 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -65,7 +65,7 @@ static void vfio_user_msix_setup(VFIOPCIDevice *vdev)
>      vdev->msix->pba_region = pba_reg;
>  
>      vfio_reg = vdev->bars[vdev->msix->pba_bar].mr;
> -    msix_reg = &vdev->pdev.msix_pba_mmio;
> +    msix_reg = &PCI_DEVICE(vdev)->msix_pba_mmio;
>      memory_region_init_io(pba_reg, OBJECT(vdev), &vfio_user_pba_ops, vdev,
>                            "VFIO MSIX PBA", int128_get64(msix_reg->size));
>      memory_region_add_subregion_overlap(vfio_reg, vdev->msix->pba_offset,
> @@ -86,7 +86,7 @@ static void vfio_user_msix_teardown(VFIOPCIDevice *vdev)
>  
>  static void vfio_user_dma_read(VFIOPCIDevice *vdev, VFIOUserDMARW *msg)
>  {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>      VFIOUserProxy *proxy = vdev->vbasedev.proxy;
>      VFIOUserDMARW *res;
>      MemTxResult r;
> @@ -134,7 +134,7 @@ static void vfio_user_dma_read(VFIOPCIDevice *vdev, VFIOUserDMARW *msg)
>  
>  static void vfio_user_dma_write(VFIOPCIDevice *vdev, VFIOUserDMARW *msg)
>  {
> -    PCIDevice *pdev = &vdev->pdev;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>      VFIOUserProxy *proxy = vdev->vbasedev.proxy;
>      MemTxResult r;
>  

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



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

* Re: [PATCH 21/22] s390x/s390-pci-vfio.c: use QOM casts where appropriate
  2025-07-15  9:26 ` [PATCH 21/22] s390x/s390-pci-vfio.c: " Mark Cave-Ayland
  2025-07-15 13:29   ` Eric Farman
@ 2025-07-15 14:19   ` Matthew Rosato
  1 sibling, 0 replies; 73+ messages in thread
From: Matthew Rosato @ 2025-07-15 14:19 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 5:26 AM, Mark Cave-Ayland wrote:
> Use QOM casts to cast to VFIOPCIDevice instead of using container_of().
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/s390x/s390-pci-vfio.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com>


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

* Re: [PATCH 00/22] vfio: improve use of QOM and coding guidelines
  2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
                   ` (21 preceding siblings ...)
  2025-07-15  9:26 ` [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj Mark Cave-Ayland
@ 2025-07-15 14:31 ` Cédric Le Goater
  22 siblings, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-07-15 14:31 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> This series attempts to improve use of QOM within the vfio subsystem which
> appears to have been added at a later date. It's mostly mechanical changes
> that do the following:
> 
>    1) Format the QOM structs per our coding guidelines
> 
>    2) Ensure the parent object is called parent_obj
> 
>    3) Use QOM casts to access the parent object, instead of accessing
>       the parent struct member directly
> 
> The benefits of this are that the QOM casts included type checking to help
> ensure the right object is being passed into the cast, and it also becomes
> much easier to infer the class hierarchy from reading the code.
> 
> Having produced this series, it feels to me that the readability could be
> further improved by renaming the structs as follows:
> 
>     VFIOContainer     -> VFIOLegacyContainer
>     VFIOContainerBase -> VFIOContainer

Yes.

> However I have left this for now given how close that we are to freeze.

I think this is too much of a change to QEMU 10.1 too. Let's keep it
as the first QEMU 10.2 series. Feel free to extend it.

Thanks,

C.


> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> 
> 
> Mark Cave-Ayland (22):
>    vfio/vfio-container-base.h: update VFIOContainerBase declaration
>    vfio/vfio-container.h: update VFIOContainer declaration
>    hw/vfio/cpr-legacy.c: use QOM casts where appropriate
>    hw/vfio/container.c: use QOM casts where appropriate
>    ppc/spapr_pci_vfio.c: use QOM casts where appropriate
>    vfio/spapr.c: use QOM casts where appropriate
>    vfio/vfio-container.h: rename VFIOContainer bcontainer field to
>      parent_obj
>    vfio-user/container.h: update VFIOUserContainer declaration
>    vfio/container.c: use QOM casts where appropriate
>    vfio-user/container.h: rename VFIOUserContainer bcontainer field to
>      parent_obj
>    vfio-user/pci.c: update VFIOUserPCIDevice declaration
>    vfio-user/pci.c: use QOM casts where appropriate
>    vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj
>    vfio/pci.h: update VFIOPCIDevice declaration
>    vfio/pci.h: use QOM casts where appropriate
>    vfio/pci.c: use QOM casts where appropriate
>    vfio/pci-quirks.c: use QOM casts where appropriate
>    vfio/cpr.c: use QOM casts where appropriate
>    vfio/igd.c: use QOM casts where appropriate
>    vfio-user/pci.c: use QOM casts where appropriate
>    s390x/s390-pci-vfio.c: use QOM casts where appropriate
>    vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj
> 
>   hw/ppc/spapr_pci_vfio.c               |   2 +-
>   hw/s390x/s390-pci-vfio.c              |  14 +-
>   hw/vfio-user/container.c              |  26 ++--
>   hw/vfio-user/container.h              |   7 +-
>   hw/vfio-user/pci.c                    |  16 +-
>   hw/vfio/container.c                   |  31 ++--
>   hw/vfio/cpr-legacy.c                  |  14 +-
>   hw/vfio/cpr.c                         |  10 +-
>   hw/vfio/igd.c                         |  38 ++---
>   hw/vfio/pci-quirks.c                  |  48 +++---
>   hw/vfio/pci.c                         | 206 +++++++++++++++-----------
>   hw/vfio/pci.h                         |   5 +-
>   hw/vfio/spapr.c                       |  16 +-
>   include/hw/vfio/vfio-container-base.h |  13 +-
>   include/hw/vfio/vfio-container.h      |   7 +-
>   15 files changed, 249 insertions(+), 204 deletions(-)
> 



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

* Re: [PATCH 05/22] ppc/spapr_pci_vfio.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 05/22] ppc/spapr_pci_vfio.c: " Mark Cave-Ayland
@ 2025-07-16  7:58   ` Harsh Prateek Bora
  2025-08-11 12:19   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Harsh Prateek Bora @ 2025-07-16  7:58 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel



On 7/15/25 14:55, Mark Cave-Ayland wrote:
> Use a QOM cast to convert to VFIOContainer instead of accessing bcontainer
> directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

> ---
>   hw/ppc/spapr_pci_vfio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
> index e318d0d912..7e1c71ef59 100644
> --- a/hw/ppc/spapr_pci_vfio.c
> +++ b/hw/ppc/spapr_pci_vfio.c
> @@ -106,7 +106,7 @@ static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
>   
>   out:
>       vfio_address_space_put(space);
> -    return container_of(bcontainer, VFIOContainer, bcontainer);
> +    return VFIO_IOMMU_LEGACY(bcontainer);
>   }
>   
>   static bool vfio_eeh_as_ok(AddressSpace *as)


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

* Re: [PATCH 06/22] vfio/spapr.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 06/22] vfio/spapr.c: " Mark Cave-Ayland
@ 2025-07-16  8:01   ` Harsh Prateek Bora
  2025-08-11 12:20   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Harsh Prateek Bora @ 2025-07-16  8:01 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel



On 7/15/25 14:55, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

> ---
>   hw/vfio/spapr.c | 16 ++++++----------
>   1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index 564b70ef97..c41e4588d6 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -62,7 +62,7 @@ static void vfio_prereg_listener_region_add(MemoryListener *listener,
>       VFIOSpaprContainer *scontainer = container_of(listener, VFIOSpaprContainer,
>                                                     prereg_listener);
>       VFIOContainer *container = &scontainer->container;
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       const hwaddr gpa = section->offset_within_address_space;
>       hwaddr end;
>       int ret;
> @@ -244,7 +244,7 @@ static bool vfio_spapr_create_window(VFIOContainer *container,
>                                       hwaddr *pgsize, Error **errp)
>   {
>       int ret = 0;
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
> @@ -352,8 +352,7 @@ vfio_spapr_container_add_section_window(VFIOContainerBase *bcontainer,
>                                           MemoryRegionSection *section,
>                                           Error **errp)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       VFIOHostDMAWindow *hostwin;
> @@ -443,8 +442,7 @@ static void
>   vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
>                                           MemoryRegionSection *section)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>   
> @@ -465,8 +463,7 @@ vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
>   
>   static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       VFIOHostDMAWindow *hostwin, *next;
> @@ -484,8 +481,7 @@ static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
>   static bool vfio_spapr_container_setup(VFIOContainerBase *bcontainer,
>                                          Error **errp)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       struct vfio_iommu_spapr_tce_info info;


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

* Re: [PATCH 19/22] vfio/igd.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 19/22] vfio/igd.c: " Mark Cave-Ayland
@ 2025-07-18 15:26   ` Tomita Moeko
  0 siblings, 0 replies; 73+ messages in thread
From: Tomita Moeko @ 2025-07-18 15:26 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, clg, steven.sistare,
	qemu-ppc, qemu-s390x, qemu-devel

On 7/15/2025 5:25 PM, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
> accessing pdev directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> ---
>  hw/vfio/igd.c | 38 +++++++++++++++++++++-----------------
>  1 file changed, 21 insertions(+), 17 deletions(-)
> 
> diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
> index e7a9d1ffc1..d3ffbe7db6 100644
> --- a/hw/vfio/igd.c
> +++ b/hw/vfio/igd.c
> @@ -199,7 +199,7 @@ static bool vfio_pci_igd_opregion_detect(VFIOPCIDevice *vdev,
>      }
>  
>      /* Hotplugging is not supported for opregion access */
> -    if (vdev->pdev.qdev.hotplugged) {
> +    if (DEVICE(vdev)->hotplugged) {
>          warn_report("IGD device detected, but OpRegion is not supported "
>                      "on hotplugged device.");
>          return false;
> @@ -259,11 +259,12 @@ static int vfio_pci_igd_copy(VFIOPCIDevice *vdev, PCIDevice *pdev,
>  static int vfio_pci_igd_host_init(VFIOPCIDevice *vdev,
>                                    struct vfio_region_info *info)
>  {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>      PCIBus *bus;
>      PCIDevice *host_bridge;
>      int ret;
>  
> -    bus = pci_device_root_bus(&vdev->pdev);
> +    bus = pci_device_root_bus(pdev);
>      host_bridge = pci_find_device(bus, 0, PCI_DEVFN(0, 0));
>  
>      if (!host_bridge) {
> @@ -326,13 +327,14 @@ type_init(vfio_pci_igd_register_types)
>  static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev,
>                                   struct vfio_region_info *info)
>  {
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>      PCIDevice *lpc_bridge;
>      int ret;
>  
> -    lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
> +    lpc_bridge = pci_find_device(pci_device_root_bus(pdev),
>                                   0, PCI_DEVFN(0x1f, 0));
>      if (!lpc_bridge) {
> -        lpc_bridge = pci_create_simple(pci_device_root_bus(&vdev->pdev),
> +        lpc_bridge = pci_create_simple(pci_device_root_bus(pdev),
>                                   PCI_DEVFN(0x1f, 0), "vfio-pci-igd-lpc-bridge");
>      }
>  
> @@ -349,13 +351,14 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
>  {
>      struct vfio_region_info *host = NULL;
>      struct vfio_region_info *lpc = NULL;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>      PCIDevice *lpc_bridge;
>      int ret;
>  
>      /*
>       * Copying IDs or creating new devices are not supported on hotplug
>       */
> -    if (vdev->pdev.qdev.hotplugged) {
> +    if (DEVICE(vdev)->hotplugged) {
>          error_setg(errp, "IGD LPC is not supported on hotplugged device");
>          return false;
>      }
> @@ -365,7 +368,7 @@ static bool vfio_pci_igd_setup_lpc_bridge(VFIOPCIDevice *vdev, Error **errp)
>       * can stuff host values into, so if there's already one there and it's not
>       * one we can hack on, this quirk is no-go.  Sorry Q35.
>       */
> -    lpc_bridge = pci_find_device(pci_device_root_bus(&vdev->pdev),
> +    lpc_bridge = pci_find_device(pci_device_root_bus(pdev),
>                                   0, PCI_DEVFN(0x1f, 0));
>      if (lpc_bridge && !object_dynamic_cast(OBJECT(lpc_bridge),
>                                             "vfio-pci-igd-lpc-bridge")) {
> @@ -509,6 +512,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
>  static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
>  {
>      struct vfio_region_info *opregion = NULL;
> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>      int ret, gen;
>      uint64_t gms_size = 0;
>      uint64_t *bdsm_size;
> @@ -528,7 +532,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
>      info_report("OpRegion detected on Intel display %x.", vdev->device_id);
>  
>      gen = igd_gen(vdev);
> -    gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, 4);
> +    gmch = vfio_pci_read_config(pdev, IGD_GMCH, 4);
>  
>      /*
>       * For backward compatibility, enable legacy mode when
> @@ -540,7 +544,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
>      if ((vdev->igd_legacy_mode != ON_OFF_AUTO_OFF) &&
>          (gen >= 6 && gen <= 9) &&
>          !strcmp(MACHINE_GET_CLASS(qdev_get_machine())->family, "pc_piix") &&
> -        (&vdev->pdev == pci_find_device(pci_device_root_bus(&vdev->pdev),
> +        (pdev == pci_find_device(pci_device_root_bus(pdev),
>          0, PCI_DEVFN(0x2, 0)))) {
>          /*
>           * IGD legacy mode requires:
> @@ -562,7 +566,7 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
>           */
>          ret = vfio_device_get_region_info(&vdev->vbasedev,
>                                            VFIO_PCI_ROM_REGION_INDEX, &rom);
> -        if ((ret || !rom->size) && !vdev->pdev.romfile) {
> +        if ((ret || !rom->size) && !pdev->romfile) {
>              error_setg(&err, "Device has no ROM");
>              goto error;
>          }
> @@ -605,8 +609,8 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
>       * ASLS (OpRegion address) is read-only, emulated
>       * It contains HPA, guest firmware need to reprogram it with GPA.
>       */
> -    pci_set_long(vdev->pdev.config + IGD_ASLS, 0);
> -    pci_set_long(vdev->pdev.wmask + IGD_ASLS, ~0);
> +    pci_set_long(pdev->config + IGD_ASLS, 0);
> +    pci_set_long(pdev->wmask + IGD_ASLS, ~0);
>      pci_set_long(vdev->emulated_config_bits + IGD_ASLS, ~0);
>  
>      /*
> @@ -620,8 +624,8 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
>          }
>  
>          /* GMCH is read-only, emulated */
> -        pci_set_long(vdev->pdev.config + IGD_GMCH, gmch);
> -        pci_set_long(vdev->pdev.wmask + IGD_GMCH, 0);
> +        pci_set_long(pdev->config + IGD_GMCH, gmch);
> +        pci_set_long(pdev->wmask + IGD_GMCH, 0);
>          pci_set_long(vdev->emulated_config_bits + IGD_GMCH, ~0);
>      }
>  
> @@ -630,12 +634,12 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
>  
>          /* BDSM is read-write, emulated. BIOS needs to be able to write it */
>          if (gen < 11) {
> -            pci_set_long(vdev->pdev.config + IGD_BDSM, 0);
> -            pci_set_long(vdev->pdev.wmask + IGD_BDSM, ~0);
> +            pci_set_long(pdev->config + IGD_BDSM, 0);
> +            pci_set_long(pdev->wmask + IGD_BDSM, ~0);
>              pci_set_long(vdev->emulated_config_bits + IGD_BDSM, ~0);
>          } else {
> -            pci_set_quad(vdev->pdev.config + IGD_BDSM_GEN11, 0);
> -            pci_set_quad(vdev->pdev.wmask + IGD_BDSM_GEN11, ~0);
> +            pci_set_quad(pdev->config + IGD_BDSM_GEN11, 0);
> +            pci_set_quad(pdev->wmask + IGD_BDSM_GEN11, ~0);
>              pci_set_quad(vdev->emulated_config_bits + IGD_BDSM_GEN11, ~0);
>          }
>      }

Reviewed-by: Tomita Moeko <tomitamoeko@gmail.com>



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

* Re: [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration
  2025-07-15  9:25 ` [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration Mark Cave-Ayland
@ 2025-08-11 11:45   ` Cédric Le Goater
  2025-08-11 11:56   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 11:45 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOContainerBase declaration to match our current coding
> guidelines: remove the explicit typedef (this is already handled by the
> OBJECT_DECLARE_TYPE() macro), add a blank line after the parent object,
> rename parent to parent_obj, and move the macro declaration next to the
> VFIOContainerBase struct declaration.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   include/hw/vfio/vfio-container-base.h | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
> index bded6e993f..acbd48a18a 100644
> --- a/include/hw/vfio/vfio-container-base.h
> +++ b/include/hw/vfio/vfio-container-base.h
> @@ -33,8 +33,9 @@ typedef struct VFIOAddressSpace {
>   /*
>    * This is the base object for vfio container backends
>    */
> -typedef struct VFIOContainerBase {
> -    Object parent;
> +struct VFIOContainerBase {
> +    Object parent_obj;
> +
>       VFIOAddressSpace *space;
>       MemoryListener listener;
>       Error *error;
> @@ -51,7 +52,10 @@ typedef struct VFIOContainerBase {
>       QLIST_HEAD(, VFIODevice) device_list;
>       GList *iova_ranges;
>       NotifierWithReturn cpr_reboot_notifier;
> -} VFIOContainerBase;
> +};
> +
> +#define TYPE_VFIO_IOMMU "vfio-iommu"
> +OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass, VFIO_IOMMU)
>   
>   typedef struct VFIOGuestIOMMU {
>       VFIOContainerBase *bcontainer;
> @@ -105,14 +109,11 @@ vfio_container_get_page_size_mask(const VFIOContainerBase *bcontainer)
>       return bcontainer->pgsizes;
>   }
>   
> -#define TYPE_VFIO_IOMMU "vfio-iommu"
>   #define TYPE_VFIO_IOMMU_LEGACY TYPE_VFIO_IOMMU "-legacy"
>   #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
>   #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
>   #define TYPE_VFIO_IOMMU_USER TYPE_VFIO_IOMMU "-user"
>   
> -OBJECT_DECLARE_TYPE(VFIOContainerBase, VFIOIOMMUClass, VFIO_IOMMU)
> -
>   struct VFIOIOMMUClass {
>       ObjectClass parent_class;
>   



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

* Re: [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration
  2025-07-15  9:25 ` [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration Mark Cave-Ayland
  2025-07-15  9:39   ` Philippe Mathieu-Daudé
@ 2025-08-11 11:45   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 11:45 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOContainer declaration so that it is closer to our coding
> guidelines: emove the explicit typedef (this is already handled by the
> OBJECT_DECLARE_TYPE() macro) and add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   include/hw/vfio/vfio-container.h | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-container.h
> index 21e5807e48..50c91788d5 100644
> --- a/include/hw/vfio/vfio-container.h
> +++ b/include/hw/vfio/vfio-container.h
> @@ -25,13 +25,14 @@ typedef struct VFIOGroup {
>       bool ram_block_discard_allowed;
>   } VFIOGroup;
>   
> -typedef struct VFIOContainer {
> +struct VFIOContainer {
>       VFIOContainerBase bcontainer;
> +
>       int fd; /* /dev/vfio/vfio, empowered by the attached groups */
>       unsigned iommu_type;
>       QLIST_HEAD(, VFIOGroup) group_list;
>       VFIOContainerCPR cpr;
> -} VFIOContainer;
> +};
>   
>   OBJECT_DECLARE_SIMPLE_TYPE(VFIOContainer, VFIO_IOMMU_LEGACY);
>   



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

* Re: [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate Mark Cave-Ayland
  2025-07-15 12:36   ` Steven Sistare
@ 2025-08-11 11:45   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 11:45 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio/cpr-legacy.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c
> index 553b203e9b..8f437194fa 100644
> --- a/hw/vfio/cpr-legacy.c
> +++ b/hw/vfio/cpr-legacy.c
> @@ -41,8 +41,8 @@ static int vfio_legacy_cpr_dma_map(const VFIOContainerBase *bcontainer,
>                                      hwaddr iova, ram_addr_t size, void *vaddr,
>                                      bool readonly, MemoryRegion *mr)
>   {
> -    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                                  bcontainer);
> +    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
> +
>       struct vfio_iommu_type1_dma_map map = {
>           .argsz = sizeof(map),
>           .flags = VFIO_DMA_MAP_FLAG_VADDR,
> @@ -65,7 +65,7 @@ static void vfio_region_remap(MemoryListener *listener,
>   {
>       VFIOContainer *container = container_of(listener, VFIOContainer,
>                                               cpr.remap_listener);
> -    vfio_container_region_add(&container->bcontainer, section, true);
> +    vfio_container_region_add(VFIO_IOMMU(container), section, true);
>   }
>   
>   static bool vfio_cpr_supported(VFIOContainer *container, Error **errp)
> @@ -98,7 +98,7 @@ static int vfio_container_pre_save(void *opaque)
>   static int vfio_container_post_load(void *opaque, int version_id)
>   {
>       VFIOContainer *container = opaque;
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
>       dma_map_fn saved_dma_map = vioc->dma_map;
>       Error *local_err = NULL;
> @@ -135,7 +135,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *notifier,
>   {
>       VFIOContainer *container =
>           container_of(notifier, VFIOContainer, cpr.transfer_notifier);
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>   
>       if (e->type != MIG_EVENT_PRECOPY_FAILED) {
>           return 0;
> @@ -167,7 +167,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *notifier,
>   
>   bool vfio_legacy_cpr_register_container(VFIOContainer *container, Error **errp)
>   {
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       Error **cpr_blocker = &container->cpr.blocker;
>   
>       migration_add_notifier_mode(&bcontainer->cpr_reboot_notifier,
> @@ -191,7 +191,7 @@ bool vfio_legacy_cpr_register_container(VFIOContainer *container, Error **errp)
>   
>   void vfio_legacy_cpr_unregister_container(VFIOContainer *container)
>   {
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>   
>       migration_remove_notifier(&bcontainer->cpr_reboot_notifier);
>       migrate_del_blocker(&container->cpr.blocker);



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

* Re: [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration
  2025-07-15  9:25 ` [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration Mark Cave-Ayland
  2025-08-11 11:45   ` Cédric Le Goater
@ 2025-08-11 11:56   ` Cédric Le Goater
  2025-08-29 11:10     ` Mark Cave-Ayland
  1 sibling, 1 reply; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 11:56 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

One more thing we could do :

> @@ -105,14 +109,11 @@ vfio_container_get_page_size_mask(const VFIOContainerBase *bcontainer)
>       return bcontainer->pgsizes;
>   }
>   
> -#define TYPE_VFIO_IOMMU "vfio-iommu"
>   #define TYPE_VFIO_IOMMU_LEGACY TYPE_VFIO_IOMMU "-legacy"
>   #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
>   #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
>   #define TYPE_VFIO_IOMMU_USER TYPE_VFIO_IOMMU "-user"

These type definitions would be better placed in the header files
defining the other software structures to which they relate.

   TYPE_VFIO_IOMMU_LEGACY  -> hw/vfio/vfio-container.h
   TYPE_VFIO_IOMMU_SPAPR   -> hw/vfio/vfio-container.h ?
   TYPE_VFIO_IOMMU_IOMMUFD -> hw/vfio/vfio-iommufd.h
   TYPE_VFIO_IOMMU_USER    -> hw/vfio-user/container.h

I don't know how possible that would be.

Thanks,

C.



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

* Re: [PATCH 05/22] ppc/spapr_pci_vfio.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 05/22] ppc/spapr_pci_vfio.c: " Mark Cave-Ayland
  2025-07-16  7:58   ` Harsh Prateek Bora
@ 2025-08-11 12:19   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:19 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Use a QOM cast to convert to VFIOContainer instead of accessing bcontainer
> directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/ppc/spapr_pci_vfio.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c
> index e318d0d912..7e1c71ef59 100644
> --- a/hw/ppc/spapr_pci_vfio.c
> +++ b/hw/ppc/spapr_pci_vfio.c
> @@ -106,7 +106,7 @@ static VFIOContainer *vfio_eeh_as_container(AddressSpace *as)
>   
>   out:
>       vfio_address_space_put(space);
> -    return container_of(bcontainer, VFIOContainer, bcontainer);
> +    return VFIO_IOMMU_LEGACY(bcontainer);
>   }
>   
>   static bool vfio_eeh_as_ok(AddressSpace *as)



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

* Re: [PATCH 04/22] hw/vfio/container.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 04/22] hw/vfio/container.c: " Mark Cave-Ayland
@ 2025-08-11 12:19   ` Cédric Le Goater
  0 siblings, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:19 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio/container.c | 31 +++++++++++++------------------
>   1 file changed, 13 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/vfio/container.c b/hw/vfio/container.c
> index 3e13feaa74..f4337741b3 100644
> --- a/hw/vfio/container.c
> +++ b/hw/vfio/container.c
> @@ -71,7 +71,7 @@ static int vfio_dma_unmap_bitmap(const VFIOContainer *container,
>                                    hwaddr iova, ram_addr_t size,
>                                    IOMMUTLBEntry *iotlb)
>   {
> -    const VFIOContainerBase *bcontainer = &container->bcontainer;
> +    const VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       struct vfio_iommu_type1_dma_unmap *unmap;
>       struct vfio_bitmap *bitmap;
>       VFIOBitmap vbmap;
> @@ -124,8 +124,7 @@ static int vfio_legacy_dma_unmap_one(const VFIOContainerBase *bcontainer,
>                                        hwaddr iova, ram_addr_t size,
>                                        IOMMUTLBEntry *iotlb)
>   {
> -    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                                  bcontainer);
> +    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       struct vfio_iommu_type1_dma_unmap unmap = {
>           .argsz = sizeof(unmap),
>           .flags = 0,
> @@ -213,8 +212,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
>                                  ram_addr_t size, void *vaddr, bool readonly,
>                                  MemoryRegion *mr)
>   {
> -    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                                  bcontainer);
> +    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       struct vfio_iommu_type1_dma_map map = {
>           .argsz = sizeof(map),
>           .flags = VFIO_DMA_MAP_FLAG_READ,
> @@ -246,8 +244,7 @@ static int
>   vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer,
>                                       bool start, Error **errp)
>   {
> -    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                                  bcontainer);
> +    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       int ret;
>       struct vfio_iommu_type1_dirty_bitmap dirty = {
>           .argsz = sizeof(dirty),
> @@ -272,8 +269,7 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer,
>   static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>                         VFIOBitmap *vbmap, hwaddr iova, hwaddr size, Error **errp)
>   {
> -    const VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                                  bcontainer);
> +    const VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       struct vfio_iommu_type1_dirty_bitmap *dbitmap;
>       struct vfio_iommu_type1_dirty_bitmap_get *range;
>       int ret;
> @@ -495,7 +491,7 @@ static void vfio_get_iommu_info_migration(VFIOContainer *container,
>   {
>       struct vfio_info_cap_header *hdr;
>       struct vfio_iommu_type1_info_cap_migration *cap_mig;
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>   
>       hdr = vfio_get_iommu_info_cap(info, VFIO_IOMMU_TYPE1_INFO_CAP_MIGRATION);
>       if (!hdr) {
> @@ -518,8 +514,7 @@ static void vfio_get_iommu_info_migration(VFIOContainer *container,
>   
>   static bool vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       g_autofree struct vfio_iommu_type1_info *info = NULL;
>       int ret;
>   
> @@ -634,7 +629,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
>   
>       if (!cpr_is_incoming()) {
>           QLIST_FOREACH(bcontainer, &space->containers, next) {
> -            container = container_of(bcontainer, VFIOContainer, bcontainer);
> +            container = VFIO_IOMMU_LEGACY(bcontainer);
>               if (!ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &container->fd)) {
>                   return vfio_container_group_add(container, group, errp);
>               }
> @@ -652,7 +647,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
>            * create the container struct and group list.
>            */
>           QLIST_FOREACH(bcontainer, &space->containers, next) {
> -            container = container_of(bcontainer, VFIOContainer, bcontainer);
> +            container = VFIO_IOMMU_LEGACY(bcontainer);
>   
>               if (vfio_cpr_container_match(container, group, fd)) {
>                   return vfio_container_group_add(container, group, errp);
> @@ -672,7 +667,7 @@ static bool vfio_container_connect(VFIOGroup *group, AddressSpace *as,
>           goto fail;
>       }
>       new_container = true;
> -    bcontainer = &container->bcontainer;
> +    bcontainer = VFIO_IOMMU(container);
>   
>       if (!vfio_legacy_cpr_register_container(container, errp)) {
>           goto fail;
> @@ -735,7 +730,7 @@ fail:
>   static void vfio_container_disconnect(VFIOGroup *group)
>   {
>       VFIOContainer *container = group->container;
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
>   
>       QLIST_REMOVE(group, container_next);
> @@ -781,7 +776,7 @@ static VFIOGroup *vfio_group_get(int groupid, AddressSpace *as, Error **errp)
>       QLIST_FOREACH(group, &vfio_group_list, next) {
>           if (group->groupid == groupid) {
>               /* Found it.  Now is it already in the right context? */
> -            if (group->container->bcontainer.space->as == as) {
> +            if (VFIO_IOMMU(group->container)->space->as == as) {
>                   return group;
>               } else {
>                   error_setg(errp, "group %d used in multiple address spaces",
> @@ -895,7 +890,7 @@ static bool vfio_device_get(VFIOGroup *group, const char *name,
>           }
>       }
>   
> -    vfio_device_prepare(vbasedev, &group->container->bcontainer, info);
> +    vfio_device_prepare(vbasedev, VFIO_IOMMU(group->container), info);
>   
>       vbasedev->fd = fd;
>       vbasedev->group = group;



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

* Re: [PATCH 06/22] vfio/spapr.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 06/22] vfio/spapr.c: " Mark Cave-Ayland
  2025-07-16  8:01   ` Harsh Prateek Bora
@ 2025-08-11 12:20   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:20 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>



Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio/spapr.c | 16 ++++++----------
>   1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index 564b70ef97..c41e4588d6 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -62,7 +62,7 @@ static void vfio_prereg_listener_region_add(MemoryListener *listener,
>       VFIOSpaprContainer *scontainer = container_of(listener, VFIOSpaprContainer,
>                                                     prereg_listener);
>       VFIOContainer *container = &scontainer->container;
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       const hwaddr gpa = section->offset_within_address_space;
>       hwaddr end;
>       int ret;
> @@ -244,7 +244,7 @@ static bool vfio_spapr_create_window(VFIOContainer *container,
>                                       hwaddr *pgsize, Error **errp)
>   {
>       int ret = 0;
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
> @@ -352,8 +352,7 @@ vfio_spapr_container_add_section_window(VFIOContainerBase *bcontainer,
>                                           MemoryRegionSection *section,
>                                           Error **errp)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       VFIOHostDMAWindow *hostwin;
> @@ -443,8 +442,7 @@ static void
>   vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
>                                           MemoryRegionSection *section)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>   
> @@ -465,8 +463,7 @@ vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
>   
>   static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       VFIOHostDMAWindow *hostwin, *next;
> @@ -484,8 +481,7 @@ static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
>   static bool vfio_spapr_container_setup(VFIOContainerBase *bcontainer,
>                                          Error **errp)
>   {
> -    VFIOContainer *container = container_of(bcontainer, VFIOContainer,
> -                                            bcontainer);
> +    VFIOContainer *container = VFIO_IOMMU_LEGACY(bcontainer);
>       VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
>                                                     container);
>       struct vfio_iommu_spapr_tce_info info;



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

* Re: [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj
  2025-07-15  9:25 ` [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj Mark Cave-Ayland
  2025-07-15  9:39   ` Philippe Mathieu-Daudé
@ 2025-08-11 12:23   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:23 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Now that nothing accesses the bcontainer field directly, rename bcontainer to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   include/hw/vfio/vfio-container.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-container.h
> index 50c91788d5..240f566993 100644
> --- a/include/hw/vfio/vfio-container.h
> +++ b/include/hw/vfio/vfio-container.h
> @@ -26,7 +26,7 @@ typedef struct VFIOGroup {
>   } VFIOGroup;
>   
>   struct VFIOContainer {
> -    VFIOContainerBase bcontainer;
> +    VFIOContainerBase parent_obj;
>   
>       int fd; /* /dev/vfio/vfio, empowered by the attached groups */
>       unsigned iommu_type;



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

* Re: [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration
  2025-07-15  9:25 ` [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration Mark Cave-Ayland
  2025-07-15  9:39   ` Philippe Mathieu-Daudé
  2025-07-15 12:57   ` John Levon
@ 2025-08-11 12:23   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:23 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOUserContainer declaration so that it is closer to our coding
> guidelines: remove the explicit typedef (this is already handled by the
> OBJECT_DECLARE_TYPE() macro) and add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio-user/container.h | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/vfio-user/container.h b/hw/vfio-user/container.h
> index 2bb1fa1343..d5d2275af7 100644
> --- a/hw/vfio-user/container.h
> +++ b/hw/vfio-user/container.h
> @@ -13,10 +13,11 @@
>   #include "hw/vfio-user/proxy.h"
>   
>   /* MMU container sub-class for vfio-user. */
> -typedef struct VFIOUserContainer {
> +struct VFIOUserContainer {
>       VFIOContainerBase bcontainer;
> +
>       VFIOUserProxy *proxy;
> -} VFIOUserContainer;
> +};
>   
>   OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserContainer, VFIO_IOMMU_USER);
>   



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

* Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
  2025-07-15  9:25 ` [PATCH 09/22] vfio/container.c: use QOM casts where appropriate Mark Cave-Ayland
  2025-07-15 14:13   ` John Levon
@ 2025-08-11 12:23   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:23 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio-user/container.c | 26 +++++++++++---------------
>   1 file changed, 11 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
> index d318e6a339..025db93ff3 100644
> --- a/hw/vfio-user/container.c
> +++ b/hw/vfio-user/container.c
> @@ -24,16 +24,14 @@
>    */
>   static void vfio_user_listener_begin(VFIOContainerBase *bcontainer)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                                 bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>   
>       container->proxy->async_ops = true;
>   }
>   
>   static void vfio_user_listener_commit(VFIOContainerBase *bcontainer)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                            bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>   
>       /* wait here for any async requests sent during the transaction */
>       container->proxy->async_ops = false;
> @@ -44,8 +42,8 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
>                                  hwaddr iova, ram_addr_t size,
>                                  IOMMUTLBEntry *iotlb, bool unmap_all)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                            bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
> +
>       Error *local_err = NULL;
>       int ret = 0;
>   
> @@ -88,8 +86,8 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
>                                ram_addr_t size, void *vaddr, bool readonly,
>                                MemoryRegion *mrp)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                                bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
> +
>       int fd = memory_region_get_fd(mrp);
>       Error *local_err = NULL;
>       int ret;
> @@ -177,8 +175,7 @@ static int vfio_user_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>   
>   static bool vfio_user_setup(VFIOContainerBase *bcontainer, Error **errp)
>   {
> -    VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> -                                                bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>   
>       assert(container->proxy->dma_pgsizes != 0);
>       bcontainer->pgsizes = container->proxy->dma_pgsizes;
> @@ -222,7 +219,7 @@ vfio_user_container_connect(AddressSpace *as, VFIODevice *vbasedev,
>           goto put_space_exit;
>       }
>   
> -    bcontainer = &container->bcontainer;
> +    bcontainer = VFIO_IOMMU(container);
>   
>       ret = ram_block_uncoordinated_discard_disable(true);
>       if (ret) {
> @@ -267,7 +264,7 @@ put_space_exit:
>   
>   static void vfio_user_container_disconnect(VFIOUserContainer *container)
>   {
> -    VFIOContainerBase *bcontainer = &container->bcontainer;
> +    VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
>       VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
>       VFIOAddressSpace *space = bcontainer->space;
>   
> @@ -295,7 +292,7 @@ static bool vfio_user_device_get(VFIOUserContainer *container,
>   
>       vbasedev->fd = -1;
>   
> -    vfio_device_prepare(vbasedev, &container->bcontainer, &info);
> +    vfio_device_prepare(vbasedev, VFIO_IOMMU(container), &info);
>   
>       return true;
>   }
> @@ -319,8 +316,7 @@ static bool vfio_user_device_attach(const char *name, VFIODevice *vbasedev,
>   
>   static void vfio_user_device_detach(VFIODevice *vbasedev)
>   {
> -    VFIOUserContainer *container = container_of(vbasedev->bcontainer,
> -                                                VFIOUserContainer, bcontainer);
> +    VFIOUserContainer *container = VFIO_IOMMU_USER(vbasedev->bcontainer);
>   
>       vfio_device_unprepare(vbasedev);
>   



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

* Re: [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj
  2025-07-15  9:25 ` [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj Mark Cave-Ayland
  2025-07-15  9:41   ` Philippe Mathieu-Daudé
  2025-07-15 14:13   ` John Levon
@ 2025-08-11 12:23   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:23 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Now that nothing accesses the bcontainer field directly, rename bcontainer to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio-user/container.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/vfio-user/container.h b/hw/vfio-user/container.h
> index d5d2275af7..96aa6785d9 100644
> --- a/hw/vfio-user/container.h
> +++ b/hw/vfio-user/container.h
> @@ -14,7 +14,7 @@
>   
>   /* MMU container sub-class for vfio-user. */
>   struct VFIOUserContainer {
> -    VFIOContainerBase bcontainer;
> +    VFIOContainerBase parent_obj;
>   
>       VFIOUserProxy *proxy;
>   };



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

* Re: [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration
  2025-07-15  9:25 ` [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration Mark Cave-Ayland
                     ` (2 preceding siblings ...)
  2025-07-15 14:15   ` John Levon
@ 2025-08-11 12:24   ` Cédric Le Goater
  3 siblings, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:24 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOUserPCIDevice declaration so that it is closer to our coding
> guidelines: add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio-user/pci.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index be71c77729..da6fe51809 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -21,6 +21,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
>   
>   struct VFIOUserPCIDevice {
>       VFIOPCIDevice device;
> +
>       SocketAddress *socket;
>       bool send_queued;   /* all sends are queued */
>       uint32_t wait_time; /* timeout for message replies */



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

* Re: [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj
  2025-07-15  9:25 ` [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj Mark Cave-Ayland
  2025-07-15  9:42   ` Philippe Mathieu-Daudé
  2025-07-15 14:15   ` John Levon
@ 2025-08-11 12:25   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:25 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Now that nothing accesses the device field directly, rename device to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio-user/pci.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index e23a941605..9380766548 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -20,7 +20,7 @@
>   OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
>   
>   struct VFIOUserPCIDevice {
> -    VFIOPCIDevice device;
> +    VFIOPCIDevice parent_obj;
>   
>       SocketAddress *socket;
>       bool send_queued;   /* all sends are queued */



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

* Re: [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration
  2025-07-15  9:25 ` [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration Mark Cave-Ayland
  2025-07-15  9:44   ` Philippe Mathieu-Daudé
@ 2025-08-11 12:25   ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:25 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Update the VFIOPCIDevice declaration so that it is closer to our coding
> guidelines: add a blank line after the parent object.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio/pci.h | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
> index 495fae737d..16f092a0c6 100644
> --- a/hw/vfio/pci.h
> +++ b/hw/vfio/pci.h
> @@ -132,6 +132,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
>   
>   struct VFIOPCIDevice {
>       PCIDevice pdev;
> +
>       VFIODevice vbasedev;
>       VFIOINTx intx;
>       unsigned int config_size;



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

* Re: [PATCH 16/22] vfio/pci.c: use QOM casts where appropriate
  2025-07-15 13:38   ` BALATON Zoltan
@ 2025-08-11 12:45     ` Cédric Le Goater
  2025-08-29 11:13       ` Mark Cave-Ayland
  2025-08-29 11:07     ` Mark Cave-Ayland
  1 sibling, 1 reply; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:45 UTC (permalink / raw)
  To: BALATON Zoltan, Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 15:38, BALATON Zoltan wrote:
> On Tue, 15 Jul 2025, Mark Cave-Ayland wrote:
>> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
>> accessing pdev directly.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>> ---
>> hw/vfio/pci.c | 202 ++++++++++++++++++++++++++++++--------------------
>> 1 file changed, 120 insertions(+), 82 deletions(-)
>>
>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> index 1093b28df7..fb9eb58da5 100644
>> --- a/hw/vfio/pci.c
>> +++ b/hw/vfio/pci.c
>> @@ -119,6 +119,7 @@ static void vfio_intx_mmap_enable(void *opaque)
>> static void vfio_intx_interrupt(void *opaque)
>> {
>>     VFIOPCIDevice *vdev = opaque;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> 
> Don't do that. Opaque data is already type checked when it is registered for the callback and cannot be changed so additional type checking here is just a performance hit without any advantage. It's OK to do it in less frequently called functions but don't add unnecessary casts to functions that can be called a lot.

This is true.

Any routines called before the first machine reset should fine
to be changed but anything called at runtime should be carefully
looked at.


Thanks,

C.




> 
> Regards,
> BALATON Zoltan
> 
>>     if (!event_notifier_test_and_clear(&vdev->intx.interrupt)) {
>>         return;
>> @@ -127,7 +128,7 @@ static void vfio_intx_interrupt(void *opaque)
>>     trace_vfio_intx_interrupt(vdev->vbasedev.name, 'A' + vdev->intx.pin);
>>
>>     vdev->intx.pending = true;
>> -    pci_irq_assert(&vdev->pdev);
>> +    pci_irq_assert(pdev);
>>     vfio_mmap_set_enabled(vdev, false);
>>     if (vdev->intx.mmap_timeout) {
>>         timer_mod(vdev->intx.mmap_timer,
>> @@ -138,6 +139,7 @@ static void vfio_intx_interrupt(void *opaque)
>> void vfio_pci_intx_eoi(VFIODevice *vbasedev)
>> {
>>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     if (!vdev->intx.pending) {
>>         return;
>> @@ -146,13 +148,14 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev)
>>     trace_vfio_pci_intx_eoi(vbasedev->name);
>>
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>     vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>> }
>>
>> static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
>> {
>> #ifdef CONFIG_KVM
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
>>
>>     if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
>> @@ -165,7 +168,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
>>     qemu_set_fd_handler(irq_fd, NULL, NULL, vdev);
>>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>
>>     /* Get an eventfd for resample/unmask */
>>     if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 0, errp)) {
>> @@ -243,6 +246,8 @@ static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
>> static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
>> {
>> #ifdef CONFIG_KVM
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>>     if (!vdev->intx.kvm_accel) {
>>         return;
>>     }
>> @@ -253,7 +258,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
>>      */
>>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>
>>     /* Tell KVM to stop listening for an INTx irqfd */
>>     if (kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.interrupt,
>> @@ -309,7 +314,7 @@ static void vfio_intx_routing_notifier(PCIDevice *pdev)
>>         return;
>>     }
>>
>> -    route = pci_device_route_intx_to_irq(&vdev->pdev, vdev->intx.pin);
>> +    route = pci_device_route_intx_to_irq(pdev, vdev->intx.pin);
>>
>>     if (pci_intx_route_changed(&vdev->intx.route, &route)) {
>>         vfio_intx_update(vdev, &route);
>> @@ -326,7 +331,8 @@ static void vfio_irqchip_change(Notifier *notify, void *data)
>>
>> static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    uint8_t pin = vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint8_t pin = vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1);
>>     Error *err = NULL;
>>     int32_t fd;
>>
>> @@ -344,7 +350,7 @@ 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);
>> +    pci_config_set_interrupt_pin(pdev->config, pin);
>>
>> #ifdef CONFIG_KVM
>>     /*
>> @@ -352,7 +358,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
>>      * where we won't actually use the result anyway.
>>      */
>>     if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) {
>> -        vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
>> +        vdev->intx.route = pci_device_route_intx_to_irq(pdev,
>>                                                         vdev->intx.pin);
>>     }
>> #endif
>> @@ -392,13 +398,14 @@ skip_signaling:
>>
>> static void vfio_intx_disable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int fd;
>>
>>     timer_del(vdev->intx.mmap_timer);
>>     vfio_intx_disable_kvm(vdev);
>>     vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>     vfio_mmap_set_enabled(vdev, true);
>>
>>     fd = event_notifier_get_fd(&vdev->intx.interrupt);
>> @@ -422,6 +429,7 @@ static void vfio_msi_interrupt(void *opaque)
>> {
>>     VFIOMSIVector *vector = opaque;
>>     VFIOPCIDevice *vdev = vector->vdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     MSIMessage (*get_msg)(PCIDevice *dev, unsigned vector);
>>     void (*notify)(PCIDevice *dev, unsigned vector);
>>     MSIMessage msg;
>> @@ -436,9 +444,9 @@ static void vfio_msi_interrupt(void *opaque)
>>         notify = msix_notify;
>>
>>         /* A masked vector firing needs to use the PBA, enable it */
>> -        if (msix_is_masked(&vdev->pdev, nr)) {
>> +        if (msix_is_masked(pdev, nr)) {
>>             set_bit(nr, vdev->msix->pending);
>> -            memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, true);
>> +            memory_region_set_enabled(&pdev->msix_pba_mmio, true);
>>             trace_vfio_msix_pba_enable(vdev->vbasedev.name);
>>         }
>>     } else if (vdev->interrupt == VFIO_INT_MSI) {
>> @@ -448,9 +456,9 @@ static void vfio_msi_interrupt(void *opaque)
>>         abort();
>>     }
>>
>> -    msg = get_msg(&vdev->pdev, nr);
>> +    msg = get_msg(pdev, nr);
>>     trace_vfio_msi_interrupt(vdev->vbasedev.name, nr, msg.address, msg.data);
>> -    notify(&vdev->pdev, nr);
>> +    notify(pdev, nr);
>> }
>>
>> void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr)
>> @@ -488,6 +496,7 @@ static int vfio_enable_msix_no_vec(VFIOPCIDevice *vdev)
>>
>> static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     struct vfio_irq_set *irq_set;
>>     int ret = 0, i, argsz;
>>     int32_t *fds;
>> @@ -530,7 +539,7 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
>>          */
>>         if (vdev->msi_vectors[i].use) {
>>             if (vdev->msi_vectors[i].virq < 0 ||
>> -                (msix && msix_is_masked(&vdev->pdev, i))) {
>> +                (msix && msix_is_masked(pdev, i))) {
>>                 fd = event_notifier_get_fd(&vdev->msi_vectors[i].interrupt);
>>             } else {
>>                 fd = event_notifier_get_fd(&vdev->msi_vectors[i].kvm_interrupt);
>> @@ -550,12 +559,14 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
>> void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector,
>>                                int vector_n, bool msix)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>>     if ((msix && vdev->no_kvm_msix) || (!msix && vdev->no_kvm_msi)) {
>>         return;
>>     }
>>
>>     vector->virq = kvm_irqchip_add_msi_route(&vfio_route_change,
>> -                                             vector_n, &vdev->pdev);
>> +                                             vector_n, pdev);
>> }
>>
>> static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector, int nr)
>> @@ -624,7 +635,7 @@ static void set_irq_signalling(VFIODevice *vbasedev, VFIOMSIVector *vector,
>> void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr)
>> {
>>     VFIOMSIVector *vector = &vdev->msi_vectors[nr];
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     Error *local_err = NULL;
>>
>>     vector->vdev = vdev;
>> @@ -713,7 +724,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
>>     clear_bit(nr, vdev->msix->pending);
>>     if (find_first_bit(vdev->msix->pending,
>>                        vdev->nr_vectors) == vdev->nr_vectors) {
>> -        memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
>> +        memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>>         trace_vfio_msix_pba_disable(vdev->vbasedev.name);
>>     }
>>
>> @@ -764,7 +775,9 @@ static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr)
>>
>> void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev)
>> {
>> -    msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>>                               vfio_msix_vector_release, NULL);
>> }
>>
>> @@ -791,6 +804,7 @@ void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev)
>>
>> static void vfio_msix_enable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int ret;
>>
>>     vfio_disable_interrupts(vdev);
>> @@ -807,7 +821,7 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>>      */
>>     vfio_pci_prepare_kvm_msi_virq_batch(vdev);
>>
>> -    if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
>> +    if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>>                                   vfio_msix_vector_release, NULL)) {
>>         error_report("vfio: msix_set_vector_notifiers failed");
>>     }
>> @@ -845,11 +859,12 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>>
>> static void vfio_msi_enable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int ret, i;
>>
>>     vfio_disable_interrupts(vdev);
>>
>> -    vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev);
>> +    vdev->nr_vectors = msi_nr_vectors_allocated(pdev);
>> retry:
>>     /*
>>      * Setting vector notifiers needs to enable route for each vector.
>> @@ -942,10 +957,11 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev)
>>
>> static void vfio_msix_disable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     Error *err = NULL;
>>     int i;
>>
>> -    msix_unset_vector_notifiers(&vdev->pdev);
>> +    msix_unset_vector_notifiers(pdev);
>>
>>     /*
>>      * MSI-X will only release vectors if MSI-X is still enabled on the
>> @@ -953,8 +969,8 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
>>      */
>>     for (i = 0; i < vdev->nr_vectors; i++) {
>>         if (vdev->msi_vectors[i].use) {
>> -            vfio_msix_vector_release(&vdev->pdev, i);
>> -            msix_vector_unuse(&vdev->pdev, i);
>> +            vfio_msix_vector_release(pdev, i);
>> +            msix_vector_unuse(pdev, i);
>>         }
>>     }
>>
>> @@ -991,6 +1007,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev)
>>
>> static void vfio_update_msi(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int i;
>>
>>     for (i = 0; i < vdev->nr_vectors; i++) {
>> @@ -1001,8 +1018,8 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
>>             continue;
>>         }
>>
>> -        msg = msi_get_message(&vdev->pdev, i);
>> -        vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev);
>> +        msg = msi_get_message(pdev, i);
>> +        vfio_update_kvm_msi_virq(vector, msg, pdev);
>>     }
>> }
>>
>> @@ -1164,13 +1181,14 @@ static const MemoryRegionOps vfio_rom_ops = {
>>
>> static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);
>>     char *name;
>>
>> -    if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
>> +    if (pdev->romfile || !pdev->rom_bar) {
>>         /* Since pci handles romfile, just print a message and return */
>> -        if (vfio_opt_rom_in_denylist(vdev) && vdev->pdev.romfile) {
>> +        if (vfio_opt_rom_in_denylist(vdev) && pdev->romfile) {
>>             warn_report("Device at %s is known to cause system instability"
>>                         " issues during option rom execution",
>>                         vdev->vbasedev.name);
>> @@ -1199,7 +1217,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>>     }
>>
>>     if (vfio_opt_rom_in_denylist(vdev)) {
>> -        if (vdev->pdev.rom_bar > 0) {
>> +        if (pdev->rom_bar > 0) {
>>             warn_report("Device at %s is known to cause system instability"
>>                         " issues during option rom execution",
>>                         vdev->vbasedev.name);
>> @@ -1218,12 +1236,12 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>>
>>     name = g_strdup_printf("vfio[%s].rom", vdev->vbasedev.name);
>>
>> -    memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),
>> +    memory_region_init_io(&pdev->rom, OBJECT(vdev),
>>                           &vfio_rom_ops, vdev, name, size);
>>     g_free(name);
>>
>> -    pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,
>> -                     PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);
>> +    pci_register_bar(pdev, PCI_ROM_SLOT,
>> +                     PCI_BASE_ADDRESS_SPACE_MEMORY, &pdev->rom);
>>
>>     vdev->rom_read_failed = false;
>> }
>> @@ -1496,6 +1514,7 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vdev)
>>
>> static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint16_t ctrl;
>>     bool msi_64bit, msi_maskbit;
>>     int ret, entries;
>> @@ -1516,7 +1535,7 @@ static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>>
>>     trace_vfio_msi_setup(vdev->vbasedev.name, pos);
>>
>> -    ret = msi_init(&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, &err);
>> +    ret = msi_init(pdev, pos, entries, msi_64bit, msi_maskbit, &err);
>>     if (ret < 0) {
>>         if (ret == -ENOTSUP) {
>>             return true;
>> @@ -1709,6 +1728,7 @@ static bool vfio_pci_relocate_msix(VFIOPCIDevice *vdev, Error **errp)
>>  */
>> static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint8_t pos;
>>     uint16_t ctrl;
>>     uint32_t table, pba;
>> @@ -1716,7 +1736,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>>     VFIOMSIXInfo *msix;
>>     int ret;
>>
>> -    pos = pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX);
>> +    pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
>>     if (!pos) {
>>         return true;
>>     }
>> @@ -1808,12 +1828,13 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>>
>> static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int ret;
>>     Error *err = NULL;
>>
>>     vdev->msix->pending = g_new0(unsigned long,
>>                                  BITS_TO_LONGS(vdev->msix->entries));
>> -    ret = msix_init(&vdev->pdev, vdev->msix->entries,
>> +    ret = msix_init(pdev, vdev->msix->entries,
>>                     vdev->bars[vdev->msix->table_bar].mr,
>>                     vdev->msix->table_bar, vdev->msix->table_offset,
>>                     vdev->bars[vdev->msix->pba_bar].mr,
>> @@ -1845,7 +1866,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>>      * vector-use notifier is called, which occurs on unmask, we test whether
>>      * PBA emulation is needed and again disable if not.
>>      */
>> -    memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
>> +    memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>>
>>     /*
>>      * The emulated machine may provide a paravirt interface for MSIX setup
>> @@ -1857,7 +1878,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>>      */
>>     if (object_property_get_bool(OBJECT(qdev_get_machine()),
>>                                  "vfio-no-msix-emulation", NULL)) {
>> -        memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false);
>> +        memory_region_set_enabled(&pdev->msix_table_mmio, false);
>>     }
>>
>>     return true;
>> @@ -1865,10 +1886,12 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>>
>> void vfio_pci_teardown_msi(VFIOPCIDevice *vdev)
>> {
>> -    msi_uninit(&vdev->pdev);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    msi_uninit(pdev);
>>
>>     if (vdev->msix) {
>> -        msix_uninit(&vdev->pdev,
>> +        msix_uninit(pdev,
>>                     vdev->bars[vdev->msix->table_bar].mr,
>>                     vdev->bars[vdev->msix->pba_bar].mr);
>>         g_free(vdev->msix->pending);
>> @@ -1929,6 +1952,7 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev)
>>
>> static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIOBAR *bar = &vdev->bars[nr];
>>     char *name;
>>
>> @@ -1950,7 +1974,7 @@ static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
>>         }
>>     }
>>
>> -    pci_register_bar(&vdev->pdev, nr, bar->type, bar->mr);
>> +    pci_register_bar(pdev, nr, bar->type, bar->mr);
>> }
>>
>> static void vfio_bars_register(VFIOPCIDevice *vdev)
>> @@ -1964,6 +1988,7 @@ static void vfio_bars_register(VFIOPCIDevice *vdev)
>>
>> void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int i;
>>
>>     for (i = 0; i < PCI_ROM_SLOT; i++) {
>> @@ -1977,7 +2002,7 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
>>     }
>>
>>     if (vdev->vga) {
>> -        pci_unregister_vga(&vdev->pdev);
>> +        pci_unregister_vga(pdev);
>>         vfio_vga_quirk_exit(vdev);
>>     }
>> }
>> @@ -2049,8 +2074,10 @@ static void vfio_set_word_bits(uint8_t *buf, uint16_t val, uint16_t mask)
>> static void vfio_add_emulated_word(VFIOPCIDevice *vdev, int pos,
>>                                    uint16_t val, uint16_t mask)
>> {
>> -    vfio_set_word_bits(vdev->pdev.config + pos, val, mask);
>> -    vfio_set_word_bits(vdev->pdev.wmask + pos, ~mask, mask);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    vfio_set_word_bits(pdev->config + pos, val, mask);
>> +    vfio_set_word_bits(pdev->wmask + pos, ~mask, mask);
>>     vfio_set_word_bits(vdev->emulated_config_bits + pos, mask, mask);
>> }
>>
>> @@ -2062,8 +2089,10 @@ static void vfio_set_long_bits(uint8_t *buf, uint32_t val, uint32_t mask)
>> static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos,
>>                                    uint32_t val, uint32_t mask)
>> {
>> -    vfio_set_long_bits(vdev->pdev.config + pos, val, mask);
>> -    vfio_set_long_bits(vdev->pdev.wmask + pos, ~mask, mask);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    vfio_set_long_bits(pdev->config + pos, val, mask);
>> +    vfio_set_long_bits(pdev->wmask + pos, ~mask, mask);
>>     vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask);
>> }
>>
>> @@ -2071,7 +2100,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>> {
>>     struct vfio_device_info_cap_pci_atomic_comp *cap;
>>     g_autofree struct vfio_device_info *info = NULL;
>> -    PCIBus *bus = pci_get_bus(&vdev->pdev);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    PCIBus *bus = pci_get_bus(pdev);
>>     PCIDevice *parent = bus->parent_dev;
>>     struct vfio_info_cap_header *hdr;
>>     uint32_t mask = 0;
>> @@ -2087,8 +2117,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>>     if (pci_bus_is_root(bus) || !parent || !parent->exp.exp_cap ||
>>         pcie_cap_get_type(parent) != PCI_EXP_TYPE_ROOT_PORT ||
>>         pcie_cap_get_version(parent) != PCI_EXP_FLAGS_VER2 ||
>> -        vdev->pdev.devfn ||
>> -        vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>> +        pdev->devfn ||
>> +        pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>>         return;
>>     }
>>
>> @@ -2132,8 +2162,10 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>>
>> static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>>     if (vdev->clear_parent_atomics_on_exit) {
>> -        PCIDevice *parent = pci_get_bus(&vdev->pdev)->parent_dev;
>> +        PCIDevice *parent = pci_get_bus(pdev)->parent_dev;
>>         uint8_t *pos = parent->config + parent->exp.exp_cap + PCI_EXP_DEVCAP2;
>>
>>         pci_long_test_and_clear_mask(pos, PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
>> @@ -2145,10 +2177,11 @@ static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
>> static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>>                                 Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint16_t flags;
>>     uint8_t type;
>>
>> -    flags = pci_get_word(vdev->pdev.config + pos + PCI_CAP_FLAGS);
>> +    flags = pci_get_word(pdev->config + pos + PCI_CAP_FLAGS);
>>     type = (flags & PCI_EXP_FLAGS_TYPE) >> 4;
>>
>>     if (type != PCI_EXP_TYPE_ENDPOINT &&
>> @@ -2160,8 +2193,8 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>>         return false;
>>     }
>>
>> -    if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) {
>> -        PCIBus *bus = pci_get_bus(&vdev->pdev);
>> +    if (!pci_bus_is_express(pci_get_bus(pdev))) {
>> +        PCIBus *bus = pci_get_bus(pdev);
>>         PCIDevice *bridge;
>>
>>         /*
>> @@ -2193,7 +2226,7 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>>             return true;
>>         }
>>
>> -    } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) {
>> +    } else if (pci_bus_is_root(pci_get_bus(pdev))) {
>>         /*
>>          * On a Root Complex bus Endpoints become Root Complex Integrated
>>          * Endpoints, which changes the type and clears the LNK & LNK2 fields.
>> @@ -2261,20 +2294,20 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
>>                                1, PCI_EXP_FLAGS_VERS);
>>     }
>>
>> -    pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size,
>> -                             errp);
>> +    pos = pci_add_capability(pdev, PCI_CAP_ID_EXP, pos, size, errp);
>>     if (pos < 0) {
>>         return false;
>>     }
>>
>> -    vdev->pdev.exp.exp_cap = pos;
>> +    pdev->exp.exp_cap = pos;
>>
>>     return true;
>> }
>>
>> static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
>> {
>> -    uint32_t cap = pci_get_long(vdev->pdev.config + pos + PCI_EXP_DEVCAP);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint32_t cap = pci_get_long(pdev->config + pos + PCI_EXP_DEVCAP);
>>
>>     if (cap & PCI_EXP_DEVCAP_FLR) {
>>         trace_vfio_check_pcie_flr(vdev->vbasedev.name);
>> @@ -2284,7 +2317,8 @@ static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
>>
>> static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
>> {
>> -    uint16_t csr = pci_get_word(vdev->pdev.config + pos + PCI_PM_CTRL);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint16_t csr = pci_get_word(pdev->config + pos + PCI_PM_CTRL);
>>
>>     if (!(csr & PCI_PM_CTRL_NO_SOFT_RESET)) {
>>         trace_vfio_check_pm_reset(vdev->vbasedev.name);
>> @@ -2294,7 +2328,8 @@ static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
>>
>> static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
>> {
>> -    uint8_t cap = pci_get_byte(vdev->pdev.config + pos + PCI_AF_CAP);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint8_t cap = pci_get_byte(pdev->config + pos + PCI_AF_CAP);
>>
>>     if ((cap & PCI_AF_CAP_TP) && (cap & PCI_AF_CAP_FLR)) {
>>         trace_vfio_check_af_flr(vdev->vbasedev.name);
>> @@ -2305,7 +2340,7 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
>> static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
>>                                          uint8_t size, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     pos = pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp);
>>     if (pos < 0) {
>> @@ -2327,7 +2362,7 @@ static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
>> static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)
>> {
>>     ERRP_GUARD();
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint8_t cap_id, next, size;
>>     bool ret;
>>
>> @@ -2413,17 +2448,18 @@ static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)
>>
>> static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint32_t ctrl;
>>     int i, nbar;
>>
>> -    ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL);
>> +    ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL);
>>     nbar = (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> PCI_REBAR_CTRL_NBAR_SHIFT;
>>
>>     for (i = 0; i < nbar; i++) {
>>         uint32_t cap;
>>         int size;
>>
>> -        ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL + (i * 8));
>> +        ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL + (i * 8));
>>         size = (ctrl & PCI_REBAR_CTRL_BAR_SIZE) >> PCI_REBAR_CTRL_BAR_SHIFT;
>>
>>         /* The cap register reports sizes 1MB to 128TB, with 4 reserved bits */
>> @@ -2461,7 +2497,7 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
>>
>> static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint32_t header;
>>     uint16_t cap_id, next, size;
>>     uint8_t cap_ver;
>> @@ -2555,7 +2591,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
>>
>> bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) ||
>>         !pdev->config[PCI_CAPABILITY_LIST]) {
>> @@ -2572,7 +2608,7 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
>>
>> void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint16_t cmd;
>>
>>     vfio_disable_interrupts(vdev);
>> @@ -2789,7 +2825,7 @@ static int vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f, Error **errp)
>> static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
>> {
>>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     pcibus_t old_addr[PCI_NUM_REGIONS - 1];
>>     int bar, ret;
>>
>> @@ -2837,6 +2873,7 @@ static VFIODeviceOps vfio_pci_ops = {
>>
>> bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     struct vfio_region_info *reg_info = NULL;
>>     int ret;
>> @@ -2893,7 +2930,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
>>                           "vfio-vga-io@0x3c0",
>>                           QEMU_PCI_VGA_IO_HI_SIZE);
>>
>> -    pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
>> +    pci_register_vga(pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
>>                      &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
>>                      &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
>>
>> @@ -2902,6 +2939,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
>>
>> bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     struct vfio_region_info *reg_info = NULL;
>>     struct vfio_irq_info irq_info;
>> @@ -2953,7 +2991,7 @@ bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
>>
>>     vdev->config_size = reg_info->size;
>>     if (vdev->config_size == PCI_CONFIG_SPACE_SIZE) {
>> -        vdev->pdev.cap_present &= ~QEMU_PCI_CAP_EXPRESS;
>> +        pdev->cap_present &= ~QEMU_PCI_CAP_EXPRESS;
>>     }
>>     vdev->config_offset = reg_info->offset;
>>
>> @@ -3156,16 +3194,16 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
>>
>> bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     uint32_t config_space_size;
>>     int ret;
>>
>> -    config_space_size = MIN(pci_config_size(&vdev->pdev), vdev->config_size);
>> +    config_space_size = MIN(pci_config_size(pdev), vdev->config_size);
>>
>>     /* Get a copy of config space */
>>     ret = vfio_pci_config_space_read(vdev, 0, config_space_size,
>> -                                     vdev->pdev.config);
>> +                                     pdev->config);
>>     if (ret < (int)config_space_size) {
>>         ret = ret < 0 ? -ret : EFAULT;
>>         error_setg_errno(errp, ret, "failed to read device config space");
>> @@ -3233,10 +3271,10 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>>                                               PCI_HEADER_TYPE_MULTI_FUNCTION;
>>
>>     /* Restore or clear multifunction, this is always controlled by QEMU */
>> -    if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>> -        vdev->pdev.config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
>> +    if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>> +        pdev->config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
>>     } else {
>> -        vdev->pdev.config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>> +        pdev->config[PCI_HEADER_TYPE] &= ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>>     }
>>
>>     /*
>> @@ -3244,8 +3282,8 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>>      * BAR, such as might be the case with the option ROM, we can get
>>      * confusing, unwritable, residual addresses from the host here.
>>      */
>> -    memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24);
>> -    memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4);
>> +    memset(&pdev->config[PCI_BASE_ADDRESS_0], 0, 24);
>> +    memset(&pdev->config[PCI_ROM_ADDRESS], 0, 4);
>>
>>     vfio_pci_size_rom(vdev);
>>
>> @@ -3262,7 +3300,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>>
>> bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     /* QEMU emulates all of MSI & MSIX */
>>     if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
>> @@ -3275,10 +3313,10 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
>>                vdev->msi_cap_size);
>>     }
>>
>> -    if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) {
>> +    if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) {
>>         vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
>>                                              vfio_intx_mmap_enable, vdev);
>> -        pci_device_set_intx_routing_notifier(&vdev->pdev,
>> +        pci_device_set_intx_routing_notifier(pdev,
>>                                              vfio_intx_routing_notifier);
>>         vdev->irqchip_change_notifier.notify = vfio_irqchip_change;
>>         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
>> @@ -3290,7 +3328,7 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
>>          */
>>         if (!cpr_is_incoming() && !vfio_intx_enable(vdev, errp)) {
>>             timer_free(vdev->intx.mmap_timer);
>> -            pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>> +            pci_device_set_intx_routing_notifier(pdev, NULL);
>>             kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
>>             return false;
>>         }
>> @@ -3440,7 +3478,7 @@ out_deregister:
>>     if (vdev->interrupt == VFIO_INT_INTx) {
>>         vfio_intx_disable(vdev);
>>     }
>> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>>     if (vdev->irqchip_change_notifier.notify) {
>>         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
>>     }
>> @@ -3472,7 +3510,7 @@ static void vfio_exitfn(PCIDevice *pdev)
>>
>>     vfio_unregister_req_notifier(vdev);
>>     vfio_unregister_err_notifier(vdev);
>> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>>     if (vdev->irqchip_change_notifier.notify) {
>>         kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
>>     }
>>
> 



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

* Re: [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj
  2025-07-15  9:26 ` [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj Mark Cave-Ayland
  2025-07-15  9:44   ` Philippe Mathieu-Daudé
  2025-07-15 12:36   ` Steven Sistare
@ 2025-08-11 12:46   ` Cédric Le Goater
  2 siblings, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-08-11 12:46 UTC (permalink / raw)
  To: Mark Cave-Ayland, npiggin, danielhb413, harshpb, mjrosato, farman,
	pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 7/15/25 11:26, Mark Cave-Ayland wrote:
> Now that nothing accesses the pdev field directly, rename pdev to
> parent_obj as per our current coding guidelines.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>


Reviewed-by: Cédric Le Goater <clg@redhat.com>

Thanks,

C.


> ---
>   hw/vfio/cpr.c | 4 ++--
>   hw/vfio/pci.c | 4 ++--
>   hw/vfio/pci.h | 2 +-
>   3 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
> index 3e3f4035ab..366490c908 100644
> --- a/hw/vfio/cpr.c
> +++ b/hw/vfio/cpr.c
> @@ -171,8 +171,8 @@ const VMStateDescription vfio_cpr_pci_vmstate = {
>       .post_load = vfio_cpr_pci_post_load,
>       .needed = cpr_incoming_needed,
>       .fields = (VMStateField[]) {
> -        VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice),
> -        VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, pci_msix_present),
> +        VMSTATE_PCI_DEVICE(parent_obj, VFIOPCIDevice),
> +        VMSTATE_MSIX_TEST(parent_obj, VFIOPCIDevice, pci_msix_present),
>           VMSTATE_VFIO_INTX(intx, VFIOPCIDevice),
>           VMSTATE_END_OF_LIST()
>       }
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index fb9eb58da5..1db6be8f21 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2804,8 +2804,8 @@ static const VMStateDescription vmstate_vfio_pci_config = {
>       .version_id = 1,
>       .minimum_version_id = 1,
>       .fields = (const VMStateField[]) {
> -        VMSTATE_PCI_DEVICE(pdev, VFIOPCIDevice),
> -        VMSTATE_MSIX_TEST(pdev, VFIOPCIDevice, vfio_msix_present),
> +        VMSTATE_PCI_DEVICE(parent_obj, VFIOPCIDevice),
> +        VMSTATE_MSIX_TEST(parent_obj, VFIOPCIDevice, vfio_msix_present),
>           VMSTATE_END_OF_LIST()
>       },
>       .subsections = (const VMStateDescription * const []) {
> diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
> index c0c3d68742..37d8b996f5 100644
> --- a/hw/vfio/pci.h
> +++ b/hw/vfio/pci.h
> @@ -131,7 +131,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VFIOPCIDevice, VFIO_PCI_BASE)
>   /* TYPE_VFIO_PCI shares struct VFIOPCIDevice. */
>   
>   struct VFIOPCIDevice {
> -    PCIDevice pdev;
> +    PCIDevice parent_obj;
>   
>       VFIODevice vbasedev;
>       VFIOINTx intx;



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

* Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
  2025-07-15 14:13   ` John Levon
@ 2025-08-28 15:14     ` Mark Cave-Ayland
  2025-08-28 15:25       ` John Levon
  0 siblings, 1 reply; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-08-28 15:14 UTC (permalink / raw)
  To: John Levon
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On 15/07/2025 15:13, John Levon wrote:

> On Tue, Jul 15, 2025 at 10:25:49AM +0100, Mark Cave-Ayland wrote:
> 
>> Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
>> of accessing bcontainer directly.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> 
> Patch subject should be  "vfio-user/container.c" not vfio/container.c
> 
> regards
> john

Ooops yes, I can easily fix that in v2. With that fixed, are you happy 
to give a SoB tag?


ATB,

Mark.



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

* Re: [PATCH 09/22] vfio/container.c: use QOM casts where appropriate
  2025-08-28 15:14     ` Mark Cave-Ayland
@ 2025-08-28 15:25       ` John Levon
  0 siblings, 0 replies; 73+ messages in thread
From: John Levon @ 2025-08-28 15:25 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, thanos.makatos,
	alex.williamson, clg, steven.sistare, tomitamoeko, qemu-ppc,
	qemu-s390x, qemu-devel

On Thu, Aug 28, 2025 at 04:14:06PM +0100, Mark Cave-Ayland wrote:

> On 15/07/2025 15:13, John Levon wrote:
> 
> > On Tue, Jul 15, 2025 at 10:25:49AM +0100, Mark Cave-Ayland wrote:
> > 
> > > Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
> > > of accessing bcontainer directly.
> > > 
> > > Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
> > 
> > Patch subject should be  "vfio-user/container.c" not vfio/container.c
> > 
> > regards
> > john
> 
> Ooops yes, I can easily fix that in v2. With that fixed, are you happy to
> give a SoB tag?

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

regards
john


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

* Re: [PATCH 16/22] vfio/pci.c: use QOM casts where appropriate
  2025-07-15 13:38   ` BALATON Zoltan
  2025-08-11 12:45     ` Cédric Le Goater
@ 2025-08-29 11:07     ` Mark Cave-Ayland
  2025-08-29 14:31       ` BALATON Zoltan
  2025-09-01 10:24       ` Cédric Le Goater
  1 sibling, 2 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-08-29 11:07 UTC (permalink / raw)
  To: BALATON Zoltan
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 15/07/2025 14:38, BALATON Zoltan wrote:

> On Tue, 15 Jul 2025, Mark Cave-Ayland wrote:
>> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
>> accessing pdev directly.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>> ---
>> hw/vfio/pci.c | 202 ++++++++++++++++++++++++++++++--------------------
>> 1 file changed, 120 insertions(+), 82 deletions(-)
>>
>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> index 1093b28df7..fb9eb58da5 100644
>> --- a/hw/vfio/pci.c
>> +++ b/hw/vfio/pci.c
>> @@ -119,6 +119,7 @@ static void vfio_intx_mmap_enable(void *opaque)
>> static void vfio_intx_interrupt(void *opaque)
>> {
>>     VFIOPCIDevice *vdev = opaque;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
> 
> Don't do that. Opaque data is already type checked when it is registered 
> for the callback and cannot be changed so additional type checking here 
> is just a performance hit without any advantage. It's OK to do it in 
> less frequently called functions but don't add unnecessary casts to 
> functions that can be called a lot.

In general the QOM casts fall into the noise in a standard profile, but 
I can see how it could be possible they might show up in the interrupt 
fast path.

I'll look at getting a vfio-pci perf test set up here to see if there is 
a noticeable effect in this case, and if so think about what the best 
approach is.

> Regards,
> BALATON Zoltan
> 
>>     if (!event_notifier_test_and_clear(&vdev->intx.interrupt)) {
>>         return;
>> @@ -127,7 +128,7 @@ static void vfio_intx_interrupt(void *opaque)
>>     trace_vfio_intx_interrupt(vdev->vbasedev.name, 'A' + vdev->intx.pin);
>>
>>     vdev->intx.pending = true;
>> -    pci_irq_assert(&vdev->pdev);
>> +    pci_irq_assert(pdev);
>>     vfio_mmap_set_enabled(vdev, false);
>>     if (vdev->intx.mmap_timeout) {
>>         timer_mod(vdev->intx.mmap_timer,
>> @@ -138,6 +139,7 @@ static void vfio_intx_interrupt(void *opaque)
>> void vfio_pci_intx_eoi(VFIODevice *vbasedev)
>> {
>>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, 
>> vbasedev);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     if (!vdev->intx.pending) {
>>         return;
>> @@ -146,13 +148,14 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev)
>>     trace_vfio_pci_intx_eoi(vbasedev->name);
>>
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>     vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>> }
>>
>> static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
>> {
>> #ifdef CONFIG_KVM
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
>>
>>     if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
>> @@ -165,7 +168,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice 
>> *vdev, Error **errp)
>>     qemu_set_fd_handler(irq_fd, NULL, NULL, vdev);
>>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>
>>     /* Get an eventfd for resample/unmask */
>>     if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 
>> 0, errp)) {
>> @@ -243,6 +246,8 @@ static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice 
>> *vdev, Error **errp)
>> static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
>> {
>> #ifdef CONFIG_KVM
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>>     if (!vdev->intx.kvm_accel) {
>>         return;
>>     }
>> @@ -253,7 +258,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice 
>> *vdev)
>>      */
>>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>
>>     /* Tell KVM to stop listening for an INTx irqfd */
>>     if (kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev- 
>> >intx.interrupt,
>> @@ -309,7 +314,7 @@ static void vfio_intx_routing_notifier(PCIDevice 
>> *pdev)
>>         return;
>>     }
>>
>> -    route = pci_device_route_intx_to_irq(&vdev->pdev, vdev->intx.pin);
>> +    route = pci_device_route_intx_to_irq(pdev, vdev->intx.pin);
>>
>>     if (pci_intx_route_changed(&vdev->intx.route, &route)) {
>>         vfio_intx_update(vdev, &route);
>> @@ -326,7 +331,8 @@ static void vfio_irqchip_change(Notifier *notify, 
>> void *data)
>>
>> static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    uint8_t pin = vfio_pci_read_config(&vdev->pdev, 
>> PCI_INTERRUPT_PIN, 1);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint8_t pin = vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1);
>>     Error *err = NULL;
>>     int32_t fd;
>>
>> @@ -344,7 +350,7 @@ 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);
>> +    pci_config_set_interrupt_pin(pdev->config, pin);
>>
>> #ifdef CONFIG_KVM
>>     /*
>> @@ -352,7 +358,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, 
>> Error **errp)
>>      * where we won't actually use the result anyway.
>>      */
>>     if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) {
>> -        vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
>> +        vdev->intx.route = pci_device_route_intx_to_irq(pdev,
>>                                                         vdev->intx.pin);
>>     }
>> #endif
>> @@ -392,13 +398,14 @@ skip_signaling:
>>
>> static void vfio_intx_disable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int fd;
>>
>>     timer_del(vdev->intx.mmap_timer);
>>     vfio_intx_disable_kvm(vdev);
>>     vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>     vdev->intx.pending = false;
>> -    pci_irq_deassert(&vdev->pdev);
>> +    pci_irq_deassert(pdev);
>>     vfio_mmap_set_enabled(vdev, true);
>>
>>     fd = event_notifier_get_fd(&vdev->intx.interrupt);
>> @@ -422,6 +429,7 @@ static void vfio_msi_interrupt(void *opaque)
>> {
>>     VFIOMSIVector *vector = opaque;
>>     VFIOPCIDevice *vdev = vector->vdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     MSIMessage (*get_msg)(PCIDevice *dev, unsigned vector);
>>     void (*notify)(PCIDevice *dev, unsigned vector);
>>     MSIMessage msg;
>> @@ -436,9 +444,9 @@ static void vfio_msi_interrupt(void *opaque)
>>         notify = msix_notify;
>>
>>         /* A masked vector firing needs to use the PBA, enable it */
>> -        if (msix_is_masked(&vdev->pdev, nr)) {
>> +        if (msix_is_masked(pdev, nr)) {
>>             set_bit(nr, vdev->msix->pending);
>> -            memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, true);
>> +            memory_region_set_enabled(&pdev->msix_pba_mmio, true);
>>             trace_vfio_msix_pba_enable(vdev->vbasedev.name);
>>         }
>>     } else if (vdev->interrupt == VFIO_INT_MSI) {
>> @@ -448,9 +456,9 @@ static void vfio_msi_interrupt(void *opaque)
>>         abort();
>>     }
>>
>> -    msg = get_msg(&vdev->pdev, nr);
>> +    msg = get_msg(pdev, nr);
>>     trace_vfio_msi_interrupt(vdev->vbasedev.name, nr, msg.address, 
>> msg.data);
>> -    notify(&vdev->pdev, nr);
>> +    notify(pdev, nr);
>> }
>>
>> void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr)
>> @@ -488,6 +496,7 @@ static int vfio_enable_msix_no_vec(VFIOPCIDevice 
>> *vdev)
>>
>> static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     struct vfio_irq_set *irq_set;
>>     int ret = 0, i, argsz;
>>     int32_t *fds;
>> @@ -530,7 +539,7 @@ static int vfio_enable_vectors(VFIOPCIDevice 
>> *vdev, bool msix)
>>          */
>>         if (vdev->msi_vectors[i].use) {
>>             if (vdev->msi_vectors[i].virq < 0 ||
>> -                (msix && msix_is_masked(&vdev->pdev, i))) {
>> +                (msix && msix_is_masked(pdev, i))) {
>>                 fd = event_notifier_get_fd(&vdev- 
>> >msi_vectors[i].interrupt);
>>             } else {
>>                 fd = event_notifier_get_fd(&vdev- 
>> >msi_vectors[i].kvm_interrupt);
>> @@ -550,12 +559,14 @@ static int vfio_enable_vectors(VFIOPCIDevice 
>> *vdev, bool msix)
>> void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector 
>> *vector,
>>                                int vector_n, bool msix)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>>     if ((msix && vdev->no_kvm_msix) || (!msix && vdev->no_kvm_msi)) {
>>         return;
>>     }
>>
>>     vector->virq = kvm_irqchip_add_msi_route(&vfio_route_change,
>> -                                             vector_n, &vdev->pdev);
>> +                                             vector_n, pdev);
>> }
>>
>> static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector, int nr)
>> @@ -624,7 +635,7 @@ static void set_irq_signalling(VFIODevice 
>> *vbasedev, VFIOMSIVector *vector,
>> void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr)
>> {
>>     VFIOMSIVector *vector = &vdev->msi_vectors[nr];
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     Error *local_err = NULL;
>>
>>     vector->vdev = vdev;
>> @@ -713,7 +724,7 @@ static int vfio_msix_vector_do_use(PCIDevice 
>> *pdev, unsigned int nr,
>>     clear_bit(nr, vdev->msix->pending);
>>     if (find_first_bit(vdev->msix->pending,
>>                        vdev->nr_vectors) == vdev->nr_vectors) {
>> -        memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
>> +        memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>>         trace_vfio_msix_pba_disable(vdev->vbasedev.name);
>>     }
>>
>> @@ -764,7 +775,9 @@ static void vfio_msix_vector_release(PCIDevice 
>> *pdev, unsigned int nr)
>>
>> void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev)
>> {
>> -    msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>>                               vfio_msix_vector_release, NULL);
>> }
>>
>> @@ -791,6 +804,7 @@ void 
>> vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev)
>>
>> static void vfio_msix_enable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int ret;
>>
>>     vfio_disable_interrupts(vdev);
>> @@ -807,7 +821,7 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>>      */
>>     vfio_pci_prepare_kvm_msi_virq_batch(vdev);
>>
>> -    if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
>> +    if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>>                                   vfio_msix_vector_release, NULL)) {
>>         error_report("vfio: msix_set_vector_notifiers failed");
>>     }
>> @@ -845,11 +859,12 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>>
>> static void vfio_msi_enable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int ret, i;
>>
>>     vfio_disable_interrupts(vdev);
>>
>> -    vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev);
>> +    vdev->nr_vectors = msi_nr_vectors_allocated(pdev);
>> retry:
>>     /*
>>      * Setting vector notifiers needs to enable route for each vector.
>> @@ -942,10 +957,11 @@ static void 
>> vfio_msi_disable_common(VFIOPCIDevice *vdev)
>>
>> static void vfio_msix_disable(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     Error *err = NULL;
>>     int i;
>>
>> -    msix_unset_vector_notifiers(&vdev->pdev);
>> +    msix_unset_vector_notifiers(pdev);
>>
>>     /*
>>      * MSI-X will only release vectors if MSI-X is still enabled on the
>> @@ -953,8 +969,8 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
>>      */
>>     for (i = 0; i < vdev->nr_vectors; i++) {
>>         if (vdev->msi_vectors[i].use) {
>> -            vfio_msix_vector_release(&vdev->pdev, i);
>> -            msix_vector_unuse(&vdev->pdev, i);
>> +            vfio_msix_vector_release(pdev, i);
>> +            msix_vector_unuse(pdev, i);
>>         }
>>     }
>>
>> @@ -991,6 +1007,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev)
>>
>> static void vfio_update_msi(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int i;
>>
>>     for (i = 0; i < vdev->nr_vectors; i++) {
>> @@ -1001,8 +1018,8 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
>>             continue;
>>         }
>>
>> -        msg = msi_get_message(&vdev->pdev, i);
>> -        vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev);
>> +        msg = msi_get_message(pdev, i);
>> +        vfio_update_kvm_msi_virq(vector, msg, pdev);
>>     }
>> }
>>
>> @@ -1164,13 +1181,14 @@ static const MemoryRegionOps vfio_rom_ops = {
>>
>> static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);
>>     char *name;
>>
>> -    if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
>> +    if (pdev->romfile || !pdev->rom_bar) {
>>         /* Since pci handles romfile, just print a message and return */
>> -        if (vfio_opt_rom_in_denylist(vdev) && vdev->pdev.romfile) {
>> +        if (vfio_opt_rom_in_denylist(vdev) && pdev->romfile) {
>>             warn_report("Device at %s is known to cause system 
>> instability"
>>                         " issues during option rom execution",
>>                         vdev->vbasedev.name);
>> @@ -1199,7 +1217,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>>     }
>>
>>     if (vfio_opt_rom_in_denylist(vdev)) {
>> -        if (vdev->pdev.rom_bar > 0) {
>> +        if (pdev->rom_bar > 0) {
>>             warn_report("Device at %s is known to cause system 
>> instability"
>>                         " issues during option rom execution",
>>                         vdev->vbasedev.name);
>> @@ -1218,12 +1236,12 @@ static void vfio_pci_size_rom(VFIOPCIDevice 
>> *vdev)
>>
>>     name = g_strdup_printf("vfio[%s].rom", vdev->vbasedev.name);
>>
>> -    memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),
>> +    memory_region_init_io(&pdev->rom, OBJECT(vdev),
>>                           &vfio_rom_ops, vdev, name, size);
>>     g_free(name);
>>
>> -    pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,
>> -                     PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);
>> +    pci_register_bar(pdev, PCI_ROM_SLOT,
>> +                     PCI_BASE_ADDRESS_SPACE_MEMORY, &pdev->rom);
>>
>>     vdev->rom_read_failed = false;
>> }
>> @@ -1496,6 +1514,7 @@ static void 
>> vfio_disable_interrupts(VFIOPCIDevice *vdev)
>>
>> static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint16_t ctrl;
>>     bool msi_64bit, msi_maskbit;
>>     int ret, entries;
>> @@ -1516,7 +1535,7 @@ static bool vfio_msi_setup(VFIOPCIDevice *vdev, 
>> int pos, Error **errp)
>>
>>     trace_vfio_msi_setup(vdev->vbasedev.name, pos);
>>
>> -    ret = msi_init(&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, 
>> &err);
>> +    ret = msi_init(pdev, pos, entries, msi_64bit, msi_maskbit, &err);
>>     if (ret < 0) {
>>         if (ret == -ENOTSUP) {
>>             return true;
>> @@ -1709,6 +1728,7 @@ static bool vfio_pci_relocate_msix(VFIOPCIDevice 
>> *vdev, Error **errp)
>>  */
>> static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint8_t pos;
>>     uint16_t ctrl;
>>     uint32_t table, pba;
>> @@ -1716,7 +1736,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice 
>> *vdev, Error **errp)
>>     VFIOMSIXInfo *msix;
>>     int ret;
>>
>> -    pos = pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX);
>> +    pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
>>     if (!pos) {
>>         return true;
>>     }
>> @@ -1808,12 +1828,13 @@ static bool 
>> vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>>
>> static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int ret;
>>     Error *err = NULL;
>>
>>     vdev->msix->pending = g_new0(unsigned long,
>>                                  BITS_TO_LONGS(vdev->msix->entries));
>> -    ret = msix_init(&vdev->pdev, vdev->msix->entries,
>> +    ret = msix_init(pdev, vdev->msix->entries,
>>                     vdev->bars[vdev->msix->table_bar].mr,
>>                     vdev->msix->table_bar, vdev->msix->table_offset,
>>                     vdev->bars[vdev->msix->pba_bar].mr,
>> @@ -1845,7 +1866,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, 
>> int pos, Error **errp)
>>      * vector-use notifier is called, which occurs on unmask, we test 
>> whether
>>      * PBA emulation is needed and again disable if not.
>>      */
>> -    memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
>> +    memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>>
>>     /*
>>      * The emulated machine may provide a paravirt interface for MSIX 
>> setup
>> @@ -1857,7 +1878,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, 
>> int pos, Error **errp)
>>      */
>>     if (object_property_get_bool(OBJECT(qdev_get_machine()),
>>                                  "vfio-no-msix-emulation", NULL)) {
>> -        memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false);
>> +        memory_region_set_enabled(&pdev->msix_table_mmio, false);
>>     }
>>
>>     return true;
>> @@ -1865,10 +1886,12 @@ static bool vfio_msix_setup(VFIOPCIDevice 
>> *vdev, int pos, Error **errp)
>>
>> void vfio_pci_teardown_msi(VFIOPCIDevice *vdev)
>> {
>> -    msi_uninit(&vdev->pdev);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    msi_uninit(pdev);
>>
>>     if (vdev->msix) {
>> -        msix_uninit(&vdev->pdev,
>> +        msix_uninit(pdev,
>>                     vdev->bars[vdev->msix->table_bar].mr,
>>                     vdev->bars[vdev->msix->pba_bar].mr);
>>         g_free(vdev->msix->pending);
>> @@ -1929,6 +1952,7 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev)
>>
>> static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIOBAR *bar = &vdev->bars[nr];
>>     char *name;
>>
>> @@ -1950,7 +1974,7 @@ static void vfio_bar_register(VFIOPCIDevice 
>> *vdev, int nr)
>>         }
>>     }
>>
>> -    pci_register_bar(&vdev->pdev, nr, bar->type, bar->mr);
>> +    pci_register_bar(pdev, nr, bar->type, bar->mr);
>> }
>>
>> static void vfio_bars_register(VFIOPCIDevice *vdev)
>> @@ -1964,6 +1988,7 @@ static void vfio_bars_register(VFIOPCIDevice *vdev)
>>
>> void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     int i;
>>
>>     for (i = 0; i < PCI_ROM_SLOT; i++) {
>> @@ -1977,7 +2002,7 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
>>     }
>>
>>     if (vdev->vga) {
>> -        pci_unregister_vga(&vdev->pdev);
>> +        pci_unregister_vga(pdev);
>>         vfio_vga_quirk_exit(vdev);
>>     }
>> }
>> @@ -2049,8 +2074,10 @@ static void vfio_set_word_bits(uint8_t *buf, 
>> uint16_t val, uint16_t mask)
>> static void vfio_add_emulated_word(VFIOPCIDevice *vdev, int pos,
>>                                    uint16_t val, uint16_t mask)
>> {
>> -    vfio_set_word_bits(vdev->pdev.config + pos, val, mask);
>> -    vfio_set_word_bits(vdev->pdev.wmask + pos, ~mask, mask);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    vfio_set_word_bits(pdev->config + pos, val, mask);
>> +    vfio_set_word_bits(pdev->wmask + pos, ~mask, mask);
>>     vfio_set_word_bits(vdev->emulated_config_bits + pos, mask, mask);
>> }
>>
>> @@ -2062,8 +2089,10 @@ static void vfio_set_long_bits(uint8_t *buf, 
>> uint32_t val, uint32_t mask)
>> static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos,
>>                                    uint32_t val, uint32_t mask)
>> {
>> -    vfio_set_long_bits(vdev->pdev.config + pos, val, mask);
>> -    vfio_set_long_bits(vdev->pdev.wmask + pos, ~mask, mask);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>> +    vfio_set_long_bits(pdev->config + pos, val, mask);
>> +    vfio_set_long_bits(pdev->wmask + pos, ~mask, mask);
>>     vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask);
>> }
>>
>> @@ -2071,7 +2100,8 @@ static void 
>> vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>> {
>>     struct vfio_device_info_cap_pci_atomic_comp *cap;
>>     g_autofree struct vfio_device_info *info = NULL;
>> -    PCIBus *bus = pci_get_bus(&vdev->pdev);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    PCIBus *bus = pci_get_bus(pdev);
>>     PCIDevice *parent = bus->parent_dev;
>>     struct vfio_info_cap_header *hdr;
>>     uint32_t mask = 0;
>> @@ -2087,8 +2117,8 @@ static void 
>> vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>>     if (pci_bus_is_root(bus) || !parent || !parent->exp.exp_cap ||
>>         pcie_cap_get_type(parent) != PCI_EXP_TYPE_ROOT_PORT ||
>>         pcie_cap_get_version(parent) != PCI_EXP_FLAGS_VER2 ||
>> -        vdev->pdev.devfn ||
>> -        vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>> +        pdev->devfn ||
>> +        pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>>         return;
>>     }
>>
>> @@ -2132,8 +2162,10 @@ static void 
>> vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>>
>> static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +
>>     if (vdev->clear_parent_atomics_on_exit) {
>> -        PCIDevice *parent = pci_get_bus(&vdev->pdev)->parent_dev;
>> +        PCIDevice *parent = pci_get_bus(pdev)->parent_dev;
>>         uint8_t *pos = parent->config + parent->exp.exp_cap + 
>> PCI_EXP_DEVCAP2;
>>
>>         pci_long_test_and_clear_mask(pos, PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
>> @@ -2145,10 +2177,11 @@ static void 
>> vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
>> static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t 
>> size,
>>                                 Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint16_t flags;
>>     uint8_t type;
>>
>> -    flags = pci_get_word(vdev->pdev.config + pos + PCI_CAP_FLAGS);
>> +    flags = pci_get_word(pdev->config + pos + PCI_CAP_FLAGS);
>>     type = (flags & PCI_EXP_FLAGS_TYPE) >> 4;
>>
>>     if (type != PCI_EXP_TYPE_ENDPOINT &&
>> @@ -2160,8 +2193,8 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice 
>> *vdev, int pos, uint8_t size,
>>         return false;
>>     }
>>
>> -    if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) {
>> -        PCIBus *bus = pci_get_bus(&vdev->pdev);
>> +    if (!pci_bus_is_express(pci_get_bus(pdev))) {
>> +        PCIBus *bus = pci_get_bus(pdev);
>>         PCIDevice *bridge;
>>
>>         /*
>> @@ -2193,7 +2226,7 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice 
>> *vdev, int pos, uint8_t size,
>>             return true;
>>         }
>>
>> -    } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) {
>> +    } else if (pci_bus_is_root(pci_get_bus(pdev))) {
>>         /*
>>          * On a Root Complex bus Endpoints become Root Complex Integrated
>>          * Endpoints, which changes the type and clears the LNK & LNK2 
>> fields.
>> @@ -2261,20 +2294,20 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice 
>> *vdev, int pos, uint8_t size,
>>                                1, PCI_EXP_FLAGS_VERS);
>>     }
>>
>> -    pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size,
>> -                             errp);
>> +    pos = pci_add_capability(pdev, PCI_CAP_ID_EXP, pos, size, errp);
>>     if (pos < 0) {
>>         return false;
>>     }
>>
>> -    vdev->pdev.exp.exp_cap = pos;
>> +    pdev->exp.exp_cap = pos;
>>
>>     return true;
>> }
>>
>> static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
>> {
>> -    uint32_t cap = pci_get_long(vdev->pdev.config + pos + 
>> PCI_EXP_DEVCAP);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint32_t cap = pci_get_long(pdev->config + pos + PCI_EXP_DEVCAP);
>>
>>     if (cap & PCI_EXP_DEVCAP_FLR) {
>>         trace_vfio_check_pcie_flr(vdev->vbasedev.name);
>> @@ -2284,7 +2317,8 @@ static void vfio_check_pcie_flr(VFIOPCIDevice 
>> *vdev, uint8_t pos)
>>
>> static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
>> {
>> -    uint16_t csr = pci_get_word(vdev->pdev.config + pos + PCI_PM_CTRL);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint16_t csr = pci_get_word(pdev->config + pos + PCI_PM_CTRL);
>>
>>     if (!(csr & PCI_PM_CTRL_NO_SOFT_RESET)) {
>>         trace_vfio_check_pm_reset(vdev->vbasedev.name);
>> @@ -2294,7 +2328,8 @@ static void vfio_check_pm_reset(VFIOPCIDevice 
>> *vdev, uint8_t pos)
>>
>> static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
>> {
>> -    uint8_t cap = pci_get_byte(vdev->pdev.config + pos + PCI_AF_CAP);
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> +    uint8_t cap = pci_get_byte(pdev->config + pos + PCI_AF_CAP);
>>
>>     if ((cap & PCI_AF_CAP_TP) && (cap & PCI_AF_CAP_FLR)) {
>>         trace_vfio_check_af_flr(vdev->vbasedev.name);
>> @@ -2305,7 +2340,7 @@ static void vfio_check_af_flr(VFIOPCIDevice 
>> *vdev, uint8_t pos)
>> static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
>>                                          uint8_t size, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     pos = pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp);
>>     if (pos < 0) {
>> @@ -2327,7 +2362,7 @@ static bool 
>> vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
>> static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error 
>> **errp)
>> {
>>     ERRP_GUARD();
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint8_t cap_id, next, size;
>>     bool ret;
>>
>> @@ -2413,17 +2448,18 @@ static bool vfio_add_std_cap(VFIOPCIDevice 
>> *vdev, uint8_t pos, Error **errp)
>>
>> static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint32_t ctrl;
>>     int i, nbar;
>>
>> -    ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL);
>> +    ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL);
>>     nbar = (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> 
>> PCI_REBAR_CTRL_NBAR_SHIFT;
>>
>>     for (i = 0; i < nbar; i++) {
>>         uint32_t cap;
>>         int size;
>>
>> -        ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL 
>> + (i * 8));
>> +        ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL + (i 
>> * 8));
>>         size = (ctrl & PCI_REBAR_CTRL_BAR_SIZE) >> 
>> PCI_REBAR_CTRL_BAR_SHIFT;
>>
>>         /* The cap register reports sizes 1MB to 128TB, with 4 
>> reserved bits */
>> @@ -2461,7 +2497,7 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice 
>> *vdev, uint16_t pos)
>>
>> static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint32_t header;
>>     uint16_t cap_id, next, size;
>>     uint8_t cap_ver;
>> @@ -2555,7 +2591,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
>>
>> bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) ||
>>         !pdev->config[PCI_CAPABILITY_LIST]) {
>> @@ -2572,7 +2608,7 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice 
>> *vdev, Error **errp)
>>
>> void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     uint16_t cmd;
>>
>>     vfio_disable_interrupts(vdev);
>> @@ -2789,7 +2825,7 @@ static int vfio_pci_save_config(VFIODevice 
>> *vbasedev, QEMUFile *f, Error **errp)
>> static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
>> {
>>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, 
>> vbasedev);
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     pcibus_t old_addr[PCI_NUM_REGIONS - 1];
>>     int bar, ret;
>>
>> @@ -2837,6 +2873,7 @@ static VFIODeviceOps vfio_pci_ops = {
>>
>> bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     struct vfio_region_info *reg_info = NULL;
>>     int ret;
>> @@ -2893,7 +2930,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, 
>> Error **errp)
>>                           "vfio-vga-io@0x3c0",
>>                           QEMU_PCI_VGA_IO_HI_SIZE);
>>
>> -    pci_register_vga(&vdev->pdev, &vdev->vga- 
>> >region[QEMU_PCI_VGA_MEM].mem,
>> +    pci_register_vga(pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
>>                      &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
>>                      &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
>>
>> @@ -2902,6 +2939,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, 
>> Error **errp)
>>
>> bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
>> {
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     struct vfio_region_info *reg_info = NULL;
>>     struct vfio_irq_info irq_info;
>> @@ -2953,7 +2991,7 @@ bool vfio_pci_populate_device(VFIOPCIDevice 
>> *vdev, Error **errp)
>>
>>     vdev->config_size = reg_info->size;
>>     if (vdev->config_size == PCI_CONFIG_SPACE_SIZE) {
>> -        vdev->pdev.cap_present &= ~QEMU_PCI_CAP_EXPRESS;
>> +        pdev->cap_present &= ~QEMU_PCI_CAP_EXPRESS;
>>     }
>>     vdev->config_offset = reg_info->offset;
>>
>> @@ -3156,16 +3194,16 @@ static void 
>> vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
>>
>> bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>     uint32_t config_space_size;
>>     int ret;
>>
>> -    config_space_size = MIN(pci_config_size(&vdev->pdev), vdev- 
>> >config_size);
>> +    config_space_size = MIN(pci_config_size(pdev), vdev->config_size);
>>
>>     /* Get a copy of config space */
>>     ret = vfio_pci_config_space_read(vdev, 0, config_space_size,
>> -                                     vdev->pdev.config);
>> +                                     pdev->config);
>>     if (ret < (int)config_space_size) {
>>         ret = ret < 0 ? -ret : EFAULT;
>>         error_setg_errno(errp, ret, "failed to read device config 
>> space");
>> @@ -3233,10 +3271,10 @@ bool vfio_pci_config_setup(VFIOPCIDevice 
>> *vdev, Error **errp)
>>                                               
>> PCI_HEADER_TYPE_MULTI_FUNCTION;
>>
>>     /* Restore or clear multifunction, this is always controlled by 
>> QEMU */
>> -    if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>> -        vdev->pdev.config[PCI_HEADER_TYPE] |= 
>> PCI_HEADER_TYPE_MULTI_FUNCTION;
>> +    if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>> +        pdev->config[PCI_HEADER_TYPE] |= PCI_HEADER_TYPE_MULTI_FUNCTION;
>>     } else {
>> -        vdev->pdev.config[PCI_HEADER_TYPE] &= 
>> ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>> +        pdev->config[PCI_HEADER_TYPE] &= 
>> ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>>     }
>>
>>     /*
>> @@ -3244,8 +3282,8 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, 
>> Error **errp)
>>      * BAR, such as might be the case with the option ROM, we can get
>>      * confusing, unwritable, residual addresses from the host here.
>>      */
>> -    memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24);
>> -    memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4);
>> +    memset(&pdev->config[PCI_BASE_ADDRESS_0], 0, 24);
>> +    memset(&pdev->config[PCI_ROM_ADDRESS], 0, 4);
>>
>>     vfio_pci_size_rom(vdev);
>>
>> @@ -3262,7 +3300,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, 
>> Error **errp)
>>
>> bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
>> {
>> -    PCIDevice *pdev = &vdev->pdev;
>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>>     /* QEMU emulates all of MSI & MSIX */
>>     if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
>> @@ -3275,10 +3313,10 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice 
>> *vdev, Error **errp)
>>                vdev->msi_cap_size);
>>     }
>>
>> -    if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) {
>> +    if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) {
>>         vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
>>                                              vfio_intx_mmap_enable, 
>> vdev);
>> -        pci_device_set_intx_routing_notifier(&vdev->pdev,
>> +        pci_device_set_intx_routing_notifier(pdev,
>>                                              vfio_intx_routing_notifier);
>>         vdev->irqchip_change_notifier.notify = vfio_irqchip_change;
>>         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
>> @@ -3290,7 +3328,7 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice 
>> *vdev, Error **errp)
>>          */
>>         if (!cpr_is_incoming() && !vfio_intx_enable(vdev, errp)) {
>>             timer_free(vdev->intx.mmap_timer);
>> -            pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>> +            pci_device_set_intx_routing_notifier(pdev, NULL);
>>             kvm_irqchip_remove_change_notifier(&vdev- 
>> >irqchip_change_notifier);
>>             return false;
>>         }
>> @@ -3440,7 +3478,7 @@ out_deregister:
>>     if (vdev->interrupt == VFIO_INT_INTx) {
>>         vfio_intx_disable(vdev);
>>     }
>> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>>     if (vdev->irqchip_change_notifier.notify) {
>>         kvm_irqchip_remove_change_notifier(&vdev- 
>> >irqchip_change_notifier);
>>     }
>> @@ -3472,7 +3510,7 @@ static void vfio_exitfn(PCIDevice *pdev)
>>
>>     vfio_unregister_req_notifier(vdev);
>>     vfio_unregister_err_notifier(vdev);
>> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>>     if (vdev->irqchip_change_notifier.notify) {
>>         kvm_irqchip_remove_change_notifier(&vdev- 
>> >irqchip_change_notifier);
>>     }


ATB,

Mark.



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

* Re: [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration
  2025-08-11 11:56   ` Cédric Le Goater
@ 2025-08-29 11:10     ` Mark Cave-Ayland
  0 siblings, 0 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-08-29 11:10 UTC (permalink / raw)
  To: Cédric Le Goater, npiggin, danielhb413, harshpb, mjrosato,
	farman, pasic, borntraeger, thuth, richard.henderson, david, iii,
	john.levon, thanos.makatos, alex.williamson, steven.sistare,
	tomitamoeko, qemu-ppc, qemu-s390x, qemu-devel

On 11/08/2025 12:56, Cédric Le Goater wrote:

> One more thing we could do :
> 
>> @@ -105,14 +109,11 @@ vfio_container_get_page_size_mask(const 
>> VFIOContainerBase *bcontainer)
>>       return bcontainer->pgsizes;
>>   }
>> -#define TYPE_VFIO_IOMMU "vfio-iommu"
>>   #define TYPE_VFIO_IOMMU_LEGACY TYPE_VFIO_IOMMU "-legacy"
>>   #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU "-spapr"
>>   #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU "-iommufd"
>>   #define TYPE_VFIO_IOMMU_USER TYPE_VFIO_IOMMU "-user"
> 
> These type definitions would be better placed in the header files
> defining the other software structures to which they relate.
> 
>    TYPE_VFIO_IOMMU_LEGACY  -> hw/vfio/vfio-container.h
>    TYPE_VFIO_IOMMU_SPAPR   -> hw/vfio/vfio-container.h ?
>    TYPE_VFIO_IOMMU_IOMMUFD -> hw/vfio/vfio-iommufd.h
>    TYPE_VFIO_IOMMU_USER    -> hw/vfio-user/container.h
> 
> I don't know how possible that would be.

I can have a look at how feasible this is if you like? This pattern 
tends to be used a lot elsewhere and feels more intuitive to me.


ATB,

Mark.



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

* Re: [PATCH 16/22] vfio/pci.c: use QOM casts where appropriate
  2025-08-11 12:45     ` Cédric Le Goater
@ 2025-08-29 11:13       ` Mark Cave-Ayland
  0 siblings, 0 replies; 73+ messages in thread
From: Mark Cave-Ayland @ 2025-08-29 11:13 UTC (permalink / raw)
  To: Cédric Le Goater, BALATON Zoltan
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 11/08/2025 13:45, Cédric Le Goater wrote:

> On 7/15/25 15:38, BALATON Zoltan wrote:
>> On Tue, 15 Jul 2025, Mark Cave-Ayland wrote:
>>> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
>>> accessing pdev directly.
>>>
>>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>>> ---
>>> hw/vfio/pci.c | 202 ++++++++++++++++++++++++++++++--------------------
>>> 1 file changed, 120 insertions(+), 82 deletions(-)
>>>
>>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>>> index 1093b28df7..fb9eb58da5 100644
>>> --- a/hw/vfio/pci.c
>>> +++ b/hw/vfio/pci.c
>>> @@ -119,6 +119,7 @@ static void vfio_intx_mmap_enable(void *opaque)
>>> static void vfio_intx_interrupt(void *opaque)
>>> {
>>>     VFIOPCIDevice *vdev = opaque;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>> Don't do that. Opaque data is already type checked when it is 
>> registered for the callback and cannot be changed so additional type 
>> checking here is just a performance hit without any advantage. It's OK 
>> to do it in less frequently called functions but don't add unnecessary 
>> casts to functions that can be called a lot.
> 
> This is true.
> 
> Any routines called before the first machine reset should fine
> to be changed but anything called at runtime should be carefully
> looked at.

I've covered this in my reply to Zoltan, so in the meantime what is the 
best way forward? Shall I continue with this series without the QOM cast 
patches for now so we can look at merging the other parts of the cleanup 
and revisit this later?

>> Regards,
>> BALATON Zoltan
>>
>>>     if (!event_notifier_test_and_clear(&vdev->intx.interrupt)) {
>>>         return;
>>> @@ -127,7 +128,7 @@ static void vfio_intx_interrupt(void *opaque)
>>>     trace_vfio_intx_interrupt(vdev->vbasedev.name, 'A' + vdev- 
>>> >intx.pin);
>>>
>>>     vdev->intx.pending = true;
>>> -    pci_irq_assert(&vdev->pdev);
>>> +    pci_irq_assert(pdev);
>>>     vfio_mmap_set_enabled(vdev, false);
>>>     if (vdev->intx.mmap_timeout) {
>>>         timer_mod(vdev->intx.mmap_timer,
>>> @@ -138,6 +139,7 @@ static void vfio_intx_interrupt(void *opaque)
>>> void vfio_pci_intx_eoi(VFIODevice *vbasedev)
>>> {
>>>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, 
>>> vbasedev);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>
>>>     if (!vdev->intx.pending) {
>>>         return;
>>> @@ -146,13 +148,14 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev)
>>>     trace_vfio_pci_intx_eoi(vbasedev->name);
>>>
>>>     vdev->intx.pending = false;
>>> -    pci_irq_deassert(&vdev->pdev);
>>> +    pci_irq_deassert(pdev);
>>>     vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>> }
>>>
>>> static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> #ifdef CONFIG_KVM
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     int irq_fd = event_notifier_get_fd(&vdev->intx.interrupt);
>>>
>>>     if (vdev->no_kvm_intx || !kvm_irqfds_enabled() ||
>>> @@ -165,7 +168,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice 
>>> *vdev, Error **errp)
>>>     qemu_set_fd_handler(irq_fd, NULL, NULL, vdev);
>>>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>>     vdev->intx.pending = false;
>>> -    pci_irq_deassert(&vdev->pdev);
>>> +    pci_irq_deassert(pdev);
>>>
>>>     /* Get an eventfd for resample/unmask */
>>>     if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 
>>> 0, errp)) {
>>> @@ -243,6 +246,8 @@ static bool 
>>> vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp)
>>> static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev)
>>> {
>>> #ifdef CONFIG_KVM
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +
>>>     if (!vdev->intx.kvm_accel) {
>>>         return;
>>>     }
>>> @@ -253,7 +258,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice 
>>> *vdev)
>>>      */
>>>     vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>>     vdev->intx.pending = false;
>>> -    pci_irq_deassert(&vdev->pdev);
>>> +    pci_irq_deassert(pdev);
>>>
>>>     /* Tell KVM to stop listening for an INTx irqfd */
>>>     if (kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev- 
>>> >intx.interrupt,
>>> @@ -309,7 +314,7 @@ static void vfio_intx_routing_notifier(PCIDevice 
>>> *pdev)
>>>         return;
>>>     }
>>>
>>> -    route = pci_device_route_intx_to_irq(&vdev->pdev, vdev->intx.pin);
>>> +    route = pci_device_route_intx_to_irq(pdev, vdev->intx.pin);
>>>
>>>     if (pci_intx_route_changed(&vdev->intx.route, &route)) {
>>>         vfio_intx_update(vdev, &route);
>>> @@ -326,7 +331,8 @@ static void vfio_irqchip_change(Notifier *notify, 
>>> void *data)
>>>
>>> static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> -    uint8_t pin = vfio_pci_read_config(&vdev->pdev, 
>>> PCI_INTERRUPT_PIN, 1);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +    uint8_t pin = vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1);
>>>     Error *err = NULL;
>>>     int32_t fd;
>>>
>>> @@ -344,7 +350,7 @@ 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);
>>> +    pci_config_set_interrupt_pin(pdev->config, pin);
>>>
>>> #ifdef CONFIG_KVM
>>>     /*
>>> @@ -352,7 +358,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, 
>>> Error **errp)
>>>      * where we won't actually use the result anyway.
>>>      */
>>>     if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) {
>>> -        vdev->intx.route = pci_device_route_intx_to_irq(&vdev->pdev,
>>> +        vdev->intx.route = pci_device_route_intx_to_irq(pdev,
>>>                                                         vdev->intx.pin);
>>>     }
>>> #endif
>>> @@ -392,13 +398,14 @@ skip_signaling:
>>>
>>> static void vfio_intx_disable(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     int fd;
>>>
>>>     timer_del(vdev->intx.mmap_timer);
>>>     vfio_intx_disable_kvm(vdev);
>>>     vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>>     vdev->intx.pending = false;
>>> -    pci_irq_deassert(&vdev->pdev);
>>> +    pci_irq_deassert(pdev);
>>>     vfio_mmap_set_enabled(vdev, true);
>>>
>>>     fd = event_notifier_get_fd(&vdev->intx.interrupt);
>>> @@ -422,6 +429,7 @@ static void vfio_msi_interrupt(void *opaque)
>>> {
>>>     VFIOMSIVector *vector = opaque;
>>>     VFIOPCIDevice *vdev = vector->vdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     MSIMessage (*get_msg)(PCIDevice *dev, unsigned vector);
>>>     void (*notify)(PCIDevice *dev, unsigned vector);
>>>     MSIMessage msg;
>>> @@ -436,9 +444,9 @@ static void vfio_msi_interrupt(void *opaque)
>>>         notify = msix_notify;
>>>
>>>         /* A masked vector firing needs to use the PBA, enable it */
>>> -        if (msix_is_masked(&vdev->pdev, nr)) {
>>> +        if (msix_is_masked(pdev, nr)) {
>>>             set_bit(nr, vdev->msix->pending);
>>> -            memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, true);
>>> +            memory_region_set_enabled(&pdev->msix_pba_mmio, true);
>>>             trace_vfio_msix_pba_enable(vdev->vbasedev.name);
>>>         }
>>>     } else if (vdev->interrupt == VFIO_INT_MSI) {
>>> @@ -448,9 +456,9 @@ static void vfio_msi_interrupt(void *opaque)
>>>         abort();
>>>     }
>>>
>>> -    msg = get_msg(&vdev->pdev, nr);
>>> +    msg = get_msg(pdev, nr);
>>>     trace_vfio_msi_interrupt(vdev->vbasedev.name, nr, msg.address, 
>>> msg.data);
>>> -    notify(&vdev->pdev, nr);
>>> +    notify(pdev, nr);
>>> }
>>>
>>> void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr)
>>> @@ -488,6 +496,7 @@ static int vfio_enable_msix_no_vec(VFIOPCIDevice 
>>> *vdev)
>>>
>>> static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     struct vfio_irq_set *irq_set;
>>>     int ret = 0, i, argsz;
>>>     int32_t *fds;
>>> @@ -530,7 +539,7 @@ static int vfio_enable_vectors(VFIOPCIDevice 
>>> *vdev, bool msix)
>>>          */
>>>         if (vdev->msi_vectors[i].use) {
>>>             if (vdev->msi_vectors[i].virq < 0 ||
>>> -                (msix && msix_is_masked(&vdev->pdev, i))) {
>>> +                (msix && msix_is_masked(pdev, i))) {
>>>                 fd = event_notifier_get_fd(&vdev- 
>>> >msi_vectors[i].interrupt);
>>>             } else {
>>>                 fd = event_notifier_get_fd(&vdev- 
>>> >msi_vectors[i].kvm_interrupt);
>>> @@ -550,12 +559,14 @@ static int vfio_enable_vectors(VFIOPCIDevice 
>>> *vdev, bool msix)
>>> void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector 
>>> *vector,
>>>                                int vector_n, bool msix)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +
>>>     if ((msix && vdev->no_kvm_msix) || (!msix && vdev->no_kvm_msi)) {
>>>         return;
>>>     }
>>>
>>>     vector->virq = kvm_irqchip_add_msi_route(&vfio_route_change,
>>> -                                             vector_n, &vdev->pdev);
>>> +                                             vector_n, pdev);
>>> }
>>>
>>> static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector, int nr)
>>> @@ -624,7 +635,7 @@ static void set_irq_signalling(VFIODevice 
>>> *vbasedev, VFIOMSIVector *vector,
>>> void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr)
>>> {
>>>     VFIOMSIVector *vector = &vdev->msi_vectors[nr];
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     Error *local_err = NULL;
>>>
>>>     vector->vdev = vdev;
>>> @@ -713,7 +724,7 @@ static int vfio_msix_vector_do_use(PCIDevice 
>>> *pdev, unsigned int nr,
>>>     clear_bit(nr, vdev->msix->pending);
>>>     if (find_first_bit(vdev->msix->pending,
>>>                        vdev->nr_vectors) == vdev->nr_vectors) {
>>> -        memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
>>> +        memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>>>         trace_vfio_msix_pba_disable(vdev->vbasedev.name);
>>>     }
>>>
>>> @@ -764,7 +775,9 @@ static void vfio_msix_vector_release(PCIDevice 
>>> *pdev, unsigned int nr)
>>>
>>> void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev)
>>> {
>>> -    msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +
>>> +    msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>>>                               vfio_msix_vector_release, NULL);
>>> }
>>>
>>> @@ -791,6 +804,7 @@ void 
>>> vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev)
>>>
>>> static void vfio_msix_enable(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     int ret;
>>>
>>>     vfio_disable_interrupts(vdev);
>>> @@ -807,7 +821,7 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>>>      */
>>>     vfio_pci_prepare_kvm_msi_virq_batch(vdev);
>>>
>>> -    if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
>>> +    if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
>>>                                   vfio_msix_vector_release, NULL)) {
>>>         error_report("vfio: msix_set_vector_notifiers failed");
>>>     }
>>> @@ -845,11 +859,12 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
>>>
>>> static void vfio_msi_enable(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     int ret, i;
>>>
>>>     vfio_disable_interrupts(vdev);
>>>
>>> -    vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev);
>>> +    vdev->nr_vectors = msi_nr_vectors_allocated(pdev);
>>> retry:
>>>     /*
>>>      * Setting vector notifiers needs to enable route for each vector.
>>> @@ -942,10 +957,11 @@ static void 
>>> vfio_msi_disable_common(VFIOPCIDevice *vdev)
>>>
>>> static void vfio_msix_disable(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     Error *err = NULL;
>>>     int i;
>>>
>>> -    msix_unset_vector_notifiers(&vdev->pdev);
>>> +    msix_unset_vector_notifiers(pdev);
>>>
>>>     /*
>>>      * MSI-X will only release vectors if MSI-X is still enabled on the
>>> @@ -953,8 +969,8 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev)
>>>      */
>>>     for (i = 0; i < vdev->nr_vectors; i++) {
>>>         if (vdev->msi_vectors[i].use) {
>>> -            vfio_msix_vector_release(&vdev->pdev, i);
>>> -            msix_vector_unuse(&vdev->pdev, i);
>>> +            vfio_msix_vector_release(pdev, i);
>>> +            msix_vector_unuse(pdev, i);
>>>         }
>>>     }
>>>
>>> @@ -991,6 +1007,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev)
>>>
>>> static void vfio_update_msi(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     int i;
>>>
>>>     for (i = 0; i < vdev->nr_vectors; i++) {
>>> @@ -1001,8 +1018,8 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
>>>             continue;
>>>         }
>>>
>>> -        msg = msi_get_message(&vdev->pdev, i);
>>> -        vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev);
>>> +        msg = msi_get_message(pdev, i);
>>> +        vfio_update_kvm_msi_virq(vector, msg, pdev);
>>>     }
>>> }
>>>
>>> @@ -1164,13 +1181,14 @@ static const MemoryRegionOps vfio_rom_ops = {
>>>
>>> static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>>     uint32_t orig, size = cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK);
>>>     char *name;
>>>
>>> -    if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
>>> +    if (pdev->romfile || !pdev->rom_bar) {
>>>         /* Since pci handles romfile, just print a message and return */
>>> -        if (vfio_opt_rom_in_denylist(vdev) && vdev->pdev.romfile) {
>>> +        if (vfio_opt_rom_in_denylist(vdev) && pdev->romfile) {
>>>             warn_report("Device at %s is known to cause system 
>>> instability"
>>>                         " issues during option rom execution",
>>>                         vdev->vbasedev.name);
>>> @@ -1199,7 +1217,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>>>     }
>>>
>>>     if (vfio_opt_rom_in_denylist(vdev)) {
>>> -        if (vdev->pdev.rom_bar > 0) {
>>> +        if (pdev->rom_bar > 0) {
>>>             warn_report("Device at %s is known to cause system 
>>> instability"
>>>                         " issues during option rom execution",
>>>                         vdev->vbasedev.name);
>>> @@ -1218,12 +1236,12 @@ static void vfio_pci_size_rom(VFIOPCIDevice 
>>> *vdev)
>>>
>>>     name = g_strdup_printf("vfio[%s].rom", vdev->vbasedev.name);
>>>
>>> -    memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev),
>>> +    memory_region_init_io(&pdev->rom, OBJECT(vdev),
>>>                           &vfio_rom_ops, vdev, name, size);
>>>     g_free(name);
>>>
>>> -    pci_register_bar(&vdev->pdev, PCI_ROM_SLOT,
>>> -                     PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom);
>>> +    pci_register_bar(pdev, PCI_ROM_SLOT,
>>> +                     PCI_BASE_ADDRESS_SPACE_MEMORY, &pdev->rom);
>>>
>>>     vdev->rom_read_failed = false;
>>> }
>>> @@ -1496,6 +1514,7 @@ static void 
>>> vfio_disable_interrupts(VFIOPCIDevice *vdev)
>>>
>>> static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     uint16_t ctrl;
>>>     bool msi_64bit, msi_maskbit;
>>>     int ret, entries;
>>> @@ -1516,7 +1535,7 @@ static bool vfio_msi_setup(VFIOPCIDevice *vdev, 
>>> int pos, Error **errp)
>>>
>>>     trace_vfio_msi_setup(vdev->vbasedev.name, pos);
>>>
>>> -    ret = msi_init(&vdev->pdev, pos, entries, msi_64bit, 
>>> msi_maskbit, &err);
>>> +    ret = msi_init(pdev, pos, entries, msi_64bit, msi_maskbit, &err);
>>>     if (ret < 0) {
>>>         if (ret == -ENOTSUP) {
>>>             return true;
>>> @@ -1709,6 +1728,7 @@ static bool 
>>> vfio_pci_relocate_msix(VFIOPCIDevice *vdev, Error **errp)
>>>  */
>>> static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     uint8_t pos;
>>>     uint16_t ctrl;
>>>     uint32_t table, pba;
>>> @@ -1716,7 +1736,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice 
>>> *vdev, Error **errp)
>>>     VFIOMSIXInfo *msix;
>>>     int ret;
>>>
>>> -    pos = pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX);
>>> +    pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
>>>     if (!pos) {
>>>         return true;
>>>     }
>>> @@ -1808,12 +1828,13 @@ static bool 
>>> vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
>>>
>>> static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     int ret;
>>>     Error *err = NULL;
>>>
>>>     vdev->msix->pending = g_new0(unsigned long,
>>>                                  BITS_TO_LONGS(vdev->msix->entries));
>>> -    ret = msix_init(&vdev->pdev, vdev->msix->entries,
>>> +    ret = msix_init(pdev, vdev->msix->entries,
>>>                     vdev->bars[vdev->msix->table_bar].mr,
>>>                     vdev->msix->table_bar, vdev->msix->table_offset,
>>>                     vdev->bars[vdev->msix->pba_bar].mr,
>>> @@ -1845,7 +1866,7 @@ static bool vfio_msix_setup(VFIOPCIDevice 
>>> *vdev, int pos, Error **errp)
>>>      * vector-use notifier is called, which occurs on unmask, we test 
>>> whether
>>>      * PBA emulation is needed and again disable if not.
>>>      */
>>> -    memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false);
>>> +    memory_region_set_enabled(&pdev->msix_pba_mmio, false);
>>>
>>>     /*
>>>      * The emulated machine may provide a paravirt interface for MSIX 
>>> setup
>>> @@ -1857,7 +1878,7 @@ static bool vfio_msix_setup(VFIOPCIDevice 
>>> *vdev, int pos, Error **errp)
>>>      */
>>>     if (object_property_get_bool(OBJECT(qdev_get_machine()),
>>>                                  "vfio-no-msix-emulation", NULL)) {
>>> -        memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false);
>>> +        memory_region_set_enabled(&pdev->msix_table_mmio, false);
>>>     }
>>>
>>>     return true;
>>> @@ -1865,10 +1886,12 @@ static bool vfio_msix_setup(VFIOPCIDevice 
>>> *vdev, int pos, Error **errp)
>>>
>>> void vfio_pci_teardown_msi(VFIOPCIDevice *vdev)
>>> {
>>> -    msi_uninit(&vdev->pdev);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +
>>> +    msi_uninit(pdev);
>>>
>>>     if (vdev->msix) {
>>> -        msix_uninit(&vdev->pdev,
>>> +        msix_uninit(pdev,
>>>                     vdev->bars[vdev->msix->table_bar].mr,
>>>                     vdev->bars[vdev->msix->pba_bar].mr);
>>>         g_free(vdev->msix->pending);
>>> @@ -1929,6 +1952,7 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev)
>>>
>>> static void vfio_bar_register(VFIOPCIDevice *vdev, int nr)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     VFIOBAR *bar = &vdev->bars[nr];
>>>     char *name;
>>>
>>> @@ -1950,7 +1974,7 @@ static void vfio_bar_register(VFIOPCIDevice 
>>> *vdev, int nr)
>>>         }
>>>     }
>>>
>>> -    pci_register_bar(&vdev->pdev, nr, bar->type, bar->mr);
>>> +    pci_register_bar(pdev, nr, bar->type, bar->mr);
>>> }
>>>
>>> static void vfio_bars_register(VFIOPCIDevice *vdev)
>>> @@ -1964,6 +1988,7 @@ static void vfio_bars_register(VFIOPCIDevice 
>>> *vdev)
>>>
>>> void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     int i;
>>>
>>>     for (i = 0; i < PCI_ROM_SLOT; i++) {
>>> @@ -1977,7 +2002,7 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev)
>>>     }
>>>
>>>     if (vdev->vga) {
>>> -        pci_unregister_vga(&vdev->pdev);
>>> +        pci_unregister_vga(pdev);
>>>         vfio_vga_quirk_exit(vdev);
>>>     }
>>> }
>>> @@ -2049,8 +2074,10 @@ static void vfio_set_word_bits(uint8_t *buf, 
>>> uint16_t val, uint16_t mask)
>>> static void vfio_add_emulated_word(VFIOPCIDevice *vdev, int pos,
>>>                                    uint16_t val, uint16_t mask)
>>> {
>>> -    vfio_set_word_bits(vdev->pdev.config + pos, val, mask);
>>> -    vfio_set_word_bits(vdev->pdev.wmask + pos, ~mask, mask);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +
>>> +    vfio_set_word_bits(pdev->config + pos, val, mask);
>>> +    vfio_set_word_bits(pdev->wmask + pos, ~mask, mask);
>>>     vfio_set_word_bits(vdev->emulated_config_bits + pos, mask, mask);
>>> }
>>>
>>> @@ -2062,8 +2089,10 @@ static void vfio_set_long_bits(uint8_t *buf, 
>>> uint32_t val, uint32_t mask)
>>> static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos,
>>>                                    uint32_t val, uint32_t mask)
>>> {
>>> -    vfio_set_long_bits(vdev->pdev.config + pos, val, mask);
>>> -    vfio_set_long_bits(vdev->pdev.wmask + pos, ~mask, mask);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +
>>> +    vfio_set_long_bits(pdev->config + pos, val, mask);
>>> +    vfio_set_long_bits(pdev->wmask + pos, ~mask, mask);
>>>     vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask);
>>> }
>>>
>>> @@ -2071,7 +2100,8 @@ static void 
>>> vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>>> {
>>>     struct vfio_device_info_cap_pci_atomic_comp *cap;
>>>     g_autofree struct vfio_device_info *info = NULL;
>>> -    PCIBus *bus = pci_get_bus(&vdev->pdev);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +    PCIBus *bus = pci_get_bus(pdev);
>>>     PCIDevice *parent = bus->parent_dev;
>>>     struct vfio_info_cap_header *hdr;
>>>     uint32_t mask = 0;
>>> @@ -2087,8 +2117,8 @@ static void 
>>> vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>>>     if (pci_bus_is_root(bus) || !parent || !parent->exp.exp_cap ||
>>>         pcie_cap_get_type(parent) != PCI_EXP_TYPE_ROOT_PORT ||
>>>         pcie_cap_get_version(parent) != PCI_EXP_FLAGS_VER2 ||
>>> -        vdev->pdev.devfn ||
>>> -        vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>>> +        pdev->devfn ||
>>> +        pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>>>         return;
>>>     }
>>>
>>> @@ -2132,8 +2162,10 @@ static void 
>>> vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
>>>
>>> static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +
>>>     if (vdev->clear_parent_atomics_on_exit) {
>>> -        PCIDevice *parent = pci_get_bus(&vdev->pdev)->parent_dev;
>>> +        PCIDevice *parent = pci_get_bus(pdev)->parent_dev;
>>>         uint8_t *pos = parent->config + parent->exp.exp_cap + 
>>> PCI_EXP_DEVCAP2;
>>>
>>>         pci_long_test_and_clear_mask(pos, 
>>> PCI_EXP_DEVCAP2_ATOMIC_COMP32 |
>>> @@ -2145,10 +2177,11 @@ static void 
>>> vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev)
>>> static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t 
>>> size,
>>>                                 Error **errp)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     uint16_t flags;
>>>     uint8_t type;
>>>
>>> -    flags = pci_get_word(vdev->pdev.config + pos + PCI_CAP_FLAGS);
>>> +    flags = pci_get_word(pdev->config + pos + PCI_CAP_FLAGS);
>>>     type = (flags & PCI_EXP_FLAGS_TYPE) >> 4;
>>>
>>>     if (type != PCI_EXP_TYPE_ENDPOINT &&
>>> @@ -2160,8 +2193,8 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice 
>>> *vdev, int pos, uint8_t size,
>>>         return false;
>>>     }
>>>
>>> -    if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) {
>>> -        PCIBus *bus = pci_get_bus(&vdev->pdev);
>>> +    if (!pci_bus_is_express(pci_get_bus(pdev))) {
>>> +        PCIBus *bus = pci_get_bus(pdev);
>>>         PCIDevice *bridge;
>>>
>>>         /*
>>> @@ -2193,7 +2226,7 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice 
>>> *vdev, int pos, uint8_t size,
>>>             return true;
>>>         }
>>>
>>> -    } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) {
>>> +    } else if (pci_bus_is_root(pci_get_bus(pdev))) {
>>>         /*
>>>          * On a Root Complex bus Endpoints become Root Complex 
>>> Integrated
>>>          * Endpoints, which changes the type and clears the LNK & 
>>> LNK2 fields.
>>> @@ -2261,20 +2294,20 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice 
>>> *vdev, int pos, uint8_t size,
>>>                                1, PCI_EXP_FLAGS_VERS);
>>>     }
>>>
>>> -    pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size,
>>> -                             errp);
>>> +    pos = pci_add_capability(pdev, PCI_CAP_ID_EXP, pos, size, errp);
>>>     if (pos < 0) {
>>>         return false;
>>>     }
>>>
>>> -    vdev->pdev.exp.exp_cap = pos;
>>> +    pdev->exp.exp_cap = pos;
>>>
>>>     return true;
>>> }
>>>
>>> static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos)
>>> {
>>> -    uint32_t cap = pci_get_long(vdev->pdev.config + pos + 
>>> PCI_EXP_DEVCAP);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +    uint32_t cap = pci_get_long(pdev->config + pos + PCI_EXP_DEVCAP);
>>>
>>>     if (cap & PCI_EXP_DEVCAP_FLR) {
>>>         trace_vfio_check_pcie_flr(vdev->vbasedev.name);
>>> @@ -2284,7 +2317,8 @@ static void vfio_check_pcie_flr(VFIOPCIDevice 
>>> *vdev, uint8_t pos)
>>>
>>> static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos)
>>> {
>>> -    uint16_t csr = pci_get_word(vdev->pdev.config + pos + PCI_PM_CTRL);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +    uint16_t csr = pci_get_word(pdev->config + pos + PCI_PM_CTRL);
>>>
>>>     if (!(csr & PCI_PM_CTRL_NO_SOFT_RESET)) {
>>>         trace_vfio_check_pm_reset(vdev->vbasedev.name);
>>> @@ -2294,7 +2328,8 @@ static void vfio_check_pm_reset(VFIOPCIDevice 
>>> *vdev, uint8_t pos)
>>>
>>> static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos)
>>> {
>>> -    uint8_t cap = pci_get_byte(vdev->pdev.config + pos + PCI_AF_CAP);
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>> +    uint8_t cap = pci_get_byte(pdev->config + pos + PCI_AF_CAP);
>>>
>>>     if ((cap & PCI_AF_CAP_TP) && (cap & PCI_AF_CAP_FLR)) {
>>>         trace_vfio_check_af_flr(vdev->vbasedev.name);
>>> @@ -2305,7 +2340,7 @@ static void vfio_check_af_flr(VFIOPCIDevice 
>>> *vdev, uint8_t pos)
>>> static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
>>>                                          uint8_t size, Error **errp)
>>> {
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>
>>>     pos = pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp);
>>>     if (pos < 0) {
>>> @@ -2327,7 +2362,7 @@ static bool 
>>> vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos,
>>> static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error 
>>> **errp)
>>> {
>>>     ERRP_GUARD();
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     uint8_t cap_id, next, size;
>>>     bool ret;
>>>
>>> @@ -2413,17 +2448,18 @@ static bool vfio_add_std_cap(VFIOPCIDevice 
>>> *vdev, uint8_t pos, Error **errp)
>>>
>>> static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     uint32_t ctrl;
>>>     int i, nbar;
>>>
>>> -    ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL);
>>> +    ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL);
>>>     nbar = (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> 
>>> PCI_REBAR_CTRL_NBAR_SHIFT;
>>>
>>>     for (i = 0; i < nbar; i++) {
>>>         uint32_t cap;
>>>         int size;
>>>
>>> -        ctrl = pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL 
>>> + (i * 8));
>>> +        ctrl = pci_get_long(pdev->config + pos + PCI_REBAR_CTRL + (i 
>>> * 8));
>>>         size = (ctrl & PCI_REBAR_CTRL_BAR_SIZE) >> 
>>> PCI_REBAR_CTRL_BAR_SHIFT;
>>>
>>>         /* The cap register reports sizes 1MB to 128TB, with 4 
>>> reserved bits */
>>> @@ -2461,7 +2497,7 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice 
>>> *vdev, uint16_t pos)
>>>
>>> static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
>>> {
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     uint32_t header;
>>>     uint16_t cap_id, next, size;
>>>     uint8_t cap_ver;
>>> @@ -2555,7 +2591,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
>>>
>>> bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>
>>>     if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) ||
>>>         !pdev->config[PCI_CAPABILITY_LIST]) {
>>> @@ -2572,7 +2608,7 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice 
>>> *vdev, Error **errp)
>>>
>>> void vfio_pci_pre_reset(VFIOPCIDevice *vdev)
>>> {
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     uint16_t cmd;
>>>
>>>     vfio_disable_interrupts(vdev);
>>> @@ -2789,7 +2825,7 @@ static int vfio_pci_save_config(VFIODevice 
>>> *vbasedev, QEMUFile *f, Error **errp)
>>> static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f)
>>> {
>>>     VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, 
>>> vbasedev);
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     pcibus_t old_addr[PCI_NUM_REGIONS - 1];
>>>     int bar, ret;
>>>
>>> @@ -2837,6 +2873,7 @@ static VFIODeviceOps vfio_pci_ops = {
>>>
>>> bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>>     struct vfio_region_info *reg_info = NULL;
>>>     int ret;
>>> @@ -2893,7 +2930,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, 
>>> Error **errp)
>>>                           "vfio-vga-io@0x3c0",
>>>                           QEMU_PCI_VGA_IO_HI_SIZE);
>>>
>>> -    pci_register_vga(&vdev->pdev, &vdev->vga- 
>>> >region[QEMU_PCI_VGA_MEM].mem,
>>> +    pci_register_vga(pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
>>>                      &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
>>>                      &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
>>>
>>> @@ -2902,6 +2939,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, 
>>> Error **errp)
>>>
>>> bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>>     struct vfio_region_info *reg_info = NULL;
>>>     struct vfio_irq_info irq_info;
>>> @@ -2953,7 +2991,7 @@ bool vfio_pci_populate_device(VFIOPCIDevice 
>>> *vdev, Error **errp)
>>>
>>>     vdev->config_size = reg_info->size;
>>>     if (vdev->config_size == PCI_CONFIG_SPACE_SIZE) {
>>> -        vdev->pdev.cap_present &= ~QEMU_PCI_CAP_EXPRESS;
>>> +        pdev->cap_present &= ~QEMU_PCI_CAP_EXPRESS;
>>>     }
>>>     vdev->config_offset = reg_info->offset;
>>>
>>> @@ -3156,16 +3194,16 @@ static void 
>>> vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
>>>
>>> bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>     VFIODevice *vbasedev = &vdev->vbasedev;
>>>     uint32_t config_space_size;
>>>     int ret;
>>>
>>> -    config_space_size = MIN(pci_config_size(&vdev->pdev), vdev- 
>>> >config_size);
>>> +    config_space_size = MIN(pci_config_size(pdev), vdev->config_size);
>>>
>>>     /* Get a copy of config space */
>>>     ret = vfio_pci_config_space_read(vdev, 0, config_space_size,
>>> -                                     vdev->pdev.config);
>>> +                                     pdev->config);
>>>     if (ret < (int)config_space_size) {
>>>         ret = ret < 0 ? -ret : EFAULT;
>>>         error_setg_errno(errp, ret, "failed to read device config 
>>> space");
>>> @@ -3233,10 +3271,10 @@ bool vfio_pci_config_setup(VFIOPCIDevice 
>>> *vdev, Error **errp)
>>>                                               
>>> PCI_HEADER_TYPE_MULTI_FUNCTION;
>>>
>>>     /* Restore or clear multifunction, this is always controlled by 
>>> QEMU */
>>> -    if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>>> -        vdev->pdev.config[PCI_HEADER_TYPE] |= 
>>> PCI_HEADER_TYPE_MULTI_FUNCTION;
>>> +    if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) {
>>> +        pdev->config[PCI_HEADER_TYPE] |= 
>>> PCI_HEADER_TYPE_MULTI_FUNCTION;
>>>     } else {
>>> -        vdev->pdev.config[PCI_HEADER_TYPE] &= 
>>> ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>>> +        pdev->config[PCI_HEADER_TYPE] &= 
>>> ~PCI_HEADER_TYPE_MULTI_FUNCTION;
>>>     }
>>>
>>>     /*
>>> @@ -3244,8 +3282,8 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, 
>>> Error **errp)
>>>      * BAR, such as might be the case with the option ROM, we can get
>>>      * confusing, unwritable, residual addresses from the host here.
>>>      */
>>> -    memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24);
>>> -    memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4);
>>> +    memset(&pdev->config[PCI_BASE_ADDRESS_0], 0, 24);
>>> +    memset(&pdev->config[PCI_ROM_ADDRESS], 0, 4);
>>>
>>>     vfio_pci_size_rom(vdev);
>>>
>>> @@ -3262,7 +3300,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, 
>>> Error **errp)
>>>
>>> bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp)
>>> {
>>> -    PCIDevice *pdev = &vdev->pdev;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>>
>>>     /* QEMU emulates all of MSI & MSIX */
>>>     if (pdev->cap_present & QEMU_PCI_CAP_MSIX) {
>>> @@ -3275,10 +3313,10 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice 
>>> *vdev, Error **errp)
>>>                vdev->msi_cap_size);
>>>     }
>>>
>>> -    if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) {
>>> +    if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) {
>>>         vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
>>>                                              vfio_intx_mmap_enable, 
>>> vdev);
>>> -        pci_device_set_intx_routing_notifier(&vdev->pdev,
>>> +        pci_device_set_intx_routing_notifier(pdev,
>>>                                              
>>> vfio_intx_routing_notifier);
>>>         vdev->irqchip_change_notifier.notify = vfio_irqchip_change;
>>>         kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
>>> @@ -3290,7 +3328,7 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice 
>>> *vdev, Error **errp)
>>>          */
>>>         if (!cpr_is_incoming() && !vfio_intx_enable(vdev, errp)) {
>>>             timer_free(vdev->intx.mmap_timer);
>>> -            pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>>> +            pci_device_set_intx_routing_notifier(pdev, NULL);
>>>             kvm_irqchip_remove_change_notifier(&vdev- 
>>> >irqchip_change_notifier);
>>>             return false;
>>>         }
>>> @@ -3440,7 +3478,7 @@ out_deregister:
>>>     if (vdev->interrupt == VFIO_INT_INTx) {
>>>         vfio_intx_disable(vdev);
>>>     }
>>> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>>> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>>>     if (vdev->irqchip_change_notifier.notify) {
>>>         kvm_irqchip_remove_change_notifier(&vdev- 
>>> >irqchip_change_notifier);
>>>     }
>>> @@ -3472,7 +3510,7 @@ static void vfio_exitfn(PCIDevice *pdev)
>>>
>>>     vfio_unregister_req_notifier(vdev);
>>>     vfio_unregister_err_notifier(vdev);
>>> -    pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>>> +    pci_device_set_intx_routing_notifier(pdev, NULL);
>>>     if (vdev->irqchip_change_notifier.notify) {
>>>         kvm_irqchip_remove_change_notifier(&vdev- 
>>> >irqchip_change_notifier);
>>>     }


ATB,

Mark.



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

* Re: [PATCH 16/22] vfio/pci.c: use QOM casts where appropriate
  2025-08-29 11:07     ` Mark Cave-Ayland
@ 2025-08-29 14:31       ` BALATON Zoltan
  2025-09-01 10:24       ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: BALATON Zoltan @ 2025-08-29 14:31 UTC (permalink / raw)
  To: Mark Cave-Ayland
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, clg, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2119 bytes --]

On Fri, 29 Aug 2025, Mark Cave-Ayland wrote:
> On 15/07/2025 14:38, BALATON Zoltan wrote:
>
>> On Tue, 15 Jul 2025, Mark Cave-Ayland wrote:
>>> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
>>> accessing pdev directly.
>>> 
>>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>>> ---
>>> hw/vfio/pci.c | 202 ++++++++++++++++++++++++++++++--------------------
>>> 1 file changed, 120 insertions(+), 82 deletions(-)
>>> 
>>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>>> index 1093b28df7..fb9eb58da5 100644
>>> --- a/hw/vfio/pci.c
>>> +++ b/hw/vfio/pci.c
>>> @@ -119,6 +119,7 @@ static void vfio_intx_mmap_enable(void *opaque)
>>> static void vfio_intx_interrupt(void *opaque)
>>> {
>>>     VFIOPCIDevice *vdev = opaque;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>> 
>> Don't do that. Opaque data is already type checked when it is registered 
>> for the callback and cannot be changed so additional type checking here is 
>> just a performance hit without any advantage. It's OK to do it in less 
>> frequently called functions but don't add unnecessary casts to functions 
>> that can be called a lot.
>
> In general the QOM casts fall into the noise in a standard profile, but I can 
> see how it could be possible they might show up in the interrupt fast path.
>
> I'll look at getting a vfio-pci perf test set up here to see if there is a 
> noticeable effect in this case, and if so think about what the best approach 
> is.

In general, casting opaque pointer of a callback is unnecessary because 
these can be checked once when registered so it's not needed to check 
again at every use. I think this should really be recommended practice to 
not use QOM casts for these opaque pointers of callbacks. A lot of these 
are also in hot path so not adding unnecessary checks is a good idea. In 
this case when you're in the vfio implementation what's wrong with 
accessing internal field of vfio anyway? An object's implemenattion should 
be able to access its own fields so maybe the current way is OK and most 
of this patch is not needed at all.

Regards,
BALATON Zoltan

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

* Re: [PATCH 16/22] vfio/pci.c: use QOM casts where appropriate
  2025-08-29 11:07     ` Mark Cave-Ayland
  2025-08-29 14:31       ` BALATON Zoltan
@ 2025-09-01 10:24       ` Cédric Le Goater
  1 sibling, 0 replies; 73+ messages in thread
From: Cédric Le Goater @ 2025-09-01 10:24 UTC (permalink / raw)
  To: Mark Cave-Ayland, BALATON Zoltan
  Cc: npiggin, danielhb413, harshpb, mjrosato, farman, pasic,
	borntraeger, thuth, richard.henderson, david, iii, john.levon,
	thanos.makatos, alex.williamson, steven.sistare, tomitamoeko,
	qemu-ppc, qemu-s390x, qemu-devel

On 8/29/25 13:07, Mark Cave-Ayland wrote:
> On 15/07/2025 14:38, BALATON Zoltan wrote:
> 
>> On Tue, 15 Jul 2025, Mark Cave-Ayland wrote:
>>> Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of
>>> accessing pdev directly.
>>>
>>> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
>>> ---
>>> hw/vfio/pci.c | 202 ++++++++++++++++++++++++++++++--------------------
>>> 1 file changed, 120 insertions(+), 82 deletions(-)
>>>
>>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>>> index 1093b28df7..fb9eb58da5 100644
>>> --- a/hw/vfio/pci.c
>>> +++ b/hw/vfio/pci.c
>>> @@ -119,6 +119,7 @@ static void vfio_intx_mmap_enable(void *opaque)
>>> static void vfio_intx_interrupt(void *opaque)
>>> {
>>>     VFIOPCIDevice *vdev = opaque;
>>> +    PCIDevice *pdev = PCI_DEVICE(vdev);
>>
>> Don't do that. Opaque data is already type checked when it is registered for the callback and cannot be changed so additional type checking here is just a performance hit without any advantage. It's OK to do it in less frequently called functions but don't add unnecessary casts to functions that can be called a lot.
> 
> In general the QOM casts fall into the noise in a standard profile, but I can see how it could be possible they might show up in the interrupt fast path.
> 
> I'll look at getting a vfio-pci perf test set up here to see if there is a noticeable effect in this case, and if so think about what the best approach is.

Booting with 'pci=nomsi' and running iperf should give some info
on INTx performance.

Thanks,

C.



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

end of thread, other threads:[~2025-09-01 10:25 UTC | newest]

Thread overview: 73+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15  9:25 [PATCH 00/22] vfio: improve use of QOM and coding guidelines Mark Cave-Ayland
2025-07-15  9:25 ` [PATCH 01/22] vfio/vfio-container-base.h: update VFIOContainerBase declaration Mark Cave-Ayland
2025-08-11 11:45   ` Cédric Le Goater
2025-08-11 11:56   ` Cédric Le Goater
2025-08-29 11:10     ` Mark Cave-Ayland
2025-07-15  9:25 ` [PATCH 02/22] vfio/vfio-container.h: update VFIOContainer declaration Mark Cave-Ayland
2025-07-15  9:39   ` Philippe Mathieu-Daudé
2025-08-11 11:45   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 03/22] hw/vfio/cpr-legacy.c: use QOM casts where appropriate Mark Cave-Ayland
2025-07-15 12:36   ` Steven Sistare
2025-08-11 11:45   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 04/22] hw/vfio/container.c: " Mark Cave-Ayland
2025-08-11 12:19   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 05/22] ppc/spapr_pci_vfio.c: " Mark Cave-Ayland
2025-07-16  7:58   ` Harsh Prateek Bora
2025-08-11 12:19   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 06/22] vfio/spapr.c: " Mark Cave-Ayland
2025-07-16  8:01   ` Harsh Prateek Bora
2025-08-11 12:20   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 07/22] vfio/vfio-container.h: rename VFIOContainer bcontainer field to parent_obj Mark Cave-Ayland
2025-07-15  9:39   ` Philippe Mathieu-Daudé
2025-08-11 12:23   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 08/22] vfio-user/container.h: update VFIOUserContainer declaration Mark Cave-Ayland
2025-07-15  9:39   ` Philippe Mathieu-Daudé
2025-07-15 12:57   ` John Levon
2025-08-11 12:23   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 09/22] vfio/container.c: use QOM casts where appropriate Mark Cave-Ayland
2025-07-15 14:13   ` John Levon
2025-08-28 15:14     ` Mark Cave-Ayland
2025-08-28 15:25       ` John Levon
2025-08-11 12:23   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 10/22] vfio-user/container.h: rename VFIOUserContainer bcontainer field to parent_obj Mark Cave-Ayland
2025-07-15  9:41   ` Philippe Mathieu-Daudé
2025-07-15 14:13   ` John Levon
2025-08-11 12:23   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 11/22] vfio-user/pci.c: update VFIOUserPCIDevice declaration Mark Cave-Ayland
2025-07-15  9:42   ` Philippe Mathieu-Daudé
2025-07-15  9:43     ` Philippe Mathieu-Daudé
2025-07-15 13:35   ` BALATON Zoltan
2025-07-15 14:15   ` John Levon
2025-08-11 12:24   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 12/22] vfio-user/pci.c: use QOM casts where appropriate Mark Cave-Ayland
2025-07-15 14:15   ` John Levon
2025-07-15  9:25 ` [PATCH 13/22] vfio-user/pci.c: rename VFIOUserPCIDevice device field to parent_obj Mark Cave-Ayland
2025-07-15  9:42   ` Philippe Mathieu-Daudé
2025-07-15 14:15   ` John Levon
2025-08-11 12:25   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 14/22] vfio/pci.h: update VFIOPCIDevice declaration Mark Cave-Ayland
2025-07-15  9:44   ` Philippe Mathieu-Daudé
2025-08-11 12:25   ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 15/22] vfio/pci.h: use QOM casts where appropriate Mark Cave-Ayland
2025-07-15  9:25 ` [PATCH 16/22] vfio/pci.c: " Mark Cave-Ayland
2025-07-15 13:38   ` BALATON Zoltan
2025-08-11 12:45     ` Cédric Le Goater
2025-08-29 11:13       ` Mark Cave-Ayland
2025-08-29 11:07     ` Mark Cave-Ayland
2025-08-29 14:31       ` BALATON Zoltan
2025-09-01 10:24       ` Cédric Le Goater
2025-07-15  9:25 ` [PATCH 17/22] vfio/pci-quirks.c: " Mark Cave-Ayland
2025-07-15  9:25 ` [PATCH 18/22] vfio/cpr.c: " Mark Cave-Ayland
2025-07-15 12:36   ` Steven Sistare
2025-07-15  9:25 ` [PATCH 19/22] vfio/igd.c: " Mark Cave-Ayland
2025-07-18 15:26   ` Tomita Moeko
2025-07-15  9:26 ` [PATCH 20/22] vfio-user/pci.c: " Mark Cave-Ayland
2025-07-15 14:17   ` John Levon
2025-07-15  9:26 ` [PATCH 21/22] s390x/s390-pci-vfio.c: " Mark Cave-Ayland
2025-07-15 13:29   ` Eric Farman
2025-07-15 14:19   ` Matthew Rosato
2025-07-15  9:26 ` [PATCH 22/22] vfio/pci.h: rename VFIOPCIDevice pdev field to parent_obj Mark Cave-Ayland
2025-07-15  9:44   ` Philippe Mathieu-Daudé
2025-07-15 12:36   ` Steven Sistare
2025-08-11 12:46   ` Cédric Le Goater
2025-07-15 14:31 ` [PATCH 00/22] vfio: improve use of QOM and coding guidelines Cédric Le Goater

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