]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Revert "mm/madvise: introduce clear_young_dirty_ptes() batch helper" syz_20240603
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 4 Jun 2024 16:00:50 +0000 (12:00 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Tue, 4 Jun 2024 16:31:57 +0000 (12:31 -0400)
This reverts commit 1b68112c40395b3b0fed3c8bb648e2d9d0b37ec2.

include/linux/mm_types.h
include/linux/pgtable.h
mm/madvise.c

index 24323c7d0bd484830739fd6846a263f2f36f609e..db0adf5721ccf1beba63275569012b9b993fbe37 100644 (file)
@@ -1368,15 +1368,6 @@ enum fault_flag {
 
 typedef unsigned int __bitwise zap_flags_t;
 
-/* Flags for clear_young_dirty_ptes(). */
-typedef int __bitwise cydp_t;
-
-/* Clear the access bit */
-#define CYDP_CLEAR_YOUNG               ((__force cydp_t)BIT(0))
-
-/* Clear the dirty bit */
-#define CYDP_CLEAR_DIRTY               ((__force cydp_t)BIT(1))
-
 /*
  * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each
  * other. Here is what they mean, and how to use them:
index 18019f037baeca0ef5a7a54e11575f908543b98e..e2f45e22a6d138c1ca69dd7dc9a7de3ea44eac03 100644 (file)
@@ -361,6 +361,36 @@ static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
 }
 #endif
 
+#ifndef mkold_ptes
+/**
+ * mkold_ptes - Mark PTEs that map consecutive pages of the same folio as old.
+ * @vma: VMA the pages are mapped into.
+ * @addr: Address the first page is mapped at.
+ * @ptep: Page table pointer for the first entry.
+ * @nr: Number of entries to mark old.
+ *
+ * May be overridden by the architecture; otherwise, implemented as a simple
+ * loop over ptep_test_and_clear_young().
+ *
+ * Note that PTE bits in the PTE range besides the PFN can differ. For example,
+ * some PTEs might be write-protected.
+ *
+ * Context: The caller holds the page table lock.  The PTEs map consecutive
+ * pages that belong to the same folio.  The PTEs are all in the same PMD.
+ */
+static inline void mkold_ptes(struct vm_area_struct *vma, unsigned long addr,
+               pte_t *ptep, unsigned int nr)
+{
+       for (;;) {
+               ptep_test_and_clear_young(vma, addr, ptep);
+               if (--nr == 0)
+                       break;
+               ptep++;
+               addr += PAGE_SIZE;
+       }
+}
+#endif
+
 #ifndef __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
 static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
@@ -459,50 +489,6 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 }
 #endif
 
-#ifndef clear_young_dirty_ptes
-/**
- * clear_young_dirty_ptes - Mark PTEs that map consecutive pages of the
- *             same folio as old/clean.
- * @mm: Address space the pages are mapped into.
- * @addr: Address the first page is mapped at.
- * @ptep: Page table pointer for the first entry.
- * @nr: Number of entries to mark old/clean.
- * @flags: Flags to modify the PTE batch semantics.
- *
- * May be overridden by the architecture; otherwise, implemented by
- * get_and_clear/modify/set for each pte in the range.
- *
- * Note that PTE bits in the PTE range besides the PFN can differ. For example,
- * some PTEs might be write-protected.
- *
- * Context: The caller holds the page table lock.  The PTEs map consecutive
- * pages that belong to the same folio.  The PTEs are all in the same PMD.
- */
-static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,
-                                         unsigned long addr, pte_t *ptep,
-                                         unsigned int nr, cydp_t flags)
-{
-       pte_t pte;
-
-       for (;;) {
-               if (flags == CYDP_CLEAR_YOUNG)
-                       ptep_test_and_clear_young(vma, addr, ptep);
-               else {
-                       pte = ptep_get_and_clear(vma->vm_mm, addr, ptep);
-                       if (flags & CYDP_CLEAR_YOUNG)
-                               pte = pte_mkold(pte);
-                       if (flags & CYDP_CLEAR_DIRTY)
-                               pte = pte_mkclean(pte);
-                       set_pte_at(vma->vm_mm, addr, ptep, pte);
-               }
-               if (--nr == 0)
-                       break;
-               ptep++;
-               addr += PAGE_SIZE;
-       }
-}
-#endif
-
 static inline void ptep_clear(struct mm_struct *mm, unsigned long addr,
                              pte_t *ptep)
 {
index 96869e59b12bbd751f496450847b5164f36b9b55..6563fb1c1f6e6337d16dcf6aaf97358f0160e65f 100644 (file)
@@ -507,8 +507,7 @@ restart:
                        continue;
 
                if (!pageout && pte_young(ptent)) {
-                       clear_young_dirty_ptes(vma, addr, pte, nr,
-                                              CYDP_CLEAR_YOUNG);
+                       mkold_ptes(vma, addr, pte, nr);
                        tlb_remove_tlb_entries(tlb, pte, nr, addr);
                }