Skip to content

Commit 5d466aa

Browse files
dcpleungnashif
authored andcommitted
xtensa: mpu: make sure write to MPU regions is atomic
This adds a spinlock to make sure writing to hardware MPU regions is atomic, and cannot be interrupted until all regions are written to hardware. Signed-off-by: Daniel Leung <daniel.leung@intel.com> (cherry picked from commit 6bd0dcf)
1 parent 4aa5607 commit 5d466aa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/xtensa/core/mpu.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ extern char _heap_start[];
3333
/** MPU foreground map for kernel mode. */
3434
static struct xtensa_mpu_map xtensa_mpu_map_fg_kernel;
3535

36+
/** Make sure write to the MPU region is atomic. */
37+
static struct k_spinlock xtensa_mpu_lock;
38+
3639
/*
3740
* Additional information about the MPU maps: foreground and background
3841
* maps.
@@ -629,6 +632,9 @@ void xtensa_mpu_map_write(struct xtensa_mpu_map *map)
629632
#endif
630633
{
631634
int entry;
635+
k_spinlock_key_t key;
636+
637+
key = k_spin_lock(&xtensa_mpu_lock);
632638

633639
#ifdef CONFIG_USERSPACE
634640
struct xtensa_mpu_map *map = thread->arch.mpu_map;
@@ -652,6 +658,8 @@ void xtensa_mpu_map_write(struct xtensa_mpu_map *map)
652658
__asm__ volatile("wptlb %0, %1\n\t"
653659
: : "a"(map->entries[entry].at), "a"(map->entries[entry].as));
654660
}
661+
662+
k_spin_unlock(&xtensa_mpu_lock, key);
655663
}
656664

657665
/**

0 commit comments

Comments
 (0)