* [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
@ 2026-11-24 12:26 Lorenzo Stoakes (ARM)
2026-11-24 13:04 ` Pedro Falcato
0 siblings, 1 reply; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-24 12:26 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Kees Cook, David Hildenbrand,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Andrew Morton, Suren Baghdasaryan, Shakeel Butt, Pedro Falcato,
Jann Horn, Puranjay Mohan, Alexei Starovoitov
Cc: linux-mm, linux-kernel, bpf, ljs, Chris Mason, stable
Commit bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to
per-VMA locks") open-codes a lock_next_vma() implementation that does
roughly the same thing in bpf_iter_task_vma_find_next(), only without
fallback to an mmap_lock.
This is because bpf_iter_task_vma_find_next() can be called from
non-sleepable contexts.
However, lock_vma_under_rcu() gave no guarantee as to which contexts it is
safe to be called from, and indeed it turns out this assumption is unsafe.
Since commit 9bbffee67ffd ("mm: fix a UAF when vma->mm is freed after
vma->vm_refcnt got dropped"), this call chain is possible on x86:
lock_vma_under_rcu()
-> vma_start_read()
-> mmdrop()
-> __mmdrop()
-> mm_free_pgd()
-> pgd_free()
-> pgd_dtor()
-> spin_lock(&pgd_lock)
Thus, a plain spin_lock() can occur when lock_vma_under_rcu() is
called. Since bpf_iter_task_vma_find_next() can be called in softirq
context, this can deadlock, for example:
pgd_alloc()
-> spin_lock(&pgd_lock)
<softirq>
bpf_iter_task_vma_next()
-> lock_vma_under_rcu()
...
-> spin_lock(&pgd_lock) [ DEADLOCK ]
Alexei Starovoitov also pointed out that a BPF program attached to
trace_contention_end() can similarly cause a deadlock:
pgd_alloc()
spin_lock(&pgd_lock)
queued_spin_lock_slowpath()
trace_contention_end() <- pgd_lock is held
tp_btf/contention_end prog
bpf_iter_task_vma_next()
lock_vma_under_rcu()
vma_start_read()
mmdrop(other_mm) <- last put takes pgd_lock again
Resolve the issue by having vma_start_read() use mmdrop_async() instead of
mmdrop() so the work is deferred to a work queue.
Make mmdrop_async() an internal mm function, defined in mm/internal.h, to
avoid abuse elsewhere (kernel/fork.c includes this header, so still retains
access).
Commit 0b16f8bed19c ("mm: change vma_start_read() to drop RCU lock on
failure") accounted for the fact that the RCU lock had to be dropped for
this operation, which is no longer applicable.
For the sake of a backported fix, retain this behaviour, however drop the
RCU lock last and remove the now irrelevant comment.
Reported-by: Chris Mason <mason@kernel.org>
Fixes: bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to per-VMA locks")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/DN267JUKDRNS.2VMV07CQ58R4X@gmail.com/
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
---
kernel/fork.c | 16 ----------------
mm/internal.h | 3 +++
mm/mmap_lock.c | 21 ++++++++++++++++++---
3 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 5efceb8d58a7..4d5866c83481 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -744,22 +744,6 @@ void __mmdrop(struct mm_struct *mm)
}
EXPORT_SYMBOL_GPL(__mmdrop);
-static void mmdrop_async_fn(struct work_struct *work)
-{
- struct mm_struct *mm;
-
- mm = container_of(work, struct mm_struct, async_put_work);
- __mmdrop(mm);
-}
-
-static void mmdrop_async(struct mm_struct *mm)
-{
- if (unlikely(atomic_dec_and_test(&mm->mm_count))) {
- INIT_WORK(&mm->async_put_work, mmdrop_async_fn);
- schedule_work(&mm->async_put_work);
- }
-}
-
static inline void free_signal_struct(struct signal_struct *sig)
{
taskstats_tgid_free(sig);
diff --git a/mm/internal.h b/mm/internal.h
index de4593b3e3b6..cc95019c7e4b 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1671,4 +1671,7 @@ static inline bool can_spin_trylock(void)
/* char-mem.c */
bool file_is_dev_zero(const struct file *file);
+/* mmap_lock.c */
+void mmdrop_async(struct mm_struct *mm);
+
#endif /* __MM_INTERNAL_H */
diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
index 073c5125b424..28b387fe543a 100644
--- a/mm/mmap_lock.c
+++ b/mm/mmap_lock.c
@@ -306,11 +306,10 @@ static struct vm_area_struct *vma_start_read(struct mm_struct *mm,
*/
other_mm = vma->vm_mm; /* use a copy as vma can be freed after we drop vm_refcnt */
- /* __mmdrop() is a heavy operation, do it after dropping RCU lock. */
- rcu_read_unlock();
mmgrab(other_mm);
vma_refcount_put(vma);
- mmdrop(other_mm);
+ mmdrop_async(other_mm);
+ rcu_read_unlock();
return NULL;
}
@@ -560,6 +559,22 @@ void __mm_reset_vma_seqcounts(struct mm_struct *mm)
}
EXPORT_SYMBOL(__mm_reset_vma_seqcounts);
+static void mmdrop_async_fn(struct work_struct *work)
+{
+ struct mm_struct *mm;
+
+ mm = container_of(work, struct mm_struct, async_put_work);
+ __mmdrop(mm);
+}
+
+void mmdrop_async(struct mm_struct *mm)
+{
+ if (unlikely(atomic_dec_and_test(&mm->mm_count))) {
+ INIT_WORK(&mm->async_put_work, mmdrop_async_fn);
+ schedule_work(&mm->async_put_work);
+ }
+}
+
#ifdef CONFIG_LOCK_MM_AND_FIND_VMA
#include <linux/extable.h>
---
base-commit: 913390e679e23e3a45643028ee7f992889094051
change-id: 20261124-vma-read-lock-mmdrop-async-ba417cd1c1f0
Cheers,
--
Lorenzo Stoakes (ARM) <ljs@kernel.org>
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 12:26 [PATCH] mm/vma: drop mm asynchronously in vma_start_read() Lorenzo Stoakes (ARM)
@ 2026-11-24 13:04 ` Pedro Falcato
2026-11-24 15:46 ` Suren Baghdasaryan
0 siblings, 1 reply; 10+ messages in thread
From: Pedro Falcato @ 2026-11-24 13:04 UTC (permalink / raw)
To: Lorenzo Stoakes (ARM)
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Valentin Schneider, K Prateek Nayak, Kees Cook, David Hildenbrand,
Liam R. Howlett, Vlastimil Babka, Mike Rapoport, Michal Hocko,
Andrew Morton, Suren Baghdasaryan, Shakeel Butt, Jann Horn,
Puranjay Mohan, Alexei Starovoitov, linux-mm, linux-kernel, bpf,
Chris Mason, stable
On Tue, Nov 24, 2026 at 12:26:19PM +0000, Lorenzo Stoakes (ARM) wrote:
> Commit bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to
> per-VMA locks") open-codes a lock_next_vma() implementation that does
> roughly the same thing in bpf_iter_task_vma_find_next(), only without
> fallback to an mmap_lock.
>
> This is because bpf_iter_task_vma_find_next() can be called from
> non-sleepable contexts.
>
> However, lock_vma_under_rcu() gave no guarantee as to which contexts it is
> safe to be called from, and indeed it turns out this assumption is unsafe.
>
> Since commit 9bbffee67ffd ("mm: fix a UAF when vma->mm is freed after
> vma->vm_refcnt got dropped"), this call chain is possible on x86:
>
> lock_vma_under_rcu()
> -> vma_start_read()
> -> mmdrop()
> -> __mmdrop()
> -> mm_free_pgd()
> -> pgd_free()
> -> pgd_dtor()
> -> spin_lock(&pgd_lock)
>
> Thus, a plain spin_lock() can occur when lock_vma_under_rcu() is
> called. Since bpf_iter_task_vma_find_next() can be called in softirq
> context, this can deadlock, for example:
>
> pgd_alloc()
> -> spin_lock(&pgd_lock)
> <softirq>
> bpf_iter_task_vma_next()
> -> lock_vma_under_rcu()
> ...
> -> spin_lock(&pgd_lock) [ DEADLOCK ]
>
> Alexei Starovoitov also pointed out that a BPF program attached to
> trace_contention_end() can similarly cause a deadlock:
>
> pgd_alloc()
> spin_lock(&pgd_lock)
> queued_spin_lock_slowpath()
> trace_contention_end() <- pgd_lock is held
> tp_btf/contention_end prog
> bpf_iter_task_vma_next()
> lock_vma_under_rcu()
> vma_start_read()
> mmdrop(other_mm) <- last put takes pgd_lock again
>
> Resolve the issue by having vma_start_read() use mmdrop_async() instead of
> mmdrop() so the work is deferred to a work queue.
>
> Make mmdrop_async() an internal mm function, defined in mm/internal.h, to
> avoid abuse elsewhere (kernel/fork.c includes this header, so still retains
> access).
>
> Commit 0b16f8bed19c ("mm: change vma_start_read() to drop RCU lock on
> failure") accounted for the fact that the RCU lock had to be dropped for
> this operation, which is no longer applicable.
>
> For the sake of a backported fix, retain this behaviour, however drop the
> RCU lock last and remove the now irrelevant comment.
Is there any particular reason for unlocking the RCU comment last? after the mmdrop_async().
>
> Reported-by: Chris Mason <mason@kernel.org>
> Fixes: bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to per-VMA locks")
> Cc: stable@vger.kernel.org
> Link: https://lore.kernel.org/all/DN267JUKDRNS.2VMV07CQ58R4X@gmail.com/
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: Pedro Falcato <pfalcato@suse.de>
--
Pedro
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 13:04 ` Pedro Falcato
@ 2026-11-24 15:46 ` Suren Baghdasaryan
2026-11-24 15:51 ` Suren Baghdasaryan
2026-11-24 15:56 ` Lorenzo Stoakes (ARM)
0 siblings, 2 replies; 10+ messages in thread
From: Suren Baghdasaryan @ 2026-11-24 15:46 UTC (permalink / raw)
To: Pedro Falcato
Cc: Lorenzo Stoakes (ARM), Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, K Prateek Nayak, Kees Cook,
David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, Shakeel Butt,
Jann Horn, Puranjay Mohan, Alexei Starovoitov, linux-mm,
linux-kernel, bpf, Chris Mason, stable
On Tue, Nov 24, 2026 at 5:04 AM Pedro Falcato <pfalcato@suse.de> wrote:
>
> On Tue, Nov 24, 2026 at 12:26:19PM +0000, Lorenzo Stoakes (ARM) wrote:
> > Commit bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to
> > per-VMA locks") open-codes a lock_next_vma() implementation that does
> > roughly the same thing in bpf_iter_task_vma_find_next(), only without
> > fallback to an mmap_lock.
> >
> > This is because bpf_iter_task_vma_find_next() can be called from
> > non-sleepable contexts.
> >
> > However, lock_vma_under_rcu() gave no guarantee as to which contexts it is
> > safe to be called from, and indeed it turns out this assumption is unsafe.
> >
> > Since commit 9bbffee67ffd ("mm: fix a UAF when vma->mm is freed after
> > vma->vm_refcnt got dropped"), this call chain is possible on x86:
> >
> > lock_vma_under_rcu()
> > -> vma_start_read()
> > -> mmdrop()
> > -> __mmdrop()
> > -> mm_free_pgd()
> > -> pgd_free()
> > -> pgd_dtor()
> > -> spin_lock(&pgd_lock)
> >
> > Thus, a plain spin_lock() can occur when lock_vma_under_rcu() is
> > called. Since bpf_iter_task_vma_find_next() can be called in softirq
> > context, this can deadlock, for example:
> >
> > pgd_alloc()
> > -> spin_lock(&pgd_lock)
> > <softirq>
> > bpf_iter_task_vma_next()
> > -> lock_vma_under_rcu()
> > ...
> > -> spin_lock(&pgd_lock) [ DEADLOCK ]
> >
> > Alexei Starovoitov also pointed out that a BPF program attached to
> > trace_contention_end() can similarly cause a deadlock:
> >
> > pgd_alloc()
> > spin_lock(&pgd_lock)
> > queued_spin_lock_slowpath()
> > trace_contention_end() <- pgd_lock is held
> > tp_btf/contention_end prog
> > bpf_iter_task_vma_next()
> > lock_vma_under_rcu()
> > vma_start_read()
> > mmdrop(other_mm) <- last put takes pgd_lock again
> >
> > Resolve the issue by having vma_start_read() use mmdrop_async() instead of
> > mmdrop() so the work is deferred to a work queue.
> >
> > Make mmdrop_async() an internal mm function, defined in mm/internal.h, to
> > avoid abuse elsewhere (kernel/fork.c includes this header, so still retains
> > access).
> >
> > Commit 0b16f8bed19c ("mm: change vma_start_read() to drop RCU lock on
> > failure") accounted for the fact that the RCU lock had to be dropped for
> > this operation, which is no longer applicable.
> >
> > For the sake of a backported fix, retain this behaviour, however drop the
> > RCU lock last and remove the now irrelevant comment.
>
> Is there any particular reason for unlocking the RCU comment last? after the mmdrop_async().
Yeah, I think moving the RCU unlocking was unnecessary (unlock as soon
as possible is in general advisable) and we could just remove the
comment. Both versions however seem correct to me.
>
> >
> > Reported-by: Chris Mason <mason@kernel.org>
> > Fixes: bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to per-VMA locks")
> > Cc: stable@vger.kernel.org
> > Link: https://lore.kernel.org/all/DN267JUKDRNS.2VMV07CQ58R4X@gmail.com/
> > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
>
> Acked-by: Pedro Falcato <pfalcato@suse.de>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
>
> --
> Pedro
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 15:46 ` Suren Baghdasaryan
@ 2026-11-24 15:51 ` Suren Baghdasaryan
2026-11-24 15:58 ` Lorenzo Stoakes (ARM)
2026-11-24 15:56 ` Lorenzo Stoakes (ARM)
1 sibling, 1 reply; 10+ messages in thread
From: Suren Baghdasaryan @ 2026-11-24 15:51 UTC (permalink / raw)
To: Pedro Falcato
Cc: Lorenzo Stoakes (ARM), Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, K Prateek Nayak, Kees Cook,
David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, Shakeel Butt,
Jann Horn, Puranjay Mohan, Alexei Starovoitov, linux-mm,
linux-kernel, bpf, Chris Mason, stable
On Tue, Nov 24, 2026 at 7:46 AM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Tue, Nov 24, 2026 at 5:04 AM Pedro Falcato <pfalcato@suse.de> wrote:
> >
> > On Tue, Nov 24, 2026 at 12:26:19PM +0000, Lorenzo Stoakes (ARM) wrote:
> > > Commit bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to
> > > per-VMA locks") open-codes a lock_next_vma() implementation that does
> > > roughly the same thing in bpf_iter_task_vma_find_next(), only without
> > > fallback to an mmap_lock.
> > >
> > > This is because bpf_iter_task_vma_find_next() can be called from
> > > non-sleepable contexts.
> > >
> > > However, lock_vma_under_rcu() gave no guarantee as to which contexts it is
> > > safe to be called from, and indeed it turns out this assumption is unsafe.
> > >
> > > Since commit 9bbffee67ffd ("mm: fix a UAF when vma->mm is freed after
> > > vma->vm_refcnt got dropped"), this call chain is possible on x86:
> > >
> > > lock_vma_under_rcu()
> > > -> vma_start_read()
> > > -> mmdrop()
> > > -> __mmdrop()
> > > -> mm_free_pgd()
> > > -> pgd_free()
> > > -> pgd_dtor()
> > > -> spin_lock(&pgd_lock)
> > >
> > > Thus, a plain spin_lock() can occur when lock_vma_under_rcu() is
> > > called. Since bpf_iter_task_vma_find_next() can be called in softirq
> > > context, this can deadlock, for example:
> > >
> > > pgd_alloc()
> > > -> spin_lock(&pgd_lock)
> > > <softirq>
> > > bpf_iter_task_vma_next()
> > > -> lock_vma_under_rcu()
> > > ...
> > > -> spin_lock(&pgd_lock) [ DEADLOCK ]
> > >
> > > Alexei Starovoitov also pointed out that a BPF program attached to
> > > trace_contention_end() can similarly cause a deadlock:
> > >
> > > pgd_alloc()
> > > spin_lock(&pgd_lock)
> > > queued_spin_lock_slowpath()
> > > trace_contention_end() <- pgd_lock is held
> > > tp_btf/contention_end prog
> > > bpf_iter_task_vma_next()
> > > lock_vma_under_rcu()
> > > vma_start_read()
> > > mmdrop(other_mm) <- last put takes pgd_lock again
> > >
> > > Resolve the issue by having vma_start_read() use mmdrop_async() instead of
> > > mmdrop() so the work is deferred to a work queue.
> > >
> > > Make mmdrop_async() an internal mm function, defined in mm/internal.h, to
> > > avoid abuse elsewhere (kernel/fork.c includes this header, so still retains
> > > access).
> > >
> > > Commit 0b16f8bed19c ("mm: change vma_start_read() to drop RCU lock on
> > > failure") accounted for the fact that the RCU lock had to be dropped for
> > > this operation, which is no longer applicable.
> > >
> > > For the sake of a backported fix, retain this behaviour, however drop the
> > > RCU lock last and remove the now irrelevant comment.
> >
> > Is there any particular reason for unlocking the RCU comment last? after the mmdrop_async().
>
> Yeah, I think moving the RCU unlocking was unnecessary (unlock as soon
> as possible is in general advisable) and we could just remove the
> comment. Both versions however seem correct to me.
Actually, VMAs are allocated from a SLAB_TYPESAFE_BY_RCU slub. With
that RCU unlocking move you don't need other_mm copy and the comment
that comes with it. VMA won't be freed until RCU lock is dropped.
>
> >
> > >
> > > Reported-by: Chris Mason <mason@kernel.org>
> > > Fixes: bee9ef4a40a2 ("bpf: switch task_vma iterator from mmap_lock to per-VMA locks")
> > > Cc: stable@vger.kernel.org
> > > Link: https://lore.kernel.org/all/DN267JUKDRNS.2VMV07CQ58R4X@gmail.com/
> > > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> >
> > Acked-by: Pedro Falcato <pfalcato@suse.de>
>
> Reviewed-by: Suren Baghdasaryan <surenb@google.com>
>
> >
> > --
> > Pedro
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 15:46 ` Suren Baghdasaryan
2026-11-24 15:51 ` Suren Baghdasaryan
@ 2026-11-24 15:56 ` Lorenzo Stoakes (ARM)
1 sibling, 0 replies; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-24 15:56 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: Pedro Falcato, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, K Prateek Nayak, Kees Cook,
David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, Shakeel Butt,
Jann Horn, Puranjay Mohan, Alexei Starovoitov, linux-mm,
linux-kernel, bpf, Chris Mason, stable
On Tue, Nov 24, 2026 at 07:46:04AM -0800, Suren Baghdasaryan wrote:
> On Tue, Nov 24, 2026 at 5:04 AM Pedro Falcato <pfalcato@suse.de> wrote:
> > Is there any particular reason for unlocking the RCU comment last? after the mmdrop_async().
>
> Yeah, I think moving the RCU unlocking was unnecessary (unlock as soon
> as possible is in general advisable) and we could just remove the
> comment. Both versions however seem correct to me.
For simplicity. 'The operation is done under an RCU lock' :)
I alluded above, but intent is to revert 0b16f8bed19c which I _think_ is
fine. And at that point it actively simplifies.
The operations done there are only done in a rare scenario (VMA recycled) and
now the extra bits done under RCU there are really quite small so I think fine.
I will follow up on that later.
> > Acked-by: Pedro Falcato <pfalcato@suse.de>
>
> Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Thanks x2!
>
> >
> > --
> > Pedro
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 15:51 ` Suren Baghdasaryan
@ 2026-11-24 15:58 ` Lorenzo Stoakes (ARM)
2026-11-24 16:05 ` Puranjay Mohan
0 siblings, 1 reply; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-24 15:58 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: Pedro Falcato, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Valentin Schneider, K Prateek Nayak, Kees Cook,
David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, Shakeel Butt,
Jann Horn, Puranjay Mohan, Alexei Starovoitov, linux-mm,
linux-kernel, bpf, Chris Mason, stable
On Tue, Nov 24, 2026 at 07:51:42AM -0800, Suren Baghdasaryan wrote:
> Actually, VMAs are allocated from a SLAB_TYPESAFE_BY_RCU slub. With
> that RCU unlocking move you don't need other_mm copy and the comment
> that comes with it. VMA won't be freed until RCU lock is dropped.
Yeah but they can be reassigned? They won't be _freed_ until a grace period but
they can go back to the slab and then allocated elsewhere right?
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 15:58 ` Lorenzo Stoakes (ARM)
@ 2026-11-24 16:05 ` Puranjay Mohan
2026-11-24 16:34 ` Suren Baghdasaryan
0 siblings, 1 reply; 10+ messages in thread
From: Puranjay Mohan @ 2026-11-24 16:05 UTC (permalink / raw)
To: Lorenzo Stoakes (ARM)
Cc: Suren Baghdasaryan, Pedro Falcato, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Kees Cook, David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, Shakeel Butt,
Jann Horn, Alexei Starovoitov, linux-mm, linux-kernel, bpf,
Chris Mason, stable
On Tue, Nov 24, 2026 at 9:28 PM Lorenzo Stoakes (ARM) <ljs@kernel.org> wrote:
>
> On Tue, Nov 24, 2026 at 07:51:42AM -0800, Suren Baghdasaryan wrote:
> > Actually, VMAs are allocated from a SLAB_TYPESAFE_BY_RCU slub. With
> > that RCU unlocking move you don't need other_mm copy and the comment
> > that comes with it. VMA won't be freed until RCU lock is dropped.
>
> Yeah but they can be reassigned? They won't be _freed_ until a grace period but
> they can go back to the slab and then allocated elsewhere right?
>
Yes, they can go back to the slab and become a different VMA.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 16:05 ` Puranjay Mohan
@ 2026-11-24 16:34 ` Suren Baghdasaryan
2026-11-24 17:23 ` Lorenzo Stoakes (ARM)
0 siblings, 1 reply; 10+ messages in thread
From: Suren Baghdasaryan @ 2026-11-24 16:34 UTC (permalink / raw)
To: Puranjay Mohan
Cc: Lorenzo Stoakes (ARM), Pedro Falcato, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Kees Cook, David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, Shakeel Butt,
Jann Horn, Alexei Starovoitov, linux-mm, linux-kernel, bpf,
Chris Mason, stable
On Tue, Nov 24, 2026 at 8:06 AM Puranjay Mohan <puranjay12@gmail.com> wrote:
>
> On Tue, Nov 24, 2026 at 9:28 PM Lorenzo Stoakes (ARM) <ljs@kernel.org> wrote:
> >
> > On Tue, Nov 24, 2026 at 07:51:42AM -0800, Suren Baghdasaryan wrote:
> > > Actually, VMAs are allocated from a SLAB_TYPESAFE_BY_RCU slub. With
> > > that RCU unlocking move you don't need other_mm copy and the comment
> > > that comes with it. VMA won't be freed until RCU lock is dropped.
> >
> > Yeah but they can be reassigned? They won't be _freed_ until a grace period but
> > they can go back to the slab and then allocated elsewhere right?
> >
>
> Yes, they can go back to the slab and become a different VMA.
Yeah, you are right about that. So, we either have to keep the RCU
unlock in place to keep other_mm comment valid (my personal
preference) or update the comment next to other_mm to explain the new
reason it is needed. Either way is fine with me.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 16:34 ` Suren Baghdasaryan
@ 2026-11-24 17:23 ` Lorenzo Stoakes (ARM)
2026-11-24 17:33 ` Andrew Morton
0 siblings, 1 reply; 10+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-24 17:23 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: Puranjay Mohan, Pedro Falcato, Ingo Molnar, Peter Zijlstra,
Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
Kees Cook, David Hildenbrand, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Michal Hocko, Andrew Morton, Shakeel Butt,
Jann Horn, Alexei Starovoitov, linux-mm, linux-kernel, bpf,
Chris Mason, stable
On Tue, Nov 24, 2026 at 08:34:40AM -0800, Suren Baghdasaryan wrote:
> On Tue, Nov 24, 2026 at 8:06 AM Puranjay Mohan <puranjay12@gmail.com> wrote:
> >
> > On Tue, Nov 24, 2026 at 9:28 PM Lorenzo Stoakes (ARM) <ljs@kernel.org> wrote:
> > >
> > > On Tue, Nov 24, 2026 at 07:51:42AM -0800, Suren Baghdasaryan wrote:
> > > > Actually, VMAs are allocated from a SLAB_TYPESAFE_BY_RCU slub. With
> > > > that RCU unlocking move you don't need other_mm copy and the comment
> > > > that comes with it. VMA won't be freed until RCU lock is dropped.
> > >
> > > Yeah but they can be reassigned? They won't be _freed_ until a grace period but
> > > they can go back to the slab and then allocated elsewhere right?
> > >
> >
> > Yes, they can go back to the slab and become a different VMA.
>
> Yeah, you are right about that. So, we either have to keep the RCU
> unlock in place to keep other_mm comment valid (my personal
> preference) or update the comment next to other_mm to explain the new
> reason it is needed. Either way is fine with me.
I think let's just change the comment?
Andrew could you change:
* stable and can be freed in the narrow window after vma->vm_refcnt
->
* stable and can be reused in the narrow window after vma->vm_refcnt
^
|
just this freed -> reused :)
Thanks!
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
2026-11-24 17:23 ` Lorenzo Stoakes (ARM)
@ 2026-11-24 17:33 ` Andrew Morton
0 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2026-11-24 17:33 UTC (permalink / raw)
To: Lorenzo Stoakes (ARM)
Cc: Suren Baghdasaryan, Puranjay Mohan, Pedro Falcato, Ingo Molnar,
Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
K Prateek Nayak, Kees Cook, David Hildenbrand, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Michal Hocko, Shakeel Butt,
Jann Horn, Alexei Starovoitov, linux-mm, linux-kernel, bpf,
Chris Mason, stable
On Tue, 24 Nov 2026 17:23:35 +0000 "Lorenzo Stoakes (ARM)" <ljs@kernel.org> wrote:
> On Tue, Nov 24, 2026 at 08:34:40AM -0800, Suren Baghdasaryan wrote:
> > On Tue, Nov 24, 2026 at 8:06 AM Puranjay Mohan <puranjay12@gmail.com> wrote:
> > >
> > > On Tue, Nov 24, 2026 at 9:28 PM Lorenzo Stoakes (ARM) <ljs@kernel.org> wrote:
> > > >
> > > > On Tue, Nov 24, 2026 at 07:51:42AM -0800, Suren Baghdasaryan wrote:
> > > > > Actually, VMAs are allocated from a SLAB_TYPESAFE_BY_RCU slub. With
> > > > > that RCU unlocking move you don't need other_mm copy and the comment
> > > > > that comes with it. VMA won't be freed until RCU lock is dropped.
> > > >
> > > > Yeah but they can be reassigned? They won't be _freed_ until a grace period but
> > > > they can go back to the slab and then allocated elsewhere right?
> > > >
> > >
> > > Yes, they can go back to the slab and become a different VMA.
> >
> > Yeah, you are right about that. So, we either have to keep the RCU
> > unlock in place to keep other_mm comment valid (my personal
> > preference) or update the comment next to other_mm to explain the new
> > reason it is needed. Either way is fine with me.
>
> I think let's just change the comment?
>
> Andrew could you change:
>
> * stable and can be freed in the narrow window after vma->vm_refcnt
>
> ->
>
> * stable and can be reused in the narrow window after vma->vm_refcnt
> ^
> |
> just this freed -> reused :)
>
np.
--- a/mm/mmap_lock.c~mm-vma-drop-mm-asynchronously-in-vma_start_read-fix
+++ a/mm/mmap_lock.c
@@ -300,7 +300,7 @@ err:
err_unstable:
/*
* If vma got attached to another mm from under us, that mm is not
- * stable and can be freed in the narrow window after vma->vm_refcnt
+ * stable and can be reused in the narrow window after vma->vm_refcnt
* is dropped and before rcuwait_wake_up(mm) is called. Grab it before
* releasing vma->vm_refcnt.
*/
_
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-24 17:33 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 12:26 [PATCH] mm/vma: drop mm asynchronously in vma_start_read() Lorenzo Stoakes (ARM)
2026-11-24 13:04 ` Pedro Falcato
2026-11-24 15:46 ` Suren Baghdasaryan
2026-11-24 15:51 ` Suren Baghdasaryan
2026-11-24 15:58 ` Lorenzo Stoakes (ARM)
2026-11-24 16:05 ` Puranjay Mohan
2026-11-24 16:34 ` Suren Baghdasaryan
2026-11-24 17:23 ` Lorenzo Stoakes (ARM)
2026-11-24 17:33 ` Andrew Morton
2026-11-24 15:56 ` Lorenzo Stoakes (ARM)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox