From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Suren Baghdasaryan <surenb@google.com>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
David Hildenbrand <david@kernel.org>,
Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
Jonathan Corbet <corbet@lwn.net>,
Randy Dunlap <rdunlap@infradead.org>,
Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, Daehyeon Ko <4ncienth@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] mm/vma: avoid spurious write locks when mm->mm_lock_seq overflows
Date: Fri, 16 Oct 2026 09:19:13 +0100 [thread overview]
Message-ID: <atHa3-KlMPg6oy8v@gremlin> (raw)
In-Reply-To: <f5548d05-5aec-42d0-b9d9-c14fb575dec9@gmail.com>
It seems likely that you're using AI to generate these review points. Please do
say if you're doing that, thanks.
Normally that'd be totally unwelcome, but both Sashiko + local AI missed these,
and I have made mistakes here I need to fix, so this is actually useful...
On Fri, Oct 16, 2026 at 09:41:28AM +0200, Jose A. Perez de Azpillaga wrote:
> On 10/15/26 10:31 PM, Lorenzo Stoakes (ARM) wrote:
> [snip]
>
> > The reset, performed in reset_vma_seqcounts(), only needs to WRITE_ONCE()
> > the value. The stores follow the smp_wmb() in do_raw_write_seqcount_end(),
> > so a reader observing a reset value also observes the VMA modifications
> > made under the write lock.
>
> the writer side looks fine, but what orders it on the reader side?
> raw_read_seqcount() is just an smp_load_acquire() since d0dd066a0fa2,
> not the smp_rmb() the comment mentions, so the earlier
> READ_ONCE(vma->vm_lock_seq) isn't ordered against the later vma reads.
> couldn't a reader on arm64 see the reset 0 with the old odd
> mm_lock_seq, pass the parity check and read stale vma fields? would
> smp_load_acquire(&vma->vm_lock_seq) be enough?
Yup that's a mistake, will fix on respin.
>
> [snip]
>
> > Cc: stable@vger.kernel.org
>
> the parity check relies on e5e7fb278e59. before that, mm_lock_seq only
> increments on unlock, so locked values can be odd or even. should this
> be limited to 6.14+, with a note that older trees need a different fix?
> a straight backport of the odd check would ignore write locks taken on
> even cycles.
I have a plan for older kernels (just make the value 64 bit...)
>
> [snip]
>
> > + /*
> > + * The VMA seqcount is always odd if locked. An even value can only be
> > + * the zero stored by reset_vma_seqcounts(), never a write lock.
> > + */
>
> vma_lock_init() now stores 0 too, so this isn't quite true, is it?
Yes it is true, because as the commit message and I think even comments say, the
VMA is not visible when detached, but it is visible when attached, at which
point a write lock will have been acquired by definition, hence non-zero.
I guess I could add a point about attached here.
>
> [snip]
>
> > -static inline struct vm_area_struct *vma_start_read(struct mm_struct *mm,
> > - struct vm_area_struct *vma)
> > +static struct vm_area_struct *vma_start_read(struct mm_struct *mm,
> > + struct vm_area_struct *vma)
>
> is dropping the inline intended?
Yes. inline in C files is useless.
>
> [snip]
>
> > +EXPORT_SYMBOL(reset_vma_seqcounts);
>
> since it has to be exported for the inline mmap_write_unlock(), would a
> __ prefix make sense, so nobody calls it outside vma_end_write_all()?
Yup, that's fair, will update.
>
> I tested it on x86 in qemu with KASAN, lockdep and DEBUG_VM on top of
> mm-unstable and saw no issues, but I'm hesitant about the points above.
> happy to give a Tested-by on the next version :)
Thanks!
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-10-16 8:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 20:31 [PATCH] mm/vma: avoid spurious write locks when mm->mm_lock_seq overflows Lorenzo Stoakes (ARM)
2026-10-16 7:41 ` Jose A. Perez de Azpillaga
2026-10-16 8:19 ` Lorenzo Stoakes (ARM) [this message]
2026-10-16 8:57 ` Jose A. Perez de Azpillaga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=atHa3-KlMPg6oy8v@gremlin \
--to=ljs@kernel.org \
--cc=4ncienth@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=azpijr@gmail.com \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=jannh@google.com \
--cc=liam@infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox