All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/14] Consolidate the error handling around device attachment
@ 2023-03-29 23:40 Jason Gunthorpe
  2023-03-29 23:40 ` [PATCH v2 01/14] iommu: Replace iommu_group_device_count() with list_count_nodes() Jason Gunthorpe
                   ` (13 more replies)
  0 siblings, 14 replies; 52+ messages in thread
From: Jason Gunthorpe @ 2023-03-29 23:40 UTC (permalink / raw)
  To: iommu, Joerg Roedel, llvm, Nathan Chancellor, Nick Desaulniers,
	Miguel Ojeda, Robin Murphy, Tom Rix, Will Deacon
  Cc: Lu Baolu, Kevin Tian, Nicolin Chen

Device attachment has a bunch of different flows open coded in different
ways throughout the code.

One of the things that became apparently recently is that error handling
is important and we do need to consistently treat errors during attach and
have some strategy to unwind back to a safe state.

Implement a single algorithm for this in one function. It will call each
device's attach, if it fails it will try to go back to the prior domain or
as a contingency against a UAF crash try to go to a blocking domain.

As part of this we consolidate how the default domain is created and
attached as well into one place with a consistent flow.

The new worker functions are called __iommu_device_set_domain() and
__iommu_group_set_domain_internal(), each has sensible error handling
internally. At the end __iommu_group_set_domain_internal() is the only
function that stores to group->domain, and must be called to change this
value.

Some flags tell the intent of the caller, if the caller cannot accept a
failure, or if the caller is a first attach and wants to do the deferred
logic.

Several of the confusing workflows where we store things in group->domain
or group->default_domain before they are fully setup are removed.

This has a followup series that does a similar de-duplication to the probe
path:

https://github.com/jgunthorpe/linux/commits/iommu_err_unwind

v2:
 - New patch to remove iommu_group_device_count()
 - New patch to add a for_each helper: for_each_group_device()
 - Rebase on Joerg's tree
 - IOMMU_SET_DOMAIN_MUST_SUCCEED instead of true
 - Split patch to fix owned groups during first attach
 - Change iommu_create_device_direct_mappings to accept a domain not a
   group
 - Significantly revise the "iommu: Consolidate the default_domain setup to
   one function" patch to de-duplicate the domain type calculation logic
   too
 - New patch to clean the flow inside iommu_group_store_type()
v1: https://lore.kernel.org/r/0-v1-20507a7e6b7e+2d6-iommu_err_unwind_jgg@nvidia.com

Jason Gunthorpe (14):
  iommu: Replace iommu_group_device_count() with list_count_nodes()
  iommu: Add for_each_group_device()
  iommu: Make __iommu_group_set_domain() handle error unwind
  iommu: Use __iommu_group_set_domain() for __iommu_attach_group()
  iommu: Use __iommu_group_set_domain() in iommu_change_dev_def_domain()
  iommu: Replace __iommu_group_dma_first_attach() with set_domain
  iommu: Make iommu_group_do_dma_first_attach() simpler
  iommu: Make iommu_group_do_dma_first_attach() work with owned groups
  iommu: Fix iommu_probe_device() to attach the right domain
  iommu: Remove the assignment of group->domain during default domain
    alloc
  iommu: Consolidate the code to calculate the target default domain
    type
  iommu: Consolidate the default_domain setup to one function
  iommu: Remove __iommu_group_for_each_dev()
  iommu: Tidy the control flow in iommu_group_store_type()

 .clang-format         |   1 +
 drivers/iommu/iommu.c | 623 ++++++++++++++++++++----------------------
 2 files changed, 293 insertions(+), 331 deletions(-)


base-commit: 3578e36f238ef81a1967e849e0a3106c9dd37e68
-- 
2.40.0


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

end of thread, other threads:[~2023-05-10  1:01 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 23:40 [PATCH v2 00/14] Consolidate the error handling around device attachment Jason Gunthorpe
2023-03-29 23:40 ` [PATCH v2 01/14] iommu: Replace iommu_group_device_count() with list_count_nodes() Jason Gunthorpe
2023-03-30  6:22   ` Baolu Lu
2023-04-04  9:15   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 02/14] iommu: Add for_each_group_device() Jason Gunthorpe
2023-03-29 23:52   ` Miguel Ojeda
2023-03-30 14:28     ` Jason Gunthorpe
2023-05-09 13:12       ` Miguel Ojeda
2023-05-10  1:01         ` Jason Gunthorpe
2023-03-30  6:23   ` Baolu Lu
2023-04-04  9:16   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 03/14] iommu: Make __iommu_group_set_domain() handle error unwind Jason Gunthorpe
2023-03-30  6:23   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 04/14] iommu: Use __iommu_group_set_domain() for __iommu_attach_group() Jason Gunthorpe
2023-03-30  6:23   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 05/14] iommu: Use __iommu_group_set_domain() in iommu_change_dev_def_domain() Jason Gunthorpe
2023-03-30  6:24   ` Baolu Lu
2023-04-04  9:16   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 06/14] iommu: Replace __iommu_group_dma_first_attach() with set_domain Jason Gunthorpe
2023-03-30  6:24   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 07/14] iommu: Make iommu_group_do_dma_first_attach() simpler Jason Gunthorpe
2023-03-30  6:42   ` Baolu Lu
2023-03-30 14:41     ` Jason Gunthorpe
2023-03-31  2:21       ` Baolu Lu
2023-04-04  9:17   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 08/14] iommu: Make iommu_group_do_dma_first_attach() work with owned groups Jason Gunthorpe
2023-03-30  6:45   ` Baolu Lu
2023-03-30 15:54   ` Robin Murphy
2023-03-30 16:49     ` Jason Gunthorpe
2023-04-04  9:21   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 09/14] iommu: Fix iommu_probe_device() to attach the right domain Jason Gunthorpe
2023-03-30  7:33   ` Baolu Lu
2023-04-04  9:25   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 10/14] iommu: Remove the assignment of group->domain during default domain alloc Jason Gunthorpe
2023-03-30  7:33   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 11/14] iommu: Consolidate the code to calculate the target default domain type Jason Gunthorpe
2023-03-30 11:51   ` Baolu Lu
2023-04-04  9:39   ` Tian, Kevin
2023-04-04 18:51     ` Jason Gunthorpe
2023-03-29 23:40 ` [PATCH v2 12/14] iommu: Consolidate the default_domain setup to one function Jason Gunthorpe
2023-03-30 12:37   ` Baolu Lu
2023-03-30 14:29     ` Robin Murphy
2023-03-30 14:45       ` Jason Gunthorpe
2023-03-30 15:42         ` Jason Gunthorpe
2023-04-04 11:29           ` Robin Murphy
2023-03-30 15:36     ` Jason Gunthorpe
2023-03-30 18:23       ` Robin Murphy
2023-03-30 19:01         ` Jason Gunthorpe
2023-03-29 23:40 ` [PATCH v2 13/14] iommu: Remove __iommu_group_for_each_dev() Jason Gunthorpe
2023-03-30 12:40   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 14/14] iommu: Tidy the control flow in iommu_group_store_type() Jason Gunthorpe
2023-03-30 12:45   ` Baolu Lu

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.