From: Matthew Wilcox <willy@infradead.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: linux-mm@kvack.org
Subject: Re: [RFC] Trylock the mmap_lock in vmf_anon_prepare()
Date: Mon, 15 Apr 2024 19:18:28 +0100 [thread overview]
Message-ID: <Zh1vdIO1cXcEycIs@casper.infradead.org> (raw)
In-Reply-To: <CAJuCfpGRAab6WLFDJTZtyPLQ4pfg1JrVONeYwhnvQQDsY0Zxmw@mail.gmail.com>
On Mon, Apr 15, 2024 at 09:14:10AM -0700, Suren Baghdasaryan wrote:
> > if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
> > - vma_end_read(vma);
> > - return VM_FAULT_RETRY;
> > + if (!mmap_read_trylock(vma->vm_mm)) {
> > + vma_end_read(vma);
> > + return VM_FAULT_RETRY;
> > + }
> > }
> > if (__anon_vma_prepare(vma))
> > return VM_FAULT_OOM;
>
> You should drop mmap_lock when returning VM_FAULT_OOM as well.
>
> > + if (vmf->flags & FAULT_FLAG_VMA_LOCK)
> > + mmap_read_unlock(vma->vm_mm);
> > return 0;
> > }
Thanks. Fixed and pushed to
git://git.infradead.org/users/willy/pagecache.git vma-lock
+++ b/mm/memory.c
@@ -3224,16 +3224,21 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf)
vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
{
struct vm_area_struct *vma = vmf->vma;
+ vm_fault_t ret = 0;
if (likely(vma->anon_vma))
return 0;
if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
- vma_end_read(vma);
- return VM_FAULT_RETRY;
+ if (!mmap_read_trylock(vma->vm_mm)) {
+ vma_end_read(vma);
+ return VM_FAULT_RETRY;
+ }
}
if (__anon_vma_prepare(vma))
- return VM_FAULT_OOM;
- return 0;
+ ret = VM_FAULT_OOM;
+ if (vmf->flags & FAULT_FLAG_VMA_LOCK)
+ mmap_read_unlock(vma->vm_mm);
+ return ret;
}
/*
next prev parent reply other threads:[~2024-04-15 18:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 15:24 Matthew Wilcox
2024-04-15 16:14 ` Suren Baghdasaryan
2024-04-15 18:18 ` Matthew Wilcox [this message]
2024-04-15 20:59 ` Suren Baghdasaryan
2024-04-15 16:45 ` Jann Horn
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=Zh1vdIO1cXcEycIs@casper.infradead.org \
--to=willy@infradead.org \
--cc=linux-mm@kvack.org \
--cc=surenb@google.com \
/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