forked from rpms/qemu-kvm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.6 KiB
99 lines
3.6 KiB
9 months ago
|
From 7de36998dd6177380e46b8c5f3a91c3fad75483c Mon Sep 17 00:00:00 2001
|
||
|
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
Date: Thu, 2 Nov 2023 15:12:30 +0800
|
||
|
Subject: [PATCH 005/101] vfio/common: Introduce vfio_container_init/destroy
|
||
|
helper
|
||
|
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: [4/67] 8287f687ef19cd84afede1e8f3b16ac3caf29a1d (eauger1/centos-qemu-kvm)
|
||
|
|
||
|
This adds two helper functions vfio_container_init/destroy which will be
|
||
|
used by both legacy and iommufd containers to do base container specific
|
||
|
initialization and release.
|
||
|
|
||
|
No functional change intended.
|
||
|
|
||
|
Suggested-by: Cédric Le Goater <clg@redhat.com>
|
||
|
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
Reviewed-by: Cédric Le Goater <clg@redhat.com>
|
||
|
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
||
|
(cherry picked from commit ed2f7f80170251e7cdd2965a13ee97527d1fbec8)
|
||
|
Signed-off-by: Eric Auger <eric.auger@redhat.com>
|
||
|
---
|
||
|
hw/vfio/container-base.c | 9 +++++++++
|
||
|
hw/vfio/container.c | 4 +++-
|
||
|
include/hw/vfio/vfio-container-base.h | 4 ++++
|
||
|
3 files changed, 16 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
|
||
|
index 55d3a35fa4..e929435751 100644
|
||
|
--- a/hw/vfio/container-base.c
|
||
|
+++ b/hw/vfio/container-base.c
|
||
|
@@ -30,3 +30,12 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
||
|
g_assert(bcontainer->ops->dma_unmap);
|
||
|
return bcontainer->ops->dma_unmap(bcontainer, iova, size, iotlb);
|
||
|
}
|
||
|
+
|
||
|
+void vfio_container_init(VFIOContainerBase *bcontainer, const VFIOIOMMUOps *ops)
|
||
|
+{
|
||
|
+ bcontainer->ops = ops;
|
||
|
+}
|
||
|
+
|
||
|
+void vfio_container_destroy(VFIOContainerBase *bcontainer)
|
||
|
+{
|
||
|
+}
|
||
|
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
|
||
|
index c04df26323..32a0251dd1 100644
|
||
|
--- a/hw/vfio/container.c
|
||
|
+++ b/hw/vfio/container.c
|
||
|
@@ -559,7 +559,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
||
|
QLIST_INIT(&container->giommu_list);
|
||
|
QLIST_INIT(&container->vrdl_list);
|
||
|
bcontainer = &container->bcontainer;
|
||
|
- bcontainer->ops = &vfio_legacy_ops;
|
||
|
+ vfio_container_init(bcontainer, &vfio_legacy_ops);
|
||
|
|
||
|
ret = vfio_init_container(container, group->fd, errp);
|
||
|
if (ret) {
|
||
|
@@ -661,6 +661,7 @@ put_space_exit:
|
||
|
static void vfio_disconnect_container(VFIOGroup *group)
|
||
|
{
|
||
|
VFIOContainer *container = group->container;
|
||
|
+ VFIOContainerBase *bcontainer = &container->bcontainer;
|
||
|
|
||
|
QLIST_REMOVE(group, container_next);
|
||
|
group->container = NULL;
|
||
|
@@ -695,6 +696,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
|
||
|
QLIST_REMOVE(giommu, giommu_next);
|
||
|
g_free(giommu);
|
||
|
}
|
||
|
+ vfio_container_destroy(bcontainer);
|
||
|
|
||
|
trace_vfio_disconnect_container(container->fd);
|
||
|
close(container->fd);
|
||
|
diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-container-base.h
|
||
|
index 56b033f59f..577f52ccbc 100644
|
||
|
--- a/include/hw/vfio/vfio-container-base.h
|
||
|
+++ b/include/hw/vfio/vfio-container-base.h
|
||
|
@@ -38,6 +38,10 @@ int vfio_container_dma_unmap(VFIOContainerBase *bcontainer,
|
||
|
hwaddr iova, ram_addr_t size,
|
||
|
IOMMUTLBEntry *iotlb);
|
||
|
|
||
|
+void vfio_container_init(VFIOContainerBase *bcontainer,
|
||
|
+ const VFIOIOMMUOps *ops);
|
||
|
+void vfio_container_destroy(VFIOContainerBase *bcontainer);
|
||
|
+
|
||
|
struct VFIOIOMMUOps {
|
||
|
/* basic feature */
|
||
|
int (*dma_map)(VFIOContainerBase *bcontainer,
|
||
|
--
|
||
|
2.39.3
|
||
|
|