Skip to content

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] sync fixes for iommu#1935

Open
opsiff wants to merge 14 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-01-nested-fixes-1-2
Open

[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] sync fixes for iommu#1935
opsiff wants to merge 14 commits into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-07-01-nested-fixes-1-2

Conversation

@opsiff

@opsiff opsiff commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Align core and driver-specific IOMMU default/identity/platform domain handling with the upstream model, replacing legacy platform-DMA hooks, tightening group-level domain-type selection (especially for untrusted devices), and removing obsolete Tegra GART support.

Bug Fixes:

  • Fix inconsistent default-domain type selection within IOMMU groups and enforce safe handling of untrusted PCI devices.
  • Ensure identity/blocked/platform domains are correctly restored on detach/release across multiple IOMMU drivers to avoid leaving hardware in an undefined translation state.

Enhancements:

  • Refactor core IOMMU default-domain management to operate per-group via iommu_ops instead of bus-level helpers, simplifying domain allocation and type resolution.
  • Introduce explicit static identity and platform domains in various architecture- and SoC-specific IOMMU drivers (Exynos, IPMMU, Qualcomm, Tegra, Sun50i, MSM, Mediatek, OMAP, s390, FSL PAMU) and wire them into the generic IOMMU framework.
  • Remove legacy set_platform_dma_ops usage and migrate older drivers to the modern default-domain/identity-domain model.
  • Drop Tegra GART support and related memory-controller power-management callbacks now that SMMU and identity-domain handling cover those use cases.
  • Tidy up IOMMU user-data helper by reordering sanity checks and fixing comments.

Build:

  • Remove tegra-gart object from the IOMMU driver Makefile as part of dropping GART support.

@sourcery-ai

sourcery-ai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors the core IOMMU default-domain and domain-allocation logic to be group/ops-based instead of bus-based, removes legacy set_platform_dma_ops pathways, and introduces explicit static IDENTITY/PLATFORM/BLOCKED domains or identity-attach flows across multiple IOMMU drivers to make domain transitions consistent and safe for all devices in an IOMMU group.

Sequence diagram for device moving from mapped domain to IDENTITY via identity_domain.attach_dev

sequenceDiagram
    participant Dev as device
    participant Core as iommu_core
    participant Group as iommu_group
    participant Ops as iommu_ops
    participant IdDom as identity_domain
    participant CurDom as current_domain

    Dev->>Core: driver calls iommu_group_set_domain(group, new_domain)
    Core->>Group: lock(mutex)
    Core->>Ops: group_iommu_ops(group)
    alt switching_to_identity
        Core->>IdDom: identity_ops.attach_dev(identity_domain, Dev)
        IdDom->>Core: (driver-specific) disable translation / detach HW
        Core->>Group: group->domain = identity_domain
    else switching_to_other_domain
        Core->>CurDom: domain_ops.attach_dev(new_domain, Dev)
        Core->>Group: group->domain = new_domain
    end
    Group-->>Core: unlock(mutex)
    Core-->>Dev: return status
Loading

File-Level Changes

Change Details Files
Refactor generic IOMMU core to allocate domains via iommu_ops/group rather than bus, and to compute a consistent default domain type per group with proper handling of identity, DMA, platform and blocked domains.
  • Replace __iommu_domain_alloc(bus, type) with __iommu_domain_alloc(ops, type) and add __iommu_group_domain_alloc() using group_iommu_ops()
  • Introduce group_iommu_ops() helper to fetch iommu_ops from the first device in a group under group->mutex
  • Rework iommu_group_alloc_default_domain() to prefer ops->default_domain when present, fall back to group-specific allocation otherwise, and to respect requested types
  • Rewrite default domain type selection: new iommu_get_def_domain_type() aggregates per-device/driver preferences, handles ARM_DMA_USE_IOMMU and untrusted PCI devices, and returns -1 on conflicts
  • Tighten __iommu_group_set_domain_internal(): disallow setting a NULL domain (now returns -EINVAL) and remove calls to ops->set_platform_dma_ops() during NULL transitions
  • Change iommu_setup_default_domain() to treat failure to allocate a default domain as an error (-ENODEV) instead of silently leaving default_domain NULL
  • Ensure blocking_domain allocation uses group-based alloc (BLOCKED or UNMANAGED fallback)
drivers/iommu/iommu.c
Replace legacy set_platform_dma_ops callback with explicit identity/platform domain implementations across several architecture-specific and SoC IOMMU drivers.
  • Remove set_platform_dma_ops from struct iommu_ops API and its call sites, simplifying the lifecycle of platform DMA ops
  • Introduce static identity domains (IOMMU_DOMAIN_IDENTITY) with minimal attach_dev handlers for Exynos, Rockchip, Renesas IPMMU (ipmmu-vmsa), Qualcomm SMMU (qcom_iommu), Tegra SMMU, Allwinner sun50i, MSM, MTK IOMMU v1/v2, OMAP, and use them as ops->identity_domain and/or initial owner->domain/iommu->domain
  • Add platform domains or platform attach handlers (IOMMU_DOMAIN_PLATFORM) for fsl_pamu and s390, using them as ops->default_domain and redirecting attach_dev to implement the previous platform-DMA behavior
  • Adjust driver attach paths to first transition devices back to the identity/platform domain (via new *_identity_attach or *_platform_attach helpers) before attaching to a new mapping domain, ensuring clean teardown of existing translation state
  • Update suspend/resume and release paths (e.g., Exynos, Tegra, sun50i) to treat the identity domain as the baseline state instead of testing for non-NULL domain pointers
include/linux/iommu.h
drivers/iommu/exynos-iommu.c
drivers/iommu/ipmmu-vmsa.c
drivers/iommu/fsl_pamu_domain.c
drivers/iommu/arm/arm-smmu/qcom_iommu.c
drivers/iommu/tegra-smmu.c
drivers/iommu/sun50i-iommu.c
drivers/iommu/msm_iommu.c
drivers/iommu/mtk_iommu.c
drivers/iommu/mtk_iommu_v1.c
drivers/iommu/omap-iommu.c
drivers/iommu/s390-iommu.c
drivers/iommu/rockchip-iommu.c
Adjust or clean up platform-specific memory controller/IOMMU glue to align with the new domain model and remove legacy Tegra GART support.
  • Remove Tegra GART driver, its Kconfig/Makefile integration, and mc.h declarations, along with Tegra MC/GART suspend/resume plumbing
  • Initialize Tegra SMMU default domain type to IDENTITY via def_domain_type hook to keep existing behavior for Tegra SoCs with quirks
  • Simplify Tegra MC probe and ops by dropping GART-related fields and power-management hooks that are now unused
drivers/memory/tegra/mc.c
drivers/memory/tegra/tegra20.c
include/soc/tegra/mc.h
drivers/iommu/Makefile
drivers/iommu/tegra-gart.c
Fix minor correctness and style issues in the IOMMU user-data helper.
  • Move NULL-pointer WARN_ON checks before using user_data->type in __iommu_copy_struct_from_user() and fix typo in comment documenting @min_last parameter of iommu_copy_struct_from_user macro
include/linux/iommu.h
Correct SPAPR (powerpc) VFIO/IOMMU blocked vs platform domain ownership transitions.
  • Split SPAPR TCE "platform" and "blocked" behavior into separate domains with distinct attach_dev implementations
  • Ensure that transitioning from BLOCKED to PLATFORM releases table_group ownership, and transitioning to BLOCKED takes ownership, matching VFIO expectations
arch/powerpc/kernel/iommu.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In tegra-smmu.c, tegra_smmu_def_domain_type is assigned to .def_domain_type as &tegra_smmu_def_domain_type, but the field expects a function pointer, so the ampersand should be dropped to avoid a type mismatch and potential build issues.
  • The new iommu_get_def_domain_type() and group-level default-domain logic introduce stricter failure paths (e.g. returning -1 when a driver’s requested type conflicts or for untrusted devices); it would be helpful to double-check all callers handle these new error returns correctly, especially around iommu_setup_default_domain() where NULL vs ERR_PTR vs -ENODEV semantics are subtle.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In tegra-smmu.c, `tegra_smmu_def_domain_type` is assigned to `.def_domain_type` as `&tegra_smmu_def_domain_type`, but the field expects a function pointer, so the ampersand should be dropped to avoid a type mismatch and potential build issues.
- The new `iommu_get_def_domain_type()` and group-level default-domain logic introduce stricter failure paths (e.g. returning `-1` when a driver’s requested type conflicts or for untrusted devices); it would be helpful to double-check all callers handle these new error returns correctly, especially around `iommu_setup_default_domain()` where `NULL` vs `ERR_PTR` vs `-ENODEV` semantics are subtle.

## Individual Comments

### Comment 1
<location path="drivers/iommu/exynos-iommu.c" line_range="833" />
<code_context>

 		mutex_lock(&owner->rpm_lock);
-		if (data->domain) {
+		if (&data->domain->domain != &exynos_identity_domain) {
 			dev_dbg(data->sysmmu, "saving state\n");
 			__sysmmu_disable(data);
</code_context>
<issue_to_address>
**issue (bug_risk):** Potential NULL dereference of data->domain in suspend/resume paths

The previous code safely checked `data->domain` before use. The new condition dereferences `data->domain` unconditionally to compare with `exynos_identity_domain`, which will crash if `data->domain` is NULL (e.g., before any domain is attached). Please restore the NULL guard, for example:

`if (data->domain && &data->domain->domain != &exynos_identity_domain)`
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


mutex_lock(&owner->rpm_lock);
if (data->domain) {
if (&data->domain->domain != &exynos_identity_domain) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential NULL dereference of data->domain in suspend/resume paths

The previous code safely checked data->domain before use. The new condition dereferences data->domain unconditionally to compare with exynos_identity_domain, which will crash if data->domain is NULL (e.g., before any domain is attached). Please restore the NULL guard, for example:

if (data->domain && &data->domain->domain != &exynos_identity_domain)

@opsiff opsiff force-pushed the linux-6.6.y-2026-07-01-nested-fixes-1-2 branch 2 times, most recently from 1192d11 to c4b6a1e Compare July 2, 2026 02:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the kernel IOMMU core and multiple IOMMU drivers with the upstream default/identity/platform domain model, removing legacy platform-DMA hooks and dropping Tegra20 GART support as obsolete.

Changes:

  • Remove iommu_ops->set_platform_dma_ops and refactor core default-domain selection/allocation to operate per-IOMMU-group.
  • Introduce/standardize static identity/platform/blocked domain handling across multiple IOMMU drivers to ensure safe detach/restore behavior.
  • Remove Tegra GART IOMMU support (Kconfig/Makefile/code) and related Tegra MC integration.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
include/soc/tegra/mc.h Removes GART-related declarations and Tegra MC suspend/resume hooks.
include/linux/iommu.h Removes set_platform_dma_ops from struct iommu_ops; tightens user-copy helper checks and fixes comment wording.
drivers/memory/tegra/tegra20.c Drops Tegra20 MC suspend/resume paths that were only used for GART.
drivers/memory/tegra/mc.c Removes GART probe and MC PM ops wiring.
drivers/iommu/tegra-smmu.c Adds identity domain + def_domain_type integration for Tegra SMMU; removes platform-DMA hook.
drivers/iommu/tegra-gart.c Deletes the legacy Tegra20 GART IOMMU driver implementation.
drivers/iommu/sun50i-iommu.c Adds identity domain handling and uses it during (re)attach flows.
drivers/iommu/s390-iommu.c Reworks platform DMA handoff into a PLATFORM default domain.
drivers/iommu/rockchip-iommu.c Removes legacy ARM-only platform-DMA hook.
drivers/iommu/omap-iommu.c Adds identity domain and removes platform-DMA hook usage.
drivers/iommu/mtk_iommu.c Adds identity domain support.
drivers/iommu/mtk_iommu_v1.c Adds identity domain support and removes legacy default-domain/platform-DMA hooks.
drivers/iommu/msm_iommu.c Adds identity domain support and removes platform-DMA hook.
drivers/iommu/Makefile Stops building tegra-gart.o.
drivers/iommu/Kconfig Removes CONFIG_TEGRA_IOMMU_GART.
drivers/iommu/ipmmu-vmsa.c Adds identity-domain detach support by disabling microTLB translation.
drivers/iommu/iommu.c Refactors core default-domain allocation/selection to per-group ops; removes set_platform_dma_ops pathways and tightens untrusted-device handling.
drivers/iommu/fsl_pamu_domain.c Converts legacy platform-DMA hook usage into a PLATFORM default domain (with documented quirks).
drivers/iommu/exynos-iommu.c Introduces a static identity domain and reworks detach/release paths around it.
drivers/iommu/arm/arm-smmu/qcom_iommu.c Adds identity-domain attach path that disables context banks.
arch/powerpc/kernel/iommu.c Adjusts SPAPR domain attach semantics for PLATFORM/BLOCKED domains.
arch/arm/configs/tegra_defconfig Drops CONFIG_TEGRA_IOMMU_GART.
arch/arm/configs/multi_v7_defconfig Drops CONFIG_TEGRA_IOMMU_GART.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/linux/iommu.h
Comment on lines 381 to 395
struct iommu_ops {
bool (*capable)(struct device *dev, enum iommu_cap);
void *(*hw_info)(struct device *dev, u32 *length, u32 *type);

/* Domain allocation and freeing by the iommu driver */
struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
struct iommu_domain *(*domain_alloc_user)(
struct device *dev, u32 flags, struct iommu_domain *parent,
const struct iommu_user_data *user_data);

struct iommu_device *(*probe_device)(struct device *dev);
void (*release_device)(struct device *dev);
void (*probe_finalize)(struct device *dev);
void (*set_platform_dma_ops)(struct device *dev);
struct iommu_group *(*device_group)(struct device *dev);

Comment thread drivers/iommu/iommu.c
Comment on lines +1880 to +1883
/*
* Try to recover, drivers are allowed to force IDENITY or DMA, IDENTITY
* takes precedence.
*/
Comment on lines 767 to +775
dev_dbg(dev, "Detaching from IOMMU domain\n");

if (iommu->domain != domain)
return;
if (iommu->domain == identity_domain)
return 0;

sun50i_domain = to_sun50i_domain(iommu->domain);
if (refcount_dec_and_test(&sun50i_domain->refcnt))
sun50i_iommu_detach_domain(iommu, sun50i_domain);
return 0;
opsiff and others added 14 commits July 2, 2026 13:47
after the commit set_platform_dma_ops will be removed.
sumbit it later.
This reverts commit 6ab6a87.

Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

All drivers are now using IDENTITY or PLATFORM domains for what this did,
we can remove it now. It is no longer possible to attach to a NULL domain.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Tested-by: Steven Price <steven.price@arm.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/15-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 24b1d47)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

This brings back the ops->detach_dev() code that commit
1b932ce ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/16-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 786478a)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

This brings back the ops->detach_dev() code that commit
1b932ce ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Also reverts commit 584d334 ("iommu/ipmmu-vmsa: Remove
ipmmu_utlb_disable()")

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/17-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 666c9f1)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

This brings back the ops->detach_dev() code that commit
1b932ce ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/18-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit b01b125)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

Prior to commit 1b932ce ("iommu: Remove detach_dev callbacks") the
sun50i_iommu_detach_device() function was being called by
ops->detach_dev().

This is an IDENTITY domain so convert sun50i_iommu_detach_device() into
sun50i_iommu_identity_attach() and a full IDENTITY domain and thus hook it
back up the same was as the old ops->detach_dev().

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/19-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 5b167de)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

At this point every iommu driver will cause a default_domain to be
selected, so we can finally remove this gap from the core code.

The following table explains what each driver supports and what the
resulting default_domain will be:

                                        ops->defaut_domain
                    IDENTITY   DMA  PLATFORM    v      ARM32          dma-iommu  ARCH
amd/iommu.c             Y       Y                       N/A             either
apple-dart.c            Y       Y                       N/A             either
arm-smmu.c              Y       Y                       IDENTITY        either
qcom_iommu.c            G       Y                       IDENTITY        either
arm-smmu-v3.c           Y       Y                       N/A             either
exynos-iommu.c          G       Y                       IDENTITY        either
fsl_pamu_domain.c                       Y       Y       N/A             N/A     PLATFORM
intel/iommu.c           Y       Y                       N/A             either
ipmmu-vmsa.c            G       Y                       IDENTITY        either
msm_iommu.c             G                               IDENTITY        N/A
mtk_iommu.c             G       Y                       IDENTITY        either
mtk_iommu_v1.c          G                               IDENTITY        N/A
omap-iommu.c            G                               IDENTITY        N/A
rockchip-iommu.c        G       Y                       IDENTITY        either
s390-iommu.c                            Y       Y       N/A             N/A     PLATFORM
sprd-iommu.c                    Y                       N/A             DMA
sun50i-iommu.c          G       Y                       IDENTITY        either
tegra-smmu.c            G       Y                       IDENTITY        IDENTITY
virtio-iommu.c          Y       Y                       N/A             either
spapr                                   Y       Y       N/A             N/A     PLATFORM
 * G means ops->identity_domain is used
 * N/A means the driver will not compile in this configuration

ARM32 drivers select an IDENTITY default domain through either the
ops->identity_domain or directly requesting an IDENTIY domain through
alloc_domain().

In ARM64 mode tegra-smmu will still block the use of dma-iommu.c and
forces an IDENTITY domain.

S390 uses a PLATFORM domain to represent when the dma_ops are set to the
s390 iommu code.

fsl_pamu uses an PLATFORM domain.

POWER SPAPR uses PLATFORM and blocking to enable its weird VFIO mode.

The x86 drivers continue unchanged.

After this patch group->default_domain is only NULL for a short period
during bus iommu probing while all the groups are constituted. Otherwise
it is always !NULL.

This completes changing the iommu subsystem driver contract to a system
where the current iommu_domain always represents some form of translation
and the driver is continuously asserting a definable translation mode.

It resolves the confusion that the original ops->detach_dev() caused
around what translation, exactly, is the IOMMU performing after
detach. There were at least three different answers to that question in
the tree, they are all now clearly named with domain types.

Tested-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Tested-by: Steven Price <steven.price@arm.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/20-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 98ac73f)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.15-rc1
category: bugfix

It turns out that deferred default domain creation leaves a subtle
race window during iommu_device_register() wherein a client driver may
asynchronously probe in parallel and get as far as performing DMA API
operations with dma-direct, only to be switched to iommu-dma underfoot
once the default domain attachment finally happens, with obviously
disastrous consequences. Even the wonky of_iommu_configure() path is at
risk, since iommu_fwspec_init() will no longer defer client probe as the
instance ops are (necessarily) already registered, and the "replay"
iommu_probe_device() call can see dev->iommu_group already set and so
think there's nothing to do either.

Fortunately we already have the right tool in the right place in the
form of iommu_device_use_default_domain(), which just needs to ensure
that said default domain is actually ready to *be* used. Deferring the
client probe shouldn't have too much impact, given that this only
happens while the IOMMU driver is probing, and thus due to kick the
deferred probe list again once it finishes.

Reported-by: Charan Teja Kalla <quic_charante@quicinc.com>
Fixes: 98ac73f ("iommu: Require a default_domain for all iommu drivers")
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/e88b94c9b575034a2c98a48b3d383654cbda7902.1740753261.git.robin.murphy@arm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit b46064a)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

Allocate a domain from a group. Automatically obtains the iommu_ops to use
from the device list of the group. Convert the internal callers to use it.

Tested-by: Steven Price <steven.price@arm.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/21-v8-81230027b2fa+9d-iommu_all_defdom_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Conflicts:
	drivers/iommu/iommu.c
[remove ops=dev_iommu_ops(dev), for group_iommu_ops(group)=dev_iommu_ops(dev) now]
(cherry picked from commit 8359cf3)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

POWER throws a splat at boot, it looks like the DMA ops were probably
changed while a driver was attached. Something is still weird about how
power sequences its bootup. Previously this was hidden since the core
iommu code did nothing during probe, now it calls
spapr_tce_platform_iommu_attach_dev().

Make spapr_tce_platform_iommu_attach_dev() do nothing on the probe time
call like it did before.

  WARNING: CPU: 0 PID: 8 at arch/powerpc/kernel/iommu.c:407 __iommu_free+0x1e4/0x1f0
  Modules linked in: sd_mod t10_pi crc64_rocksoft crc64 sg ibmvfc mlx5_core(+) scsi_transport_fc ibmveth mlxfw psample dm_multipath dm_mirror dm_region_hash dm_log dm_mod fuse
  CPU: 0 PID: 8 Comm: kworker/0:0 Not tainted 6.6.0-rc3-next-20230929-auto #1
  Hardware name: IBM,9080-HEX POWER10 (raw) 0x800200 0xf000006 of:IBM,FW1030.30 (NH1030_062) hv:phyp pSeries
  Workqueue: events work_for_cpu_fn
  NIP:  c00000000005f6d4 LR: c00000000005f6d0 CTR: 00000000005ca81c
  REGS: c000000003a27890 TRAP: 0700   Not tainted (6.6.0-rc3-next-20230929-auto)
  MSR:  800000000282b033 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI,LE>  CR: 48000824  XER: 00000008
  CFAR: c00000000020f738 IRQMASK: 0
  GPR00: c00000000005f6d0 c000000003a27b30 c000000001481800 000000000000017
  GPR04: 00000000ffff7fff c000000003a27950 c000000003a27948 0000000000000027
  GPR08: c000000c18c07c10 0000000000000001 0000000000000027 c000000002ac8a08
  GPR12: 0000000000000000 c000000002ff0000 c00000000019cc88 c000000003042300
  GPR16: 0000000000000000 0000000000000000 0000000000000000 c000000003071ab0
  GPR20: c00000000349f80d c000000003215440 c000000003215480 61c8864680b583eb
  GPR24: 0000000000000000 000000007fffffff 0800000020000000 0000000000000010
  GPR28: 0000000000020000 0000800000020000 c00000000c5dc800 c00000000c5dc880
  NIP [c00000000005f6d4] __iommu_free+0x1e4/0x1f0
  LR [c00000000005f6d0] __iommu_free+0x1e0/0x1f0
  Call Trace:
  [c000000003a27b30] [c00000000005f6d0] __iommu_free+0x1e0/0x1f0 (unreliable)
  [c000000003a27bc0] [c00000000005f848] iommu_free+0x28/0x70
  [c000000003a27bf0] [c000000000061518] iommu_free_coherent+0x68/0xa0
  [c000000003a27c20] [c00000000005e8d4] dma_iommu_free_coherent+0x24/0x40
  [c000000003a27c40] [c00000000024698c] dma_free_attrs+0x10c/0x140
  [c000000003a27c90] [c008000000dcb8d4] mlx5_cmd_cleanup+0x5c/0x90 [mlx5_core]
  [c000000003a27cc0] [c008000000dc45a0] mlx5_mdev_uninit+0xc8/0x100 [mlx5_core]
  [c000000003a27d00] [c008000000dc4ac4] probe_one+0x3ec/0x530 [mlx5_core]
  [c000000003a27d90] [c0000000008c5edc] local_pci_probe+0x6c/0x110
  [c000000003a27e10] [c000000000189c98] work_for_cpu_fn+0x38/0x60
  [c000000003a27e40] [c00000000018d1d0] process_scheduled_works+0x230/0x4f0
  [c000000003a27f10] [c00000000018ff14] worker_thread+0x1e4/0x500
  [c000000003a27f90] [c00000000019cdb8] kthread+0x138/0x140
  [c000000003a27fe0] [c00000000000df98] start_kernel_thread+0x14/0x18
  Code: 481b004d 60000000 e89e0028 3c62ffe0 3863dd20 481b0039 60000000 e89e0038 3c62ffe0 3863dd38 481b0025 60000000 <0fe00000> 4bffff20 60000000 3c4c0142
  ---[ end trace 0000000000000000 ]---
  iommu_free: invalid entry
      entry     = 0x8000000203d0
      dma_addr  = 0x8000000203d0000
      Table     = 0xc00000000c5dc800
      bus#      = 0x1
      size      = 0x20000
      startOff  = 0x800000000000
      index     = 0x70200016

Fixes: 2ad56ef ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops")
Reported-by: Tasmiya Nalatwad <tasmiya@linux.vnet.ibm.com>
Link: https://lore.kernel.org/r/d06cee81-c47f-9d62-dfc6-4c77b60058db@linux.vnet.ibm.com
Tested-by: Tasmiya Nalatwad <tasmiya@linux.vnet.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/0-v1-2b52423411b9+164fc-iommu_ppc_defdomain_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit a8ca9fc)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.7-rc1
category: bugfix

This function returns NULL on errors, not ERR_PTR.

Fixes: 1c68cbc ("iommu: Add IOMMU_DOMAIN_PLATFORM")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/8fb75157-6c81-4a9c-9992-d73d49902fa8@moroto.mountain
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/0-v2-ee2bae9af0f2+96-iommu_ga_err_ptr_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit b85b4f3)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.8-rc3
category: bugfix

The ops->default_domain flow used a 0 req_type to select the default
domain and this was enforced by iommu_group_alloc_default_domain().

When !CONFIG_IOMMU_DMA started forcing the old ARM32 drivers into IDENTITY
it also overroad the 0 req_type of the ops->default_domain drivers to
IDENTITY which ends up causing failures during device probe.

Make iommu_group_alloc_default_domain() accept a req_type that matches the
ops->default_domain and have iommu_group_alloc_default_domain() generate a
req_type that matches the default_domain.

This way the req_type always describes what kind of domain should be
attached and ops->default_domain overrides all other mechanisms to choose
the default domain.

Fixes: 2ad56ef ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops")
Fixes: 0f6a904 ("iommu: Do not use IOMMU_DOMAIN_DMA if CONFIG_IOMMU_DMA is not enabled")
Reported-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Closes: https://lore.kernel.org/linux-iommu/20240123165829.630276-1-ovidiu.panait@windriver.com/
Reported-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Closes: https://lore.kernel.org/linux-iommu/170618452753.3805.4425669653666211728.stgit@ltcd48-lp2.aus.stglab.ibm.com/
Tested-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Tested-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/0-v1-755bd21c4a64+525b8-iommu_def_dom_fix_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Conflicts:
	drivers/iommu/iommu.c
(cherry picked from commit 83b3836)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
mainline inclusion
from mainline-v6.8-rc3
categroy: bugfix

The commit 2ad56ef ("powerpc/iommu: Setup a default domain and
remove set_platform_dma_ops") refactored the code removing the
set_platform_dma_ops(). It missed out the table group
release_ownership() call which would have got called otherwise
during the guest shutdown via vfio_group_detach_container(). On
PPC64, this particular call actually sets up the 32-bit TCE table,
and enables the 64-bit DMA bypass etc. Now after guest shutdown,
the subsequent host driver (e.g megaraid-sas) probe post unbind
from vfio-pci fails like,

megaraid_sas 0031:01:00.0: Warning: IOMMU dma not supported: mask 0x7fffffffffffffff, table unavailable
megaraid_sas 0031:01:00.0: Warning: IOMMU dma not supported: mask 0xffffffff, table unavailable
megaraid_sas 0031:01:00.0: Failed to set DMA mask
megaraid_sas 0031:01:00.0: Failed from megasas_init_fw 6539

The patch brings back the call to table_group release_ownership()
call when switching back to PLATFORM domain from BLOCKED, while
also separates the domain_ops for both.

Fixes: 2ad56ef ("powerpc/iommu: Setup a default domain and remove set_platform_dma_ops")
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/170628173462.3742.18330000394415935845.stgit@ltcd48-lp2.aus.stglab.ibm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit d2d00e1)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
deepin inclusion
category: other

Assisted-by: kimi-cli: kimi-k2.7 code
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@opsiff opsiff force-pushed the linux-6.6.y-2026-07-01-nested-fixes-1-2 branch from c4b6a1e to 057d3ea Compare July 2, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants