[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y49xlV8I2/92Flha@x1n>
Date: Tue, 6 Dec 2022 11:45:09 -0500
From: Peter Xu <peterx@...hat.com>
To: John Hubbard <jhubbard@...dia.com>
Cc: Mike Kravetz <mike.kravetz@...cle.com>, linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
James Houghton <jthoughton@...gle.com>,
Jann Horn <jannh@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Andrea Arcangeli <aarcange@...hat.com>,
Rik van Riel <riel@...riel.com>,
Nadav Amit <nadav.amit@...il.com>,
Miaohe Lin <linmiaohe@...wei.com>,
Muchun Song <songmuchun@...edance.com>,
David Hildenbrand <david@...hat.com>
Subject: Re: [PATCH 08/10] mm/hugetlb: Make walk_hugetlb_range() safe to pmd
unshare
On Mon, Dec 05, 2022 at 03:52:51PM -0800, John Hubbard wrote:
> On 12/5/22 15:33, Mike Kravetz wrote:
> > On 11/29/22 14:35, Peter Xu wrote:
> > > Since walk_hugetlb_range() walks the pgtable, it needs the vma lock
> > > to make sure the pgtable page will not be freed concurrently.
> > >
> > > Signed-off-by: Peter Xu <peterx@...hat.com>
> > > ---
> > > mm/pagewalk.c | 2 ++
> > > 1 file changed, 2 insertions(+)
> > >
> > > diff --git a/mm/pagewalk.c b/mm/pagewalk.c
> > > index 7f1c9b274906..d98564a7be57 100644
> > > --- a/mm/pagewalk.c
> > > +++ b/mm/pagewalk.c
> > > @@ -302,6 +302,7 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end,
> > > const struct mm_walk_ops *ops = walk->ops;
> > > int err = 0;
> > > + hugetlb_vma_lock_read(vma);
> > > do {
> > > next = hugetlb_entry_end(h, addr, end);
> > > pte = huge_pte_offset(walk->mm, addr & hmask, sz);
> >
> > For each found pte, we will be calling mm_walk_ops->hugetlb_entry() with
> > the vma_lock held. I looked into the various hugetlb_entry routines, and
> > I am not sure about hmm_vma_walk_hugetlb_entry. It seems like it could
> > possibly call hmm_vma_fault -> handle_mm_fault -> hugetlb_fault. If this
> > can happen, then we may have an issue as hugetlb_fault will also need to
> > acquire the vma_lock in read mode.
Thanks for spotting that, Mike.
I used to notice that path special but that's when I was still using RCU
locks who doesn't have the issue. Then I overlooked this one when
switchover.
> >
> > I do not know the hmm code well enough to know if this may be an actual
> > issue?
>
> Oh, this sounds like a serious concern. If we add a new lock, and hold it
> during callbacks that also need to take it, that's not going to work out,
> right?
>
> And yes, hmm_range_fault() and related things do a good job of revealing
> this kind of deadlock. :)
I've got a fixup attached. John, since this got your attention please also
have a look too in case there's further issues.
Thanks,
--
Peter Xu
View attachment "0001-fixup-mm-hugetlb-Make-walk_hugetlb_range-safe-to-pmd.patch" of type "text/plain" (2968 bytes)
Powered by blists - more mailing lists