Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: introduce and use vm_normal_page_pud()

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>

authored by

David Hildenbrand and committed by
Andrew Morton
2db30816 af385388

+34 -13
+2
include/linux/mm.h
··· 2360 2360 unsigned long addr, pmd_t pmd); 2361 2361 struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, 2362 2362 pmd_t pmd); 2363 + struct page *vm_normal_page_pud(struct vm_area_struct *vma, unsigned long addr, 2364 + pud_t pud); 2363 2365 2364 2366 void zap_vma_ptes(struct vm_area_struct *vma, unsigned long address, 2365 2367 unsigned long size);
+19
mm/memory.c
··· 809 809 return page_folio(page); 810 810 return NULL; 811 811 } 812 + 813 + /** 814 + * vm_normal_page_pud() - Get the "struct page" associated with a PUD 815 + * @vma: The VMA mapping the @pud. 816 + * @addr: The address where the @pud is mapped. 817 + * @pud: The PUD. 818 + * 819 + * Get the "struct page" associated with a PUD. See __vm_normal_page() 820 + * for details on "normal" and "special" mappings. 821 + * 822 + * Return: Returns the "struct page" if this is a "normal" mapping. Returns 823 + * NULL if this is a "special" mapping. 824 + */ 825 + struct page *vm_normal_page_pud(struct vm_area_struct *vma, 826 + unsigned long addr, pud_t pud) 827 + { 828 + return __vm_normal_page(vma, addr, pud_pfn(pud), pud_special(pud), 829 + pud_val(pud), PGTABLE_LEVEL_PUD); 830 + } 812 831 #endif 813 832 814 833 /**
+13 -13
mm/pagewalk.c
··· 902 902 fw->pudp = pudp; 903 903 fw->pud = pud; 904 904 905 + if (pud_none(pud)) { 906 + spin_unlock(ptl); 907 + goto not_found; 908 + } else if (pud_present(pud) && !pud_leaf(pud)) { 909 + spin_unlock(ptl); 910 + goto pmd_table; 911 + } else if (pud_present(pud)) { 912 + page = vm_normal_page_pud(vma, addr, pud); 913 + if (page) 914 + goto found; 915 + } 905 916 /* 906 917 * TODO: FW_MIGRATION support for PUD migration entries 907 918 * once there are relevant users. 908 919 */ 909 - if (!pud_present(pud) || pud_special(pud)) { 910 - spin_unlock(ptl); 911 - goto not_found; 912 - } else if (!pud_leaf(pud)) { 913 - spin_unlock(ptl); 914 - goto pmd_table; 915 - } 916 - /* 917 - * TODO: vm_normal_page_pud() will be handy once we want to 918 - * support PUD mappings in VM_PFNMAP|VM_MIXEDMAP VMAs. 919 - */ 920 - page = pud_page(pud); 921 - goto found; 920 + spin_unlock(ptl); 921 + goto not_found; 922 922 } 923 923 924 924 pmd_table: