Re: [PATCH 0/9] userfaultfd: add minor fault handling

2021-01-21 Thread Peter Xu
pports that (hugetlbfs_punch_hole()). But I agree with you on what you said should be good enough. Thanks, -- Peter Xu

Re: [PATCH 7/9] userfaultfd: add UFFDIO_CONTINUE ioctl

2021-01-21 Thread Peter Xu
r = mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr, > -src_addr, &page, zeropage, wp_copy); > +src_addr, &page, mcopy_mode, wp_copy); > cond_resched(); > > if (unlikely(err == -ENOENT)) { > @@ -626,14 +660,22 @@ ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned > long dst_start, >unsigned long src_start, unsigned long len, >bool *mmap_changing, __u64 mode) > { > - return __mcopy_atomic(dst_mm, dst_start, src_start, len, false, > - mmap_changing, mode); > + return __mcopy_atomic(dst_mm, dst_start, src_start, len, > + MCOPY_ATOMIC_NORMAL, mmap_changing, mode); > } > > ssize_t mfill_zeropage(struct mm_struct *dst_mm, unsigned long start, > unsigned long len, bool *mmap_changing) > { > - return __mcopy_atomic(dst_mm, start, 0, len, true, mmap_changing, 0); > + return __mcopy_atomic(dst_mm, start, 0, len, MCOPY_ATOMIC_ZEROPAGE, > + mmap_changing, 0); > +} > + > +ssize_t mcopy_continue(struct mm_struct *dst_mm, unsigned long start, > +unsigned long len, bool *mmap_changing) > +{ > + return __mcopy_atomic(dst_mm, start, 0, len, MCOPY_ATOMIC_CONTINUE, > + mmap_changing, 0); > } > > int mwriteprotect_range(struct mm_struct *dst_mm, unsigned long start, > -- > 2.30.0.284.gd98b1dd5eaa7-goog > -- Peter Xu

Re: [PATCH] vfio/pci: make the vfio_pci_mmap_fault reentrant

2021-03-09 Thread Peter Xu
still the simplest way to fix the problem for the current code base. I see io_remap_pfn_range() is also used in the new series - maybe that'll need to be moved to where PCI_COMMAND_MEMORY got turned on/off in the new series (I just noticed remap_pfn_range modifies vma flags..), as you suggested in the other email. Thanks, -- Peter Xu

Re: [PATCH] vfio/pci: make the vfio_pci_mmap_fault reentrant

2021-03-09 Thread Peter Xu
On Tue, Mar 09, 2021 at 12:26:07PM -0700, Alex Williamson wrote: > On Tue, 9 Mar 2021 13:47:39 -0500 > Peter Xu wrote: > > > On Tue, Mar 09, 2021 at 12:40:04PM -0400, Jason Gunthorpe wrote: > > > On Tue, Mar 09, 2021 at 08:29:51AM -0700, Alex Williamson wrote: > >

Re: [PATCH] vfio/pci: make the vfio_pci_mmap_fault reentrant

2021-03-09 Thread Peter Xu
an userspace to quickly populate a huge chunk of mmap()ed region for either MMIO or RAM. Indeed from that pov vmf_insert_pfn() seems to be even more efficient on prefaulting since it can be threaded. Thanks, -- Peter Xu

[PATCH 0/5] userfaultfd/selftests: A few cleanups

2021-03-09 Thread Peter Xu
ng, to use an err() macro instead of either fprintf() or perror() then another exit() call. The huge cleanup is done in the last patch. The first 4 patches are some other standalone cleanups for the same file, so I put them together. Please review, thanks. Peter Xu (5): userfaultfd/selftests

[PATCH 3/5] userfaultfd/selftests: Dropping VERIFY check in locking_thread

2021-03-09 Thread Peter Xu
conditionally check the fault flag - just do it unconditionally. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 55 +--- 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm

[PATCH 1/5] userfaultfd/selftests: Use user mode only

2021-03-09 Thread Peter Xu
Userfaultfd selftest does not need to handle kernel initiated fault. Set user mode so it can be run even if unprivileged_userfaultfd=0 (which is the default). Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git

[PATCH 4/5] userfaultfd/selftests: Only dump counts if mode enabled

2021-03-09 Thread Peter Xu
WP and MINOR modes are conditionally enabled on specific memory types. This patch avoids dumping tons of zeros for those cases when the modes are not supported at all. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 30 1 file changed, 20

[PATCH 2/5] userfaultfd/selftests: Remove the time() check on delayed uffd

2021-03-09 Thread Peter Xu
edule latency of resolving thread. It may not mean an issue with uffd. Neither do I saw this error triggered either in the past runs. Even if it triggers, it'll be drown in all the rest of test logs. Remove it. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 8 --

[PATCH 5/5] userfaultfd/selftests: Unify error handling

2021-03-09 Thread Peter Xu
Introduce err()/_err() and replace all the different ways to fail the program, mostly "fprintf" and "perror" with tons of exit() calls. Always stop the test program at any failure. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 649 ---

Re: [PATCH v2 4/4] hugetlb: Do early cow when page pinned on src mm

2021-02-05 Thread Peter Xu
> I do not have the full history, but it 'looks' like > lockdep might have been confused and this was added to keep it quiet. > > BTW - Copy page range for 'normal' pages has the same spin_lock_nested(). Yes. I'll need to take the same lock in v3, so I think I'll just follow. Thanks, -- Peter Xu

Re: [PATCH RFC 00/30] userfaultfd-wp: Support shmem and hugetlbfs

2021-02-05 Thread Peter Xu
On Fri, Feb 05, 2021 at 01:53:34PM -0800, Mike Kravetz wrote: > On 1/29/21 2:49 PM, Peter Xu wrote: > > On Fri, Jan 15, 2021 at 12:08:37PM -0500, Peter Xu wrote: > >> This is a RFC series to support userfaultfd upon shmem and hugetlbfs. > ... > > Huge & Mike, > &g

Re: [PATCH RFC 00/30] userfaultfd-wp: Support shmem and hugetlbfs

2021-02-05 Thread Peter Xu
On Fri, Feb 05, 2021 at 02:21:47PM -0800, Hugh Dickins wrote: > On Fri, 29 Jan 2021, Peter Xu wrote: > > > > Huge & Mike, > > > > Would any of you have comment/concerns on the high-level design of this > > series? > > > > It would be great to kn

Re: [PATCH v2 4/4] hugetlb: Do early cow when page pinned on src mm

2021-02-07 Thread Peter Xu
On Sun, Feb 07, 2021 at 11:09:29AM +0200, Gal Pressman wrote: > On 05/02/2021 17:51, Peter Xu wrote: > > On Fri, Feb 05, 2021 at 02:58:33PM +, Zhang, Wei wrote: > >> Hi Peter, > > > > Hi, Wei, > > > >> > >> Gal and I worked together. We t

[PATCH RFC 00/30] userfaultfd-wp: Support shmem and hugetlbfs

2021-01-15 Thread Peter Xu
/lkml/20201225092529.3228466-1-na...@vmware.com/ [1] https://github.com/xzpeter/linux/tree/uffd-wp-shmem-hugetlbfs [2] https://github.com/LLNL/umap-apps [3] https://github.com/xzpeter/umap/tree/peter-shmem-hugetlbfs Peter Xu (30): mm/thp: Simplify copying of huge zero page pmd when fork

[PATCH RFC 09/30] mm: Drop first_index/last_index in zap_details

2021-01-15 Thread Peter Xu
zap_details and let them simply be parameters of unmap_mapping_range_tree(), which is inlined. Signed-off-by: Peter Xu --- include/linux/mm.h | 2 -- mm/memory.c| 20 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index

[PATCH RFC 06/30] mm/userfaultfd: Introduce special pte for unmapped file-backed mem

2021-01-15 Thread Peter Xu
ifference. Link: https://lore.kernel.org/lkml/20201126222359.8120-1-pet...@redhat.com/ Link: https://lore.kernel.org/lkml/20201130230603.46187-1-pet...@redhat.com/ Suggested-by: Andrea Arcangeli Suggested-by: Hugh Dickins Signed-off-by: Peter Xu --- arch/x86/include

[PATCH RFC 04/30] shmem/userfaultfd: Take care of UFFDIO_COPY_MODE_WP

2021-01-15 Thread Peter Xu
. For uffd-wp, that could lead to data loss if without the dirty bit set. Note that shmem_mfill_zeropage_pte() will always call shmem_mfill_atomic_pte() with wp_copy==false because UFFDIO_ZEROCOPY does not support UFFDIO_COPY_MODE_WP. Signed-off-by: Peter Xu --- include/linux/shmem_fs.h |

[PATCH RFC 11/30] mm: Introduce ZAP_FLAG_SKIP_SWAP

2021-01-15 Thread Peter Xu
check_swap_entries"), but introduce ZAP_FLAG_SKIP_SWAP flag, which means the opposite of previous "details" parameter: the caller should explicitly set this to skip swap entries, otherwise swap entries will always be considered (which is still the major case here). Cc: Kir

[PATCH RFC 14/30] shmem/userfaultfd: Allow wr-protect none pte for file-backed mem

2021-01-15 Thread Peter Xu
exist. Note that this patch only covers the small pages (pte level) but not covering any of the transparent huge pages yet. But this will be a base for thps too. Signed-off-by: Peter Xu --- mm/mprotect.c | 48 1 file changed, 48 insertions(+) dif

[PATCH RFC 01/30] mm/thp: Simplify copying of huge zero page pmd when fork

2021-01-15 Thread Peter Xu
x27;s separately done with a global counter. This prepares for a future patch to modify the huge pmd to be installed, so that we don't need to duplicate it explicitly into huge zero page case too. Cc: Kirill A. Shutemov Signed-off-by: Peter Xu --- mm/huge_memory.c | 9 +++-- 1 file changed, 3

[PATCH RFC 16/30] shmem/userfaultfd: Handle the left-overed special swap ptes

2021-01-15 Thread Peter Xu
d to also teach userfaultfd itself on either UFFDIO_COPY or handling page faults, so that everything will still work as expected. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 15 +++ mm/shmem.c | 13 - 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/fs/

[PATCH RFC 27/30] hugetlb/userfaultfd: Allow wr-protect none ptes

2021-01-15 Thread Peter Xu
ze fetcher. Signed-off-by: Peter Xu --- mm/hugetlb.c | 29 + 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9b9f71ec30e1..7959fb4b1633 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4978,7 +4978,7 @@ uns

[PATCH RFC 12/30] mm: Pass zap_flags into unmap_mapping_pages()

2021-01-15 Thread Peter Xu
_MAPPING, while even_cow==true means a none zap flag to pass in (though in most cases we have had even_cow==false). No functional change intended. Signed-off-by: Peter Xu --- fs/dax.c | 10 ++ include/linux/mm.h | 4 ++-- mm/khugepaged.c| 3 ++- mm/memory.c| 15

[PATCH RFC 28/30] hugetlb/userfaultfd: Only drop uffd-wp special pte if required

2021-01-15 Thread Peter Xu
ptes, because it has taken hugetlb fault mutex so that no concurrent page fault would trigger. While the call to hugetlb_vmdelete_list() in hugetlbfs_punch_hole() is not safe. That's why the previous call will be with ZAP_FLAG_DROP_FILE_UFFD_WP, while the latter one won't be able to. Si

[PATCH RFC 15/30] shmem/userfaultfd: Allows file-back mem to be uffd wr-protected on thps

2021-01-15 Thread Peter Xu
rotection of pgtable lock. Signed-off-by: Peter Xu --- mm/mprotect.c | 10 +- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index c9390fd673fe..055871322007 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -296,8 +296,16 @@ static inline unsigned lon

[PATCH RFC 29/30] userfaultfd: Enable write protection for shmem & hugetlbfs

2021-01-15 Thread Peter Xu
with _UFFDIO_WRITEPROTECT too because all existing types now support write protection mode. Since vma_can_userfault() will be used elsewhere, move into userfaultfd_k.h. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 17 - include/linux/userfaultfd_k.h| 7 +++ include

[PATCH RFC 23/30] mm/hugetlb: Introduce huge version of special swap pte helpers

2021-01-15 Thread Peter Xu
This is to let hugetlbfs be prepared to also recognize swap special ptes just like uffd-wp special swap ptes. Signed-off-by: Peter Xu --- mm/hugetlb.c | 23 +-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index dd2acb8b3f0f

[PATCH RFC 24/30] mm/hugetlb: Move flush_hugetlb_tlb_range() into hugetlb.h

2021-01-15 Thread Peter Xu
Prepare for it to be called outside of mm/hugetlb.c. Signed-off-by: Peter Xu --- include/linux/hugetlb.h | 8 mm/hugetlb.c| 8 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 27ada597a8e6

[PATCH RFC 26/30] hugetlb/userfaultfd: Handle uffd-wp special pte in hugetlb pf handler

2021-01-15 Thread Peter Xu
he special swap pte too just like a none pte. Note that we also need to teach UFFDIO_COPY about this special pte across the code path so that we can safely install a new page at this special pte as long as we know it's a stall entry. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 5

[PATCH RFC 21/30] hugetlb: Pass vma into huge_pte_alloc()

2021-01-15 Thread Peter Xu
It is a preparation work to be able to behave differently in the per architecture huge_pte_alloc() according to different VMA attributes. Signed-off-by: Peter Xu --- arch/arm64/mm/hugetlbpage.c | 2 +- arch/ia64/mm/hugetlbpage.c| 3 ++- arch/mips/mm/hugetlbpage.c| 4 ++-- arch/parisc

[PATCH RFC 22/30] hugetlb/userfaultfd: Forbid huge pmd sharing when uffd enabled

2021-01-15 Thread Peter Xu
arch code would like to use too - ARM64 currently directly check against CONFIG_ARCH_WANT_HUGE_PMD_SHARE when trying to share huge pmd. Switch to the want_pmd_share() helper. Signed-off-by: Peter Xu --- arch/arm64/mm/hugetlbpage.c | 3 +-- include/linux/hugetlb.h

[PATCH RFC 20/30] hugetlb/userfaultfd: Handle UFFDIO_WRITEPROTECT

2021-01-15 Thread Peter Xu
This starts from passing cp_flags into hugetlb_change_protection() so hugetlb will be able to handle MM_CP_UFFD_WP[_RESOLVE] requests. huge_pte_clear_uffd_wp() is introduced to handle the case where the UFFDIO_WRITEPROTECT is requested upon migrating huge page entries. Signed-off-by: Peter Xu

[PATCH RFC 18/30] hugetlb/userfaultfd: Hook page faults for uffd write protection

2021-01-15 Thread Peter Xu
Hook up hugetlbfs_fault() with the capability to handle userfaultfd-wp faults. We do this slightly earlier than hugetlb_cow() so that we can avoid taking some extra locks that we definitely don't need. Signed-off-by: Peter Xu --- mm/hugetlb.c | 19 +++ 1 file change

[PATCH RFC 08/30] shmem/userfaultfd: Handle uffd-wp special pte in page fault handler

2021-01-15 Thread Peter Xu
und it. Doing fault-around with the new flag could confuse all the rest of pages when installing ptes from page cache when there's a cache hit. Signed-off-by: Peter Xu --- include/linux/mm.h | 2 + mm/memory.c| 107 +++-- 2 files chan

[PATCH RFC 25/30] hugetlb/userfaultfd: Unshare all pmds for hugetlbfs when register wp

2021-01-15 Thread Peter Xu
want_pmd_share() in hugetlb code so that huge pmd sharing is completely disabled for userfaultfd-wp registered range. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 43 include/linux/mmu_notifier.h | 1 + 2 files changed, 44 insertions(+) diff

[PATCH RFC 17/30] shmem/userfaultfd: Pass over uffd-wp special swap pte when fork()

2021-01-15 Thread Peter Xu
It should be handled similarly like other uffd-wp wr-protected ptes: we should pass it over when the dst_vma has VM_UFFD_WP armed, otherwise drop it. Signed-off-by: Peter Xu --- mm/memory.c | 15 ++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm

[PATCH RFC 05/30] mm: Clear vmf->pte after pte_unmap_same() returns

2021-01-15 Thread Peter Xu
f->pte first. Or, alloc_set_pte() will make sure to allocate a new pte even after calling pte_unmap_same(). Since we'll need to modify vmf->pte, directly pass in vmf into pte_unmap_same() and then we can also avoid the long parameter list. Signed-off-by: Peter Xu --- mm/memory.

[PATCH RFC 10/30] mm: Introduce zap_details.zap_flags

2021-01-15 Thread Peter Xu
th ZAP_FLAG_CHECK_MAPPING flag, it'll be very easy to grep this information by simply grepping the flag. It'll also make life easier when we want to e.g. pass in zap_flags into the callers like unmap_mapping_pages() (instead of adding new booleans besides the even_cows parame

[PATCH RFC 19/30] hugetlb/userfaultfd: Take care of UFFDIO_COPY_MODE_WP

2021-01-15 Thread Peter Xu
it even if UFFDIO_COPY_MODE_WP is provided, so that the core mm will know this page contains valid data and never drop it. Signed-off-by: Peter Xu --- include/asm-generic/hugetlb.h | 5 + include/linux/hugetlb.h | 6 -- mm/hugetlb.c | 9 +++-- mm/use

[PATCH RFC 07/30] mm/swap: Introduce the idea of special swap ptes

2021-01-15 Thread Peter Xu
lt "else" paths. Warn properly (e.g., in do_swap_page()) when we see a special swap pte - we should never call do_swap_page() upon those ptes, but just to bail out early if it happens. Signed-off-by: Peter Xu --- fs/proc/task_mmu.c | 14 -- include/linux/swapops.h

[PATCH RFC 03/30] mm/userfaultfd: Fix a few thp pmd missing uffd-wp bit

2021-01-15 Thread Peter Xu
-wp bit. 3. When convert pmd to swap entry, should drop the uffd-wp bit always. Signed-off-by: Peter Xu --- include/linux/swapops.h | 2 ++ mm/huge_memory.c| 4 2 files changed, 6 insertions(+) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index d9b7c9132

[PATCH RFC 02/30] mm/userfaultfd: Fix uffd-wp special cases for fork()

2021-01-15 Thread Peter Xu
opied has uffd-wp bit set. Remove the comment in copy_present_pte() about this. It won't help a huge lot to only comment there, but comment everywhere would be an overkill. Let's assume the commit messages would help. Cc: Jerome Glisse Cc: Mike Rapoport Fixes: b569a1760782f3da03ff718d61

[PATCH RFC 13/30] shmem/userfaultfd: Persist uffd-wp bit across zapping for file-backed

2021-01-15 Thread Peter Xu
g the whole vma, or punching a hole in a shmem file. For the latter, we can only drop the uffd-wp bit when holding the page lock. It means the unmap_mapping_range() in shmem_fallocate() still reuqires to zap without ZAP_FLAG_DROP_FILE_UFFD_WP because that's still racy with the page faults.

[PATCH RFC 30/30] userfaultfd/selftests: Enable uffd-wp for shmem/hugetlbfs

2021-01-15 Thread Peter Xu
After we added support for shmem and hugetlbfs, we can turn uffd-wp test on always now. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 14 ++ 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
t;preserve_write" for that pte looks odd already. Meanwhile, if that really happens (when pte write bit set, but during a uffd_wp_resolve request) imho there is really nothing we can do, so we should simply avoid touching that at all, and also avoid ptep_modify_prot_start, pte_modify, ptep_modify_prot_commit, calls etc., which takes extra cost. Thanks, -- Peter Xu

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
On Tue, Jan 05, 2021 at 01:08:48PM -0500, Andrea Arcangeli wrote: > On Tue, Jan 05, 2021 at 10:08:13AM -0500, Peter Xu wrote: > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > > > diff --git a/mm/mprotect.c b/mm/mprotect.c > > > index ab709023e9aa..c08c

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
On Tue, Jan 05, 2021 at 07:07:51PM +, Nadav Amit wrote: > > On Jan 5, 2021, at 7:08 AM, Peter Xu wrote: > > > > On Fri, Dec 25, 2020 at 01:25:28AM -0800, Nadav Amit wrote: > >> diff --git a/mm/mprotect.c b/mm/mprotect.c > >> index ab709023e9aa..c08c4055

Re: [RFC PATCH v2 1/2] mm/userfaultfd: fix memory corruption due to writeprotect

2021-01-05 Thread Peter Xu
COW is the only one affected (or, is it?) while umap may not use cow that lot by accident. But I could be completely wrong on that. [1] https://github.com/LLNL/umap [2] https://llnl-umap.readthedocs.io/en/develop/environment_variables.html -- Peter Xu

Re: [RFC PATCH v2 2/2] fs/task_mmu: acquire mmap_lock for write on soft-dirty cleanup

2021-01-05 Thread Peter Xu
t me know if you prefer me to do it, or I'll wait for your new version. Thanks, -- Peter Xu

Re: [PATCH 0/3] mm: Some rework on zap_details

2020-12-15 Thread Peter Xu
On Mon, Dec 07, 2020 at 09:50:19PM -0500, Peter Xu wrote: > Posted this small series out to rework zap_details a bit, before adding > something new in. Hopefully it makes things slighly clearer. > > Smoke test only. Please have a look, thanks. > > Peter Xu (3): >

[PATCH] mm: Don't fault around userfaultfd-registered regions on reads

2020-11-26 Thread Peter Xu
userspace full control of the uffd-registered ranges, rather than trying to do the tricks. Cc: Hugh Dickins Cc: Andrea Arcangeli Cc: Andrew Morton Cc: Mike Rapoport Signed-off-by: Peter Xu --- Note that since no file-backed uffd-wp support is there yet upstream, so the uffd-wp check is actual

Re: [PATCH] mm: Don't fault around userfaultfd-registered regions on reads

2020-11-27 Thread Peter Xu
On Fri, Nov 27, 2020 at 10:16:05AM +0200, Mike Rapoport wrote: > On Thu, Nov 26, 2020 at 05:23:59PM -0500, Peter Xu wrote: > > Faulting around for reads are in most cases helpful for the performance so > > that > > continuous memory accesses may avoid another trip of pa

Re: [PATCH] mm: Don't fault around userfaultfd-registered regions on reads

2020-11-27 Thread Peter Xu
Matthew, Thanks for the review comments. On Fri, Nov 27, 2020 at 12:22:24PM +, Matthew Wilcox wrote: > On Thu, Nov 26, 2020 at 05:23:59PM -0500, Peter Xu wrote: > > For missing mode uffds, fault around does not help because if the page cache > > existed, then the page should b

Re: [PATCH] mm: Don't fault around userfaultfd-registered regions on reads

2020-11-27 Thread Peter Xu
On Fri, Nov 27, 2020 at 06:00:44PM +0100, David Hildenbrand wrote: > On 26.11.20 23:23, Peter Xu wrote: > > Faulting around for reads are in most cases helpful for the performance so > > that > > continuous memory accesses may avoid another trip of page fault. However it &g

Re: [PATCH] mm: Don't fault around userfaultfd-registered regions on reads

2020-11-28 Thread Peter Xu
On Fri, Nov 27, 2020 at 07:33:39PM -0500, Andrea Arcangeli wrote: > Hello, Hi, Andrea! > > On Fri, Nov 27, 2020 at 12:22:24PM +, Matthew Wilcox wrote: > > On Thu, Nov 26, 2020 at 05:23:59PM -0500, Peter Xu wrote: > > > For wr-protected mode uffds, errornously fau

[PATCH v2 00/26] userfaultfd: write protection support

2019-02-11 Thread Peter Xu
rfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers userfaultfd: wp: add UFFDIO_COPY_MODE_WP userfaultfd: wp: add the writeprotect API to userfaultfd ioctl Martin Cracauer (1): userfaultfd: wp: UFFDIO_REGISTER_MODE_WP documentation update Peter Xu (17): mm: gup: rename "nonblocking" to "lo

[PATCH v2 01/26] mm: gup: rename "nonblocking" to "locked" where proper

2019-02-11 Thread Peter Xu
ter suite the functionality of the variable. While at it, fixing up some of the comments accordingly. Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- mm/gup.c | 44 +--- mm/hugetlb.c | 8 2 files changed, 25 insertions(+), 27

[PATCH v2 03/26] userfaultfd: don't retake mmap_sem to emulate NOPAGE

2019-02-11 Thread Peter Xu
-by: Linus Torvalds Signed-off-by: Peter Xu --- fs/userfaultfd.c | 24 1 file changed, 24 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 89800fc7dc9d..b397bc3b954d 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -514,30 +514,6 @@

[PATCH v2 07/26] userfaultfd: wp: hook userfault handler to write protection fault

2019-02-11 Thread Peter Xu
t certainly worth to achieve it but in a later incremental patch. v3: Add hooking point for THP wrprotect faults. CC: Shaohua Li Signed-off-by: Andrea Arcangeli Signed-off-by: Peter Xu --- mm/memory.c | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/memory.c

[PATCH v2 04/26] mm: allow VM_FAULT_RETRY for multiple times

2019-02-11 Thread Peter Xu
ult write-protection. Please read the thread below for more information. [1] https://lkml.org/lkml/2017/11/2/833 [2] https://lkml.org/lkml/2018/12/30/64 Suggested-by: Linus Torvalds Suggested-by: Andrea Arcangeli Signed-off-by: Peter Xu --- arch/alpha/mm/fault.c | 2 +- arch/arc/m

[PATCH v2 05/26] mm: gup: allow VM_FAULT_RETRY for multiple times

2019-02-11 Thread Peter Xu
This is the gup counterpart of the change that allows the VM_FAULT_RETRY to happen for more than once. Signed-off-by: Peter Xu --- mm/gup.c | 17 + 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index fa75a03204c1..ba387aec0d80 100644 --- a/mm

[PATCH v2 02/26] mm: userfault: return VM_FAULT_RETRY on signals

2019-02-11 Thread Peter Xu
to handle nonfatal signals faster than before. This patch is a preparation work for the next patch to finally remove the special code path mentioned above in handle_userfault(). Suggested-by: Linus Torvalds Suggested-by: Andrea Arcangeli Signed-off-by: Peter Xu --- arch/alpha/mm/fault.c

[PATCH v2 08/26] userfaultfd: wp: add WP pagetable tracking to x86

2019-02-11 Thread Peter Xu
ay on that, we'd need to stay on the safe side and generate false positive wp faults for every swapped out page. Signed-off-by: Andrea Arcangeli Signed-off-by: Peter Xu --- arch/x86/Kconfig | 1 + arch/x86/include/asm/pgtable.h | 52

[PATCH v2 06/26] userfaultfd: wp: add helper for writeprotect check

2019-02-11 Thread Peter Xu
From: Shaohua Li add helper for writeprotect check. Will use it later. Cc: Andrea Arcangeli Cc: Pavel Emelyanov Cc: Rik van Riel Cc: Kirill A. Shutemov Cc: Mel Gorman Cc: Hugh Dickins Cc: Johannes Weiner Signed-off-by: Shaohua Li Signed-off-by: Andrea Arcangeli Signed-off-by: Peter Xu

[PATCH v2 10/26] userfaultfd: wp: add UFFDIO_COPY_MODE_WP

2019-02-11 Thread Peter Xu
From: Andrea Arcangeli This allows UFFDIO_COPY to map pages wrprotected. Signed-off-by: Andrea Arcangeli Signed-off-by: Peter Xu --- fs/userfaultfd.c | 5 +++-- include/linux/userfaultfd_k.h| 2 +- include/uapi/linux/userfaultfd.h | 11 +- mm/userfaultfd.c

[PATCH v2 09/26] userfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers

2019-02-11 Thread Peter Xu
From: Andrea Arcangeli 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 Signed-off-by: Pe

[PATCH v2 11/26] mm: merge parameters for change_protection()

2019-02-11 Thread Peter Xu
ameters to change_protection(). In the follow up patches, a new parameter for userfaultfd write protection will be introduced. No functional change at all. Signed-off-by: Peter Xu --- include/linux/huge_mm.h | 2 +- include/linux/mm.h | 14 +- mm/huge_memory.c| 3 ++- mm/m

[PATCH v2 13/26] mm: export wp_page_copy()

2019-02-11 Thread Peter Xu
Export this function for usages outside page fault handlers. Signed-off-by: Peter Xu --- include/linux/mm.h | 2 ++ mm/memory.c| 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f38fbe9c8bc9..2fd14a62324b 100644 --- a

[PATCH v2 12/26] userfaultfd: wp: apply _PAGE_UFFD_WP bit

2019-02-11 Thread Peter Xu
page faults in either do_wp_page() or wp_huge_pmd(). Signed-off-by: Peter Xu --- arch/x86/include/asm/pgtable_types.h | 2 +- include/linux/mm.h | 5 + mm/huge_memory.c | 14 +- mm/memory.c | 4 ++-- mm/mprotect.c

[PATCH v2 14/26] userfaultfd: wp: handle COW properly for uffd-wp

2019-02-11 Thread Peter Xu
t to resolve an uffd-wp page fault always. That matches what we do with general huge PMD write protections. In that way, we resolved the huge PMD copy-on-write issue into PTE copy-on-write. Signed-off-by: Peter Xu --- mm/memory.c | 2 ++ mm/

[PATCH v2 15/26] userfaultfd: wp: drop _PAGE_UFFD_WP properly when fork

2019-02-11 Thread Peter Xu
: Peter Xu --- mm/huge_memory.c | 8 mm/memory.c | 8 2 files changed, 16 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 817335b443c2..fb2234cb595a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -938,6 +938,14 @@ int copy_huge_pmd(struct

[PATCH v2 16/26] userfaultfd: wp: add pmd_swp_*uffd_wp() helpers

2019-02-11 Thread Peter Xu
Adding these missing helpers for uffd-wp operations with pmd swap/migration entries. Signed-off-by: Peter Xu --- arch/x86/include/asm/pgtable.h | 15 +++ include/asm-generic/pgtable_uffd.h | 15 +++ 2 files changed, 30 insertions(+) diff --git a/arch/x86/include/asm

[PATCH v2 17/26] userfaultfd: wp: support swap and page migration

2019-02-11 Thread Peter Xu
serfaultfd: wp: hook userfault handler to write protection fault" where we try to remove the VM_FAULT_WRITE from vmf->flags when uffd-wp is set for the VMA. This patch will still keep the write flag there. Signed-off-by: Peter Xu --- include/linux/swapops.h | 2 ++ mm/huge_memory.c

[PATCH v2 20/26] userfaultfd: wp: support write protection for userfault vma range

2019-02-11 Thread Peter Xu
ngeli [peterx: - use the helper to find VMA; - return -ENOENT if not found to match mcopy case; - use the new MM_CP_UFFD_WP* flags for change_protection - check against mmap_changing for failures] Signed-off-by: Peter Xu --- include/linux/userfaultfd_k.h | 3 ++ mm/userfaultfd.c

[PATCH v2 18/26] khugepaged: skip collapse if uffd-wp detected

2019-02-11 Thread Peter Xu
same thing needs to be considered for swap entries and migration entries. So do the check as well disregarding khugepaged_max_ptes_swap. Signed-off-by: Peter Xu --- include/trace/events/huge_memory.h | 1 + mm/khugepaged.c| 23 +++ 2 files changed, 24

[PATCH v2 21/26] userfaultfd: wp: add the writeprotect API to userfaultfd ioctl

2019-02-11 Thread Peter Xu
ff-by: Peter Xu --- fs/userfaultfd.c | 82 +--- include/uapi/linux/userfaultfd.h | 11 + 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 3092885c9d2c..81962d62520c 100644 --- a/fs/userfaultfd.c +++

[PATCH v2 19/26] userfaultfd: introduce helper vma_find_uffd

2019-02-11 Thread Peter Xu
We've have multiple (and more coming) places that would like to find a userfault enabled VMA from a mm struct that covers a specific memory range. This patch introduce the helper for it, meanwhile apply it to the code. Suggested-by: Mike Rapoport Signed-off-by: Peter Xu --- mm/userfaul

[PATCH v2 22/26] userfaultfd: wp: enabled write protection in userfaultfd API

2019-02-11 Thread Peter Xu
ff-by: Peter Xu --- include/uapi/linux/userfaultfd.h | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/userfaultfd.h b/include/uapi/linux/userfaultfd.h index 1b977a7a4435..a50f1ed24d23 100644 --- a/include/uapi/linux/userfaultfd.h +++ b/include/uapi/

[PATCH v2 23/26] userfaultfd: wp: don't wake up when doing write protect

2019-02-11 Thread Peter Xu
It does not make sense to try to wake up any waiting thread when we're write-protecting a memory region. Only wake up when resolving a write protected page fault. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 13 - 1 file changed, 8 insertions(+), 5 deletions(-) diff --git

[PATCH v2 25/26] userfaultfd: selftests: refactor statistics

2019-02-11 Thread Peter Xu
structure, it's very easy to introduce new statistics. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 76 +++- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftes

[PATCH v2 26/26] userfaultfd: selftests: add write-protect test

2019-02-11 Thread Peter Xu
ious tests but will do MISSING+WP for each page. For sigbus-mode test we'll need to provide standalone path to handle the write protection faults. For all tests, do statistics as well for uffd-wp pages. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/user

[PATCH v2 24/26] userfaultfd: wp: UFFDIO_REGISTER_MODE_WP documentation update

2019-02-11 Thread Peter Xu
From: Martin Cracauer Adds documentation about the write protection support. Signed-off-by: Andrea Arcangeli [peterx: rewrite in rst format; fixups here and there] Signed-off-by: Peter Xu --- Documentation/admin-guide/mm/userfaultfd.rst | 51 1 file changed, 51

Virtio-scsi multiqueue irq affinity

2019-03-17 Thread Peter Xu
the big picture? I believe I must have missed some contexts here and there... but I'd like to raise the question up. Say, if the new way is preferred and attempted, maybe it would worth it to spread the idea to the rest of the virtio drivers who support multi-queues as well. Thanks, -- Peter Xu

[PATCH] genirq: Fix typo in comment of IRQD_MOVE_PCNTXT

2019-03-17 Thread Peter Xu
CC: Marc Zyngier CC: Thomas Gleixner CC: Dou Liyang CC: Julien Thierry CC: Peter Xu CC: linux-kernel@vger.kernel.org Signed-off-by: Peter Xu --- include/linux/irq.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index

[PATCH v2 0/1] userfaultfd: allow to forbid unprivileged users

2019-03-18 Thread Peter Xu
age sysctl.conf with that and also since no one yet explicitly asked for sysfs for a better reason yet (And I just noticed BPF just added another bpf_stats_enabled into sysctl a few weeks ago). Please have a look, thanks. Peter Xu (1): userfaultfd/sysctl: add vm.unprivileged_userfaultfd Documen

[PATCH v2 1/1] userfaultfd/sysctl: add vm.unprivileged_userfaultfd

2019-03-18 Thread Peter Xu
by: Andrea Arcangeli Suggested-by: Mike Rapoport Signed-off-by: Peter Xu --- Documentation/sysctl/vm.txt | 12 fs/userfaultfd.c | 5 + include/linux/userfaultfd_k.h | 2 ++ kernel/sysctl.c | 12 4 files changed, 31 insertions(+) di

Re: [PATCH v2 1/1] userfaultfd/sysctl: add vm.unprivileged_userfaultfd

2019-03-19 Thread Peter Xu
On Tue, Mar 19, 2019 at 06:28:23PM +, Dr. David Alan Gilbert wrote: > * Andrew Morton (a...@linux-foundation.org) wrote: > > On Tue, 19 Mar 2019 11:07:22 +0800 Peter Xu wrote: > > > > > Add a global sysctl knob "vm.unprivileged_userfaultfd" to control >

[PATCH v3 03/28] userfaultfd: don't retake mmap_sem to emulate NOPAGE

2019-03-19 Thread Peter Xu
-by: Linus Torvalds Reviewed-by: Jerome Glisse Signed-off-by: Peter Xu --- fs/userfaultfd.c | 24 1 file changed, 24 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 89800fc7dc9d..b397bc3b954d 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -514

[PATCH v3 00/28] userfaultfd: write protection support

2019-03-19 Thread Peter Xu
_WP userfaultfd: wp: add the writeprotect API to userfaultfd ioctl Martin Cracauer (1): userfaultfd: wp: UFFDIO_REGISTER_MODE_WP documentation update Peter Xu (19): mm: gup: rename "nonblocking" to "locked" where proper mm: userfault: return VM_FAULT_RETRY on signals userfau

[PATCH v3 04/28] mm: allow VM_FAULT_RETRY for multiple times

2019-03-19 Thread Peter Xu
Linus Torvalds Suggested-by: Andrea Arcangeli Signed-off-by: Peter Xu --- arch/alpha/mm/fault.c | 2 +- arch/arc/mm/fault.c | 1 - arch/arm/mm/fault.c | 3 --- arch/arm64/mm/fault.c | 5 - arch/hexagon/mm/vm_fault.c | 1 - arch/ia64/mm/fault.c

[PATCH v3 02/28] mm: userfault: return VM_FAULT_RETRY on signals

2019-03-19 Thread Peter Xu
to handle nonfatal signals faster than before. This patch is a preparation work for the next patch to finally remove the special code path mentioned above in handle_userfault(). Suggested-by: Linus Torvalds Suggested-by: Andrea Arcangeli Reviewed-by: Jerome Glisse Signed-off-by: Peter Xu ---

[PATCH v3 01/28] mm: gup: rename "nonblocking" to "locked" where proper

2019-03-19 Thread Peter Xu
ter suite the functionality of the variable. While at it, fixing up some of the comments accordingly. Reviewed-by: Mike Rapoport Reviewed-by: Jerome Glisse Signed-off-by: Peter Xu --- mm/gup.c | 44 +--- mm/hugetlb.c | 8 2 files changed, 25

[PATCH v3 09/28] userfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers

2019-03-19 Thread Peter Xu
ome Glisse Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- 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/li

[PATCH v3 11/28] mm: merge parameters for change_protection()

2019-03-19 Thread Peter Xu
ameters to change_protection(). In the follow up patches, a new parameter for userfaultfd write protection will be introduced. No functional change at all. Reviewed-by: Jerome Glisse Signed-off-by: Peter Xu --- include/linux/huge_mm.h | 2 +- include/linux/mm.h | 14 +- mm/huge_memory.c

[PATCH v3 08/28] userfaultfd: wp: add WP pagetable tracking to x86

2019-03-19 Thread Peter Xu
ay on that, we'd need to stay on the safe side and generate false positive wp faults for every swapped out page. Signed-off-by: Andrea Arcangeli [peterx: append _PAGE_UFD_WP to _PAGE_CHG_MASK] Reviewed-by: Jerome Glisse Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- arch/x

[PATCH v3 05/28] mm: gup: allow VM_FAULT_RETRY for multiple times

2019-03-19 Thread Peter Xu
This is the gup counterpart of the change that allows the VM_FAULT_RETRY to happen for more than once. Reviewed-by: Jerome Glisse Signed-off-by: Peter Xu --- mm/gup.c | 17 + mm/hugetlb.c | 6 -- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mm/gup.c

[PATCH v3 10/28] userfaultfd: wp: add UFFDIO_COPY_MODE_WP

2019-03-19 Thread Peter Xu
by: Jerome Glisse Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- fs/userfaultfd.c | 5 +++-- include/linux/userfaultfd_k.h| 2 +- include/uapi/linux/userfaultfd.h | 11 +- mm/userfaultfd.c | 36 ++-- 4 files chang

[PATCH v3 07/28] userfaultfd: wp: hook userfault handler to write protection fault

2019-03-19 Thread Peter Xu
t certainly worth to achieve it but in a later incremental patch. v3: Add hooking point for THP wrprotect faults. CC: Shaohua Li Signed-off-by: Andrea Arcangeli [peterx: don't conditionally drop FAULT_FLAG_WRITE in do_swap_page] Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- mm/me

<    1   2   3   4   5   6   7   8   9   10   >