linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Suren Baghdasaryan <surenb@google.com>,
	akpm@linux-foundation.org, jannh@google.com, willy@infradead.org,
	david@redhat.com, peterx@redhat.com, ldufour@linux.ibm.com,
	vbabka@suse.cz, michel@lespinasse.org, jglisse@google.com,
	mhocko@suse.com, hannes@cmpxchg.org, dave@stgolabs.net,
	hughd@google.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, stable@vger.kernel.org
Subject: Re: [PATCH v3 5/6] mm: always lock new vma before inserting into vma tree
Date: Thu, 3 Aug 2023 14:15:20 -0400	[thread overview]
Message-ID: <20230803181520.yd5ao45rm3rxnsbs@revolver> (raw)
In-Reply-To: <CAHk-=wiCrWAoEesBuoGoqqufvesicbGp3cX0LyKgEvsFaZNpDA@mail.gmail.com>

* Linus Torvalds <torvalds@linux-foundation.org> [230803 14:02]:
> On Thu, 3 Aug 2023 at 10:27, Suren Baghdasaryan <surenb@google.com> wrote:
> >
> > While it's not strictly necessary to lock a newly created vma before
> > adding it into the vma tree (as long as no further changes are performed
> > to it), it seems like a good policy to lock it and prevent accidental
> > changes after it becomes visible to the page faults. Lock the vma before
> > adding it into the vma tree.
> 
> So my main reaction here is that I started to wonder about the vma allocation.
> 
> Why doesn't vma_init() do something like
> 
>         mmap_assert_write_locked(mm);
>         vma->vm_lock_seq = mm->mm_lock_seq;
> 
> and instead we seem to expect vma_lock_alloc() to do this (and do it
> very badly indeed).
> 
> Strange.
> 
> Anyway, this observation was just a reaction to that "not strictly
> necessary to lock a newly created vma" part of the commentary. I feel
> like we could/should just make sure that all newly created vma's are
> always simply created write-locked.
> 

I thought the same thing initially, but Suren pointed out that it's not
necessary to hold the vma lock to allocate a vma object.  And it seems
there is at least one user (arch/ia64/mm/init.c) which does allocate
outside the lock during ia64_init_addr_space(), which is fine but I'm
not sure it gains much to do it this way - the insert needs to take the
lock anyways and it is hardly going to be contended.

Anywhere else besides an address space setup would probably introduce a
race.

Thanks,
Liam



  reply	other threads:[~2023-08-03 18:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 17:26 [PATCH v3 0/6] make vma locking more obvious Suren Baghdasaryan
2023-08-03 17:26 ` [PATCH v3 1/6] mm: enable page walking API to lock vmas during the walk Suren Baghdasaryan
2023-08-03 17:26 ` [PATCH v3 2/6] mm: for !CONFIG_PER_VMA_LOCK equate write lock assertion for vma and mmap Suren Baghdasaryan
2023-08-03 17:26 ` [PATCH v3 3/6] mm: replace mmap with vma write lock assertions when operating on a vma Suren Baghdasaryan
2023-08-03 17:26 ` [PATCH v3 4/6] mm: lock vma explicitly before doing vm_flags_reset and vm_flags_reset_once Suren Baghdasaryan
2023-08-03 17:26 ` [PATCH v3 5/6] mm: always lock new vma before inserting into vma tree Suren Baghdasaryan
2023-08-03 18:01   ` Linus Torvalds
2023-08-03 18:15     ` Liam R. Howlett [this message]
2023-08-03 18:26       ` Suren Baghdasaryan
2023-08-03 18:34         ` Suren Baghdasaryan
2023-08-03 17:26 ` [PATCH v3 6/6] mm: move vma locking out of vma_prepare and dup_anon_vma Suren Baghdasaryan
2023-08-03 18:32   ` Liam R. Howlett
2023-08-03 19:14     ` Suren Baghdasaryan
2023-08-03 19:20       ` Liam R. Howlett
2023-08-04 15:29 ` [PATCH v3 0/6] make vma locking more obvious Suren Baghdasaryan

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=20230803181520.yd5ao45rm3rxnsbs@revolver \
    --to=liam.howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave@stgolabs.net \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=jglisse@google.com \
    --cc=ldufour@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=michel@lespinasse.org \
    --cc=peterx@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.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