From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 E7192261B8D for ; Mon, 24 Nov 2025 12:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763987938; cv=none; b=aSNLka820eDqaM7sv8Xl9JxQlowslN0SZCrvYuzUxfVmi0wDNVei0TTUryzT/vVbGKwbCyaHSADkMi77t94Sz48cbRprm1sDuPthoxqczGWnieCQldsgH4F8LueHA34KhZ2E5rxdcUutE86Xz2Wrhjj97bKETez2wAjqEFxkxNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763987938; c=relaxed/simple; bh=fmhzmUbf5MkrRNaJZmVA3g0/x3ROh18aYfmbA6C/VdY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tl95imtAxUw6Gtq4G96kziQCixNpAE8anu88IPGj+0jXFx2mH+EKdMmjKBoVM2VuN4XItOh228/drcG/BAlfw0nIoBgDXyO1dXbGekesa88XvBJTBQEQvxfPUaaUtahVzxPazpAt3e3/BCdQ8dSUVLYim1Hi9Kt38Zr0VAandmc= 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=VzwWA1ca; arc=none smtp.client-ip=209.85.128.42 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="VzwWA1ca" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4779a4fc916so93215e9.1 for ; Mon, 24 Nov 2025 04:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763987935; x=1764592735; 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=+hKcjz4CEQtKu1cZ8SM9PbIexDlVU/R+LQLODvCo9Dg=; b=VzwWA1caUj0gMTgIN/oEIhOGaEbPxawRlAyBH0ayg7ykTp+Q0aKSiNhgvVAjZjwJgd RQU9RcAcBlNxNxWX1YmpjLUK+Fq357pw7YZl6CvEYOiSbRNCDPIqkxd6m45a+mQAuuwf HtzzJrT5JuUXXs++hvutGUv+jCbOjy+mqf0C1SOo4W3JpiD1vAXulRgSZCnrNrckbbSR FeBSB+gbnt+r0AuO5kV5kqjRCH5oHJVDPRJ2O3LY2A3BJxgeQCOkEGbu0YPybXc3xleB B4iitT8ee/TggLV2Vd1cODfaAUEU7tPxwVIQaBXCGxAEY13GVs6vglWSaeJEuW7Bi7gi GjiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763987935; x=1764592735; 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=+hKcjz4CEQtKu1cZ8SM9PbIexDlVU/R+LQLODvCo9Dg=; b=tvEB75nw6F7AQRoC4Coge8Bl/RBRHH26k5P5LO51TEI96KR/VfZkihV2nrtfeD4xJT cLWwUBX/PRqxr5E1jc20sSwJUmUmyn4LE8ubyoqoR2+RBjdP0306yh+p/YtXQIyGFQvt oYM7frJ88GyVurAFgd97W0lOWEmHV0wE5uOjfqQK4Lw0qkTv71cczGXplQR1rXcrrx0l aLihKZIcvPrZMB5e5ubi+w5nA5FNZykEbEd6/ab7E9anYAnU+zw3gX08s7O8UApTj9KV 1sV85uPHolBaDqYb59Wlb2nuXtlM3/gBLQ4wIJvJx63NOw4xcdGSFAft9bsRiNQ+9vP3 Ij6A== X-Forwarded-Encrypted: i=1; AJvYcCX3erLgSMrlLNyVid0ctSn5E6IAdbrBP5v9M8/IsdFB29613jkYaNh/Nzec0hJ9RVAd9pHqwsTVpq9wtNc=@vger.kernel.org X-Gm-Message-State: AOJu0YxCVcgYDQTWuI7GDpKPY1XRHPWhyZvtuOa+xB4xA1zBIOmk0xqL JwScjh7JRhtzsiKCBHu1cb54aufj1UQ+kSjoYmlNKb3nIrImqFxrR9l6pLVy8/VXuw== X-Gm-Gg: ASbGncswAaTgtNQGu+zGGum5AWPV9BqVTdj8CXyDhenogJDn37+66FebmpBq6UA8hHM APW3xFeqc2rZWlbC0SY/Of6H/DHluSwqchwi7cBr+Mp3y70ebXlFmhZgX1IkzNzX17ZLfcigKBN H2o9S9OoTJzutGLTYDaW/fMTUZG9/SAaRESpXP6JNdhYF4aAJU9G4rh36emKb7hczdeal6n4IDE mza+566ScqFSZb6pTE2/wLtvgIxES7c4J6ZrMmcpuUIlb1d4+oALJgmUJBbIBbXwCWY1fs/VNHJ ubYBi7NsRvtVNTnmF3NABTzhv0vo8rNvncVrC8x6lOqdHxsiLkFKpKArm/qINi2JB3jlif+Ht3P 23I72nBc8iVaaTDUwJT9L06V5uYI2b2ChghMqI+lEYOE/AlNEK6pY1wYIsFJmeZqBlpQu++fJLR EQDtevq53Qq43xXQaWjgVFwomYdmW9w86NgRFGJPDKAuxNjL+78Q== X-Google-Smtp-Source: AGHT+IEZgUg1bUbdAI5VMl92UmNgBFeGgbcBg9hYsUoLQBWM96FEzs3PepDjVAB17q+bUwBOhS6TRA== X-Received: by 2002:a05:600c:8a8:b0:477:86fd:fb48 with SMTP id 5b1f17b1804b1-477c5e9b0e9mr810065e9.9.1763987935133; Mon, 24 Nov 2025 04:38:55 -0800 (PST) Received: from google.com (54.140.140.34.bc.googleusercontent.com. [34.140.140.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7f34fddsm29238614f8f.14.2025.11.24.04.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Nov 2025 04:38:54 -0800 (PST) Date: Mon, 24 Nov 2025 12:38:50 +0000 From: Mostafa Saleh To: Will Deacon 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 Subject: Re: [PATCH v2 4/4] drivers/iommu-debug-pagealloc: Check mapped/unmapped kernel memory Message-ID: References: <20251106163953.1971067-1-smostafa@google.com> <20251106163953.1971067-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 Thu, Nov 13, 2025 at 10:59:57AM +0000, Will Deacon wrote: > On Thu, Nov 06, 2025 at 04:39:53PM +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. > > > > Signed-off-by: Mostafa Saleh > > Tested-by: Qinxin Xia > > --- > > drivers/iommu/iommu-debug-pagealloc.c | 19 +++++++++++++++++++ > > include/linux/iommu-debug-pagealloc.h | 12 ++++++++++++ > > include/linux/mm.h | 5 +++++ > > 3 files changed, 36 insertions(+) > > > > diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c > > index 0e14104b971c..5b26c84d3a0e 100644 > > --- a/drivers/iommu/iommu-debug-pagealloc.c > > +++ b/drivers/iommu/iommu-debug-pagealloc.c > > @@ -71,6 +71,25 @@ static size_t iommu_debug_page_size(struct iommu_domain *domain) > > return 1UL << __ffs(domain->pgsize_bitmap); > > } > > > > +static unsigned int iommu_debug_page_count(unsigned long phys) > > 'phys_addr_t phys' ? > > But having said that, wouldn't you be better off taking the > 'struct page *' here rather than converting it to a physical address > only for get_iommu_page_ext() to convert it straight back again? Will do, we will need the physical address anyway for the error message. > > > +{ > > + unsigned int ref; > > + struct page_ext *page_ext = get_iommu_page_ext(phys); > > + struct iommu_debug_metadate *d = get_iommu_data(page_ext); > > + > > + ref = atomic_read(&d->ref); > > + page_ext_put(page_ext); > > + return ref; > > +} > > + > > +void __iommu_debug_check_unmapped(const struct page *page, int numpages) > > +{ > > + while (numpages--) { > > + WARN_ON(iommu_debug_page_count(page_to_phys(page))); > > Since you only care about the count being non-zero, perhaps tweak > iommu_debug_page_count() to be something like: > > bool iommu_debug_page_referenced(struct page *); > Will do. Thanks, Mostafa > Will