Re: [RFC PATCH v1 0/6] Lazy mmu mode fixes and improvements

2025-06-02 Thread Ryan Roberts
On 31/05/2025 08:46, Mike Rapoport wrote: > Hi Ryan, > > On Fri, May 30, 2025 at 04:55:36PM +0100, Ryan Roberts wrote: >> On 30/05/2025 15:47, Lorenzo Stoakes wrote: >>> +cc Jann who is a specialist in all things page table-y and especially scary >>> edge cases :

Re: [RFC PATCH v1 3/6] mm: Avoid calling page allocator from apply_to_page_range()

2025-05-30 Thread Ryan Roberts
On 30/05/2025 17:23, Liam R. Howlett wrote: > * Ryan Roberts [250530 10:05]: >> Lazy mmu mode applies to the current task and permits pte modifications >> to be deferred and updated at a later time in a batch to improve >> performance. apply_to_page_range() calls its call

Re: [RFC PATCH v1 1/6] fs/proc/task_mmu: Fix pte update and tlb maintenance ordering in pagemap_scan_pmd_entry()

2025-05-30 Thread Ryan Roberts
On 30/05/2025 17:26, Jann Horn wrote: > On Fri, May 30, 2025 at 4:04 PM Ryan Roberts wrote: >> pagemap_scan_pmd_entry() was previously modifying ptes while in lazy mmu >> mode, then performing tlb maintenance for the modified ptes, then >> leaving lazy mmu mode. But any pte

Re: [RFC PATCH v1 0/6] Lazy mmu mode fixes and improvements

2025-05-30 Thread Ryan Roberts
On 30/05/2025 15:47, Lorenzo Stoakes wrote: > +cc Jann who is a specialist in all things page table-y and especially scary > edge cases :) > > On Fri, May 30, 2025 at 03:04:38PM +0100, Ryan Roberts wrote: >> Hi All, >> >> I recently added support for lazy mmu mode

[RFC PATCH v1 6/6] Revert "arm64/mm: Permit lazy_mmu_mode to be nested"

2025-05-30 Thread Ryan Roberts
commit and reinstate the VM_WARN() if nesting is detected in future. Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/pgtable.h | 14 ++ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index ad

[RFC PATCH v1 5/6] mm: Avoid calling page allocator while in lazy mmu mode

2025-05-30 Thread Ryan Roberts
PI to check if we are in lazy mmu mode, and if so, when calling into the page allocator, temporarily leave lazy mmu mode. Given this new API we can also add VM_WARNings to check that we exit lazy mmu mode when required to ensure the PTEs are actually updated prior to tlb flushing. Signed-off-by:

[RFC PATCH v1 4/6] mm: Introduce arch_in_lazy_mmu_mode()

2025-05-30 Thread Ryan Roberts
performing an allocation, and will additionally be used to ensure pte modification vs tlb flushing order does not get inadvertantly swapped. Signed-off-by: Ryan Roberts --- arch/arm64/include/asm/pgtable.h | 8 .../powerpc/include/asm/book3s/64/tlbflush-hash.h | 15

[RFC PATCH v1 3/6] mm: Avoid calling page allocator from apply_to_page_range()

2025-05-30 Thread Ryan Roberts
e updated to use the _nolazy variants. Signed-off-by: Ryan Roberts --- include/linux/mm.h | 6 ++ kernel/bpf/arena.c | 6 +++--- mm/kasan/shadow.c | 2 +- mm/memory.c| 54 +++--- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/

[RFC PATCH v1 2/6] mm: Fix pte update and tlb maintenance ordering in migrate_vma_collect_pmd()

2025-05-30 Thread Ryan Roberts
ot;) Signed-off-by: Ryan Roberts --- mm/migrate_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 3158afe7eb23..fc73a940c112 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -283,11 +283,1

[RFC PATCH v1 1/6] fs/proc/task_mmu: Fix pte update and tlb maintenance ordering in pagemap_scan_pmd_entry()

2025-05-30 Thread Ryan Roberts
lly clear info about PTEs") Signed-off-by: Ryan Roberts --- fs/proc/task_mmu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 994cde10e3f4..361f3ffd9a0c 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2557,10 +2

[RFC PATCH v1 0/6] Lazy mmu mode fixes and improvements

2025-05-30 Thread Ryan Roberts
es (with DEBUG_PAGEALLOC and KFENCE enabled). Applies against Linus's master branch (f66bc387efbe). Thanks, Ryan Ryan Roberts (6): fs/proc/task_mmu: Fix pte update and tlb maintenance ordering in pagemap_scan_pmd_entry() mm: Fix pte update and tlb maintenance orderi

Re: [PATCH v2] selftests/mm: add simple VM_PFNMAP tests based on mmap'ing /dev/mem

2025-05-28 Thread Ryan Roberts
On 28/05/2025 13:40, David Hildenbrand wrote: > On 28.05.25 12:53, Ryan Roberts wrote: >> On 28/05/2025 11:48, David Hildenbrand wrote: >>> On 28.05.25 12:44, David Hildenbrand wrote: >>>> On 28.05.25 12:34, Ryan Roberts wrote: >>>>> Hi David,

Re: [PATCH v2] selftests/mm: add simple VM_PFNMAP tests based on mmap'ing /dev/mem

2025-05-28 Thread Ryan Roberts
On 28/05/2025 11:48, David Hildenbrand wrote: > On 28.05.25 12:44, David Hildenbrand wrote: >> On 28.05.25 12:34, Ryan Roberts wrote: >>> Hi David, >>> >>> >>> On 09/05/2025 16:30, David Hildenbrand wrote: >>>> Let's test some basic

Re: [PATCH v2] selftests/mm: add simple VM_PFNMAP tests based on mmap'ing /dev/mem

2025-05-28 Thread Ryan Roberts
Hi David, On 09/05/2025 16:30, David Hildenbrand wrote: > Let's test some basic functionality using /dev/mem. These tests will > implicitly cover some PAT (Page Attribute Handling) handling on x86. > > These tests will only run when /dev/mem access to the first two pages > in physical address sp

Re: [PATCH 3/4] tools/selftests: expand all guard region tests to file-backed

2025-04-22 Thread Ryan Roberts
On 22/04/2025 12:07, Lorenzo Stoakes wrote: > On Tue, Apr 22, 2025 at 12:03:08PM +0100, Ryan Roberts wrote: >> On 22/04/2025 11:47, Lorenzo Stoakes wrote: >>> On Tue, Apr 22, 2025 at 11:37:57AM +0100, Ryan Roberts wrote: > > [snip] > >>>> >>>>

Re: [PATCH 3/4] tools/selftests: expand all guard region tests to file-backed

2025-04-22 Thread Ryan Roberts
On 22/04/2025 11:47, Lorenzo Stoakes wrote: > On Tue, Apr 22, 2025 at 11:37:57AM +0100, Ryan Roberts wrote: >> On 13/02/2025 18:17, Lorenzo Stoakes wrote: >>> Extend the guard region tests to allow for test fixture variants for anon, >>> shmem, and local file files

Re: [PATCH 3/4] tools/selftests: expand all guard region tests to file-backed

2025-04-22 Thread Ryan Roberts
On 13/02/2025 18:17, Lorenzo Stoakes wrote: > Extend the guard region tests to allow for test fixture variants for anon, > shmem, and local file files. > > This allows us to assert that each of the expected behaviours of anonymous > memory also applies correctly to file-backed (both shmem and an a

Re: [PATCH v1 1/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-24 Thread Ryan Roberts
On 23/01/2025 17:40, Peter Xu wrote: > On Thu, Jan 23, 2025 at 02:38:46PM +0000, Ryan Roberts wrote: >>> @@ -5470,7 +5471,18 @@ static void move_huge_pte(struct vm_area_struct >>> *vma, unsigned long old_addr, >>> spin_lock_nested(src_ptl, SINGLE_DEP

Re: [PATCH v1 1/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-23 Thread Ryan Roberts
On 23/01/2025 14:38, Ryan Roberts wrote: > I think there might be a bug in this after all... > > > On 07/01/2025 14:47, Ryan Roberts wrote: >> When mremap()ing a memory region previously registered with userfaultfd >> as write-protected but without UFFD_FEATURE_EVENT_RE

Re: [PATCH v1 1/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-23 Thread Ryan Roberts
I think there might be a bug in this after all... On 07/01/2025 14:47, Ryan Roberts wrote: > When mremap()ing a memory region previously registered with userfaultfd > as write-protected but without UFFD_FEATURE_EVENT_REMAP, an > inconsistency in flag clearing leads to a mismatch betwee

Re: [PATCH v1 1/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-16 Thread Ryan Roberts
On 15/01/2025 20:28, Peter Xu wrote: > On Tue, Jan 07, 2025 at 02:47:52PM +0000, Ryan Roberts wrote: >> When mremap()ing a memory region previously registered with userfaultfd >> as write-protected but without UFFD_FEATURE_EVENT_REMAP, an >> inconsistency in flag clearin

Re: [PATCH v1 1/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-15 Thread Ryan Roberts
On 15/01/2025 17:30, Lorenzo Stoakes wrote: > On Wed, Jan 15, 2025 at 12:21:15PM -0500, Peter Xu wrote: >> On Wed, Jan 15, 2025 at 04:58:06PM +0000, Ryan Roberts wrote: >>> Hi Peter, David, >> >> Hey, Ryan, >> >>> >>> On 07/01/2025 14:47, Rya

Re: [PATCH v1 1/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-15 Thread Ryan Roberts
Hi Peter, David, On 07/01/2025 14:47, Ryan Roberts wrote: > When mremap()ing a memory region previously registered with userfaultfd > as write-protected but without UFFD_FEATURE_EVENT_REMAP, an > inconsistency in flag clearing leads to a mismatch between the vma flags > (which

[PATCH v1 2/2] selftests/mm: Introduce uffd-wp-mremap regression test

2025-01-07 Thread Ryan Roberts
: Ryan Roberts --- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 2 + tools/testing/selftests/mm/run_vmtests.sh | 1 + tools/testing/selftests/mm/uffd-wp-mremap.c | 380 4 files changed, 384 insertions(+) create mode

[PATCH v1 1/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-07 Thread Ryan Roberts
existing clearing of VM_UFFD_WP. Be careful to clear the logical flag regardless of its physical form; a PTE bit, a swap PTE bit, or a PTE marker. Cover PTE, huge PMD and hugetlb paths. Co-developed-by: Mikołaj Lenczewski Signed-off-by: Mikołaj Lenczewski Signed-off-by: Ryan Roberts Closes: https

[PATCH v1 0/2] mm: Clear uffd-wp PTE/PMD state on mremap()

2025-01-07 Thread Ryan Roberts
d the patch, which I have subsequently extended. Applies on top of mm-unstable (f349e79bfbf3) Thanks, Ryan Ryan Roberts (2): mm: Clear uffd-wp PTE/PMD state on mremap() selftests/mm: Introduce uffd-wp-mremap regression test include/linux/userfaultfd_k.h | 12 + mm/huge_mem

Re: [PATCH 1/2] selftests/mm: replace atomic_bool with pthread_barrier_t

2024-10-18 Thread Ryan Roberts
On 03/10/2024 22:17, Edward Liaw wrote: > Swaps synchronization primitive with pthread_barrier, so that > stdatomic.h does not need to be included. > > The synchronization is needed on Android ARM64; we see a deadlock with > pthread_create when the parent thread races forward before the child has