Skip to contentSkip to conversation

mm: move vma_(kernel|mmu)_pagesize() out of hugetlb.c

PATCH Superseded David Hildenbrand (Arm) 5 participants 21 messages Mar 6 – Mar 10

Subsystems (7)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

David Hildenbrand (Arm)

author maintainer
#0 lore raw

cover mm: move vma_(kernel|mmu)_pagesize() out of hugetlb.c

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.

Cross-compiled heavily.

Cc Andrew Morton <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc "Christophe Leroy (CS GROUP)" <[email protected]>
Cc Muchun Song <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Jann Horn <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Dan Williams <[email protected]>

David Hildenbrand (Arm) (4):
mm: move vma_kernel_pagesize() from hugetlb to mm.h
mm: move vma_mmu_pagesize() from hugetlb to vma.c
KVM: remove hugetlb.h inclusion
KVM: PPC: remove hugetlb.h inclusion

 arch/powerpc/kvm/book3s_hv.c |  1 -
 include/linux/hugetlb.h      | 14 --------------
 include/linux/mm.h           | 22 ++++++++++++++++++++++
 mm/hugetlb.c                 | 28 ----------------------------
 mm/vma.c                     | 21 +++++++++++++++++++++
 virt/kvm/kvm_main.c          |  1 -
 6 files changed, 43 insertions(+), 44 deletions(-)

base-commit: f75825cdfc4c5477cffcfd2cafa4e5ce5aa67f13

Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/4 mm: move vma_kernel_pagesize() from hugetlb to mm.h

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.

Fixes c1d53b92b95c ("device-dax: implement ->pagesize() for smaps to report MMUPageSize")
Cc Dan Williams <[email protected]>
---
 include/linux/hugetlb.h |  7 -------
 include/linux/mm.h      | 20 ++++++++++++++++++++
 mm/hugetlb.c            | 17 -----------------
 3 files changed, 20 insertions(+), 24 deletions(-)
include/linux/hugetlb.h +0 -7
index 65910437be1c..44c1848a2c21 100644
@@ -777,8 +777,6 @@ static inline unsigned long huge_page_size(const struct hstate *h)
 	return (unsigned long)PAGE_SIZE << h->order;
 }
 
-extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
-
 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
 
 static inline unsigned long huge_page_mask(struct hstate *h)
@@ -1177,11 +1175,6 @@ static inline unsigned long huge_page_mask(struct hstate *h)
 	return PAGE_MASK;
 }
 
-static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
-{
-	return PAGE_SIZE;
-}
-
 static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
 {
 	return PAGE_SIZE;
include/linux/mm.h +20 -0
index 44e04a42fe77..227809790f1a 100644
@@ -1307,6 +1307,26 @@ static inline bool vma_is_shared_maywrite(const struct vm_area_struct *vma)
 	return is_shared_maywrite(&vma->flags);
 }
 
+/**
+ * vma_kernel_pagesize - Default page size granularity for this VMA.
+ * @vma: The user mapping.
+ *
+ * The kernel page size specifies in which granularity VMA modifications
+ * can be performed. Folios in this VMA will be aligned to, and at least
+ * the size of the number of bytes returned by this function.
+ *
+ * The default kernel page size is not affected by Transparent Huge Pages
+ * being in effect.
+ *
+ * Return: The default page size granularity for this VMA.
+ */
+static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
+{
+	if (unlikely(vma->vm_ops && vma->vm_ops->pagesize))
+		return vma->vm_ops->pagesize(vma);
+	return PAGE_SIZE;
+}
+
 static inline
 struct vm_area_struct *vma_find(struct vma_iterator *vmi, unsigned long max)
 {
mm/hugetlb.c +0 -17
index 1d41fa3dd43e..66eadfa9e958 100644
@@ -1017,23 +1017,6 @@ static pgoff_t vma_hugecache_offset(struct hstate *h,
 			(vma->vm_pgoff >> huge_page_order(h));
 }
 
-/**
- * vma_kernel_pagesize - Page size granularity for this VMA.
- * @vma: The user mapping.
- *
- * Folios in this VMA will be aligned to, and at least the size of the
- * number of bytes returned by this function.
- *
- * Return: The default size of the folios allocated when backing a VMA.
- */
-unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
-{
-	if (vma->vm_ops && vma->vm_ops->pagesize)
-		return vma->vm_ops->pagesize(vma);
-	return PAGE_SIZE;
-}
-EXPORT_SYMBOL_GPL(vma_kernel_pagesize);
-
 /*
  * Return the page size being used by the MMU to back a VMA. In the majority
  * of cases, the page size used by the kernel matches the MMU size. On
Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 2/4 mm: move vma_mmu_pagesize() from hugetlb to vma.c

In reply to David Hildenbrand (Arm)

vma_mmu_pagesize() is also queried on non-hugetlb VMAs and does not really belong into hugetlb.c.

PPC64 provides a custom overwrite with CONFIG_HUGETLB_PAGE, see arch/powerpc/mm/book3s64/slice.c, so we cannot easily make this a static inline function.

So let's move it to vma.c and add some proper kerneldoc.

---
 include/linux/hugetlb.h |  7 -------
 include/linux/mm.h      |  2 ++
 mm/hugetlb.c            | 11 -----------
 mm/vma.c                | 21 +++++++++++++++++++++
 4 files changed, 23 insertions(+), 18 deletions(-)
include/linux/hugetlb.h +0 -7
index 44c1848a2c21..aaf3d472e6b5 100644
@@ -777,8 +777,6 @@ static inline unsigned long huge_page_size(const struct hstate *h)
 	return (unsigned long)PAGE_SIZE << h->order;
 }
 
-extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
-
 static inline unsigned long huge_page_mask(struct hstate *h)
 {
 	return h->mask;
@@ -1175,11 +1173,6 @@ static inline unsigned long huge_page_mask(struct hstate *h)
 	return PAGE_MASK;
 }
 
-static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
-{
-	return PAGE_SIZE;
-}
-
 static inline unsigned int huge_page_order(struct hstate *h)
 {
 	return 0;
include/linux/mm.h +2 -0
index 227809790f1a..22d338933c84 100644
@@ -1327,6 +1327,8 @@ static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
 	return PAGE_SIZE;
 }
 
+unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
+
 static inline
 struct vm_area_struct *vma_find(struct vma_iterator *vmi, unsigned long max)
 {
mm/hugetlb.c +0 -11
index 66eadfa9e958..f6ecca9aae01 100644
@@ -1017,17 +1017,6 @@ static pgoff_t vma_hugecache_offset(struct hstate *h,
 			(vma->vm_pgoff >> huge_page_order(h));
 }
 
-/*
- * Return the page size being used by the MMU to back a VMA. In the majority
- * of cases, the page size used by the kernel matches the MMU size. On
- * architectures where it differs, an architecture-specific 'strong'
- * version of this symbol is required.
- */
-__weak unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
-{
-	return vma_kernel_pagesize(vma);
-}
-
 /*
  * Flags for MAP_PRIVATE reservations.  These are stored in the bottom
  * bits of the reservation map pointer, which are always clear due to
mm/vma.c +21 -0
index be64f781a3aa..e95fd5a5fe5c 100644
@@ -3300,3 +3300,24 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
 
 	return 0;
 }
+
+/**
+ * vma_mmu_pagesize - Default MMU page size granularity for this VMA.
+ * @vma: The user mapping.
+ *
+ * In the common case, the default page size used by the MMU matches the
+ * default page size used by the kernel (see vma_kernel_pagesize()). On
+ * architectures where it differs, an architecture-specific 'strong' version
+ * of this symbol is required.
+ *
+ * The default MMU page size is not affected by Transparent Huge Pages
+ * being in effect, or any usage of larger MMU page sizes (either through
+ * architectural huge-page mappings or other explicit/implicit coalescing of
+ * virtual ranges performed by the MMU).
+ *
+ * Return: The default MMU page size granularity for this VMA.
+ */
+__weak unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
+{
+	return vma_kernel_pagesize(vma);
+}
Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH 3/4 KVM: remove hugetlb.h inclusion

In reply to David Hildenbrand (Arm)

hugetlb.h is no longer required now that we moved vma_kernel_pagesize() to mm.h.

---
 virt/kvm/kvm_main.c | 1 -
 1 file changed, 1 deletion(-)
virt/kvm/kvm_main.c +0 -1
index 22f8a672e1fd..58059648b881 100644
@@ -41,7 +41,6 @@
 #include <linux/spinlock.h>
 #include <linux/compat.h>
 #include <linux/srcu.h>
-#include <linux/hugetlb.h>
 #include <linux/slab.h>
 #include <linux/sort.h>
 #include <linux/bsearch.h>
Signature · 1 line
2.43.0
author maintainer
#12 lore raw

PATCH 4/4 KVM: PPC: remove hugetlb.h inclusion

In reply to David Hildenbrand (Arm)

hugetlb.h is no longer required now that we moved vma_kernel_pagesize() to mm.h.

---
 arch/powerpc/kvm/book3s_hv.c | 1 -
 1 file changed, 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +0 -1
index 08e5816fdd61..61dbeea317f3 100644
@@ -36,7 +36,6 @@
 #include <linux/gfp.h>
 #include <linux/vmalloc.h>
 #include <linux/highmem.h>
-#include <linux/hugetlb.h>
 #include <linux/kvm_irqfd.h>
 #include <linux/irqbypass.h>
 #include <linux/module.h>
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH v1 1/4] mm: move vma_kernel_pagesize() from hugetlb to mm.h

In reply to David Hildenbrand (Arm)
Quoted 22 lines · David Hildenbrand (Arm)

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.

Quoted 5 lines

This was found by code inspection.

Fixes c1d53b92b95c ("device-dax: implement ->pagesize() for smaps to report MMUPageSize")
Cc Dan Williams <[email protected]>

LGTM, but you need to fix up VMA tests, I attach a patch below to do this. Will this resolved:

Quoted 91 lines
---
 include/linux/hugetlb.h |  7 -------
 include/linux/mm.h      | 20 ++++++++++++++++++++
 mm/hugetlb.c            | 17 -----------------
 3 files changed, 20 insertions(+), 24 deletions(-)
include/linux/hugetlb.h +0 -7
index 65910437be1c..44c1848a2c21 100644
@@ -777,8 +777,6 @@ static inline unsigned long huge_page_size(const struct hstate *h)
 	return (unsigned long)PAGE_SIZE << h->order;
 }
 
-extern unsigned long vma_kernel_pagesize(struct vm_area_struct *vma);
-
 extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
 
 static inline unsigned long huge_page_mask(struct hstate *h)
@@ -1177,11 +1175,6 @@ static inline unsigned long huge_page_mask(struct hstate *h)
 	return PAGE_MASK;
 }
 
-static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
-{
-	return PAGE_SIZE;
-}
-
 static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
 {
 	return PAGE_SIZE;
include/linux/mm.h +20 -0
index 44e04a42fe77..227809790f1a 100644
@@ -1307,6 +1307,26 @@ static inline bool vma_is_shared_maywrite(const struct vm_area_struct *vma)
 	return is_shared_maywrite(&vma->flags);
 }
 
+/**
+ * vma_kernel_pagesize - Default page size granularity for this VMA.
+ * @vma: The user mapping.
+ *
+ * The kernel page size specifies in which granularity VMA modifications
+ * can be performed. Folios in this VMA will be aligned to, and at least
+ * the size of the number of bytes returned by this function.
+ *
+ * The default kernel page size is not affected by Transparent Huge Pages
+ * being in effect.
+ *
+ * Return: The default page size granularity for this VMA.
+ */
+static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
+{
+	if (unlikely(vma->vm_ops && vma->vm_ops->pagesize))
+		return vma->vm_ops->pagesize(vma);
+	return PAGE_SIZE;
+}
+
 static inline
 struct vm_area_struct *vma_find(struct vma_iterator *vmi, unsigned long max)
 {
mm/hugetlb.c +0 -18
index 1d41fa3dd43e..66eadfa9e958 100644
@@ -1017,23 +1017,6 @@ static pgoff_t vma_hugecache_offset(struct hstate *h,
 			(vma->vm_pgoff >> huge_page_order(h));
 }
 
-/**
- * vma_kernel_pagesize - Page size granularity for this VMA.
- * @vma: The user mapping.
- *
- * Folios in this VMA will be aligned to, and at least the size of the
- * number of bytes returned by this function.
- *
- * Return: The default size of the folios allocated when backing a VMA.
- */
-unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
-{
-	if (vma->vm_ops && vma->vm_ops->pagesize)
-		return vma->vm_ops->pagesize(vma);
-	return PAGE_SIZE;
-}
-EXPORT_SYMBOL_GPL(vma_kernel_pagesize);
-
 /*
  * Return the page size being used by the MMU to back a VMA. In the majority
  * of cases, the page size used by the kernel matches the MMU size. On
--
Quoted 2 lines

2.43.0

----8<----
This breaks the VMA tests when patch 2/4 removes the references in other headers. So this patch should also update them, I enclose a simple fix for convenience:

From bec84895cbdbe28e3495c4d90e097074598419e5 Mon Sep 17 00:00:00 2001
From: "Lorenzo Stoakes (Oracle)" <[email protected]>
Date: Fri, 6 Mar 2026 11:05:12 +0000
Subject: [PATCH] fix

---
 tools/testing/vma/include/dup.h | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/vma/include/dup.h +7 -0
index 3078ff1487d3..65b1030a7fdf 100644
@@ -1318,3 +1318,10 @@ static inline void vma_set_file(struct vm_area_struct *vma, struct file *file)
 	swap(vma->vm_file, file);
 	fput(file);
 }
+
+static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
+{
+	if (unlikely(vma->vm_ops && vma->vm_ops->pagesize))
+		return vma->vm_ops->pagesize(vma);
+	return PAGE_SIZE;
+}

--
2.53.0

maintainer Reviewed-by on v1 2/4
#8 lore raw

Re: [PATCH v1 2/4] mm: move vma_mmu_pagesize() from hugetlb to vma.c

In reply to David Hildenbrand (Arm)
Quoted 10 lines · David Hildenbrand (Arm)

vma_mmu_pagesize() is also queried on non-hugetlb VMAs and does not really belong into hugetlb.c.

PPC64 provides a custom overwrite with CONFIG_HUGETLB_PAGE, see arch/powerpc/mm/book3s64/slice.c, so we cannot easily make this a static inline function.

So let's move it to vma.c and add some proper kerneldoc.

LGTM, so:

Quoted 99 lines
---
 include/linux/hugetlb.h |  7 -------
 include/linux/mm.h      |  2 ++
 mm/hugetlb.c            | 11 -----------
 mm/vma.c                | 21 +++++++++++++++++++++
 4 files changed, 23 insertions(+), 18 deletions(-)
include/linux/hugetlb.h +0 -7
index 44c1848a2c21..aaf3d472e6b5 100644
@@ -777,8 +777,6 @@ static inline unsigned long huge_page_size(const struct hstate *h)
 	return (unsigned long)PAGE_SIZE << h->order;
 }
 
-extern unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
-
 static inline unsigned long huge_page_mask(struct hstate *h)
 {
 	return h->mask;
@@ -1175,11 +1173,6 @@ static inline unsigned long huge_page_mask(struct hstate *h)
 	return PAGE_MASK;
 }
 
-static inline unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
-{
-	return PAGE_SIZE;
-}
-
 static inline unsigned int huge_page_order(struct hstate *h)
 {
 	return 0;
include/linux/mm.h +2 -0
index 227809790f1a..22d338933c84 100644
@@ -1327,6 +1327,8 @@ static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
 	return PAGE_SIZE;
 }
 
+unsigned long vma_mmu_pagesize(struct vm_area_struct *vma);
+
 static inline
 struct vm_area_struct *vma_find(struct vma_iterator *vmi, unsigned long max)
 {
mm/hugetlb.c +0 -11
index 66eadfa9e958..f6ecca9aae01 100644
@@ -1017,17 +1017,6 @@ static pgoff_t vma_hugecache_offset(struct hstate *h,
 			(vma->vm_pgoff >> huge_page_order(h));
 }
 
-/*
- * Return the page size being used by the MMU to back a VMA. In the majority
- * of cases, the page size used by the kernel matches the MMU size. On
- * architectures where it differs, an architecture-specific 'strong'
- * version of this symbol is required.
- */
-__weak unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
-{
-	return vma_kernel_pagesize(vma);
-}
-
 /*
  * Flags for MAP_PRIVATE reservations.  These are stored in the bottom
  * bits of the reservation map pointer, which are always clear due to
mm/vma.c +21 -1
index be64f781a3aa..e95fd5a5fe5c 100644
@@ -3300,3 +3300,24 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
 
 	return 0;
 }
+
+/**
+ * vma_mmu_pagesize - Default MMU page size granularity for this VMA.
+ * @vma: The user mapping.
+ *
+ * In the common case, the default page size used by the MMU matches the
+ * default page size used by the kernel (see vma_kernel_pagesize()). On
+ * architectures where it differs, an architecture-specific 'strong' version
+ * of this symbol is required.
+ *
+ * The default MMU page size is not affected by Transparent Huge Pages
+ * being in effect, or any usage of larger MMU page sizes (either through
+ * architectural huge-page mappings or other explicit/implicit coalescing of
+ * virtual ranges performed by the MMU).
+ *
+ * Return: The default MMU page size granularity for this VMA.
+ */
+__weak unsigned long vma_mmu_pagesize(struct vm_area_struct *vma)
+{
+	return vma_kernel_pagesize(vma);
+}
--

2.43.0

maintainer Reviewed-by on v1 3/4
#10 lore raw

Re: [PATCH v1 3/4] KVM: remove hugetlb.h inclusion

In reply to David Hildenbrand (Arm)
Quoted 4 lines · David Hildenbrand (Arm)

hugetlb.h is no longer required now that we moved vma_kernel_pagesize() to mm.h.

Aww this is the tiniest cutest patch evah!

Quoted 17 lines
---
 virt/kvm/kvm_main.c | 1 -
 1 file changed, 1 deletion(-)
virt/kvm/kvm_main.c +0 -2
index 22f8a672e1fd..58059648b881 100644
@@ -41,7 +41,6 @@
 #include <linux/spinlock.h>
 #include <linux/compat.h>
 #include <linux/srcu.h>
-#include <linux/hugetlb.h>
 #include <linux/slab.h>
 #include <linux/sort.h>
 #include <linux/bsearch.h>
--
Quoted 2 lines

2.43.0

Cheers, Lorenzo

maintainer Reviewed-by on v1 4/4
#13 lore raw

Re: [PATCH v1 4/4] KVM: PPC: remove hugetlb.h inclusion

In reply to David Hildenbrand (Arm)
Quoted 4 lines · David Hildenbrand (Arm)

hugetlb.h is no longer required now that we moved vma_kernel_pagesize() to mm.h.

You've gone mega cute on this one too! <3

Quoted 17 lines
---
 arch/powerpc/kvm/book3s_hv.c | 1 -
 1 file changed, 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +0 -2
index 08e5816fdd61..61dbeea317f3 100644
@@ -36,7 +36,6 @@
 #include <linux/gfp.h>
 #include <linux/vmalloc.h>
 #include <linux/highmem.h>
-#include <linux/hugetlb.h>
 #include <linux/kvm_irqfd.h>
 #include <linux/irqbypass.h>
 #include <linux/module.h>
--
Quoted 2 lines

2.43.0

Cheers, Lorenzo

reviewer
#14 lore raw
In reply to David Hildenbrand (Arm)
Quoted 25 lines · David Hildenbrand (Arm)

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.

Cross-compiled heavily.

Cc Andrew Morton <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc "Christophe Leroy (CS GROUP)" <[email protected]>
Cc Muchun Song <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Quoted 8 lines
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Jann Horn <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Dan Williams <[email protected]>

Although we all love less mail, FYI it seems like this didn't work properly for the patches (no CC's on there).

Did you try git-email --cc-cover?

Signature · 1 line
Pedro
#15 lore raw
Quoted 35 lines · Pedro Falcato
Quoted 25 lines · David Hildenbrand (Arm)

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.

Cross-compiled heavily.

Cc Andrew Morton <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc "Christophe Leroy (CS GROUP)" <[email protected]>
Cc Muchun Song <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Quoted 8 lines
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Jann Horn <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Dan Williams <[email protected]>
Quoted 4 lines

Although we all love less mail, FYI it seems like this didn't work properly for the patches (no CC's on there).

Did you try git-email --cc-cover?

Yeah I noticed this also :>) Assumed it was a new way of doing things somehow? :P

Quoted 3 lines

--
Pedro

Cheers, Lorenzo

author maintainer
#16 lore raw
Quoted 36 lines · Lorenzo Stoakes (Oracle)
Quoted 35 lines · Pedro Falcato
Quoted 33 lines · David Hildenbrand (Arm)

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.

Cross-compiled heavily.

Cc Andrew Morton <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc "Christophe Leroy (CS GROUP)" <[email protected]>
Cc Muchun Song <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Jann Horn <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Dan Williams <[email protected]>
Quoted 7 lines
Quoted 4 lines

Although we all love less mail, FYI it seems like this didn't work properly for the patches (no CC's on there).

Did you try git-email --cc-cover?

Yeah I noticed this also :>) Assumed it was a new way of doing things somehow? :P

"--cc-cover" is apparently not the git default on my new machine.

"See, I CCed you, I totally did not try to sneak something in. Oh, I messed up my tooling, stupid me ...". :)

Signature · 3 lines
Cheers,

David
author maintainer
#3 lore raw

Re: [PATCH v1 1/4] mm: move vma_kernel_pagesize() from hugetlb to mm.h

In reply to Lorenzo Stoakes (Oracle)
Quoted 23 lines · Lorenzo Stoakes (Oracle)
Quoted 22 lines · David Hildenbrand (Arm)

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.

Quoted 8 lines
Quoted 5 lines

This was found by code inspection.

Fixes c1d53b92b95c ("device-dax: implement ->pagesize() for smaps to report MMUPageSize")
Cc Dan Williams <[email protected]>

LGTM, but you need to fix up VMA tests, I attach a patch below to do this. Will this resolved:

Thanks!

I assume that should go into patch #2 instead?

Quoted 2 lines

[...]

Quoted 9 lines
---
 tools/testing/vma/include/dup.h | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/vma/include/dup.h +0 -0
index 3078ff1487d3..65b1030a7fdf 100644

tools/testing/vma/include/dup.h static inline void vma_set_file(struct vm_area_struct *vma, struct file *file) · line 1326

Quoted 9 lines
tools/testing/vma/include/dup.h +6 -0
@@ -1318,3 +1318,10 @@ static inline void vma_set_file(struct vm_area_struct *vma, struct file *file)
 	swap(vma->vm_file, file);
 	fput(file);
 }
+
+static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
+{
+	if (unlikely(vma->vm_ops && vma->vm_ops->pagesize))
+		return vma->vm_ops->pagesize(vma);
+	return PAGE_SIZE;

Should we just KIS and use PAGE_SIZE for the test?

Signature · 3 lines
Cheers,

David
reviewer Acked-by on the v1 series
#20 lore raw
In reply to David Hildenbrand (Arm)
Quoted 40 lines · David Hildenbrand (Arm)

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.

Cross-compiled heavily.

Cc Andrew Morton <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc "Christophe Leroy (CS GROUP)" <[email protected]>
Cc Muchun Song <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Jann Horn <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Dan Williams <[email protected]>

David Hildenbrand (Arm) (4):
mm: move vma_kernel_pagesize() from hugetlb to mm.h
mm: move vma_mmu_pagesize() from hugetlb to vma.c
KVM: remove hugetlb.h inclusion
KVM: PPC: remove hugetlb.h inclusion

Quoted 7 lines
 arch/powerpc/kvm/book3s_hv.c |  1 -
 include/linux/hugetlb.h      | 14 --------------
 include/linux/mm.h           | 22 ++++++++++++++++++++++
 mm/hugetlb.c                 | 28 ----------------------------
 mm/vma.c                     | 21 +++++++++++++++++++++
 virt/kvm/kvm_main.c          |  1 -
 6 files changed, 43 insertions(+), 44 deletions(-)

For the series:

Quoted 4 lines

base-commit: f75825cdfc4c5477cffcfd2cafa4e5ce5aa67f13

Signature · 1 line
2.43.0
Signature · 2 lines
Sincerely yours,
Mike.
#4 lore raw

Re: [PATCH v1 1/4] mm: move vma_kernel_pagesize() from hugetlb to mm.h

In reply to David Hildenbrand (Arm)
Quoted 47 lines · David Hildenbrand (Arm)
Quoted 23 lines · Lorenzo Stoakes (Oracle)
Quoted 22 lines · David Hildenbrand (Arm)

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.

Quoted 8 lines
Quoted 5 lines

This was found by code inspection.

Fixes c1d53b92b95c ("device-dax: implement ->pagesize() for smaps to report MMUPageSize")
Cc Dan Williams <[email protected]>

LGTM, but you need to fix up VMA tests, I attach a patch below to do this. Will this resolved:

Thanks!

I assume that should go into patch #2 instead?

Quoted 2 lines

[...]

Quoted 4 lines
---
 tools/testing/vma/include/dup.h | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 16 lines
Quoted 5 lines
tools/testing/vma/include/dup.h +0 -0
index 3078ff1487d3..65b1030a7fdf 100644

tools/testing/vma/include/dup.h static inline void vma_set_file(struct vm_area_struct *vma, struct file *file) · line 1326

Quoted 9 lines
tools/testing/vma/include/dup.h +6 -0
@@ -1318,3 +1318,10 @@ static inline void vma_set_file(struct vm_area_struct *vma, struct file *file)
 	swap(vma->vm_file, file);
 	fput(file);
 }
+
+static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
+{
+	if (unlikely(vma->vm_ops && vma->vm_ops->pagesize))
+		return vma->vm_ops->pagesize(vma);
+	return PAGE_SIZE;

Should we just KIS and use PAGE_SIZE for the test?

Yeah that's fine, but then should go in tools/testing/vma/include/custom.h :>)

I tidied things up there to make it easier to understand WTH is going on with the headers used by VMA tests.

Quoted 5 lines

--
Cheers,

David

Thanks, Lorenzo

#17 lore raw
In reply to David Hildenbrand (Arm)
Quoted 42 lines · David Hildenbrand (Arm)
Quoted 41 lines · Lorenzo Stoakes (Oracle)
Quoted 39 lines · Pedro Falcato
Quoted 25 lines · David Hildenbrand (Arm)

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.

Cross-compiled heavily.

Cc Andrew Morton <[email protected]>
Cc Madhavan Srinivasan <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc "Christophe Leroy (CS GROUP)" <[email protected]>
Cc Muchun Song <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Quoted 8 lines
Cc Vlastimil Babka <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Jann Horn <[email protected]>
Cc Pedro Falcato <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Dan Williams <[email protected]>

Although we all love less mail, FYI it seems like this didn't work properly for the patches (no CC's on there).

Did you try git-email --cc-cover?

Quoted 7 lines
Quoted 2 lines

Yeah I noticed this also :>) Assumed it was a new way of doing things somehow? :P

"--cc-cover" is apparently not the git default on my new machine.

"See, I CCed you, I totally did not try to sneak something in. Oh, I messed up my tooling, stupid me ...". :)

;)

Wasn't aware of that option actually, handy!

Quoted 5 lines

--
Cheers,

David

Cheers, Lorenzo

#6 lore raw

Re: [PATCH v1 1/4] mm: move vma_kernel_pagesize() from hugetlb to mm.h

In reply to David Hildenbrand (Arm)
Quoted 30 lines · David Hildenbrand (Arm)
Quoted 29 lines · Lorenzo Stoakes (Oracle)
Quoted 27 lines · David Hildenbrand (Arm)

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.

Fixes c1d53b92b95c ("device-dax: implement ->pagesize() for smaps to report MMUPageSize")
Cc Dan Williams <[email protected]>
Quoted 6 lines
Quoted 2 lines

LGTM, but you need to fix up VMA tests, I attach a patch below to do this. Will this resolved:

Thanks!

I assume that should go into patch #2 instead?

(Sorry missed this on first reply)

It doesn't matter too much from compilation point of view but thought it made more sense as this is where you pull vma_kernel_pagesize() in? But I'm fine with either!

Cheers, Lorenzo

author maintainer
#5 lore raw

Re: [PATCH v1 1/4] mm: move vma_kernel_pagesize() from hugetlb to mm.h

In reply to Lorenzo Stoakes (Oracle)
Quoted 37 lines · Lorenzo Stoakes (Oracle)
Quoted 19 lines · David Hildenbrand (Arm)
Quoted 3 lines · Lorenzo Stoakes (Oracle)

LGTM, but you need to fix up VMA tests, I attach a patch below to do this. Will this resolved:

Thanks!

I assume that should go into patch #2 instead?

Quoted 2 lines

[...]

Quoted 4 lines
---
 tools/testing/vma/include/dup.h | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 16 lines
Quoted 5 lines
tools/testing/vma/include/dup.h +0 -0
index 3078ff1487d3..65b1030a7fdf 100644

tools/testing/vma/include/dup.h static inline void vma_set_file(struct vm_area_struct *vma, struct file *file) · line 1326

Quoted 9 lines
tools/testing/vma/include/dup.h +6 -0
@@ -1318,3 +1318,10 @@ static inline void vma_set_file(struct vm_area_struct *vma, struct file *file)
 	swap(vma->vm_file, file);
 	fput(file);
 }
+
+static inline unsigned long vma_kernel_pagesize(struct vm_area_struct *vma)
+{
+	if (unlikely(vma->vm_ops && vma->vm_ops->pagesize))
+		return vma->vm_ops->pagesize(vma);
+	return PAGE_SIZE;

Should we just KIS and use PAGE_SIZE for the test?

Quoted 1 line

Yeah that's fine, but then should go in tools/testing/vma/include/custom.h :>)

I'll place it in there, then, thanks.

Signature · 3 lines
Cheers,

David
author maintainer
#18 lore raw
In reply to Lorenzo Stoakes (Oracle)
Quoted 6 lines · Lorenzo Stoakes (Oracle)
Quoted 5 lines · David Hildenbrand (Arm)
Quoted 3 lines · Lorenzo Stoakes (Oracle)

Yeah I noticed this also :>) Assumed it was a new way of doing things somehow? :P

Quoted 8 lines
Quoted 4 lines

"--cc-cover" is apparently not the git default on my new machine.

"See, I CCed you, I totally did not try to sneak something in. Oh, I messed up my tooling, stupid me ...". :)

;)

Wasn't aware of that option actually, handy!

On my old setup I had a script that would, in addition, also CC anybody CC'ed on individual patches on the cover letter. Was quite useful for larger series where you don't want to spam people with unrelated patches.

Still have to set that back up.

Signature · 3 lines
Cheers,

David
#19 lore raw
Quoted 12 lines · David Hildenbrand (Arm)
Quoted 11 lines · Lorenzo Stoakes (Oracle)
Quoted 9 lines · David Hildenbrand (Arm)
Quoted 3 lines · Lorenzo Stoakes (Oracle)

Yeah I noticed this also :>) Assumed it was a new way of doing things somehow? :P

"--cc-cover" is apparently not the git default on my new machine.

"See, I CCed you, I totally did not try to sneak something in. Oh, I messed up my tooling, stupid me ...". :)

Quoted 7 lines
Quoted 3 lines

;)

Wasn't aware of that option actually, handy!

On my old setup I had a script that would, in addition, also CC anybody CC'ed on individual patches on the cover letter. Was quite useful for larger series where you don't want to spam people with unrelated patches.

I had such a script too.

Quoted 1 line

Still have to set that back up.

But now "b4 send" does that for me automatically. And I don't need to do a "git format-patch" beforehand. It also does the equivalent of "--cc-cover".