From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 34556238C2A for ; Fri, 12 Dec 2025 18:47:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765565278; cv=none; b=awIedA6Q8x1np4OqN+fRMKWGzC2qULe7nb6J7+7DoPIGOCVZkshlyZDsiwdJyblf1EZkix/lnLOBPX6ouEHew/n7CV4Vqy79MQfs4lNENZgOzzW6LavUKv3cwpYftIwCLntREFYYDTZ5cEOY6CmQbGqvIVBokeFyoa+BoWnWQx4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765565278; c=relaxed/simple; bh=aYlLP5oK9ujcask7x6uq3Z6XkCkRSggu11eLJH2sWLg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BOT0MFdmNRWccnR+29U+JMhuGoW9s61OsvPl/X+Ajp/OXagUUwN54cu/2woa2bAYM4pW5CM/mSOuAtgEPjrK2gZu6iiS7vb0OwWMGLMx3PeRNeOvXWCpi/hldCfnJzVPPRnWM8uWcgh4mLzWvCGiuts70S0N4tqHCDubVLt5ZbA= 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=OmxBo1f8; arc=none smtp.client-ip=209.85.128.48 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="OmxBo1f8" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-477a1c8cc47so182075e9.0 for ; Fri, 12 Dec 2025 10:47:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765565274; x=1766170074; 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=kyaZ/i78MwYb3FB370zdecXw44g8nQdErJMSZHrGqA8=; b=OmxBo1f8/H+X8+SzPhKOM5glhBh26dOOV7ZOXD6RZ/xxKLUx1KoqkKdGc1263lZ7no 4FDqJTj7i6Md8f6Qn3kHz4zgux9P0bp37DGSdHrhlsvOm2JZCJmBNiF1qTkD/up6zxHH W9dvC1spdUB9TBM2+mwqF+nYZRRd+51WTJPWzeqVlHP3Zyteh6hlnQeVi84aGVNvSowh YBasRFCVOMwNQvZ/zg3UstxhWfmlMfKBYy5uVLUZkgnfoEe0oD72R57JxlW3zEi0Svh9 SSt3xE1wNOHY8eZ3erY4wkip08nH4zS7g5Q/Gg+yZoVPGVluf3ShlvfOBANjTEcDO56N 3DJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765565274; x=1766170074; 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=kyaZ/i78MwYb3FB370zdecXw44g8nQdErJMSZHrGqA8=; b=YFYQVtEZCxyR/8QYoK13HX/0k60qj55WywrysNJ9C6mcKDf2QaDSCDQXYNa3gF1+Po 0JrU8fPkuiEZ+Qp4KN7gpR7KYZVVoFRJinnMgbaov6A/5BSr+MBN0p4f1NNsbiUv7Pap tCA2G9BrQpDj8U9lBbYo3okoHYDA8y5qaqQ/fPEQ3ohV+ei/a5gz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b1804b1-47a948c78e9mr17525e9.3.1765565274191; Fri, 12 Dec 2025 10:47:54 -0800 (PST) Received: from google.com (54.140.140.34.bc.googleusercontent.com. [34.140.140.54]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a8f74b44csm43341825e9.3.2025.12.12.10.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 10:47:53 -0800 (PST) Date: Fri, 12 Dec 2025 18:47:50 +0000 From: Mostafa Saleh To: Baolu Lu 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, rdunlap@infradead.org Subject: Re: [PATCH v4 4/4] iommu: debug-pagealloc: Check mapped/unmapped kernel memory Message-ID: References: <20251211125928.3258905-1-smostafa@google.com> <20251211125928.3258905-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: On Fri, Dec 12, 2025 at 10:51:24AM +0800, Baolu Lu wrote: > On 12/11/25 20:59, 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. > > > > 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(+) > > [...] > > > 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); > > +} > > Same here, possible to make iommu_debug_initialized static? This also is similar to the iommu ones to reduce overhead, the main feature have the same pattern with "_debug_pagealloc_enabled" static key. Thanks, Mostafa > > > +#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 7a1819c20643..3763b71a7d3e 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); > > } > > Other changes look good to me, > > Reviewed-by: Lu Baolu