Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
kernel: allocate rootserver objects from untyped memory
Browse files Browse the repository at this point in the history
This changes how allocation process for rootserver capabilities looks
like. Instead of directly allocating objects from free memory region,
allocate memory for Untyped object which can fit initial CNode. This
CNode is then filled with Untyped objects created from remaining free
memory. At this point, all the other objects are allocated from
Untyped memory. The Untyped object used for rootserver CNode is
then provided in the bootinfo with rest of untyped capabilities.

Change-Id: I416e5f2a3eb1d2a6c721446e831ad1042f3d0a4b
GitOrigin-RevId: d59ba81c96f4c758a3ddd6661bbf86e24a9f603d
  • Loading branch information
MarWit authored and sleffler committed Aug 12, 2022
1 parent f263c2a commit 4220386
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 84 deletions.
4 changes: 4 additions & 0 deletions include/kernel/boot.h
Expand Up @@ -8,6 +8,9 @@
#include <bootinfo.h>
#include <arch/bootinfo.h>

#define DUMMY_CNODE_SIZE_BITS (2 + seL4_SlotBits)
#define DUMMY_CNODE_SIZE (1 << DUMMY_CNODE_SIZE_BITS)

#ifndef CONFIG_ARCH_ARM
#define MAX_NUM_FREEMEM_REG 16
#else
Expand Down Expand Up @@ -64,6 +67,7 @@ bool_t create_device_untypeds(cap_t root_cnode_cap, seL4_SlotPos slot_pos_before
bool_t create_kernel_untypeds(cap_t root_cnode_cap, region_t boot_mem_reuse_reg, seL4_SlotPos first_untyped_slot);
void bi_finalise(void);
void create_domain_cap(cap_t root_cnode_cap);
cap_t create_rootserver_obj(object_t objectType, word_t slot, word_t userSize);

cap_t create_ipcbuf_frame_cap(cap_t root_cnode_cap, cap_t pd_cap, vptr_t vptr);
word_t calculate_extra_bi_size_bits(word_t extra_size);
Expand Down
36 changes: 32 additions & 4 deletions src/arch/riscv/kernel/boot.c
Expand Up @@ -41,14 +41,35 @@ BOOT_CODE static bool_t create_untypeds(cap_t root_cnode_cap, region_t boot_mem_
create_device_untypeds(root_cnode_cap, slot_pos_before);
bool_t res = create_kernel_untypeds(root_cnode_cap, boot_mem_reuse_reg, slot_pos_before);

// Reserve next slot for BSS untyped
ndks_boot.slot_pos_cur += 1;

slot_pos_after = ndks_boot.slot_pos_cur;

ndks_boot.bi_frame->untyped = (seL4_SlotRegion) {
slot_pos_before, slot_pos_after
};
return res;

}

BOOT_CODE static bool_t create_bss_untyped(cap_t root_cnode_cap, region_t boot_mem_reuse_reg)
{
seL4_SlotPos first_untyped_slot;
seL4_SlotPos slot_pos_copy;

first_untyped_slot = ndks_boot.bi_frame->untyped.start;
slot_pos_copy = ndks_boot.slot_pos_cur;
ndks_boot.slot_pos_cur = ndks_boot.bi_frame->untyped.end - 1;

if (!create_untypeds_for_region(root_cnode_cap, false, boot_mem_reuse_reg, first_untyped_slot)) {
return false;
}

ndks_boot.slot_pos_cur = slot_pos_copy;
return true;
}

BOOT_CODE cap_t create_mapped_it_frame_cap(cap_t pd_cap, pptr_t pptr, vptr_t vptr, asid_t asid, bool_t
use_large, bool_t executable)
{
Expand Down Expand Up @@ -215,6 +236,7 @@ static BOOT_CODE bool_t try_init_kernel(
vptr_t ipcbuf_vptr;
create_frames_of_region_ret_t create_frames_ret;
create_frames_of_region_ret_t extra_bi_ret;
region_t empty_region = {0};

/* convert from physical addresses to userland vptrs */
v_region_t ui_v_reg;
Expand Down Expand Up @@ -293,6 +315,13 @@ static BOOT_CODE bool_t try_init_kernel(
*(seL4_BootInfoHeader *)(rootserver.extra_bi + extra_bi_offset) = header;
}

/* make untyped memory avaiable */
if (!create_untypeds(
root_cnode_cap,
empty_region)) {
return false;
}

/* Construct an initial address space with enough virtual addresses
* to cover the user image + ipc buffer and bootinfo frames */
it_pd_cap = create_it_address_space(root_cnode_cap, it_v_reg);
Expand Down Expand Up @@ -327,6 +356,7 @@ static BOOT_CODE bool_t try_init_kernel(
ndks_boot.bi_frame->extraBIPages = extra_bi_ret.region;
}


#ifdef CONFIG_KERNEL_MCS
init_sched_control(root_cnode_cap, CONFIG_MAX_NUM_NODES);
#endif
Expand Down Expand Up @@ -384,10 +414,8 @@ static BOOT_CODE bool_t try_init_kernel(

init_core_state(initial);

/* convert the remaining free memory into UT objects and provide the caps */
if (!create_untypeds(
root_cnode_cap,
boot_mem_reuse_reg)) {
/* convert the BSS memory into UT objects and provide the caps */
if (!create_bss_untyped(root_cnode_cap, boot_mem_reuse_reg)) {
return false;
}

Expand Down
39 changes: 20 additions & 19 deletions src/arch/riscv/kernel/vspace.c
Expand Up @@ -236,15 +236,16 @@ BOOT_CODE cap_t create_unmapped_it_frame_cap(pptr_t pptr, bool_t use_large)
}

/* Create a page table for the initial thread */
static BOOT_CODE cap_t create_it_pt_cap(cap_t vspace_cap, pptr_t pptr, vptr_t vptr, asid_t asid)
static BOOT_CODE cap_t create_it_pt_cap(cap_t vspace_cap, vptr_t vptr, asid_t asid)
{
cap_t cap;
cap = cap_page_table_cap_new(
asid, /* capPTMappedASID */
pptr, /* capPTBasePtr */
1, /* capPTIsMapped */
vptr /* capPTMappedAddress */
);

cap = create_rootserver_obj(seL4_RISCV_PageTableObject, ndks_boot.slot_pos_cur, 1);
cap = cap_page_table_cap_set_capPTMappedASID(cap, asid);
cap = cap_page_table_cap_set_capPTIsMapped(cap, 1);
cap = cap_page_table_cap_set_capPTMappedAddress(cap, vptr);
SLOT_PTR(rootserver.cnode, ndks_boot.slot_pos_cur)->cap = cap;
ndks_boot.slot_pos_cur++;

map_it_pt_cap(vspace_cap, cap);
return cap;
Expand All @@ -266,28 +267,28 @@ BOOT_CODE cap_t create_it_address_space(cap_t root_cnode_cap, v_region_t it_v_re
cap_t lvl1pt_cap;
vptr_t pt_vptr;

copyGlobalMappings(PTE_PTR(rootserver.vspace));
lvl1pt_cap = create_rootserver_obj(seL4_RISCV_PageTableObject, seL4_CapInitThreadVSpace, seL4_VSpaceBits);
void* vspace = (void*)cap_get_capPtr(lvl1pt_cap);

lvl1pt_cap =
cap_page_table_cap_new(
IT_ASID, /* capPTMappedASID */
(word_t) rootserver.vspace, /* capPTBasePtr */
1, /* capPTIsMapped */
(word_t) rootserver.vspace /* capPTMappedAddress */
);
copyGlobalMappings(PTE_PTR(vspace));

lvl1pt_cap = cap_page_table_cap_set_capPTMappedASID(lvl1pt_cap, IT_ASID);
lvl1pt_cap = cap_page_table_cap_set_capPTIsMapped(lvl1pt_cap, 1);
lvl1pt_cap = cap_page_table_cap_set_capPTMappedAddress(lvl1pt_cap, cap_page_table_cap_get_capPTBasePtr(lvl1pt_cap));
SLOT_PTR(rootserver.cnode, seL4_CapInitThreadVSpace)->cap = lvl1pt_cap;

seL4_SlotPos slot_pos_before = ndks_boot.slot_pos_cur;
write_slot(SLOT_PTR(pptr_of_cap(root_cnode_cap), seL4_CapInitThreadVSpace), lvl1pt_cap);

/* create all n level PT caps necessary to cover userland image in 4KiB pages */
for (int i = 0; i < CONFIG_PT_LEVELS - 1; i++) {

for (pt_vptr = ROUND_DOWN(it_v_reg.start, RISCV_GET_LVL_PGSIZE_BITS(i));
pt_vptr < it_v_reg.end;
pt_vptr += RISCV_GET_LVL_PGSIZE(i)) {
if (!provide_cap(root_cnode_cap,
create_it_pt_cap(lvl1pt_cap, it_alloc_paging(), pt_vptr, IT_ASID))
) {
if (!cap_capType_equals(
create_it_pt_cap(lvl1pt_cap, pt_vptr, IT_ASID),
cap_page_table_cap
)) {
return cap_null_cap_new();
}
}
Expand Down

0 comments on commit 4220386

Please sign in to comment.