kernel: expose k_mem_partition_attr_t outside User mode

This commit exposes k_mem_partition_attr_t outside User Mode, so
we can use struct k_mem_partition for defining memory partitions
outside the scope of user space (for example, to describe thread
stack guards or no-cacheable MPU regions). A requirement is that
the Zephyr build supports Memory protection. To signify this, a
new hidden, all-architecture Kconfig symbol is defined (MPU). In
the wake of exposing k_mem_partition_attr_t, the commit exposes
the MPU architecture-specific access permission attribute macros
outside the User space context (for all ARCHs), so they can be
used in a more generic way.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2018-11-27 15:45:36 +01:00 committed by Anas Nashif
commit 39bf24a9bd
10 changed files with 18 additions and 13 deletions

View file

@ -393,6 +393,14 @@ config CPU_HAS_MPU
help help
This option is enabled when the CPU has a Memory Protection Unit (MPU). This option is enabled when the CPU has a Memory Protection Unit (MPU).
config MEMORY_PROTECTION
bool
# Omit prompt to signify "hidden" option
help
This option is enabled when Memory Protection features are supported.
Memory protection support is currently available on ARC, ARM, and x86
architectures.
config MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT config MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
bool bool
# Omit prompt to signify "hidden" option # Omit prompt to signify "hidden" option

View file

@ -31,6 +31,7 @@ config ARC_MPU
depends on CPU_HAS_MPU depends on CPU_HAS_MPU
select ARC_CORE_MPU select ARC_CORE_MPU
select THREAD_STACK_INFO select THREAD_STACK_INFO
select MEMORY_PROTECTION
select MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT if ARC_MPU_VER = 2 select MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT if ARC_MPU_VER = 2
help help
Target has ARC MPU (currently only works for EMSK 2.2/2.3 ARCEM7D) Target has ARC MPU (currently only works for EMSK 2.2/2.3 ARCEM7D)

View file

@ -9,6 +9,7 @@
config ARM_MPU config ARM_MPU
bool "ARM MPU Support" bool "ARM MPU Support"
depends on CPU_HAS_MPU depends on CPU_HAS_MPU
select MEMORY_PROTECTION
select THREAD_STACK_INFO select THREAD_STACK_INFO
select ARCH_HAS_EXECUTABLE_PAGE_BIT select ARCH_HAS_EXECUTABLE_PAGE_BIT
select MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT if !(CPU_HAS_NXP_MPU || ARMV8_M_BASELINE || ARMV8_M_MAINLINE) select MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT if !(CPU_HAS_NXP_MPU || ARMV8_M_BASELINE || ARMV8_M_MAINLINE)

View file

@ -64,6 +64,7 @@ config X86_IAMCU
menu "Memory Management" menu "Memory Management"
config X86_MMU config X86_MMU
bool "Enable Memory Management Unit" bool "Enable Memory Management Unit"
select MEMORY_PROTECTION
help help
This options enables the memory management unit present in x86. Enabling This options enables the memory management unit present in x86. Enabling
this will create boot time page table structure. this will create boot time page table structure.

View file

@ -243,7 +243,7 @@
#endif /* CONFIG_X86_PAE_MODE */ #endif /* CONFIG_X86_PAE_MODE */
#ifdef CONFIG_X86_USERSPACE #ifdef CONFIG_X86_MMU
/* Flags which are only available for PAE mode page tables */ /* Flags which are only available for PAE mode page tables */
#ifdef CONFIG_X86_PAE_MODE #ifdef CONFIG_X86_PAE_MODE
@ -297,7 +297,7 @@
#endif /* CONFIG_X86_PAE_MODE */ #endif /* CONFIG_X86_PAE_MODE */
#endif /* CONFIG_X86_USERSPACE */ #endif /* CONFIG_X86_MMU */
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <zephyr/types.h> #include <zephyr/types.h>

View file

@ -155,7 +155,6 @@ extern "C" {
#endif /* CONFIG_USERSPACE */ #endif /* CONFIG_USERSPACE */
#ifdef CONFIG_USERSPACE
#ifdef CONFIG_ARC_MPU #ifdef CONFIG_ARC_MPU
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <arch/arc/v2/mpu/arc_mpu.h> #include <arch/arc/v2/mpu/arc_mpu.h>
@ -217,7 +216,6 @@ extern "C" {
"start address of the partition must align with 32.") "start address of the partition must align with 32.")
#endif #endif
#endif /* CONFIG_ARC_MPU*/ #endif /* CONFIG_ARC_MPU*/
#endif /* CONFIG_USERSPACE */
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
/* Typedef for the k_mem_partition attribute*/ /* Typedef for the k_mem_partition attribute*/

View file

@ -252,7 +252,7 @@ extern "C" {
#define _ARCH_THREAD_STACK_BUFFER(sym) \ #define _ARCH_THREAD_STACK_BUFFER(sym) \
((char *)(sym) + MPU_GUARD_ALIGN_AND_SIZE) ((char *)(sym) + MPU_GUARD_ALIGN_AND_SIZE)
#ifdef CONFIG_USERSPACE #ifdef CONFIG_ARM_MPU
#ifdef CONFIG_CPU_HAS_ARM_MPU #ifdef CONFIG_CPU_HAS_ARM_MPU
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
#include <arch/arm/cortex_m/mpu/arm_mpu.h> #include <arch/arm/cortex_m/mpu/arm_mpu.h>
@ -323,8 +323,8 @@ extern "C" {
" and greater than or equal to minimum MPU region size." \ " and greater than or equal to minimum MPU region size." \
"start address of the partition must align with minimum MPU \ "start address of the partition must align with minimum MPU \
region size.") region size.")
#endif /* CONFIG_CPU_HAS_ARM_MPU */ #endif /* CONFIG_CPU_HAS_NXP_MPU */
#endif /* CONFIG_USERSPACE */ #endif /* CONFIG_ARM_MPU */
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
/* Typedef for the k_mem_partition attribute*/ /* Typedef for the k_mem_partition attribute*/

View file

@ -129,7 +129,6 @@ struct arm_mpu_region_attr {
typedef struct arm_mpu_region_attr arm_mpu_region_attr_t; typedef struct arm_mpu_region_attr arm_mpu_region_attr_t;
#ifdef CONFIG_USERSPACE
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
/* Read-Write access permission attributes */ /* Read-Write access permission attributes */
#define K_MEM_PARTITION_P_NA_U_NA (NO_ACCESS_Msk | NOT_EXEC) #define K_MEM_PARTITION_P_NA_U_NA (NO_ACCESS_Msk | NOT_EXEC)
@ -162,4 +161,3 @@ typedef struct arm_mpu_region_attr arm_mpu_region_attr_t;
#define K_MEM_PARTITION_IS_EXECUTABLE(attr) \ #define K_MEM_PARTITION_IS_EXECUTABLE(attr) \
(!((attr) & (NOT_EXEC))) (!((attr) & (NOT_EXEC)))
#endif /* _ASMLANGUAGE */ #endif /* _ASMLANGUAGE */
#endif /* USERSPACE */

View file

@ -139,7 +139,6 @@ struct arm_mpu_region_attr {
typedef struct arm_mpu_region_attr arm_mpu_region_attr_t; typedef struct arm_mpu_region_attr arm_mpu_region_attr_t;
#ifdef CONFIG_USERSPACE
#ifndef _ASMLANGUAGE #ifndef _ASMLANGUAGE
/* Read-Write access permission attributes */ /* Read-Write access permission attributes */
#define K_MEM_PARTITION_P_RW_U_RW (P_RW_U_RW_Msk | NOT_EXEC) #define K_MEM_PARTITION_P_RW_U_RW (P_RW_U_RW_Msk | NOT_EXEC)
@ -168,4 +167,3 @@ struct arm_mpu_region_attr {
#define K_MEM_PARTITION_IS_EXECUTABLE(attr) \ #define K_MEM_PARTITION_IS_EXECUTABLE(attr) \
(!((attr) & (NOT_EXEC))) (!((attr) & (NOT_EXEC)))
#endif /* _ASMLANGUAGE */ #endif /* _ASMLANGUAGE */
#endif /* USERSPACE */

View file

@ -4781,10 +4781,10 @@ struct k_mem_partition {
u32_t start; u32_t start;
/* size of memory partition */ /* size of memory partition */
u32_t size; u32_t size;
#ifdef CONFIG_USERSPACE #if defined(CONFIG_MEMORY_PROTECTION)
/* attribute of memory partition */ /* attribute of memory partition */
k_mem_partition_attr_t attr; k_mem_partition_attr_t attr;
#endif /* CONFIG_USERSPACE */ #endif /* CONFIG_MEMORY_PROTECTION */
}; };
/* memory domain /* memory domain