iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 00/17] Consolidate the error handling around device attachment
@ 2023-05-11  4:41 Jason Gunthorpe
  2023-05-11  4:41 ` [PATCH v5 01/17] iommu: Replace iommu_group_device_count() with list_count_nodes() Jason Gunthorpe
                   ` (17 more replies)
  0 siblings, 18 replies; 24+ messages in thread
From: Jason Gunthorpe @ 2023-05-11  4:41 UTC (permalink / raw)
  To: iommu, Joerg Roedel, llvm, Nathan Chancellor, Nick Desaulniers,
	Miguel Ojeda, Robin Murphy, Tom Rix, Will Deacon
  Cc: Lu Baolu, Heiko Stuebner, Kevin Tian, Nicolin Chen, Niklas Schnelle

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

v5:
 - Print a warning if iommu_create_device_direct_mappings() fails the
   first time. Fail probe() if it fails the second time
 - Update comments
 - Rebase to v6.4-rc1
 - Tested-by's for ARM32, ARM64, S390
v4: https://lore.kernel.org/r/0-v4-79d0c229580a+650-iommu_err_unwind_jgg@nvidia.com
 - Update comments and commit messages
 - New patch "Remove iommu_group_do_dma_first_attach() from iommu_group_add_device()"
 - Redo "Replace __iommu_group_dma_first_attach() with set_domain"
   to avoid the flag
 - Drop "Make iommu_group_do_dma_first_attach() work with owned groups"
   since the fix happens implicitly now
 - Use __iommu_group_set_domain() instead of
   __iommu_group_set_domain_internal() in most places
 - Make sure iommu_create_device_direct_mappings() is always called to
   update the default domain, even if the current attached domain is not
   the default domain
 - Make the error case for inconsistent iommu_get_def_domain_type()'s
   always use iommu_def_domain_type
 - Handle errrors for the first default domain attach more cleanly
v3: https://lore.kernel.org/r/0-v3-e89a9bb522f5+8c87-iommu_err_unwind_jgg@nvidia.com
 - New patch to do iommu_group_create_direct_mappings() before
   attach on the hotplug path based on Lu and Robin's remarks
 - Fix to return 0 if the group has conflicting default domain types like
   the original code
 - Put iommu_group_create_direct_mappings() before attach in setup_domains
 - Split up the alloc changes from the setup_domain patch to their own
   patch, implement Robin's point about how the iommu_def_domain_type should
   work
 - New patch to optionally do iommu_group_create_direct_mappings() after
   attach
 - Reword the setup_domain patch's commit message
v2: https://lore.kernel.org/r/0-v2-cd32667d2ba6+70bd1-iommu_err_unwind_jgg@nvidia.com
 - 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 (17):
  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: Remove iommu_group_do_dma_first_attach() from
    iommu_group_add_device()
  iommu: Replace iommu_group_do_dma_first_attach with
    __iommu_device_set_domain
  iommu: Fix iommu_probe_device() to attach the right domain
  iommu: Do iommu_group_create_direct_mappings() before attach
  iommu: Remove the assignment of group->domain during default domain
    alloc
  iommu: Consolidate the code to calculate the target default domain
    type
  iommu: Revise iommu_group_alloc_default_domain()
  iommu: Consolidate the default_domain setup to one function
  iommu: Allow IOMMU_RESV_DIRECT to work on ARM
  iommu: Remove __iommu_group_for_each_dev()
  iommu: Tidy the control flow in iommu_group_store_type()

 .clang-format         |   1 +
 drivers/iommu/iommu.c | 683 +++++++++++++++++++++---------------------
 2 files changed, 345 insertions(+), 339 deletions(-)


base-commit: ac9a78681b921877518763ba0e89202254349d1b
-- 
2.40.1


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

end of thread, other threads:[~2023-06-06  5:33 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-11  4:41 [PATCH v5 00/17] Consolidate the error handling around device attachment Jason Gunthorpe
2023-05-11  4:41 ` [PATCH v5 01/17] iommu: Replace iommu_group_device_count() with list_count_nodes() Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 02/17] iommu: Add for_each_group_device() Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 03/17] iommu: Make __iommu_group_set_domain() handle error unwind Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 04/17] iommu: Use __iommu_group_set_domain() for __iommu_attach_group() Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 05/17] iommu: Use __iommu_group_set_domain() in iommu_change_dev_def_domain() Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 06/17] iommu: Replace __iommu_group_dma_first_attach() with set_domain Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 07/17] iommu: Remove iommu_group_do_dma_first_attach() from iommu_group_add_device() Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 08/17] iommu: Replace iommu_group_do_dma_first_attach with __iommu_device_set_domain Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 09/17] iommu: Fix iommu_probe_device() to attach the right domain Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 10/17] iommu: Do iommu_group_create_direct_mappings() before attach Jason Gunthorpe
2023-06-05  7:09   ` Ricardo Cañuelo
2023-06-05 13:47     ` Jason Gunthorpe
2023-06-05 14:00       ` Robin Murphy
2023-06-05 14:11         ` Jason Gunthorpe
2023-06-06  5:33         ` Ricardo Cañuelo
2023-05-11  4:42 ` [PATCH v5 11/17] iommu: Remove the assignment of group->domain during default domain alloc Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 12/17] iommu: Consolidate the code to calculate the target default domain type Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 13/17] iommu: Revise iommu_group_alloc_default_domain() Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 14/17] iommu: Consolidate the default_domain setup to one function Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 15/17] iommu: Allow IOMMU_RESV_DIRECT to work on ARM Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 16/17] iommu: Remove __iommu_group_for_each_dev() Jason Gunthorpe
2023-05-11  4:42 ` [PATCH v5 17/17] iommu: Tidy the control flow in iommu_group_store_type() Jason Gunthorpe
2023-05-23  6:16 ` [PATCH v5 00/17] Consolidate the error handling around device attachment Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).