From: Mostafa Saleh <smostafa@google.com>
To: Will Deacon <will@kernel.org>
Cc: linux-mm@kvack.org, iommu@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
corbet@lwn.net, joro@8bytes.org, robin.murphy@arm.com,
akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com,
mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org,
ziy@nvidia.com, david@redhat.com, lorenzo.stoakes@oracle.com,
Liam.Howlett@oracle.com, rppt@kernel.org,
Qinxin Xia <xiaqinxin@huawei.com>
Subject: Re: [PATCH v2 1/4] drivers/iommu: Add page_ext for IOMMU_DEBUG_PAGEALLOC
Date: Mon, 24 Nov 2025 11:10:06 +0000 [thread overview]
Message-ID: <aSQ9DsR0nAAvc4Pd@google.com> (raw)
In-Reply-To: <aRWtX3n2I7El4Ykv@willie-the-truck>
On Thu, Nov 13, 2025 at 10:05:19AM +0000, Will Deacon wrote:
> Hi Mostafa,
>
> On Thu, Nov 06, 2025 at 04:39:50PM +0000, Mostafa Saleh wrote:
> > Add a new config IOMMU_DEBUG_PAGEALLOC, which registers new data to
> > page_ext.
> > This config will be used by the IOMMU API to track pages mapped in
> > the IOMMU to catch drivers trying to free kernel memory that they
> > still map in their domains, causing all types of memory corruption.
> > This behaviour is disabled by default and can be enabled using
> > kernel cmdline iommu.debug_pagealloc.
> >
> > Signed-off-by: Mostafa Saleh <smostafa@google.com>
> > Tested-by: Qinxin Xia <xiaqinxin@huawei.com>
> > ---
> > .../admin-guide/kernel-parameters.txt | 6 ++++
> > drivers/iommu/Kconfig | 15 +++++++++
> > drivers/iommu/Makefile | 1 +
> > drivers/iommu/iommu-debug-pagealloc.c | 32 +++++++++++++++++++
> > include/linux/iommu-debug-pagealloc.h | 17 ++++++++++
> > mm/page_ext.c | 4 +++
> > 6 files changed, 75 insertions(+)
> > create mode 100644 drivers/iommu/iommu-debug-pagealloc.c
> > create mode 100644 include/linux/iommu-debug-pagealloc.h
>
> This looks like a pretty handy feature to me, but I have some nits below.
Thanks for taking the time to review the patches!
>
> > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> > index 6c42061ca20e..9a1c4ac8ba96 100644
> > --- a/Documentation/admin-guide/kernel-parameters.txt
> > +++ b/Documentation/admin-guide/kernel-parameters.txt
> > @@ -2557,6 +2557,12 @@
> > 1 - Bypass the IOMMU for DMA.
> > unset - Use value of CONFIG_IOMMU_DEFAULT_PASSTHROUGH.
> >
> > + iommu.debug_pagealloc=
> > + [KNL,EARLY] When CONFIG_IOMMU_DEBUG_PAGEALLOC is set, this
> > + parameter enables the feature at boot time. By default, it
> > + is disabled and the system will work mostly the same as a
> > + kernel built without CONFIG_IOMMU_DEBUG_PAGEALLOC.
>
> Can you be more specific about "mostly the same"?
The only difference is that the static key to gate the calls, I was not sure if
saying “exactly the same” is correct, but I think it’s better avoid “mostly” as
it might be confusing and as the data in the cover letter shows no overhead,
I will re-write the whole help anyway.
>
> > +
> > io7= [HW] IO7 for Marvel-based Alpha systems
> > See comment before marvel_specify_io7 in
> > arch/alpha/kernel/core_marvel.c.
> > diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> > index 70d29b14d851..6b5e9a2d936a 100644
> > --- a/drivers/iommu/Kconfig
> > +++ b/drivers/iommu/Kconfig
> > @@ -383,4 +383,19 @@ config SPRD_IOMMU
> >
> > Say Y here if you want to use the multimedia devices listed above.
> >
> > +config IOMMU_DEBUG_PAGEALLOC
> > + bool "Debug page memory allocations against IOMMU"
>
> Perhaps "IOMMU mappings" would make this a little clearer?
Will do.
>
> > + depends on DEBUG_PAGEALLOC && IOMMU_API && PAGE_EXTENSION
> > + help
> > + This config checks that a page is freed(unmapped) or mapped by the
> > + kernel is not mapped in any IOMMU domain.
>
> I can't really parse this sentence :/
I will re-write it.
>
> > It can help with debugging
> > + use-after-free or out-of-bound maps from drivers doing DMA through
> > + the IOMMU API.
> > + This santaizer can have false-negative cases where some problems
> > + won't be detected.
>
> Maybe just say "The sanitizer is best-effort and can fail to detect problems
> in the case that ...".
Makes sense, will do.
>
> > + Expect overhead when enabling this and enabling the kernel command
> > + line iommu.debug_pagealloc.
>
> I'd reword this to say something like "Due to the overhead of the sanitiser,
> iommu.debug_pagealloc must also be passed on the kernel command-line to
> enable this feature".
Will do.
>
> > +
> > + If unsure, say N here.
> > +
> > endif # IOMMU_SUPPORT
> > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> > index 355294fa9033..8f5130b6a671 100644
> > --- a/drivers/iommu/Makefile
> > +++ b/drivers/iommu/Makefile
> > @@ -34,3 +34,4 @@ obj-$(CONFIG_IOMMU_SVA) += iommu-sva.o
> > obj-$(CONFIG_IOMMU_IOPF) += io-pgfault.o
> > obj-$(CONFIG_SPRD_IOMMU) += sprd-iommu.o
> > obj-$(CONFIG_APPLE_DART) += apple-dart.o
> > +obj-$(CONFIG_IOMMU_DEBUG_PAGEALLOC) += iommu-debug-pagealloc.o
> > diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c
> > new file mode 100644
> > index 000000000000..385c8bfae02b
> > --- /dev/null
> > +++ b/drivers/iommu/iommu-debug-pagealloc.c
> > @@ -0,0 +1,32 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * Copyright (C) 2025 - Google Inc
> > + * Author: Mostafa Saleh <smostafa@google.com>
> > + * IOMMU API debug page alloc sanitizer
> > + */
> > +#include <linux/atomic.h>
> > +#include <linux/iommu-debug-pagealloc.h>
> > +#include <linux/kernel.h>
> > +#include <linux/page_ext.h>
> > +
> > +static bool needed;
> > +
> > +struct iommu_debug_metadate {
> > + atomic_t ref;
> > +};
>
> s/metadate/metadata/
Ah, that's embarrassing, I will fix it.
Thanks,
Mostafa
>
> Will
next prev parent reply other threads:[~2025-11-24 11:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 16:39 [PATCH v2 0/4] iommu: Add IOMMU_DEBUG_PAGEALLOC sanitizer Mostafa Saleh
2025-11-06 16:39 ` [PATCH v2 1/4] drivers/iommu: Add page_ext for IOMMU_DEBUG_PAGEALLOC Mostafa Saleh
2025-11-06 19:50 ` Randy Dunlap
2025-11-24 11:04 ` Mostafa Saleh
2025-11-13 10:05 ` Will Deacon
2025-11-24 11:10 ` Mostafa Saleh [this message]
2025-11-24 12:45 ` Mostafa Saleh
2025-11-06 16:39 ` [PATCH v2 2/4] drivers/iommu: Add calls " Mostafa Saleh
2025-11-13 11:00 ` Will Deacon
2025-11-24 11:23 ` Mostafa Saleh
2025-11-06 16:39 ` [PATCH v2 3/4] drivers/iommu-debug-pagealloc: Track IOMMU pages Mostafa Saleh
2025-11-13 11:00 ` Will Deacon
2025-11-24 12:37 ` Mostafa Saleh
2025-11-24 15:35 ` Will Deacon
2025-11-24 16:01 ` Mostafa Saleh
2025-11-06 16:39 ` [PATCH v2 4/4] drivers/iommu-debug-pagealloc: Check mapped/unmapped kernel memory Mostafa Saleh
2025-11-13 10:59 ` Will Deacon
2025-11-24 12:38 ` Mostafa Saleh
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=aSQ9DsR0nAAvc4Pd@google.com \
--to=smostafa@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=iommu@lists.linux.dev \
--cc=jackmanb@google.com \
--cc=joro@8bytes.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=robin.murphy@arm.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=will@kernel.org \
--cc=xiaqinxin@huawei.com \
--cc=ziy@nvidia.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 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.