linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yang Shi <shy828301@gmail.com>
To: "Zach O'Keefe" <zokeefe@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	 Matthew Wilcox <willy@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Linux MM <linux-mm@kvack.org>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [v3 PATCH 3/7] mm: khugepaged: remove the redundant anon vma check
Date: Thu, 9 Jun 2022 17:01:40 -0700	[thread overview]
Message-ID: <CAHbLzkqhH5oJmQ6YMvBoAW17t03nqwJsrxfzw4gXtP_mTtnWAg@mail.gmail.com> (raw)
In-Reply-To: <CAAa6QmRTt2EXJTudBf7DK6yPTr2DRDUbGZiHDC8pAmKRwoB4_A@mail.gmail.com>

On Thu, Jun 9, 2022 at 4:24 PM Zach O'Keefe <zokeefe@google.com> wrote:
>
> On Mon, Jun 6, 2022 at 2:44 PM Yang Shi <shy828301@gmail.com> wrote:
> >
> > The hugepage_vma_check() already checked it, so remove the redundant
> > check.
> >
> > Signed-off-by: Yang Shi <shy828301@gmail.com>
> > ---
> >  mm/khugepaged.c | 3 ---
> >  1 file changed, 3 deletions(-)
> >
> > diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> > index d0f8020164fc..7a5d1c1a1833 100644
> > --- a/mm/khugepaged.c
> > +++ b/mm/khugepaged.c
> > @@ -966,9 +966,6 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
> >                 return SCAN_ADDRESS_RANGE;
> >         if (!hugepage_vma_check(vma, vma->vm_flags))
> >                 return SCAN_VMA_CHECK;
> > -       /* Anon VMA expected */
> > -       if (!vma->anon_vma || !vma_is_anonymous(vma))
> > -               return SCAN_VMA_CHECK;
> >         return 0;
> >  }
> >
> > --
> > 2.26.3
> >
> >
>
> So, I don't know if this is possible, but I wonder if there is a race here:
>
> hugepage_vma_revalidate() is called in the anon path when mmap_lock
> after dropped + reacquired, and we want to refind / revalidate the
> vma, since it might have changed.
>
> There is the possibility that the memory was unmapped, then remapped
> as file or shmem. If so, hugepage_vma_check() could return true
> without actually checking vma->anon_vma || !vma_is_anonymous(vma) -
> and we probably do want to (re)validate that this is indeed still an
> anon vma.

Nice catch! Totally possible. I did overlook this. I will drop this
patch in the next version or maybe making the comment clearer is a
better choice.


  reply	other threads:[~2022-06-10  0:01 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-06 21:44 [mm-unstable v3 PATCH 0/7] Cleanup transhuge_xxx helpers Yang Shi
2022-06-06 21:44 ` [v3 PATCH 1/7] mm: khugepaged: check THP flag in hugepage_vma_check() Yang Shi
2022-06-09 17:49   ` Zach O'Keefe
2022-06-10  7:09   ` Miaohe Lin
2022-06-06 21:44 ` [v3 PATCH 2/7] mm: thp: introduce transhuge_vma_size_ok() helper Yang Shi
2022-06-09 22:21   ` Zach O'Keefe
2022-06-10  0:08     ` Yang Shi
2022-06-10  0:51       ` Zach O'Keefe
2022-06-10 16:38         ` Yang Shi
2022-06-10 21:24           ` Yang Shi
2022-06-10  7:20   ` Miaohe Lin
2022-06-10 16:47     ` Yang Shi
2022-06-06 21:44 ` [v3 PATCH 3/7] mm: khugepaged: remove the redundant anon vma check Yang Shi
2022-06-09 23:23   ` Zach O'Keefe
2022-06-10  0:01     ` Yang Shi [this message]
2022-06-10  7:23   ` Miaohe Lin
2022-06-10  7:28     ` Miaohe Lin
2022-06-06 21:44 ` [v3 PATCH 4/7] mm: khugepaged: use transhuge_vma_suitable replace open-code Yang Shi
2022-06-10  1:51   ` Zach O'Keefe
2022-06-10 16:59     ` Yang Shi
2022-06-10 22:03       ` Yang Shi
2022-06-11  0:27         ` Zach O'Keefe
2022-06-11  3:25           ` Yang Shi
2022-06-11 21:43             ` Zach O'Keefe
2022-06-14 17:40               ` Yang Shi
2022-06-06 21:44 ` [v3 PATCH 5/7] mm: thp: kill transparent_hugepage_active() Yang Shi
2022-06-10  1:02   ` Zach O'Keefe
2022-06-10 17:02     ` Yang Shi
2022-06-13 15:06       ` Zach O'Keefe
2022-06-14 19:16         ` Yang Shi
2022-06-06 21:44 ` [v3 PATCH 6/7] mm: thp: kill __transhuge_page_enabled() Yang Shi
2022-06-10  2:22   ` Zach O'Keefe
2022-06-10 17:24     ` Yang Shi
2022-06-10 21:07       ` Yang Shi
2022-06-13 14:54         ` Zach O'Keefe
2022-06-14 18:51           ` Yang Shi
2022-06-14 23:55             ` Zach O'Keefe
2022-06-06 21:44 ` [v3 PATCH 7/7] mm: khugepaged: reorg some khugepaged helpers Yang Shi
2022-06-09 23:32 ` [mm-unstable v3 PATCH 0/7] Cleanup transhuge_xxx helpers Zach O'Keefe
2022-06-10  7:08 ` Miaohe Lin

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=CAHbLzkqhH5oJmQ6YMvBoAW17t03nqwJsrxfzw4gXtP_mTtnWAg@mail.gmail.com \
    --to=shy828301@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=zokeefe@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