arch: arm: mpu: Lock irqs while reprogramming the nxp mpu
arch: arm: mpu: Lock irqs while reprogramming the nxp mpu

The nxp mpu uses the logical OR of access permissions when multiple
region descriptors apply to a given memory access. This means that we
must partition the sram into two non-overlapping regions to implement
the mpu stack guard. This partitioning gets reconfigured at every
context switch, and if an interrupt occurs during this time, it can
cause a fault because we do not have a valid mpu region descriptor for
the sram.

This scenario was observed on frdm_k64f in tests/posix/common before
commit 2895da02a44980e901fbcdd7ec87edc2016605c5, which changed timing.
In this case, we couldn't even print fault information to the console
and the hardware would reset. It looked a lot like a watchdog reset,
unless you attached a debugger to see the fault.

A similar problem was fixed in commit
ec424b7a455cc98c36e3cab80be7e152ef2c5217, but this change temporarily
disabled the mpu.

Fix both cases by locking interrupts during the critical sections, as
this is more secure than disabling the mpu.

Signed-off-by: Maureen Helm <87a696db5547fa477bda9f9e0f00013c839c14d3@nxp.com>

nashif/zephyr,ldts/zephyr,galak/zephyr,galak/zephyr,nashif/zephyr,galak/zephyr,zephyrproject-rtos/zephyr,Vudentz/zephyr,Vudentz/zephyr,finikorg/zephyr,ldts/zephyr,Vudentz/zephyr,GiulianoFranchetto/zephyr,finikorg/zephyr,finikorg/zephyr,zephyrproject-rtos/zephyr,galak/zephyr,galak/zephyr,nashif/zephyr,Vudentz/zephyr,zephyrproject-rtos/zephyr,GiulianoFranchetto/zephyr,finikorg/zephyr,zephyrproject-rtos/zephyr,finikorg/zephyr,GiulianoFranchetto/zephyr,zephyrproject-rtos/zephyr,ldts/zephyr,ldts/zephyr,nashif/zephyr,ldts/zephyr,GiulianoFranchetto/zephyr,nashif/zephyr,Vudentz/zephyr,Vudentz/zephyr,GiulianoFranchetto/zephyr