qemu-kvm/SOURCES/kvm-vfio-spapr-Extend-VFIOIOMMUOps-with-a-release-handle.patch

130 lines
4.8 KiB
Diff
Raw Normal View History

2024-04-30 11:41:18 +00:00
From e75ec2aca351daabe597ca6322c1589885f30d7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <clg@redhat.com>
Date: Tue, 19 Dec 2023 07:58:16 +0100
Subject: [PATCH 049/101] vfio/spapr: Extend VFIOIOMMUOps with a release
handler
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
RH-Author: Eric Auger <eric.auger@redhat.com>
RH-MergeRequest: 211: IOMMUFD backend backport
RH-Jira: RHEL-19302 RHEL-21057
RH-Acked-by: Cédric Le Goater <clg@redhat.com>
RH-Acked-by: Sebastian Ott <sebott@redhat.com>
RH-Commit: [48/67] 1c4d22a6f69324805d050767fcf178d8566f2030 (eauger1/centos-qemu-kvm)
This allows to abstract a bit more the sPAPR IOMMU support in the
legacy IOMMU backend.
Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Tested-by: Eric Farman <farman@linux.ibm.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 001a013ea3f125d2ec0e709b5765754149d8d968)
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
hw/vfio/container.c | 10 +++-----
hw/vfio/spapr.c | 35 +++++++++++++++------------
include/hw/vfio/vfio-container-base.h | 1 +
3 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
index b22feb8ded..1e77a2929e 100644
--- a/hw/vfio/container.c
+++ b/hw/vfio/container.c
@@ -632,9 +632,8 @@ listener_release_exit:
QLIST_REMOVE(bcontainer, next);
vfio_kvm_device_del_group(group);
memory_listener_unregister(&bcontainer->listener);
- if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU ||
- container->iommu_type == VFIO_SPAPR_TCE_IOMMU) {
- vfio_spapr_container_deinit(container);
+ if (bcontainer->ops->release) {
+ bcontainer->ops->release(bcontainer);
}
enable_discards_exit:
@@ -667,9 +666,8 @@ static void vfio_disconnect_container(VFIOGroup *group)
*/
if (QLIST_EMPTY(&container->group_list)) {
memory_listener_unregister(&bcontainer->listener);
- if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU ||
- container->iommu_type == VFIO_SPAPR_TCE_IOMMU) {
- vfio_spapr_container_deinit(container);
+ if (bcontainer->ops->release) {
+ bcontainer->ops->release(bcontainer);
}
}
diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
index 5c6426e697..44617dfc6b 100644
--- a/hw/vfio/spapr.c
+++ b/hw/vfio/spapr.c
@@ -440,6 +440,24 @@ vfio_spapr_container_del_section_window(VFIOContainerBase *bcontainer,
}
}
+static void vfio_spapr_container_release(VFIOContainerBase *bcontainer)
+{
+ VFIOContainer *container = container_of(bcontainer, VFIOContainer,
+ bcontainer);
+ VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
+ container);
+ VFIOHostDMAWindow *hostwin, *next;
+
+ if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU) {
+ memory_listener_unregister(&scontainer->prereg_listener);
+ }
+ QLIST_FOREACH_SAFE(hostwin, &scontainer->hostwin_list, hostwin_next,
+ next) {
+ QLIST_REMOVE(hostwin, hostwin_next);
+ g_free(hostwin);
+ }
+}
+
static VFIOIOMMUOps vfio_iommu_spapr_ops;
static void setup_spapr_ops(VFIOContainerBase *bcontainer)
@@ -447,6 +465,7 @@ static void setup_spapr_ops(VFIOContainerBase *bcontainer)
vfio_iommu_spapr_ops = *bcontainer->ops;
vfio_iommu_spapr_ops.add_window = vfio_spapr_container_add_section_window;
vfio_iommu_spapr_ops.del_window = vfio_spapr_container_del_section_window;
+ vfio_iommu_spapr_ops.release = vfio_spapr_container_release;
bcontainer->ops = &vfio_iommu_spapr_ops;
}
@@ -527,19 +546,3 @@ listener_unregister_exit:
}
return ret;
}
-
-void vfio_spapr_container_deinit(VFIOContainer *container)
-{
- VFIOSpaprContainer *scontainer = container_of(container, VFIOSpaprContainer,
- container);
- VFIOHostDMAWindow *hostwin, *next;
-
- if (container->iommu_type == VFIO_SPAPR_TCE_v2_IOMMU) {
- memory_listener_unregister(&scontainer->prereg_listener);
- }
- QLIST_FOREACH_SAFE(hostwin, &scontainer->hostwin_list, hostwin_next,
- next) {
- QLIST_REMOVE(hostwin, hostwin_next);
- g_free(hostwin);
- }
-}
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
index 2ae297ccda..5c9594b6c7 100644
--- a/include/hw/vfio/vfio-container-base.h
+++ b/include/hw/vfio/vfio-container-base.h
@@ -117,5 +117,6 @@ struct VFIOIOMMUOps {
Error **errp);
void (*del_window)(VFIOContainerBase *bcontainer,
MemoryRegionSection *section);
+ void (*release)(VFIOContainerBase *bcontainer);
};
#endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */
--
2.39.3