From nobody Sun Feb 8 08:22:22 2026 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 A758037418B for ; Mon, 19 Jan 2026 14:22:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768832575; cv=none; b=flUxsLl4Ag72gcPkd6P5MSSzdMh4J/pV0w81ETpRII4gpcgjwKUmy29TC0O0pcA/nzLlRCqlMsEncVOyYDagOVNsZCp1SxR6RaliYyn5D6uV5g5J5VEs//eRKPthleQTTsbwezdb5fqdpMn/sM9UC+mc4AGHjNsgsO09ABfK5Xs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768832575; c=relaxed/simple; bh=w2scubrWigPI5aAVKJGSmibtcgc4McVhvAh8XisAp4w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FXkLq+auLuUb5kPQLR8tycuYUsBZMRiPCeoB/5I7zGQo0wDsDLDpeRvdHFDU26ypeF7oHxCydMq5u05SiNVz2ubg3vI6MC8DCIHssBwEFOKKVKDxgNhluVpI6zUZi0xdL/W17rHH3Czmt9EnP55YiBkvjrEhCbbpfr8Lj5ju2To= 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=aPS2OMFK; arc=none smtp.client-ip=209.85.218.73 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="aPS2OMFK" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b876b03afc5so1039675166b.3 for ; Mon, 19 Jan 2026 06:22:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768832572; x=1769437372; 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=9nuz806mp9+5PhIDWKxO6w4brkXaM9E/Fe3SahLfIE4=; b=aPS2OMFKECv3ZXwqy1jrWAiupoUh08fCzLXss1JJnJxpddbdyeqUMD/T+73MrwikUT qjH0B0D/MwrT42RQ/nyJMoZohMH12Y9Ib0MorR2t0dEzn/71EJID+wqhn3e6mXVwBxp6 WaFgJJQs761Xzr49O/OXlGljDmNbO5hBrGUIbrfxmsw0mXOc4w9/xtNiXifPTsl+L1Dt a9LZtMDcfI//LlVztj4dR5f9xDxGkoorBlBfJoK64QWvCdeNsxGhwoCqFW78VrxEV2/B tlnBsVFTjubkEu6YY6N28JTkaw2IUoYy0nmZ7lMjmimlz9vLzPCTX2O6pmrcWd+/ZrEY skYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768832572; x=1769437372; 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=9nuz806mp9+5PhIDWKxO6w4brkXaM9E/Fe3SahLfIE4=; b=Zhl/cBmVvlkTiYRuai6EYsIvC7WYyPBIf7N1Qd7XdFW38TA6AbeipiO8+NLmvDHvua YLMPC5eWWkU/Lky1p39ty9mzmRKsqgSYFF8XF3mMNMmphg9AjjGqRWIMX0UGYxPQOm6s wRX5K4McPt6hKn5YX0uDDXBoJJEtO59ihAA3b2n9Axso+yz3zlixYmPcaS7MEtDbO0eg +ogfiC0CnpfNK0lqeAgfI2tZX4UHntlJP7vrdYuXeSJ41uTO2aKQG56oc6RurreZulMM p6jP3qagGFnJjumQuNj0l0L69lypDiz5v/31typTShgpY/O0o3HdZZGlJewCgx8YbkKr SiGw== X-Forwarded-Encrypted: i=1; AJvYcCX0Qd7CFMmKa3L1deFwcP/WBO3y3oJjVjE/NCATVVPeSVIX1QN2jKByhytoOr5BGbK86HgQFb//n2l+JV8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxr4FRDR5f5acNksvebFvk6NuAGhDkMU+VG5reeEs4svJkVWdIZ YAyCaUlPP0xzQPYXKGsRZFShKHOTpmzGP6ugKzJl/PY7LU+g4l8VunTQ2nWWgHADDYuGnIOtoYa ewTirKRmeLujU1g== X-Received: from edrb16.prod.google.com ([2002:aa7:d490:0:b0:650:5e46:20c]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:7ba5:b0:b87:191f:4f96 with SMTP id a640c23a62f3a-b87932557e2mr1034243266b.61.1768832572024; Mon, 19 Jan 2026 06:22:52 -0800 (PST) Date: Mon, 19 Jan 2026 14:22:45 +0000 In-Reply-To: <20260119142246.3821052-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: <20260119142246.3821052-1-smostafa@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260119142246.3821052-2-smostafa@google.com> Subject: [PATCH 1/2] 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 297e4cd8ce90..5fe65a0ac4f3 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -538,6 +538,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