[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [PATCH V3 31/42] vfio/iommufd: use IOMMU_IOAS_MAP_FILE
From: |
Duan, Zhenzhong |
Subject: |
RE: [PATCH V3 31/42] vfio/iommufd: use IOMMU_IOAS_MAP_FILE |
Date: |
Fri, 16 May 2025 08:48:35 +0000 |
>-----Original Message-----
>From: Steve Sistare <steven.sistare@oracle.com>
>Subject: [PATCH V3 31/42] vfio/iommufd: use IOMMU_IOAS_MAP_FILE
>
>Use IOMMU_IOAS_MAP_FILE when the mapped region is backed by a file.
>Such a mapping can be preserved without modification during CPR,
>because it depends on the file's address space, which does not change,
>rather than on the process's address space, which does change.
>
>Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
>---
> hw/vfio/container-base.c | 9 +++++++++
> hw/vfio/iommufd.c | 13 +++++++++++++
> include/hw/vfio/vfio-container-base.h | 3 +++
> 3 files changed, 25 insertions(+)
>
>diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c
>index 8f43bc8..72a51a6 100644
>--- a/hw/vfio/container-base.c
>+++ b/hw/vfio/container-base.c
>@@ -79,7 +79,16 @@ int vfio_container_dma_map(VFIOContainerBase
>*bcontainer,
> RAMBlock *rb)
> {
> VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
>+ int mfd = rb ? qemu_ram_get_fd(rb) : -1;
>
>+ if (mfd >= 0 && vioc->dma_map_file) {
>+ unsigned long start = vaddr - qemu_ram_get_host_addr(rb);
>+ unsigned long offset = qemu_ram_get_fd_offset(rb);
>+
>+ vioc->dma_map_file(bcontainer, iova, size, mfd, start + offset,
>+ readonly);
Shouldn't we return result to call site?
>+ return 0;
>+ }
> g_assert(vioc->dma_map);
> return vioc->dma_map(bcontainer, iova, size, vaddr, readonly);
> }
>diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>index 167bda4..6eb417a 100644
>--- a/hw/vfio/iommufd.c
>+++ b/hw/vfio/iommufd.c
>@@ -44,6 +44,18 @@ static int iommufd_cdev_map(const VFIOContainerBase
>*bcontainer, hwaddr iova,
> iova, size, vaddr, readonly);
> }
>
>+static int iommufd_cdev_map_file(const VFIOContainerBase *bcontainer,
>+ hwaddr iova, ram_addr_t size,
>+ int fd, unsigned long start, bool readonly)
>+{
>+ const VFIOIOMMUFDContainer *container =
>+ container_of(bcontainer, VFIOIOMMUFDContainer, bcontainer);
>+
>+ return iommufd_backend_map_file_dma(container->be,
>+ container->ioas_id,
>+ iova, size, fd, start, readonly);
>+}
>+
> static int iommufd_cdev_unmap(const VFIOContainerBase *bcontainer,
> hwaddr iova, ram_addr_t size,
> IOMMUTLBEntry *iotlb, bool unmap_all)
>@@ -802,6 +814,7 @@ static void vfio_iommu_iommufd_class_init(ObjectClass
>*klass, const void *data)
> VFIOIOMMUClass *vioc = VFIO_IOMMU_CLASS(klass);
>
> vioc->dma_map = iommufd_cdev_map;
>+ vioc->dma_map_file = iommufd_cdev_map_file;
> vioc->dma_unmap = iommufd_cdev_unmap;
> vioc->attach_device = iommufd_cdev_attach;
> vioc->detach_device = iommufd_cdev_detach;
>diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-
>container-base.h
>index 03b3f9c..f30f828 100644
>--- a/include/hw/vfio/vfio-container-base.h
>+++ b/include/hw/vfio/vfio-container-base.h
>@@ -123,6 +123,9 @@ struct VFIOIOMMUClass {
> int (*dma_map)(const VFIOContainerBase *bcontainer,
> hwaddr iova, ram_addr_t size,
> void *vaddr, bool readonly);
>+ int (*dma_map_file)(const VFIOContainerBase *bcontainer,
>+ hwaddr iova, ram_addr_t size,
>+ int fd, unsigned long start, bool readonly);
> /**
> * @dma_unmap
> *
>--
>1.8.3.1
- Re: [PATCH V3 16/42] vfio/pci: vfio_vector_init, (continued)
- [PATCH V3 19/42] vfio/pci: vfio_notifier_init cpr parameters, Steve Sistare, 2025/05/12
- [PATCH V3 18/42] vfio/pci: pass vector to virq functions, Steve Sistare, 2025/05/12
- [PATCH V3 21/42] vfio/pci: export MSI functions, Steve Sistare, 2025/05/12
- [PATCH V3 32/42] vfio/iommufd: export iommufd_cdev_get_info_iova_range, Steve Sistare, 2025/05/12
- [PATCH V3 34/42] vfio/iommufd: invariant device name, Steve Sistare, 2025/05/12
- [PATCH V3 31/42] vfio/iommufd: use IOMMU_IOAS_MAP_FILE, Steve Sistare, 2025/05/12
- RE: [PATCH V3 31/42] vfio/iommufd: use IOMMU_IOAS_MAP_FILE,
Duan, Zhenzhong <=
- [PATCH V3 22/42] vfio-pci: preserve MSI, Steve Sistare, 2025/05/12
- [PATCH V3 26/42] vfio: return mr from vfio_get_xlat_addr, Steve Sistare, 2025/05/12
- Re: [PATCH V3 26/42] vfio: return mr from vfio_get_xlat_addr, Steven Sistare, 2025/05/15
- Re: [PATCH V3 26/42] vfio: return mr from vfio_get_xlat_addr, Mark Cave-Ayland, 2025/05/13
[PATCH V3 28/42] backends/iommufd: iommufd_backend_map_file_dma, Steve Sistare, 2025/05/12