Skip to content

Add iommufd physical device operations for replace and alloc hwpt

Jason Gunthorpe kvm linux-iommu linux-kselftest 8 versions – Applied

Status from this message: Applied to iommufd for-next, I fixed up the conflicts with the cdev series

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest19 patches 1 replyApplied
  2. v719 patches 17 repliesSuperseded
  3. v619 patches 3 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v517 patches0 repliesSuperseded
v417 patches3 repliesSuperseded
v317 patches28 repliesSuperseded
v217 patches31 repliesSuperseded
v114 patches49 repliesSuperseded

Changes in v8 from the cover letter · 34 lines

- Rebase to v6.5-rc2, update to new behavior of __iommu_group_set_domain()
v7: https://lore.kernel.org/r/[email protected]
- Rebase to v6.4-rc2, update to new signature of iommufd_get_ioas()
v6: https://lore.kernel.org/r/[email protected]
- Go back to the v4 locking arragnment with now both the attach/detach igroup->locks inside the functions, Kevin says he needs this for a followup series. This still fixes the syzkaller bug
- Fix two more error unwind locking bugs where iommufd_object_abort_and_destroy(hwpt) would deadlock or be mislocked. Make sure fail_nth will catch these mistakes
- Add a patch allowing objects to have different abort than destroy function, it allows hwpt abort to require the caller to continue
to hold the lock and enforces this with lockdep.
v5: https://lore.kernel.org/r/[email protected]
- Go back to the v3 version of the code, keep the comment changes from v4. Syzkaller says the group lock change in v4 didn't work.
- Adjust the fail_nth test to cover the path syzkaller found. We need to have an ioas with a mapped page installed to inject a failure during domain attachment.
v4: https://lore.kernel.org/r/[email protected]
- Refine comments and commit messages
- Move the group lock into iommufd_hw_pagetable_attach()
- Fix error unwind in iommufd_device_do_replace()
v3: https://lore.kernel.org/r/[email protected]
- Refine comments and commit messages
- Adjust the flow in iommufd_device_auto_get_domain() so pt_id is only set on success
- Reject replace on non-attached devices
- Add missing __reserved check for IOMMU_HWPT_ALLOC
v2: https://lore.kernel.org/r/[email protected]
- Use WARN_ON for the igroup->group test and move that logic to a function iommufd_group_try_get()
- Change igroup->devices to igroup->device list
Replace will need to iterate over all attached idevs
- Rename to iommufd_group_setup_msi()
- New patch to export iommu_get_resv_regions()
- New patch to use per-device reserved regions instead of per-group regions
- Split out the reorganizing of iommufd_device_change_pt() from the replace patch
- Replace uses the per-dev reserved regions
- Use stdev_id in a few more places in the selftest
- Fix error handling in IOMMU_HWPT_ALLOC
- Clarify comments
- Rebase on v6.3-rc1
v1: https://lore.kernel.org/all/[email protected]/

Patches in v8 Applied

#Subject and filesSizeRepliesApplied
1/19iommufd: Move isolated msi enforcement to iommufd_device_bind()drivers/iommu/iommufd/device.c+20 -180 replies
2/19iommufd: Add iommufd_groupdrivers/iommu/iommufd/device.c drivers/iommu/iommufd/iommufd_private.h drivers/iommu/iommufd/main.c+135 -170 replies
3/19iommufd: Replace the hwpt->devices list with iommufd_groupdrivers/iommu/iommufd/device.c drivers/iommu/iommufd/hw_pagetable.c drivers/iommu/iommufd/iommufd_private.h+54 -810 replies
4/19iommu: Export iommu_get_resv_regions()drivers/iommu/iommu.c+10 -10 replies
5/19iommufd: Keep track of each device's reserved regions instead of groupsdrivers/iommu/iommufd/device.c drivers/iommu/iommufd/io_pagetable.c drivers/iommu/iommufd/iommufd_private.h+16 -230 replies
6/19iommufd: Use the iommufd_group to avoid duplicate MSI setupdrivers/iommu/iommufd/device.c+4 -40 replies
7/19iommufd: Make sw_msi_start a group globaldrivers/iommu/iommufd/device.c drivers/iommu/iommufd/iommufd_private.h+8 -70 replies
8/19iommufd: Move putting a hwpt to a helper functiondrivers/iommu/iommufd/device.c drivers/iommu/iommufd/iommufd_private.h+11 -50 replies
9/19iommufd: Add enforced_cache_coherency to iommufd_hw_pagetable_alloc()drivers/iommu/iommufd/device.c drivers/iommu/iommufd/hw_pagetable.c drivers/iommu/iommufd/iommufd_private.h+32 -150 replies
10/19iommufd: Allow a hwpt to be aborted after allocationdrivers/iommu/iommufd/hw_pagetable.c drivers/iommu/iommufd/iommufd_private.h drivers/iommu/iommufd/main.c+26 -10 replies
11/19iommufd: Fix locking around hwpt allocationdrivers/iommu/iommufd/device.c+1 -10 replies
12/19iommufd: Reorganize iommufd_device_attach into iommufd_device_change_ptdrivers/iommu/iommufd/device.c+114 -510 replies
13/19iommu: Introduce a new iommu_group_replace_domain() APIdrivers/iommu/iommu-priv.h drivers/iommu/iommu.c+37 -00 replies
14/19iommufd: Add iommufd_device_replace()drivers/iommu/iommufd/device.c drivers/iommu/iommufd/main.c+102 -00 replies
15/19iommufd: Make destroy_rwsem use a lock class per object typedrivers/iommu/iommufd/iommufd_private.h drivers/iommu/iommufd/main.c+11 -10 replies
16/19iommufd/selftest: Test iommufd_device_replace()drivers/iommu/iommufd/iommufd_test.h drivers/iommu/iommufd/selftest.c include/linux/iommufd.h +3 more+149 -40 replies
17/19iommufd: Add IOMMU_HWPT_ALLOCdrivers/iommu/iommufd/hw_pagetable.c drivers/iommu/iommufd/iommufd_private.h drivers/iommu/iommufd/main.c +1 more+84 -00 replies
18/19iommufd/selftest: Return the real idev id from selftest mock_domaindrivers/iommu/iommufd/iommufd_test.h drivers/iommu/iommufd/selftest.c tools/testing/selftests/iommu/iommufd.c +2 more+29 -210 replies
19/19iommufd/selftest: Add a selftest for IOMMU_HWPT_ALLOCdrivers/iommu/iommufd/io_pagetable.c tools/testing/selftests/iommu/iommufd.c tools/testing/selftests/iommu/iommufd_fail_nth.c +1 more+49 -10 replies

Reviews trailers per patch

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

PatchKevin TianNicolin ChenLu Baolu
1/19R-b T-b R-b
2/19R-b T-b R-b
3/19R-b T-b R-b
4/19R-b T-b R-b
5/19R-b T-b R-b
6/19R-b T-b
7/19R-b T-b
8/19R-b T-b R-b
9/19R-b T-b R-b
10/19R-b T-b
11/19R-b T-b
12/19R-b T-b R-b
13/19R-b T-b R-b
14/19R-b T-b R-b
15/19R-b T-b
16/19R-b T-b
17/19R-b T-b R-b
18/19R-b T-b
19/19R-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 3 reviewers.

Read the v8 thread

Cover letter [PATCH v8 00/19] Add iommufd physical device operations for replace and alloc hwpt

This is the basic functionality for iommufd to support iommufd_device_replace() and IOMMU_HWPT_ALLOC for physical devices.

iommufd_device_replace() allows changing the HWPT associated with the device to a new IOAS or HWPT. Replace does this in way that failure leaves things unchanged, and utilizes the iommu iommu_group_replace_domain() API to allow the iommu driver to perform an optional non-disruptive change.

IOMMU_HWPT_ALLOC allows HWPTs to be explicitly allocated by the user and used by attach or replace. At this point it isn't very useful since the HWPT is the same as the automatically managed HWPT from the IOAS. However a following series will allow userspace to customize the created HWPT.

The implementation is complicated because we have to introduce some per-iommu_group memory in iommufd and redo how we think about multi-device groups to be more explicit. This solves all the locking problems in the prior attempts.

This series is infrastructure work for the following series which:
- Add replace for attach
- Expose replace through VFIO APIs
- Implement driver parameters for HWPT creation (nesting)

Once review of this is complete I will keep it on a side branch and accumulate the following series when they are ready so we can have a stable base and make more incremental progress. When we have all the parts together to get a full implementation it can go to Linus.

This is on github: https://github.com/jgunthorpe/linux/commits/iommufd_hwpt

v8:
- Rebase to v6.5-rc2, update to new behavior of __iommu_group_set_domain()
v7: https://lore.kernel.org/r/[email protected]
- Rebase to v6.4-rc2, update to new signature of iommufd_get_ioas()
v6: https://lore.kernel.org/r/[email protected]
- Go back to the v4 locking arragnment with now both the attach/detach igroup->locks inside the functions, Kevin says he needs this for a followup series. This still fixes the syzkaller bug
- Fix two more error unwind locking bugs where iommufd_object_abort_and_destroy(hwpt) would deadlock or be mislocked. Make sure fail_nth will catch these mistakes
- Add a patch allowing objects to have different abort than destroy function, it allows hwpt abort to require the caller to continue
to hold the lock and enforces this with lockdep.
v5: https://lore.kernel.org/r/[email protected]
- Go back to the v3 version of the code, keep the comment changes from v4. Syzkaller says the group lock change in v4 didn't work.
- Adjust the fail_nth test to cover the path syzkaller found. We need to have an ioas with a mapped page installed to inject a failure during domain attachment.
v4: https://lore.kernel.org/r/[email protected]
- Refine comments and commit messages
- Move the group lock into iommufd_hw_pagetable_attach()
- Fix error unwind in iommufd_device_do_replace()
v3: https://lore.kernel.org/r/[email protected]
- Refine comments and commit messages
- Adjust the flow in iommufd_device_auto_get_domain() so pt_id is only set on success
- Reject replace on non-attached devices
- Add missing __reserved check for IOMMU_HWPT_ALLOC
v2: https://lore.kernel.org/r/[email protected]
- Use WARN_ON for the igroup->group test and move that logic to a function iommufd_group_try_get()
- Change igroup->devices to igroup->device list
Replace will need to iterate over all attached idevs
- Rename to iommufd_group_setup_msi()
- New patch to export iommu_get_resv_regions()
- New patch to use per-device reserved regions instead of per-group regions
- Split out the reorganizing of iommufd_device_change_pt() from the replace patch
- Replace uses the per-dev reserved regions
- Use stdev_id in a few more places in the selftest
- Fix error handling in IOMMU_HWPT_ALLOC
- Clarify comments
- Rebase on v6.3-rc1
v1: https://lore.kernel.org/all/[email protected]/

Jason Gunthorpe (17):
iommufd: Move isolated msi enforcement to iommufd_device_bind()
iommufd: Add iommufd_group
iommufd: Replace the hwpt->devices list with iommufd_group
iommu: Export iommu_get_resv_regions()
iommufd: Keep track of each device's reserved regions instead of
groups
iommufd: Use the iommufd_group to avoid duplicate MSI setup
iommufd: Make sw_msi_start a group global
iommufd: Move putting a hwpt to a helper function
iommufd: Add enforced_cache_coherency to iommufd_hw_pagetable_alloc()
iommufd: Allow a hwpt to be aborted after allocation
iommufd: Fix locking around hwpt allocation
iommufd: Reorganize iommufd_device_attach into
iommufd_device_change_pt
iommufd: Add iommufd_device_replace()
iommufd: Make destroy_rwsem use a lock class per object type
iommufd: Add IOMMU_HWPT_ALLOC
iommufd/selftest: Return the real idev id from selftest mock_domain iommufd/selftest: Add a selftest for IOMMU_HWPT_ALLOC

Nicolin Chen (2):
iommu: Introduce a new iommu_group_replace_domain() API iommufd/selftest: Test iommufd_device_replace()

 drivers/iommu/iommu-priv.h                    |  10 +
 drivers/iommu/iommu.c                         |  38 +-
 drivers/iommu/iommufd/device.c                | 555 +++++++++++++-----
 drivers/iommu/iommufd/hw_pagetable.c          | 112 +++-
 drivers/iommu/iommufd/io_pagetable.c          |  32 +-
 drivers/iommu/iommufd/iommufd_private.h       |  52 +-
 drivers/iommu/iommufd/iommufd_test.h          |   6 +
 drivers/iommu/iommufd/main.c                  |  24 +-
 drivers/iommu/iommufd/selftest.c              |  40 ++
 include/linux/iommufd.h                       |   1 +
 include/uapi/linux/iommufd.h                  |  26 +
 tools/testing/selftests/iommu/iommufd.c       |  67 ++-
 .../selftests/iommu/iommufd_fail_nth.c        |  67 ++-
 tools/testing/selftests/iommu/iommufd_utils.h |  63 +-
 14 files changed, 867 insertions(+), 226 deletions(-)
 create mode 100644 drivers/iommu/iommu-priv.h

base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c

Signature · 1 line
2.41.0