All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 00/14] iommufd support pasid attach/replace
@ 2024-12-19 13:27 Yi Liu
  2024-12-19 13:27 ` [PATCH v6 01/14] iommu: Introduce a replace API for device pasid Yi Liu
                   ` (13 more replies)
  0 siblings, 14 replies; 71+ messages in thread
From: Yi Liu @ 2024-12-19 13:27 UTC (permalink / raw)
  To: joro, jgg, kevin.tian, baolu.lu
  Cc: eric.auger, nicolinc, chao.p.peng, yi.l.liu, iommu, vasant.hegde,
	will

PASID (Process Address Space ID) is a PCIe extension to tag the DMA
transactions out of a physical device, and most modern IOMMU hardware
have supported PASID granular address translation. So a PASID-capable
device can be attached to multiple hwpts (a.k.a. domains), and each
attachment is tagged with a pasid.

This series is based on the preparation series [1] [2], it first adds a
missing iommu API to replace the domain for a pasid. Based on the iommu
pasid attach/ replace/detach APIs, this series adds iommufd APIs for device
drivers to attach/replace/detach pasid to/from hwpt per userspace's request,
add PASID compat domain enforcement, add PASID compat hwpt allocation in
iommufd, and adds selftest to validate the iommufd APIs.

The completed code can be found in the below link [3]. Heads up! The existing
iommufd selftest was broken, there was a temp fix patch in the top of the
branch [3]. If want to run the iommufd selftest, please apply that fix. Sorry
for the inconvenience.

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

Change log:

v6:
 - 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 (14):
  iommu: Introduce a replace API for device pasid
  iommufd: Refactor __fault_domain_replace_dev() to be a wrapper of
    iommu_replace_group_handle()
  iommufd: Move the iommufd_handle helpers to device.c
  iommufd: Always pass iommu_attach_handle to iommu core
  iommufd: Pass pasid through the device attach/replace 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 a helper to get test device
  iommufd/selftest: Add test ops to test pasid attach/detach
  iommufd/selftest: Add coverage for iommufd pasid attach/detach

 drivers/iommu/intel/iommu.c                   |   3 +-
 drivers/iommu/intel/nested.c                  |   2 +-
 drivers/iommu/iommu-priv.h                    |   4 +
 drivers/iommu/iommu.c                         |  90 ++++-
 drivers/iommu/iommufd/Makefile                |   1 +
 drivers/iommu/iommufd/device.c                | 123 +++++--
 drivers/iommu/iommufd/fault.c                 |  88 +----
 drivers/iommu/iommufd/hw_pagetable.c          |  15 +-
 drivers/iommu/iommufd/iommufd_private.h       |  95 ++++-
 drivers/iommu/iommufd/iommufd_test.h          |  31 ++
 drivers/iommu/iommufd/pasid.c                 | 173 +++++++++
 drivers/iommu/iommufd/selftest.c              | 231 +++++++++++-
 include/linux/iommufd.h                       |   7 +
 tools/testing/selftests/iommu/iommufd.c       | 348 ++++++++++++++++++
 .../selftests/iommu/iommufd_fail_nth.c        |  39 +-
 tools/testing/selftests/iommu/iommufd_utils.h | 102 +++++
 16 files changed, 1216 insertions(+), 136 deletions(-)
 create mode 100644 drivers/iommu/iommufd/pasid.c

-- 
2.34.1


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

end of thread, other threads:[~2025-02-20  6:57 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-19 13:27 [PATCH v6 00/14] iommufd support pasid attach/replace Yi Liu
2024-12-19 13:27 ` [PATCH v6 01/14] iommu: Introduce a replace API for device pasid Yi Liu
2024-12-20  2:47   ` Baolu Lu
2025-01-09  7:08   ` Tian, Kevin
2025-01-09  7:20   ` Tian, Kevin
2025-01-09 14:43     ` Jason Gunthorpe
2025-01-10  2:31       ` Baolu Lu
2025-01-10  7:21         ` Tian, Kevin
2025-01-16 10:00           ` Yi Liu
2025-01-13 20:21   ` Jason Gunthorpe
2025-01-14  8:10     ` Tian, Kevin
2025-01-14 13:45       ` Jason Gunthorpe
2025-01-15  4:43         ` Tian, Kevin
2025-01-15 14:43           ` Jason Gunthorpe
2025-01-16  5:48             ` Tian, Kevin
2025-01-17 10:32               ` Yi Liu
2024-12-19 13:27 ` [PATCH v6 02/14] iommufd: Refactor __fault_domain_replace_dev() to be a wrapper of iommu_replace_group_handle() Yi Liu
2024-12-19 13:27 ` [PATCH v6 03/14] iommufd: Move the iommufd_handle helpers to device.c Yi Liu
2024-12-20  3:31   ` Baolu Lu
2024-12-20  6:34     ` Yi Liu
2024-12-19 13:27 ` [PATCH v6 04/14] iommufd: Always pass iommu_attach_handle to iommu core Yi Liu
2024-12-20  4:35   ` Nicolin Chen
2024-12-20  6:40     ` Yi Liu
2024-12-20  6:58       ` Nicolin Chen
2025-01-09  7:44   ` Tian, Kevin
2025-01-17 12:33     ` Yi Liu
2025-01-17 19:03       ` Nicolin Chen
2024-12-19 13:27 ` [PATCH v6 05/14] iommufd: Pass pasid through the device attach/replace path Yi Liu
2025-01-09  7:53   ` Tian, Kevin
2025-01-09 14:51     ` Jason Gunthorpe
2025-01-10  7:22       ` Tian, Kevin
2024-12-19 13:27 ` [PATCH v6 06/14] iommufd: Mark PASID-compatible domain Yi Liu
2025-01-09  7:56   ` Tian, Kevin
2025-01-09 14:54   ` Jason Gunthorpe
2025-01-17 10:50     ` Yi Liu
2024-12-19 13:27 ` [PATCH v6 07/14] iommufd: Support pasid attach/replace Yi Liu
2025-01-09  8:25   ` Tian, Kevin
2024-12-19 13:27 ` [PATCH v6 08/14] iommufd: Enforce PASID-compatible domain for RID Yi Liu
2025-01-09  8:31   ` Tian, Kevin
2024-12-19 13:27 ` [PATCH v6 09/14] iommu/vt-d: Add IOMMU_HWPT_ALLOC_PASID support Yi Liu
2024-12-23  2:51   ` Baolu Lu
2024-12-24 11:35     ` Yi Liu
2024-12-25  1:02       ` Baolu Lu
2024-12-25  4:30         ` Yi Liu
2024-12-25  7:13           ` Baolu Lu
2025-02-12  7:47             ` Yi Liu
2025-02-12 12:59               ` Jason Gunthorpe
2025-02-13  9:34                 ` Yi Liu
2025-02-13 12:56                   ` Jason Gunthorpe
2025-02-14  3:24                     ` Yi Liu
2025-02-12 13:00               ` Robin Murphy
2025-02-12 13:08                 ` Jason Gunthorpe
2025-02-13 10:10                 ` Yi Liu
2025-02-13 10:24                   ` Robin Murphy
2025-02-13 12:53                     ` Yi Liu
2025-02-19  8:02                     ` Tian, Kevin
2025-02-19 12:50                       ` Yi Liu
2025-02-20  6:57                         ` Tian, Kevin
2025-01-09 15:27     ` Jason Gunthorpe
2025-01-10  2:41       ` Baolu Lu
2025-01-10  7:34         ` Tian, Kevin
2025-01-17 10:57           ` Yi Liu
2025-01-10  7:38   ` Tian, Kevin
2025-01-14  8:13     ` Tian, Kevin
2025-01-13 20:31   ` Jason Gunthorpe
2025-01-14  8:19     ` Tian, Kevin
2024-12-19 13:27 ` [PATCH v6 10/14] iommufd: Allow allocating PASID-compatible domain Yi Liu
2024-12-19 13:27 ` [PATCH v6 11/14] iommufd/selftest: Add set_dev_pasid in mock iommu Yi Liu
2024-12-19 13:27 ` [PATCH v6 12/14] iommufd/selftest: Add a helper to get test device Yi Liu
2024-12-19 13:27 ` [PATCH v6 13/14] iommufd/selftest: Add test ops to test pasid attach/detach Yi Liu
2024-12-19 13:27 ` [PATCH v6 14/14] 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.