109 lines
3.3 KiB
Diff
109 lines
3.3 KiB
Diff
|
|
From 1bb64d6e69c385af5817dc6f0c3bbd204783c237 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:17 +0100
|
||
|
|
Subject: [PATCH] vfio/container: Introduce vfio_legacy_setup() for further
|
||
|
|
cleanups
|
||
|
|
MIME-Version: 1.0
|
||
|
|
Content-Type: text/plain; charset=UTF-8
|
||
|
|
Content-Transfer-Encoding: 8bit
|
||
|
|
|
||
|
|
This will help subsequent patches to unify the initialization of type1
|
||
|
|
and sPAPR IOMMU backends.
|
||
|
|
|
||
|
|
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>
|
||
|
|
---
|
||
|
|
hw/vfio/container.c | 60 +++++++++++++++++++++++++++------------------
|
||
|
|
1 file changed, 36 insertions(+), 24 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/hw/vfio/container.c b/hw/vfio/container.c
|
||
|
|
index 67aeaa825b..27ce31c883 100644
|
||
|
|
--- a/hw/vfio/container.c
|
||
|
|
+++ b/hw/vfio/container.c
|
||
|
|
@@ -567,6 +567,35 @@ static void shared_memory_listener_unregister(void)
|
||
|
|
g_shl = NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
+static int vfio_legacy_setup(VFIOContainerBase *bcontainer, Error **errp)
|
||
|
|
+{
|
||
|
|
+ VFIOContainer *container = container_of(bcontainer, VFIOContainer,
|
||
|
|
+ bcontainer);
|
||
|
|
+ g_autofree struct vfio_iommu_type1_info *info = NULL;
|
||
|
|
+ int ret;
|
||
|
|
+
|
||
|
|
+ ret = vfio_get_iommu_info(container, &info);
|
||
|
|
+ if (ret) {
|
||
|
|
+ error_setg_errno(errp, -ret, "Failed to get VFIO IOMMU info");
|
||
|
|
+ return ret;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ if (info->flags & VFIO_IOMMU_INFO_PGSIZES) {
|
||
|
|
+ bcontainer->pgsizes = info->iova_pgsizes;
|
||
|
|
+ } else {
|
||
|
|
+ bcontainer->pgsizes = qemu_real_host_page_size();
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ if (!vfio_get_info_dma_avail(info, &bcontainer->dma_max_mappings)) {
|
||
|
|
+ bcontainer->dma_max_mappings = 65535;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ vfio_get_info_iova_range(info, bcontainer);
|
||
|
|
+
|
||
|
|
+ vfio_get_iommu_info_migration(container, info);
|
||
|
|
+ return 0;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
||
|
|
Error **errp)
|
||
|
|
{
|
||
|
|
@@ -665,31 +694,8 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
||
|
|
case VFIO_TYPE1v2_IOMMU:
|
||
|
|
case VFIO_TYPE1_IOMMU:
|
||
|
|
case VFIO_TYPE1v2_S_IOMMU:
|
||
|
|
- {
|
||
|
|
- struct vfio_iommu_type1_info *info;
|
||
|
|
-
|
||
|
|
- ret = vfio_get_iommu_info(container, &info);
|
||
|
|
- if (ret) {
|
||
|
|
- error_setg_errno(errp, -ret, "Failed to get VFIO IOMMU info");
|
||
|
|
- goto enable_discards_exit;
|
||
|
|
- }
|
||
|
|
-
|
||
|
|
- if (info->flags & VFIO_IOMMU_INFO_PGSIZES) {
|
||
|
|
- bcontainer->pgsizes = info->iova_pgsizes;
|
||
|
|
- } else {
|
||
|
|
- bcontainer->pgsizes = qemu_real_host_page_size();
|
||
|
|
- }
|
||
|
|
-
|
||
|
|
- if (!vfio_get_info_dma_avail(info, &bcontainer->dma_max_mappings)) {
|
||
|
|
- bcontainer->dma_max_mappings = 65535;
|
||
|
|
- }
|
||
|
|
-
|
||
|
|
- vfio_get_info_iova_range(info, bcontainer);
|
||
|
|
-
|
||
|
|
- vfio_get_iommu_info_migration(container, info);
|
||
|
|
- g_free(info);
|
||
|
|
+ ret = vfio_legacy_setup(bcontainer, errp);
|
||
|
|
break;
|
||
|
|
- }
|
||
|
|
case VFIO_SPAPR_TCE_v2_IOMMU:
|
||
|
|
case VFIO_SPAPR_TCE_IOMMU:
|
||
|
|
{
|
||
|
|
@@ -699,6 +705,12 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
+ default:
|
||
|
|
+ g_assert_not_reached();
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ if (ret) {
|
||
|
|
+ goto enable_discards_exit;
|
||
|
|
}
|
||
|
|
|
||
|
|
vfio_kvm_device_add_group(group);
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|