From f32ea4433c5385956c07f361d89f2fd225acc370 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Mon, 12 Jul 2021 11:17:56 -0700 Subject: [PATCH] kernel: demand_paging: clear BSS after paging is initialized If BSS section is not present in memory at boot, it would not have been cleared as the data pages are not in physical memory. Manipulating those pages would result in page faults. In this scenario, zeroing BSS can only be done once the paging mechanism has been initialized. So do it there. Signed-off-by: Daniel Leung --- kernel/mmu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/mmu.c b/kernel/mmu.c index 26a4ae2958a..5e629a7bfb5 100644 --- a/kernel/mmu.c +++ b/kernel/mmu.c @@ -797,6 +797,16 @@ void z_mem_manage_init(void) page_frames_initialized = true; #endif k_spin_unlock(&z_mm_lock, key); + +#ifndef CONFIG_LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT + /* If BSS section is not present in memory at boot, + * it would not have been cleared. This needs to be + * done now since paging mechanism has been initialized + * and the BSS pages can be brought into physical + * memory to be cleared. + */ + z_bss_zero(); +#endif } #ifdef CONFIG_DEMAND_PAGING