[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] sync fixes for iommu#1935
[Deepin-Kernel-SIG] [linux 6.6.y] [Upstream] sync fixes for iommu#1935opsiff wants to merge 14 commits into
Conversation
Reviewer's GuideRefactors 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_devsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In tegra-smmu.c,
tegra_smmu_def_domain_typeis assigned to.def_domain_typeas&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-1when 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 aroundiommu_setup_default_domain()whereNULLvsERR_PTRvs-ENODEVsemantics 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>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) { |
There was a problem hiding this comment.
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)
1192d11 to
c4b6a1e
Compare
There was a problem hiding this comment.
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_opsand 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.
| 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); | ||
|
|
| /* | ||
| * Try to recover, drivers are allowed to force IDENITY or DMA, IDENTITY | ||
| * takes precedence. | ||
| */ |
| 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; |
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>
c4b6a1e to
057d3ea
Compare
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:
Enhancements:
Build: