Re: [RFC PATCH v3 12/24] x86/mm: Modify ptep_set_wrprotect and pmdp_set_wrprotect for _PAGE_DIRTY_SW

From: Yu-cheng Yu
Date: Fri Aug 31 2018 - 10:38:11 EST


On Fri, 2018-08-31 at 11:53 +0200, Peter Zijlstra wrote:
> On Thu, Aug 30, 2018 at 11:47:16PM +0200, Jann Horn wrote:
> >
> > ÂÂÂÂÂÂÂÂdo {
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpte = pte_wrprotect(pte);
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ/* note: relies on _PAGE_DIRTY_HW < _PAGE_DIRTY_SW
> > */
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ/* dirty direct bit-twiddling; you can probably
> > write
> > this in a nicer way */
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpte.pte |= (pte.pte & _PAGE_DIRTY_HW) >>
> > _PAGE_BIT_DIRTY_HW << _PAGE_BIT_DIRTY_SW;
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpte.pte &= ~_PAGE_DIRTY_HW;
> > ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpte = cmpxchg(ptep, pte, new_pte);
> > ÂÂÂÂÂÂÂÂ} while (pte != new_pte);
> Please use the form:
>
> pte_t new_pte, pte = READ_ONCE(*ptep);
> do {
> new_pte = /* ... */;
> } while (!try_cmpxchg(ptep, &pte, new_pte);
>
> Also, this will fail to build on i386-PAE, but I suspect this code
> will
> be under some CONFIG option specific to x86_64 anyway.

Thanks! ÂI will work on it.

Yu-cheng