A virtual memory is allocated via k_mem_map() cannot be used for a partition in arm64 MMU-based? #45160
Unanswered
Dat-NguyenDuy
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm using newlib for arm cortex-a53 with MMU is enabled, Zephyr image is loaded and ran from SRAM only.
I want to use
printf
in user thread, and i noticed that it will use newlib heap: https://github.com/zephyrproject-rtos/zephyr/blob/main/lib/libc/newlib/libc-hooks.c#L290 via_sbrk
.The heap is currently alocated via
k_mem_map()
: https://github.com/zephyrproject-rtos/zephyr/blob/main/lib/libc/newlib/libc-hooks.c#L111 and is added toz_malloc_partition
.So to use
printf
in user thread, i addedz_malloc_partition
into a domain by usingk_mem_domain_add_partition()
But i see that currently, the private map always treats the virtual memory and physical memory are the same: https://github.com/zephyrproject-rtos/zephyr/blob/main/arch/arm64/core/mmu.c#L1057-L1058
So i'm not clear that the virtual address and physical address for the partition should be the same before adding it into a domain.
With these Kconfigs from my side:
And here is the chart how the heap is allocated, there is a risk that the heap will be mapped in to invalid SRAM after
k_mem_domain_add_partition()
:Based on that, I have few points want to clarify:
The
malloc_prepare
implementation for heap is wrong for arm64 MMU? because we cannot use k_mem_map() to map the heap (heap virtual memory is may difference than physical memory) and then add it to a domain (expect virtual and physical are the same).Allocate a virtual region via
k_mem_map()
and add it in to a domain is not intended behavior, but how user space can use newlib heap with current implementation for heap?CONFIG_KERNEL_VM_SIZE
must be set equal or less thanCONFIG_SRAM_SIZE
to ensure that the virtual memory always fit in physical SRAM, in my side:CONFIG_KERNEL_VM_SIZE
= 0x380000 (=3584*1024)Thank you!!
Dat Nguyen
Beta Was this translation helpful? Give feedback.
All reactions