From 4d377539a1190e838eae5d8b8a794dde0696d572 Mon Sep 17 00:00:00 2001 From: Ye Li Date: Tue, 29 Oct 2019 00:11:33 -0700 Subject: [PATCH] MLK-22866 imx8: Remove the optee shared memory from DDR banks Optee has 4MB shared memory at its top space which was assigned to non-secure OS partition in ATF. By default this memory is added to u-boot DDR banks and will pass to kernel. This means kernel has possibility to allocate from this memory for system usage. At same time this memory is used by optee and mem-remapped by optee kernel driver. So it is possible to have conflict and cause kernel crash. Fix the issue by removing the shared memory from u-boot DDR banks. Then it is not visible for both u-boot and kernel and can avoid such issue. Signed-off-by: Ye Li Reviewed-by: Anson Huang (cherry picked from commit 164279c42de0d058b7abe198cc154ee683087e6a) --- arch/arm/mach-imx/imx8/cpu.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/imx8/cpu.c b/arch/arm/mach-imx/imx8/cpu.c index b497e2a..5b87ff4 100644 --- a/arch/arm/mach-imx/imx8/cpu.c +++ b/arch/arm/mach-imx/imx8/cpu.c @@ -1250,6 +1250,27 @@ int ft_system_setup(void *blob, bd_t *bd) #define MEMSTART_ALIGNMENT SZ_2M /* Align the memory start with 2MB */ +static sc_faddr_t reserve_optee_shm(sc_faddr_t addr_start) +{ + /* OPTEE has a share memory at its top address, + * ATF assigns the share memory to non-secure os partition for share with kernel + * We should not add this share memory to DDR bank, as this memory is dedicated for + * optee, optee driver will memremap it and can't be used by system malloc. + */ + + sc_faddr_t optee_start = rom_pointer[0]; + sc_faddr_t optee_size = rom_pointer[1]; + + if (optee_size && optee_start <= addr_start && + addr_start < optee_start + optee_size) { + debug("optee 0x%llx 0x%llx, addr_start 0x%llx\n", + optee_start, optee_size, addr_start); + return optee_start + optee_size; + } + + return addr_start; +} + static int get_owned_memreg(sc_rm_mr_t mr, sc_faddr_t *addr_start, sc_faddr_t *addr_end) { @@ -1265,7 +1286,7 @@ static int get_owned_memreg(sc_rm_mr_t mr, sc_faddr_t *addr_start, return -EINVAL; } debug("0x%llx -- 0x%llx\n", start, end); - *addr_start = start; + *addr_start = reserve_optee_shm(start); *addr_end = end; return 0; -- 1.9.1