Skip to content

Commit da5f7e1

Browse files
dcpleungaescolar
authored andcommitted
xtensa: mpu: update hardware if manipulating current domain
If adding/removing to the domain of the current running thread, we need to update the hardware MPU regions or else the addition or removal would not be reflected to current running thread. Signed-off-by: Daniel Leung <[email protected]>
1 parent 6bd0dcf commit da5f7e1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

arch/xtensa/core/mpu.c

+25
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
773773
{
774774
int ret;
775775
uint32_t perm;
776+
struct k_thread *cur_thread;
776777
struct xtensa_mpu_map *map = &domain->arch.mpu_map;
777778
struct k_mem_partition *partition = &domain->partitions[partition_id];
778779
uintptr_t end_addr = partition->start + partition->size;
@@ -841,6 +842,15 @@ int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
841842
CONFIG_XTENSA_MPU_DEFAULT_MEM_TYPE,
842843
NULL);
843844

845+
/*
846+
* Need to update hardware MPU regions if we are removing
847+
* partition from the domain of the current running thread.
848+
*/
849+
cur_thread = _current_cpu->current;
850+
if (cur_thread->mem_domain_info.mem_domain == domain) {
851+
xtensa_mpu_map_write(cur_thread);
852+
}
853+
844854
out:
845855
return ret;
846856
}
@@ -849,6 +859,7 @@ int arch_mem_domain_partition_add(struct k_mem_domain *domain,
849859
uint32_t partition_id)
850860
{
851861
int ret;
862+
struct k_thread *cur_thread;
852863
struct xtensa_mpu_map *map = &domain->arch.mpu_map;
853864
struct k_mem_partition *partition = &domain->partitions[partition_id];
854865
uintptr_t end_addr = partition->start + partition->size;
@@ -863,6 +874,20 @@ int arch_mem_domain_partition_add(struct k_mem_domain *domain,
863874
CONFIG_XTENSA_MPU_DEFAULT_MEM_TYPE,
864875
NULL);
865876

877+
/*
878+
* Need to update hardware MPU regions if we are removing
879+
* partition from the domain of the current running thread.
880+
*
881+
* Note that this function can be called with dummy thread
882+
* at boot so we need to avoid writing MPU regions to
883+
* hardware.
884+
*/
885+
cur_thread = _current_cpu->current;
886+
if (((cur_thread->base.thread_state & _THREAD_DUMMY) != _THREAD_DUMMY) &&
887+
(cur_thread->mem_domain_info.mem_domain == domain)) {
888+
xtensa_mpu_map_write(cur_thread);
889+
}
890+
866891
out:
867892
return ret;
868893
}

0 commit comments

Comments
 (0)