Skip to content

vfio-pci support pasid attach/detach

Yi Liu kvm 9 versions – Applied

Status from this message: Applied to iommufd for-next, thanks

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest5 patches 2 repliesApplied
  2. v85 patches 19 repliesSuperseded
  3. v75 patches 0 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v65 patches11 repliesSuperseded
v55 patches10 repliesSuperseded
v44 patches5 repliesSuperseded
v34 patches25 repliesSuperseded
v24 patches97 repliesSuperseded
v13 patches27 repliesSuperseded

Changes in v9 from the cover letter

- Remove unnecessary parentheses in flag check (Nic)
- Use the MOCK_PASID_WIDTH in the place of 20 is used in patch 05 (Nic)
- Drop duplicated pci.h include (Nic)

Patches in v9 Applied

#Subject and filesSizeRepliesApplied
1/5ida: Add ida_find_first_range()include/linux/idr.h lib/idr.c lib/test_ida.c+148 -00 replies
2/5vfio-iommufd: Support pasid [at|de]tach for physical VFIO devicesdrivers/vfio/iommufd.c drivers/vfio/pci/vfio_pci.c include/linux/vfio.h+66 -00 replies
3/5vfio: VFIO_DEVICE_[AT|DE]TACH_IOMMUFD_PT support pasiddrivers/vfio/device_cdev.c include/uapi/linux/vfio.h+71 -180 replies
4/5iommufd: Extend IOMMU_GET_HW_INFO to report PASID capabilitydrivers/iommu/iommufd/device.c drivers/pci/ats.c include/linux/pci-ats.h +1 more+82 -20 replies
5/5iommufd/selftest: Add coverage for reporting max_pasid_log2 via IOMMU_HW_INFOtools/testing/selftests/iommu/iommufd.c tools/testing/selftests/iommu/iommufd_fail_nth.c tools/testing/selftests/iommu/iommufd_utils.h+33 -51 reply

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchJason GunthorpeKevin TianMatthew Wilcox (Oracle)Alex WilliamsonNicolin ChenZhangfei Gao
1/5R-b R-b A-b
2/5R-b R-b
3/5R-b R-b R-b
4/5R-b R-b T-b
5/5R-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 6 reviewers.

Read the v9 thread

Cover letter [PATCH v9 0/5] vfio-pci support pasid attach/detach

This series introduces the PASID attach/detach user APIs (uAPIs) that allow userspace to attach or detach a device's PASID to or from a specified IOAS/hwpt. Currently, only the vfio-pci driver is enabled in this series.

Following this update, PASID-capable devices bound to vfio-pci can report PASID capabilities to userspace and virtual machines (VMs), facilitating PASID use cases such as Shared Virtual Addressing (SVA). In discussions about reporting the virtual PASID (vPASID) to VMs [1], it was agreed that the userspace virtual machine monitor (VMM) will synthesize the vPASID capability. The VMM must identify a suitable location to insert the vPASID capability, including handling hidden bits for certain devices. However, this responsibility lies with userspace and is not the focus of this series.

This series begins by adding helpers for PASID attachment in the vfio core, then extends the device character device (cdev) attach/detach ioctls to support PASID attach/detach operations. At the conclusion of this series, the IOMMU_GET_HW_INFO ioctl is extended to report PCI PASID capabilities to userspace. Userspace should verify this capability before utilizing any PASID-related uAPIs provided by VFIO, as agreed in [2]. This series depends on the iommufd PASID attach/detach series [3].

The complete code is available at [4] and has been tested with a modified QEMU branch [5].

[1] https://lore.kernel.org/kvm/BN9PR11MB5276318969A212AD0649C7BE8CBE2@BN9PR11MB5276.namprd11.prod.outlook.com/
[2] https://lore.kernel.org/kvm/[email protected]/
[3] https://lore.kernel.org/linux-iommu/[email protected]/
[4] https://github.com/yiliu1765/iommufd/tree/iommufd_pasid
[5] https://github.com/yiliu1765/qemu/tree/wip/zhenzhong/iommufd_nesting_rfcv2-test-pasid

Change log:

v9:
- Remove unnecessary parentheses in flag check (Nic)
- Use the MOCK_PASID_WIDTH in the place of 20 is used in patch 05 (Nic)
- Drop duplicated pci.h include (Nic)

v8: https://lore.kernel.org/kvm/[email protected]/
- Rebased on top of the latest iommufd series, mainly using the latest kAPI for pasid attach

v7: https://lore.kernel.org/kvm/[email protected]/#t
- Add Alex's and Kevin's r-b on vfio patches
- Minor tweaks on patch 04 (Kevin)

v6: https://lore.kernel.org/kvm/[email protected]/
- Drop the vfio_copy_user_data() generalization as it is not totally clear what it would cover. (Alex)
- Reworked the patch 03 of v5 a bit. e.g. lift the pasid_{at|de}tach_ioas op test before the second user data copy; make 'if (xend > minsz)' to be 'if (xend)' and remove the comment accordingly. This is because we don't generalize the user data copy now, so xend is either 0 or non-zero, no need to check against minsz.
- Make the IOMMU_GET_HW_INFO report out_max_pasid_log2 by checking the dev->iommu->max_pasids. This is because iommu drivers enables PASID as long as it supports. So checking it is enough. Also, it is more friendly to non-PCI PASID supports compared with reading the PCI config space to check if PASID is enabled.
- Add selftest coverage for reporting max_pasid_log2 in IOMMU_HW_INFO ioctl.

v5: https://lore.kernel.org/kvm/[email protected]/
- Fix a wrong return value (Alex)
- Fix the policy of setting the xend array per flag extension (Alex)
- A separate patch to generalize the code of copy user data (Alex)

v4: https://lore.kernel.org/kvm/[email protected]/
- Add acked-by for the ida patch from Matthew
- Add r-b from Kevin and Jason on patch 01, 02 and 04 of v3
- Add common code to copy user data for the user struct with new fields
- Extend the VFIO_DEVICE_[AT|DE]TACH_IOMMUFD_PT to support pasid, patch 03 is updated per this change. Hence drop r-b of it. (Kevin, Alex)
- Add t-b from Zhangfei for patch 4 of v3
- Nits from Vasant

v3: https://lore.kernel.org/linux-iommu/[email protected]/
- Misc enhancement on patch 01 of v2 (Alex, Jason)
- Add Jason's r-b to patch 03 of v2
- Drop the logic that report PASID via VFIO_DEVICE_FEATURE ioctl
- Extend IOMMU_GET_HW_INFO to report PASID support (Kevin, Jason, Alex)

v2: https://lore.kernel.org/kvm/[email protected]/
- Use IDA to track if PASID is attached or not in VFIO. (Jason)
- Fix the issue of calling pasid_at[de]tach_ioas callback unconditionally (Alex)
- Fix the wrong data copy in vfio_df_ioctl_pasid_detach_pt() (Zhenzhong)
- Minor tweaks in comments (Kevin)

v1: https://lore.kernel.org/kvm/[email protected]/
- Report PASID capability via VFIO_DEVICE_FEATURE (Alex)

rfc: https://lore.kernel.org/linux-iommu/[email protected]/

Regards,
Yi Liu

Yi Liu (5):
ida: Add ida_find_first_range()
vfio-iommufd: Support pasid [at|de]tach for physical VFIO devices
vfio: VFIO_DEVICE_[AT|DE]TACH_IOMMUFD_PT support pasid
iommufd: Extend IOMMU_GET_HW_INFO to report PASID capability iommufd/selftest: Add coverage for reporting max_pasid_log2 via
IOMMU_HW_INFO

 drivers/iommu/iommufd/device.c                | 34 ++++++++-
 drivers/pci/ats.c                             | 33 +++++++++
 drivers/vfio/device_cdev.c                    | 60 +++++++++++++---
 drivers/vfio/iommufd.c                        | 50 +++++++++++++
 drivers/vfio/pci/vfio_pci.c                   |  2 +
 include/linux/idr.h                           | 11 +++
 include/linux/pci-ats.h                       |  3 +
 include/linux/vfio.h                          | 14 ++++
 include/uapi/linux/iommufd.h                  | 14 +++-
 include/uapi/linux/vfio.h                     | 29 +++++---
 lib/idr.c                                     | 67 ++++++++++++++++++
 lib/test_ida.c                                | 70 +++++++++++++++++++
 tools/testing/selftests/iommu/iommufd.c       | 18 +++++
 .../selftests/iommu/iommufd_fail_nth.c        |  3 +-
 tools/testing/selftests/iommu/iommufd_utils.h | 17 +++--
 15 files changed, 400 insertions(+), 25 deletions(-)
Signature · 1 line
2.34.1