Re: [RFC PATCH v9 09/27] x86/mm: Introduce _PAGE_DIRTY_SW

Yu-cheng Yu
2020-04-01T19:08:26Z

On Wed, 2020-02-26 at 13:35 -0800, Dave Hansen wrote:
> On 2/5/20 10:19 AM, Yu-cheng Yu wrote:
> > When Shadow Stack (SHSTK) is introduced, a R/O and Dirty PTE exists in the
> > following cases:
> >
> > (a) A modified, copy-on-write (COW) page;
> > (b) A R/O page that has been COW'ed;
> > (c) A SHSTK page.
[...]

> > diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
> > index e647e3c75578..826823df917f 100644
> > --- a/arch/x86/include/asm/pgtable_types.h
> > +++ b/arch/x86/include/asm/pgtable_types.h
> > @@ -23,7 +23,8 @@
> > #define _PAGE_BIT_SOFTW2 10 /* " */
> > #define _PAGE_BIT_SOFTW3 11 /* " */
> > #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
> > -#define _PAGE_BIT_SOFTW4 58 /* available for programmer */
> > +#define _PAGE_BIT_SOFTW4 57 /* available for programmer */
> > +#define _PAGE_BIT_SOFTW5 58 /* available for programmer */
> > #define _PAGE_BIT_PKEY_BIT0 59 /* Protection Keys, bit 1/4 */
> > #define _PAGE_BIT_PKEY_BIT1 60 /* Protection Keys, bit 2/4 */
> > #define _PAGE_BIT_PKEY_BIT2 61 /* Protection Keys, bit 3/4 */
> > @@ -35,6 +36,12 @@
> > #define _PAGE_BIT_SOFT_DIRTY _PAGE_BIT_SOFTW3 /* software dirty tracking */
> > #define _PAGE_BIT_DEVMAP _PAGE_BIT_SOFTW4
> >
> > +/*
> > + * This bit indicates a copy-on-write page, and is different from
> > + * _PAGE_BIT_SOFT_DIRTY, which tracks which pages a task writes to.
> > + */
> > +#define _PAGE_BIT_DIRTY_SW _PAGE_BIT_SOFTW5 /* was written to */
>
> Does it *only* indicate a copy-on-write (or copy-on-access) page? If
> so, haven't we misnamed it?

It indicates either a copy-on-write page or a read-only page that has been
cow'ed. What about _PAGE_BIT_COW?

Yu-cheng