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>,
	"Steve Sistare" <steven.sistare@oracle.com>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 14/27] vfio/container: discard old DMA vaddr
Date: Wed, 11 Jun 2025 17:06:06 +0200	[thread overview]
Message-ID: <20250611150620.701903-15-clg@redhat.com> (raw)
In-Reply-To: <20250611150620.701903-1-clg@redhat.com>

From: Steve Sistare <steven.sistare@oracle.com>

In the container pre_save handler, discard the virtual addresses in DMA
mappings with VFIO_DMA_UNMAP_FLAG_VADDR, because guest RAM will be
remapped at a different VA after in new QEMU.  DMA to already-mapped
pages continues.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/1749569991-25171-6-git-send-email-steven.sistare@oracle.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/cpr-legacy.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c
index ac4a9ab315eab515607fb2405032ddc1ab980cf0..ef106d0ea865e86e3fdce86928e987e812724a0e 100644
--- a/hw/vfio/cpr-legacy.c
+++ b/hw/vfio/cpr-legacy.c
@@ -15,6 +15,22 @@
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 
+static bool vfio_dma_unmap_vaddr_all(VFIOContainer *container, Error **errp)
+{
+    struct vfio_iommu_type1_dma_unmap unmap = {
+        .argsz = sizeof(unmap),
+        .flags = VFIO_DMA_UNMAP_FLAG_VADDR | VFIO_DMA_UNMAP_FLAG_ALL,
+        .iova = 0,
+        .size = 0,
+    };
+    if (ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap)) {
+        error_setg_errno(errp, errno, "vfio_dma_unmap_vaddr_all");
+        return false;
+    }
+    return true;
+}
+
+
 static bool vfio_cpr_supported(VFIOContainer *container, Error **errp)
 {
     if (!ioctl(container->fd, VFIO_CHECK_EXTENSION, VFIO_UPDATE_VADDR)) {
@@ -30,10 +46,23 @@ static bool vfio_cpr_supported(VFIOContainer *container, Error **errp)
     }
 }
 
+static int vfio_container_pre_save(void *opaque)
+{
+    VFIOContainer *container = opaque;
+    Error *local_err = NULL;
+
+    if (!vfio_dma_unmap_vaddr_all(container, &local_err)) {
+        error_report_err(local_err);
+        return -1;
+    }
+    return 0;
+}
+
 static const VMStateDescription vfio_container_vmstate = {
     .name = "vfio-container",
     .version_id = 0,
     .minimum_version_id = 0,
+    .pre_save = vfio_container_pre_save,
     .needed = cpr_incoming_needed,
     .fields = (VMStateField[]) {
         VMSTATE_END_OF_LIST()
-- 
2.49.0



  parent reply	other threads:[~2025-06-11 15:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 15:05 [PULL 00/27] vfio queue Cédric Le Goater
2025-06-11 15:05 ` [PULL 01/27] vfio/container: Fix vfio_listener_commit() Cédric Le Goater
2025-06-11 15:05 ` [PULL 02/27] vfio/pci: Fix instance_size of VFIO_PCI_BASE Cédric Le Goater
2025-06-11 15:05 ` [PULL 03/27] hw/vfio/ap: notification handler for AP config changed event Cédric Le Goater
2025-06-11 15:05 ` [PULL 04/27] hw/vfio/ap: store object indicating AP config changed in a queue Cédric Le Goater
2025-06-11 15:05 ` [PULL 05/27] hw/vfio/ap: Storing event information for an AP configuration change event Cédric Le Goater
2025-06-11 15:05 ` [PULL 06/27] s390: implementing CHSC SEI for AP config change Cédric Le Goater
2025-06-11 15:05 ` [PULL 07/27] vfio: export PCI helpers needed for vfio-user Cédric Le Goater
2025-06-11 15:06 ` [PULL 08/27] vfio: add per-region fd support Cédric Le Goater
2025-06-11 15:06 ` [PULL 09/27] vfio: mark posted writes in region write callbacks Cédric Le Goater
2025-06-11 15:06 ` [PULL 10/27] migration: cpr helpers Cédric Le Goater
2025-06-11 15:06 ` [PULL 11/27] migration: lower handler priority Cédric Le Goater
2025-06-11 15:06 ` [PULL 12/27] vfio/container: register container for cpr Cédric Le Goater
2025-06-11 15:06 ` [PULL 13/27] vfio/container: preserve descriptors Cédric Le Goater
2025-06-11 15:06 ` Cédric Le Goater [this message]
2025-06-11 15:06 ` [PULL 15/27] vfio/container: restore DMA vaddr Cédric Le Goater
2025-06-11 15:06 ` [PULL 16/27] vfio/container: mdev cpr blocker Cédric Le Goater
2025-06-11 15:06 ` [PULL 17/27] vfio/container: recover from unmap-all-vaddr failure Cédric Le Goater
2025-06-11 15:06 ` [PULL 18/27] pci: export msix_is_pending Cédric Le Goater
2025-06-11 15:06 ` [PULL 19/27] pci: skip reset during cpr Cédric Le Goater
2025-06-11 15:06 ` [PULL 20/27] vfio-pci: " Cédric Le Goater
2025-06-11 15:06 ` [PULL 21/27] vfio/pci: vfio_pci_vector_init Cédric Le Goater
2025-06-11 15:06 ` [PULL 22/27] vfio/pci: vfio_notifier_init Cédric Le Goater
2025-06-11 15:06 ` [PULL 23/27] vfio/pci: pass vector to virq functions Cédric Le Goater
2025-06-11 15:06 ` [PULL 24/27] vfio/pci: vfio_notifier_init cpr parameters Cédric Le Goater
2025-06-11 15:06 ` [PULL 25/27] vfio/pci: vfio_notifier_cleanup Cédric Le Goater
2025-06-11 15:06 ` [PULL 26/27] vfio/pci: export MSI functions Cédric Le Goater
2025-06-11 15:06 ` [PULL 27/27] vfio: improve VFIODeviceIOOps docs Cédric Le Goater
2025-06-11 18:22 ` [PULL 00/27] vfio queue Stefan Hajnoczi

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=20250611150620.701903-15-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=steven.sistare@oracle.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).