From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: Liam.Howlett@oracle.com, linux-mm@kvack.org, willy@infradead.org,
ldufour@linux.ibm.com, michel@lespinasse.org,
jglisse@google.com, vbabka@suse.cz, paulmck@kernel.org,
brauner@kernel.org, linux-kernel@vger.kernel.org,
syzbot+339b02f826caafd5f7a8@syzkaller.appspotmail.com
Subject: Re: [PATCH 1/1] mm: fix a lockdep issue in vma_assert_write_locked
Date: Wed, 12 Jul 2023 13:00:40 -0700 [thread overview]
Message-ID: <CAJuCfpEX2fpHpJYzgBp8-3nbySUo758wuKt_fqUrs6_eM75LbA@mail.gmail.com> (raw)
In-Reply-To: <20230712195652.969194-1-surenb@google.com>
On Wed, Jul 12, 2023 at 12:56 PM Suren Baghdasaryan <surenb@google.com> wrote:
>
> __is_vma_write_locked() can be used only when mmap_lock is write-locked
> to guarantee vm_lock_seq and mm_lock_seq stability during the check.
> Therefore it asserts this condition before further checks. Because of
> that it can't be used unless the user expects the mmap_lock to be
> write-locked. vma_assert_locked() can't assume this before ensuring
> that VMA is not read-locked.
> Change the order of the checks in vma_assert_locked() to check if the
> VMA is read-locked first and only then assert if it's not write-locked.
>
> Fixes: 50b88b63e3e4 ("mm: handle userfaults under VMA lock")
> Reported-by: Liam R. Howlett <liam.howlett@oracle.com>
> Closes: https://lore.kernel.org/all/20230712022620.3yytbdh24b7i4zrn@revolver/
> Reported-by: syzbot+339b02f826caafd5f7a8@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/0000000000002db68f05ffb791bc@google.com/
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Should have mentioned that this patch is for mm-unstable.
> ---
> include/linux/mm.h | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 9687b48dfb1b..e3b022a66343 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -668,6 +668,7 @@ static inline void vma_end_read(struct vm_area_struct *vma)
> rcu_read_unlock();
> }
>
> +/* WARNING! Can only be used if mmap_lock is expected to be write-locked */
> static bool __is_vma_write_locked(struct vm_area_struct *vma, int *mm_lock_seq)
> {
> mmap_assert_write_locked(vma->vm_mm);
> @@ -707,22 +708,17 @@ static inline bool vma_try_start_write(struct vm_area_struct *vma)
> return true;
> }
>
> -static inline void vma_assert_locked(struct vm_area_struct *vma)
> +static inline void vma_assert_write_locked(struct vm_area_struct *vma)
> {
> int mm_lock_seq;
>
> - if (__is_vma_write_locked(vma, &mm_lock_seq))
> - return;
> -
> - lockdep_assert_held(&vma->vm_lock->lock);
> - VM_BUG_ON_VMA(!rwsem_is_locked(&vma->vm_lock->lock), vma);
> + VM_BUG_ON_VMA(!__is_vma_write_locked(vma, &mm_lock_seq), vma);
> }
>
> -static inline void vma_assert_write_locked(struct vm_area_struct *vma)
> +static inline void vma_assert_locked(struct vm_area_struct *vma)
> {
> - int mm_lock_seq;
> -
> - VM_BUG_ON_VMA(!__is_vma_write_locked(vma, &mm_lock_seq), vma);
> + if (!rwsem_is_locked(&vma->vm_lock->lock))
> + vma_assert_write_locked(vma);
> }
>
> static inline void vma_mark_detached(struct vm_area_struct *vma, bool detached)
> --
> 2.41.0.455.g037347b96a-goog
>
prev parent reply other threads:[~2023-07-12 20:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-12 19:56 Suren Baghdasaryan
2023-07-12 20:00 ` Suren Baghdasaryan [this message]
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=CAJuCfpEX2fpHpJYzgBp8-3nbySUo758wuKt_fqUrs6_eM75LbA@mail.gmail.com \
--to=surenb@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=jglisse@google.com \
--cc=ldufour@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=michel@lespinasse.org \
--cc=paulmck@kernel.org \
--cc=syzbot+339b02f826caafd5f7a8@syzkaller.appspotmail.com \
--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