MLK-22866 imx8: Remove the optee shared memory from DDR banks
authorYe Li <ye.li@nxp.com>
Tue, 29 Oct 2019 07:11:33 +0000 (00:11 -0700)
committerYe Li <ye.li@nxp.com>
Thu, 29 Apr 2021 07:56:34 +0000 (00:56 -0700)
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 <ye.li@nxp.com>
Reviewed-by: Anson Huang <Anson.Huang@nxp.com>
(cherry picked from commit 164279c42de0d058b7abe198cc154ee683087e6a)
(cherry picked from commit 2c1016db0c08b8ade597146782c4267d77f77973)

arch/arm/mach-imx/imx8/cpu.c

index a488712..8b43715 100644 (file)
@@ -416,6 +416,27 @@ int mmc_get_env_dev(void)
 
 #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 = boot_pointer[0];
+       sc_faddr_t optee_size = boot_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)
 {
@@ -431,7 +452,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;