Skip to content

Commit 55d614b

Browse files
committed
core: arm: enable dynamic config with pager
Add support for CFG_DYN_CONFIG=y and CFG_WITH_PAGER=y. The special .pager_boot_mem section is extended to cover the memory needed by CFG_DYN_CONFIG=y, this includes translation tables, stacks, and heap. Later patches can make CFG_DYN_CONFIG=y mandatory for ARCH=arm and remove redundant code. Signed-off-by: Jens Wiklander <[email protected]>
1 parent 7fe6862 commit 55d614b

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

core/arch/arm/kernel/boot.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,11 @@ static void init_primary(unsigned long pageable_part)
911911
* every virtual partition separately. Core code uses nex_malloc
912912
* instead.
913913
*/
914+
#ifndef CFG_DYN_CONFIG
914915
#ifdef CFG_WITH_PAGER
915916
/* Add heap2 first as heap1 may be too small as initial bget pool */
916917
malloc_add_pool(__heap2_start, __heap2_end - __heap2_start);
917918
#endif
918-
#ifndef CFG_DYN_CONFIG
919919
#ifdef CFG_NS_VIRTUALIZATION
920920
nex_malloc_add_pool(__nex_heap_start, __nex_heap_end -
921921
__nex_heap_start);
@@ -981,6 +981,12 @@ static void init_primary(unsigned long pageable_part)
981981
* init_runtime()).
982982
*/
983983
thread_get_core_local()->curr_thread = 0;
984+
if (IS_ENABLED(CFG_DYN_CONFIG)) {
985+
threads = calloc(1, sizeof(*threads));
986+
if (!threads)
987+
panic();
988+
thread_count = 1;
989+
}
984990
init_pager_runtime(pageable_part);
985991
}
986992

core/arch/arm/kernel/entry_a32.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,12 @@ shadow_stack_access_ok:
451451
#endif
452452

453453
#if defined(CFG_DYN_CONFIG)
454+
#ifdef CFG_WITH_PAGER
455+
ldr r0, =__vcore_free_end
456+
#else
454457
ldr r0, =boot_embdata_ptr
455458
ldr r0, [r0]
459+
#endif
456460
sub r1, r0, #THREAD_BOOT_INIT_TMP_ALLOC
457461

458462
/* Clear the allocated struct thread_core_local */
@@ -537,7 +541,11 @@ shadow_stack_access_ok:
537541
ldr r0, =__vcore_free_start
538542
ldr r2, =__vcore_free_end
539543
#ifdef CFG_WITH_PAGER
544+
#ifdef CFG_DYN_CONFIG
545+
sub r1, r2, #THREAD_BOOT_INIT_TMP_ALLOC
546+
#else
540547
mov r1, r2
548+
#endif
541549
#else
542550
ldr r1, =boot_embdata_ptr
543551
ldr r1, [r1]

core/arch/arm/kernel/entry_a64.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,12 @@ clear_nex_bss:
316316
* Point SP_EL1 a temporary struct thread_core_local before the
317317
* temporary stack.
318318
*/
319+
#ifdef CFG_WITH_PAGER
320+
adr_l x0, __vcore_free_end
321+
#else
319322
adr_l x0, boot_embdata_ptr
320323
ldr x0, [x0]
324+
#endif
321325
sub x1, x0, #THREAD_BOOT_INIT_TMP_ALLOC
322326

323327
/* Clear the allocated struct thread_core_local */
@@ -391,7 +395,11 @@ clear_nex_bss:
391395
adr_l x0, __vcore_free_start
392396
adr_l x2, __vcore_free_end
393397
#ifdef CFG_WITH_PAGER
398+
#ifdef CFG_DYN_CONFIG
399+
sub x1, x2, #THREAD_BOOT_INIT_TMP_ALLOC
400+
#else
394401
mov x1, x2
402+
#endif
395403
#else
396404
adr_l x1, boot_embdata_ptr
397405
ldr x1, [x1]

core/arch/arm/kernel/kern.ld.S

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5050
*/
5151

52+
#include <generated/asm-defines.h>
53+
#include <kernel/thread_private_arch.h>
5254
#include <mm/core_mmu.h>
5355
#include <platform_config.h>
5456
#include <util.h>
@@ -316,7 +318,33 @@ SECTIONS
316318
* the physical memory.
317319
*/
318320
.pager_boot_mem (NOLOAD): {
321+
#ifdef CFG_DYN_CONFIG
322+
#ifdef CFG_WITH_LPAE
323+
XLAT_TABLE_SIZE = SMALL_PAGE_SIZE;
324+
#ifndef MAX_XLAT_TABLES
325+
MAX_XLAT_TABLES = 3 /* ASLR_EXTRA */ + 5 /* TEE_EXTRA */;
326+
#endif
327+
/* Base tables */
328+
. += 4 * 2 * CFG_TEE_CORE_NB_CORE * XLAT_TABLE_SIZE;
329+
/* Per thread EL0 tables */
330+
. += CFG_NUM_THREADS * XLAT_TABLE_SIZE;
331+
#else
332+
XLAT_TABLE_SIZE = 1024;
333+
#ifndef MAX_XLAT_TABLES
334+
MAX_XLAT_TABLES = 6 + 2 /* ASLR_EXTRA */;
335+
#endif
336+
. += 16 * 1024; /* Main L1 table */
337+
. += 64 * 4 * CFG_NUM_THREADS; /* L1 table for TAs */
338+
#endif
339+
. += MAX_XLAT_TABLES * XLAT_TABLE_SIZE;
340+
. += CFG_CORE_HEAP_SIZE;
341+
. += CFG_NUM_THREADS * THREAD_CTX_SIZE;
342+
. += CFG_TEE_CORE_NB_CORE * THREAD_CORE_LOCAL_SIZE;
343+
. += THREAD_BOOT_INIT_TMP_ALLOC;
344+
#else
319345
. += SMALL_PAGE_SIZE;
346+
#endif
347+
. = ALIGN(SMALL_PAGE_SIZE);
320348
}
321349
__flatmap_free_start = ADDR(.pager_boot_mem);
322350
__flatmap_free_size = SIZEOF(.pager_boot_mem);

mk/config.mk

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,12 +1296,8 @@ CFG_CORE_UNSAFE_MODEXP ?= n
12961296
CFG_TA_MBEDTLS_UNSAFE_MODEXP ?= n
12971297

12981298
# CFG_DYN_CONFIG, when enabled, use dynamic memory allocation for translation
1299-
# tables and stacks. Not supported with pager.
1300-
ifeq ($(CFG_WITH_PAGER),y)
1301-
$(call force,CFG_DYN_CONFIG,n,conflicts with CFG_WITH_PAGER)
1302-
else
1299+
# tables and stacks.
13031300
CFG_DYN_CONFIG ?= y
1304-
endif
13051301

13061302
# CFG_EXTERNAL_ABORT_PLAT_HANDLER is used to implement platform-specific
13071303
# handling of external abort implementing the plat_external_abort_handler()

0 commit comments

Comments
 (0)