mm: make PTE_MARKER_SWAPIN_ERROR more general
[linux-2.6-microblaze.git] / include / linux / mm_inline.h
index 21d6c72..a86c846 100644 (file)
@@ -523,6 +523,25 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm)
        return atomic_read(&mm->tlb_flush_pending) > 1;
 }
 
+/*
+ * 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;
+}
+
 /*
  * 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