Commit 4d377539a1190e838eae5d8b8a794dde0696d572

Authored by Ye Li
1 parent 64f857aefa

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 <ye.li@nxp.com>
Reviewed-by: Anson Huang <Anson.Huang@nxp.com>
(cherry picked from commit 164279c42de0d058b7abe198cc154ee683087e6a)

Showing 1 changed file with 22 additions and 1 deletions Side-by-side Diff

arch/arm/mach-imx/imx8/cpu.c
... ... @@ -1250,6 +1250,27 @@
1250 1250  
1251 1251 #define MEMSTART_ALIGNMENT SZ_2M /* Align the memory start with 2MB */
1252 1252  
  1253 +static sc_faddr_t reserve_optee_shm(sc_faddr_t addr_start)
  1254 +{
  1255 + /* OPTEE has a share memory at its top address,
  1256 + * ATF assigns the share memory to non-secure os partition for share with kernel
  1257 + * We should not add this share memory to DDR bank, as this memory is dedicated for
  1258 + * optee, optee driver will memremap it and can't be used by system malloc.
  1259 + */
  1260 +
  1261 + sc_faddr_t optee_start = rom_pointer[0];
  1262 + sc_faddr_t optee_size = rom_pointer[1];
  1263 +
  1264 + if (optee_size && optee_start <= addr_start &&
  1265 + addr_start < optee_start + optee_size) {
  1266 + debug("optee 0x%llx 0x%llx, addr_start 0x%llx\n",
  1267 + optee_start, optee_size, addr_start);
  1268 + return optee_start + optee_size;
  1269 + }
  1270 +
  1271 + return addr_start;
  1272 +}
  1273 +
1253 1274 static int get_owned_memreg(sc_rm_mr_t mr, sc_faddr_t *addr_start,
1254 1275 sc_faddr_t *addr_end)
1255 1276 {
... ... @@ -1265,7 +1286,7 @@
1265 1286 return -EINVAL;
1266 1287 }
1267 1288 debug("0x%llx -- 0x%llx\n", start, end);
1268   - *addr_start = start;
  1289 + *addr_start = reserve_optee_shm(start);
1269 1290 *addr_end = end;
1270 1291  
1271 1292 return 0;