From nobody Thu Apr 2 01:53:34 2026 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 EF60B352C5C for ; Wed, 11 Feb 2026 19:52:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770839570; cv=none; b=B9H8l5zXUgNzqCYJHQdslgSWRiV91qLf3J4s+1AjQLeShEtAcXfqeqPEv2SZSjx2/ip4sO1FJXsPXT75qDqaTtA8bSm2iR+lf2G7rK5KRuNv28qwrjudIL0M+jMp2YuaFUGoLDZoRC+nzCAjbvrgcK3uF8/6yxA0idC91Rp3y7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770839570; c=relaxed/simple; bh=kVNFmmhEA/18Yty/d1sA6KBeNN2ApPvD66j4ouN24bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n51OXn9SXx8yZeel1Ss3MKKLd9IgCSsCDWo9IYdIy0REA2X00MIYiLqCRr851McWked+zhT8cFoFOqxgTagHk+4IvAboWaGbUOrCD3kIyTdldov9wCYx/PGB/nMv27WAnYUsPuD/nsF1ignn52gqhOAs3pEkE6HSInLryJZOIN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V8nQqbGB; arc=none smtp.client-ip=74.125.82.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V8nQqbGB" Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-2b86ce04c5cso517057eec.1 for ; Wed, 11 Feb 2026 11:52:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770839566; x=1771444366; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PW0O7GWcMWLn2TYy5yKCekih8BmMZppbzDUWkPTzKZs=; b=V8nQqbGB7uwQSwHcAVvehHMCgpmU8jMerkCTu36zSc1djh2j941nf2q7+RmaWNJzX4 lO/hfzagLpSQnTIyloUKuaK3YG+77pT+PwSVKgIuq49vzJZcn6s832S7WqA9zRQIiRgm NjO2zt+LRqwmC3lJx5R6t/ZFOGXv7zwmDBF2+8yNq5XQHl/rtUm0FrqtmFn+lw1u9AGJ bImzLcT8SB1ae1DnwUljvGv7MbIfBR78ebeaijxvqkdYds9eejXEW+liDxsVKa41uEMU wVo76r4xWgQjVR17WFeDiPBVtMWd/rKob0u6/uVpbAUyBiyAFk0yV1quWrfyOX2JqOOv pG7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770839567; x=1771444367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PW0O7GWcMWLn2TYy5yKCekih8BmMZppbzDUWkPTzKZs=; b=PmhTzzg1QF3mhuA0W+O7RLZ2Fh790DmkxLMOtQeNv9aVE4edF1xGZSaPUMlBs6nCN8 +7ogJMKC9PA3GPDOWFpLUlR/b8NVV0I+lc1tdiP8Jp89N3M1BDynk3lUaY2tsJ8C2n8m MT4ND3X9KGDS2j0Oueus5udR83iYfRx5TYRjXWyrAtIzYj76fEcx0MzfQk8hxe7yoOOW Oh1W3GCxYmUocX3MgWyA3bsp03qK8Q5+r+vYYQ2lO2i/mJDGWHHAdGS+KP3OejxL4+6S dISfo04NwRpfe65vfZktLQXbWJQbL6E0XKWHhijsnPC+eVXfzM0Vr2M5X/xxZjdPq8rE DJvw== X-Gm-Message-State: AOJu0Yzgwb+sIT20Q9vYaUszKT4MUAphCphcEhAk3lOC+dW7Y2pJyUas mCvm+UweLX5AkOiPj1qvOd9TfkDBRIOVP5ahDVYSI0xXV0lu/4XY4QEh8YruWw== X-Gm-Gg: AZuq6aKpLqD2xPQVWajr9rMUpWmzjmT37kdglM503w3sn8U/umy6h7qLxy3ersfqv2u IO8JuPJx6Imxcu3QIa6X/xTVRT1V+LgW/DlAJTF/jRJVwU9D+rd5weBxOAyZ22FoMApUi4CpoWs DbmH3wGTTq3ck1K+YxydKRCglrxdAOt8Evkap1xsNrJWZXI22NJJ8epHMaF2P/0uDJ8raAzTqGg KdTVKyLAtdEtU2CbOTDe+YMFXzcy8MZzeybZbDqlXnIXntz4dHWS2jdH6hOGonME+NE10yx8o41 ImFBpPZfKx1ElMSjpei04aqmDaetH3BgwXUpjOUe6ppL9cRq64cjy3Zlph2GHOdxARVl95eanYP 9EqufdF7U1xKM/wwaxFFYYzuI8nn7Kyiaf1hGg2ECcDA55FO0vKF2u+OGXH1vuEPcOV4uTTg+zf dnEOpg6RnLlpIQ4qdJCaWaS3+u2NPX/yqmzvE/5gx+Dam0yZGkyqROOMBe6KEeyO8ivg== X-Received: by 2002:a05:7300:7ba0:b0:2b7:12f8:5eea with SMTP id 5a478bee46e88-2baa7f682f7mr297764eec.9.1770839566550; Wed, 11 Feb 2026 11:52:46 -0800 (PST) Received: from fedora (c-67-164-59-41.hsd1.ca.comcast.net. [67.164.59.41]) by smtp.googlemail.com with ESMTPSA id 5a478bee46e88-2ba9dcfe6b7sm2426463eec.29.2026.02.11.11.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 11:52:45 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, "Mike Rapoport (Microsoft)" Cc: akpm@linux-foundation.org, "Matthew Wilcox (Oracle)" , Dave Hansen , Andy Lutomirski , Peter Zijlstra , "Vishal Moola (Oracle)" , Dave Hansen Subject: [PATCH v5 1/4] mm: Add address apis for ptdescs Date: Wed, 11 Feb 2026 11:52:30 -0800 Message-ID: <20260211195233.368497-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260211195233.368497-1-vishal.moola@gmail.com> References: <20260211195233.368497-1-vishal.moola@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Architectures frequently only care about the address associated with a page table. The current ptdesc api forced callers to acquire a ptdesc to use them. Add more apis to abstract ptdescs away from architectures that don't need the descriptor. Add pgtable_alloc_addr() and pgtable_free_addr() to operate on the underlying addresses associated with page table descriptors, similar to get_free_pages() and free_pages(). Zero the allocations since theres no reason to want a page table with stale data. Have pgtable_alloc_addr() return a void pointer. This will simplify code for callers since they all want pointers. Suggested-by: Dave Hansen Signed-off-by: Vishal Moola (Oracle) --- include/linux/mm.h | 4 ++++ mm/memory.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index f8a8fd47399c..9b6d3d910990 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3419,6 +3419,10 @@ static inline void __pagetable_free(struct ptdesc *p= t) __free_pages(page, compound_order(page)); } =20 +void *pgtable_alloc_addr_noprof(gfp_t gfp, unsigned int order); +#define pgtable_alloc_addr(...) alloc_hooks(pgtable_alloc_addr_noprof(= __VA_ARGS__)) +void pgtable_free_addr(const void *addr); + #ifdef CONFIG_ASYNC_KERNEL_PGTABLE_FREE void pagetable_free_kernel(struct ptdesc *pt); #else diff --git a/mm/memory.c b/mm/memory.c index 1a26947ed8cd..b9653377d647 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -7452,6 +7452,40 @@ long copy_folio_from_user(struct folio *dst_folio, } #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */ =20 +/** + * pgtable_alloc_addr - Allocate pagetables to get an address + * @gfp: GFP flags + * @order: desired pagetable order + * + * pgtable_alloc_addr is like pagetable_alloc. This is for callers who onl= y want a + * page table's address, not its ptdesc. + * + * Return: The address associated with the allocated page table, or 0 on + * failure. + */ +void *pgtable_alloc_addr_noprof(gfp_t gfp, unsigned int order) +{ + struct ptdesc *ptdesc =3D pagetable_alloc_noprof(gfp | __GFP_ZERO, order); + + if (!ptdesc) + return 0; + return ptdesc_address(ptdesc); +} + +/** + * pgtable_free_addr - Free pagetables by address + * @addr: The virtual address from pgtable_alloc() + * + * This function is for callers who have the address but no ptdesc. If you + * have the ptdesc, use pagetable_free() instead. + */ +void pgtable_free_addr(const void *addr) +{ + struct ptdesc *ptdesc =3D virt_to_ptdesc(addr); + + pagetable_free(ptdesc); +} + #if defined(CONFIG_SPLIT_PTE_PTLOCKS) && ALLOC_SPLIT_PTLOCKS =20 static struct kmem_cache *page_ptl_cachep; --=20 2.52.0