On 09/22, Peter Xu wrote:
>
> On Tue, Sep 22, 2020 at 12:18:16PM +0200, Oleg Nesterov wrote:
> > On 09/22, Oleg Nesterov wrote:
> > >
> > > On 09/21, Peter Xu wrote:
> > > >
> > > > @@ -866,13 +877,18 @@ static int copy_pte_range(struct mm_struct 
> > > > *dst_mm, struct mm_struct *src_mm,
> > > >         pte_unmap_unlock(orig_dst_pte, dst_ptl);
> > > >         cond_resched();
> > > >
> > > > -       if (entry.val) {
> > > > -               if (add_swap_count_continuation(entry, GFP_KERNEL) < 0)
> > > > +       switch (copy_ret) {
> > > > +       case COPY_MM_SWAP_CONT:
> > > > +               if (add_swap_count_continuation(data.entry, GFP_KERNEL) 
> > > > < 0)
> > > >                         return -ENOMEM;
> > > > -               progress = 0;
> > > > +               break;
> > >
> > > Note that you didn't clear copy_ret, it is still COPY_MM_SWAP_CONT,
> > >
> > > > +       default:
> > > > +               break;
> > > >         }
> > > > +
> > > >         if (addr != end)
> > > >                 goto again;
> > >
> > > After that the main loop can stop again because of need_resched(), and
> > > in this case add_swap_count_continuation(data.entry) will be called again?
> >
> > No, this is not possible, copy_one_pte() should be called at least once,
> > progress = 0 before restart. Sorry for noise.
>
> Oh wait, I think you're right... when we get a COPY_MM_SWAP_CONT, goto 
> "again",
> then if there're 32 pte_none() ptes _plus_ an need_resched(), then we might
> reach again at the same add_swap_count_continuation() with the same swp entry.

Yes, please see my reply to 4/5 ;)

> However since I didn't change this logic in this patch, it probably means this
> bug is also in the original code before this series...  I'm thinking maybe I
> should prepare a standalone patch to clear the swp_entry_t and cc stable.

Well, if copy_one_pte(src_pte) hits a swap entry and returns entry.val != 0, 
then
pte_none(*src_pte) is not possible after restart? This means that copy_one_pte()
will be called at least once.

So _think_ that the current code is fine, but I can be easily wrong and I agree
this doesn't look clean.

Oleg.

Reply via email to