Merge tag 'phy-for-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy
[linux-block.git] / include / linux / mm_inline.h
index 21d6c72bcc71e334070df8b72a20b187543ebba2..8148b30a9df10874967fc461948fbc08b1c2f629 100644 (file)
@@ -523,6 +523,27 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
        return atomic_read(&mm->tlb_flush_pending) > 1;
 }
 
+#ifdef CONFIG_MMU
+/*
+ * Computes the pte marker to copy from the given source entry into dst_vma.
+ * If no marker should be copied, returns 0.
+ * The caller should insert a new pte created with make_pte_marker().
+ */
+static inline pte_marker copy_pte_marker(
+               swp_entry_t entry, struct vm_area_struct *dst_vma)
+{
+       pte_marker srcm = pte_marker_get(entry);
+       /* Always copy error entries. */
+       pte_marker dstm = srcm & PTE_MARKER_POISONED;
+
+       /* Only copy PTE markers if UFFD register matches. */
+       if ((srcm & PTE_MARKER_UFFD_WP) && userfaultfd_wp(dst_vma))
+               dstm |= PTE_MARKER_UFFD_WP;
+
+       return dstm;
+}
+#endif
+
 /*
  * If this pte is wr-protected by uffd-wp in any form, arm the special pte to
  * replace a none pte.  NOTE!  This should only be called when *pte is already