From: sashiko-bot@kernel.org
To: "Sasha Levin" <sashal@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH AUTOSEL 6.18] drm/msm: detach the ARM DMA mapping before attaching our own domain
Date: Mon, 19 Oct 2026 14:59:42 +0000 [thread overview]
Message-ID: <sashiko-outbox-177584@kernel.org> (raw)
In-Reply-To: <20261019135441.1420968-276-sashal@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/msm: NULL dereference in __free_iova() via msm_iommu_new() detach
--
commit 8a10d4b676f6bf2e4f498788e23c54cc872ffbc5
Author: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
drm/msm: detach the ARM DMA mapping before attaching our own domain
This commit detaches and releases the default ARM32 DMA IOMMU mapping in
msm_iommu_new() before attaching the driver's own IOMMU domain so that
__iommu_attach_group() does not fail with -EBUSY on ARM32 platforms with
CONFIG_ARM_DMA_USE_IOMMU enabled.
Link: https://lore.kernel.org/r/20260730-fix-qcom-smmu-v2-3-18e0daf2d836@oss.qualcomm.com
> diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c
> index 82a172f21a3ec..41a4eaa1b8fd9 100644
> --- a/drivers/gpu/drm/msm/msm_iommu.c
> +++ b/drivers/gpu/drm/msm/msm_iommu.c
[ ... ]
> @@ -746,6 +755,19 @@ struct msm_mmu *msm_iommu_new(struct device *dev, unsigned long quirks)
>
> mutex_init(&iommu->init_lock);
>
> + /*
> + * ARM32 attaches a DMA mapping domain to every IOMMU-backed device,
> + * which would make attaching our own domain fail with -EBUSY.
> + */
> + if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) {
> + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
> +
> + if (mapping) {
> + arm_iommu_detach_device(dev);
> + arm_iommu_release_mapping(mapping);
> + }
> + }
[Severity: High]
Could backporting this patch without the rest of its upstream series cause a
NULL pointer dereference in __free_iova() when probing the GPU or display
controller on APQ8064?
Upstream commit 140b13475302 ("drm/msm: detach the ARM DMA mapping before
attaching our own domain") is patch 3/3 of the series at
20260730-fix-qcom-smmu-v2-3-18e0daf2d836@oss.qualcomm.com, alongside two
prerequisite fixes in drivers/iommu/msm_iommu.c:
1/3: "iommu/msm: track a context master per device and IOMMU"
2/3: "iommu/msm: use the IOMMU device for page table allocation"
Neither of those prerequisite patches is present in this tree.
During initial DMA setup in arm_setup_iommu_dma_ops(),
__arm_iommu_attach_device(dev, mapping) runs before set_dma_ops(dev,
&iommu_ops). Without patch 2/3, msm_iommu_attach_dev() and
msm_iommu_domain_config() set priv->cfg.iommu_dev to the client device (dev)
instead of the IOMMU hardware device:
drivers/iommu/msm_iommu.c:msm_iommu_domain_config() {
priv->cfg = (struct io_pgtable_cfg) {
.pgsize_bitmap = priv->domain.pgsize_bitmap,
.ias = 32,
.oas = 32,
.tlb = &msm_iommu_flush_ops,
.iommu_dev = priv->dev,
};
}
When alloc_io_pgtable_ops() allocates the L1 page table in
__arm_v7s_alloc_table(), dev->dma_ops is still NULL, so dma_map_single() uses
direct DMA and returns the physical RAM address virt_to_phys(data->pgd)
without allocating an IOVA in mapping. Afterward, arm_setup_iommu_dma_ops()
sets dev->dma_ops = &iommu_ops.
When msm_iommu_new() now calls arm_iommu_detach_device(dev),
iommu_detach_device() runs while dev->dma_ops is still &iommu_ops:
arch/arm/mm/dma-mapping.c:arm_iommu_detach_device() {
...
iommu_detach_device(mapping->domain, dev);
kref_put(&mapping->kref, release_iommu_mapping);
to_dma_iommu_mapping(dev) = NULL;
set_dma_ops(dev, NULL);
}
This triggers the following call chain:
iommu_detach_device(mapping->domain, dev)
-> msm_iommu_identity_attach()
-> free_io_pgtable_ops(priv->iop)
-> arm_v7s_free_pgtable()
-> __arm_v7s_free_table()
-> dma_unmap_single(cfg->iommu_dev, __arm_v7s_dma_addr(table), ...)
-> arm_iommu_unmap_page()
-> __free_iova(mapping, iova, len)
Because cfg->iommu_dev is the client device and dev->dma_ops is still
&iommu_ops, arm_iommu_unmap_page() treats the page table's physical RAM
address (for example >= 0x80000000 on APQ8064) as an IOVA handle in
mapping->domain, hits WARN_ON(!ARM_V7S_PTE_IS_VALID(pte[i])) in iommu_unmap(),
and passes that address to __free_iova():
arch/arm/mm/dma-mapping.c:__free_iova() {
...
spin_lock_irqsave(&mapping->lock, flags);
bitmap_clear(mapping->bitmaps[bitmap_index], start, count);
spin_unlock_irqrestore(&mapping->lock, flags);
}
Since arm_iommu_create_mapping() initializes mapping with base = 0,
mapping_size = 128 MB, extensions = 32, and nr_bitmaps = 1 (leaving
mapping->bitmaps[1..31] NULL), a physical address >= 0x80000000 yields
bitmap_index >= 16 and dereferences a NULL mapping->bitmaps[bitmap_index] (or
hits BUG_ON(bitmap_index >= mapping->nr_bitmaps) if out of range).
In addition, this tree includes commit da33e87bd2bf ("iommu: Handle yet
another race around registration") without patch 1/3 ("iommu/msm: track a
context master per device and IOMMU"), so find_iommu_for_dev() and
msm_iommu_attach_dev() call list_first_entry(&iommu->ctx_list, ...) on IOMMU
instances whose ctx_list is still empty, and insert_iommu_master() does not
track per-IOMMU context masters for devices attached to two IOMMU instances
(gfx3d/gfx3d1 for the GPU and mdp_port0/mdp_port1 for MDP4).
Should patches 1/3 and 2/3 from the same series also be backported before
this change?
> +
> ret = iommu_attach_device(iommu->domain, dev);
> if (ret) {
> iommu_domain_free(domain);
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261019135441.1420968-276-sashal@kernel.org?part=1
next prev parent reply other threads:[~2026-10-19 14:59 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261019135441.1420968-1-sashal@kernel.org>
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18-6.6] drm/amdgpu: add buf length check Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/pm: Validate Vega hwmgr PowerPlay table bounds Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18] drm/amdgpu: validate XCP topology counts before division Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18] drm/panel-edp: Add BOE NE140QDM-NX2 Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18-5.10] drm/panel: simple: Add Kyocera tcg070wvlq panel Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18-6.1] drm/amdgpu/gfx11: WARN() rather than BUG() for invalid SDMA engine Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18] drm/amdgpu: Validate ATPX buffer length before use Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/pm: Validate legacy hwmgr PP table offsets Sasha Levin
2026-10-19 14:28 ` sashiko-bot
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18] drm/amd/display: Fix rounding errors in CalculatePrefetchSchedule Sasha Levin
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18-5.10] drm/amdgpu: Validate ATIF buffer length before use Sasha Levin
2026-10-19 14:22 ` sashiko-bot
2026-10-19 13:45 ` [PATCH AUTOSEL 6.18-5.10] drm/amdgpu: Add checks to vbios fetch through ATRM Sasha Levin
2026-10-19 13:46 ` [PATCH AUTOSEL 6.18] drm/amd/pm: derive stable PPT limits from PPTable Sasha Levin
2026-10-19 14:32 ` sashiko-bot
2026-10-19 13:46 ` [PATCH AUTOSEL 6.18-6.12] drm/msm/adreno: Add support for A704 GPU Sasha Levin
2026-10-19 13:46 ` [PATCH AUTOSEL 6.18-6.12] drm/xe: only resume exec queues that were actually suspended Sasha Levin
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18-6.1] drm/amd/pm: Use uploaded size for legacy custom PPTable Sasha Levin
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18-5.10] gpu: host1x: Wait for timeout worker completion on channel free Sasha Levin
2026-10-19 14:39 ` sashiko-bot
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18-5.10] fbdev: udlfb: validate vendor descriptor items Sasha Levin
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18-5.10] fbdev: maxine: fix 64-bit build error Sasha Levin
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18] drm/msm: Move nr_cmds initialization Sasha Levin
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18] drm/amdgpu: Fix kobject cleanup in xcp sysfs Sasha Levin
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18] drm/amdgpu/mes_v12_0: use mes schedule pipe for legacy queues on unified MES Sasha Levin
2026-10-19 13:47 ` [PATCH AUTOSEL 6.18-6.1] drm/virtio: reclaim pending vbufs before tearing down vqs Sasha Levin
2026-10-19 13:48 ` [PATCH AUTOSEL 6.18-5.15] drm/amd/pm: Validate Tonga PPTable subtable bounds Sasha Levin
2026-10-19 14:47 ` sashiko-bot
2026-10-19 13:48 ` [PATCH AUTOSEL 6.18-6.12] drm/etnaviv: force flush on power register ops Sasha Levin
2026-10-19 13:48 ` [PATCH AUTOSEL 6.18-5.10] drm/amdgpu: Support some Barco AMD based graphics adapters Sasha Levin
2026-10-19 13:48 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/pm: validate vega10 profile mode inputs Sasha Levin
2026-10-19 13:49 ` [PATCH AUTOSEL 6.18] drm/amdgpu: add check for xcp id Sasha Levin
2026-10-19 13:49 ` [PATCH AUTOSEL 6.18-6.1] drm/amdgpu: add bounds check to prevent array overflow Sasha Levin
2026-10-19 13:49 ` [PATCH AUTOSEL 6.18] drm/msm: detach the ARM DMA mapping before attaching our own domain Sasha Levin
2026-10-19 14:59 ` sashiko-bot [this message]
2026-10-19 13:49 ` [PATCH AUTOSEL 6.18-6.6] drm/amd/pm: Validate Vega10 PPTable subtable bounds Sasha Levin
2026-10-19 13:49 ` [PATCH AUTOSEL 6.18] drm/sysfb: simpledrm: Validate mmap size against framebuffer size Sasha Levin
2026-10-19 13:49 ` [PATCH AUTOSEL 6.18-6.12] drm/panel-edp: Support MB116AS01'3 edp panel Sasha Levin
2026-10-19 13:49 ` [PATCH AUTOSEL 6.18-5.10] drm/etnaviv: check all modules for idle after reset Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18] drm/panel: panel-edp: Adjust T8 timing for AUO B116XAK01.6 and B140XTK02.4 Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18-5.10] fbdev: omap2: dsi: do not copy isr table Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18-6.6] drm/radeon: fix internal display on iMac11, 1 (RV770/DCE3.1) Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18] drm/etnaviv: check MMUv2 status after reset Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18-6.6] drm/panel-edp: Add BOE NE160QDM-NY1 panel Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18-6.12] drm/amd/display: fix max dispclk_khz/dppclk_khz double 1000 Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18] drm/panel-edp: Add BOE NV116WH2-M30, BOE NT116WHM-N21, BOE NV116FH1-M31, BOE NV116FH1-M30 Sasha Levin
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18-5.10] drm/rockchip: dw_hdmi: Use resume_early pm ops for system suspend Sasha Levin
2026-10-19 15:06 ` sashiko-bot
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18-5.10] drm/amdgpu: Gate debugfs MMIO access on kernel lockdown Sasha Levin
2026-10-19 15:09 ` sashiko-bot
2026-10-19 13:50 ` [PATCH AUTOSEL 6.18-5.10] fbcon: Fix KASAN slab-out-of-bounds Read in fbcon_prepare_logo Sasha Levin
2026-10-19 13:51 ` [PATCH AUTOSEL 6.18] drm/amdkfd: use node XCC count for v9 CRIU control stack restore Sasha Levin
2026-10-19 13:51 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/pm: Validate OD DPM triples before mutating tables Sasha Levin
2026-10-19 13:51 ` [PATCH AUTOSEL 6.18] drm/virtio: abort virtqueue wait on device removal to avoid hung task Sasha Levin
2026-10-19 15:24 ` sashiko-bot
2026-10-19 13:51 ` [PATCH AUTOSEL 6.18-5.10] drm/amd/pm: Validate Tonga PowerPlay state array bounds Sasha Levin
2026-10-19 13:51 ` [PATCH AUTOSEL 6.18-5.15] drm/amd/pm: Guard VBIOS AC timing table walk Sasha Levin
2026-10-19 15:20 ` sashiko-bot
2026-10-19 13:52 ` [PATCH AUTOSEL 6.18-6.1] drm/amd/pm: Validate pp_table header before reading size Sasha Levin
2026-10-19 15:31 ` sashiko-bot
2026-10-19 13:52 ` [PATCH AUTOSEL 6.18] drm/msm: Fix barriers accessing ctx vm Sasha Levin
2026-10-19 15:27 ` sashiko-bot
2026-10-19 13:52 ` [PATCH AUTOSEL 6.18-6.1] drm/amdgpu/atomfirmware: WARN() rather than BUG() Sasha Levin
2026-10-19 15:24 ` sashiko-bot
2026-10-19 13:52 ` [PATCH AUTOSEL 6.18] drm/amdgpu/gfx12: set KMD_QUEUE for kernel gfx queues Sasha Levin
2026-10-19 13:52 ` [PATCH AUTOSEL 6.18-6.12] drm/amdgpu: Guard reads in pcie state readout Sasha Levin
2026-10-19 15:24 ` sashiko-bot
2026-10-19 13:52 ` [PATCH AUTOSEL 6.18] drm/amdkfd: Fix signal reset event Sasha Levin
2026-10-19 13:53 ` [PATCH AUTOSEL 6.18-5.10] drm/radeon: avoid double free in r600 DPM cleanup Sasha Levin
2026-10-19 15:33 ` sashiko-bot
2026-10-19 13:53 ` [PATCH AUTOSEL 6.18-6.1] drm/amdkfd: add sanity check in svm_range_is_valid Sasha Levin
2026-10-19 15:36 ` sashiko-bot
2026-10-19 13:53 ` [PATCH AUTOSEL 6.18] drm/amdgpu/gfx11: set KMD_QUEUE for kernel gfx queues Sasha Levin
2026-10-19 13:53 ` [PATCH AUTOSEL 6.18-5.10] fbdev: platinumfb: add error checking for ioremap calls Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-177584@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashal@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox