Skip to content

Commit 94b09d3

Browse files
committed
arm64: map kernel using large pages when page size is 16K
When the page size is 16K, use ATTR_CONTIGUOUS to map the kernel code and data sections using 2M pages. Previously, they were mapped using 16K pages. Reviewed by: markj Tested by: markj Differential Revision: https://reviews.freebsd.org/D45162
1 parent 47535ba commit 94b09d3

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

sys/arm64/arm64/locore.S

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,10 @@ booti_no_fdt:
516516
common:
517517
#if PAGE_SIZE != PAGE_SIZE_4K
518518
/*
519-
* Create L3 pages. The kernel will be loaded at a 2M aligned
520-
* address, however L2 blocks are too large when the page size is
521-
* not 4k to map the kernel with such an aligned address. However,
522-
* when the page size is larger than 4k, L2 blocks are too large to
523-
* map the kernel with such an alignment.
519+
* Create L3 and L3C pages. The kernel will be loaded at a 2M aligned
520+
* address, enabling the creation of L3C pages. However, when the page
521+
* size is larger than 4k, L2 blocks are too large to map the kernel
522+
* with 2M alignment.
524523
*/
525524
#define PTE_SHIFT L3_SHIFT
526525
#define BUILD_PTE_FUNC build_l3_page_pagetable
@@ -784,13 +783,17 @@ LENTRY(link_l2_pagetable)
784783
LEND(link_l2_pagetable)
785784

786785
/*
787-
* Builds count level 3 page table entries
786+
* Builds count level 3 page table entries. Uses ATTR_CONTIGUOUS to create
787+
* large page (L3C) mappings when the current VA and remaining count allow
788+
* it.
788789
* x6 = L3 table
789790
* x7 = Block attributes
790791
* x8 = VA start
791792
* x9 = PA start (trashed)
792793
* x10 = Entry count (trashed)
793794
* x11, x12 and x13 are trashed
795+
*
796+
* VA start (x8) modulo L3C_SIZE must equal PA start (x9) modulo L3C_SIZE.
794797
*/
795798
LENTRY(build_l3_page_pagetable)
796799
/*
@@ -811,8 +814,17 @@ LENTRY(build_l3_page_pagetable)
811814
/* Only use the output address bits */
812815
lsr x9, x9, #L3_SHIFT
813816

817+
/* Check if an ATTR_CONTIGUOUS mapping is possible */
818+
1: tst x11, #(L3C_ENTRIES - 1)
819+
b.ne 2f
820+
cmp x10, #L3C_ENTRIES
821+
b.lo 3f
822+
orr x12, x12, #(ATTR_CONTIGUOUS)
823+
b 2f
824+
3: and x12, x12, #(~ATTR_CONTIGUOUS)
825+
814826
/* Set the physical address for this virtual address */
815-
1: orr x13, x12, x9, lsl #L3_SHIFT
827+
2: orr x13, x12, x9, lsl #L3_SHIFT
816828

817829
/* Store the entry */
818830
str x13, [x6, x11, lsl #3]

0 commit comments

Comments
 (0)