]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm: introduce pmd|pte_needs_soft_dirty_wp helpers for softdirty write-protect
authorBarry Song <v-songbaohua@oppo.com>
Fri, 7 Jun 2024 21:13:57 +0000 (09:13 +1200)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Jul 2024 02:30:07 +0000 (19:30 -0700)
Patch series "mm: introduce pmd|pte_needs_soft_dirty_wp helpers and
utilize them", v2.

This patchset introduces the pte_need_soft_dirty_wp and
pmd_need_soft_dirty_wp helpers to determine if write protection is
required for softdirty tracking.  These helpers enhance code readability
and improve the overall appearance.

They are then utilized in gup, mprotect, swap, and other related
functions.

This patch (of 2):

This patch introduces the pte_needs_soft_dirty_wp and
pmd_needs_soft_dirty_wp helpers to determine if write protection is
required for softdirty tracking.  This can enhance code readability and
improve its overall appearance.  These new helpers are then utilized in
gup, huge_memory, and mprotect.

Link: https://lkml.kernel.org/r/20240607211358.4660-1-21cnbao@gmail.com
Link: https://lkml.kernel.org/r/20240607211358.4660-2-21cnbao@gmail.com
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/gup.c
mm/huge_memory.c
mm/internal.h
mm/mprotect.c

index ca0f5cedce9b26c0b68efdb636ad129e304acb83..a01a0c96da312df0269a722c225247088fd41404 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -771,7 +771,7 @@ static inline bool can_follow_write_pmd(pmd_t pmd, struct page *page,
                return false;
 
        /* ... and a write-fault isn't required for other reasons. */
-       if (vma_soft_dirty_enabled(vma) && !pmd_soft_dirty(pmd))
+       if (pmd_needs_soft_dirty_wp(vma, pmd))
                return false;
        return !userfaultfd_huge_pmd_wp(vma, pmd);
 }
@@ -892,7 +892,7 @@ static inline bool can_follow_write_pte(pte_t pte, struct page *page,
                return false;
 
        /* ... and a write-fault isn't required for other reasons. */
-       if (vma_soft_dirty_enabled(vma) && !pte_soft_dirty(pte))
+       if (pte_needs_soft_dirty_wp(vma, pte))
                return false;
        return !userfaultfd_pte_wp(vma, pte);
 }
index f55362a73e2d1dfdb525a800e4c556ea76e78f86..6b294c9160de17ece7ee358155113dfbaaa505f1 100644 (file)
@@ -1626,7 +1626,7 @@ static inline bool can_change_pmd_writable(struct vm_area_struct *vma,
                return false;
 
        /* Do we need write faults for softdirty tracking? */
-       if (vma_soft_dirty_enabled(vma) && !pmd_soft_dirty(pmd))
+       if (pmd_needs_soft_dirty_wp(vma, pmd))
                return false;
 
        /* Do we need write faults for uffd-wp tracking? */
index 5020bb440c23221d698af53c4110c9274f381cce..0a190c3c55b0b28a5438b6c28f6643e24fb4f3f9 100644 (file)
@@ -1333,6 +1333,16 @@ static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma)
        return !(vma->vm_flags & VM_SOFTDIRTY);
 }
 
+static inline bool pmd_needs_soft_dirty_wp(struct vm_area_struct *vma, pmd_t pmd)
+{
+       return vma_soft_dirty_enabled(vma) && !pmd_soft_dirty(pmd);
+}
+
+static inline bool pte_needs_soft_dirty_wp(struct vm_area_struct *vma, pte_t pte)
+{
+       return vma_soft_dirty_enabled(vma) && !pte_soft_dirty(pte);
+}
+
 static inline void vma_iter_config(struct vma_iterator *vmi,
                unsigned long index, unsigned long last)
 {
index 888ef66468dbdac3526e3cdb2e1e3baac5eabbcc..222ab434da549dcd796d66144ed359efe0df98fa 100644 (file)
@@ -53,7 +53,7 @@ bool can_change_pte_writable(struct vm_area_struct *vma, unsigned long addr,
                return false;
 
        /* Do we need write faults for softdirty tracking? */
-       if (vma_soft_dirty_enabled(vma) && !pte_soft_dirty(pte))
+       if (pte_needs_soft_dirty_wp(vma, pte))
                return false;
 
        /* Do we need write faults for uffd-wp tracking? */