2020-04-14 16:56:11

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH] mm/gup: dereference page table entry using helper

On Tue, Apr 14, 2020 at 05:10:01PM +0200, Alexander Gordeev wrote:
> Commit 0005d20 ("mm/gup: Move page table entry dereference
> into helper function") wrapped access to page table entries
> larger than sizeof(long) into a race-aware accessor. One of
> the two dereferences in gup_fast path was however overlooked.
>
> CC: Kirill A. Shutemov <[email protected]>
> CC: [email protected]
> Signed-off-by: Alexander Gordeev <[email protected]>
> mm/gup.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index d53f7dd..eceb98b 100644
> +++ b/mm/gup.c
> @@ -2208,7 +2208,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
> if (!head)
> goto pte_unmap;
>
> - if (unlikely(pte_val(pte) != pte_val(*ptep))) {
> + if (unlikely(pte_val(pte) != pte_val(gup_get_pte(ptep)))) {

It doesn't seem like this needs the special helper as it is just
checking that the pte hasn't changed, it doesn't need to be read
exactly.

But it probably should technically still be a READ_ONCE. Although I
think the atomic inside try_grab_compound_head prevents any real
problems.

Jason


2020-04-15 21:52:24

by Ira Weiny

[permalink] [raw]
Subject: Re: [PATCH] mm/gup: dereference page table entry using helper

On Tue, Apr 14, 2020 at 01:32:34PM -0300, Jason Gunthorpe wrote:
> On Tue, Apr 14, 2020 at 05:10:01PM +0200, Alexander Gordeev wrote:
> > Commit 0005d20 ("mm/gup: Move page table entry dereference
> > into helper function") wrapped access to page table entries
> > larger than sizeof(long) into a race-aware accessor. One of
> > the two dereferences in gup_fast path was however overlooked.
> >
> > CC: Kirill A. Shutemov <[email protected]>
> > CC: [email protected]
> > Signed-off-by: Alexander Gordeev <[email protected]>
> > mm/gup.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/gup.c b/mm/gup.c
> > index d53f7dd..eceb98b 100644
> > +++ b/mm/gup.c
> > @@ -2208,7 +2208,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
> > if (!head)
> > goto pte_unmap;
> >
> > - if (unlikely(pte_val(pte) != pte_val(*ptep))) {
> > + if (unlikely(pte_val(pte) != pte_val(gup_get_pte(ptep)))) {
>
> It doesn't seem like this needs the special helper as it is just
> checking that the pte hasn't changed, it doesn't need to be read
> exactly.
>
> But it probably should technically still be a READ_ONCE. Although I
> think the atomic inside try_grab_compound_head prevents any real
> problems.

I think we should go for consistency here and use the helper function.

Ira

>
> Jason
>