From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Steve Sistare" <steven.sistare@oracle.com>,
"Zhenzhong Duan" <zhenzhong.duan@intel.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 11/27] backends/iommufd: iommufd_backend_map_file_dma
Date: Fri, 4 Jul 2025 10:45:12 +0200 [thread overview]
Message-ID: <20250704084528.1412959-12-clg@redhat.com> (raw)
In-Reply-To: <20250704084528.1412959-1-clg@redhat.com>
From: Steve Sistare <steven.sistare@oracle.com>
Define iommufd_backend_map_file_dma to implement IOMMU_IOAS_MAP_FILE.
This will be called as a substitute for iommufd_backend_map_dma, so
the error conditions for BARs are copied as-is from that function.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Link: https://lore.kernel.org/qemu-devel/1751493538-202042-6-git-send-email-steven.sistare@oracle.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
include/system/iommufd.h | 3 +++
backends/iommufd.c | 34 ++++++++++++++++++++++++++++++++++
backends/trace-events | 1 +
3 files changed, 38 insertions(+)
diff --git a/include/system/iommufd.h b/include/system/iommufd.h
index 283861b92432a1297e3e7465bdf86c3816393dcc..2d24d93d17e280bce53030a52588bd91425e03ea 100644
--- a/include/system/iommufd.h
+++ b/include/system/iommufd.h
@@ -43,6 +43,9 @@ void iommufd_backend_disconnect(IOMMUFDBackend *be);
bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id,
Error **errp);
void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id);
+int iommufd_backend_map_file_dma(IOMMUFDBackend *be, uint32_t ioas_id,
+ hwaddr iova, ram_addr_t size, int fd,
+ unsigned long start, bool readonly);
int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova,
ram_addr_t size, void *vaddr, bool readonly);
int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
diff --git a/backends/iommufd.c b/backends/iommufd.c
index c2c47abf7ed533c0512b89e58605b6b20ac103e8..3a2ecc7f5ba67699249ae1ad632fc8a45e9b53d3 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -172,6 +172,40 @@ int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova,
return ret;
}
+int iommufd_backend_map_file_dma(IOMMUFDBackend *be, uint32_t ioas_id,
+ hwaddr iova, ram_addr_t size,
+ int mfd, unsigned long start, bool readonly)
+{
+ int ret, fd = be->fd;
+ struct iommu_ioas_map_file map = {
+ .size = sizeof(map),
+ .flags = IOMMU_IOAS_MAP_READABLE |
+ IOMMU_IOAS_MAP_FIXED_IOVA,
+ .ioas_id = ioas_id,
+ .fd = mfd,
+ .start = start,
+ .iova = iova,
+ .length = size,
+ };
+
+ if (!readonly) {
+ map.flags |= IOMMU_IOAS_MAP_WRITEABLE;
+ }
+
+ ret = ioctl(fd, IOMMU_IOAS_MAP_FILE, &map);
+ trace_iommufd_backend_map_file_dma(fd, ioas_id, iova, size, mfd, start,
+ readonly, ret);
+ if (ret) {
+ ret = -errno;
+
+ /* TODO: Not support mapping hardware PCI BAR region for now. */
+ if (errno == EFAULT) {
+ warn_report("IOMMU_IOAS_MAP_FILE failed: %m, PCI BAR?");
+ }
+ }
+ return ret;
+}
+
int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
hwaddr iova, ram_addr_t size)
{
diff --git a/backends/trace-events b/backends/trace-events
index 7278214ea51144b7d7b36d64908567c9467036e8..e5f3e70cd1ba7eb532c8f763b12460ef8f552245 100644
--- a/backends/trace-events
+++ b/backends/trace-events
@@ -11,6 +11,7 @@ iommufd_backend_connect(int fd, bool owned, uint32_t users) "fd=%d owned=%d user
iommufd_backend_disconnect(int fd, uint32_t users) "fd=%d users=%d"
iommu_backend_set_fd(int fd) "pre-opened /dev/iommu fd=%d"
iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, void *vaddr, bool readonly, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" addr=%p readonly=%d (%d)"
+iommufd_backend_map_file_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int fd, unsigned long start, bool readonly, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" fd=%d start=%ld readonly=%d (%d)"
iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)"
iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)"
iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=%d ioas=%d"
--
2.50.0
next prev parent reply other threads:[~2025-07-04 8:52 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 ` [PULL 02/27] vfio/container: Fix vfio_container_post_load() Cédric Le Goater
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 ` Cédric Le Goater [this message]
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-12-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).