qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vivek Kasireddy <vivek.kasireddy@intel.com>
To: qemu-devel@nongnu.org
Cc: "Vivek Kasireddy" <vivek.kasireddy@intel.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PATCH v2 05/10] vfio/device: Add a helper to lookup VFIODevice from memory region
Date: Sat,  8 Nov 2025 21:33:48 -0800	[thread overview]
Message-ID: <20251109053801.2267149-6-vivek.kasireddy@intel.com> (raw)
In-Reply-To: <20251109053801.2267149-1-vivek.kasireddy@intel.com>

Instead of iterating over all QOM devices to find the VFIODevice
associated with a memory region, it is faster to just use the
vfio_device_list to lookup the VFIODevice.

Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
 hw/vfio/device.c              | 12 ++++++++++++
 include/hw/vfio/vfio-device.h |  9 +++++++++
 2 files changed, 21 insertions(+)

diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 76869828fc..9ff73f9941 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -603,3 +603,15 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl = {
     .region_read = vfio_device_io_region_read,
     .region_write = vfio_device_io_region_write,
 };
+
+VFIODevice *vfio_device_lookup(MemoryRegion *mr)
+{
+    VFIODevice *vbasedev;
+
+    QLIST_FOREACH(vbasedev, &vfio_device_list, next) {
+        if (vbasedev->dev == mr->dev) {
+            return vbasedev;
+        }
+    }
+    return NULL;
+}
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 44cacd3728..2f8087f133 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -300,6 +300,15 @@ int vfio_device_get_irq_info(VFIODevice *vbasedev, int index,
  * Returns the region index or -1 on error.
  */
 int vfio_get_region_index_from_mr(MemoryRegion *mr);
+
+/**
+ * Return the VFIO device associated with a given MemoryRegion.
+ *
+ * @mr: MemoryRegion to use
+ *
+ * Returns the VFIO device if found or NULL.
+ */
+VFIODevice *vfio_device_lookup(MemoryRegion *mr);
 #endif
 
 /* Returns 0 on success, or a negative errno. */
-- 
2.50.1



  parent reply	other threads:[~2025-11-09  5:40 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-09  5:33 [PATCH v2 00/10] vfio: Implement VFIO_DEVICE_FEATURE_DMA_BUF and use it in virtio-gpu Vivek Kasireddy
2025-11-09  5:33 ` [PATCH v2 01/10] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Vivek Kasireddy
2025-11-10  4:59   ` Akihiko Odaki
2025-11-09  5:33 ` [PATCH v2 02/10] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Vivek Kasireddy
2025-11-10  5:00   ` Akihiko Odaki
2025-11-11  4:45   ` Akihiko Odaki
2025-11-12  4:30     ` Kasireddy, Vivek
2025-11-12  8:14       ` Akihiko Odaki
2025-11-13  3:39         ` Kasireddy, Vivek
2025-11-13  4:08           ` Akihiko Odaki
2025-11-17  4:14             ` Kasireddy, Vivek
2025-11-17  6:56               ` Akihiko Odaki
2025-11-18  5:26                 ` Kasireddy, Vivek
2025-11-18  5:37                   ` Akihiko Odaki
2025-11-19  5:42                     ` Kasireddy, Vivek
2025-11-19  5:55                       ` Akihiko Odaki
2025-11-21  6:56                         ` Kasireddy, Vivek
2025-11-21  7:08                           ` Akihiko Odaki
2025-11-09  5:33 ` [PATCH v2 03/10] vfio: Document vfio_device_get_region_info() Vivek Kasireddy
2025-11-09  5:33 ` [PATCH v2 04/10] vfio/region: Add a helper to get region index from memory region Vivek Kasireddy
2025-11-09  5:33 ` Vivek Kasireddy [this message]
2025-11-09  5:33 ` [PATCH v2 06/10] linux-headers: Update vfio.h to include VFIO_DEVICE_FEATURE_DMA_BUF Vivek Kasireddy
2025-11-09  6:49   ` Leon Romanovsky
2025-11-17  9:02     ` Cédric Le Goater
2025-11-09  5:33 ` [PATCH v2 07/10] vfio/device: Add support for VFIO_DEVICE_FEATURE_DMA_BUF Vivek Kasireddy
2025-11-09  5:33 ` [PATCH v2 08/10] virtio-gpu: Rename udmabuf files and helpers to dmabuf Vivek Kasireddy
2025-11-10  5:00   ` Akihiko Odaki
2025-11-09  5:33 ` [PATCH v2 09/10] virtio-gpu-dmabuf: Introduce qemu_iovec_same_memory_regions() Vivek Kasireddy
2025-11-10  5:19   ` Akihiko Odaki
2025-11-12  4:24     ` Kasireddy, Vivek
2025-11-12  8:21       ` Akihiko Odaki
2025-11-13  3:14         ` Kasireddy, Vivek
2025-11-13  3:28           ` Akihiko Odaki
2025-11-09  5:33 ` [PATCH v2 10/10] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Vivek Kasireddy
2025-11-10  4:55   ` Akihiko Odaki
2025-11-12  4:26     ` Kasireddy, Vivek
2025-11-12  8:17       ` Akihiko Odaki
2025-11-13  3:17         ` Kasireddy, Vivek
2025-11-13  3:31           ` Akihiko Odaki
2025-11-17  4:19             ` Kasireddy, Vivek
2025-11-17  7:13               ` Akihiko Odaki
2025-11-18  5:22                 ` Kasireddy, Vivek
2025-11-18  6:02                   ` Akihiko Odaki
2025-11-19  5:33                     ` Kasireddy, Vivek
2025-11-17  9:04 ` [PATCH v2 00/10] vfio: Implement VFIO_DEVICE_FEATURE_DMA_BUF and use it in virtio-gpu 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=20251109053801.2267149-6-vivek.kasireddy@intel.com \
    --to=vivek.kasireddy@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=clg@redhat.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).