diff mbox series

[2/2] arm64: mm: Always make sw-dirty PTEs hw-dirty in pte_modify

Message ID 20231204172646.2541916-3-jthoughton@google.com (mailing list archive)
State New
Headers show
Series arm64: hugetlb: Fix page fault loop for sw-dirty/hw-clean contiguous PTEs | expand

Commit Message

James Houghton Dec. 4, 2023, 5:26 p.m. UTC
Make it impossible to create a sw-dirty, hw-clean PTE with pte_modify.
Such a PTE should be impossible to create, and there may be places that
assume that pte_dirty() implies pte_hw_dirty().

Signed-off-by: James Houghton <jthoughton@google.com>

Comments

Ryan Roberts Dec. 6, 2023, 10:26 a.m. UTC | #1
On 04/12/2023 17:26, James Houghton wrote:
> Make it impossible to create a sw-dirty, hw-clean PTE with pte_modify.
> Such a PTE should be impossible to create, and there may be places that
> assume that pte_dirty() implies pte_hw_dirty().
> 
> Signed-off-by: James Houghton <jthoughton@google.com>

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>

> 
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index b19a8aee684c..79ce70fbb751 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -834,6 +834,12 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
>  		pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
>  
>  	pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
> +	/*
> +	 * If we end up clearing hw dirtiness for a sw-dirty PTE, set hardware
> +	 * dirtiness again.
> +	 */
> +	if (pte_sw_dirty(pte))
> +		pte = pte_mkdirty(pte);
>  	return pte;
>  }
>
Will Deacon Dec. 11, 2023, 6:42 p.m. UTC | #2
On Mon, Dec 04, 2023 at 05:26:46PM +0000, James Houghton wrote:
> Make it impossible to create a sw-dirty, hw-clean PTE with pte_modify.
> Such a PTE should be impossible to create, and there may be places that
> assume that pte_dirty() implies pte_hw_dirty().
> 
> Signed-off-by: James Houghton <jthoughton@google.com>

I'm not sure how, but you seem to be missing the '---' separator and the
diffstat here, so I suspect this might confuse tools such as b4 which try
to apply the patch directly.

> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index b19a8aee684c..79ce70fbb751 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -834,6 +834,12 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
>  		pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
>  
>  	pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
> +	/*
> +	 * If we end up clearing hw dirtiness for a sw-dirty PTE, set hardware
> +	 * dirtiness again.
> +	 */
> +	if (pte_sw_dirty(pte))
> +		pte = pte_mkdirty(pte);
>  	return pte;

Looks like this is a fix for Catalin to pick up (patch #1 isn't necessary
afaict).

Will
James Houghton Dec. 11, 2023, 7:01 p.m. UTC | #3
On Mon, Dec 11, 2023 at 10:42 AM Will Deacon <will@kernel.org> wrote:
>
> On Mon, Dec 04, 2023 at 05:26:46PM +0000, James Houghton wrote:
> > Make it impossible to create a sw-dirty, hw-clean PTE with pte_modify.
> > Such a PTE should be impossible to create, and there may be places that
> > assume that pte_dirty() implies pte_hw_dirty().
> >
> > Signed-off-by: James Houghton <jthoughton@google.com>
>
> I'm not sure how, but you seem to be missing the '---' separator and the
> diffstat here, so I suspect this might confuse tools such as b4 which try
> to apply the patch directly.

Thanks for pointing that out. Looks like it came from using
`--summary` in git format-patch. :/

>
> > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> > index b19a8aee684c..79ce70fbb751 100644
> > --- a/arch/arm64/include/asm/pgtable.h
> > +++ b/arch/arm64/include/asm/pgtable.h
> > @@ -834,6 +834,12 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
> >               pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
> >
> >       pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
> > +     /*
> > +      * If we end up clearing hw dirtiness for a sw-dirty PTE, set hardware
> > +      * dirtiness again.
> > +      */
> > +     if (pte_sw_dirty(pte))
> > +             pte = pte_mkdirty(pte);
> >       return pte;
>
> Looks like this is a fix for Catalin to pick up (patch #1 isn't necessary
> afaict).

If only this patch is taken, make sure to add cc:stable and the fixes
tag from patch #1. Thank you!
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index b19a8aee684c..79ce70fbb751 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -834,6 +834,12 @@  static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 		pte = set_pte_bit(pte, __pgprot(PTE_DIRTY));
 
 	pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
+	/*
+	 * If we end up clearing hw dirtiness for a sw-dirty PTE, set hardware
+	 * dirtiness again.
+	 */
+	if (pte_sw_dirty(pte))
+		pte = pte_mkdirty(pte);
 	return pte;
 }