From nobody Wed Feb 11 04:17:17 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 673BD3A4F26 for ; Wed, 14 Jan 2026 16:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768409014; cv=none; b=MpensgJU0Zqo0H/vJYsKOZd4sKHQx9XNYChz6/8V2fp2HKGxrIf/Crl/0Vhz7C5ZIulsxILr0y7Ph++9qbSBtr3av2VEgua664A6rOKPS3T86G/SR14vwTZRfBDDbrlk8NS5lmVaI34p86Zhi+j35hFAvGhfTbvYPvLVq7BgyC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768409014; c=relaxed/simple; bh=7BYRgRnhfN3fHr35Z4lIewD7nb4bdgg7dJRSYUFPl2k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=khlw8cNcwams5sMGu05qnT9YHSYF/5iP2IJ96E3OZrKOVLGSJvBpH2z9znC6QzY8q2fRPR7WLhaLWgusTNLoUxWIA/73xxmigxcIccZd6ZMfi724hbnjbICzCstJm2AMGw+pLsLMR0fIL9BfPKHsRn5SAg72p8KNMJEzmciDwGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=iCmITmYz; arc=none smtp.client-ip=209.85.128.74 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=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iCmITmYz" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-47d1622509eso163395e9.3 for ; Wed, 14 Jan 2026 08:43:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768409011; x=1769013811; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NagltRQpX2SlKWY3/YB/PdnajjFmvEiNKHSf6/veCZ0=; b=iCmITmYzBFUH9gYHFUZPjgDr1WAUBC4PkanBW9XOw9HBQEr0Fd7MGoISiB+V+LCw7h Z8HyT6dFWF3lNxxflP1tJaoaW08cO61FsOmtT/adxI4vRkv+Xj+YSSdQ8aSlbF78HQYt orEyr4M17eirungbI6dkPTXCWFRY9/QOR2dcsNUCHSvdvdcTZaphpSRjxoHaqmfwCiQR UFLUmsRgIBcAzXMa+XTAwdAVH31X/mNzkiC3BKhtZZgu11I0oNXkX2ZgwmTu0rXN8XZ4 ZsPEOCMVShMuzC76+3tcWs6gVqDsr9liXXa/pq+B4CUkZueVJg8oLoN7wLUh7efAFrEC sL3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768409011; x=1769013811; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NagltRQpX2SlKWY3/YB/PdnajjFmvEiNKHSf6/veCZ0=; b=ABZBDIB+W7mHJMRcSwXA4xkUj/vEa0zFGVrJYQViprz3Xa201QlatqYVdt9C5v1ZWU ZPUQPuKnWiGSpnt5u3OvU8s0g58l3T0ZpR+kWYem2PumN1rWfPTYXcsRdomGuUkD02GS OJNJinqzbKFkfq9dnmHS3uuk26uyUQnMzsRoPHaCPFSvqszEd5joBBarFoysReM60y5t H1J22Q38yM8230HQteUeUecOpvMvwJyyfRLMoAwnkPZC6NZXxtwd0Xkg/dWTSSLeUA3X zRgrmz6LBWBdgr+rZUwrFPEu/jSB648UGJOh7plvbBIE75lDiA1vk95cPWfoI2vYwh9Q DMjA== X-Forwarded-Encrypted: i=1; AJvYcCXwwFIjSDylLtN94sxNo/D8bir1+DDcg0V0rRGjv7PfjsgKZ3VlI5ThlfudfKoU9NJQTGiPPRXFy9Nsn10=@vger.kernel.org X-Gm-Message-State: AOJu0YyTdEemm3cG3Aatezd24pD/WkYCdhLXsgDqfwNwcjmDIqkpbBdQ QLhpFtoIMOYjSxeotTvpE6DKPrgNLkzhVkKzOqKleozitVoaIcgV8eUYVw44ZpJiQ4hDk6G7vBR Qc6wUFYq7uWagDw== X-Received: from wmbd23.prod.google.com ([2002:a05:600c:58d7:b0:477:9654:b44c]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8707:b0:477:7f4a:44b4 with SMTP id 5b1f17b1804b1-47ee33192c2mr42786345e9.1.1768409011069; Wed, 14 Jan 2026 08:43:31 -0800 (PST) Date: Wed, 14 Jan 2026 16:43:18 +0000 In-Reply-To: <20260114164322.787125-1-smostafa@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260114164322.787125-1-smostafa@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260114164322.787125-2-smostafa@google.com> Subject: [PATCH v7 1/5] mm/page_ext: Add page_ext_get_phys() From: Mostafa Saleh To: linux-mm@kvack.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: 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, Mostafa Saleh Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the next patches, IOMMU code will add data to page_ext. The IOMMU code would operate on physical addresses which can be outside of system RAM. Add a new function page_ext_get_phys() to abstract the logic of checking the address and returning the page_ext. Signed-off-by: Mostafa Saleh --- include/linux/page_ext.h | 6 ++++++ mm/page_ext.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index 76c817162d2f..bd373496e166 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -93,6 +93,7 @@ static inline bool page_ext_iter_next_fast_possible(unsig= ned long next_pfn) #endif =20 extern struct page_ext *page_ext_get(const struct page *page); +extern struct page_ext *page_ext_get_phys(phys_addr_t phys); extern void page_ext_put(struct page_ext *page_ext); extern struct page_ext *page_ext_lookup(unsigned long pfn); =20 @@ -215,6 +216,11 @@ static inline struct page_ext *page_ext_get(const stru= ct page *page) return NULL; } =20 +static inline struct page_ext *page_ext_get_phys(phys_addr_t phys) +{ + return NULL; +} + static inline void page_ext_put(struct page_ext *page_ext) { } diff --git a/mm/page_ext.c b/mm/page_ext.c index d7396a8970e5..95e8c40131b7 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -534,6 +534,29 @@ struct page_ext *page_ext_get(const struct page *page) return page_ext; } =20 +/** + * page_ext_get_phys() - Get the page_ext structure for a physical address. + * @phys: The physical address to query. + * + * This function safely gets the `struct page_ext` associated with a given + * physical address. It performs validation to ensure the address correspo= nds + * to a valid, online struct page before attempting to access it. + * It should return NULL for (MMIO, ZONE_DEVICE, holes, offline memory) + * + * Return: NULL if no page_ext exists for this physical address. + * Context: Any context. Caller may not sleep until they have called + * page_ext_put(). + */ +struct page_ext *page_ext_get_phys(phys_addr_t phys) +{ + struct page *page =3D pfn_to_online_page(__phys_to_pfn(phys)); + + if (!page) + return NULL; + + return page_ext_get(page); +} + /** * page_ext_put() - Working with page extended information is done. * @page_ext: Page extended information received from page_ext_get(). --=20 2.52.0.457.g6b5491de43-goog