]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: introduce and use vm_normal_page_pud()
authorDavid Hildenbrand <david@redhat.com>
Mon, 11 Aug 2025 11:26:30 +0000 (13:26 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:24:47 +0000 (17:24 -0700)
Let's introduce vm_normal_page_pud(), which ends up being fairly simple
because of our new common helpers and there not being a PUD-sized zero
folio.

Use vm_normal_page_pud() in folio_walk_start() to resolve a TODO,
structuring the code like the other (pmd/pte) cases.  Defer introducing
vm_normal_folio_pud() until really used.

Note that we can so far get PUDs with hugetlb, daxfs and PFNMAP entries.

Link: https://lkml.kernel.org/r/20250811112631.759341-11-david@redhat.com
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Juegren Gross <jgross@suse.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/mm.h
mm/memory.c
mm/pagewalk.c

index b626d1bacef523031df114a2396cdd1d374052f9..8ca7d2fa71343bd264675c3734787510213f5abb 100644 (file)
@@ -2360,6 +2360,8 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma,
                                  unsigned long addr, pmd_t pmd);
 struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
                                pmd_t pmd);
+struct page *vm_normal_page_pud(struct vm_area_struct *vma, unsigned long addr,
+               pud_t pud);
 
 void zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
                  unsigned long size);
index 78af3f243cee7330a85f80e6e110ab1779df2429..6f806bf3cc994b0d6fae1fdc840470a2c666b9e7 100644 (file)
@@ -809,6 +809,25 @@ struct folio *vm_normal_folio_pmd(struct vm_area_struct *vma,
                return page_folio(page);
        return NULL;
 }
+
+/**
+ * vm_normal_page_pud() - Get the "struct page" associated with a PUD
+ * @vma: The VMA mapping the @pud.
+ * @addr: The address where the @pud is mapped.
+ * @pud: The PUD.
+ *
+ * Get the "struct page" associated with a PUD. See __vm_normal_page()
+ * for details on "normal" and "special" mappings.
+ *
+ * Return: Returns the "struct page" if this is a "normal" mapping. Returns
+ *        NULL if this is a "special" mapping.
+ */
+struct page *vm_normal_page_pud(struct vm_area_struct *vma,
+               unsigned long addr, pud_t pud)
+{
+       return __vm_normal_page(vma, addr, pud_pfn(pud), pud_special(pud),
+                               pud_val(pud), PGTABLE_LEVEL_PUD);
+}
 #endif
 
 /**
index 648038247a8d288be3cb789d085bd5a0efb3e7e3..c6753d370ff4e57374fb8d89c49c68abbdf05edf 100644 (file)
@@ -902,23 +902,23 @@ struct folio *folio_walk_start(struct folio_walk *fw,
                fw->pudp = pudp;
                fw->pud = pud;
 
-               /*
-                * TODO: FW_MIGRATION support for PUD migration entries
-                * once there are relevant users.
-                */
-               if (!pud_present(pud) || pud_special(pud)) {
+               if (pud_none(pud)) {
                        spin_unlock(ptl);
                        goto not_found;
-               } else if (!pud_leaf(pud)) {
+               } else if (pud_present(pud) && !pud_leaf(pud)) {
                        spin_unlock(ptl);
                        goto pmd_table;
+               } else if (pud_present(pud)) {
+                       page = vm_normal_page_pud(vma, addr, pud);
+                       if (page)
+                               goto found;
                }
                /*
-                * TODO: vm_normal_page_pud() will be handy once we want to
-                * support PUD mappings in VM_PFNMAP|VM_MIXEDMAP VMAs.
+                * TODO: FW_MIGRATION support for PUD migration entries
+                * once there are relevant users.
                 */
-               page = pud_page(pud);
-               goto found;
+               spin_unlock(ptl);
+               goto not_found;
        }
 
 pmd_table: