# Re: \[PATCH v23 12/28\] x86/mm: Update ptep\_set\_wrprotect() and pmdp\_set\_wrprotect() for transition from \_PAGE\_DIRTY to \_PAGE\_COW

- From: Peter Zijlstra \<peterz@infradead.org\>
- Date: 2021-03-22 10:49:27 
- List: linux-api
- Page: https://ratatoskr.run/linux-api/2021/03/6309918
- Thread: https://ratatoskr.run/linux-doc/2021/03/6303369/t.md

```text
On Mon, Mar 22, 2021 at 01:15:02PM +0300, Kirill A. Shutemov wrote:
> On Tue, Mar 16, 2021 at 08:10:38AM -0700, Yu-cheng Yu wrote:

> > +		pte_t old_pte, new_pte;
> > +
> > +		old_pte = READ_ONCE(*ptep);
> > +		do {
> > +			new_pte = pte_wrprotect(old_pte);
> > +		} while (!try_cmpxchg(&ptep->pte, &old_pte.pte, new_pte.pte));
> 
> I think this is wrong. You need to update old_pte on every loop iteration,
> otherwise you can get in to endless loop.

It is correct, please consider why the old argument is a pointer.
```
