Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ config ARM64
select ARCH_HAS_DEMAND_MAPPING
select ARCH_SUPPORTS_EVICTION_TRACKING
select EVICTION_TRACKING if DEMAND_PAGING
select MEM_DOMAIN_HAS_THREAD_LIST if ARM_MPU
help
ARM64 (AArch64) architecture

Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/core/cortex_r/arm_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,8 @@ static int configure_domain_partitions(struct k_mem_domain *domain)
struct k_thread *thread;
int ret;

SYS_DLIST_FOR_EACH_CONTAINER(&domain->mem_domain_q, thread,
mem_domain_info.mem_domain_q_node) {
SYS_DLIST_FOR_EACH_CONTAINER(&domain->thread_mem_domain_list, thread,
mem_domain_info.thread_mem_domain_node) {
ret = configure_dynamic_mpu_regions(thread);
if (ret != 0) {
return ret;
Expand Down
9 changes: 7 additions & 2 deletions include/zephyr/app_memory/mem_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ struct k_mem_domain {
#endif /* CONFIG_ARCH_MEM_DOMAIN_DATA */
/** partitions in the domain */
struct k_mem_partition partitions[CONFIG_MAX_DOMAIN_PARTITIONS];
/** Doubly linked list of member threads */
sys_dlist_t mem_domain_q;
#ifdef CONFIG_MEM_DOMAIN_HAS_THREAD_LIST
/** Doubly linked list of member threads,
* pointer to the thread_mem_domain_node inside
* each thread's memory domain info struct.
*/
sys_dlist_t thread_mem_domain_list;
#endif /* CONFIG_MEM_DOMAIN_HAS_THREAD_LIST */
/** number of active partitions in the domain */
uint8_t num_partitions;
};
Expand Down
4 changes: 3 additions & 1 deletion include/zephyr/kernel/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ typedef struct _thread_stack_info _thread_stack_info_t;

#if defined(CONFIG_USERSPACE)
struct _mem_domain_info {
#ifdef CONFIG_MEM_DOMAIN_HAS_THREAD_LIST
/** memory domain queue node */
sys_dnode_t mem_domain_q_node;
sys_dnode_t thread_mem_domain_node;
#endif /* CONFIG_MEM_DOMAIN_HAS_THREAD_LIST */
/** memory domain of the thread */
struct k_mem_domain *mem_domain;
};
Expand Down
9 changes: 9 additions & 0 deletions kernel/Kconfig.mem_domain
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,13 @@ config MEM_DOMAIN_ISOLATED_STACKS
Regardless of this settings, threads cannot access the stacks of
threads outside of their domains.

config MEM_DOMAIN_HAS_THREAD_LIST
bool
help
If enabled, there is a doubly linked list in each memory domain
struct to keep track of the threads associated with this
particular memory domain.

This is selected by architecture needing this to function.

endmenu
18 changes: 14 additions & 4 deletions kernel/mem_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ int k_mem_domain_init(struct k_mem_domain *domain, uint8_t num_parts,

domain->num_partitions = 0U;
(void)memset(domain->partitions, 0, sizeof(domain->partitions));
sys_dlist_init(&domain->mem_domain_q);

#ifdef CONFIG_MEM_DOMAIN_HAS_THREAD_LIST
sys_dlist_init(&domain->thread_mem_domain_list);
#endif /* CONFIG_MEM_DOMAIN_HAS_THREAD_LIST */

#ifdef CONFIG_ARCH_MEM_DOMAIN_DATA
ret = arch_mem_domain_init(domain);
Expand Down Expand Up @@ -265,8 +268,12 @@ static int add_thread_locked(struct k_mem_domain *domain,
__ASSERT_NO_MSG(thread != NULL);

LOG_DBG("add thread %p to domain %p\n", thread, domain);
sys_dlist_append(&domain->mem_domain_q,
&thread->mem_domain_info.mem_domain_q_node);

#ifdef CONFIG_MEM_DOMAIN_HAS_THREAD_LIST
sys_dlist_append(&domain->thread_mem_domain_list,
&thread->mem_domain_info.thread_mem_domain_node);
#endif /* CONFIG_MEM_DOMAIN_HAS_THREAD_LIST */

thread->mem_domain_info.mem_domain = domain;

#ifdef CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API
Expand All @@ -283,7 +290,10 @@ static int remove_thread_locked(struct k_thread *thread)
__ASSERT_NO_MSG(thread != NULL);
LOG_DBG("remove thread %p from memory domain %p\n",
thread, thread->mem_domain_info.mem_domain);
sys_dlist_remove(&thread->mem_domain_info.mem_domain_q_node);

#ifdef CONFIG_MEM_DOMAIN_HAS_THREAD_LIST
sys_dlist_remove(&thread->mem_domain_info.thread_mem_domain_node);
#endif /* CONFIG_MEM_DOMAIN_HAS_THREAD_LIST */

#ifdef CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API
ret = arch_mem_domain_thread_remove(thread);
Expand Down