lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZYJGsUWpmF1P1Nd0@x1n>
Date: Wed, 20 Dec 2023 09:43:13 +0800
From: Peter Xu <peterx@...hat.com>
To: James Houghton <jthoughton@...gle.com>
Cc: linux-kernel@...r.kernel.org, linux-mm@...ck.org,
	Matthew Wilcox <willy@...radead.org>,
	Christophe Leroy <christophe.leroy@...roup.eu>,
	Lorenzo Stoakes <lstoakes@...il.com>,
	David Hildenbrand <david@...hat.com>,
	Vlastimil Babka <vbabka@...e.cz>,
	Mike Kravetz <mike.kravetz@...cle.com>,
	Mike Rapoport <rppt@...nel.org>,
	Christoph Hellwig <hch@...radead.org>,
	John Hubbard <jhubbard@...dia.com>,
	Andrew Jones <andrew.jones@...ux.dev>,
	linux-arm-kernel@...ts.infradead.org,
	Michael Ellerman <mpe@...erman.id.au>,
	"Kirill A . Shutemov" <kirill@...temov.name>,
	linuxppc-dev@...ts.ozlabs.org, Rik van Riel <riel@...riel.com>,
	linux-riscv@...ts.infradead.org, Yang Shi <shy828301@...il.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@...nel.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Jason Gunthorpe <jgg@...dia.com>,
	Andrea Arcangeli <aarcange@...hat.com>,
	Axel Rasmussen <axelrasmussen@...gle.com>
Subject: Re: [PATCH 09/13] mm/gup: Cache *pudp in follow_pud_mask()

On Tue, Dec 19, 2023 at 11:28:54AM -0500, James Houghton wrote:
> On Tue, Dec 19, 2023 at 2:57 AM <peterx@...hat.com> wrote:
> >
> > From: Peter Xu <peterx@...hat.com>
> >
> > Introduce "pud_t pud" in the function, so the code won't dereference *pudp
> > multiple time.  Not only because that looks less straightforward, but also
> > because if the dereference really happened, it's not clear whether there
> > can be race to see different *pudp values if it's being modified at the
> > same time.
> >
> > Signed-off-by: Peter Xu <peterx@...hat.com>
> > ---
> >  mm/gup.c | 17 +++++++++--------
> >  1 file changed, 9 insertions(+), 8 deletions(-)
> >
> > diff --git a/mm/gup.c b/mm/gup.c
> > index 6c0d82fa8cc7..97e87b7a15c3 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -753,26 +753,27 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma,
> >                                     unsigned int flags,
> >                                     struct follow_page_context *ctx)
> >  {
> > -       pud_t *pud;
> > +       pud_t *pudp, pud;
> >         spinlock_t *ptl;
> >         struct page *page;
> >         struct mm_struct *mm = vma->vm_mm;
> >
> > -       pud = pud_offset(p4dp, address);
> > -       if (pud_none(*pud))
> > +       pudp = pud_offset(p4dp, address);
> > +       pud = *pudp;
> 
> I think you might want a READ_ONCE() on this so that the compiler
> doesn't actually read the pud multiple times.

Makes sense.  I probably only did the "split" part which Christoph
requested, without thinking futher than that. :)

> 
> > +       if (pud_none(pud))
> >                 return no_page_table(vma, flags, address);
> > -       if (pud_devmap(*pud)) {
> > -               ptl = pud_lock(mm, pud);
> > -               page = follow_devmap_pud(vma, address, pud, flags, &ctx->pgmap);
> > +       if (pud_devmap(pud)) {
> > +               ptl = pud_lock(mm, pudp);
> > +               page = follow_devmap_pud(vma, address, pudp, flags, &ctx->pgmap);
> >                 spin_unlock(ptl);
> >                 if (page)
> >                         return page;
> >                 return no_page_table(vma, flags, address);
> >         }
> > -       if (unlikely(pud_bad(*pud)))
> > +       if (unlikely(pud_bad(pud)))
> >                 return no_page_table(vma, flags, address);
> 
> Not your change, but reading this, it's not clear to me that
> `pud_present(*pudp)` (and non-leaf) would necessarily be true at this
> point -- like, I would prefer to see `!pud_present(pud)` instead of
> `pud_bad()`. Thank you for adding that in the next patch. :)

I think the assumption here is it is expected to be a directory entry when
reaching here, and for a valid directory entry pud_present() should always
return true (a side note: pud_present() may not mean "PRESENT bit set", see
m68k's implementation for example).

Yeah I added that in the next patch, my intention was to check
!pud_present() for all cases without the need to take pgtable lock, though.

> 
> Feel free to add:
> 
> Acked-by: James Houghton <jthoughton@...gle.com>

Thanks,

-- 
Peter Xu


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ