IOMMUFD Generic interface
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v6 Latest19 patches 19 repliesIn review
- v519 patches 39 repliesSuperseded
- v417 patches 80 repliesSuperseded
Earlier versions · 3
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v3 | 15 patches | 69 replies | Superseded | |
| v2 RFC | 13 patches | 50 replies | Superseded | |
| v1 RFC | 12 patches | 109 replies | Superseded |
Changes in v6 from the cover letter · 56 lines
- Comment clarity and grammar updates
- Enforce 0 on the reserved and object_id IOMMU_OPTION values
- Add allow_unsafe_interrupts as an iommufd module option and remove the forwarding of the vfio option
- Add a test that the GUP FOLL_FORCE path is working right, since that is all being revised on the mm side.
v5: https://lore.kernel.org/r/[email protected]
- Move WARN_ON in __iommu_group_alloc_blocking_domain()
- Fix rebase error of pfn_batch::npfns
- iopt_pages_add/remove_access() is now iopt_area_add/remove_access()
- Change iopt_pages_access::refcount into an unsigned int
- Lower mutex/etc into iopt_area_add_access()
- Match VFIO error codes for some map failure modes
- Block area split if accesses are present
- Match VFIO behavior for pin/unpin when the IOVA is unaligned. Round down the IOVA to PAGE_SIZE and assume the caller will take an offset into the first page based on IOVA % PAGE_SIZE
- Increase VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL to U32_MAX for s390
- Enforce that access->ops->unmap is set if pin_pages is used
- Split the test code into several patches to stay below the 100k mailing list message size limit
- A few code naming changes for clarity
- Use double span for IOVA allocation
- Lots of comment and doc updates
v4: https://lore.kernel.org/r/[email protected]
- Rebase to v6.1-rc3, include the iommu branch with the needed EINVAL patch series and also the SVA rework
- All bug fixes and comments with no API or behavioral changes
- gvt tests are passing again
- Syzkaller is no longer finding issues and achieved high coverage of 69%(75%)
- Coverity has been run by two people
- new "nth failure" test that systematically sweeps all error unwind paths looking for splats
- All fixes noted in the mailing list
If you sent an email and I didn't reply please ping it, I have lost it.
- The selftest patch has been broken into three to make the additional modification to the main code clearer
- The interdiff is 1.8k lines for the main code, with another 3k of test suite changes
v3: https://lore.kernel.org/r/[email protected]
- Rebase to v6.1-rc1
- Improve documentation
- Use EXPORT_SYMBOL_NS
- Fix W1, checkpatch stuff
- Revise pages.c to resolve the FIXMEs. Create a interval_tree_double_span_iter which allows a simple expression of the previously problematic algorithms
- Consistently use the word 'access' instead of user to refer to an access from an in-kernel user (eg vfio mdev)
- Support two forms of rlimit accounting and make the vfio compatible one the default in compatability mode (following series)
- Support old VFIO type1 by disabling huge pages and implementing a simple algorithm to split a struct iopt_area
- Full implementation of access support, test coverage and optimizations
- Complete COPY to be able to copy across contiguous areas. Improve all the algorithms around contiguous areas with a dedicated iterator
- Functional ENFORCED_COHERENT support
- Support multi-device groups
- Lots of smaller changes (the interdiff is 5k lines)
v2: https://lore.kernel.org/r/[email protected]
- Rebase to v6.0-rc3
- Improve comments
- Change to an iterative destruction approach to avoid cycles
- Near rewrite of the vfio facing implementation, supported by a complete implementation on the vfio side
- New IOMMU_IOAS_ALLOW_IOVAS API as discussed. Allows userspace to assert that ranges of IOVA must always be mappable. To be used by a VMM that has promised a guest a certain availability of IOVA. May help guide PPC's multi-window implementation.
- Rework how unmap_iova works, user can unmap the whole ioas now
- The no-snoop / wbinvd support is implemented
- Bug fixes
- Test suite improvements
- Lots of smaller changes (the interdiff is 3k lines)
v1: https://lore.kernel.org/r/[email protected]
Patches in v6 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/19 | iommu: Add IOMMU_CAP_ENFORCE_CACHE_COHERENCYdrivers/ drivers/ include/ | +18 | 0 replies | |
| 2/19 | iommu: Add device-centric DMA ownership interfacesdrivers/ include/ | +107 | 0 replies | |
| 3/19 | interval-tree: Add a utility to iterate over spans in an interval tree.clang-format include/ lib/ +1 more | +195 | 0 replies | |
| 4/19 | scripts/kernel-doc: support EXPORT_SYMBOL_NS_GPL() with -exportscripts/ | +8 | 0 replies | |
| 5/19 | iommufd: Document overview of iommufdDocumentation/ Documentation/ | +224 | 0 replies | |
| 6/19 | iommufd: File descriptor, context, kconfig and makefilesDocumentation/ MAINTAINERS drivers/ +7 more | +571 | 2 replies | |
| 7/19 | kernel/user: Allow user::locked_vm to be usable for iommufdinclude/ kernel/ | +2 | 3 replies | |
| 8/19 | iommufd: PFN handling for iopt_pages.clang-format drivers/ drivers/ +4 more | +1262 | 4 replies | |
| 9/19 | iommufd: Algorithms for PFN storagedrivers/ drivers/ | +917 | 0 replies | |
| 10/19 | iommufd: Data structure to provide IOVA to PFN mapping.clang-format drivers/ drivers/ +2 more | +1295 | 0 replies | |
| 11/19 | iommufd: IOCTLs for the io_pagetabledrivers/ drivers/ drivers/ +2 more | +729 | 1 reply | |
| 12/19 | iommufd: Add a HW pagetable objectdrivers/ drivers/ drivers/ +2 more | +97 | 0 replies | |
| 13/19 | iommufd: Add kAPI toward external drivers for physical devicesdrivers/ drivers/ drivers/ +2 more | +437 | 0 replies | |
| 14/19 | iommufd: Add kAPI toward external drivers for kernel accessdrivers/ drivers/ drivers/ +2 more | +377 | 0 replies | |
| 15/19 | iommufd: vfio container FD ioctl compatibilitydrivers/ drivers/ drivers/ +3 more | +534 | 0 replies | |
| 16/19 | iommufd: Add kernel support for testing iommufddrivers/ drivers/ drivers/ +7 more | +1061 | 4 replies | |
| 17/19 | iommufd: Add some fault injection pointsdrivers/ drivers/ | +29 | 0 replies | |
| 18/19 | iommufd: Add additional invariant assertionsdrivers/ drivers/ drivers/ +1 more | +70 | 0 replies | |
| 19/19 | iommufd: Add a selftesttools/ tools/ tools/ +4 more | +2530 | 5 replies |
Reviews trailers per patch
15 of 19 patches have a Reviewed-by or Acked-by.
| Patch | Jonathan Corbet | Nicolin Chen | Yi Liu | Lixiao Yang | Matthew Rosato | Kevin Tian | Eric Auger | Bagas Sanjaya | Lu Baolu | Yu He |
|---|---|---|---|---|---|---|---|---|---|---|
| 1/19 | T-b | T-b | T-b | T-b | R-b | R-b | T-b | |||
| 2/19 | T-b | T-b | T-b | T-b | R-b | R-b | ||||
| 3/19 | T-b | T-b | T-b | T-b | R-b | R-b | ||||
| 4/19 | A-b | |||||||||
| 5/19 | R-b | R-b | ||||||||
| 6/19 | T-b | T-b | T-b | T-b | R-b | R-b | R-b | |||
| 7/19 | T-b | T-b | T-b | T-b | R-b | R-b | ||||
| 8/19 | T-b | T-b | T-b | T-b | R-b | |||||
| 9/19 | T-b | T-b | T-b | T-b | R-b | |||||
| 10/19 | T-b | T-b | T-b | T-b | R-b | |||||
| 11/19 | T-b | T-b | T-b | T-b | R-b | R-b | ||||
| 12/19 | T-b | T-b | T-b | T-b | R-b | R-b | ||||
| 13/19 | T-b | T-b | T-b | T-b | R-b | |||||
| 14/19 | T-b | T-b | T-b | T-b | R-b | |||||
| 15/19 | T-b | T-b | T-b | T-b | R-b | R-b | ||||
| 16/19 | T-b | |||||||||
| 17/19 | T-b | |||||||||
| 18/19 | T-b | T-b | ||||||||
| 19/19 | T-b | T-b | T-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 10 reviewers.
Cover letter [PATCH v6 00/19] IOMMUFD Generic interface
[
There is very little functional change in this verion. We are at rc7 now, so I intend to apply this version and stop changing the branch. Unless something major happens this will be the final posting of this series.
New functional changes will have to come as followup patches from this point.
I will continue to rebase to collect any tags and documentation/comment changes. The branch will be sent as a PR to Linus promptly on the Monday of the merge window.
Thank you to all
]
iommufd is the user API to control the IOMMU subsystem as it relates to managing IO page tables that point at user space memory.
It takes over from drivers/vfio/vfio_iommu_type1.c (aka the VFIO container) which is the VFIO specific interface for a similar idea.
We see a broad need for extended features, some being highly IOMMU device specific:
- Binding iommu_domain's to PASID/SSID
- Userspace IO page tables, for ARM, x86 and S390
- Kernel bypassed invalidation of user page tables
- Re-use of the KVM page table in the IOMMU
- Dirty page tracking in the IOMMU
- Runtime Increase/Decrease of IOPTE size
- PRI support with faults resolved in userspace
Many of these HW features exist to support VM use cases - for instance the combination of PASID, PRI and Userspace IO Page Tables allows an implementation of DMA Shared Virtual Addressing (vSVA) within a guest. Dirty tracking enables VM live migration with SRIOV devices and PASID support allow creating "scalable IOV" devices, among other things.
As these features are fundamental to a VM platform they need to be uniformly exposed to all the driver families that do DMA into VMs, which is currently VFIO and VDPA.
The pre-v1 series proposed re-using the VFIO type 1 data structure, however it was suggested that if we are doing this big update then we should also come with an improved data structure that solves the limitations that VFIO type1 has. Notably this addresses:
- Multiple IOAS/'containers' and multiple domains inside a single FD
- Single-pin operation no matter how many domains and containers use a page
- A fine grained locking scheme supporting user managed concurrency for multi-threaded map/unmap
- A pre-registration mechanism to optimize vIOMMU use cases by pre-pinning pages
- Extended ioctl API that can manage these new objects and exposes domains directly to user space
- domains are sharable between subsystems, eg VFIO and VDPA
The bulk of this code is a new data structure design to track how the IOVAs are mapped to PFNs.
iommufd intends to be general and consumable by any driver that wants to DMA to userspace. From a driver perspective it can largely be dropped in in-place of iommu_attach_device() and provides a uniform full feature set to all consumers.
As this is a larger project this series is the first step. This series provides the iommfd "generic interface" which is designed to be suitable for applications like DPDK and VMM flows that are not optimized to specific HW scenarios. It is close to being a drop in replacement for the existing VFIO type 1 and supports existing qemu based VM flows.
Several follow-on series are being prepared:
- Patches integrating with qemu in native mode:
https://github.com/yiliu1765/qemu/commits/qemu-iommufd-6.0-rc2
- A completed integration with VFIO now exists that covers "emulated" mdev use cases now, and can pass testing with qemu/etc in compatability mode:
https://github.com/jgunthorpe/linux/commits/vfio_iommufd
- A draft providing system iommu dirty tracking on top of iommufd, including iommu driver implementations:
https://github.com/jpemartins/linux/commits/x86-iommufd
This pairs with patches for providing a similar API to support VFIO-device tracking to give a complete vfio solution:
https://lore.kernel.org/kvm/[email protected]/
- Userspace page tables aka 'nested translation' for ARM and Intel iommu drivers:
https://github.com/nicolinc/iommufd/commits/iommufd_nesting
- "device centric" vfio series to expose the vfio_device FD directly as a normal cdev, and provide an extended API allowing dynamically changing the IOAS binding:
https://github.com/yiliu1765/iommufd/commits/iommufd-v6.0-rc2-nesting-0901
- Drafts for PASID and PRI interfaces are included above as well
Overall enough work is done now to show the merit of the new API design and at least draft solutions to many of the main problems.
Several people have contributed directly to this work: Eric Auger, Joao Martins, Kevin Tian, Lu Baolu, Nicolin Chen, Yi L Liu. Many more have participated in the discussions that lead here, and provided ideas. Thanks to all!
The v1/v2 iommufd series has been used to guide a large amount of preparatory work that has now been merged. The general theme is to organize things in a way that makes injecting iommufd natural:
- VFIO live migration support with mlx5 and hisi_acc drivers. These series need a dirty tracking solution to be really usable.
https://lore.kernel.org/kvm/[email protected]/
https://lore.kernel.org/kvm/[email protected]/
- Significantly rework the VFIO gvt mdev and remove struct mdev_parent_ops
https://lore.kernel.org/lkml/[email protected]/
- Rework how PCIe no-snoop blocking works
https://lore.kernel.org/kvm/[email protected]/
- Consolidate dma ownership into the iommu core code
https://lore.kernel.org/linux-iommu/[email protected]/
- Make all vfio driver interfaces use struct vfio_device consistently
https://lore.kernel.org/kvm/[email protected]/
- Remove the vfio_group from the kvm/vfio interface
https://lore.kernel.org/kvm/[email protected]/
- Simplify locking in vfio
https://lore.kernel.org/kvm/[email protected]/
- Remove the vfio notifiter scheme that faces drivers
https://lore.kernel.org/kvm/[email protected]/
- Improve the driver facing API for vfio pin/unpin pages to make the presence of struct page clear
https://lore.kernel.org/kvm/[email protected]/
- Clean up in the Intel IOMMU driver
https://lore.kernel.org/linux-iommu/[email protected]/
https://lore.kernel.org/linux-iommu/[email protected]/
https://lore.kernel.org/linux-iommu/[email protected]/
https://lore.kernel.org/linux-iommu/[email protected]/
https://lore.kernel.org/linux-iommu/[email protected]/
- Rework s390 vfio drivers
https://lore.kernel.org/kvm/[email protected]/
- Normalize vfio ioctl handling
https://lore.kernel.org/kvm/[email protected]/
- VFIO API for dirty tracking (aka dma logging) managed inside a PCI device, with mlx5 implementation
https://lore.kernel.org/kvm/[email protected]
- Introduce a struct device sysfs presence for struct vfio_device
https://lore.kernel.org/kvm/[email protected]/
- Complete restructuring the vfio mdev model
https://lore.kernel.org/kvm/[email protected]/
- Isolate VFIO container code in preperation for iommufd to provide an alternative implementation of it all
https://lore.kernel.org/kvm/[email protected]
- Simplify and consolidate iommu_domain/device compatability checking
https://lore.kernel.org/linux-iommu/[email protected]/
- Align iommu SVA support with the domain-centric model
https://lore.kernel.org/all/[email protected]/
This is about 233 patches applied since March, thank you to everyone involved in all this work!
Currently there are a number of supporting series still in progress:
- DMABUF exporter support for VFIO to allow PCI P2P with VFIO
https://lore.kernel.org/r/[email protected]
- Start to provide iommu_domain ops for POWER
https://lore.kernel.org/all/[email protected]/
However, these are not necessary for this series to advance.
Syzkaller coverage has been merged and is now running in the syzbot environment on linux-next:
https://github.com/google/syzkaller/pull/3515
https://github.com/google/syzkaller/pull/3521
This is on github: https://github.com/jgunthorpe/linux/commits/iommufd
v6:
- Comment clarity and grammar updates
- Enforce 0 on the reserved and object_id IOMMU_OPTION values
- Add allow_unsafe_interrupts as an iommufd module option and remove the forwarding of the vfio option
- Add a test that the GUP FOLL_FORCE path is working right, since that is all being revised on the mm side.
v5: https://lore.kernel.org/r/[email protected]
- Move WARN_ON in __iommu_group_alloc_blocking_domain()
- Fix rebase error of pfn_batch::npfns
- iopt_pages_add/remove_access() is now iopt_area_add/remove_access()
- Change iopt_pages_access::refcount into an unsigned int
- Lower mutex/etc into iopt_area_add_access()
- Match VFIO error codes for some map failure modes
- Block area split if accesses are present
- Match VFIO behavior for pin/unpin when the IOVA is unaligned. Round down the IOVA to PAGE_SIZE and assume the caller will take an offset into the first page based on IOVA % PAGE_SIZE
- Increase VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL to U32_MAX for s390
- Enforce that access->ops->unmap is set if pin_pages is used
- Split the test code into several patches to stay below the 100k mailing list message size limit
- A few code naming changes for clarity
- Use double span for IOVA allocation
- Lots of comment and doc updates
v4: https://lore.kernel.org/r/[email protected]
- Rebase to v6.1-rc3, include the iommu branch with the needed EINVAL patch series and also the SVA rework
- All bug fixes and comments with no API or behavioral changes
- gvt tests are passing again
- Syzkaller is no longer finding issues and achieved high coverage of 69%(75%)
- Coverity has been run by two people
- new "nth failure" test that systematically sweeps all error unwind paths looking for splats
- All fixes noted in the mailing list
If you sent an email and I didn't reply please ping it, I have lost it.
- The selftest patch has been broken into three to make the additional modification to the main code clearer
- The interdiff is 1.8k lines for the main code, with another 3k of test suite changes
v3: https://lore.kernel.org/r/[email protected]
- Rebase to v6.1-rc1
- Improve documentation
- Use EXPORT_SYMBOL_NS
- Fix W1, checkpatch stuff
- Revise pages.c to resolve the FIXMEs. Create a interval_tree_double_span_iter which allows a simple expression of the previously problematic algorithms
- Consistently use the word 'access' instead of user to refer to an access from an in-kernel user (eg vfio mdev)
- Support two forms of rlimit accounting and make the vfio compatible one the default in compatability mode (following series)
- Support old VFIO type1 by disabling huge pages and implementing a simple algorithm to split a struct iopt_area
- Full implementation of access support, test coverage and optimizations
- Complete COPY to be able to copy across contiguous areas. Improve all the algorithms around contiguous areas with a dedicated iterator
- Functional ENFORCED_COHERENT support
- Support multi-device groups
- Lots of smaller changes (the interdiff is 5k lines)
v2: https://lore.kernel.org/r/[email protected]
- Rebase to v6.0-rc3
- Improve comments
- Change to an iterative destruction approach to avoid cycles
- Near rewrite of the vfio facing implementation, supported by a complete implementation on the vfio side
- New IOMMU_IOAS_ALLOW_IOVAS API as discussed. Allows userspace to assert that ranges of IOVA must always be mappable. To be used by a VMM that has promised a guest a certain availability of IOVA. May help guide PPC's multi-window implementation.
- Rework how unmap_iova works, user can unmap the whole ioas now
- The no-snoop / wbinvd support is implemented
- Bug fixes
- Test suite improvements
- Lots of smaller changes (the interdiff is 3k lines)
v1: https://lore.kernel.org/r/[email protected]
Jason Gunthorpe (17):
iommu: Add IOMMU_CAP_ENFORCE_CACHE_COHERENCY
interval-tree: Add a utility to iterate over spans in an interval tree scripts/kernel-doc: support EXPORT_SYMBOL_NS_GPL() with -export
iommufd: File descriptor, context, kconfig and makefiles kernel/user: Allow user::locked_vm to be usable for iommufd
iommufd: PFN handling for iopt_pages
iommufd: Algorithms for PFN storage
iommufd: Data structure to provide IOVA to PFN mapping
iommufd: IOCTLs for the io_pagetable
iommufd: Add a HW pagetable object
iommufd: Add kAPI toward external drivers for physical devices
iommufd: Add kAPI toward external drivers for kernel access
iommufd: vfio container FD ioctl compatibility
iommufd: Add kernel support for testing iommufd
iommufd: Add some fault injection points
iommufd: Add additional invariant assertions
iommufd: Add a selftest
Kevin Tian (1):
iommufd: Document overview of iommufd
Lu Baolu (1):
iommu: Add device-centric DMA ownership interfaces
.clang-format | 3 + Documentation/userspace-api/index.rst | 1 + .../userspace-api/ioctl/ioctl-number.rst | 1 + Documentation/userspace-api/iommufd.rst | 223 ++ MAINTAINERS | 12 + drivers/iommu/Kconfig | 1 + drivers/iommu/Makefile | 2 +- drivers/iommu/amd/iommu.c | 2 + drivers/iommu/intel/iommu.c | 16 +- drivers/iommu/iommu.c | 121 +- drivers/iommu/iommufd/Kconfig | 24 + drivers/iommu/iommufd/Makefile | 13 + drivers/iommu/iommufd/device.c | 778 +++++++ drivers/iommu/iommufd/double_span.h | 53 + drivers/iommu/iommufd/hw_pagetable.c | 57 + drivers/iommu/iommufd/io_pagetable.c | 1212 ++++++++++ drivers/iommu/iommufd/io_pagetable.h | 241 ++ drivers/iommu/iommufd/ioas.c | 398 ++++ drivers/iommu/iommufd/iommufd_private.h | 307 +++ drivers/iommu/iommufd/iommufd_test.h | 93 + drivers/iommu/iommufd/main.c | 424 ++++ drivers/iommu/iommufd/pages.c | 1981 +++++++++++++++++ drivers/iommu/iommufd/selftest.c | 853 +++++++ drivers/iommu/iommufd/vfio_compat.c | 472 ++++ include/linux/interval_tree.h | 58 + include/linux/iommu.h | 17 + include/linux/iommufd.h | 98 + include/linux/sched/user.h | 2 +- include/uapi/linux/iommufd.h | 345 +++ kernel/user.c | 1 + lib/Kconfig | 4 + lib/interval_tree.c | 132 ++ scripts/kernel-doc | 12 +- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/iommu/.gitignore | 3 + tools/testing/selftests/iommu/Makefile | 12 + tools/testing/selftests/iommu/config | 2 + tools/testing/selftests/iommu/iommufd.c | 1654 ++++++++++++++ .../selftests/iommu/iommufd_fail_nth.c | 580 +++++ tools/testing/selftests/iommu/iommufd_utils.h | 278 +++ 40 files changed, 10450 insertions(+), 37 deletions(-) create mode 100644 Documentation/userspace-api/iommufd.rst create mode 100644 drivers/iommu/iommufd/Kconfig create mode 100644 drivers/iommu/iommufd/Makefile create mode 100644 drivers/iommu/iommufd/device.c create mode 100644 drivers/iommu/iommufd/double_span.h create mode 100644 drivers/iommu/iommufd/hw_pagetable.c create mode 100644 drivers/iommu/iommufd/io_pagetable.c create mode 100644 drivers/iommu/iommufd/io_pagetable.h create mode 100644 drivers/iommu/iommufd/ioas.c create mode 100644 drivers/iommu/iommufd/iommufd_private.h create mode 100644 drivers/iommu/iommufd/iommufd_test.h create mode 100644 drivers/iommu/iommufd/main.c create mode 100644 drivers/iommu/iommufd/pages.c create mode 100644 drivers/iommu/iommufd/selftest.c create mode 100644 drivers/iommu/iommufd/vfio_compat.c create mode 100644 include/linux/iommufd.h create mode 100644 include/uapi/linux/iommufd.h create mode 100644 tools/testing/selftests/iommu/.gitignore create mode 100644 tools/testing/selftests/iommu/Makefile create mode 100644 tools/testing/selftests/iommu/config create mode 100644 tools/testing/selftests/iommu/iommufd.c create mode 100644 tools/testing/selftests/iommu/iommufd_fail_nth.c create mode 100644 tools/testing/selftests/iommu/iommufd_utils.h
base-commit: 69e61edebea030f177de7a23b8d5d9b8c4a90bda
Signature · 1 line
2.38.1