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

Configure Feed

Select the types of activity you want to include in your feed.

mm: move vma_kernel_pagesize() from hugetlb to mm.h

Patch series "mm: move vma_(kernel|mmu)_pagesize() out of hugetlb.c", v2.

Looking into vma_(kernel|mmu)_pagesize(), I realized that there is one
scenario where DAX would not do the right thing when the kernel is not
compiled with hugetlb support.

Without hugetlb support, vma_(kernel|mmu)_pagesize() will always return
PAGE_SIZE instead of using the ->pagesize() result provided by dax-device
code.

Fix that by moving vma_kernel_pagesize() to core MM code, where it
belongs. I don't think this is stable material, but am not 100% sure.

Also, move vma_mmu_pagesize() while at it. Remove the unnecessary
hugetlb.h inclusion from KVM code.


This patch (of 4):

In the past, only hugetlb had special "vma_kernel_pagesize()"
requirements, so it provided its own implementation.

In commit 05ea88608d4e ("mm, hugetlbfs: introduce ->pagesize() to
vm_operations_struct") we generalized that approach by providing a
vm_ops->pagesize() callback to be used by device-dax.

Once device-dax started using that callback in commit c1d53b92b95c
("device-dax: implement ->pagesize() for smaps to report MMUPageSize") it
was missed that CONFIG_DEV_DAX does not depend on hugetlb support.

So building a kernel with CONFIG_DEV_DAX but without CONFIG_HUGETLBFS
would not pick up that value.

Fix it by moving vma_kernel_pagesize() to mm.h, providing only a single
implementation. While at it, improve the kerneldoc a bit.

Ideally, we'd move vma_mmu_pagesize() as well to the header. However, its
__weak symbol might be overwritten by a PPC variant in hugetlb code. So
let's leave it in there for now, as it really only matters for some
hugetlb oddities.

This was found by code inspection.

Link: https://lkml.kernel.org/r/20260309151901.123947-1-david@kernel.org
Link: https://lkml.kernel.org/r/20260309151901.123947-2-david@kernel.org
Fixes: c1d53b92b95c ("device-dax: implement ->pagesize() for smaps to report MMUPageSize")
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: Jann Horn <jannh@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand (Arm) and committed by
Andrew Morton
341ffe82 1eba4c95

+20 -24
-7
include/linux/hugetlb.h
··· 777 777 return (unsigned long)PAGE_SIZE << h->order; 778 778 } 779 779 780 - extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma); 781 - 782 780 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma); 783 781 784 782 static inline unsigned long huge_page_mask(struct hstate *h) ··· 1173 1175 static inline unsigned long huge_page_mask(struct hstate *h) 1174 1176 { 1175 1177 return PAGE_MASK; 1176 - } 1177 - 1178 - static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma) 1179 - { 1180 - return PAGE_SIZE; 1181 1178 } 1182 1179 1183 1180 static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
+20
include/linux/mm.h
··· 1351 1351 return is_shared_maywrite(&vma->flags); 1352 1352 } 1353 1353 1354 + /** 1355 + * vma_kernel_pagesize - Default page size granularity for this VMA. 1356 + * @vma: The user mapping. 1357 + * 1358 + * The kernel page size specifies in which granularity VMA modifications 1359 + * can be performed. Folios in this VMA will be aligned to, and at least 1360 + * the size of the number of bytes returned by this function. 1361 + * 1362 + * The default kernel page size is not affected by Transparent Huge Pages 1363 + * being in effect. 1364 + * 1365 + * Return: The default page size granularity for this VMA. 1366 + */ 1367 + static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma) 1368 + { 1369 + if (unlikely(vma->vm_ops && vma->vm_ops->pagesize)) 1370 + return vma->vm_ops->pagesize(vma); 1371 + return PAGE_SIZE; 1372 + } 1373 + 1354 1374 static inline 1355 1375 struct vm_area_struct *vma_find(struct vma_iterator *vmi, unsigned long max) 1356 1376 {
-17
mm/hugetlb.c
··· 1017 1017 (vma->vm_pgoff >> huge_page_order(h)); 1018 1018 } 1019 1019 1020 - /** 1021 - * vma_kernel_pagesize - Page size granularity for this VMA. 1022 - * @vma: The user mapping. 1023 - * 1024 - * Folios in this VMA will be aligned to, and at least the size of the 1025 - * number of bytes returned by this function. 1026 - * 1027 - * Return: The default size of the folios allocated when backing a VMA. 1028 - */ 1029 - unsigned long vma_kernel_pagesize(struct vm_area_struct *vma) 1030 - { 1031 - if (vma->vm_ops && vma->vm_ops->pagesize) 1032 - return vma->vm_ops->pagesize(vma); 1033 - return PAGE_SIZE; 1034 - } 1035 - EXPORT_SYMBOL_GPL(vma_kernel_pagesize); 1036 - 1037 1020 /* 1038 1021 * Return the page size being used by the MMU to back a VMA. In the majority 1039 1022 * of cases, the page size used by the kernel matches the MMU size. On