All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 00/10] iommu/arm-smmu-v3: Implement Runtime/System Sleep ops
@ 2025-04-18 23:33 Pranjal Shrivastava
  2025-04-18 23:34 ` [RFC PATCH v2 01/10] iommu/arm-smmu-v3: Refactor arm_smmu_setup_irqs Pranjal Shrivastava
                   ` (9 more replies)
  0 siblings, 10 replies; 27+ messages in thread
From: Pranjal Shrivastava @ 2025-04-18 23:33 UTC (permalink / raw)
  To: Joerg Roedel, Will Deacon, Robin Murphy, Jason Gunthorpe
  Cc: Nicolin Chen, Mostafa Saleh, Daniel Mentz, iommu,
	Pranjal Shrivastava

As arm-smmu-v3 rapidly finds its way into SoCs designed for hand-held
devices, power management capabilities, similar to its predecessors, are
crucial for these applications. This series introduces power management
support for the arm-smmu-v3 driver.

Design
=======
The arm-smmu-v3 primarily operates with in-memory data structures
through HW registers pointing to these data structures in some fashion.
The proposed design tries to make use of this fact for implementing the
suspend and resume ops.

1. Suspend / Resume
The idea for the "suspend" op is to wait till all the queues are flushed
before disabling the SMMU through CR0. In order to avoid mis-use or
spurious transactions (b/w SMMU disable -> power-down), the GBPA register
is configured to abort all transactions.

The resume operation uses the `arm_smmu_device_reset` function which
re-initializes the HW using the SW-copies maintained by the driver. For
example, prod/cons for queues, base addresses for queues & tables. The
arm_smmu_device_reset also clears the TLBs and config caches.

2. Interrupt Re-config
a. Wired irqs: The series refactors the `arm_smmu_setup_irqs` to be
able to enable/disable irqs and install their handlers separately to
help with the re-initialization of the interrupts correctly.

b. MSIs: The series relies on caching the msi_msg and retrieving it
through a newly introduced helper `arm_smmu_resume_msis()` which
re-configures the *_IRQ_CFGn registers via writing back cached msi_msgs.

3. Handling user-space attachments
This version of the series relies on the user-space paths invoking the
iommu_*_claim_dma_owner API. The existing IOMMU API 
iommu_group_dma_owner_claimed() checks if DMA ownership for a group has
been claimed. However, it does NOT distinguish between kernel clients 
and user-space clients. This version of the series introduce a new helper
iommu_group_dma_owner_user() which allows the callers to specifically
determine if a iommu_group is owned by the user-space.

The function checks the group->owner field which is exclusively managed
by the iommu_group_claim_dma_owner() OR iommu_device_claim_dma_owner(),
instead of relying on the iommu_group->owner_cnt. Both the
*_claim_dma_owner APIs are ONLY called by vfio and iommufd at the moment
indicating user-space's DMA ownership for the said iommu_group.

Based on this new API, the arm-smmu-v3 driver tracks all the non-trusted
attachments in a list and keeps deferring suspend till the list of
non-trusted devices is empty, i.e. no non-trusted attachment exists.

SVA: The binding driver would either be in user-space or kernel-space.
For the latter, devlinks would suffice and for the former, we won't
suspend until all user-space attachments are removed.

4. Invoking runtime_pm_get/put
Given that most of the configuration done by arm-smmu-v3 is stored in
memory, the idea in this version of the series is to elide all TLBIs and
CFGIs if the SMMU is suspended and only go ahead with ATC invalidations.

Thus, for most calls, the SMMU driver would make the required changes to
the in-memory data structures, but elide all TLBIs, CFGIs and prefetches
This is done by introducing another runtime PM helper based on
pm_runtime_get_if_active.

Only places where the driver does a pm_runtime_resume_and_get is where
touching the HW is unavoidable and important commands like ATC_INV and
other commands resuming stalled transactions.

Future Work / Potential Improvements
Draining queues could be slightly optimized based on the feature-set
supported by the smmu, for e.g. if STALL isn't supported or ATS is
disabled, we could avoid draining evtq and priq respectivey.

Additionally, for tracking insecure attachments, an rbtee/hashtable
could be used to improve search times, subject to finding a way to
generate IDs / keys for pointers.

Call for review
Any insights/comments on the proposed changes are appreciated,
especially in areas related to locking, atomic contexts, early resume, 
PCIe-related considerations etc. or any other potential optimizations.

Note: The series isn't tested with MSIs and weakly tested for PCIe
clients. The same holds true for tegra241_cmdv changes. Any help in
reviewing and testing these parts is appreciated.

Changelog:

[v2]
 - Introduced `arm_smmu_rpm_get_if_active` for eliding TLBIs & CFGIs
 - Updated the rpm helper invocation strategy.
 - Drained all queues in suspend callback (including tegra241-cmdv)
 - Cache and restore msi_msg instead of free-ing realloc-ing on resume
 - Added support to identify and track user-space attachments
 - Fixed the setup_irqs as per Nicolin & Mostafa's suggestions
 - Used force_runtime_suspend/resume instead as per Mostafa's suggestion.
 - Added "Reviewed-by" line from Mostafa on an unchanged patch

[v1]
 - https://lore.kernel.org/all/20250319004254.2547950-1-praan@google.com/

Pranjal Shrivastava (10):
  iommu/arm-smmu-v3: Refactor arm_smmu_setup_irqs
  iommu/arm-smmu-v3: Add a helper to drain all queues
  iommu/tegra241-cmdqv: Add a helper to drain VCMDQs
  iommu/arm-smmu-v3: Cache and restore MSI config
  iommu/arm-smmu-v3: Implement pm_runtime & system sleep ops
  iommu: Add a helper to check for user ownership
  iommu/arm-smmu-v3: Track masters with user-owned groups
  iommu/arm-smmu-v3: Avoid suspend when user owns DMA
  iommu/arm-smmu-v3: Enable pm_runtime and setup devlinks
  iommu/arm-smmu-v3: Invoke pm_runtime before hw access

 .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c     |  11 +-
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c   | 468 ++++++++++++++++--
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h   |  19 +
 .../iommu/arm/arm-smmu-v3/tegra241-cmdqv.c    |  28 ++
 drivers/iommu/iommu.c                         |  19 +
 include/linux/iommu.h                         |   1 +
 6 files changed, 513 insertions(+), 33 deletions(-)

-- 
2.49.0.805.g082f7c87e0-goog


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

end of thread, other threads:[~2025-05-05 16:11 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-18 23:33 [RFC PATCH v2 00/10] iommu/arm-smmu-v3: Implement Runtime/System Sleep ops Pranjal Shrivastava
2025-04-18 23:34 ` [RFC PATCH v2 01/10] iommu/arm-smmu-v3: Refactor arm_smmu_setup_irqs Pranjal Shrivastava
2025-05-02 19:14   ` Nicolin Chen
2025-04-18 23:34 ` [RFC PATCH v2 02/10] iommu/arm-smmu-v3: Add a helper to drain all queues Pranjal Shrivastava
2025-05-02 19:32   ` Nicolin Chen
2025-05-05 15:14     ` Pranjal Shrivastava
2025-05-04 20:28   ` Daniel Mentz
2025-05-05 15:10     ` Pranjal Shrivastava
2025-04-18 23:34 ` [RFC PATCH v2 03/10] iommu/tegra241-cmdqv: Add a helper to drain VCMDQs Pranjal Shrivastava
2025-04-23  6:34   ` Nicolin Chen
2025-04-18 23:34 ` [RFC PATCH v2 04/10] iommu/arm-smmu-v3: Cache and restore MSI config Pranjal Shrivastava
2025-05-02 19:43   ` Nicolin Chen
2025-05-05 15:16     ` Pranjal Shrivastava
2025-04-18 23:34 ` [RFC PATCH v2 05/10] iommu/arm-smmu-v3: Implement pm_runtime & system sleep ops Pranjal Shrivastava
2025-05-04 20:29   ` Daniel Mentz
2025-05-05 15:22     ` Pranjal Shrivastava
2025-04-18 23:34 ` [RFC PATCH v2 06/10] iommu: Add a helper to check for user ownership Pranjal Shrivastava
2025-04-19 14:03   ` kernel test robot
2025-04-18 23:34 ` [RFC PATCH v2 07/10] iommu/arm-smmu-v3: Track masters with user-owned groups Pranjal Shrivastava
2025-04-18 23:34 ` [RFC PATCH v2 08/10] iommu/arm-smmu-v3: Avoid suspend when user owns DMA Pranjal Shrivastava
2025-05-04 20:28   ` Daniel Mentz
2025-05-05 15:22     ` Pranjal Shrivastava
2025-04-18 23:34 ` [RFC PATCH v2 09/10] iommu/arm-smmu-v3: Enable pm_runtime and setup devlinks Pranjal Shrivastava
2025-04-18 23:34 ` [RFC PATCH v2 10/10] iommu/arm-smmu-v3: Invoke pm_runtime before hw access Pranjal Shrivastava
2025-04-19 14:13   ` kernel test robot
2025-05-04 20:29   ` Daniel Mentz
2025-05-05 16:10     ` Pranjal Shrivastava

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.