From a396fa95638627e30fcd7a63b378695a3347d68e Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Mon, 4 Jul 2016 09:19:52 +0200 Subject: [PATCH] sel4: support up to 16K capabilities per pd before we had 256 capabilities Issue #2044 --- .../base-sel4/src/core/include/platform_pd.h | 15 +++++++-- repos/base-sel4/src/core/include/vm_space.h | 2 +- repos/base-sel4/src/core/platform_pd.cc | 33 +++++++++++++------ repos/base-sel4/src/core/platform_thread.cc | 10 +++--- .../base/internal/capability_space_sel4.h | 4 ++- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/repos/base-sel4/src/core/include/platform_pd.h b/repos/base-sel4/src/core/include/platform_pd.h index 020389790f..4ef2fa3e5f 100644 --- a/repos/base-sel4/src/core/include/platform_pd.h +++ b/repos/base-sel4/src/core/include/platform_pd.h @@ -42,9 +42,9 @@ class Genode::Platform_pd : public Address_space Vm_space _vm_space; - Cap_sel const _cspace_cnode_sel; + Cnode _cspace_cnode_1st; - Cnode _cspace_cnode; + Lazy_volatile_object _cspace_cnode_2nd[1UL << CSPACE_SIZE_LOG2_1ST]; Native_capability _parent; @@ -105,7 +105,16 @@ class Genode::Platform_pd : public Address_space void free_sel(Cap_sel sel); - Cnode &cspace_cnode() { return _cspace_cnode; } + Cnode &cspace_cnode(Cap_sel sel) + { + const unsigned index = sel.value() / (1 << CSPACE_SIZE_LOG2_2ND); + ASSERT(index < sizeof(_cspace_cnode_2nd) / + sizeof(_cspace_cnode_2nd[0])); + + return *_cspace_cnode_2nd[index]; + } + + Cnode &cspace_cnode_1st() { return _cspace_cnode_1st; } Cap_sel page_directory_sel() const { return _page_directory_sel; } diff --git a/repos/base-sel4/src/core/include/vm_space.h b/repos/base-sel4/src/core/include/vm_space.h index b0c57d82f2..784a0f40b2 100644 --- a/repos/base-sel4/src/core/include/vm_space.h +++ b/repos/base-sel4/src/core/include/vm_space.h @@ -57,7 +57,7 @@ class Genode::Vm_space /** * Number of leaf CNodes */ - NUM_LEAF_CNODES_LOG2 = 4UL, + NUM_LEAF_CNODES_LOG2 = 6UL, NUM_LEAF_CNODES = 1UL << NUM_LEAF_CNODES_LOG2, /** diff --git a/repos/base-sel4/src/core/platform_pd.cc b/repos/base-sel4/src/core/platform_pd.cc index 32846a356f..9372361a34 100644 --- a/repos/base-sel4/src/core/platform_pd.cc +++ b/repos/base-sel4/src/core/platform_pd.cc @@ -100,9 +100,9 @@ void Platform_pd::assign_parent(Native_capability parent) * Install parent endpoint selector at the predefined position * INITIAL_SEL_PARENT within the PD's CSpace. */ - _cspace_cnode.copy(platform_specific()->core_cnode(), - Cnode_index(ipc_cap_data.sel), - Cnode_index(INITIAL_SEL_PARENT)); + _cspace_cnode_2nd[0]->copy(platform_specific()->core_cnode(), + Cnode_index(ipc_cap_data.sel), + Cnode_index(INITIAL_SEL_PARENT)); } @@ -166,15 +166,28 @@ Platform_pd::Platform_pd(Allocator * md_alloc, char const *, platform_specific()->phys_cnode(), _id, _page_table_registry), - _cspace_cnode_sel(platform_specific()->core_sel_alloc().alloc()), - _cspace_cnode(platform_specific()->core_cnode().sel(), _cspace_cnode_sel, - CSPACE_SIZE_LOG2, - *platform()->ram_alloc()) + _cspace_cnode_1st(platform_specific()->core_cnode().sel(), + platform_specific()->core_sel_alloc().alloc(), + CSPACE_SIZE_LOG2_1ST, + *platform()->ram_alloc()) { + /* add all 2nd level CSpace's to 1st level CSpace */ + for (unsigned i = 0; i < sizeof(_cspace_cnode_2nd) / + sizeof(_cspace_cnode_2nd[0]); i++) { + _cspace_cnode_2nd[i].construct(platform_specific()->core_cnode().sel(), + platform_specific()->core_sel_alloc().alloc(), + CSPACE_SIZE_LOG2_2ND, + *platform()->ram_alloc()); + + _cspace_cnode_1st.copy(platform_specific()->core_cnode(), + _cspace_cnode_2nd[i]->sel(), + Cnode_index(i)); + } + /* install CSpace selector at predefined position in the PD's CSpace */ - _cspace_cnode.copy(platform_specific()->core_cnode(), - _cspace_cnode_sel, - Cnode_index(INITIAL_SEL_CNODE)); + _cspace_cnode_2nd[0]->copy(platform_specific()->core_cnode(), + _cspace_cnode_1st.sel(), + Cnode_index(INITIAL_SEL_CNODE)); } diff --git a/repos/base-sel4/src/core/platform_thread.cc b/repos/base-sel4/src/core/platform_thread.cc index 6fcfdddb32..b514a14a53 100644 --- a/repos/base-sel4/src/core/platform_thread.cc +++ b/repos/base-sel4/src/core/platform_thread.cc @@ -124,15 +124,15 @@ int Platform_thread::start(void *ip, void *sp, unsigned int cpu_no) Cap_sel const pager_sel(Capability_space::ipc_cap_data(_pager->cap()).sel); /* install page-fault handler endpoint selector to the PD's CSpace */ - _pd->cspace_cnode().copy(platform_specific()->core_cnode(), pager_sel, - _fault_handler_sel); + _pd->cspace_cnode(_fault_handler_sel).copy(platform_specific()->core_cnode(), + pager_sel, _fault_handler_sel); /* allocate endpoint selector in the PD's CSpace */ _ep_sel = _pd->alloc_sel(); /* install the thread's endpoint selector to the PD's CSpace */ - _pd->cspace_cnode().copy(platform_specific()->core_cnode(), _info.ep_sel, - _ep_sel); + _pd->cspace_cnode(_ep_sel).copy(platform_specific()->core_cnode(), + _info.ep_sel, _ep_sel); /* * Populate the thread's IPC buffer with initial information about the @@ -148,7 +148,7 @@ int Platform_thread::start(void *ip, void *sp, unsigned int cpu_no) seL4_CapData_t const no_cap_data = { { 0 } }; int const ret = seL4_TCB_SetSpace(_info.tcb_sel.value(), _fault_handler_sel.value(), - _pd->cspace_cnode().sel().value(), guard_cap_data, + _pd->cspace_cnode_1st().sel().value(), guard_cap_data, _pd->page_directory_sel().value(), no_cap_data); ASSERT(ret == 0); diff --git a/repos/base-sel4/src/include/base/internal/capability_space_sel4.h b/repos/base-sel4/src/include/base/internal/capability_space_sel4.h index bad1180676..39d9580a8c 100644 --- a/repos/base-sel4/src/include/base/internal/capability_space_sel4.h +++ b/repos/base-sel4/src/include/base/internal/capability_space_sel4.h @@ -101,7 +101,9 @@ namespace Genode }; enum { - CSPACE_SIZE_LOG2 = 8, + CSPACE_SIZE_LOG2_1ST = 4, + CSPACE_SIZE_LOG2_2ND = 8, + CSPACE_SIZE_LOG2 = CSPACE_SIZE_LOG2_1ST + CSPACE_SIZE_LOG2_2ND, NUM_CORE_MANAGED_SEL_LOG2 = 7, }; };