Re: [PATCH 7/7] x86: mm: accelerate pagefault when badaccess

2024-04-03 Thread Suren Baghdasaryan
On Wed, Apr 3, 2024 at 12:58 AM Kefeng Wang wrote: > > > > On 2024/4/3 13:59, Suren Baghdasaryan wrote: > > On Tue, Apr 2, 2024 at 12:53 AM Kefeng Wang > > wrote: > >> > >> The vm_flags of vma already checked under per-VMA lock, if it is a > &g

Re: [PATCH 7/7] x86: mm: accelerate pagefault when badaccess

2024-04-03 Thread Suren Baghdasaryan
safe to me. Using (mm != NULL) to indicate that we are holding mmap_lock is not ideal but I guess that works. Reviewed-by: Suren Baghdasaryan > --- > arch/x86/mm/fault.c | 23 ++- > 1 file changed, 14 insertions(+), 9 deletions(-) > > diff --git a/arch/x86

Re: [PATCH 5/7] riscv: mm: accelerate pagefault when badaccess

2024-04-02 Thread Suren Baghdasaryan
On Tue, Apr 2, 2024 at 12:53 AM Kefeng Wang wrote: > > The vm_flags of vma already checked under per-VMA lock, if it is a > bad access, directly handle error and return, there is no need to > lock_mm_and_find_vma() and check vm_flags again. > > Signed-off-by: Kefeng Wang

Re: [PATCH 4/7] powerpc: mm: accelerate pagefault when badaccess

2024-04-02 Thread Suren Baghdasaryan
On Tue, Apr 2, 2024 at 12:53 AM Kefeng Wang wrote: > > The vm_flags of vma already checked under per-VMA lock, if it is a > bad access, directly handle error and return, there is no need to > lock_mm_and_find_vma() and check vm_flags again. > > Signed-off-by: Kefeng Wang Code-wise looks correct

Re: [PATCH 3/7] arm: mm: accelerate pagefault when VM_FAULT_BADACCESS

2024-04-02 Thread Suren Baghdasaryan
ff-by: Kefeng Wang Reviewed-by: Suren Baghdasaryan > --- > arch/arm/mm/fault.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c > index 439dc6a26bb9..5c4b417e24f9 100644 > --- a/arch/arm/mm/fault.c > ++

Re: [PATCH 2/7] arm64: mm: accelerate pagefault when VM_FAULT_BADACCESS

2024-04-02 Thread Suren Baghdasaryan
On Tue, Apr 2, 2024 at 10:19 PM Suren Baghdasaryan wrote: > > On Tue, Apr 2, 2024 at 12:53 AM Kefeng Wang > wrote: > > > > The vm_flags of vma already checked under per-VMA lock, if it is a > > bad access, directly set fault to VM_FAULT_BADACCESS an

Re: [PATCH 2/7] arm64: mm: accelerate pagefault when VM_FAULT_BADACCESS

2024-04-02 Thread Suren Baghdasaryan
34% in lmbench 'lat_sig -P 1 prot lat_sig'. The change makes sense to me. Per-VMA lock is enough to keep vma->vm_flags stable, so no need to retry with mmap_lock. > > Signed-off-by: Kefeng Wang Reviewed-by: Suren Baghdasaryan > --- > arch/arm64/mm/fault.c | 4 +++- > 1

Re: [PATCH 1/7] arm64: mm: cleanup __do_page_fault()

2024-04-02 Thread Suren Baghdasaryan
On Tue, Apr 2, 2024 at 12:53 AM Kefeng Wang wrote: > > The __do_page_fault() only check vma->flags and call handle_mm_fault(), > and only called by do_page_fault(), let's squash it into do_page_fault() > to cleanup code. > > Signed-off-by: Kefeng Wang Reviewed-b

Re: [PATCH 1/1] arch/arm/mm: fix major fault accounting when retrying under per-VMA lock

2024-01-25 Thread Suren Baghdasaryan
On Thu, Jan 25, 2024 at 6:04 PM Andrew Morton wrote: > > On Mon, 22 Jan 2024 22:43:05 -0800 Suren Baghdasaryan > wrote: > > > The change [1] missed ARM architecture when fixing major fault accounting > > for page fault retry under per-VMA lock. Add missing code to fix AR

Re: [PATCH 1/1] arch/mm/fault: fix major fault accounting when retrying under per-VMA lock

2024-01-22 Thread Suren Baghdasaryan
On Sun, Jan 21, 2024 at 11:38 PM Suren Baghdasaryan wrote: > > On Sat, Jan 20, 2024 at 1:15 PM Russell King (Oracle) > wrote: > > > > On Sat, Jan 20, 2024 at 09:09:47PM +, > > patchwork-bot+linux-ri...@kernel.org wrote: > > > Hello: > > > &g

[PATCH 1/1] arch/arm/mm: fix major fault accounting when retrying under per-VMA lock

2024-01-22 Thread Suren Baghdasaryan
a1992 ("mm: handle read faults under the VMA lock") Reported-by: Russell King (Oracle) Signed-off-by: Suren Baghdasaryan --- arch/arm/mm/fault.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index e96fb40b9cc3..07565b593ed6 100644 --- a

Re: [PATCH 1/1] arch/mm/fault: fix major fault accounting when retrying under per-VMA lock

2024-01-21 Thread Suren Baghdasaryan
On Sat, Jan 20, 2024 at 1:15 PM Russell King (Oracle) wrote: > > On Sat, Jan 20, 2024 at 09:09:47PM +, > patchwork-bot+linux-ri...@kernel.org wrote: > > Hello: > > > > This patch was applied to riscv/linux.git (fixes) > > by Andrew Morton : > > > > On Tue, 26 Dec 2023 13:46:10 -0800 you

[PATCH 1/1] arch/mm/fault: fix major fault accounting when retrying under per-VMA lock

2023-12-26 Thread Suren Baghdasaryan
://lore.kernel.org/all/20231006195318.4087158-6-wi...@infradead.org/ Fixes: 12214eba1992 ("mm: handle read faults under the VMA lock") Cc: Matthew Wilcox Signed-off-by: Suren Baghdasaryan --- arch/arm64/mm/fault.c | 2 ++ arch/powerpc/mm/fault.c | 2 ++ arch/riscv/mm/fault.c | 2 ++ ar

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-08-10 Thread Suren Baghdasaryan
On Wed, Aug 9, 2023 at 2:07 PM Mateusz Guzik wrote: > > On 8/5/23, Suren Baghdasaryan wrote: > > On Fri, Aug 4, 2023 at 6:06 PM Mateusz Guzik wrote: > >> > >> On 8/5/23, Linus Torvalds wrote: > >> > On Fri, 4 Aug 2023 at 16:25, Mateusz Guzik wrot

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-08-04 Thread Suren Baghdasaryan
On Fri, Aug 4, 2023 at 6:06 PM Mateusz Guzik wrote: > > On 8/5/23, Linus Torvalds wrote: > > On Fri, 4 Aug 2023 at 16:25, Mateusz Guzik wrote: > >> > >> I know of these guys, I think they are excluded as is -- they go > >> through access_remote_vm, starting with: > >> if

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-08-04 Thread Suren Baghdasaryan
On Fri, Aug 4, 2023 at 6:17 PM Mateusz Guzik wrote: > > On 8/5/23, Suren Baghdasaryan wrote: > > On Fri, Aug 4, 2023 at 5:49 PM Mateusz Guzik wrote: > >> However, the other users (that I know of ) go through the mmap > >> semaphore to mess with anyth

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-08-04 Thread Suren Baghdasaryan
On Fri, Aug 4, 2023 at 5:49 PM Mateusz Guzik wrote: > > On 8/5/23, Suren Baghdasaryan wrote: > > On Fri, Aug 4, 2023 at 5:26 PM Suren Baghdasaryan > > wrote: > >> > >> On Fri, Aug 4, 2023 at 5:15 PM Linus Torvalds > >> wrote: > >> >

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-08-04 Thread Suren Baghdasaryan
On Fri, Aug 4, 2023 at 5:26 PM Suren Baghdasaryan wrote: > > On Fri, Aug 4, 2023 at 5:15 PM Linus Torvalds > wrote: > > > > On Fri, 4 Aug 2023 at 16:25, Mateusz Guzik wrote: > > > > > > I know of these guys, I think they are excluded as is -- they go &

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-08-04 Thread Suren Baghdasaryan
On Fri, Aug 4, 2023 at 5:15 PM Linus Torvalds wrote: > > On Fri, 4 Aug 2023 at 16:25, Mateusz Guzik wrote: > > > > I know of these guys, I think they are excluded as is -- they go > > through access_remote_vm, starting with: > > if (mmap_read_lock_killable(mm)) > > return

Re: [PATCH rfc -next 01/10] mm: add a generic VMA lock-based page fault handler

2023-07-13 Thread Suren Baghdasaryan
On Thu, Jul 13, 2023 at 9:15 AM Matthew Wilcox wrote: > > > +int try_vma_locked_page_fault(struct vm_locked_fault *vmlf, vm_fault_t > > *ret) > > +{ > > + struct vm_area_struct *vma; > > + vm_fault_t fault; > > > On Thu, Jul 13, 2023 at 05:53:29PM +0800, Kefeng Wang wrote: > > +#define

Re: [PATCH v4 00/33] Per-VMA locks

2023-07-11 Thread Suren Baghdasaryan
> On Mon, Feb 27, 2023 at 09:35:59AM -0800, Suren Baghdasaryan wrote: > > > > > > > > <...> > > > > > > > >> Laurent Dufour (1): > > > >> powerc/mm: try VMA lock-based page fault handling first > > > > > >

Re: [PATCH] mm: lock newly mapped VMA with corrected ordering

2023-07-08 Thread Suren Baghdasaryan
On Sat, Jul 8, 2023 at 4:10 PM Suren Baghdasaryan wrote: > > On Sat, Jul 8, 2023 at 4:04 PM Hugh Dickins wrote: > > > > Lockdep is certainly right to complain about > > (>vm_lock->lock){}-{3:3}, at: vma_start_write+0x2d/0x3f > >

Re: [PATCH] mm: lock newly mapped VMA with corrected ordering

2023-07-08 Thread Suren Baghdasaryan
On Sat, Jul 8, 2023 at 4:04 PM Hugh Dickins wrote: > > Lockdep is certainly right to complain about > (>vm_lock->lock){}-{3:3}, at: vma_start_write+0x2d/0x3f >but task is already holding lock: > (>i_mmap_rwsem){+.+.}-{3:3}, at: mmap_region+0x4dc/0x6db > Invert those to the

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-07-08 Thread Suren Baghdasaryan
On Sat, Jul 8, 2023 at 3:54 PM Linus Torvalds wrote: > > On Sat, 8 Jul 2023 at 15:36, Suren Baghdasaryan wrote: > > > > On Sat, Jul 8, 2023 at 2:18 PM Linus Torvalds > > > > > > Again - maybe I messed up, but it really feels like the missing > >

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-07-08 Thread Suren Baghdasaryan
On Sat, Jul 8, 2023 at 2:18 PM Linus Torvalds wrote: > > On Sat, 8 Jul 2023 at 12:12, Suren Baghdasaryan wrote: > > > > kernel/fork.c | 1 + > > 1 file changed, 1 insertion(+) > > I ended up editing your explanation a lot. > > I'm not convinced that the bug

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-08 Thread Suren Baghdasaryan
On Sat, Jul 8, 2023 at 12:23 PM Linus Torvalds wrote: > > On Sat, 8 Jul 2023 at 12:17, Suren Baghdasaryan wrote: > > > > Do you want me to disable per-VMA locks by default as well? > > No. I seriously believe that if the per-vma locking is so broken that &

Re: [PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-07-08 Thread Suren Baghdasaryan
On Sat, Jul 8, 2023 at 12:12 PM Suren Baghdasaryan wrote: > > When forking a child process, parent write-protects an anonymous page > and COW-shares it with the child being forked using copy_present_pte(). > Parent's TLB is flushed right before we drop the parent's mmap_lock i

[PATCH v2 3/3] fork: lock VMAs of the parent process when forking

2023-07-08 Thread Suren Baghdasaryan
?id=217624 Fixes: 0bff0aaea03e ("x86/mm: try VMA lock-based page fault handling first") Cc: sta...@vger.kernel.org Signed-off-by: Suren Baghdasaryan --- kernel/fork.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/fork.c b/kernel/fork.c index b85814e614a5..d2e12b6d2

[PATCH v2 2/3] mm: lock newly mapped VMA which can be modified after it becomes visible

2023-07-08 Thread Suren Baghdasaryan
it into the VMA tree. Other places where a new VMA is added into VMA tree do not modify it after the insertion, so do not need the same locking. Cc: sta...@vger.kernel.org Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index

[PATCH v2 1/3] mm: lock a vma before stack expansion

2023-07-08 Thread Suren Baghdasaryan
With recent changes necessitating mmap_lock to be held for write while expanding a stack, per-VMA locks should follow the same rules and be write-locked to prevent page faults into the VMA being expanded. Add the necessary locking. Cc: sta...@vger.kernel.org Signed-off-by: Suren Baghdasaryan

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-08 Thread Suren Baghdasaryan
On Sat, Jul 8, 2023 at 11:05 AM Linus Torvalds wrote: > > On Sat, 8 Jul 2023 at 10:39, Andrew Morton wrote: > > > > That was the v1 fix, but after some discussion > > (https://lkml.kernel.org/r/20230705063711.2670599-1-sur...@google.com) > > it was decided to take the "excessive" approach. > >

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-05 Thread Suren Baghdasaryan
On Wed, Jul 5, 2023 at 9:14 AM Suren Baghdasaryan wrote: > > On Wed, Jul 5, 2023 at 8:49 AM Andrew Morton > wrote: > > > > On Wed, 5 Jul 2023 10:51:57 +0200 "Linux regression tracking (Thorsten > > Leemhuis)" wrote: > > > > > >>

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-05 Thread Suren Baghdasaryan
On Wed, Jul 5, 2023 at 8:49 AM Andrew Morton wrote: > > On Wed, 5 Jul 2023 10:51:57 +0200 "Linux regression tracking (Thorsten > Leemhuis)" wrote: > > > >>> I'm in wait-a-few-days-mode on this. To see if we have a backportable > > >>> fix rather than disabling the feature in -stable. > > > >

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-05 Thread Suren Baghdasaryan
On Tue, Jul 4, 2023 at 3:04 PM Suren Baghdasaryan wrote: > > On Tue, Jul 4, 2023 at 2:28 PM Andrew Morton > wrote: > > > > On Tue, 4 Jul 2023 13:22:54 -0700 Suren Baghdasaryan > > wrote: > > > > > On Tue, Jul 4, 2023 at 9:18 AM Andrew Morton >

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-04 Thread Suren Baghdasaryan
On Tue, Jul 4, 2023 at 2:28 PM Andrew Morton wrote: > > On Tue, 4 Jul 2023 13:22:54 -0700 Suren Baghdasaryan > wrote: > > > On Tue, Jul 4, 2023 at 9:18 AM Andrew Morton > > wrote: > > > > > > On Tue, 4 Jul 2023 09:00:19 +0100 Greg KH >

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-04 Thread Suren Baghdasaryan
On Tue, Jul 4, 2023 at 9:18 AM Andrew Morton wrote: > > On Tue, 4 Jul 2023 09:00:19 +0100 Greg KH wrote: > > > > > > > Thanks! I'll investigate this later today. After discussing with > > > > > > Andrew, we would like to disable CONFIG_PER_VMA_LOCK by default > > > > > > until > > > > > > the

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-04 Thread Suren Baghdasaryan
On Mon, Jul 3, 2023 at 11:44 AM Greg KH wrote: > > On Mon, Jul 03, 2023 at 11:27:19AM -0700, Suren Baghdasaryan wrote: > > On Mon, Jul 3, 2023 at 11:08 AM Suren Baghdasaryan > > wrote: > > > > > > On Mon, Jul 3, 2023 at 2:53 AM Linux regression track

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-03 Thread Suren Baghdasaryan
On Mon, Jul 3, 2023 at 11:08 AM Suren Baghdasaryan wrote: > > On Mon, Jul 3, 2023 at 2:53 AM Linux regression tracking (Thorsten > Leemhuis) wrote: > > > > On 02.07.23 14:27, Bagas Sanjaya wrote: > > > I notice a regression report on Bugzilla [1]. Quoting from it

Re: Fwd: Memory corruption in multithreaded user space program while calling fork

2023-07-03 Thread Suren Baghdasaryan
y memory corruption with either my > reproducer or the original program. > ``` > > FWIW: 0bff0aaea03 ("x86/mm: try VMA lock-based page fault handling > first") [merged for v6.4-rc1, authored by Suren Baghdasaryan [already CCed]] > > That's the same commit that

Re: [PATCH v4 29/33] x86/mm: try VMA lock-based page fault handling first

2023-06-30 Thread Suren Baghdasaryan
On Fri, Jun 30, 2023 at 1:43 AM Jiri Slaby wrote: > > On 30. 06. 23, 10:28, Jiri Slaby wrote: > > > 2348 > > clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, > > child_tid=0x7fcaa5882990,

Re: [PATCH v4 29/33] x86/mm: try VMA lock-based page fault handling first

2023-06-29 Thread Suren Baghdasaryan
On Thu, Jun 29, 2023 at 7:40 AM Jiri Slaby wrote: > > Hi, > > On 27. 02. 23, 18:36, Suren Baghdasaryan wrote: > > Attempt VMA lock-based page fault handling first, and fall back to the > > existing mmap_lock-based handling if that fails. > > > &g

Re: [PATCH v4 0/7] introduce vm_flags modifier functions

2023-03-17 Thread Suren Baghdasaryan
On Fri, Mar 17, 2023 at 3:41 PM Alex Williamson wrote: > > On Fri, 17 Mar 2023 12:08:32 -0700 > Suren Baghdasaryan wrote: > > > On Tue, Mar 14, 2023 at 1:11 PM Alex Williamson > > wrote: > > > > > > On Thu, 26 Jan 2023 11:37:45 -0800 > > > Sur

Re: [PATCH v4 0/7] introduce vm_flags modifier functions

2023-03-17 Thread Suren Baghdasaryan
On Tue, Mar 14, 2023 at 1:11 PM Alex Williamson wrote: > > On Thu, 26 Jan 2023 11:37:45 -0800 > Suren Baghdasaryan wrote: > > > This patchset was originally published as a part of per-VMA locking [1] and > > was split after suggestion that it's viable on its own and to f

Re: [PATCH v4 31/33] powerc/mm: try VMA lock-based page fault handling first

2023-03-06 Thread Suren Baghdasaryan
On Mon, Feb 27, 2023 at 9:37 AM Suren Baghdasaryan wrote: > > From: Laurent Dufour > > Attempt VMA lock-based page fault handling first, and fall back to the > existing mmap_lock-based handling if that fails. > Copied from "x86/mm: try VMA lock-based page fault han

Re: [PATCH] powerpc/mm: fix mmap_lock bad unlock

2023-03-06 Thread Suren Baghdasaryan
ry VMA lock-based page fault handling > >> first") > >> Reported-by: Sachin Sant > >> Link: > >> https://lore.kernel.org/linux-mm/842502fb-f99c-417c-9648-a37d0ecdc...@linux.ibm.com > >> Cc: Suren Baghdasaryan > >> Signed-off-by: Laurent Dufour >

Re: [PATCH 1/1] mm/nommu: remove unnecessary VMA locking

2023-03-03 Thread Suren Baghdasaryan
On Fri, Mar 3, 2023 at 1:05 AM David Hildenbrand wrote: > > >> > >> Just a general comment: usually, if review of the original series is > >> still going on, it makes a lot more sense to raise such things in the > >> original series so the author can fixup while things are still in > >>

Re: [PATCH 1/1] mm/nommu: remove unnecessary VMA locking

2023-03-02 Thread Suren Baghdasaryan
On Thu, Mar 2, 2023 at 1:41 AM David Hildenbrand wrote: > > On 01.03.23 20:04, Suren Baghdasaryan wrote: > > Since CONFIG_PER_VMA_LOCK depends on CONFIG_MMU, the changes in nommu > > are not needed. Remove them. > > > > Fixes: bad94decd6a4 ("mm: write-lock

Re: [PATCH v4 18/33] mm: write-lock VMAs before removing them from VMA tree

2023-03-01 Thread Suren Baghdasaryan
On Wed, Mar 1, 2023 at 4:54 PM Hyeonggon Yoo <42.hye...@gmail.com> wrote: > > On Wed, Mar 01, 2023 at 10:42:48AM -0800, Suren Baghdasaryan wrote: > > On Wed, Mar 1, 2023 at 10:34 AM Suren Baghdasaryan > > wrote: > > > > > > On Tue, Feb 28, 2023 at 1

Re: [PATCH v4 18/33] mm: write-lock VMAs before removing them from VMA tree

2023-03-01 Thread Suren Baghdasaryan
On Wed, Mar 1, 2023 at 10:34 AM Suren Baghdasaryan wrote: > > On Tue, Feb 28, 2023 at 11:57 PM Hyeonggon Yoo <42.hye...@gmail.com> wrote: > > > > On Wed, Mar 01, 2023 at 07:43:33AM +, Hyeonggon Yoo wrote: > > > On Mon, Feb 27, 2023 at 09:36:17AM -0800, Suren

[PATCH 1/1] mm/nommu: remove unnecessary VMA locking

2023-03-01 Thread Suren Baghdasaryan
ocalhost/ Signed-off-by: Suren Baghdasaryan --- Fix cleanly applies over mm-unstable, SHA in "Fixes" is from that tree. mm/nommu.c | 5 - 1 file changed, 5 deletions(-) diff --git a/mm/nommu.c b/mm/nommu.c index 2ab162d773e2..57ba243c6a37 100644 --- a/mm/nommu.c +++ b/mm/nommu.c

Re: [PATCH v4 18/33] mm: write-lock VMAs before removing them from VMA tree

2023-03-01 Thread Suren Baghdasaryan
On Wed, Mar 1, 2023 at 10:34 AM Suren Baghdasaryan wrote: > > On Tue, Feb 28, 2023 at 11:57 PM Hyeonggon Yoo <42.hye...@gmail.com> wrote: > > > > On Wed, Mar 01, 2023 at 07:43:33AM +, Hyeonggon Yoo wrote: > > > On Mon, Feb 27, 2023 at 09:36:17AM -0800, Suren

Re: [PATCH v4 18/33] mm: write-lock VMAs before removing them from VMA tree

2023-03-01 Thread Suren Baghdasaryan
On Tue, Feb 28, 2023 at 11:57 PM Hyeonggon Yoo <42.hye...@gmail.com> wrote: > > On Wed, Mar 01, 2023 at 07:43:33AM +, Hyeonggon Yoo wrote: > > On Mon, Feb 27, 2023 at 09:36:17AM -0800, Suren Baghdasaryan wrote: > > > Write-locking VMAs before isolating t

Re: [PATCH v2 00/33] Per-VMA locks

2023-02-28 Thread Suren Baghdasaryan
On Tue, Feb 28, 2023 at 4:06 AM Punit Agrawal wrote: > > Punit Agrawal writes: > > > Suren Baghdasaryan writes: > > > >> Previous version: > >> v1: https://lore.kernel.org/all/20230109205336.3665937-1-sur...@google.com/ > >> RFC: https:/

[PATCH v4 33/33] mm: separate vma->lock from vm_area_struct

2023-02-27 Thread Suren Baghdasaryan
k anymore. A number of drivers allocate a pseudo VMA on the stack but they never use the VMA's lock, therefore it does not need to be allocated. The future drivers which might need the VMA lock should use vm_area_alloc()/vm_area_free() to allocate the VMA. Signed-off-by: Suren Baghdasaryan --- incl

[PATCH v4 32/33] mm/mmap: free vm_area_struct without call_rcu in exit_mmap

2023-02-27 Thread Suren Baghdasaryan
caused by it. Signed-off-by: Suren Baghdasaryan --- include/linux/mm.h | 2 ++ kernel/fork.c | 2 +- mm/mmap.c | 11 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d07ac92f..5e142bfe7a58 100644

[PATCH v4 31/33] powerc/mm: try VMA lock-based page fault handling first

2023-02-27 Thread Suren Baghdasaryan
From: Laurent Dufour Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. Copied from "x86/mm: try VMA lock-based page fault handling first" Signed-off-by: Laurent Dufour Signed-off-by: Suren Baghdasaryan --- arch/

[PATCH v4 30/33] arm64/mm: try VMA lock-based page fault handling first

2023-02-27 Thread Suren Baghdasaryan
Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. Signed-off-by: Suren Baghdasaryan --- arch/arm64/Kconfig| 1 + arch/arm64/mm/fault.c | 36 2 files changed, 37 insertions(+) diff

[PATCH v4 29/33] x86/mm: try VMA lock-based page fault handling first

2023-02-27 Thread Suren Baghdasaryan
Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. Signed-off-by: Suren Baghdasaryan --- arch/x86/Kconfig| 1 + arch/x86/mm/fault.c | 36 2 files changed, 37 insertions(+) diff --git

[PATCH v4 28/33] mm: introduce per-VMA lock statistics

2023-02-27 Thread Suren Baghdasaryan
Add a new CONFIG_PER_VMA_LOCK_STATS config option to dump extra statistics about handling page fault under VMA lock. Signed-off-by: Suren Baghdasaryan --- include/linux/vm_event_item.h | 6 ++ include/linux/vmstat.h| 6 ++ mm/Kconfig.debug | 6 ++ mm/memory.c

[PATCH v4 27/33] mm: prevent userfaults to be handled under per-vma lock

2023-02-27 Thread Suren Baghdasaryan
Due to the possibility of handle_userfault dropping mmap_lock, avoid fault handling under VMA lock and retry holding mmap_lock. This can be handled more gracefully in the future. Signed-off-by: Suren Baghdasaryan Suggested-by: Peter Xu --- mm/memory.c | 9 + 1 file changed, 9

[PATCH v4 26/33] mm: prevent do_swap_page from handling page faults under VMA lock

2023-02-27 Thread Suren Baghdasaryan
Due to the possibility of do_swap_page dropping mmap_lock, abort fault handling under VMA lock and retry holding mmap_lock. This can be handled more gracefully in the future. Signed-off-by: Suren Baghdasaryan Reviewed-by: Laurent Dufour --- mm/memory.c | 5 + 1 file changed, 5 insertions

[PATCH v4 24/33] mm: fall back to mmap_lock if vma->anon_vma is not yet set

2023-02-27 Thread Suren Baghdasaryan
ed-off-by: Suren Baghdasaryan --- mm/memory.c | 4 1 file changed, 4 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index bda4c1a991f0..8855846a361b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5243,6 +5243,10 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_stru

[PATCH v4 25/33] mm: add FAULT_FLAG_VMA_LOCK flag

2023-02-27 Thread Suren Baghdasaryan
Add a new flag to distinguish page faults handled under protection of per-vma lock. Signed-off-by: Suren Baghdasaryan Reviewed-by: Laurent Dufour --- include/linux/mm.h | 3 ++- include/linux/mm_types.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux

[PATCH v4 23/33] mm: introduce lock_vma_under_rcu to be used from arch-specific code

2023-02-27 Thread Suren Baghdasaryan
is acquired. VMA lock statistics are updated according to the results. For now only anonymous VMAs can be searched this way. In other cases the function returns NULL. Signed-off-by: Suren Baghdasaryan --- include/linux/mm.h | 3 +++ mm/memory.c| 46

[PATCH v4 22/33] mm: introduce vma detached flag

2023-02-27 Thread Suren Baghdasaryan
Per-vma locking mechanism will search for VMA under RCU protection and then after locking it, has to ensure it was not removed from the VMA tree after we found it. To make this check efficient, introduce a vma->detached flag to mark VMAs which were removed from the VMA tree. Signed-off-by: Su

[PATCH v4 21/33] mm/mmap: prevent pagefault handler from racing with mmu_notifier registration

2023-02-27 Thread Suren Baghdasaryan
order as in page fault handlers. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 9 + 1 file changed, 9 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index ec745586785c..b947d82e8522 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3486,6 +3486,7 @@ static void vm_lock_mapping(struct

[PATCH v4 20/33] kernel/fork: assert no VMA readers during its destruction

2023-02-27 Thread Suren Baghdasaryan
Assert there are no holders of VMA lock for reading when it is about to be destroyed. Signed-off-by: Suren Baghdasaryan --- kernel/fork.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index e1dd79c7738c..bdb55f25895d 100644 --- a/kernel/fork.c +++ b/kernel

[PATCH v4 19/33] mm: conditionally write-lock VMA in free_pgtables

2023-02-27 Thread Suren Baghdasaryan
to free_pgtables for such scenario. Signed-off-by: Suren Baghdasaryan --- mm/internal.h | 2 +- mm/memory.c | 6 +- mm/mmap.c | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 08ce56dbb1d9..fce94775819c 100644 --- a/mm/internal.h +++ b/mm

[PATCH v4 18/33] mm: write-lock VMAs before removing them from VMA tree

2023-02-27 Thread Suren Baghdasaryan
Write-locking VMAs before isolating them ensures that page fault handlers don't operate on isolated VMAs. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 1 + mm/nommu.c | 5 + 2 files changed, 6 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 1f42b9a52b9b..f7ed357056c4 100644

[PATCH v4 17/33] mm/mremap: write-lock VMA while remapping it to a new address range

2023-02-27 Thread Suren Baghdasaryan
Write-lock VMA as locked before copying it and when copy_vma produces a new VMA. Signed-off-by: Suren Baghdasaryan Reviewed-by: Laurent Dufour --- mm/mmap.c | 1 + mm/mremap.c | 1 + 2 files changed, 2 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index e73fbb84ce12..1f42b9a52b9b 100644

[PATCH v4 16/33] mm/mmap: write-lock VMAs in vma_prepare before modifying them

2023-02-27 Thread Suren Baghdasaryan
Write-lock all VMAs which might be affected by a merge, split, expand or shrink operations. All these operations use vma_prepare() before making the modifications, therefore it provides a centralized place to perform VMA locking. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 10

[PATCH v4 15/33] mm/khugepaged: write-lock VMA while collapsing a huge page

2023-02-27 Thread Suren Baghdasaryan
a fourth lock under which page tables can be traversed, and so khugepaged must also lock out that one. Signed-off-by: Suren Baghdasaryan --- mm/khugepaged.c | 5 + mm/rmap.c | 31 --- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/mm

[PATCH v4 14/33] mm/mmap: move vma_prepare before vma_adjust_trans_huge

2023-02-27 Thread Suren Baghdasaryan
vma_prepare() acquires all locks required before VMA modifications. Move vma_prepare() before vma_adjust_trans_huge() so that VMA is locked before any modification. Signed-off-by: Suren Baghdasaryan --- mm/mmap.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm

[PATCH v4 13/33] mm: mark VMA as being written when changing vm_flags

2023-02-27 Thread Suren Baghdasaryan
Updates to vm_flags have to be done with VMA marked as being written for preventing concurrent page faults or other modifications. Signed-off-by: Suren Baghdasaryan --- include/linux/mm.h | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/mm.h b/include

[PATCH v4 12/33] mm: add per-VMA lock and helper functions to control it

2023-02-27 Thread Suren Baghdasaryan
ive mmap_lock is released by incrementing mm sequence counter (mm_lock_seq). - write downgrade - if the mmap_lock is downgraded to the read lock, all vma write locks are released as well (effectivelly same as write unlock). Signed-off-by: Suren Baghdasaryan --- include/linux/m

[PATCH v4 11/33] mm: move mmap_lock assert function definitions

2023-02-27 Thread Suren Baghdasaryan
Move mmap_lock assert function definitions up so that they can be used by other mmap_lock routines. Signed-off-by: Suren Baghdasaryan --- include/linux/mmap_lock.h | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/mmap_lock.h b/include

[PATCH v4 10/33] mm: rcu safe VMA freeing

2023-02-27 Thread Suren Baghdasaryan
From: Michel Lespinasse This prepares for page faults handling under VMA lock, looking up VMAs under protection of an rcu read lock, instead of the usual mmap read lock. Signed-off-by: Michel Lespinasse Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 13 ++--- kernel

[PATCH v4 09/33] mm: introduce CONFIG_PER_VMA_LOCK

2023-02-27 Thread Suren Baghdasaryan
needs modifications to handle faults under VMA lock. Signed-off-by: Suren Baghdasaryan --- mm/Kconfig | 12 1 file changed, 12 insertions(+) diff --git a/mm/Kconfig b/mm/Kconfig index ca98b2072df5..2e4a7e61768a 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1211,6 +1211,18 @@ config

[PATCH v4 08/33] mm: Enable maple tree RCU mode by default.

2023-02-27 Thread Suren Baghdasaryan
to ensure the nodes remain valid for readers. Signed-off-by: Liam R. Howlett Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 3 ++- kernel/fork.c| 3 +++ mm/mmap.c| 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/mm

[PATCH v4 07/33] maple_tree: Add RCU lock checking to rcu callback functions

2023-02-27 Thread Suren Baghdasaryan
and parent pointers. Fixes: 54a611b60590 ("Maple Tree: add new data structure") Reported-by: Suren Baghdasaryan Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 188 --- 1 file changed, 96 insertions(+), 92 deletions(-) diff --git a/li

[PATCH v4 06/33] maple_tree: Add smp_rmb() to dead node detection

2023-02-27 Thread Suren Baghdasaryan
re") Signed-off-by: Liam R. Howlett Signed-off-by: Suren Baghdasaryan --- lib/maple_tree.c | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 6b6eddadd9d2..8ad2d1669fad 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -539

[PATCH v4 05/33] maple_tree: Fix write memory barrier of nodes once dead for RCU mode

2023-02-27 Thread Suren Baghdasaryan
e RCU mode of the maple tree. Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett Signed-off-by: Suren Baghdasaryan --- lib/maple_tree.c | 7 +-- tools/testing/radix-tree/maple.c | 16 2 files changed, 21 insert

[PATCH v4 04/33] maple_tree: remove extra smp_wmb() from mas_dead_leaves()

2023-02-27 Thread Suren Baghdasaryan
From: Liam Howlett The call to mte_set_dead_node() before the smp_wmb() already calls smp_wmb() so this is not needed. This is an optimization for the RCU mode of the maple tree. Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam Howlett Signed-off

[PATCH v4 03/33] maple_tree: Fix freeing of nodes in rcu mode

2023-02-27 Thread Suren Baghdasaryan
Tree: add new data structure") Signed-off-by: Liam Howlett Signed-off-by: Suren Baghdasaryan --- lib/maple_tree.c | 73 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 089cd76ec379..44

[PATCH v4 02/33] maple_tree: Detect dead nodes in mas_start()

2023-02-27 Thread Suren Baghdasaryan
t;) Signed-off-by: Liam Howlett Signed-off-by: Suren Baghdasaryan --- lib/maple_tree.c | 4 1 file changed, 4 insertions(+) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index cc356b8369ad..089cd76ec379 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1360,12 +1360,16 @@ sta

[PATCH v4 01/33] maple_tree: Be more cautious about dead nodes

2023-02-27 Thread Suren Baghdasaryan
am Howlett Signed-off-by: Suren Baghdasaryan --- lib/maple_tree.c | 52 +++- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 646297cae5d1..cc356b8369ad 100644 --- a/lib/maple_tree.c +++ b/lib/ma

[PATCH v4 00/33] Per-VMA locks

2023-02-27 Thread Suren Baghdasaryan
maple_tree: Fix write memory barrier of nodes once dead for RCU mode maple_tree: Add smp_rmb() to dead node detection maple_tree: Add RCU lock checking to rcu callback functions mm: Enable maple tree RCU mode by default. Michel Lespinasse (1): mm: rcu safe VMA freeing Suren Baghdasaryan (23):

Re: [PATCH v3 17/35] mm/mmap: write-lock VMA before shrinking or expanding it

2023-02-27 Thread Suren Baghdasaryan
On Fri, Feb 24, 2023 at 8:19 AM Suren Baghdasaryan wrote: > > On Fri, Feb 24, 2023 at 8:14 AM Liam R. Howlett > wrote: > > > > * Suren Baghdasaryan [230223 21:06]: > > > On Thu, Feb 23, 2023 at 5:46 PM Liam R. Howlett > > > wrote: > > &g

Re: [PATCH v3 00/35] Per-VMA locks

2023-02-27 Thread Suren Baghdasaryan
On Mon, Feb 27, 2023 at 9:19 AM Davidlohr Bueso wrote: > > On Fri, 24 Feb 2023, freak07 wrote: > > >Here are some measurements from a Pixel 7 Pro that´s running a kernel either > >with the Per-VMA locks patchset or without. > >If there´s interest I can provide results of other specific apps as

Re: [PATCH v3 17/35] mm/mmap: write-lock VMA before shrinking or expanding it

2023-02-24 Thread Suren Baghdasaryan
On Fri, Feb 24, 2023 at 8:14 AM Liam R. Howlett wrote: > > * Suren Baghdasaryan [230223 21:06]: > > On Thu, Feb 23, 2023 at 5:46 PM Liam R. Howlett > > wrote: > > > > > > * Suren Baghdasaryan [230223 16:16]: > > > > On Thu, Feb 23,

Re: [PATCH v3 17/35] mm/mmap: write-lock VMA before shrinking or expanding it

2023-02-23 Thread Suren Baghdasaryan
On Thu, Feb 23, 2023 at 5:46 PM Liam R. Howlett wrote: > > * Suren Baghdasaryan [230223 16:16]: > > On Thu, Feb 23, 2023 at 12:28 PM Liam R. Howlett > > wrote: > > > > > > > > > Wait, I figured a better place to do this. > > > > >

Re: [PATCH v3 17/35] mm/mmap: write-lock VMA before shrinking or expanding it

2023-02-23 Thread Suren Baghdasaryan
: > > Reviewed-by: Liam R. Howlett > > > > * Suren Baghdasaryan [230216 00:18]: > > > vma_expand and vma_shrink change VMA boundaries. Expansion might also > > > result in freeing of an adjacent VMA. Write-lock affected VMAs to prevent > > > concurrent page fa

Re: [PATCH v3 24/35] mm: introduce vma detached flag

2023-02-23 Thread Suren Baghdasaryan
nd meets your usecase? > > * Suren Baghdasaryan [230216 00:18]: > > Per-vma locking mechanism will search for VMA under RCU protection and > > then after locking it, has to ensure it was not removed from the VMA > > tree after we found it. To make this check efficient, introduce a &

Re: [PATCH v3 23/35] mm/mmap: prevent pagefault handler from racing with mmu_notifier registration

2023-02-23 Thread Suren Baghdasaryan
On Thu, Feb 23, 2023 at 12:06 PM Liam R. Howlett wrote: > > * Suren Baghdasaryan [230216 00:18]: > > Page fault handlers might need to fire MMU notifications while a new > > notifier is being registered. Modify mm_take_all_locks to write-lock all > > VMAs and prevent t

Re: [PATCH v3 26/35] mm: fall back to mmap_lock if vma->anon_vma is not yet set

2023-02-17 Thread Suren Baghdasaryan
On Fri, Feb 17, 2023 at 2:21 AM Hyeonggon Yoo <42.hye...@gmail.com> wrote: > > On Fri, Feb 17, 2023 at 11:15 AM Suren Baghdasaryan wrote: > > > > On Thu, Feb 16, 2023 at 11:43 AM Suren Baghdasaryan > > wrote: > > > > > > On Thu, Feb

Re: [PATCH v3 26/35] mm: fall back to mmap_lock if vma->anon_vma is not yet set

2023-02-17 Thread Suren Baghdasaryan
On Fri, Feb 17, 2023 at 8:05 AM Matthew Wilcox wrote: > > On Thu, Feb 16, 2023 at 06:14:59PM -0800, Suren Baghdasaryan wrote: > > On Thu, Feb 16, 2023 at 11:43 AM Suren Baghdasaryan > > wrote: > > > > > > On Thu, Feb 16, 2023 at 7:44 AM Matthew Wilcox >

Re: [PATCH v3 21/35] mm/mmap: write-lock adjacent VMAs if they can grow into unmapped area

2023-02-17 Thread Suren Baghdasaryan
On Fri, Feb 17, 2023 at 6:51 AM Liam R. Howlett wrote: > > * Suren Baghdasaryan [230216 14:36]: > > On Thu, Feb 16, 2023 at 7:34 AM Liam R. Howlett > > wrote: > > > > > > > > > First, sorry I didn't see this before v3.. >

Re: [PATCH v3 26/35] mm: fall back to mmap_lock if vma->anon_vma is not yet set

2023-02-16 Thread Suren Baghdasaryan
On Thu, Feb 16, 2023 at 11:43 AM Suren Baghdasaryan wrote: > > On Thu, Feb 16, 2023 at 7:44 AM Matthew Wilcox wrote: > > > > On Wed, Feb 15, 2023 at 09:17:41PM -0800, Suren Baghdasaryan wrote: > > > When vma->anon_vma is not set, page fault handler will set it by

Re: [PATCH v3 26/35] mm: fall back to mmap_lock if vma->anon_vma is not yet set

2023-02-16 Thread Suren Baghdasaryan
On Thu, Feb 16, 2023 at 7:44 AM Matthew Wilcox wrote: > > On Wed, Feb 15, 2023 at 09:17:41PM -0800, Suren Baghdasaryan wrote: > > When vma->anon_vma is not set, page fault handler will set it by either > > reusing anon_vma of an adjacent VMA if VMAs are compatible or by >

Re: [PATCH v3 21/35] mm/mmap: write-lock adjacent VMAs if they can grow into unmapped area

2023-02-16 Thread Suren Baghdasaryan
On Thu, Feb 16, 2023 at 7:34 AM Liam R. Howlett wrote: > > > First, sorry I didn't see this before v3.. Feedback at any time is highly appreciated! > > * Suren Baghdasaryan [230216 00:18]: > > While unmapping VMAs, adjacent VMAs might be able to grow into the ar

  1   2   3   4   >