All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: qemu-devel@nongnu.org
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Cedric Le Goater <clg@redhat.com>,
	Yishai Hadas <yishaih@nvidia.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	Maor Gottlieb <maorg@nvidia.com>,
	Kirti Wankhede <kwankhede@nvidia.com>,
	Tarun Gupta <targupta@nvidia.com>,
	Avihai Horon <avihaih@nvidia.com>,
	Joao Martins <joao.m.martins@oracle.com>
Subject: [PATCH v5 11/15] vfio/common: Extract code from vfio_get_dirty_bitmap() to new function
Date: Tue,  7 Mar 2023 12:54:46 +0000	[thread overview]
Message-ID: <20230307125450.62409-12-joao.m.martins@oracle.com> (raw)
In-Reply-To: <20230307125450.62409-1-joao.m.martins@oracle.com>

From: Avihai Horon <avihaih@nvidia.com>

Extract the VFIO_IOMMU_DIRTY_PAGES ioctl code in vfio_get_dirty_bitmap()
to its own function.

This will help the code to be more readable after next patch will add
device dirty page bitmap sync functionality.

Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/common.c | 57 +++++++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 80f2d287bab5..1f97a8a3db18 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1595,26 +1595,13 @@ static void vfio_listener_log_global_stop(MemoryListener *listener)
     }
 }
 
-static int vfio_get_dirty_bitmap(VFIOContainer *container, uint64_t iova,
-                                 uint64_t size, ram_addr_t ram_addr)
+static int vfio_query_dirty_bitmap(VFIOContainer *container, VFIOBitmap *vbmap,
+                                   hwaddr iova, hwaddr size)
 {
     struct vfio_iommu_type1_dirty_bitmap *dbitmap;
     struct vfio_iommu_type1_dirty_bitmap_get *range;
-    VFIOBitmap vbmap;
     int ret;
 
-    if (!container->dirty_pages_supported) {
-        cpu_physical_memory_set_dirty_range(ram_addr, size,
-                                            tcg_enabled() ? DIRTY_CLIENTS_ALL :
-                                            DIRTY_CLIENTS_NOCODE);
-        return 0;
-    }
-
-    ret = vfio_bitmap_alloc(&vbmap, size);
-    if (ret) {
-        return ret;
-    }
-
     dbitmap = g_malloc0(sizeof(*dbitmap) + sizeof(*range));
 
     dbitmap->argsz = sizeof(*dbitmap) + sizeof(*range);
@@ -1629,8 +1616,8 @@ static int vfio_get_dirty_bitmap(VFIOContainer *container, uint64_t iova,
      * to qemu_real_host_page_size.
      */
     range->bitmap.pgsize = qemu_real_host_page_size();
-    range->bitmap.size = vbmap.size;
-    range->bitmap.data = (__u64 *)vbmap.bitmap;
+    range->bitmap.size = vbmap->size;
+    range->bitmap.data = (__u64 *)vbmap->bitmap;
 
     ret = ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, dbitmap);
     if (ret) {
@@ -1638,16 +1625,42 @@ static int vfio_get_dirty_bitmap(VFIOContainer *container, uint64_t iova,
         error_report("Failed to get dirty bitmap for iova: 0x%"PRIx64
                 " size: 0x%"PRIx64" err: %d", (uint64_t)range->iova,
                 (uint64_t)range->size, errno);
-        goto err_out;
+    }
+
+    g_free(dbitmap);
+
+    return ret;
+}
+
+static int vfio_get_dirty_bitmap(VFIOContainer *container, uint64_t iova,
+                                 uint64_t size, ram_addr_t ram_addr)
+{
+    VFIOBitmap vbmap;
+    int ret;
+
+    if (!container->dirty_pages_supported) {
+        cpu_physical_memory_set_dirty_range(ram_addr, size,
+                                            tcg_enabled() ? DIRTY_CLIENTS_ALL :
+                                            DIRTY_CLIENTS_NOCODE);
+        return 0;
+    }
+
+    ret = vfio_bitmap_alloc(&vbmap, size);
+    if (ret) {
+        return ret;
+    }
+
+    ret = vfio_query_dirty_bitmap(container, &vbmap, iova, size);
+    if (ret) {
+        goto out;
     }
 
     cpu_physical_memory_set_dirty_lebitmap(vbmap.bitmap, ram_addr,
                                            vbmap.pages);
 
-    trace_vfio_get_dirty_bitmap(container->fd, range->iova, range->size,
-                                range->bitmap.size, ram_addr);
-err_out:
-    g_free(dbitmap);
+    trace_vfio_get_dirty_bitmap(container->fd, iova, size, vbmap.size,
+                                ram_addr);
+out:
     g_free(vbmap.bitmap);
 
     return ret;
-- 
2.17.2



  parent reply	other threads:[~2023-03-07 12:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 12:54 [PATCH v5 00/15] vfio/migration: Device dirty page tracking Joao Martins
2023-03-07 12:54 ` [PATCH v5 01/15] vfio/common: Fix error reporting in vfio_get_dirty_bitmap() Joao Martins
2023-03-07 12:54 ` [PATCH v5 02/15] vfio/common: Fix wrong %m usages Joao Martins
2023-03-07 12:54 ` [PATCH v5 03/15] vfio/common: Abort migration if dirty log start/stop/sync fails Joao Martins
2023-03-07 12:54 ` [PATCH v5 04/15] vfio/common: Add VFIOBitmap and alloc function Joao Martins
2023-03-07 12:54 ` [PATCH v5 05/15] vfio/common: Add helper to validate iova/end against hostwin Joao Martins
2023-03-07 12:54 ` [PATCH v5 06/15] vfio/common: Use a single tracepoint for skipped sections Joao Martins
2023-03-07 13:27   ` Cédric Le Goater
2023-03-07 12:54 ` [PATCH v5 07/15] vfio/common: Consolidate skip/invalid section into helper Joao Martins
2023-03-07 12:54 ` [PATCH v5 08/15] vfio/common: Add helper to consolidate iova/end calculation Joao Martins
2023-03-07 13:28   ` Cédric Le Goater
2023-03-07 12:54 ` [PATCH v5 09/15] vfio/common: Record DMA mapped IOVA ranges Joao Martins
2023-03-07 13:36   ` Cédric Le Goater
2023-03-07 12:54 ` [PATCH v5 10/15] vfio/common: Add device dirty page tracking start/stop Joao Martins
2023-03-07 14:49   ` Cédric Le Goater
2023-03-07 14:54     ` Joao Martins
2023-03-07 12:54 ` Joao Martins [this message]
2023-03-07 12:54 ` [PATCH v5 12/15] vfio/common: Add device dirty page bitmap sync Joao Martins
2023-03-07 15:16   ` Cédric Le Goater
2023-03-07 12:54 ` [PATCH v5 13/15] vfio/migration: Block migration with vIOMMU Joao Martins
2023-03-07 16:38   ` Alex Williamson
2023-03-07 16:42     ` Alex Williamson
2023-03-07 12:54 ` [PATCH v5 14/15] vfio/migration: Query device dirty page tracking support Joao Martins
2023-03-07 12:54 ` [PATCH v5 15/15] docs/devel: Document VFIO device dirty page tracking Joao Martins

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=20230307125450.62409-12-joao.m.martins@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=alex.williamson@redhat.com \
    --cc=avihaih@nvidia.com \
    --cc=clg@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kwankhede@nvidia.com \
    --cc=maorg@nvidia.com \
    --cc=qemu-devel@nongnu.org \
    --cc=targupta@nvidia.com \
    --cc=yishaih@nvidia.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.