From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Zhenzhong Duan" <zhenzhong.duan@intel.com>,
"Steve Sistare" <steven.sistare@oracle.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 02/27] vfio/container: Fix vfio_container_post_load()
Date: Fri, 4 Jul 2025 10:45:03 +0200 [thread overview]
Message-ID: <20250704084528.1412959-3-clg@redhat.com> (raw)
In-Reply-To: <20250704084528.1412959-1-clg@redhat.com>
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
When there are multiple VFIO containers, vioc->dma_map is restored
multiple times, this made only first container work and remaining
containers using vioc->dma_map restored by first container.
Fix it by save and restore vioc->dma_map locally. saved_dma_map in
VFIOContainerCPR becomes useless and is removed.
Fixes: 7e9f21411302 ("vfio/container: restore DMA vaddr")
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Steve Sistare <steven.sistare@oracle.com>
Link: https://lore.kernel.org/qemu-devel/20250627063332.5173-3-zhenzhong.duan@intel.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
include/hw/vfio/vfio-cpr.h | 7 ++++---
hw/vfio/cpr-legacy.c | 23 +++++++++--------------
2 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/include/hw/vfio/vfio-cpr.h b/include/hw/vfio/vfio-cpr.h
index 8bf85b9f4ec2cd712ef835dc5d720fe03d767d03..dbb2a16b7a8174c15412a9297e0beb3d274ab520 100644
--- a/include/hw/vfio/vfio-cpr.h
+++ b/include/hw/vfio/vfio-cpr.h
@@ -16,14 +16,15 @@ struct VFIOContainer;
struct VFIOContainerBase;
struct VFIOGroup;
+typedef int (*dma_map_fn)(const struct VFIOContainerBase *bcontainer,
+ hwaddr iova, ram_addr_t size, void *vaddr,
+ bool readonly, MemoryRegion *mr);
+
typedef struct VFIOContainerCPR {
Error *blocker;
bool vaddr_unmapped;
NotifierWithReturn transfer_notifier;
MemoryListener remap_listener;
- int (*saved_dma_map)(const struct VFIOContainerBase *bcontainer,
- hwaddr iova, ram_addr_t size,
- void *vaddr, bool readonly, MemoryRegion *mr);
} VFIOContainerCPR;
typedef struct VFIODeviceCPR {
diff --git a/hw/vfio/cpr-legacy.c b/hw/vfio/cpr-legacy.c
index 0a5d1bd480ee510f4ab5fc952170fba80a5f41c8..1216717546ca13d6f33e802777aa69ab4d59ecba 100644
--- a/hw/vfio/cpr-legacy.c
+++ b/hw/vfio/cpr-legacy.c
@@ -99,20 +99,21 @@ static int vfio_container_post_load(void *opaque, int version_id)
{
VFIOContainer *container = opaque;
VFIOContainerBase *bcontainer = &container->bcontainer;
- VFIOGroup *group;
+ VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
+ dma_map_fn saved_dma_map = vioc->dma_map;
Error *local_err = NULL;
+ /* During incoming CPR, divert calls to dma_map. */
+ vioc->dma_map = vfio_legacy_cpr_dma_map;
+
if (!vfio_listener_register(bcontainer, &local_err)) {
error_report_err(local_err);
return -1;
}
- QLIST_FOREACH(group, &container->group_list, container_next) {
- VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
+ /* Restore original dma_map function */
+ vioc->dma_map = saved_dma_map;
- /* Restore original dma_map function */
- vioc->dma_map = container->cpr.saved_dma_map;
- }
return 0;
}
@@ -148,6 +149,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *notifier,
*/
VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
+ dma_map_fn saved_dma_map = vioc->dma_map;
vioc->dma_map = vfio_legacy_cpr_dma_map;
container->cpr.remap_listener = (MemoryListener) {
@@ -158,7 +160,7 @@ static int vfio_cpr_fail_notifier(NotifierWithReturn *notifier,
bcontainer->space->as);
memory_listener_unregister(&container->cpr.remap_listener);
container->cpr.vaddr_unmapped = false;
- vioc->dma_map = container->cpr.saved_dma_map;
+ vioc->dma_map = saved_dma_map;
}
return 0;
}
@@ -179,13 +181,6 @@ bool vfio_legacy_cpr_register_container(VFIOContainer *container, Error **errp)
vmstate_register(NULL, -1, &vfio_container_vmstate, container);
- /* During incoming CPR, divert calls to dma_map. */
- VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
- container->cpr.saved_dma_map = vioc->dma_map;
- if (cpr_is_incoming()) {
- vioc->dma_map = vfio_legacy_cpr_dma_map;
- }
-
migration_add_notifier_mode(&container->cpr.transfer_notifier,
vfio_cpr_fail_notifier,
MIG_MODE_CPR_TRANSFER);
--
2.50.0
next prev parent reply other threads:[~2025-07-04 8:46 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-04 8:45 [PULL 00/27] vfio queue Cédric Le Goater
2025-07-04 8:45 ` [PULL 01/27] vfio/container: Fix potential SIGSEGV when recover from unmap-all-vaddr failure Cédric Le Goater
2025-07-04 8:45 ` Cédric Le Goater [this message]
2025-07-04 8:45 ` [PULL 03/27] vfio-user: do not register vfio-user container with cpr Cédric Le Goater
2025-07-04 8:45 ` [PULL 04/27] i386/tdx: Build TDX only for 64-bit target Cédric Le Goater
2025-07-04 8:45 ` [PULL 05/27] b4: Drop linktrailermask Cédric Le Goater
2025-07-04 8:45 ` [PULL 06/27] Makefile: prune quilt source files for cscope Cédric Le Goater
2025-07-04 8:45 ` [PULL 07/27] vfio-pci: preserve MSI Cédric Le Goater
2025-07-04 8:45 ` [PULL 08/27] vfio-pci: preserve INTx Cédric Le Goater
2025-07-04 8:45 ` [PULL 09/27] migration: close kvm after cpr Cédric Le Goater
2025-07-04 8:45 ` [PULL 10/27] migration: cpr_get_fd_param helper Cédric Le Goater
2025-07-04 8:45 ` [PULL 11/27] backends/iommufd: iommufd_backend_map_file_dma Cédric Le Goater
2025-07-04 8:45 ` [PULL 12/27] backends/iommufd: change process ioctl Cédric Le Goater
2025-07-04 8:45 ` [PULL 13/27] physmem: qemu_ram_get_fd_offset Cédric Le Goater
2025-07-04 8:45 ` [PULL 14/27] vfio/iommufd: use IOMMU_IOAS_MAP_FILE Cédric Le Goater
2025-07-04 8:45 ` [PULL 15/27] vfio/iommufd: invariant device name Cédric Le Goater
2025-07-04 8:45 ` [PULL 16/27] vfio/iommufd: add vfio_device_free_name Cédric Le Goater
2025-07-04 8:45 ` [PULL 17/27] vfio/iommufd: device name blocker Cédric Le Goater
2025-07-04 8:45 ` [PULL 18/27] vfio/iommufd: register container for cpr Cédric Le Goater
2025-07-04 8:45 ` [PULL 19/27] migration: vfio cpr state hook Cédric Le Goater
2025-07-04 8:45 ` [PULL 20/27] vfio/iommufd: cpr state Cédric Le Goater
2025-07-04 8:45 ` [PULL 21/27] vfio/iommufd: preserve descriptors Cédric Le Goater
2025-07-04 8:45 ` [PULL 22/27] vfio/iommufd: reconstruct device Cédric Le Goater
2025-07-04 8:45 ` [PULL 23/27] vfio/iommufd: reconstruct hwpt Cédric Le Goater
2025-07-04 8:45 ` [PULL 24/27] vfio/iommufd: change process Cédric Le Goater
2025-07-04 8:45 ` [PULL 25/27] iommufd: preserve DMA mappings Cédric Le Goater
2025-07-04 8:45 ` [PULL 26/27] vfio/container: delete old cpr register Cédric Le Goater
2025-07-04 8:45 ` [PULL 27/27] vfio: doc changes for cpr Cédric Le Goater
2025-07-04 17:49 ` [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=20250704084528.1412959-3-clg@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=steven.sistare@oracle.com \
--cc=zhenzhong.duan@intel.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).