Message ID | 20210304171145.12281-2-ardb@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | arm64: use XN table mappings for the linear region | expand |
On Thu, Mar 04, 2021 at 06:11:44PM +0100, Ard Biesheuvel wrote: > Even though level 0, 1 and 2 descriptors share the same attribute > encodings, let's be a bit more consistent about using the right one at > the right level. So add new macros for level 0/P4D definitions, and > clean up some inconsistencies involving these macros. > > Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Mark Rutland <mark.rutland@arm.com> > --- > arch/arm64/include/asm/pgtable-hwdef.h | 9 +++++++++ > arch/arm64/mm/mmu.c | 6 +++--- > 2 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h > index 42442a0ae2ab..e64e77a345b2 100644 > --- a/arch/arm64/include/asm/pgtable-hwdef.h > +++ b/arch/arm64/include/asm/pgtable-hwdef.h > @@ -94,6 +94,15 @@ > /* > * Hardware page table definitions. > * > + * Level 0 descriptor (P4D). > + */ > +#define P4D_TYPE_TABLE (_AT(p4dval_t, 3) << 0) > +#define P4D_TABLE_BIT (_AT(p4dval_t, 1) << 1) > +#define P4D_TYPE_MASK (_AT(p4dval_t, 3) << 0) > +#define P4D_TYPE_SECT (_AT(p4dval_t, 1) << 0) > +#define P4D_SECT_RDONLY (_AT(p4dval_t, 1) << 7) /* AP[2] */ > + > +/* > * Level 1 descriptor (PUD). > */ > #define PUD_TYPE_TABLE (_AT(pudval_t, 3) << 0) > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 3802cfbdd20d..029091474042 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -309,7 +309,7 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, > phys_addr_t pud_phys; > BUG_ON(!pgtable_alloc); > pud_phys = pgtable_alloc(PUD_SHIFT); > - __p4d_populate(p4dp, pud_phys, PUD_TYPE_TABLE); > + __p4d_populate(p4dp, pud_phys, P4D_TYPE_TABLE); > p4d = READ_ONCE(*p4dp); > } > BUG_ON(p4d_bad(p4d)); > @@ -1209,11 +1209,11 @@ void __init early_fixmap_init(void) > pudp = pud_offset_kimg(p4dp, addr); > } else { > if (p4d_none(p4d)) > - __p4d_populate(p4dp, __pa_symbol(bm_pud), PUD_TYPE_TABLE); > + __p4d_populate(p4dp, __pa_symbol(bm_pud), P4D_TYPE_TABLE); > pudp = fixmap_pud(addr); > } > if (pud_none(READ_ONCE(*pudp))) > - __pud_populate(pudp, __pa_symbol(bm_pmd), PMD_TYPE_TABLE); > + __pud_populate(pudp, __pa_symbol(bm_pmd), PUD_TYPE_TABLE); > pmdp = fixmap_pmd(addr); > __pmd_populate(pmdp, __pa_symbol(bm_pte), PMD_TYPE_TABLE); > > -- > 2.20.1 >
On 3/4/21 10:41 PM, Ard Biesheuvel wrote: > Even though level 0, 1 and 2 descriptors share the same attribute > encodings, let's be a bit more consistent about using the right one at > the right level. So add new macros for level 0/P4D definitions, and > clean up some inconsistencies involving these macros. > > Signed-off-by: Ard Biesheuvel <ardb@kernel.org> > --- > arch/arm64/include/asm/pgtable-hwdef.h | 9 +++++++++ > arch/arm64/mm/mmu.c | 6 +++--- > 2 files changed, 12 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h > index 42442a0ae2ab..e64e77a345b2 100644 > --- a/arch/arm64/include/asm/pgtable-hwdef.h > +++ b/arch/arm64/include/asm/pgtable-hwdef.h > @@ -94,6 +94,15 @@ > /* > * Hardware page table definitions. > * > + * Level 0 descriptor (P4D). > + */ > +#define P4D_TYPE_TABLE (_AT(p4dval_t, 3) << 0) > +#define P4D_TABLE_BIT (_AT(p4dval_t, 1) << 1) > +#define P4D_TYPE_MASK (_AT(p4dval_t, 3) << 0) > +#define P4D_TYPE_SECT (_AT(p4dval_t, 1) << 0) > +#define P4D_SECT_RDONLY (_AT(p4dval_t, 1) << 7) /* AP[2] */ > + > +/* > * Level 1 descriptor (PUD). > */ > #define PUD_TYPE_TABLE (_AT(pudval_t, 3) << 0) > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index 3802cfbdd20d..029091474042 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -309,7 +309,7 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, > phys_addr_t pud_phys; > BUG_ON(!pgtable_alloc); > pud_phys = pgtable_alloc(PUD_SHIFT); > - __p4d_populate(p4dp, pud_phys, PUD_TYPE_TABLE); > + __p4d_populate(p4dp, pud_phys, P4D_TYPE_TABLE); > p4d = READ_ONCE(*p4dp); > } > BUG_ON(p4d_bad(p4d)); > @@ -1209,11 +1209,11 @@ void __init early_fixmap_init(void) > pudp = pud_offset_kimg(p4dp, addr); > } else { > if (p4d_none(p4d)) > - __p4d_populate(p4dp, __pa_symbol(bm_pud), PUD_TYPE_TABLE); > + __p4d_populate(p4dp, __pa_symbol(bm_pud), P4D_TYPE_TABLE); > pudp = fixmap_pud(addr); > } > if (pud_none(READ_ONCE(*pudp))) > - __pud_populate(pudp, __pa_symbol(bm_pmd), PMD_TYPE_TABLE); > + __pud_populate(pudp, __pa_symbol(bm_pmd), PUD_TYPE_TABLE); > pmdp = fixmap_pmd(addr); > __pmd_populate(pmdp, __pa_symbol(bm_pte), PMD_TYPE_TABLE); > > I guess there are still some more similar inconsistencies around. diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 3c6a7f5988b1..27cc643d0509 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -27,7 +27,7 @@ static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot) static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp) { - __pud_populate(pudp, __pa(pmdp), PMD_TYPE_TABLE); + __pud_populate(pudp, __pa(pmdp), PUD_TYPE_TABLE); } #else static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot) @@ -45,7 +45,7 @@ static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp) { - __p4d_populate(p4dp, __pa(pudp), PUD_TYPE_TABLE); + __p4d_populate(p4dp, __pa(pudp), P4D_TYPE_TABLE); } #else static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index d8e66c78440e..9fe40cbbd8c0 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -79,7 +79,7 @@ static pmd_t *__init kasan_pmd_offset(pud_t *pudp, unsigned long addr, int node, phys_addr_t pmd_phys = early ? __pa_symbol(kasan_early_shadow_pmd) : kasan_alloc_zeroed_page(node); - __pud_populate(pudp, pmd_phys, PMD_TYPE_TABLE); + __pud_populate(pudp, pmd_phys, PUD_TYPE_TABLE); } return early ? pmd_offset_kimg(pudp, addr) : pmd_offset(pudp, addr); @@ -92,7 +92,7 @@ static pud_t *__init kasan_pud_offset(p4d_t *p4dp, unsigned long addr, int node, phys_addr_t pud_phys = early ? __pa_symbol(kasan_early_shadow_pud) : kasan_alloc_zeroed_page(node); - __p4d_populate(p4dp, pud_phys, PMD_TYPE_TABLE); + __p4d_populate(p4dp, pud_phys, P4D_TYPE_TABLE); } return early ? pud_offset_kimg(p4dp, addr) : pud_offset(p4dp, addr);
On Mon, 8 Mar 2021 at 10:06, Anshuman Khandual <anshuman.khandual@arm.com> wrote: > > > > On 3/4/21 10:41 PM, Ard Biesheuvel wrote: > > Even though level 0, 1 and 2 descriptors share the same attribute > > encodings, let's be a bit more consistent about using the right one at > > the right level. So add new macros for level 0/P4D definitions, and > > clean up some inconsistencies involving these macros. > > > > Signed-off-by: Ard Biesheuvel <ardb@kernel.org> > > --- > > arch/arm64/include/asm/pgtable-hwdef.h | 9 +++++++++ > > arch/arm64/mm/mmu.c | 6 +++--- > > 2 files changed, 12 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h > > index 42442a0ae2ab..e64e77a345b2 100644 > > --- a/arch/arm64/include/asm/pgtable-hwdef.h > > +++ b/arch/arm64/include/asm/pgtable-hwdef.h > > @@ -94,6 +94,15 @@ > > /* > > * Hardware page table definitions. > > * > > + * Level 0 descriptor (P4D). > > + */ > > +#define P4D_TYPE_TABLE (_AT(p4dval_t, 3) << 0) > > +#define P4D_TABLE_BIT (_AT(p4dval_t, 1) << 1) > > +#define P4D_TYPE_MASK (_AT(p4dval_t, 3) << 0) > > +#define P4D_TYPE_SECT (_AT(p4dval_t, 1) << 0) > > +#define P4D_SECT_RDONLY (_AT(p4dval_t, 1) << 7) /* AP[2] */ > > + > > +/* > > * Level 1 descriptor (PUD). > > */ > > #define PUD_TYPE_TABLE (_AT(pudval_t, 3) << 0) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > > index 3802cfbdd20d..029091474042 100644 > > --- a/arch/arm64/mm/mmu.c > > +++ b/arch/arm64/mm/mmu.c > > @@ -309,7 +309,7 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, > > phys_addr_t pud_phys; > > BUG_ON(!pgtable_alloc); > > pud_phys = pgtable_alloc(PUD_SHIFT); > > - __p4d_populate(p4dp, pud_phys, PUD_TYPE_TABLE); > > + __p4d_populate(p4dp, pud_phys, P4D_TYPE_TABLE); > > p4d = READ_ONCE(*p4dp); > > } > > BUG_ON(p4d_bad(p4d)); > > @@ -1209,11 +1209,11 @@ void __init early_fixmap_init(void) > > pudp = pud_offset_kimg(p4dp, addr); > > } else { > > if (p4d_none(p4d)) > > - __p4d_populate(p4dp, __pa_symbol(bm_pud), PUD_TYPE_TABLE); > > + __p4d_populate(p4dp, __pa_symbol(bm_pud), P4D_TYPE_TABLE); > > pudp = fixmap_pud(addr); > > } > > if (pud_none(READ_ONCE(*pudp))) > > - __pud_populate(pudp, __pa_symbol(bm_pmd), PMD_TYPE_TABLE); > > + __pud_populate(pudp, __pa_symbol(bm_pmd), PUD_TYPE_TABLE); > > pmdp = fixmap_pmd(addr); > > __pmd_populate(pmdp, __pa_symbol(bm_pte), PMD_TYPE_TABLE); > > > > > > I guess there are still some more similar inconsistencies around. > Indeed - I will fix those as well in v2. Thanks, Ard. > diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h > index 3c6a7f5988b1..27cc643d0509 100644 > --- a/arch/arm64/include/asm/pgalloc.h > +++ b/arch/arm64/include/asm/pgalloc.h > @@ -27,7 +27,7 @@ static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot) > > static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp) > { > - __pud_populate(pudp, __pa(pmdp), PMD_TYPE_TABLE); > + __pud_populate(pudp, __pa(pmdp), PUD_TYPE_TABLE); > } > #else > static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot) > @@ -45,7 +45,7 @@ static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) > > static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp) > { > - __p4d_populate(p4dp, __pa(pudp), PUD_TYPE_TABLE); > + __p4d_populate(p4dp, __pa(pudp), P4D_TYPE_TABLE); > } > #else > static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) > diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c > index d8e66c78440e..9fe40cbbd8c0 100644 > --- a/arch/arm64/mm/kasan_init.c > +++ b/arch/arm64/mm/kasan_init.c > @@ -79,7 +79,7 @@ static pmd_t *__init kasan_pmd_offset(pud_t *pudp, unsigned long addr, int node, > phys_addr_t pmd_phys = early ? > __pa_symbol(kasan_early_shadow_pmd) > : kasan_alloc_zeroed_page(node); > - __pud_populate(pudp, pmd_phys, PMD_TYPE_TABLE); > + __pud_populate(pudp, pmd_phys, PUD_TYPE_TABLE); > } > > return early ? pmd_offset_kimg(pudp, addr) : pmd_offset(pudp, addr); > @@ -92,7 +92,7 @@ static pud_t *__init kasan_pud_offset(p4d_t *p4dp, unsigned long addr, int node, > phys_addr_t pud_phys = early ? > __pa_symbol(kasan_early_shadow_pud) > : kasan_alloc_zeroed_page(node); > - __p4d_populate(p4dp, pud_phys, PMD_TYPE_TABLE); > + __p4d_populate(p4dp, pud_phys, P4D_TYPE_TABLE); > } > > return early ? pud_offset_kimg(p4dp, addr) : pud_offset(p4dp, addr);
diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 42442a0ae2ab..e64e77a345b2 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -94,6 +94,15 @@ /* * Hardware page table definitions. * + * Level 0 descriptor (P4D). + */ +#define P4D_TYPE_TABLE (_AT(p4dval_t, 3) << 0) +#define P4D_TABLE_BIT (_AT(p4dval_t, 1) << 1) +#define P4D_TYPE_MASK (_AT(p4dval_t, 3) << 0) +#define P4D_TYPE_SECT (_AT(p4dval_t, 1) << 0) +#define P4D_SECT_RDONLY (_AT(p4dval_t, 1) << 7) /* AP[2] */ + +/* * Level 1 descriptor (PUD). */ #define PUD_TYPE_TABLE (_AT(pudval_t, 3) << 0) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 3802cfbdd20d..029091474042 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -309,7 +309,7 @@ static void alloc_init_pud(pgd_t *pgdp, unsigned long addr, unsigned long end, phys_addr_t pud_phys; BUG_ON(!pgtable_alloc); pud_phys = pgtable_alloc(PUD_SHIFT); - __p4d_populate(p4dp, pud_phys, PUD_TYPE_TABLE); + __p4d_populate(p4dp, pud_phys, P4D_TYPE_TABLE); p4d = READ_ONCE(*p4dp); } BUG_ON(p4d_bad(p4d)); @@ -1209,11 +1209,11 @@ void __init early_fixmap_init(void) pudp = pud_offset_kimg(p4dp, addr); } else { if (p4d_none(p4d)) - __p4d_populate(p4dp, __pa_symbol(bm_pud), PUD_TYPE_TABLE); + __p4d_populate(p4dp, __pa_symbol(bm_pud), P4D_TYPE_TABLE); pudp = fixmap_pud(addr); } if (pud_none(READ_ONCE(*pudp))) - __pud_populate(pudp, __pa_symbol(bm_pmd), PMD_TYPE_TABLE); + __pud_populate(pudp, __pa_symbol(bm_pmd), PUD_TYPE_TABLE); pmdp = fixmap_pmd(addr); __pmd_populate(pmdp, __pa_symbol(bm_pte), PMD_TYPE_TABLE);
Even though level 0, 1 and 2 descriptors share the same attribute encodings, let's be a bit more consistent about using the right one at the right level. So add new macros for level 0/P4D definitions, and clean up some inconsistencies involving these macros. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> --- arch/arm64/include/asm/pgtable-hwdef.h | 9 +++++++++ arch/arm64/mm/mmu.c | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-)