From: Samiullah Khawaja <skhawaja@google.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
Allen Hubbe <allenbh@gmail.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
ntb@lists.linux.dev
Subject: Re: [PATCH v2 6/6] dma-debug: Ensure mappings are created and released with matching attributes
Date: Wed, 6 May 2026 18:16:27 +0000 [thread overview]
Message-ID: <afuFcwO8hHqWZWuc@google.com> (raw)
In-Reply-To: <20260501-dma-attrs-debug-v2-6-8dbac75cd501@nvidia.com>
On Fri, May 01, 2026 at 09:35:10AM +0300, Leon Romanovsky wrote:
>From: Leon Romanovsky <leonro@nvidia.com>
>
>The DMA API expects that callers use the same attributes when mapping
>and unmapping. Add tracking to verify this and catch mismatches.
>
>Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
>---
> kernel/dma/debug.c | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
>diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
>index 3dfed51c3d9aa..c38efc1ac8d6c 100644
>--- a/kernel/dma/debug.c
>+++ b/kernel/dma/debug.c
>@@ -1074,6 +1074,29 @@ static void check_unmap(struct dma_debug_entry *ref)
> type2name[entry->type]);
> }
>
>+ /*
>+ * This may be no bug in reality - but DMA API still expects
>+ * that entry is unmapped with same attributes as it was mapped.
>+ *
>+ * DMA_ATTR_UNMAP_VALID lists the attributes that must be identical
>+ * between map and unmap. Any attribute outside this set (e.g.
>+ * DMA_ATTR_NO_WARN, DMA_ATTR_SKIP_CPU_SYNC) is allowed to differ.
>+ */
>+#define DMA_ATTR_UNMAP_VALID \
>+ (DMA_ATTR_NO_KERNEL_MAPPING | DMA_ATTR_FORCE_CONTIGUOUS | \
>+ DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT | DMA_ATTR_PRIVILEGED | \
>+ DMA_ATTR_CC_SHARED)
>+ if ((ref->attrs & DMA_ATTR_UNMAP_VALID) !=
>+ (entry->attrs & DMA_ATTR_UNMAP_VALID)) {
>+ err_printk(ref->dev, entry,
>+ "device driver frees "
>+ "DMA memory with different attributes "
>+ "[device address=0x%016llx] [size=%llu bytes] "
>+ "[mapped with 0x%lx] [unmapped with 0x%lx]\n",
>+ ref->dev_addr, ref->size, entry->attrs, ref->attrs);
>+ }
>+#undef DMA_ATTR_UNMAP_VALID
>+
> hash_bucket_del(entry);
> put_hash_bucket(bucket, flags);
>
>
>--
>2.53.0
>
>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
prev parent reply other threads:[~2026-05-06 18:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 6:35 [PATCH v2 0/6] Add DMA attributes tracking Leon Romanovsky
2026-05-01 6:35 ` [PATCH v2 1/6] ntb: Store original DMA address for future release Leon Romanovsky
2026-05-01 17:00 ` Dave Jiang
2026-05-01 6:35 ` [PATCH v2 2/6] ntb: Use consistent DMA attributes when freeing DMA mappings Leon Romanovsky
2026-05-01 17:00 ` Dave Jiang
2026-05-01 6:35 ` [PATCH v2 3/6] dma-debug: Remove unused DMA attribute parameter Leon Romanovsky
2026-05-06 17:47 ` Samiullah Khawaja
2026-05-01 6:35 ` [PATCH v2 4/6] dma-debug: Record DMA attributes in debug entry Leon Romanovsky
2026-05-06 17:53 ` Samiullah Khawaja
2026-05-01 6:35 ` [PATCH v2 5/6] dma-debug: Feed DMA attribute for unmapping flows too Leon Romanovsky
2026-05-06 18:06 ` Samiullah Khawaja
2026-05-01 6:35 ` [PATCH v2 6/6] dma-debug: Ensure mappings are created and released with matching attributes Leon Romanovsky
2026-05-06 18:16 ` Samiullah Khawaja [this message]
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=afuFcwO8hHqWZWuc@google.com \
--to=skhawaja@google.com \
--cc=allenbh@gmail.com \
--cc=dave.jiang@intel.com \
--cc=iommu@lists.linux.dev \
--cc=jdmason@kudzu.us \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=ntb@lists.linux.dev \
--cc=robin.murphy@arm.com \
/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