Skip to content

Commit

Permalink
boot, pmm: add compile-time configurable early address space
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 17, 2021
1 parent 7bda5b3 commit 83de1e2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .config
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Size (in MB) of boot-time virtual address space coverage
CONFIG_EARLY_VIRT_MEM=8
CONFIG_LIBPFM=n
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ifeq ($(CONFIG_LIBPFM),y)
COMMON_INCLUDES += -I$(PFMLIB_INCLUDE)
endif

COMMON_FLAGS := $(COMMON_INCLUDES) -pipe -MP -MMD -m64 -D__x86_64__
COMMON_FLAGS := $(COMMON_INCLUDES) -pipe -MP -MMD -m64 -D__x86_64__ -DEARLY_VIRT_MEM=$(CONFIG_EARLY_VIRT_MEM)

ifeq ($(CONFIG_LIBPFM),y)
COMMON_FLAGS += -DKTF_PMU
Expand Down
61 changes: 37 additions & 24 deletions arch/x86/boot/pagetables.S
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,52 @@
#include <asm-macros.h>
#include <page.h>

/* Initial identity map page tables */
SECTION(.data.init, "aw", PAGE_SIZE)
#define EARLY_PT_NUM (EARLY_VIRT_MEM / 2)
#define PT_NAME(x) l1_pt_entries ## x

#if EARLY_PT_NUM > L2_PT_ENTRIES
#error "Unable to cover more than 1GB of early address space"
#endif

#define FIRST_PT_IDX 0

/* Each single l1_pt_entry covers a 4K of virtual addr range */
.macro alloc_l1_pt idx
GLOBAL(PT_NAME(\idx))
.rept L1_PT_ENTRIES
.long PT_PADDR(PT_NAME(0), L1_PT_SHIFT) + L1_PROT, 0
.endr
END_OBJECT(PT_NAME(\idx))
.endm

/* First 2M range 0-2M */
GLOBAL(l1_pt_entries1)
.rept L1_PT_ENTRIES
.long PT_PADDR(l1_pt_entries1, L1_PT_SHIFT) + L1_PROT, 0
.endr
END_OBJECT(l1_pt_entries1)
.macro l2_pt_entry idx
.long PT_NAME(\idx) + L2_PROT, 0
.endm

/* Second 2M range 2M-4M */
GLOBAL(l1_pt_entries2)
.rept L1_PT_ENTRIES
.long PT_PADDR(l1_pt_entries1, L1_PT_SHIFT) + L1_PROT, 0
.endr
END_OBJECT(l1_pt_entries2)
.altmacro

/* Third 2M range 4M-6M */
GLOBAL(l1_pt_entries3)
.rept L1_PT_ENTRIES
.long PT_PADDR(l1_pt_entries1, L1_PT_SHIFT) + L1_PROT, 0
.endr
END_OBJECT(l1_pt_entries3)
/* Initial identity map page tables */
SECTION(.data.init, "aw", PAGE_SIZE)

/* Allocate L1 page tables */
.set i, FIRST_PT_IDX
.rept EARLY_PT_NUM
alloc_l1_pt %i
.set i, i + 1
.endr

/*
* Each single l2_pt_entry points to l1_pt_entry table and
* thus a single l2_pt_entry covers a 2M of virtual addr range
*/
GLOBAL(l2_pt_entries)
.long l1_pt_entries1 + L2_PROT, 0 /* Covers 0-2M */
.long l1_pt_entries2 + L2_PROT, 0 /* Covers 2M-4M */
.long l1_pt_entries3 + L2_PROT, 0 /* Covers 4M-6M */
.fill (L2_PT_ENTRIES - 3), PTE_SIZE, 0 /* 3 entries used, rests all are zeroed */
/* Assign L1 page tables to their L2 table */
.set i, FIRST_PT_IDX
.rept EARLY_PT_NUM
l2_pt_entry %i
.set i, i + 1
.endr
.fill (L2_PT_ENTRIES - EARLY_PT_NUM), PTE_SIZE, 0 /* EARLY_PT_NUM entries used, rests all are zeroed */
END_OBJECT(l2_pt_entries)

/*
Expand Down Expand Up @@ -99,3 +110,5 @@ GLOBAL(l4_pt_entries)
.long l3_pt_entries + L4_PROT, 0
END_OBJECT(l4_pt_entries)
#endif

.noaltmacro
7 changes: 6 additions & 1 deletion mm/pmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static size_t process_memory_range(unsigned index) {
*/

/* Add initial 4K frames and align to 2M. */
while (cur % PAGE_SIZE_2M && cur + PAGE_SIZE <= end) {
while ((cur < MB(EARLY_VIRT_MEM) || cur % PAGE_SIZE_2M) && cur + PAGE_SIZE <= end) {
if (index <= 1)
add_early_frame(paddr_to_mfn(cur), PAGE_ORDER_4K);
else
Expand Down Expand Up @@ -169,6 +169,11 @@ void init_pmm(void) {
total_phys_memory += process_memory_range(i);

display_frames_count();

if (frames_count[PAGE_ORDER_4K] < (MB(EARLY_VIRT_MEM) / PAGE_SIZE))
panic("Not enough early frames: %u missing\n",
(MB(EARLY_VIRT_MEM) / PAGE_SIZE) - frames_count[PAGE_ORDER_4K]);

if (opt_debug)
display_frames();
}
Expand Down

0 comments on commit 83de1e2

Please sign in to comment.