qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: John Levon <john.levon@nutanix.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Tomita Moeko" <tomitamoeko@gmail.com>,
	"Matthew Rosato" <mjrosato@linux.ibm.com>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Tony Krowiak" <akrowiak@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"David Hildenbrand" <david@redhat.com>,
	qemu-s390x@nongnu.org, "Jason Herne" <jjherne@linux.ibm.com>,
	"John Levon" <john.levon@nutanix.com>
Subject: [PATCH v3 01/15] vfio: add vfio_device_prepare()
Date: Wed,  7 May 2025 16:20:06 +0100	[thread overview]
Message-ID: <20250507152020.1254632-2-john.levon@nutanix.com> (raw)
In-Reply-To: <20250507152020.1254632-1-john.levon@nutanix.com>

Commonize some initialization code shared by the legacy and iommufd vfio
implementations.

Reviewed-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
---
 include/hw/vfio/vfio-device.h |  3 +++
 hw/vfio/container.c           | 14 ++------------
 hw/vfio/device.c              | 14 ++++++++++++++
 hw/vfio/iommufd.c             |  9 +--------
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 81c95bb51e..081929ca4b 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -134,6 +134,9 @@ typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
 extern VFIODeviceList vfio_device_list;
 
 #ifdef CONFIG_LINUX
+void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
+                         struct vfio_device_info *info);
+
 int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
                                 struct vfio_region_info **info);
 int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index a761f0958b..d30c1a141d 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -826,18 +826,14 @@ static bool vfio_device_get(VFIOGroup *group, const char *name,
         }
     }
 
+    vfio_device_prepare(vbasedev, &group->container->bcontainer, info);
+
     vbasedev->fd = fd;
     vbasedev->group = group;
     QLIST_INSERT_HEAD(&group->device_list, vbasedev, next);
 
-    vbasedev->num_irqs = info->num_irqs;
-    vbasedev->num_regions = info->num_regions;
-    vbasedev->flags = info->flags;
-
     trace_vfio_device_get(name, info->flags, info->num_regions, info->num_irqs);
 
-    vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET);
-
     return true;
 }
 
@@ -890,7 +886,6 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
     int groupid = vfio_device_get_groupid(vbasedev, errp);
     VFIODevice *vbasedev_iter;
     VFIOGroup *group;
-    VFIOContainerBase *bcontainer;
 
     if (groupid < 0) {
         return false;
@@ -919,11 +914,6 @@ static bool vfio_legacy_attach_device(const char *name, VFIODevice *vbasedev,
         goto device_put_exit;
     }
 
-    bcontainer = &group->container->bcontainer;
-    vbasedev->bcontainer = bcontainer;
-    QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next);
-    QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
-
     return true;
 
 device_put_exit:
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index d625a7c4db..f3b9902d21 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -398,3 +398,17 @@ void vfio_device_detach(VFIODevice *vbasedev)
     }
     VFIO_IOMMU_GET_CLASS(vbasedev->bcontainer)->detach_device(vbasedev);
 }
+
+void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
+                         struct vfio_device_info *info)
+{
+    vbasedev->num_irqs = info->num_irqs;
+    vbasedev->num_regions = info->num_regions;
+    vbasedev->flags = info->flags;
+    vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET);
+
+    vbasedev->bcontainer = bcontainer;
+    QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next);
+
+    QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
+}
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 232c06dd15..83033c352a 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -588,14 +588,7 @@ found_container:
         iommufd_cdev_ram_block_discard_disable(false);
     }
 
-    vbasedev->group = 0;
-    vbasedev->num_irqs = dev_info.num_irqs;
-    vbasedev->num_regions = dev_info.num_regions;
-    vbasedev->flags = dev_info.flags;
-    vbasedev->reset_works = !!(dev_info.flags & VFIO_DEVICE_FLAGS_RESET);
-    vbasedev->bcontainer = bcontainer;
-    QLIST_INSERT_HEAD(&bcontainer->device_list, vbasedev, container_next);
-    QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
+    vfio_device_prepare(vbasedev, bcontainer, &dev_info);
 
     trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_irqs,
                                    vbasedev->num_regions, vbasedev->flags);
-- 
2.43.0



  reply	other threads:[~2025-05-07 15:23 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 15:20 [PATCH v3 00/15] vfio: preparation for vfio-user John Levon
2025-05-07 15:20 ` John Levon [this message]
2025-05-07 15:20 ` [PATCH v3 02/15] vfio: add vfio_device_unprepare() John Levon
2025-05-07 15:20 ` [PATCH v3 03/15] vfio: add vfio_attach_device_by_iommu_type() John Levon
2025-05-07 15:20 ` [PATCH v3 04/15] vfio: add vfio_device_get_irq_info() helper John Levon
2025-05-07 15:20 ` [PATCH v3 05/15] vfio: consistently handle return value for helpers John Levon
2025-05-07 15:20 ` [PATCH v3 06/15] vfio: add strread/writeerror() John Levon
2025-05-09 10:05   ` Cédric Le Goater
2025-05-07 15:20 ` [PATCH v3 07/15] vfio: add vfio_pci_config_space_read/write() John Levon
2025-05-07 15:20 ` [PATCH v3 08/15] vfio: add unmap_all flag to DMA unmap callback John Levon
2025-05-09 10:07   ` Cédric Le Goater
2025-05-07 15:20 ` [PATCH v3 09/15] vfio: implement unmap all for DMA unmap callbacks John Levon
2025-05-09 10:08   ` Cédric Le Goater
2025-05-07 15:20 ` [PATCH v3 10/15] vfio: add device IO ops vector John Levon
2025-05-09 10:09   ` Cédric Le Goater
2025-05-07 15:20 ` [PATCH v3 11/15] vfio: add region info cache John Levon
2025-05-09 10:09   ` Cédric Le Goater
2025-05-07 15:20 ` [PATCH v3 12/15] vfio: add read/write to device IO ops vector John Levon
2025-05-09 10:14   ` Cédric Le Goater
2025-05-09 10:32     ` John Levon
2025-05-07 15:20 ` [PATCH v3 13/15] vfio: add vfio-pci-base class John Levon
2025-05-09 10:14   ` Cédric Le Goater
2025-05-07 15:20 ` [PATCH v3 14/15] vfio/container: pass listener_begin/commit callbacks John Levon
2025-05-07 15:20 ` [PATCH v3 15/15] vfio/container: pass MemoryRegion to DMA operations John Levon
2025-05-09 10:22   ` Cédric Le Goater
2025-05-09 10:24 ` [PATCH v3 00/15] vfio: preparation for vfio-user Cédric Le Goater
2025-05-09 12:45   ` Cédric Le Goater

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=20250507152020.1254632-2-john.levon@nutanix.com \
    --to=john.levon@nutanix.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=david@redhat.com \
    --cc=farman@linux.ibm.com \
    --cc=jjherne@linux.ibm.com \
    --cc=mjrosato@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=thuth@redhat.com \
    --cc=tomitamoeko@gmail.com \
    /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).