Re: [PATCH v3 04/27] mm/userfaultfd: Introduce special pte for unmapped file-backed mem
From: Peter Xu <peterx@redhat.com>
Date: 2021-06-09 14:43:45
Also in:
lkml
Subsystem:
memory management - userfaultfd, the rest · Maintainers:
Andrew Morton, Mike Rapoport, Linus Torvalds
On Wed, Jun 09, 2021 at 11:06:32PM +1000, Alistair Popple wrote:
On Friday, 28 May 2021 6:19:04 AM AEST Peter Xu wrote: [...]quoted
diff --git a/include/asm-generic/pgtable_uffd.h b/include/asm-generic/pgtable_uffd.h index 828966d4c281..95e9811ce9d1 100644 --- a/include/asm-generic/pgtable_uffd.h +++ b/include/asm-generic/pgtable_uffd.h@@ -2,6 +2,9 @@ #define _ASM_GENERIC_PGTABLE_UFFD_H #ifndef CONFIG_HAVE_ARCH_USERFAULTFD_WP + +#define UFFD_WP_SWP_PTE_SPECIAL __pte(0) + static __always_inline int pte_uffd_wp(pte_t pte) { return 0;diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 331d2ccf0bcc..93f932b53a71 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h@@ -145,6 +145,17 @@ extern int userfaultfd_unmap_prep(struct vm_area_struct *vma, extern void userfaultfd_unmap_complete(struct mm_struct *mm, struct list_head *uf); +static inline pte_t pte_swp_mkuffd_wp_special(struct vm_area_struct *vma) +{ + WARN_ON_ONCE(vma_is_anonymous(vma)); + return UFFD_WP_SWP_PTE_SPECIAL; +} + +static inline bool pte_swp_uffd_wp_special(pte_t pte) +{ + return pte_same(pte, UFFD_WP_SWP_PTE_SPECIAL); +} +Sorry, only just noticed this but do we need to define a different version of this helper that returns false for CONFIG_HAVE_ARCH_USERFAULTFD_WP=n to avoid spurious matches with __pte(0) on architectures supporting userfaultfd but not userfaultfd-wp?
Good point.. Yes we definitely don't want the empty pte to be recognized as the special pte.. I'll squash below into the same patch: ----8<----
diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
index 489fb375e66c..23ca449240d1 100644
--- a/include/linux/userfaultfd_k.h
+++ b/include/linux/userfaultfd_k.h@@ -177,7 +177,11 @@ static inline pte_t pte_swp_mkuffd_wp_special(struct vm_area_struct *vma) static inline bool pte_swp_uffd_wp_special(pte_t pte) { +#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP return pte_same(pte, UFFD_WP_SWP_PTE_SPECIAL); +#else + return false; +#fi } #else /* CONFIG_USERFAULTFD */ ----8<----
I'll see whether I can give some dry run without HAVE_ARCH_USERFAULTFD_WP but with USERFAULTFD. Thanks for spotting that! -- Peter Xu