#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP
 static inline int pte_uffd_wp(pte_t pte)
 {
-       return pte_flags(pte) & _PAGE_UFFD_WP;
+       bool wp = pte_flags(pte) & _PAGE_UFFD_WP;
+
+#ifdef CONFIG_DEBUG_VM
+       /*
+        * Having write bit for wr-protect-marked present ptes is fatal,
+        * because it means the uffd-wp bit will be ignored and write will
+        * just go through.
+        *
+        * Use any chance of pgtable walking to verify this (e.g., when
+        * page swapped out or being migrated for all purposes). It means
+        * something is already wrong.  Tell the admin even before the
+        * process crashes. We also nail it with wrong pgtable setup.
+        */
+       WARN_ON_ONCE(wp && pte_write(pte));
+#endif
+
+       return wp;
 }
 
 static inline pte_t pte_mkuffd_wp(pte_t pte)