From: Peter Xu <[email protected]>
Hi,
This is a small patchset that will fix two known issues that got reported
today on the previous hugetlb unification series on slow gup [1].
The first issue was reported by Ryan Roberts [2] on a test failure over
gup_longterm. Patch 1-2 should fix it. Tested with 32MB hugepages on
arm64 VM.
The second issue was reported by Nathan Chancellor [3] on a build issue
over loongson's defconfig (loongson3_defconfig). It can be easily
reproduced with my own build setup [4], while patch 3 fixes it, and should
hopefully fix similar archs where pud_pfn() is not defined even if
pud_leaf() can return true.
For the 2nd issue, it's debatable whether it's an arch issue, because
logically speaking pud_pfn() and pud_leaf() should either be both defined
or both not. But since the current fix will be the simplest and still safe
(I at least checked loongarch doesn't support either pud dax or pud
hugetlb), I think we can consider having this to unbreak the build first,
assuming this could also happen to other archs.
One note is that the last 2 patches should be squashed into corresponding
patch, while the 1st patch should be kept standalone.
Thanks,
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/ZgyKLLVZ4vN56uZE@x1n
[4] https://gitlab.com/peterx/lkb-harness/-/blob/main/config.json?ref_type=heads#L32
Peter Xu (3):
mm: Allow anon exclusive check over hugetlb tail pages
fixup! mm/gup: handle huge pmd for follow_pmd_mask()
fixup! mm/arch: provide pud_pfn() fallback
include/linux/page-flags.h | 8 +++++++-
include/linux/pgtable.h | 6 +++++-
mm/gup.c | 3 ---
mm/internal.h | 10 ----------
4 files changed, 12 insertions(+), 15 deletions(-)
--
2.44.0
From: Peter Xu <[email protected]>
Allow follow_pmd_mask() to take hugetlb tail pages. The old warnings do
not help now as hugetlb now allows it to happen, so drop them.
Reported-by: Ryan Roberts <[email protected]>
Signed-off-by: Peter Xu <[email protected]>
---
mm/gup.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index 91d70057aea0..d60b63fcfc82 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -775,8 +775,6 @@ static struct page *follow_huge_pmd(struct vm_area_struct *vma,
assert_spin_locked(pmd_lockptr(mm, pmd));
page = pmd_page(pmdval);
- VM_BUG_ON_PAGE(!PageHead(page) && !is_zone_device_page(page), page);
-
if ((flags & FOLL_WRITE) &&
!can_follow_write_pmd(pmdval, page, vma, flags))
return NULL;
@@ -805,7 +803,6 @@ static struct page *follow_huge_pmd(struct vm_area_struct *vma,
page += (addr & ~HPAGE_PMD_MASK) >> PAGE_SHIFT;
ctx->page_mask = HPAGE_PMD_NR - 1;
- VM_BUG_ON_PAGE(!PageCompound(page) && !is_zone_device_page(page), page);
return page;
}
--
2.44.0
From: Peter Xu <[email protected]>
Signed-off-by: Peter Xu <[email protected]>
---
include/linux/pgtable.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index fa8f92f6e2d7..0f4b2faa1d71 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1882,9 +1882,13 @@ typedef unsigned int pgtbl_mod_mask;
* code. Now it happens too for pud_pfn (and can happen for larger
* mappings too in the future; we're not there yet). Instead of defining
* it for all archs (like pmd_pfn), provide a fallback.
+ *
+ * Note that returning 0 here means any arch that didn't define this can
+ * get severely wrong when it hits a real pud leaf. It's arch's
+ * responsibility to properly define it when a huge pud is possible.
*/
#ifndef pud_pfn
-#define pud_pfn(x) ({ BUILD_BUG(); 0; })
+#define pud_pfn(x) 0
#endif
/*
--
2.44.0
On 03/04/2024 02:32, [email protected] wrote:
> From: Peter Xu <[email protected]>
>
> Hi,
>
> This is a small patchset that will fix two known issues that got reported
> today on the previous hugetlb unification series on slow gup [1].
>
> The first issue was reported by Ryan Roberts [2] on a test failure over
> gup_longterm. Patch 1-2 should fix it. Tested with 32MB hugepages on
> arm64 VM.
>
> The second issue was reported by Nathan Chancellor [3] on a build issue
> over loongson's defconfig (loongson3_defconfig). It can be easily
> reproduced with my own build setup [4], while patch 3 fixes it, and should
> hopefully fix similar archs where pud_pfn() is not defined even if
> pud_leaf() can return true.
>
> For the 2nd issue, it's debatable whether it's an arch issue, because
> logically speaking pud_pfn() and pud_leaf() should either be both defined
> or both not. But since the current fix will be the simplest and still safe
> (I at least checked loongarch doesn't support either pud dax or pud
> hugetlb), I think we can consider having this to unbreak the build first,
> assuming this could also happen to other archs.
>
> One note is that the last 2 patches should be squashed into corresponding
> patch, while the 1st patch should be kept standalone.
>
> Thanks,
>
> [1] https://lore.kernel.org/r/[email protected]
> [2] https://lore.kernel.org/r/[email protected]
> [3] https://lore.kernel.org/r/ZgyKLLVZ4vN56uZE@x1n
> [4] https://gitlab.com/peterx/lkb-harness/-/blob/main/config.json?ref_type=heads#L32
>
> Peter Xu (3):
> mm: Allow anon exclusive check over hugetlb tail pages
> fixup! mm/gup: handle huge pmd for follow_pmd_mask()
> fixup! mm/arch: provide pud_pfn() fallback
>
> include/linux/page-flags.h | 8 +++++++-
> include/linux/pgtable.h | 6 +++++-
> mm/gup.c | 3 ---
> mm/internal.h | 10 ----------
> 4 files changed, 12 insertions(+), 15 deletions(-)
>
With these applied, gup_longterm is now passing for me on arm64. So for the series:
Tested-by: Ryan Roberts <[email protected]>