From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 048A9238C29 for ; Fri, 9 Jan 2026 19:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767986179; cv=none; b=T0HVcfFKatcGPGv865/jyusuEg8OZ8DXm6piL9zSA4lHs/rFlas6XlbTw3zZujCTA5JCrVNSi6TDLzH2nmgU+gibuA6mHi77XyiU3BGYu0UNzZJJN50vh5Jtxn1Jdee6XKwt7hHPwV6HYvB9gLaicpcgGPMLVPcmhhvUcll6Xlc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767986179; c=relaxed/simple; bh=1nPt0jMenK9foxrM3p/sw5FChCH1n394SDkI1BEWCNo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hZ1Jsqu2T38zsVW6jmrcljK+XrvrCPUsGQMEcJWJxWVpTNFXF62oTB6q6zof9Km10KJTeHyco+G1uNvAzUJkNKt56zN+yUGkFRnhJrg4heDrdWivXAJ2hlSlFAEuEMIvwPMFvc06kIw7swn2BI7qeZcs1S9KNhHRuJZYHjjZH9U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yPTbktrq; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yPTbktrq" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2a35ae38bdfso12805ad.1 for ; Fri, 09 Jan 2026 11:16:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767986177; x=1768590977; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=OY298V/mlr0e0R/jNCYCk/cEMiQwxaFCVZQ5rO28hR8=; b=yPTbktrqMBipzxWSUIYwgIgnnI4u8uDQo4MKz8bw46b/nLo38heV9zh3JXP5golVDC 64IMtgh7Vi6bRuPuA52/XnozSyWOOgq1pLxbt5SplJlZFEk+X0EZDOIVEFSSMyURgoYN KU7b+IgnbSz3UPPmtL0lx0Cn4W5RAp+wVcb4bbaCbkgiBvmXO0VXoA7e1tYaBOY4/srP n2yGxX7qWw9MaIXk0U1mH73JgUnhFxr9zD8CsG5rDaD/qJi3pU7yrVw2Ngf5gjBdWu3s ZMIWB2o5CkxtrJ8YEiXwS/CfGB27eaVLRK5gva7X3TGqYVxN+qgnUVUU/tUfN5rODcAu DEKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767986177; x=1768590977; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OY298V/mlr0e0R/jNCYCk/cEMiQwxaFCVZQ5rO28hR8=; b=MuYVrmg8xAS14rmHDCPTDX5350c/+hU8uAAILReXUacQlNadNZ2LwrrQmIwvfqVAlc AZh9Pn3MqFrIu6c/95TE4ErYIxUwE5g0cTDexkb2CF0x8WKC9GowjovgX3m0E+Ga1ulU sobf6QTTBRo6L6143jTwEN7DmiFk+n1u0Sto4MuTIjGO475sP2gN8sO1jnN2I/20MxVS WpkfTdXwoO6Qp5gLUbfUWgLYzPSWt/s2rVRNu7wweC+ekAuO4TX4GuN5Zup+pDmtBIOk 44CEiDQ34QnCwwzTaMqGyy6748QDOOyure0JNKKevCVC9h2TipixJaI7Prca47tEyekp tpAQ== X-Forwarded-Encrypted: i=1; AJvYcCVkCZUyCZR0QBgwGJ7i+5HMWNeUW4FGNFLT0LNwFX9ipRQVI883V4Gl8n++bb+AJThy4+KGYirc/owZt/4=@vger.kernel.org X-Gm-Message-State: AOJu0YyGyaMqVVtXUXgFFvj7eNxI7Ic/UGHvMfy5OZ407LzGmUh80RQZ a1USEZZpzwgSNqzieONSMJGZaProDZN6U2S5lJdQLszq8XRon68jyPo1xQCfcF3gEQ== X-Gm-Gg: AY/fxX5gEx5lUf5teTroF64F+LHCMcFqnu/Bjmp2pKTeloI+s7dxBQKVN+4pMr7S28f IsXIJu5xDt8I3DAamHPmGhSHdy8rAmqYfCzFecjS5vg6ueXMDZSrNnQRJharr5OEFWYmb5ES0o2 hgy5aIRnZ1KxOgxRvzJT0CZ2t5V/bU7MsaAuKkmgeeVnH3ktVNSsjrROGc2FZ/OScnKpZsyfVb+ V/EifWqCcuRw3Sxk3p6sJpg4qRstzXRTyYKZeWFdlF6TNywlkDby9UW0ZrBJUTnXZh5+zE4XQil JsccEdfRM+dVNtKrXnrXkzvsSUuETc+bif6ucK0rol/yvl/YJAegKQy/ajoueTRdm8Tx3dZTgLP usD3qF1MZXnoALAjrccfIQ4xOhFJ3SIPgX4zKoITSA8mpqVxz0IHJUygsUM/6fOT7/nGPvCppzN 54DAXzfXPOWx4JIfsu0ExIX2oahT3gVDJuvMvapP/soWedKTLH X-Received: by 2002:a17:902:f690:b0:2a1:3cda:8e99 with SMTP id d9443c01a7336-2a4149da4e3mr360525ad.21.1767986176660; Fri, 09 Jan 2026 11:16:16 -0800 (PST) Received: from google.com (222.245.187.35.bc.googleusercontent.com. [35.187.245.222]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81d87955bb6sm4087620b3a.50.2026.01.09.11.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 11:16:16 -0800 (PST) Date: Fri, 9 Jan 2026 19:16:08 +0000 From: Pranjal Shrivastava To: Mostafa Saleh 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, will@kernel.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, xiaqinxin@huawei.com, baolu.lu@linux.intel.com, rdunlap@infradead.org, Samiullah Khawaja Subject: Re: [PATCH v6 4/4] iommu: debug-pagealloc: Check mapped/unmapped kernel memory Message-ID: References: <20260109171805.901995-1-smostafa@google.com> <20260109171805.901995-5-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260109171805.901995-5-smostafa@google.com> On Fri, Jan 09, 2026 at 05:18:05PM +0000, Mostafa Saleh wrote: > Now, as the page_ext holds count of IOMMU mappings, we can use it to > assert that any page allocated/freed is indeed not in the IOMMU. > > The sanitizer doesn’t protect against mapping/unmapping during this > period. However, that’s less harmful as the page is not used by the > kernel. > > Reviewed-by: Samiullah Khawaja > Reviewed-by: Lu Baolu > Signed-off-by: Mostafa Saleh > --- > drivers/iommu/iommu-debug-pagealloc.c | 23 +++++++++++++++++++++++ > include/linux/iommu-debug-pagealloc.h | 14 ++++++++++++++ > include/linux/mm.h | 5 +++++ > 3 files changed, 42 insertions(+) > Reviewed-by: Pranjal Shrivastava Thanks, Praan > diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c > index 9eb49e1230ee..c080a38f45a4 100644 > --- a/drivers/iommu/iommu-debug-pagealloc.c > +++ b/drivers/iommu/iommu-debug-pagealloc.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > #include "iommu-priv.h" > > @@ -73,6 +74,28 @@ static size_t iommu_debug_page_size(struct iommu_domain *domain) > return 1UL << __ffs(domain->pgsize_bitmap); > } > > +static bool iommu_debug_page_count(const struct page *page) > +{ > + unsigned int ref; > + struct page_ext *page_ext = page_ext_get(page); > + struct iommu_debug_metadata *d = get_iommu_data(page_ext); > + > + ref = atomic_read(&d->ref); > + page_ext_put(page_ext); > + return ref != 0; > +} > + > +void __iommu_debug_check_unmapped(const struct page *page, int numpages) > +{ > + while (numpages--) { > + if (WARN_ON(iommu_debug_page_count(page))) { > + pr_warn("iommu: Detected page leak!\n"); > + dump_page_owner(page); > + } > + page++; > + } > +} > + > void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t size) > { > size_t off, end; > diff --git a/include/linux/iommu-debug-pagealloc.h b/include/linux/iommu-debug-pagealloc.h > index a439d6815ca1..46c3c1f70150 100644 > --- a/include/linux/iommu-debug-pagealloc.h > +++ b/include/linux/iommu-debug-pagealloc.h > @@ -13,6 +13,20 @@ DECLARE_STATIC_KEY_FALSE(iommu_debug_initialized); > > extern struct page_ext_operations page_iommu_debug_ops; > > +void __iommu_debug_check_unmapped(const struct page *page, int numpages); > + > +static inline void iommu_debug_check_unmapped(const struct page *page, int numpages) > +{ > + if (static_branch_unlikely(&iommu_debug_initialized)) > + __iommu_debug_check_unmapped(page, numpages); > +} > + > +#else > +static inline void iommu_debug_check_unmapped(const struct page *page, > + int numpages) > +{ > +} > + > #endif /* CONFIG_IOMMU_DEBUG_PAGEALLOC */ > > #endif /* __LINUX_IOMMU_DEBUG_PAGEALLOC_H */ > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 6f959d8ca4b4..32205d2a24b2 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -36,6 +36,7 @@ > #include > #include > #include > +#include > > struct mempolicy; > struct anon_vma; > @@ -4133,12 +4134,16 @@ extern void __kernel_map_pages(struct page *page, int numpages, int enable); > #ifdef CONFIG_DEBUG_PAGEALLOC > static inline void debug_pagealloc_map_pages(struct page *page, int numpages) > { > + iommu_debug_check_unmapped(page, numpages); > + > if (debug_pagealloc_enabled_static()) > __kernel_map_pages(page, numpages, 1); > } > > static inline void debug_pagealloc_unmap_pages(struct page *page, int numpages) > { > + iommu_debug_check_unmapped(page, numpages); > + > if (debug_pagealloc_enabled_static()) > __kernel_map_pages(page, numpages, 0); > } > -- > 2.52.0.457.g6b5491de43-goog > >