qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
	"Mark Cave-Ayland" <mark.caveayland@nutanix.com>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 08/29] vfio/iommufd.c: use QOM casts where appropriate
Date: Fri, 26 Sep 2025 07:33:37 +0200	[thread overview]
Message-ID: <20250926053358.308198-9-clg@redhat.com> (raw)
In-Reply-To: <20250926053358.308198-1-clg@redhat.com>

From: Mark Cave-Ayland <mark.caveayland@nutanix.com>

Use QOM casts to convert between VFIOIOMMUFDContainer and 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>
Link: https://lore.kernel.org/qemu-devel/20250925113159.1760317-8-mark.caveayland@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/iommufd.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 7f2243d9d197d9aced99d8d8a9065e7e9d888e97..f0ffe2359196505468dd5ed159440f4655847d42 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -38,8 +38,7 @@ static int iommufd_cdev_map(const VFIOContainer *bcontainer, hwaddr iova,
                             ram_addr_t size, void *vaddr, bool readonly,
                             MemoryRegion *mr)
 {
-    const VFIOIOMMUFDContainer *container =
-        container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
+    const VFIOIOMMUFDContainer *container = VFIO_IOMMU_IOMMUFD(bcontainer);
 
     return iommufd_backend_map_dma(container->be,
                                    container->ioas_id,
@@ -50,8 +49,7 @@ static int iommufd_cdev_map_file(const VFIOContainer *bcontainer,
                                  hwaddr iova, ram_addr_t size,
                                  int fd, unsigned long start, bool readonly)
 {
-    const VFIOIOMMUFDContainer *container =
-        container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
+    const VFIOIOMMUFDContainer *container = VFIO_IOMMU_IOMMUFD(bcontainer);
 
     return iommufd_backend_map_file_dma(container->be,
                                         container->ioas_id,
@@ -62,8 +60,7 @@ static int iommufd_cdev_unmap(const VFIOContainer *bcontainer,
                               hwaddr iova, ram_addr_t size,
                               IOMMUTLBEntry *iotlb, bool unmap_all)
 {
-    const VFIOIOMMUFDContainer *container =
-        container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
+    const VFIOIOMMUFDContainer *container = VFIO_IOMMU_IOMMUFD(bcontainer);
 
     /* unmap in halves */
     if (unmap_all) {
@@ -162,8 +159,7 @@ static bool iommufd_hwpt_dirty_tracking(VFIOIOASHwpt *hwpt)
 static int iommufd_set_dirty_page_tracking(const VFIOContainer *bcontainer,
                                            bool start, Error **errp)
 {
-    const VFIOIOMMUFDContainer *container =
-        container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
+    const VFIOIOMMUFDContainer *container = VFIO_IOMMU_IOMMUFD(bcontainer);
     VFIOIOASHwpt *hwpt;
 
     QLIST_FOREACH(hwpt, &container->hwpt_list, next) {
@@ -194,9 +190,7 @@ static int iommufd_query_dirty_bitmap(const VFIOContainer *bcontainer,
                                       VFIOBitmap *vbmap, hwaddr iova,
                                       hwaddr size, Error **errp)
 {
-    VFIOIOMMUFDContainer *container = container_of(bcontainer,
-                                                   VFIOIOMMUFDContainer,
-                                                   bcontainer);
+    VFIOIOMMUFDContainer *container = VFIO_IOMMU_IOMMUFD(bcontainer);
     unsigned long page_size = qemu_real_host_page_size();
     VFIOIOASHwpt *hwpt;
 
@@ -324,6 +318,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
 {
     ERRP_GUARD();
     IOMMUFDBackend *iommufd = vbasedev->iommufd;
+    VFIOContainer *bcontainer = VFIO_IOMMU(container);
     uint32_t type, flags = 0;
     uint64_t hw_caps;
     VFIOIOASHwpt *hwpt;
@@ -408,9 +403,9 @@ skip_alloc:
     vbasedev->iommu_dirty_tracking = iommufd_hwpt_dirty_tracking(hwpt);
     QLIST_INSERT_HEAD(&hwpt->device_list, vbasedev, hwpt_next);
     QLIST_INSERT_HEAD(&container->hwpt_list, hwpt, next);
-    container->bcontainer.dirty_pages_supported |=
+    bcontainer->dirty_pages_supported |=
                                 vbasedev->iommu_dirty_tracking;
-    if (container->bcontainer.dirty_pages_supported &&
+    if (bcontainer->dirty_pages_supported &&
         !vbasedev->iommu_dirty_tracking) {
         warn_report("IOMMU instance for device %s doesn't support dirty tracking",
                     vbasedev->name);
@@ -464,7 +459,7 @@ static void iommufd_cdev_detach_container(VFIODevice *vbasedev,
 
 static void iommufd_cdev_container_destroy(VFIOIOMMUFDContainer *container)
 {
-    VFIOContainer *bcontainer = &container->bcontainer;
+    VFIOContainer *bcontainer = VFIO_IOMMU(container);
 
     if (!QLIST_EMPTY(&bcontainer->device_list)) {
         return;
@@ -486,7 +481,7 @@ static int iommufd_cdev_ram_block_discard_disable(bool state)
 static bool iommufd_cdev_get_info_iova_range(VFIOIOMMUFDContainer *container,
                                              uint32_t ioas_id, Error **errp)
 {
-    VFIOContainer *bcontainer = &container->bcontainer;
+    VFIOContainer *bcontainer = VFIO_IOMMU(container);
     g_autofree struct iommu_ioas_iova_ranges *info = NULL;
     struct iommu_iova_range *iova_ranges;
     int sz, fd = container->be->fd;
@@ -559,7 +554,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
 
     /* try to attach to an existing container in this space */
     QLIST_FOREACH(bcontainer, &space->containers, next) {
-        container = container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
+        container = VFIO_IOMMU_IOMMUFD(bcontainer);
         if (VFIO_IOMMU_GET_CLASS(bcontainer) != iommufd_vioc ||
             vbasedev->iommufd != container->be) {
             continue;
@@ -609,7 +604,7 @@ skip_ioas_alloc:
     QLIST_INIT(&container->hwpt_list);
     vbasedev->cpr.ioas_id = ioas_id;
 
-    bcontainer = &container->bcontainer;
+    bcontainer = VFIO_IOMMU(container);
     vfio_address_space_insert(space, bcontainer);
 
     if (!iommufd_cdev_attach_container(vbasedev, container, errp)) {
@@ -689,9 +684,8 @@ static void iommufd_cdev_detach(VFIODevice *vbasedev)
 {
     VFIOContainer *bcontainer = vbasedev->bcontainer;
     VFIOAddressSpace *space = bcontainer->space;
-    VFIOIOMMUFDContainer *container = container_of(bcontainer,
-                                                   VFIOIOMMUFDContainer,
-                                                   bcontainer);
+    VFIOIOMMUFDContainer *container = VFIO_IOMMU_IOMMUFD(bcontainer);
+
     vfio_device_unprepare(vbasedev);
 
     if (!vbasedev->ram_block_discard_allowed) {
-- 
2.51.0



  parent reply	other threads:[~2025-09-26  5:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26  5:33 [PULL 00/29] vfio queue Cédric Le Goater
2025-09-26  5:33 ` [PULL 01/29] tests/functional: add a vfio-user smoke test Cédric Le Goater
2025-09-26  5:33 ` [PULL 02/29] include/hw/vfio/vfio-container.h: rename VFIOContainer to VFIOLegacyContainer Cédric Le Goater
2025-09-26  5:33 ` [PULL 03/29] include/hw/vfio/vfio-container-base.h: rename VFIOContainerBase to VFIOContainer Cédric Le Goater
2025-09-26  5:33 ` [PULL 04/29] include/hw/vfio/vfio-container.h: rename file to vfio-container-legacy.h Cédric Le Goater
2025-09-26  5:33 ` [PULL 05/29] include/hw/vfio/vfio-container-base.h: rename file to vfio-container.h Cédric Le Goater
2025-09-26  5:33 ` [PULL 06/29] hw/vfio/container.c: rename file to container-legacy.c Cédric Le Goater
2025-09-26  5:33 ` [PULL 07/29] hw/vfio/container-base.c: rename file to container.c Cédric Le Goater
2025-09-26  5:33 ` Cédric Le Goater [this message]
2025-09-26  5:33 ` [PULL 09/29] vfio/cpr-iommufd.c: use QOM casts where appropriate Cédric Le Goater
2025-09-26  5:33 ` [PULL 10/29] vfio/vfio-iommufd.h: rename VFIOContainer bcontainer field to parent_obj Cédric Le Goater
2025-09-26  5:33 ` [PULL 11/29] vfio/spapr.c: use QOM casts where appropriate Cédric Le Goater
2025-09-26  5:33 ` [PULL 12/29] vfio/spapr.c: rename VFIOContainer bcontainer field to parent_obj Cédric Le Goater
2025-09-26  5:33 ` [PULL 13/29] vfio/pci.c: rename vfio_instance_init() to vfio_pci_init() Cédric Le Goater
2025-09-26  5:33 ` [PULL 14/29] vfio/pci.c: rename vfio_instance_finalize() to vfio_pci_finalize() Cédric Le Goater
2025-09-26  5:33 ` [PULL 15/29] vfio/pci.c: rename vfio_pci_dev_class_init() to vfio_pci_class_init() Cédric Le Goater
2025-09-26  5:33 ` [PULL 16/29] vfio/pci.c: rename vfio_pci_dev_info to vfio_pci_info Cédric Le Goater
2025-09-26  5:33 ` [PULL 17/29] hw/vfio/types.h: rename TYPE_VFIO_PCI_BASE to TYPE_VFIO_PCI_DEVICE Cédric Le Goater
2025-09-26  5:33 ` [PULL 18/29] vfio/pci.c: rename vfio_pci_base_dev_class_init() to vfio_pci_device_class_init() Cédric Le Goater
2025-09-26  5:33 ` [PULL 19/29] vfio/pci.c: rename vfio_pci_base_dev_info to vfio_pci_device_info Cédric Le Goater
2025-09-26  5:33 ` [PULL 20/29] vfio/pci.c: rename vfio_pci_dev_properties[] to vfio_pci_properties[] Cédric Le Goater
2025-09-26  5:33 ` [PULL 21/29] vfio/pci.c: rename vfio_pci_dev_nohotplug_properties[] to vfio_pci_nohotplug_properties[] Cédric Le Goater
2025-09-26  5:33 ` [PULL 22/29] vfio/pci.c: rename vfio_pci_nohotplug_dev_class_init() to vfio_pci_nohotplug_class_init() Cédric Le Goater
2025-09-26  5:33 ` [PULL 23/29] vfio/pci.c: rename vfio_pci_nohotplug_dev_info to vfio_pci_nohotplug_info Cédric Le Goater
2025-09-26  5:33 ` [PULL 24/29] vfio-user/pci.c: rename vfio_user_pci_dev_class_init() to vfio_user_pci_class_init() Cédric Le Goater
2025-09-26  5:33 ` [PULL 25/29] vfio-user/pci.c: rename vfio_user_pci_dev_properties[] to vfio_user_pci_properties[] Cédric Le Goater
2025-09-26  5:33 ` [PULL 26/29] vfio-user/pci.c: rename vfio_user_instance_init() to vfio_user_pci_init() Cédric Le Goater
2025-09-26  5:33 ` [PULL 27/29] vfio-user/pci.c: rename vfio_user_instance_finalize() to vfio_user_pci_finalize() Cédric Le Goater
2025-09-26  5:33 ` [PULL 28/29] vfio-user/pci.c: rename vfio_user_pci_dev_info to vfio_user_pci_info Cédric Le Goater
2025-09-26  5:33 ` [PULL 29/29] include/hw/vfio/vfio-device.h: fix include header guard name Cédric Le Goater
2025-09-27 15:41 ` [PULL 00/29] vfio queue Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250926053358.308198-9-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=mark.caveayland@nutanix.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).