Re: [PATCH 08/31] mm/page_vma_mapped: pte_offset_map_nolock() not pte_lockptr()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 22 May 2023, Qi Zheng wrote:
> On 2023/5/22 12:58, Hugh Dickins wrote:
> > map_pte() use pte_offset_map_nolock(), to make sure of the ptl belonging
> > to pte, even if pmd entry is then changed racily: page_vma_mapped_walk()
> > use that instead of getting pte_lockptr() later, or restart if map_pte()
> > found no page table.
> > 
> > Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx>
> > ---
> >   mm/page_vma_mapped.c | 28 ++++++++++++++++++++++------
> >   1 file changed, 22 insertions(+), 6 deletions(-)
> > 
> > diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c
> > index 947dc7491815..2af734274073 100644
> > --- a/mm/page_vma_mapped.c
> > +++ b/mm/page_vma_mapped.c
> > @@ -156,6 +168,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk
> > *pvmw)
> >    struct vm_area_struct *vma = pvmw->vma;
> >    struct mm_struct *mm = vma->vm_mm;
> >    unsigned long end;
> > +	spinlock_t *ptl;
> >    pgd_t *pgd;
> >    p4d_t *p4d;
> >    pud_t *pud;
> > @@ -257,8 +270,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk
> > *pvmw)
> >      step_forward(pvmw, PMD_SIZE);
> >      continue;
> >   		}
> > -		if (!map_pte(pvmw))
> > +		if (!map_pte(pvmw, &ptl)) {
> > +			if (!pvmw->pte)
> > +				goto restart;
> 
> Could pvmw->pmd be changed? Otherwise, how about just jumping to the
> retry label below?
> 
> @@ -205,6 +205,8 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk
> *pvmw)
>                 }
> 
>                 pvmw->pmd = pmd_offset(pud, pvmw->address);
> +
> +retry:
>                 /*
>                  * Make sure the pmd value isn't cached in a register by the
>                  * compiler and used as a stale value after we've observed a

You're right, that could be done, and that's where I'd have inserted
the label if there were none already.  I just thought the fewer goto
labels the better, so reused the restart already there.  If you feel
strongly that it's actively misleading, I can certainly make that
change; but it's too rare an occurrence to be worth optimizing for.

Hugh




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux