[RFC PATCH 2/2] mm/pgtable: convert pgtable_trans_huge_withdraw to ptdesc

alexs
2025-12-14T06:56:30Z

From: Alex Shi <alexs@kernel.org>

Following the last function change in pgtable_trans_huge_deposit().
this time we convert the return value for pgtable_trans_huge_withdraw()

In future, we could do further to convert more pgtable_t to ptdesc
struct and then replace the pgtable_t to ptdesc* except s390/powerpc/sparc
archs.

Signed-off-by: Alex Shi <alexs@kernel.org>
Cc: linux-mm@kvack.org
Cc: sparclinux@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: Juergen Gross <jgross@suse.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Magnus Lindholm <linmag7@gmail.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Barry Song <baohua@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Nico Pache <npache@redhat.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Christophe Leroy <chleroy@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
---
arch/powerpc/include/asm/book3s/64/pgtable.h | 8 ++++----
arch/s390/include/asm/pgtable.h | 2 +-
arch/s390/mm/pgtable.c | 4 ++--
arch/sparc/include/asm/pgtable_64.h | 2 +-
arch/sparc/mm/tlb.c | 4 ++--
include/linux/pgtable.h | 3 ++-
mm/huge_memory.c | 15 +++++++--------
mm/pgtable-generic.c | 4 ++--
8 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h
index f10736af296d..3485de5178b5 100644
--- a/arch/powerpc/include/asm/book3s/64/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/64/pgtable.h
@@ -1328,12 +1328,12 @@ static inline void pgtable_trans_huge_deposit(struct mm_struct *mm,
}

#define __HAVE_ARCH_PGTABLE_WITHDRAW
-static inline pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm,
- pmd_t *pmdp)
+static inline struct ptdesc *pgtable_trans_huge_withdraw(struct mm_struct *mm,
+ pmd_t *pmdp)
{
if (radix_enabled())
- return radix__pgtable_trans_huge_withdraw(mm, pmdp);
- return hash__pgtable_trans_huge_withdraw(mm, pmdp);
+ return page_ptdesc(radix__pgtable_trans_huge_withdraw(mm, pmdp));
+ return page_ptdesc(hash__pgtable_trans_huge_withdraw(mm, pmdp));
}

#define __HAVE_ARCH_PMDP_INVALIDATE
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index e45cb52a923a..5f7fab7b121b 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1754,7 +1754,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
struct ptdesc *pgtable);

#define __HAVE_ARCH_PGTABLE_WITHDRAW
-pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
+struct ptdesc *pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);

#define __HAVE_ARCH_PMDP_SET_ACCESS_FLAGS
static inline int pmdp_set_access_flags(struct vm_area_struct *vma,
diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index c301af71b3ec..6e53a30dd3ae 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -534,7 +534,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
pmd_huge_pte(mm, pmdp) = pgtable;
}

-pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
+struct ptdesc *pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
{
struct list_head *lh;
pgtable_t pgtable;
@@ -555,7 +555,7 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
set_pte(ptep, __pte(_PAGE_INVALID));
ptep++;
set_pte(ptep, __pte(_PAGE_INVALID));
- return pgtable;
+ return page_ptdesc(pgtable);
}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
index 4b7f7113a1b3..29fc86175300 100644
--- a/arch/sparc/include/asm/pgtable_64.h
+++ b/arch/sparc/include/asm/pgtable_64.h
@@ -995,7 +995,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
struct ptdesc *pgtable);

#define __HAVE_ARCH_PGTABLE_WITHDRAW
-pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
+struct ptdesc *pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
#endif

/*
diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
index 5dfee57d2440..8b00b62c06bd 100644
--- a/arch/sparc/mm/tlb.c
+++ b/arch/sparc/mm/tlb.c
@@ -284,7 +284,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
pmd_huge_pte(mm, pmdp) = pgtable;
}

-pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
+struct ptdesc *pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
{
struct list_head *lh;
pgtable_t pgtable;
@@ -303,6 +303,6 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
pte_val(pgtable[0]) = 0;
pte_val(pgtable[1]) = 0;

- return pgtable;
+ return page_ptdesc(pgtable);
}
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index a5b1e3f7452a..4b20b3d7aaec 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1021,7 +1021,8 @@ extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
#endif

#ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
-extern pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
+extern struct ptdesc *pgtable_trans_huge_withdraw(struct mm_struct *mm,
+ pmd_t *pmdp);
#endif

#ifndef arch_needs_pgtable_deposit
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index ff74bd70690d..6f6cdb3ae888 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2334,7 +2334,7 @@ static inline void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd)
{
pgtable_t pgtable;

- pgtable = pgtable_trans_huge_withdraw(mm, pmd);
+ pgtable = ptdesc_page(pgtable_trans_huge_withdraw(mm, pmd));
pte_free(mm, pgtable);
mm_dec_nr_ptes(mm);
}
@@ -2492,10 +2492,9 @@ bool move_huge_pmd(struct vm_area_struct *vma, unsigned long old_addr,
VM_BUG_ON(!pmd_none(*new_pmd));

if (pmd_move_must_withdraw(new_ptl, old_ptl, vma)) {
- pgtable_t pgtable;
+ struct ptdesc *pgtable;
pgtable = pgtable_trans_huge_withdraw(mm, old_pmd);
- pgtable_trans_huge_deposit(mm, new_pmd,
- page_ptdesc(pgtable));
+ pgtable_trans_huge_deposit(mm, new_pmd, pgtable);
}
pmd = move_soft_dirty_pmd(pmd);
if (vma_has_uffd_without_event_remap(vma))
@@ -2710,7 +2709,7 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm
struct page *src_page;
struct folio *src_folio;
spinlock_t *src_ptl, *dst_ptl;
- pgtable_t src_pgtable;
+ struct ptdesc *src_pgtable;
struct mmu_notifier_range range;
int err = 0;

@@ -2801,7 +2800,7 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm
set_pmd_at(mm, dst_addr, dst_pmd, _dst_pmd);

src_pgtable = pgtable_trans_huge_withdraw(mm, src_pmd);
- pgtable_trans_huge_deposit(mm, dst_pmd, page_ptdesc(src_pgtable));
+ pgtable_trans_huge_deposit(mm, dst_pmd, src_pgtable);
unlock_ptls:
double_pt_unlock(src_ptl, dst_ptl);
/* unblock rmap walks */
@@ -2962,7 +2961,7 @@ static void __split_huge_zero_page_pmd(struct vm_area_struct *vma,
*/
old_pmd = pmdp_huge_clear_flush(vma, haddr, pmd);

- pgtable = pgtable_trans_huge_withdraw(mm, pmd);
+ pgtable = ptdesc_page(pgtable_trans_huge_withdraw(mm, pmd));
pmd_populate(mm, &_pmd, pgtable);

pte = pte_offset_map(&_pmd, haddr);
@@ -3169,7 +3168,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
* Withdraw the table only after we mark the pmd entry invalid.
* This's critical for some architectures (Power).
*/
- pgtable = pgtable_trans_huge_withdraw(mm, pmd);
+ pgtable = ptdesc_page(pgtable_trans_huge_withdraw(mm, pmd));
pmd_populate(mm, &_pmd, pgtable);

pte = pte_offset_map(&_pmd, haddr);
diff --git a/mm/pgtable-generic.c b/mm/pgtable-generic.c
index 220844a81e38..a95d9309215e 100644
--- a/mm/pgtable-generic.c
+++ b/mm/pgtable-generic.c
@@ -179,7 +179,7 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,

#ifndef __HAVE_ARCH_PGTABLE_WITHDRAW
/* no "address" argument so destroys page coloring of some arch */
-pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
+struct ptdesc *pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
{
struct ptdesc *pgtable;

@@ -191,7 +191,7 @@ pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp)
struct ptdesc, pt_list);
if (pmd_huge_pte(mm, pmdp))
list_del(&pgtable->pt_list);
- return ptdesc_page(pgtable);
+ return pgtable;
}
#endif

--
2.43.0