Message ID | 20190212025632.28946-10-peterx@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | userfaultfd: write protection support | expand |
On Tue, Feb 12, 2019 at 10:56:15AM +0800, Peter Xu wrote: > From: Andrea Arcangeli <aarcange@redhat.com> > > Implement helpers methods to invoke userfaultfd wp faults more > selectively: not only when a wp fault triggers on a vma with > vma->vm_flags VM_UFFD_WP set, but only if the _PAGE_UFFD_WP bit is set > in the pagetable too. > > Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> > Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Jérôme Glisse <jglisse@redhat.com> > --- > include/linux/userfaultfd_k.h | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h > index 38f748e7186e..c6590c58ce28 100644 > --- a/include/linux/userfaultfd_k.h > +++ b/include/linux/userfaultfd_k.h > @@ -14,6 +14,8 @@ > #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */ > > #include <linux/fcntl.h> > +#include <linux/mm.h> > +#include <asm-generic/pgtable_uffd.h> > > /* > * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining > @@ -55,6 +57,18 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) > return vma->vm_flags & VM_UFFD_WP; > } > > +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, > + pte_t pte) > +{ > + return userfaultfd_wp(vma) && pte_uffd_wp(pte); > +} > + > +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, > + pmd_t pmd) > +{ > + return userfaultfd_wp(vma) && pmd_uffd_wp(pmd); > +} > + > static inline bool userfaultfd_armed(struct vm_area_struct *vma) > { > return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP); > @@ -104,6 +118,19 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) > return false; > } > > +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, > + pte_t pte) > +{ > + return false; > +} > + > +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, > + pmd_t pmd) > +{ > + return false; > +} > + > + > static inline bool userfaultfd_armed(struct vm_area_struct *vma) > { > return false; > -- > 2.17.1 >
On Tue, Feb 12, 2019 at 10:56:15AM +0800, Peter Xu wrote: > From: Andrea Arcangeli <aarcange@redhat.com> > > Implement helpers methods to invoke userfaultfd wp faults more > selectively: not only when a wp fault triggers on a vma with > vma->vm_flags VM_UFFD_WP set, but only if the _PAGE_UFFD_WP bit is set > in the pagetable too. > > Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> > Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com> > --- > include/linux/userfaultfd_k.h | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h > index 38f748e7186e..c6590c58ce28 100644 > --- a/include/linux/userfaultfd_k.h > +++ b/include/linux/userfaultfd_k.h > @@ -14,6 +14,8 @@ > #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */ > > #include <linux/fcntl.h> > +#include <linux/mm.h> > +#include <asm-generic/pgtable_uffd.h> > > /* > * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining > @@ -55,6 +57,18 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) > return vma->vm_flags & VM_UFFD_WP; > } > > +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, > + pte_t pte) > +{ > + return userfaultfd_wp(vma) && pte_uffd_wp(pte); > +} > + > +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, > + pmd_t pmd) > +{ > + return userfaultfd_wp(vma) && pmd_uffd_wp(pmd); > +} > + > static inline bool userfaultfd_armed(struct vm_area_struct *vma) > { > return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP); > @@ -104,6 +118,19 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) > return false; > } > > +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, > + pte_t pte) > +{ > + return false; > +} > + > +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, > + pmd_t pmd) > +{ > + return false; > +} > + > + > static inline bool userfaultfd_armed(struct vm_area_struct *vma) > { > return false; > -- > 2.17.1 >
diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 38f748e7186e..c6590c58ce28 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -14,6 +14,8 @@ #include <linux/userfaultfd.h> /* linux/include/uapi/linux/userfaultfd.h */ #include <linux/fcntl.h> +#include <linux/mm.h> +#include <asm-generic/pgtable_uffd.h> /* * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining @@ -55,6 +57,18 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) return vma->vm_flags & VM_UFFD_WP; } +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, + pte_t pte) +{ + return userfaultfd_wp(vma) && pte_uffd_wp(pte); +} + +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, + pmd_t pmd) +{ + return userfaultfd_wp(vma) && pmd_uffd_wp(pmd); +} + static inline bool userfaultfd_armed(struct vm_area_struct *vma) { return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP); @@ -104,6 +118,19 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) return false; } +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, + pte_t pte) +{ + return false; +} + +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, + pmd_t pmd) +{ + return false; +} + + static inline bool userfaultfd_armed(struct vm_area_struct *vma) { return false;