Question about critical section when enable MPU support

I am porting the PMP part of RISCV with reference to MPU. I am currently confused about whether non-privileged tasks can enter the critical section.

On ARM Cortex-M3/4/7 ports, there is a macro configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS to allow unprivileged tasks to create critical sections. In FreeRTOS-Kernel/portable/GCC/ARM_CM4_MPU/portmacro.h at e5987bbdb2041f70c9502f99a8c5643a30b9ff26 · FreeRTOS/FreeRTOS-Kernel · GitHub . vPortEnterCritical() and vPortExitCritical() are not placed in the PRIVILEGED_FUNCTION section. I’m wondering if unprivileged tasks can call taskENTER_CRITICAL() if configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS is disabled?

Besides, for Cortex-V8M (CM23, CM33), can unprivileged tasks enter critical sections?

Unprivileged tasks are not permitted to enter critical sections because, if allowed, a misbehaving unprivileged task could enter a critical section and deliberately not exit, bringing the system to a halt. The configALLOW_UNPRIVILEGED_CRITICAL_SECTIONS configuration option in ARM-v7M ports exists solely for backward compatibility and its use is discouraged.

For more details on the security considerations, please refer to the FreeRTOS Kernel Threat Model: Kernel threat model - FreeRTOS™.

Once done, please upstream your port as it could benefit the broader FreeRTOS community.

Thanks for confirming—absolutely want to contribute if possible.

But there seems to be significant uncertainty here, because RISC-V’s PMP (Physical Memory Protection) does not govern memory access permissions in M-mode—unless the lock bit is set. This stands in sharp contrast to Cortex-M’s MPU (Memory Protection Unit), which cancontrol access for privileged modes.

Additionally, pvPortMalloc()does not support specifying alignment granularity. If configSUPPORT_DYNAMIC_ALLOCATIONis enabled, on platforms with a large PMP granularity (e.g., 256 Byte), RTOS objects allocated from the FreeRTOS heap fail to meet the required alignment.

It seems there is still a long road ahead.

I am not very familiar with PMP but does it mean that we need to run tasks in U-mode and only kernel runs in M-mode?

For this one, you can enforce that all the tasks must be created using xTaskCreateRestricted APIs and the application writer must supply the correctly aligned stack.