From 34e9c0933083dca3349b90f47ddffbc2eb87dbc1 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 22 Jan 2021 07:37:37 -0500 Subject: [PATCH] Revert "arch: remove KERNEL_RAM_SIZE" This reverts commit 73561be5001f67f0194a505fed19fca98b2be2b7. Signed-off-by: Anas Nashif --- arch/Kconfig | 37 ++++++++++++++------ tests/kernel/mem_protect/syscalls/src/main.c | 5 ++- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index c226591aa9b..dedc122a590 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -541,10 +541,21 @@ config MMU_PAGE_SIZE support multiple page sizes, put the smallest one here. config KERNEL_VM_BASE - hex "Virtual address space base address" + hex "Base virtual address to link the kernel" default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_SRAM)) help - Define the base of the kernel's address space. + Define the base virtual memory address for the core kernel. + + The kernel expects a mappings for all physical RAM regions starting at + this virtual address, with any unused space up to the size denoted by + KERNEL_VM_SIZE available for memory mappings. This base address denotes + the start of the RAM mapping and may not be the base address of the + kernel itself, but the offset of the kernel here will be the same as the + offset from the beginning of physical memory where it was loaded. + + If there are multiple physical RAM regions which are discontinuous in + the physical memory map, they should all be mapped in a continuous + virtual region, with bounds defined by KERNEL_RAM_SIZE. By default, this is the same as the DT_CHOSEN_Z_SRAM physical base SRAM address from DTS, in which case RAM will be identity-mapped. Some @@ -552,7 +563,7 @@ config KERNEL_VM_BASE just one RAM region and doing this makes linking much simpler, as at least when the kernel boots all virtual RAM addresses are the same as their physical address (demand paging at runtime may later modify - this for non-pinned page frames). + this for some subset of non-pinned pages). Otherwise, if RAM isn't identity-mapped: 1. It is the architecture's responsibility to transition the @@ -565,9 +576,14 @@ config KERNEL_VM_BASE double-linking of paging structures to make the instruction pointer transition simpler). - Zephyr does not implement a split address space and if multiple - page tables are in use, they all have the same virtual-to-physical - mappings (with potentially different permissions). +config KERNEL_RAM_SIZE + hex "Total size of RAM mappings in bytes" + default $(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_SRAM)) + help + Indicates to the kernel the total size of RAM that is mapped. The + kernel expects that all physical RAM has a memory mapping in the virtual + address space, and that these RAM mappings are all within the virtual + region [KERNEL_VM_BASE..KERNEL_VM_BASE + KERNEL_RAM_SIZE). config KERNEL_VM_OFFSET hex "Kernel offset within address space" @@ -596,16 +612,17 @@ config KERNEL_VM_SIZE Size of the kernel's address space. Constraining this helps control how much total memory can be used for page tables. - The difference between KERNEL_VM_BASE and KERNEL_VM_SIZE indicates the + The difference between KERNEL_RAM_SIZE and KERNEL_VM_SIZE indicates the size of the virtual region for runtime memory mappings. This is needed for mapping driver MMIO regions, as well as special RAM mapping use-cases such as VSDO pages, memory mapped thread stacks, and anonymous memory - mappings. The kernel itself will be mapped in here as well at boot. + mappings. - Systems with very large amounts of memory (such as 512M or more) + The system currently assumes all RAM can be mapped in the virtual address + space. Systems with very large amounts of memory (such as 512M or more) will want to use a 64-bit build of Zephyr, there are no plans to implement a notion of "high" memory in Zephyr to work around physical - RAM size larger than the defined bounds of the virtual address space. + RAM which can't have a boot-time mapping due to a too-small address space. endif # MMU diff --git a/tests/kernel/mem_protect/syscalls/src/main.c b/tests/kernel/mem_protect/syscalls/src/main.c index 69f2f3d0c2f..83d88766cc7 100644 --- a/tests/kernel/mem_protect/syscalls/src/main.c +++ b/tests/kernel/mem_protect/syscalls/src/main.c @@ -7,7 +7,6 @@ #include #include #include -#include #include "test_syscalls.h" #define BUF_SIZE 32 @@ -17,8 +16,8 @@ || defined(CONFIG_BOARD_NUCLEO_L073RZ) #define FAULTY_ADDRESS 0x0FFFFFFF #elif CONFIG_MMU -/* Just past the zephyr image mapping should be a non-present page */ -#define FAULTY_ADDRESS ((uint8_t *)(&z_mapped_end)) +/* Just past the permanent RAM mapping should be a non-present page */ +#define FAULTY_ADDRESS (CONFIG_KERNEL_VM_BASE + CONFIG_KERNEL_RAM_SIZE) #else #define FAULTY_ADDRESS 0xFFFFFFF0 #endif