All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 00/12] iommufd support pasid attach/replace
@ 2025-02-26 11:40 Yi Liu
  2025-02-26 11:40 ` [PATCH v8 01/12] iommu: Add iommu_attach_device_pasid_handle() Yi Liu
                   ` (11 more replies)
  0 siblings, 12 replies; 75+ messages in thread
From: Yi Liu @ 2025-02-26 11:40 UTC (permalink / raw)
  To: kevin.tian, jgg; +Cc: joro, baolu.lu, yi.l.liu, iommu, nicolinc

PASID (Process Address Space ID) is a PCIe extension that tags the DMA
transactions from a physical device. Most modern IOMMU hardware supports
PASID-granular address translation. This allows a PASID-capable device
to be attached to multiple hardware page tables (hwpts, also known as
domains), with each attachment tagged by a PASID.

This series builds on previous series [1] [2]. It begins by adding a missing
IOMMU API to replace the domain for a PASID. Utilizing the IOMMU PASID
attach/replace/detach APIs, this series introduces iommufd APIs for device
drivers to attach, replace, or detach PASIDs to/from hwpts at the request
of userspace. It also enforces PASID compatibility with domain requirements,
allocates PASID-compatible hwpts in iommufd, and includes self-tests to
validate the iommufd APIs.

The complete code is available at the following link [3]. Please note that
the existing iommufd self-test was broken, and a temporary fix patch is at
the top of the branch [3]. If you wish to run the iommufd self-test, please
apply that fix. We apologize for any inconvenience.

[1] https://lore.kernel.org/linux-iommu/20250226011849.5102-1-yi.l.liu@intel.com/
[2] https://lore.kernel.org/linux-iommu/20250226050130.5814-1-yi.l.liu@intel.com/
[3] https://github.com/yiliu1765/iommufd/tree/iommufd_pasid

Change log:

v8:
 - Rebase on top of the dependency patch series
 - Check both handle and domain in the iommu_replace_device_pasid_handle()
   to support replace between domain and handle.
 - Fix a typo in patch 02 of v7 (Kevin)
 - Dropped patch 11 0f v7 as it is included in a series to add iommufd
   selftest to cover replace between domain and handle.
 - r-b tag on patch 01 of v7 (Kevin)
 - Add selftest for replace between handle and non-handle case

v7: https://lore.kernel.org/linux-iommu/20250216035228.23831-1-yi.l.liu@intel.com/
 - Remove the iommu_attach_handle related refactors, as they have been addressed
   by Nic's series.
 - Address the comments on patch 01 of v6 in a separate series [1]. Store either
   the domain or handle in group->pasid_array, and swap the order of setting
   group->pasid_array and invoking the attach operation of IOMMU drivers.
 - Introduce iommu_attach_device_pasid_handle() and iommu_replace_device_pasid_handle(),
   and remove iommu_replace_device_pasid() since iommufd consistently uses the
   _handle() API.
 - Add patch 04 to include reserved_iova only for the RID path, as the underlying
   helpers are shared by both the RID and PASID paths, but only the RID path needs
   to add reserved_iova.
 - Remove the iommu_dev.max_pasids check in patch 11 of v6. The mock IOMMU always
   supports 20-bit PASIDs, so there is no need to verify PASID support in the mock
   IOMMU driver. Additionally, the IOMMU_HWPT_ALLOC_PASID flag does not imply PASID
   support, so it should be removed to avoid misleading IOMMU driver programming.

v6: https://lore.kernel.org/linux-iommu/20241219132746.16193-1-yi.l.liu@intel.com/
 - Add kdoc to iommufd_device_get_attach_handle() to note the returned handle
   should be used with care. (Baolu)
 - Reworked the patch 07 and 08 of v5 to avoid domain allocation failure on VT-d
   after applying patch 07 of v5.
     1) Split out the intel iommu driver IOMMU_HWPT_ALLOC_PASID support out of
	patch 08
     2) Rework the PASID-compatible domain enforcement by checking the RID domain
	and idev->pasid_hwpts under the idev->igroup->lock.
 - iommufd_device_pasid_do_attach() returns -EINVAL if there is old hwpt and it's
   not the same with new hwpt. This aligns with how the iommufd_device_do_attach()
   deals it. Otherwise, attaching the same pasid to the same ioas is going to fail
   before the auto_domain loop goes to the correct hwpt. Thsi is not reasonable. So
   make this change.
 - Enhanced the pasid selftest to have non-pasid-capable device and pasid-capable
   device.
 - The order of the series is tweaked to be prepare the iommufd for pasid attach,
   add pasid attach, add PASID-compat domain enforcement and then add the PASID-compat
   hwpt allocation.
 - Rebased on top of 6.13-rc3 and some already applied patches.

v5: https://lore.kernel.org/linux-iommu/20241104132513.15890-1-yi.l.liu@intel.com/
 - Fix a mistake in patch 02 of v4 (Kevin)
 - Move the iommufd_handle helpers to device.c
 - Add IOMMU_HWPT_ALLOC_PASID check to enforce pasid-compatible domain for pasid
   capable device in iommufd
 - Update the iommufd selftest to use IOMMU_HWPT_ALLOC_PASID

v4: https://lore.kernel.org/linux-iommu/20240912131255.13305-1-yi.l.liu@intel.com/
 - Replace remove_dev_pasid() by supporting set_dev_pasid() for blocking domain (Kevin)
	- This is done by the preparation series "Support attaching PASID to the blocked_domain"
 - Misc tweaks to foil the merging of the iommufd iopf series. Three new patches are added:
	- iommufd: Always pass iommu_attach_handle to iommu core
	- iommufd: Move the iommufd_handle helpers to iommufd_private.h
	- iommufd: Refactor __fault_domain_replace_dev() to be a wrapper of iommu_replace_group_handle()
 - Renmae patch 03 of v3 to be "iommufd: Support pasid attach/replace"
 - Add test case for attaching/replacing iopf-capable hwpt to pasid

v3: https://lore.kernel.org/kvm/20240628090557.50898-1-yi.l.liu@intel.com/
 - Split the set_dev_pasid op enhancements for domain replacement to be a
   separate series "Make set_dev_pasid op supportting domain replacement" [1].
   The below changes are made in the separate series.
   *) set_dev_pasid() callback should keep the old config if failed to attach to
      a domain. This simplifies the caller a lot as caller does not need to attach
      it back to old domain explicitly. This also avoids some corner cases in which
      the core may do duplicated domain attachment as described in below link (Jason)
      https://lore.kernel.org/linux-iommu/BN9PR11MB52768C98314A95AFCD2FA6478C0F2@BN9PR11MB5276.namprd11.prod.outlook.com/
   *) Drop patch 10 of v2 as it's a bug fix and can be submitted separately (Kevin)
   *) Rebase on top of Baolu's domain_alloc_paging refactor series (Jason)
 - Drop the attach_data which includes attach_fn and pasid, insteadly passing the
   pasid through the device attach path. (Jason)
 - Add a pasid-num-bits property to mock dev to make pasid selftest work (Kevin)

v2: https://lore.kernel.org/linux-iommu/20240412081516.31168-1-yi.l.liu@intel.com/
 - Domain replace for pasid should be handled in set_dev_pasid() callbacks
   instead of remove_dev_pasid and call set_dev_pasid afteward in iommu
   layer (Jason)
 - Make xarray operations more self-contained in iommufd pasid attach/replace/detach
   (Jason)
 - Tweak the dev_iommu_get_max_pasids() to allow iommu driver to populate the
   max_pasids. This makes the iommufd selftest simpler to meet the max_pasids
   check in iommu_attach_device_pasid()  (Jason)

v1: https://lore.kernel.org/kvm/20231127063428.127436-1-yi.l.liu@intel.com/#r
 - Implemnet iommu_replace_device_pasid() to fall back to the original domain
   if this replacement failed (Kevin)
 - Add check in do_attach() to check corressponding attach_fn per the pasid value.

rfc: https://lore.kernel.org/linux-iommu/20230926092651.17041-1-yi.l.liu@intel.com/

Regards,
	Yi Liu

Yi Liu (12):
  iommu: Add iommu_attach_device_pasid_handle()
  iommu: Introduce a replace API for device pasid
  iommufd: Pass @pasid through the device attach/replace path
  iommufd/device: Only add reserved_iova in non-pasid path
  iommufd: Mark PASID-compatible domain
  iommufd: Support pasid attach/replace
  iommufd: Enforce PASID-compatible domain for RID
  iommu/vt-d: Add IOMMU_HWPT_ALLOC_PASID support
  iommufd: Allow allocating PASID-compatible domain
  iommufd/selftest: Add set_dev_pasid in mock iommu
  iommufd/selftest: Add test ops to test pasid attach/detach
  iommufd/selftest: Add coverage for iommufd pasid attach/detach

 drivers/dma/idxd/init.c                       |   2 +-
 drivers/iommu/intel/iommu.c                   |   3 +-
 drivers/iommu/intel/nested.c                  |   2 +-
 drivers/iommu/iommu-priv.h                    |   4 +
 drivers/iommu/iommu-sva.c                     |  10 +-
 drivers/iommu/iommu.c                         | 121 +++++-
 drivers/iommu/iommufd/Makefile                |   1 +
 drivers/iommu/iommufd/device.c                | 139 ++++---
 drivers/iommu/iommufd/hw_pagetable.c          |  15 +-
 drivers/iommu/iommufd/iommufd_private.h       |  32 +-
 drivers/iommu/iommufd/iommufd_test.h          |  37 ++
 drivers/iommu/iommufd/pasid.c                 | 155 ++++++++
 drivers/iommu/iommufd/selftest.c              | 238 +++++++++++-
 include/linux/iommu.h                         |  34 +-
 include/linux/iommufd.h                       |   7 +
 tools/testing/selftests/iommu/iommufd.c       | 350 ++++++++++++++++++
 .../selftests/iommu/iommufd_fail_nth.c        |  46 ++-
 tools/testing/selftests/iommu/iommufd_utils.h | 123 ++++++
 18 files changed, 1230 insertions(+), 89 deletions(-)
 create mode 100644 drivers/iommu/iommufd/pasid.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2025-03-17 15:35 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26 11:40 [PATCH v8 00/12] iommufd support pasid attach/replace Yi Liu
2025-02-26 11:40 ` [PATCH v8 01/12] iommu: Add iommu_attach_device_pasid_handle() Yi Liu
2025-02-26 13:58   ` Baolu Lu
2025-02-26 22:16   ` Nicolin Chen
2025-02-27  1:27     ` Yi Liu
2025-02-27 16:26       ` Nicolin Chen
2025-02-28  6:48         ` Yi Liu
2025-02-28 15:12           ` Jason Gunthorpe
2025-03-01 10:09             ` Yi Liu
2025-02-28 15:17   ` Jason Gunthorpe
2025-03-01 10:10     ` Yi Liu
2025-03-04  7:34       ` Tian, Kevin
2025-03-04  8:45         ` Yi Liu
2025-02-26 11:40 ` [PATCH v8 02/12] iommu: Introduce a replace API for device pasid Yi Liu
2025-02-26 23:11   ` Nicolin Chen
2025-02-27  1:43     ` Yi Liu
2025-02-27 16:04       ` Nicolin Chen
2025-02-28 14:12         ` Yi Liu
2025-03-01  4:46           ` Nicolin Chen
2025-03-01 10:12             ` Yi Liu
2025-02-27  1:31   ` Baolu Lu
2025-02-27  2:29     ` Yi Liu
2025-02-27  2:59       ` Baolu Lu
2025-02-28 15:21   ` Jason Gunthorpe
2025-03-04  7:42   ` Tian, Kevin
2025-03-04  8:49     ` Yi Liu
2025-03-05  2:36       ` Tian, Kevin
2025-02-26 11:40 ` [PATCH v8 03/12] iommufd: Pass @pasid through the device attach/replace path Yi Liu
2025-02-26 23:45   ` Nicolin Chen
2025-02-28 15:25   ` Jason Gunthorpe
2025-02-26 11:40 ` [PATCH v8 04/12] iommufd/device: Only add reserved_iova in non-pasid path Yi Liu
2025-02-27  0:05   ` Nicolin Chen
2025-02-27  1:50     ` Yi Liu
2025-02-27 16:31       ` Nicolin Chen
2025-02-28 14:03         ` Yi Liu
2025-02-28 15:24   ` Jason Gunthorpe
2025-03-01 10:12     ` Yi Liu
2025-03-04  7:43   ` Tian, Kevin
2025-02-26 11:40 ` [PATCH v8 05/12] iommufd: Mark PASID-compatible domain Yi Liu
2025-02-27  3:06   ` Baolu Lu
2025-02-27 18:58   ` Nicolin Chen
2025-02-28 15:27   ` Jason Gunthorpe
2025-02-26 11:40 ` [PATCH v8 06/12] iommufd: Support pasid attach/replace Yi Liu
2025-02-27  3:27   ` Baolu Lu
2025-02-27  4:19     ` Yi Liu
2025-02-27 20:15       ` Jason Gunthorpe
2025-02-28 14:13         ` Yi Liu
2025-02-28 15:32   ` Jason Gunthorpe
2025-03-01 11:44     ` Yi Liu
2025-03-03 17:48       ` Jason Gunthorpe
2025-03-04  7:59         ` Tian, Kevin
2025-02-26 11:40 ` [PATCH v8 07/12] iommufd: Enforce PASID-compatible domain for RID Yi Liu
2025-02-27  3:43   ` Baolu Lu
2025-02-27  5:16     ` Yi Liu
2025-02-28 19:39   ` Jason Gunthorpe
2025-03-04  8:00   ` Tian, Kevin
2025-02-26 11:40 ` [PATCH v8 08/12] iommu/vt-d: Add IOMMU_HWPT_ALLOC_PASID support Yi Liu
2025-02-27  3:46   ` Baolu Lu
2025-02-28 19:39   ` Jason Gunthorpe
2025-03-04  8:00   ` Tian, Kevin
2025-02-26 11:40 ` [PATCH v8 09/12] iommufd: Allow allocating PASID-compatible domain Yi Liu
2025-02-27  4:00   ` Baolu Lu
2025-02-27  5:34     ` Yi Liu
2025-02-27 20:17     ` Jason Gunthorpe
2025-02-28 19:56   ` Jason Gunthorpe
2025-03-04  8:08   ` Tian, Kevin
2025-03-04 11:48     ` Yi Liu
2025-03-05  2:38       ` Tian, Kevin
2025-03-13 13:17         ` Yi Liu
2025-03-17 15:35           ` Jason Gunthorpe
2025-02-26 11:40 ` [PATCH v8 10/12] iommufd/selftest: Add set_dev_pasid in mock iommu Yi Liu
2025-03-04  8:08   ` Tian, Kevin
2025-02-26 11:40 ` [PATCH v8 11/12] iommufd/selftest: Add test ops to test pasid attach/detach Yi Liu
2025-03-04  8:09   ` Tian, Kevin
2025-02-26 11:40 ` [PATCH v8 12/12] iommufd/selftest: Add coverage for iommufd " Yi Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.