arm64/mm: Enable 128 bit page table entries
Subsystems (10)
v3 cover arm64/mm: Enable 128 bit page table entries
FEAT_D128 is a new arm architecture feature adding support for VMSAv9-128 translation system. FEAT_D128 is an optional feature from ARMV9.3 onwards. arm64 platforms with FEAT_D128 enabled will now have two different memory translation systems i.e VMSAv8-64 and VMSAv9-128.
FEAT_D128 adds 128 bit page table entries, thus supporting larger physical and virtual address range while also expanding available room for more MMU feature bits for both HW and SW usage.
A new config option ARM64_D128 is being added thus enabling users to chose between aforementioned memory translations regimes VMSAv8-64 (aka D64) and VMSAv9-128 (aka D128) during the build time. If the ARM64_D128 built kernel does not detect FEAT_D128 feature on the hardware, then it gets stuck with with a new reason code CPU_STUCK_REASON_NO_D128. So ARM64_D128 built kernel cannot fallback to D64 translation regime on unsupported HW. Besides config ARM64_D128 is only available with CONFIG_EXPERT.
ARM64_[VA|PA]_BITS combinations for respective CONFIG_ARM64_XXK_PAGES are now supported both on VMSAv8-64 and VMSAv9-128 memory translation regimes. Although FEAT_D128 provided 52 bit VA and PA space along with skip levels are not supported currently.
Basic page table geometry has also been changed with VMSAv9-128, as there are fewer entries per level as compared to VMSAv8-64. Please refer to the following table for various leaf entry sizes including the cont entries.
------------------------------------------------
| | D64 | D128 |
------------------------------------------------
| PAGE_SIZE | PMD | PUD | PMD | PUD | -----------------------------|-----------------| | 4K | 2M | 1G | 1M | 256M | | 16K | 32M | 64G | 16M | 16G | | 64K | 512M | 4T | 256M | 1T |
------------------------------------------------
--------------------------------------------------------------------
| | D64 | D128 |
--------------------------------------------------------------------
| PAGE_SIZE | CONT_PTE | CONT_PMD | CONT_PTE | CONT_PMD | --------------------------|------------|-------------|-------------- | 4K | 64K | 32M | 64K | 16M | | 16K | 2M | 1G | 1M | 256M | | 64K | 2M | 16G | 1M | 16G |
--------------------------------------------------------------------
Besides arm64 kernel features such as KVM and UNMAP_KERNEL_AT_EL0 are not supported currently. This series applies on v7.4-rc3 after applying the following posted earlier.
https://lore.kernel.org/all/[email protected]/
There are no apparent problems while running MM kselftests with and without CONFIG_ARM64_D128 being enabled on various pgtable geometry configurations.
For referfence
[email protected]:linux-arm/linux-anshuman.git (arm64_d128_V3)
Changes in V3:
- Rebased on v7.4-rc3
- Add const pgprot_t * in pgprot_read() both for generic and arm64 per David
- Fixed indent problems in ___ptep_set_wrprotect() and __clear_young_dirty_pte()
- Updated commit message for the 5-level fixmap patch per David
Changes in V2:
https://lore.kernel.org/all/[email protected]/
- Rebased on v7.3-rc1
- Enabled KASAN on D128 - dropped !KASAN dependency from CONFIG_ARM64_D128
- Split out pgtable printf standardizsation into a separate series
- Split out READ_ONCE() conversion into separate series
- Added d128.config for testing ARM64_D128 enabled kernels in CI environment
Changes in V1:
https://lore.kernel.org/all/[email protected]/
- Rebased on v7.2-rc5
- Pulled in new standardized pgtable entry print patch
- Added standardized pgtable entry print on arm64 platform
- Added KASAN related pgdp_get() changes missing earlier
- Renamed pxxval_get/set() as ptval_get/set()
- Renamed ptval_cmpxchg_relaxed() and ptval_xchg_relaxed()
- Renamed tlbi_args_t as tlbi_arg_t per Ryan
- Split final D128 enablement patch into four separate ones
- Updated all commit messages as required
Changes in RFC V2:
https://lore.kernel.org/all/[email protected]/
- Dropped some patches that were merged upstream and rebased on v7.1-rc3
- Updated commit message for the 5-level fixmap change per David
- Moved pxdval_t definition inside generic page table header
- Dropped _once from pgprot_read/write() per Mike
- Updated ARM64_CONT_[PTE|PMD]_SHIFT both for 16K and 64K base pages
- Renamed __PRIpte as __PRIpxx per David
- Added abstraction for tlbi_op
- Adopted TLBIP implementation to recent TLB flush changes
- Moved back all helpers back from arch/arm64/mm/mmu.c into the header
- Moved arm64 pgtable header READ_ONCE() replacements later in the series
- Renamed all ptdesc_ instances as pxxval_ instead
- Updated all commit messages as required and suggested
- Restored print format in __print_bad_page_map_pgtable() per Usama
Changes in RFC V1:
https://lore.kernel.org/linux-arm-kernel/[email protected]/
Anshuman Khandual (12):
mm: Add read-write accessors for vm_page_prot arm64/mm: Route all pgtable reads via ptval_get() arm64/mm: Route all pgtable writes via ptval_set() arm64/mm: Route all pgtable atomics to central helpers arm64/mm: Override read-write accessors for vm_page_prot arm64/mm: Enable fixmap with 5 level page table arm64/mm: Enable pgtable geometry for FEAT_D128 arm64/mm: Enable pgtable descriptor for FEAT_D128 arm64/mm: Enable 128 bit translation
arm64/mm: Relax KASAN shadow alignment for FEAT_D128 arm64/mm: Make ARM64_D128 selectable arm64/configs: Add d128.config
Linu Cherian (2):
arm64/mm: Add an abstraction level for tlbi_op arm64/mm: Enable TLBIP instruction based TLB flush
arch/arm64/Kconfig | 50 ++++++++- arch/arm64/Makefile | 4 + arch/arm64/configs/d128.config | 6 ++ arch/arm64/include/asm/assembler.h | 4 +- arch/arm64/include/asm/el2_setup.h | 9 ++ arch/arm64/include/asm/pgtable-hwdef.h | 137 ++++++++++++++++++++++++ arch/arm64/include/asm/pgtable-prot.h | 20 +++- arch/arm64/include/asm/pgtable-types.h | 4 + arch/arm64/include/asm/pgtable.h | 120 +++++++++++++++++---- arch/arm64/include/asm/smp.h | 1 + arch/arm64/include/asm/tlbflush.h | 138 +++++++++++++++++-------- arch/arm64/kernel/head.S | 12 +++ arch/arm64/mm/fault.c | 2 +- arch/arm64/mm/fixmap.c | 18 +++- arch/arm64/mm/kasan_init.c | 4 +- arch/arm64/mm/mmu.c | 4 +- arch/arm64/mm/proc.S | 25 ++++- include/linux/pgtable.h | 14 +++ mm/huge_memory.c | 4 +- mm/memory.c | 2 +- mm/migrate.c | 2 +- mm/mmap.c | 2 +- 22 files changed, 497 insertions(+), 85 deletions(-) create mode 100644 arch/arm64/configs/d128.config
Signature · 1 line
2.43.0
PATCH v3 1/14 mm: Add read-write accessors for vm_page_prot
Currently vma->vm_page_prot is safely read from and written to, without any locks with READ_ONCE() and WRITE_ONCE(). But with introduction of D128 page tables on arm64 platform, vm_page_prot grows to 128 bits which can't safely be handled with READ_ONCE() and WRITE_ONCE().
Add read and write accessors for vm_page_prot like pgprot_[read|write]() which any platform can override when required, although still defaulting as READ_ONCE() and WRITE_ONCE(), thus preserving the functionality for others.
---
Changes in V3:
- Add const pgprot_t * in pgprot_read()
include/linux/pgtable.h | 14 ++++++++++++++ mm/huge_memory.c | 4 ++-- mm/memory.c | 2 +- mm/migrate.c | 2 +- mm/mmap.c | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-)
include/linux/pgtable.h +14 -0
@@ -524,6 +524,20 @@ static inline pgd_t pgdp_get(const pgd_t *pgdp) }#endif +#ifndef pgprot_read +static inline pgprot_t pgprot_read (const pgprot_t *prot) +{ +return READ_ONCE (*prot); +} +#endif + +#ifndef pgprot_write +static inline void pgprot_write (pgprot_t *prot,pgprot_t val) +{ +WRITE_ONCE (*prot, val); +} +#endif +#ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNGstatic inline bool ptep_test_and_clear_young (struct vm_area_struct *vma,unsigned long address,pte_t *ptep)
mm/huge_memory.c +2 -2
@@ -3438,7 +3438,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, }else {pte_t entry; - entry =mk_pte (page,READ_ONCE (vma->vm_page_prot)); + entry =mk_pte (page,pgprot_read (&vma->vm_page_prot));if (write) entry =pte_mkwrite (entry, vma);if (!young)
@@ -5217,7 +5217,7 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct folio *folio entry =softleaf_from_pmd (*pvmw->pmd);folio_get (folio); - pmde =folio_mk_pmd (folio,READ_ONCE (vma->vm_page_prot)); + pmde =folio_mk_pmd (folio,pgprot_read (&vma->vm_page_prot));if (pmd_swp_soft_dirty (*pvmw->pmd)) pmde =pmd_mksoft_dirty (pmde);
mm/memory.c +1 -1
@@ -915,7 +915,7 @@ static void restore_exclusive_pte(struct vm_area_struct *vma,VM_WARN_ON_FOLIO (!folio_test_locked (folio), folio); - pte =pte_mkold (mk_pte (page,READ_ONCE (vma->vm_page_prot))); + pte =pte_mkold (mk_pte (page,pgprot_read (&vma->vm_page_prot)));if (pte_swp_soft_dirty (orig_pte)) pte =pte_mksoft_dirty (pte);
mm/migrate.c +1 -1
@@ -387,7 +387,7 @@ static bool remove_migration_pte(struct folio *folio,folio_get (folio); new =folio_page (folio, idx); - pte =mk_pte (new,READ_ONCE (vma->vm_page_prot)); + pte =mk_pte (new,pgprot_read (&vma->vm_page_prot));if (!softleaf_is_migration_young (entry)) pte =pte_mkold (pte);if (folio_test_dirty (folio) &&softleaf_is_migration_dirty (entry))
mm/mmap.c +1 -1
@@ -89,7 +89,7 @@ void vma_set_page_prot(struct vm_area_struct *vma) vm_page_prot =vma_pgprot_modify (vm_page_prot, vma_flags); }/* remove_protection_ptes reads vma->vm_page_prot without mmap_lock */ -WRITE_ONCE (vma->vm_page_prot, vm_page_prot); +pgprot_write (&vma->vm_page_prot, vm_page_prot); }/*
Signature · 1 line
2.43.0
PATCH v3 2/14 arm64/mm: Route all pgtable reads via ptval_get()
In reply to Anshuman KhandualDefine arm64 platform specific implementations for new pxdp_get() helpers. These resolve into READ_ONCE(), thus ensuring required single copy atomic semantics for the page table entry reads.
In future this infrastructure can be used for D128 to maintain single copy atomicity semantics with inline asm blocks.
--- arch/arm64/include/asm/pgtable.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
arch/arm64/include/asm/pgtable.h +7 -5
@@ -84,28 +84,30 @@ static inline void arch_leave_lazy_mmu_mode(void)arch_flush_lazy_mmu_mode (); } +#define ptval_get (x) READ_ONCE(x) +#define pmdp_get pmdp_getstatic inline pmd_t pmdp_get (const pmd_t *pmdp) { -return READ_ONCE (*pmdp); +return ptval_get (*pmdp); }#define pudp_get pudp_getstatic inline pud_t pudp_get (const pud_t *pudp) { -return READ_ONCE (*pudp); +return ptval_get (*pudp); }#define p4dp_get p4dp_getstatic inline p4d_t p4dp_get (const p4d_t *p4dp) { -return READ_ONCE (*p4dp); +return ptval_get (*p4dp); }#define pgdp_get pgdp_getstatic inline pgd_t pgdp_get (const pgd_t *pgdp) { -return READ_ONCE (*pgdp); +return ptval_get (*pgdp); }#ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -405,7 +407,7 @@ static inline void __set_pte(pte_t *ptep, pte_t pte)static inline pte_t __ptep_get (pte_t *ptep) { -return READ_ONCE (*ptep); +return ptval_get (*ptep); }extern void __sync_icache_dcache (pte_t pteval);
Signature · 1 line
2.43.0
PATCH v3 3/14 arm64/mm: Route all pgtable writes via ptval_set()
In reply to Anshuman KhandualCurrently ptval_set() is defined as WRITE_ONCE() but this will change for D128 pgtable builds, for which WRITE_ONCE() is not sufficient for single copy atomicity.
In future this infrastructure can be used for D128 to maintain single copy atomicity semantics with inline asm blocks.
--- arch/arm64/include/asm/pgtable.h | 11 ++++++----- arch/arm64/mm/mmu.c | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-)
arch/arm64/include/asm/pgtable.h +6 -5
@@ -85,6 +85,7 @@ static inline void arch_leave_lazy_mmu_mode(void) }#define ptval_get (x) READ_ONCE(x) +#define ptval_set (x, val) WRITE_ONCE(x, val)#define pmdp_get pmdp_getstatic inline pmd_t pmdp_get (const pmd_t *pmdp)
@@ -386,7 +387,7 @@ static inline pte_t pte_clear_uffd(pte_t pte)static inline void __set_pte_nosync (pte_t *ptep,pte_t pte) { -WRITE_ONCE (*ptep, pte); +ptval_set (*ptep, pte); }static inline void __set_pte_complete (pte_t pte)
@@ -815,7 +816,7 @@ static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) }#endif /* __PAGETABLE_PMD_FOLDED */ -WRITE_ONCE (*pmdp, pmd); +ptval_set (*pmdp, pmd);if (pmd_valid (pmd))queue_pte_barriers ();
@@ -877,7 +878,7 @@ static inline void set_pud(pud_t *pudp, pud_t pud)return ; } -WRITE_ONCE (*pudp, pud); +ptval_set (*pudp, pud);if (pud_valid (pud))queue_pte_barriers ();
@@ -956,7 +957,7 @@ static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)return ; } -WRITE_ONCE (*p4dp, p4d); +ptval_set (*p4dp, p4d);queue_pte_barriers (); }
@@ -1081,7 +1082,7 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)return ; } -WRITE_ONCE (*pgdp, pgd); +ptval_set (*pgdp, pgd);queue_pte_barriers (); }
arch/arm64/mm/mmu.c +2 -2
@@ -75,7 +75,7 @@ void noinstr set_swapper_pgd(pgd_t *pgdp, pgd_t pgd)* writable in the kernel mapping. */ if (rodata_is_rw) { -WRITE_ONCE (*pgdp, pgd); +ptval_set (*pgdp, pgd);dsb (ishst);isb ();return ;
@@ -83,7 +83,7 @@ void noinstr set_swapper_pgd(pgd_t *pgdp, pgd_t pgd)spin_lock (&swapper_pgdir_lock); fixmap_pgdp =pgd_set_fixmap (__pa_symbol (pgdp)); -WRITE_ONCE (*fixmap_pgdp, pgd); +ptval_set (*fixmap_pgdp, pgd);/* * We need dsb(ishst) here to ensure the page-table-walker sees * our new entry before set_p?d() returns. The fixmap's
Signature · 1 line
2.43.0
PATCH v3 4/14 arm64/mm: Route all pgtable atomics to central helpers
In reply to Anshuman KhandualRoute all cmpxchg() operations performed on various page table entries to a new ptval_cmpxchg_relaxed() helper. Similarly route all xchg() operations performed on page table entries to a new ptval_xchg_relaxed() helper.
Currently these helpers just forward to the same APIs that were previously called direct, but in future we will change the routing for D128 which is too long to use the standard APIs.
---
Changes in V3:
- Fixed indent problems in ___ptep_set_wrprotect() and __clear_young_dirty_pte()
arch/arm64/include/asm/pgtable.h | 30 +++++++++++++++++++++--------- arch/arm64/mm/fault.c | 2 +- 2 files changed, 22 insertions(+), 10 deletions(-)
arch/arm64/include/asm/pgtable.h +21 -9
@@ -87,6 +87,17 @@ static inline void arch_leave_lazy_mmu_mode(void)#define ptval_get (x) READ_ONCE(x)#define ptval_set (x, val) WRITE_ONCE(x, val) +static inline ptval_t ptval_cmpxchg_relaxed (ptval_t *ptep,ptval_t old, +ptval_t new) +{ +return cmpxchg_relaxed (ptep, old, new); +} + +static inline ptval_t ptval_xchg_relaxed (ptval_t *ptep,ptval_t new) +{ +return xchg_relaxed (ptep, new); +} +#define pmdp_get pmdp_getstatic inline pmd_t pmdp_get (const pmd_t *pmdp) {
@@ -1287,8 +1298,8 @@ static inline bool __ptep_test_and_clear_young(struct vm_area_struct *vma,do { old_pte = pte; pte =pte_mkold (pte); -pte_val (pte) =cmpxchg_relaxed (&pte_val (*ptep), -pte_val (old_pte),pte_val (pte)); +pte_val (pte) =ptval_cmpxchg_relaxed (&pte_val (*ptep), +pte_val (old_pte),pte_val (pte)); }while (pte_val (pte) !=pte_val (old_pte));return pte_young (pte);
@@ -1330,7 +1341,7 @@ static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm, pte_t *ptep, unsigned long pgsize) { -pte_t pte =__pte (xchg_relaxed (&pte_val (*ptep),0 )); +pte_t pte =__pte (ptval_xchg_relaxed (&pte_val (*ptep),0 ));switch (pgsize) {case PAGE_SIZE :
@@ -1406,8 +1417,8 @@ static inline void ___ptep_set_wrprotect(struct mm_struct *mm,do { old_pte = pte; pte =pte_wrprotect (pte); -pte_val (pte) =cmpxchg_relaxed (&pte_val (*ptep), -pte_val (old_pte),pte_val (pte)); +pte_val (pte) =ptval_cmpxchg_relaxed (&pte_val (*ptep), +pte_val (old_pte),pte_val (pte)); }while (pte_val (pte) !=pte_val (old_pte)); }
@@ -1444,8 +1455,8 @@ static inline void __clear_young_dirty_pte(struct vm_area_struct *vma,if (flags &CYDP_CLEAR_DIRTY ) pte =pte_mkclean (pte); -pte_val (pte) =cmpxchg_relaxed (&pte_val (*ptep), -pte_val (old_pte),pte_val (pte)); +pte_val (pte) =ptval_cmpxchg_relaxed (&pte_val (*ptep), +pte_val (old_pte),pte_val (pte)); }while (pte_val (pte) !=pte_val (old_pte)); }
@@ -1483,7 +1494,7 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp, pmd_t pmd) { page_table_check_pmd_set(vma->vm_mm, address, pmdp, pmd); -return __pmd (xchg_relaxed (&pmd_val (*pmdp),pmd_val (pmd))); +return __pmd (ptval_xchg_relaxed (&pmd_val (*pmdp),pmd_val (pmd))); }#endif
@@ -1813,7 +1824,8 @@ static inline bool ptep_try_set(pte_t *ptep, pte_t new_pte) {pteval_t old =0 ; -if (!try_cmpxchg (&pte_val (*ptep), &old,pte_val (new_pte))) + old =ptval_cmpxchg_relaxed (&pte_val (*ptep), old,pte_val (new_pte)); +if (old !=0 )return false;/*
arch/arm64/mm/fault.c +1 -1
@@ -244,7 +244,7 @@ int __ptep_set_access_flags_anysz(struct vm_area_struct *vma, pteval ^=PTE_RDONLY ; pteval |=pte_val (entry); pteval ^=PTE_RDONLY ; - pteval =cmpxchg_relaxed (&pte_val (*ptep), old_pteval, pteval); + pteval =ptval_cmpxchg_relaxed (&pte_val (*ptep), old_pteval, pteval); }while (pteval != old_pteval);/*
Signature · 1 line
2.43.0
PATCH v3 5/14 arm64/mm: Override read-write accessors for vm_page_prot
In reply to Anshuman KhandualOverride pgprot_[read|write]() accessors using ptval_[get|set]() providing required single copy atomic operation for vma->vm_page_prot.
---
Changes in V3:
- Add const pgprot_t * in pgprot_read()
arch/arm64/include/asm/pgtable.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/arm64/include/asm/pgtable.h +12 -0
@@ -122,6 +122,18 @@ static inline pgd_t pgdp_get(const pgd_t *pgdp)return ptval_get (*pgdp); } +#define pgprot_read pgprot_read +static inline pgprot_t pgprot_read (const pgprot_t *prot) +{ +return ptval_get (*prot); +} + +#define pgprot_write pgprot_write +static inline void pgprot_write (pgprot_t *prot,pgprot_t val) +{ +ptval_set (*prot, val); +} +#ifdef CONFIG_TRANSPARENT_HUGEPAGE #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE
Signature · 1 line
2.43.0
PATCH v3 6/14 arm64/mm: Enable fixmap with 5 level page table
In reply to Anshuman KhandualFEAT_D128 halves PTRS_PER_PXX thus shrinking the VA range coverage for each pgtable level. So in order to preserve all existing VA range configurations for various base page sizes, some pgtable configurations now need to become 5-level which were 4-level earlier.
Since fixmap builds and manipulates kernel page tables early on during boot these mappings must also gain that additional level, which was not required earlier.
Changes in the page table geometry can result in the P4D table covering the fixmap range no longer being populated by other kernel initialization code.
Enable this scenario by allocating and populating a static P4D table during early fixmap initialization, similar to the existing handling of other page table levels.
Add a pgd_page_paddr() fallback stub when (PGTBALE_LEVELS <= 4) which helps in intercepting any unintended usage.
---
Changes in V3:
- Updated the commit message
arch/arm64/include/asm/pgtable.h | 1 + arch/arm64/mm/fixmap.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-)
arch/arm64/include/asm/pgtable.h +1 -0
@@ -1184,6 +1184,7 @@ static inline p4d_t *p4d_offset_kimg(pgd_t *pgdp, u64 addr)#else static inline bool pgtable_l5_enabled (void ) {return false; } +#define pgd_page_paddr (pgd) ({ BUILD_BUG(); 0; })#define p4d_index (addr) (((addr) >> P4D_SHIFT) & (PTRS_PER_P4D - 1))
arch/arm64/mm/fixmap.c +15 -3
@@ -34,6 +34,7 @@ static_assert(NR_BM_PMD_TABLES == 1); static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __bss_pgtbl; static pmd_t bm_pmd[PTRS_PER_PMD] __bss_pgtbl __maybe_unused; static pud_t bm_pud[PTRS_PER_PUD] __bss_pgtbl __maybe_unused; +static p4d_t bm_p4d[PTRS_PER_P4D] __bss_pgtbl __maybe_unused;static inline pte_t *fixmap_pte (unsigned long addr) {
@@ -95,6 +96,19 @@ static void __init early_fixmap_init_pud(p4d_t *p4dp, unsigned long addr,early_fixmap_init_pmd (pudp, addr, end); } +static void __init early_fixmap_init_p4d (pgd_t *pgdp,unsigned long addr, +unsigned long end) +{ +pgd_t pgd =pgdp_get (pgdp); +p4d_t *p4dp; + +if (pgd_none (pgd)) +__pgd_populate (pgdp,__pa_symbol (bm_p4d), +PGD_TYPE_TABLE |PGD_TABLE_AF ); + p4dp =p4d_offset_kimg (pgdp, addr); +early_fixmap_init_pud (p4dp, addr, end); +} +/* * The p*d_populate functions call virt_to_phys implicitly so they can't be used * directly on kernel symbols (bm_p*d). This function is called too early to use
@@ -107,9 +121,7 @@ void __init early_fixmap_init(void)unsigned long end =FIXADDR_TOP ;pgd_t *pgdp =pgd_offset_k (addr); -p4d_t *p4dp =p4d_offset_kimg (pgdp, addr); - -early_fixmap_init_pud (p4dp, addr, end); +early_fixmap_init_p4d (pgdp, addr, end); }/*
Signature · 1 line
2.43.0
PATCH v3 7/14 arm64/mm: Enable pgtable geometry for FEAT_D128
In reply to Anshuman KhandualAdd build time support for FEAT_D128 page tables with a new Kconfig option i.e CONFIG_ARM64_D128. When selected, PTE types become 128 bits wide and PTE bits are mapped to their new locations. Besides the basic page table geometry is also updated since each table page now holds half the number of entries (aka PTRS_PER_PXX) as it did previously. Similarly update the geometry relevant macros ARM64_CONT_[PTE|PMD]_SHIFT, PGTABLE_LEVELS, and PTDESC_ORDER.
Although for now config ARM64_D128 remains disabled while all the required dependencies are getting created in subsequent patches.
--- arch/arm64/Kconfig | 37 ++++++++++++++++++++++---- arch/arm64/include/asm/pgtable-hwdef.h | 4 +++ arch/arm64/include/asm/pgtable.h | 2 ++ 3 files changed, 38 insertions(+), 5 deletions(-)
arch/arm64/Kconfig +32 -5
@@ -280,14 +280,18 @@ config MMU config ARM64_CONT_PTE_SHIFT int - default 5 if PAGE_SIZE_64KB - default 7 if PAGE_SIZE_16KB + default 4 if PAGE_SIZE_64KB && ARM64_D128 + default 5 if PAGE_SIZE_64KB && !ARM64_D128 + default 6 if PAGE_SIZE_16KB && ARM64_D128 + default 7 if PAGE_SIZE_16KB && !ARM64_D128 default 4 config ARM64_CONT_PMD_SHIFT int - default 5 if PAGE_SIZE_64KB - default 5 if PAGE_SIZE_16KB + default 6 if PAGE_SIZE_64KB && ARM64_D128 + default 5 if PAGE_SIZE_64KB && !ARM64_D128 + default 4 if PAGE_SIZE_16KB && ARM64_D128 + default 5 if PAGE_SIZE_16KB && !ARM64_D128 default 4 config ARCH_MMAP_RND_BITS_MIN
@@ -366,6 +370,16 @@ config FIX_EARLYCON_MEM config PGTABLE_LEVELS int + default 4 if ARM64_D128 && ARM64_4K_PAGES && ARM64_VA_BITS_39 + default 5 if ARM64_D128 && ARM64_4K_PAGES && ARM64_VA_BITS_48 + default 5 if ARM64_D128 && ARM64_4K_PAGES && ARM64_VA_BITS_52 + default 3 if ARM64_D128 && ARM64_16K_PAGES && ARM64_VA_BITS_36 + default 4 if ARM64_D128 && ARM64_16K_PAGES && ARM64_VA_BITS_47 + default 4 if ARM64_D128 && ARM64_16K_PAGES && ARM64_VA_BITS_48 + default 4 if ARM64_D128 && ARM64_16K_PAGES && ARM64_VA_BITS_52 + default 3 if ARM64_D128 && ARM64_64K_PAGES && ARM64_VA_BITS_42 + default 3 if ARM64_D128 && ARM64_64K_PAGES && ARM64_VA_BITS_48 + default 3 if ARM64_D128 && ARM64_64K_PAGES && ARM64_VA_BITS_52 default 2 if ARM64_16K_PAGES && ARM64_VA_BITS_36 default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42 default 3 if ARM64_64K_PAGES && (ARM64_VA_BITS_48 || ARM64_VA_BITS_52)
@@ -1697,7 +1711,7 @@ config ARM64_PA_BITS config ARM64_LPA2 def_bool y - depends on ARM64_PA_BITS_52 && !ARM64_64K_PAGES + depends on ARM64_PA_BITS_52 && !ARM64_64K_PAGES && !ARM64_D128 config NR_CPUS int "Maximum number of CPUs (2-4096)"
@@ -2369,6 +2383,19 @@ config ARM64_HAFT endmenu # "ARMv8.9 architectural features" +menu "ARMv9.3 architectural features" + +config ARM64_D128 + bool + default n + help + ARMv9.3 introduces FEAT_D128, which provides a 128 bit page + table format, along with related instructions. + + If unsure, say Y. + +endmenu # "ARMv9.3 architectural features" + menu "ARMv9.4 architectural features" config ARM64_GCS
arch/arm64/include/asm/pgtable-hwdef.h +4 -0
@@ -7,7 +7,11 @@#include <asm/memory.h> +#ifdef CONFIG_ARM64_D128 +#define PTDESC_ORDER 4 +#else #define PTDESC_ORDER 3 +#endif /* Number of VA bits resolved by a single translation table level */ #define PTDESC_TABLE_SHIFT (PAGE_SHIFT - PTDESC_ORDER)
arch/arm64/include/asm/pgtable.h +2 -0
@@ -1081,6 +1081,8 @@ static inline bool pgtable_l4_enabled(void) { return false; } static __always_inline bool pgtable_l5_enabled(void) { +if (IS_ENABLED (CONFIG_ARM64_D128 )) +return true;if (!alternative_has_cap_likely (ARM64_ALWAYS_BOOT ))return vabits_actual ==VA_BITS ;return alternative_has_cap_unlikely (ARM64_HAS_VA52 );
Signature · 1 line
2.43.0
PATCH v3 8/14 arm64/mm: Enable pgtable descriptor for FEAT_D128
In reply to Anshuman KhandualEnable pgtable descriptor fields and related accessors for FEAT_D128. First expand ptval_t as 128 bits, add all D128 specific pgtable descriptor fields and update accessors like ptval_get/set() and ptval_xchg_relaxed(). Also do ensure that ARM64_PA_BITS_52 specific handlings are not applicable for D128 which does not follow PA bits folding mechanisms as in FEAT_[LPA|LPA2].
Although all the above changes gets enabled only with CONFIG_ARM64_D128.
--- arch/arm64/include/asm/assembler.h | 4 +- arch/arm64/include/asm/pgtable-hwdef.h | 133 +++++++++++++++++++++++++ arch/arm64/include/asm/pgtable-prot.h | 20 +++- arch/arm64/include/asm/pgtable-types.h | 4 + arch/arm64/include/asm/pgtable.h | 52 +++++++++- arch/arm64/mm/proc.S | 2 +- 6 files changed, 208 insertions(+), 7 deletions(-)
arch/arm64/include/asm/assembler.h +2 -2
@@ -597,7 +597,7 @@ alternative_else_nop_endif* ttbr: returns the TTBR value */ .macro phys_to_ttbr, ttbr, phys -#ifdef CONFIG_ARM64_PA_BITS_52 +#if defined(CONFIG_ARM64_PA_BITS_52 ) && !defined(CONFIG_ARM64_D128 ) orr \ttbr, \phys, \phys, lsr #46 and \ttbr, \ttbr, #TTBR_BADDR_MASK_52 #else
@@ -606,7 +606,7 @@ alternative_else_nop_endif .endm .macro phys_to_pte, pte, phys -#ifdef CONFIG_ARM64_PA_BITS_52 +#if defined(CONFIG_ARM64_PA_BITS_52 ) && !defined(CONFIG_ARM64_D128 ) orr \pte, \phys, \phys, lsr #PTE_ADDR_HIGH_SHIFT and \pte, \pte, #PHYS_TO_PTE_ADDR_MASK #else
arch/arm64/include/asm/pgtable-hwdef.h +133 -0
146 lines not on this page · raw message
arch/arm64/include/asm/pgtable-prot.h +18 -2
@@ -13,10 +13,15 @@/* * Software defined PTE bits definition. */ -#define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_WRITE (PTE_DBM)/* same as DBM (51 / 116) */ #define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */ +#ifdef CONFIG_ARM64_D128 +#define PTE_DIRTY (_AT(pteval_t, 1) << 91) +#define PTE_SPECIAL (_AT(pteval_t, 1) << 92) +#else #define PTE_DIRTY (_AT(pteval_t, 1) << 55)#define PTE_SPECIAL (_AT(pteval_t, 1) << 56) +#endif /* * PTE_PRESENT_INVALID=1 & PTE_VALID=0 indicates that the pte's fields should be
@@ -28,7 +33,11 @@#define PTE_PRESENT_VALID_KERNEL (PTE_VALID | PTE_MAYBE_NG)#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP -#define PTE_UFFD (_AT(pteval_t, 1) << 58)/* userfaultfd tracking */ +#ifdef CONFIG_ARM64_D128 +#define PTE_UFFD (_AT(pteval_t, 1) << 94)/* userfaultd tracking */ +#else +#define PTE_UFFD (_AT(pteval_t, 1) << 58)/* userfaultd tracking */ +#endif /* CONFIG_ARM64_D128 */ #define PTE_SWP_UFFD (_AT(pteval_t, 1) << 3)/* only for swp ptes */ #else #define PTE_UFFD (_AT(pteval_t, 0))
@@ -131,11 +140,18 @@ static inline bool __pure lpa2_is_enabled(void)#endif /* __ASSEMBLER__ */ +#ifdef CONFIG_ARM64_D128 +#define pte_pi_index (pte) (((pte) & PTE_PI_MASK) >> PTE_PI_SHIFT) +#define pte_po_index (pte) ((pte_val(pte) & PTE_PO_IDX_MASK) >> PTE_PO_IDX_SHIFT) +#else #define pte_pi_index (pte) ( \ ((pte & BIT(PTE_PI_IDX_3)) >> (PTE_PI_IDX_3 - 3)) | \ ((pte & BIT(PTE_PI_IDX_2)) >> (PTE_PI_IDX_2 - 2)) | \ ((pte & BIT(PTE_PI_IDX_1)) >> (PTE_PI_IDX_1 - 1)) | \ ((pte & BIT(PTE_PI_IDX_0)) >> (PTE_PI_IDX_0 - 0))) +#define pte_po_index (pte) FIELD_GET(PTE_PO_IDX_MASK, pte_val(pte)) +#endif +/* * Page types used via Permission Indirection Extension (PIE). PIE uses
arch/arm64/include/asm/pgtable-types.h +4 -0
@@ -17,7 +17,11 @@* Generic page table descriptor format from which * all level specific descriptors can be derived. */ +#ifdef CONFIG_ARM64_D128 +typedef u128 ptval_t ; +#else typedef u64 ptval_t ; +#endif typedef ptval_t pteval_t ;typedef ptval_t pmdval_t ;
arch/arm64/include/asm/pgtable.h +50 -2
93 lines not on this page · raw message
arch/arm64/mm/proc.S +1 -1
@@ -250,7 +250,7 @@ SYM_FUNC_ALIAS(__pi_idmap_cpu_replace_ttbr1, idmap_cpu_replace_ttbr1) .macro pte_to_phys, phys, pte and \phys, \pte, #PTE_ADDR_LOW -#ifdef CONFIG_ARM64_PA_BITS_52 +#if defined(CONFIG_ARM64_PA_BITS_52) && !defined(CONFIG_ARM64_D128) and \pte, \pte, #PTE_ADDR_HIGH orr \phys, \phys, \pte, lsl #PTE_ADDR_HIGH_SHIFT #endif
Signature · 1 line
2.43.0
PATCH v3 9/14 arm64/mm: Enable 128 bit translation
In reply to Anshuman KhandualAll required changes to page table geometry and descriptor are now in place for D128 translation to be enabled.
Since FEAT_D128 exclusively supports the permission indirection style for page table entry permission management, given kernel compiled for FEAT_D128 requires both FEAT_S1PIE and FEAT_D128. If these architecture features are not present during boot, the kernel panics just like it does when there is a granule size mismatch. So added a new stuck CPU debug identifier for such scenarios called CPU_STUCK_REASON_NO_D128.
TTBR0/1_EL1 and PAR_EL1 registers become 128 bit wide when D128 is enabled, thus requiring MSRR/MRRS instructions for their updates. Because PA_BITS is still capped at 52 bits, MRS/MSR instructions are currently sufficient for the register accesses that basically operate on the lower 64 bits. Although entire 128 bits for these registers get cleared during boot via MSRR.
--- arch/arm64/Makefile | 4 ++++ arch/arm64/include/asm/el2_setup.h | 9 +++++++++ arch/arm64/include/asm/smp.h | 1 + arch/arm64/kernel/head.S | 12 ++++++++++++ arch/arm64/mm/proc.S | 23 +++++++++++++++++++++++ 5 files changed, 49 insertions(+)
arch/arm64/Makefile +4 -0
@@ -57,6 +57,10 @@ endif KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) +ifeq ($(CONFIG_ARM64_D128),y) +KBUILD_AFLAGS += -march=armv9.3-a+d128 +endif + # Avoid generating .eh_frame* sections. ifneq ($(CONFIG_UNWIND_TABLES),y) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
arch/arm64/include/asm/el2_setup.h +9 -0
@@ -78,6 +78,15 @@ cbz x0, .Lskip_hcrx_\@ mov_q x0, (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En | HCRX_EL2_EnFPM) +#ifdef CONFIG_ARM64_D128 + mrs_s x1, SYS_ID_AA64MMFR3_EL1 + ubfx x1, x1, #ID_AA64MMFR3_EL1_D128_SHIFT, #4 + cbz x1, .Lskip_d128_\@ + + orr x0, x0, HCRX_EL2_D128En // Disable MRRS/MSRR traps +.Lskip_d128_\@: +#endif +/* Enable GCS if supported */ mrs_s x1, SYS_ID_AA64PFR1_EL1 ubfx x1, x1, #ID_AA64PFR1_EL1_GCS_SHIFT, #4
arch/arm64/include/asm/smp.h +1 -0
@@ -22,6 +22,7 @@#define CPU_STUCK_REASON_52_BIT_VA (UL(1) << CPU_STUCK_REASON_SHIFT)#define CPU_STUCK_REASON_NO_GRAN (UL(2) << CPU_STUCK_REASON_SHIFT) +#define CPU_STUCK_REASON_NO_D128 (UL(3) << CPU_STUCK_REASON_SHIFT)#ifndef __ASSEMBLER__
arch/arm64/kernel/head.S +12 -0
@@ -504,6 +504,18 @@ SYM_FUNC_START_LOCAL(__no_granule_support) b 1b SYM_FUNC_END(__no_granule_support) +#ifdef CONFIG_ARM64_D128 +SYM_FUNC_START(__no_d128_support) + /* Indicate that this CPU can't boot and is stuck in the kernel */ + update_early_cpu_boot_status \ + CPU_STUCK_IN_KERNEL | CPU_STUCK_REASON_NO_D128, x1, x2 +1: + wfe + wfi + b 1b +SYM_FUNC_END(__no_d128_support) +#endif + SYM_FUNC_START_LOCAL(__primary_switch) adrp x1, reserved_pg_dir adrp x2, __pi_init_idmap_pg_dir
arch/arm64/mm/proc.S +23 -0
@@ -576,7 +576,30 @@ alternative_else_nop_endif mrs_s x1, SYS_ID_AA64MMFR3_EL1 ubfx x1, x1, #ID_AA64MMFR3_EL1_S1PIE_SHIFT, #4 +#ifdef CONFIG_ARM64_D128 + cbnz x1, .Lcheck_d128 + bl __no_d128_support +.Lcheck_d128: + mrs_s x1, SYS_ID_AA64MMFR3_EL1 + ubfx x1, x1, #ID_AA64MMFR3_EL1_D128_SHIFT, #4 + cbnz x1, .Linit_d128 + bl __no_d128_support +.Linit_d128: + /* + * Although the lower 64 bits in TTBRx_EL1 registers are now + * being used it is prudent to clear out the entire 128 bits + * just in case the kernel receives non-zero value in higher + * 64 bits from the EL3 which might corrupt the page tables. + */ + mov x4, xzr + mov x5, xzr + + msrr ttbr0_el1, x4, x5 + msrr ttbr1_el1, x4, x5 + orr tcr2, tcr2, #TCR2_EL1_D128 +#else cbz x1, .Lskip_indirection +#endif mov_q x0, PIE_E0_ASM msr REG_PIRE0_EL1, x0
Signature · 1 line
2.43.0
PATCH v3 10/14 arm64/mm: Add an abstraction level for tlbi_op
In reply to Anshuman KhandualFrom: Linu Cherian <[email protected]>
With FEAT_D128, a new instruction aka TLBIP is being introduced for the TLB -by-range operations which has an argument size of 128 bit.
Add an abstraction level to void (*tlbi_op)(u64 arg) helpers to support the D128 variations when applicable.
No functional changes are introduced with this patch.
--- arch/arm64/include/asm/tlbflush.h | 70 ++++++++++++++++--------------- 1 file changed, 37 insertions(+), 33 deletions(-)
arch/arm64/include/asm/tlbflush.h +37 -33
@@ -130,49 +130,53 @@ static inline void sme_dvmsync_batch(void)#define TLBI_TTL_UNKNOWN INT_MAX -typedef void (*tlbi_op )(u64 arg); +typedef u64 tlbi_arg_t ; +#define __tlbi_wrapper (op, arg) __tlbi(op, arg) +#define __tlbi_user_wrapper (op, arg) __tlbi_user(op, arg) -static __always_inline void vae1is(u64 arg) +typedef void (*tlbi_op )(tlbi_arg_t arg); + +static __always_inline void vae1is(tlbi_arg_t arg) { -__tlbi (vae1is, arg); -__tlbi_user (vae1is, arg); +__tlbi_wrapper (vae1is, arg); +__tlbi_user_wrapper (vae1is, arg); } -static __always_inline void vae2is(u64 arg) +static __always_inline void vae2is(tlbi_arg_t arg) { -__tlbi (vae2is, arg); +__tlbi_wrapper (vae2is, arg); } -static __always_inline void vale1(u64 arg) +static __always_inline void vale1(tlbi_arg_t arg) { -__tlbi (vale1, arg); -__tlbi_user (vale1, arg); +__tlbi_wrapper (vale1, arg); +__tlbi_user_wrapper (vale1, arg); } -static __always_inline void vale1is(u64 arg) +static __always_inline void vale1is(tlbi_arg_t arg) { -__tlbi (vale1is, arg); -__tlbi_user (vale1is, arg); +__tlbi_wrapper (vale1is, arg); +__tlbi_user_wrapper (vale1is, arg); } -static __always_inline void vale2is(u64 arg) +static __always_inline void vale2is(tlbi_arg_t arg) { -__tlbi (vale2is, arg); +__tlbi_wrapper (vale2is, arg); } -static __always_inline void vaale1is(u64 arg) +static __always_inline void vaale1is(tlbi_arg_t arg) { -__tlbi (vaale1is, arg); +__tlbi_wrapper (vaale1is, arg); } -static __always_inline void ipas2e1(u64 arg) +static __always_inline void ipas2e1(tlbi_arg_t arg) { -__tlbi (ipas2e1, arg); +__tlbi_wrapper (ipas2e1, arg); } -static __always_inline void ipas2e1is(u64 arg) +static __always_inline void ipas2e1is(tlbi_arg_t arg) { -__tlbi (ipas2e1is, arg); +__tlbi_wrapper (ipas2e1is, arg); } static __always_inline void __tlbi_level_asid(tlbi_op op, u64 addr, u32 level,
@@ -447,32 +451,32 @@ static inline void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)* operations can only span an even number of pages. We save this for last to * ensure 64KB start alignment is maintained for the LPA2 case. */ -static __always_inline void rvae1is(u64 arg) +static __always_inline void rvae1is(tlbi_arg_t arg) { -__tlbi (rvae1is, arg); -__tlbi_user (rvae1is, arg); +__tlbi_wrapper (rvae1is, arg); +__tlbi_user_wrapper (rvae1is, arg); } -static __always_inline void rvale1(u64 arg) +static __always_inline void rvale1(tlbi_arg_t arg) { -__tlbi (rvale1, arg); -__tlbi_user (rvale1, arg); +__tlbi_wrapper (rvale1, arg); +__tlbi_user_wrapper (rvale1, arg); } -static __always_inline void rvale1is(u64 arg) +static __always_inline void rvale1is(tlbi_arg_t arg) { -__tlbi (rvale1is, arg); -__tlbi_user (rvale1is, arg); +__tlbi_wrapper (rvale1is, arg); +__tlbi_user_wrapper (rvale1is, arg); } -static __always_inline void rvaale1is(u64 arg) +static __always_inline void rvaale1is(tlbi_arg_t arg) { -__tlbi (rvaale1is, arg); +__tlbi_wrapper (rvaale1is, arg); } -static __always_inline void ripas2e1is(u64 arg) +static __always_inline void ripas2e1is(tlbi_arg_t arg) { -__tlbi (ripas2e1is, arg); +__tlbi_wrapper (ripas2e1is, arg); } static __always_inline void __tlbi_range(tlbi_op op, u64 addr,
Signature · 1 line
2.43.0
PATCH v3 11/14 arm64/mm: Enable TLBIP instruction based TLB flush
In reply to Anshuman KhandualFrom: Linu Cherian <[email protected]>
Add TLBIP instruction support for TLB flush operation updating all relevant macros as necessary. This enables back pgtable level hint and address range support during TLB flush operation for D128 translation.
--- arch/arm64/include/asm/tlbflush.h | 68 +++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-)
arch/arm64/include/asm/tlbflush.h +59 -9
@@ -41,6 +41,25 @@#define __tlbi (op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0) +#ifdef CONFIG_ARM64_D128 +#define __tlbip (op, arg) do { \ + asm (ARM64_ASM_PREAMBLE \ + ".arch_extension d128\n\t" \ + "tlbip " #op ", %0, %H0\n" \ + : : "r" (arg.full)); \ +} while (0) + +#define __tlbip_user (op, arg) do { \ + if (arm64_kernel_unmapped_at_el0()) { \ + arg.low |= USER_ASID_FLAG; \ + __tlbip(op, (arg)); \ + } \ +} while (0) + +#endif + +#define TLBI_ASID_MASK GENMASK_ULL(63, 48) +#define __tlbi_user (op, arg) do { \ if (arm64_kernel_unmapped_at_el0()) \ __tlbi(op, (arg) | USER_ASID_FLAG); \
@@ -130,9 +149,15 @@ static inline void sme_dvmsync_batch(void)#define TLBI_TTL_UNKNOWN INT_MAX +#ifdef CONFIG_ARM64_D128 +typedef union __u128_halves tlbi_arg_t ; +#define __tlbi_wrapper (op, arg) __tlbip(op, arg) +#define __tlbi_user_wrapper (op, arg) __tlbip_user(op, arg) +#else typedef u64 tlbi_arg_t ;#define __tlbi_wrapper (op, arg) __tlbi(op, arg)#define __tlbi_user_wrapper (op, arg) __tlbi_user(op, arg) +#endif typedef void (*tlbi_op )(tlbi_arg_t arg);
@@ -179,17 +204,28 @@ static __always_inline void ipas2e1is(tlbi_arg_t arg)__tlbi_wrapper (ipas2e1is, arg); } -static __always_inline void __tlbi_level_asid(tlbi_op op, u64 addr, u32 level, -u16 asid) +static __always_inline void __tlbi_update_level(u32 level, u64 *arg) { -u64 arg =__TLBI_VADDR (addr, asid); -if (alternative_has_cap_unlikely (ARM64_HAS_ARMv8_4_TTL) && level <=3 ) {u64 ttl = level | (get_trans_granule () <<2 ); -FIELD_MODIFY (TLBI_TTL_MASK , &arg, ttl); +FIELD_MODIFY (TLBI_TTL_MASK , arg, ttl); } +} + +static __always_inline void __tlbi_level_asid(tlbi_op op, u64 addr, u32 level, u16 asid) +{ +#ifdef CONFIG_ARM64_D128 +union __u128_halves arg; + + arg.low =FIELD_PREP (TLBI_ASID_MASK , asid); +__tlbi_update_level (level, &arg.low); + arg.high = addr >>12 ; +#else +u64 arg =__TLBI_VADDR (addr, asid); +__tlbi_update_level (level, &arg); +#endif op (arg); }
@@ -479,19 +515,33 @@ static __always_inline void ripas2e1is(tlbi_arg_t arg)__tlbi_wrapper (ripas2e1is, arg); } -static __always_inline void __tlbi_range(tlbi_op op, u64 addr, -u16 asid,int scale,int num, -u32 level,bool lpa2) +static __always_inline u64 __tlbi_range_args_encode_comm(u16 asid, int scale, int num, u32 level) {u64 arg =0 ; - arg |=FIELD_PREP (TLBIR_BADDR_MASK , addr >> (lpa2 ?16 :PAGE_SHIFT )); arg |=FIELD_PREP (TLBIR_TTL_MASK , level >3 ?0 : level); arg |=FIELD_PREP (TLBIR_NUM_MASK , num); arg |=FIELD_PREP (TLBIR_SCALE_MASK , scale); arg |=FIELD_PREP (TLBIR_TG_MASK ,get_trans_granule ()); arg |=FIELD_PREP (TLBIR_ASID_MASK , asid); +return arg; +} + +static __always_inline void __tlbi_range(tlbi_op op, u64 addr, +u16 asid,int scale,int num, +u32 level,bool lpa2) +{ +#ifdef CONFIG_ARM64_D128 +union __u128_halves arg; + + arg.low =__tlbi_range_args_encode_comm (asid, scale, num, level); + arg.high = addr >>12 ; +#else +u64 arg =__tlbi_range_args_encode_comm (asid, scale, num, level); + + arg |=FIELD_PREP (TLBIR_BADDR_MASK , addr >> (lpa2 ?16 :PAGE_SHIFT )); +#endif op (arg); }
Signature · 1 line
2.43.0
PATCH v3 12/14 arm64/mm: Relax KASAN shadow alignment for FEAT_D128
In reply to Anshuman KhandualD128 reduces the number of descriptors in each translation table, causing some VA size and page granule combinations that use two page table levels with D64 to now require three levels.
For three-level page tables, the PUD level is folded while the PMD level remains a real translation level. Hence, PUD_SIZE represents a root-level span. With D128, some configurations have a KASAN shadow region smaller than this span, making it impossible for both KASAN shadow boundaries to satisfy the existing PUD_SIZE alignment requirement.
The KASAN initialization code on arm64 already supports shadow boundaries which are not root-level aligned, by installing or cloning the next-level table as required.
Similarly for three level D128 page tables, relax SHADOW_ALIGN to PMD_SIZE, which corresponds to the first non-folded level below the root level. Keep the existing alignment requirements unchanged for all other configurations.
--- arch/arm64/mm/kasan_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm64/mm/kasan_init.c +3 -1
@@ -178,7 +178,9 @@ static void __init kasan_pgd_populate(unsigned long addr, unsigned long end, }while (pgdp++, addr = next, addr != end); } -#if defined(CONFIG_ARM64_64K_PAGES ) ||CONFIG_PGTABLE_LEVELS >4 +#if defined(CONFIG_ARM64_D128 ) &&CONFIG_PGTABLE_LEVELS ==3 +#define SHADOW_ALIGN PMD_SIZE +#elif defined(CONFIG_ARM64_64K_PAGES ) ||CONFIG_PGTABLE_LEVELS >4 #define SHADOW_ALIGN P4D_SIZE#else #define SHADOW_ALIGN PUD_SIZE
Signature · 1 line
2.43.0
PATCH v3 13/14 arm64/mm: Make ARM64_D128 selectable
In reply to Anshuman KhandualAll required changes are already in place including the TLBIP instruction support for enabling D128 translation. Just make this new ARM64_D128 user selectable, after ensuring necessary tools chain support required for the new instructions being used for D128.
--- arch/arm64/Kconfig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +14 -1
@@ -272,6 +272,10 @@ config GCC_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS def_bool CC_IS_GCC depends on $(cc-option,-fpatchable-function-entry=2) +config CC_SUPPORTS_LSE128 + def_bool CC_IS_GCC + depends on $(cc-option, -march=armv8.1-a+lse128) + config 64BIT def_bool y
@@ -2385,8 +2389,17 @@ endmenu # "ARMv8.9 architectural features" menu "ARMv9.3 architectural features" +config AS_HAS_ARMV9_3 + def_bool $(cc-option,-Wa$(comma)-march=armv9.3-a) + config ARM64_D128 - bool + bool "Enable support for 128 bit page table (FEAT_D128)" + depends on ARCH_SUPPORTS_INT128 + depends on CC_SUPPORTS_LSE128 + depends on AS_HAS_ARMV9_3 + depends on EXPERT + depends on !VIRTUALIZATION + depends on !UNMAP_KERNEL_AT_EL0 default n help ARMv9.3 introduces FEAT_D128, which provides a 128 bit page
Signature · 1 line
2.43.0
PATCH v3 14/14 arm64/configs: Add d128.config
In reply to Anshuman KhandualProvide a slimline configuration intended to be booted with ARM64_D128.
--- arch/arm64/configs/d128.config | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 arch/arm64/configs/d128.config
arch/arm64/configs/d128.config new file +6 -0
@@ -0,0 +1,6 @@ +# ARM64_D128-specific configuration + +# CONFIG_UNMAP_KERNEL_AT_EL0 is not set +# CONFIG_VIRTUALIZATION is not set +CONFIG_EXPERT=y +CONFIG_ARM64_D128=y
Signature · 1 line
2.43.0
Quoted 4 lines · Anshuman Khandual
FEAT_D128is a new arm architecture feature adding support for VMSAv9-128 translation system.FEAT_D128is an optional feature from ARMV9.3 onwards. arm64 platforms withFEAT_D128enabled will now have two different memory translation systems i.e VMSAv8-64 and VMSAv9-128.
Please don't forget to update arm_smmu_sva_supported()
Jason
Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Anshuman Khandual
FEAT_D128is a new arm architecture feature adding support for VMSAv9-128 translation system.FEAT_D128is an optional feature from ARMV9.3 onwards. arm64 platforms withFEAT_D128enabled will now have two different memory translation systems i.e VMSAv8-64 and VMSAv9-128.Please don't forget to update
arm_smmu_sva_supported()
Sure, thanks for the pointer.
Fow now will disable SVA with CONFIG_ARM_D128 enabled but later it can be enabled back with SMMU_IDR5.D128 feature. I will probably fold back the following change in the series.
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +3 -0
@@ -205,6 +205,9 @@ bool arm_smmu_sva_supported(struct arm_smmu_device *smmu)unsigned long asid_bits;u32 feat_mask =ARM_SMMU_FEAT_COHERENCY ; +if (IS_ENABLED (CONFIG_ARM64_D128 )) +return false; +if (vabits_actual ==52 ) {/* We don't support LPA2 */ if (PAGE_SIZE !=SZ_64K )
Quoted 18 lines · Anshuman Khandual
Quoted 7 lines · Jason Gunthorpe
Quoted 4 lines · Anshuman Khandual
FEAT_D128is a new arm architecture feature adding support for VMSAv9-128 translation system.FEAT_D128is an optional feature from ARMV9.3 onwards. arm64 platforms withFEAT_D128enabled will now have two different memory translation systems i.e VMSAv8-64 and VMSAv9-128.Please don't forget to update
arm_smmu_sva_supported()Sure, thanks for the pointer.
Fow now will disable SVA with
CONFIG_ARM_D128enabled but later it can be enabled back with SMMU_IDR5.D128 feature. I will probably fold back the following change in the series.
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c bool arm_smmu_sva_supported(struct arm_smmu_device *smmu) · line 209
Quoted 5 lines
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +2
-0@@ -205,6 +205,9 @@ bool arm_smmu_sva_supported(struct arm_smmu_device *smmu)unsigned long asid_bits;u32 feat_mask =ARM_SMMU_FEAT_COHERENCY ; +if (IS_ENABLED (CONFIG_ARM64_D128 )) +return false;
That seems wrong if the arch code is enabling this based on a CPU IDR.
I would expect distro kernels to enable this kconfig unconditionally, so this will break SVA for everyone.
Jason