From 3450fd622412927ec4c4834b24b9c669f905b40a Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Wed, 9 May 2018 15:14:06 +0100 Subject: [PATCH 1/2] plat/arm: Fix incorrect number of reserved memory map entries There are three calls to mmap_add_region() that always occur in arm_setup_page_tables(), and two further calls based on whether coherent memory is enabled, and whether SPM is enabled in BL31. This commit adapts the ARM_BL_REGIONS definition to match the number of calls made inside arm_setup_page_tables() so that the MAX_MMAP_REGIONS is realigned with what is actually occurring. Change-Id: I7adc05951abccf2cbd5c86280eb874911e6a1566 Signed-off-by: Chris Kay --- include/plat/arm/common/arm_def.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/plat/arm/common/arm_def.h b/include/plat/arm/common/arm_def.h index 95e986bf2b..a0368dafc0 100644 --- a/include/plat/arm/common/arm_def.h +++ b/include/plat/arm/common/arm_def.h @@ -245,10 +245,16 @@ * The number of regions like RO(code), coherent and data required by * different BL stages which need to be mapped in the MMU. */ -#if USE_COHERENT_MEM -#define ARM_BL_REGIONS 3 +#if ENABLE_SPM && defined(IMAGE_BL31) +# if USE_COHERENT_MEM +# define ARM_BL_REGIONS 5 +# else +# define ARM_BL_REGIONS 4 +# endif +#elif USE_COHERENT_MEM +# define ARM_BL_REGIONS 4 #else -#define ARM_BL_REGIONS 2 +# define ARM_BL_REGIONS 3 #endif #define MAX_MMAP_REGIONS (PLAT_ARM_MMAP_ENTRIES + \ From 053b4f92cbfa627418441daf5f9b1b89739c2fd1 Mon Sep 17 00:00:00 2001 From: Chris Kay Date: Wed, 9 May 2018 15:46:07 +0100 Subject: [PATCH 2/2] plat/arm: Fix incorrect bounds check in ARM_CASSERT_MMAP The bounds check in ARM_CASSERT_MMAP does not take into account the array sentinel in plat_arm_mmap. This commit fixes this, and adds an additional check to ensure the number of entries in the array is within the bounds of PLAT_ARM_MMAP_ENTRIES. Change-Id: Ie6df10c0aa0890d62826bc3224ad7b3e36fd53e2 Signed-off-by: Chris Kay --- include/plat/arm/common/plat_arm.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h index 612a63a8c6..fc3f4ec3a7 100644 --- a/include/plat/arm/common/plat_arm.h +++ b/include/plat/arm/common/plat_arm.h @@ -59,9 +59,11 @@ typedef struct arm_tzc_regions_info { PLAT_ARM_TZC_NS_DEV_ACCESS} #endif -#define ARM_CASSERT_MMAP \ - CASSERT((ARRAY_SIZE(plat_arm_mmap) + ARM_BL_REGIONS) \ - <= MAX_MMAP_REGIONS, \ +#define ARM_CASSERT_MMAP \ + CASSERT((ARRAY_SIZE(plat_arm_mmap) - 1) <= PLAT_ARM_MMAP_ENTRIES, \ + assert_plat_arm_mmap_mismatch); \ + CASSERT((PLAT_ARM_MMAP_ENTRIES + ARM_BL_REGIONS) \ + <= MAX_MMAP_REGIONS, \ assert_max_mmap_regions); /*