Skip to contentSkip to conversation

+ mm-memory-extend-finish_fault-to-support-large-folio-fix.patch added to mm-unstable branch

PATCH Andrew Morton 2 participants 2 messages Jun 13, 2024 – Jun 14, 2024

Subsystems (2)
lore
Share & tools
lore

Andrew Morton

author maintainer tree notice
#0 lore raw

The patch titled
Subject: mm-memory-extend-finish_fault-to-support-large-folio-fix
has been added to the -mm mm-unstable branch. Its filename is
mm-memory-extend-finish_fault-to-support-large-folio-fix.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memory-extend-finish_fault-to-support-large-folio-fix.patch

This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Baolin Wang <[email protected]>
Subject: mm-memory-extend-finish_fault-to-support-large-folio-fix
Date: Thu, 13 Jun 2024 21:03:36 +0800

avoid going beyond the PMD pagetable size

Reported-by [email protected]
Fixes 1c05047ad016 ("mm: memory: extend finish_fault() to support
Cc Barry Song <[email protected]>
Cc Daniel Gomez <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc "Huang, Ying" <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Lance Yang <[email protected]>
Cc Pankaj Raghav <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Yang Shi <[email protected]>
Cc Zi Yan <[email protected]>

---

 mm/memory.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/memory.c renamed from mm/memory.c~mm-memory-extend-finish_fault-to-support-large-folio-fix +6 -2
@@ -4875,13 +4875,17 @@ vm_fault_t finish_fault(struct vm_fault
 		pgoff_t idx = folio_page_idx(folio, page);
 		/* The page offset of vmf->address within the VMA. */
 		pgoff_t vma_off = vmf->pgoff - vmf->vma->vm_pgoff;
+		/* The index of the entry in the pagetable for fault page. */
+		pgoff_t pte_off = pte_index(vmf->address);
 
 		/*
 		 * Fallback to per-page fault in case the folio size in page
-		 * cache beyond the VMA limits.
+		 * cache beyond the VMA limits and PMD pagetable limits.
 		 */
 		if (unlikely(vma_off < idx ||
-			     vma_off + (nr_pages - idx) > vma_pages(vma))) {
+			    vma_off + (nr_pages - idx) > vma_pages(vma) ||
+			    pte_off < idx ||
+			    pte_off + (nr_pages - idx)  > PTRS_PER_PTE - 1)) {
 			nr_pages = 1;
 		} else {
 			/* Now we can set mappings for the whole large folio. */

_

Patches currently in -mm which might be from [email protected] are

mm-memory-extend-finish_fault-to-support-large-folio.patch mm-memory-extend-finish_fault-to-support-large-folio-fix.patch mm-shmem-add-thp-validation-for-pmd-mapped-thp-related-statistics.patch mm-shmem-add-multi-size-thp-sysfs-interface-for-anonymous-shmem.patch mm-shmem-add-multi-size-thp-sysfs-interface-for-anonymous-shmem-fix.patch mm-shmem-add-mthp-support-for-anonymous-shmem.patch mm-shmem-add-mthp-size-alignment-in-shmem_get_unmapped_area.patch mm-shmem-add-mthp-counters-for-anonymous-shmem.patch

#1 lore raw
Quoted 60 lines · Andrew Morton

The patch titled
Subject: mm-memory-extend-finish_fault-to-support-large-folio-fix
has been added to the -mm mm-unstable branch. Its filename is
mm-memory-extend-finish_fault-to-support-large-folio-fix.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memory-extend-finish_fault-to-support-large-folio-fix.patch

This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Baolin Wang <[email protected]>
Subject: mm-memory-extend-finish_fault-to-support-large-folio-fix
Date: Thu, 13 Jun 2024 21:03:36 +0800

avoid going beyond the PMD pagetable size

Reported-by [email protected]
Fixes 1c05047ad016 ("mm: memory: extend finish_fault() to support
Cc Barry Song <[email protected]>
Cc Daniel Gomez <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc "Huang, Ying" <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Kefeng Wang <[email protected]>
Cc Lance Yang <[email protected]>
Cc Pankaj Raghav <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Yang Shi <[email protected]>
Cc Zi Yan <[email protected]>

---

  mm/memory.c |    8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
mm/memory.c renamed from mm/memory.c~mm-memory-extend-finish_fault-to-support-large-folio-fix +2 -0
@@ -4875,13 +4875,17 @@ vm_fault_t finish_fault(struct vm_fault
  		pgoff_t idx = folio_page_idx(folio, page);
  		/* The page offset of vmf->address within the VMA. */
  		pgoff_t vma_off = vmf->pgoff - vmf->vma->vm_pgoff;
+		/* The index of the entry in the pagetable for fault page. */
+		pgoff_t pte_off = pte_index(vmf->address);
 

mm/memory.c vm_fault_t finish_fault(struct vm_fault · line 4888

Quoted 10 lines
mm/memory.c renamed from mm/memory.c~mm-memory-extend-finish_fault-to-support-large-folio-fix +4 -2
  		/*
  		 * Fallback to per-page fault in case the folio size in page
-		 * cache beyond the VMA limits.
+		 * cache beyond the VMA limits and PMD pagetable limits.
  		 */
  		if (unlikely(vma_off < idx ||
-			     vma_off + (nr_pages - idx) > vma_pages(vma))) {
+			    vma_off + (nr_pages - idx) > vma_pages(vma) ||
+			    pte_off < idx ||
+			    pte_off + (nr_pages - idx)  > PTRS_PER_PTE - 1)) {

We should use 'PTRS_PER_PTE' instead of 'PTRS_PER_PTE - 1'. Sorry for my math fault (I wrote the code too late last night, wasn't thinking clearly:( ).

Sorry Andrew, could you help to squash this change? Thanks.

mm/memory.c +1 -1
index b7137d9c99a9..e6521dd82281 100644
@@ -4888,7 +4888,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf)
                if (unlikely(vma_off < idx ||
                            vma_off + (nr_pages - idx) > vma_pages(vma) ||
                            pte_off < idx ||
-                           pte_off + (nr_pages - idx)  > PTRS_PER_PTE - 1)) {
+                           pte_off + (nr_pages - idx)  > PTRS_PER_PTE)) {
                        nr_pages = 1;
                } else {
                        /* Now we can set mappings for the whole large 

folio. */

Quoted 15 lines
mm/memory.c renamed from mm/memory.c~mm-memory-extend-finish_fault-to-support-large-folio-fix +0 -0
  			nr_pages = 1;
  		} else {
  			/* Now we can set mappings for the whole large folio. */

_

Patches currently in -mm which might be from [email protected] are

mm-memory-extend-finish_fault-to-support-large-folio.patch mm-memory-extend-finish_fault-to-support-large-folio-fix.patch mm-shmem-add-thp-validation-for-pmd-mapped-thp-related-statistics.patch mm-shmem-add-multi-size-thp-sysfs-interface-for-anonymous-shmem.patch mm-shmem-add-multi-size-thp-sysfs-interface-for-anonymous-shmem-fix.patch mm-shmem-add-mthp-support-for-anonymous-shmem.patch mm-shmem-add-mthp-size-alignment-in-shmem_get_unmapped_area.patch mm-shmem-add-mthp-counters-for-anonymous-shmem.patch