Subject: Re: [PATCH] arm64: contpte: fix set_access_flags() no-op check for SMMU/ATS faults

From: Jason Gunthorpe <[email-masked]>
Date: Wed, 4 Mar 2026 09:44:45 -0400

On Wed, Mar 04, 2026 at 12:20:31PM +0000, Ryan Roberts wrote:
> >  static int __cont_access_flags_changed(pte_t *ptep, pte_t pte, int ncontig)
> >  {
> > +	const pteval_t access_mask = PTE_RDONLY | PTE_AF | PTE_WRITE | PTE_DIRTY;
> > +	pteval_t pte_access = pte_val(pte) & access_mask;
> >  	int i;
> >  
> > -	if (pte_write(pte) != pte_write(__ptep_get(ptep)))
> > -		return 1;
> > -
> >  	for (i = 0; i < ncontig; i++) {
> > -		pte_t orig_pte = __ptep_get(ptep + i);
> > -
> > -		if (pte_dirty(pte) != pte_dirty(orig_pte))
> > -			return 1;
> > -
> > -		if (pte_young(pte) != pte_young(orig_pte))
> > +		if ((pte_val(__ptep_get(ptep + i)) & access_mask) != pte_access)
> >  			return 1;
> >  	}
> 
> I think, based on all the above, the current version is actually not buggy. But
> I'm only willing to go to 95% confidence :)

If I understand it right James already found and fixed a case that
violated the invariant right? Maybe it is wise to be robust since
things lock up if it goes wrong.

Jason