Closed lorc closed 6 years ago
I found why this happens, but I'm not sure if this behavior is intended. So, memremap()
detects that shared region is located in System RAM, and, thus, returns pointer to mapped system memory. Problem is that this region is not mapped. It is being unmapped during kernel initialization:
[ 0.000000] [
] change_page_range+0x70/0x80 [ 0.000000] [ ] apply_to_page_range+0x1ec/0x390 [ 0.000000] [ ] change_memory_common+0x38/0xb0 [ 0.000000] [ ] set_memory_valid+0x1c/0x40 [ 0.000000] [ kernel_map_pages+0x14/0x20 [ 0.000000] [] ] free_pages_ok+0x2a0/0x2a8 [ 0.000000] [ ] free_pages+0x30/0x50 [ 0.000000] [] __free_pages_bootmem+0xa0/0xa8 [ 0.000000] [ ] free_all_bootmem+0x124/0x194 [ 0.000000] [ ] mem_init+0x98/0x2b8 [ 0.000000] [ ] start_kernel+0x1ec/0x3b0
change_page_range()
removes valid
bit from a PTE.
Actually, I expected that kernel memory is always mapped. But looks like this is not true. So, from user point of view it looks like memremap()
returns pointer to not mapped memory. I don't know is this right behavior. But for me it looks wrong.
Also, I'm bothered by /reserved-memory
entry in DTB. According to optee-os code, it should write range of shared memory region there. But in reality, it stores TEE RAM region:
[ 0.000000] OF: reserved mem: name: optee@0xe400000 base:e400000, size:200000
(SHM starts at 0x7fe00000
).
Looks like misconfiguration somewhere.
It looks like config_nsmem()
in OP-TEE is using virtual addresses instead of physical addresses.
@jenswi-linaro, great eye! You are right. I did quick and dirty fix. Now kernel panics during early boot.
Looking further....
That's funny. QEMU puts initrd
image in the middle of SHM region.
So, with right /reserved-memory/optee
entry, kernel sees that initrd
is in midst of reserved memory and panics.
I tried to make SHM region smaller and all worked fine.
Aha, that's bad luck. I suppose we'd better change address range used for SHM inside OP-TEE. The good news is that we only need to update inside OP-TEE as the device tree passed to the kernel is updated automatically.
I created two PRs, that together should fix this issue:
Will close this issue after merge.
Tested on qemu_v8
To reproduce
Kernel panics:
The same test on
linaro/optee
(ac0c2c26b9819c5e95d56cb2d8937de0357eecaa) works perfectly fine.Small test shows that memory is remapped just fine, but access to it generates panic:
I'm currently investigating this further.