On Tue, Jan 26, 2021 at 09:46:36AM +0100, Peter Zijlstra wrote:
> On Mon, Jan 25, 2021 at 07:27:09PM +0100, Borislav Petkov wrote:
> 
> > > +         pte_t old_pte, new_pte;
> > > +
> > > +         do {
> > > +                 old_pte = READ_ONCE(*ptep);
> > > +                 new_pte = pte_wrprotect(old_pte);
> > 
> > Maybe I'm missing something but those two can happen outside of the
> > loop, no? Or is *ptep somehow changing concurrently while the loop is
> > doing the CMPXCHG and you need to recreate it each time?
> > 
> > IOW, you can generate upfront and do the empty loop...
> > 
> > > +
> > > +         } while (!try_cmpxchg(&ptep->pte, &old_pte.pte, new_pte.pte));
> > > +
> > > +         return;
> > > + }
> 
> Empty loop would be wrong, but that wants to be written like:
> 
>       old_pte = READ_ONCE(*ptep);
>       do {
>               new_pte = pte_wrprotect(old_pte);
>       } while (try_cmpxchg(&ptep->pte, &old_pte.pte, new_pte.pte));

! went missing, too early, moar wake-up juice.

> Since try_cmpxchg() will update old_pte on failure.

Reply via email to