• Zhen Lei's avatar
    ARM: 9210/1: Mark the FDT_FIXED sections as shareable · 598f0a99
    Zhen Lei authored
    commit 7a1be318 ("ARM: 9012/1: move device tree mapping out of linear
    region") use FDT_FIXED_BASE to map the whole FDT_FIXED_SIZE memory area
    which contains fdt. But it only reserves the exact physical memory that
    fdt occupied. Unfortunately, this mapping is non-shareable. An illegal or
    speculative read access can bring the RAM content from non-fdt zone into
    cache, PIPT makes it to be hit by subsequently read access through
    shareable mapping(such as linear mapping), and the cache consistency
    between cores is lost due to non-shareable property.
    
    |<---------FDT_FIXED_SIZE------>|
    |                               |
     -------------------------------
    | <non-fdt> | <fdt> | <non-fdt> |
     -------------------------------
    
    1. CoreA read <non-fdt> through MT_ROM mapping, the old data is loaded
       into the cache.
    2. CoreB write <non-fdt> to update data through linear mapping. CoreA
       received the notification to invalid the corresponding cachelines, but
       the property non-shareable makes it to be ignored.
    3. CoreA read <non-fdt> through linear mapping, cache hit, the old data
       is read.
    
    To eliminate this risk, add a new memory type MT_MEMORY_RO. Compared to
    MT_ROM, it is shareable and non-executable.
    
    Here's an example:
      list_del corruption. prev->next should be c0ecbf74, but was c08410dc
      kernel BUG at lib/list_debug.c:53!
      ... ...
      PC is at __list_del_entry_valid+0x58/0x98
      LR is at __list_del_entry_valid+0x58/0x98
      psr: 60000093
      sp : c0ecbf30  ip : 00000000  fp : 00000001
      r10: c08410d0  r9 : 00000001  r8 : c0825e0c
      r7 : 20000013  r6 : c08410d0  r5 : c0ecbf74  r4 : c0ecbf74
      r3 : c0825d08  r2 : 00000000  r1 : df7ce6f4  r0 : 00000044
      ... ...
      Stack: (0xc0ecbf30 to 0xc0ecc000)
      bf20:                                     c0ecbf74 c0164fd0 c0ecbf70 c0165170
      bf40: c0eca000 c0840c00 c0840c00 c0824500 c0825e0c c0189bbc c088f404 60000013
      bf60: 60000013 c0e85100 000004ec 00000000 c0ebcdc0 c0ecbf74 c0ecbf74 c0825d08
      ... ...                                           <  next     prev  >
      (__list_del_entry_valid) from (__list_del_entry+0xc/0x20)
      (__list_del_entry) from (finish_swait+0x60/0x7c)
      (finish_swait) from (rcu_gp_kthread+0x560/0xa20)
      (rcu_gp_kthread) from (kthread+0x14c/0x15c)
      (kthread) from (ret_from_fork+0x14/0x24)
    
    The faulty list node to be deleted is a local variable, its address is
    c0ecbf74. The dumped stack shows that 'prev' = c0ecbf74, but its value
    before lib/list_debug.c:53 is c08410dc. A large amount of printing results
    in swapping out the cacheline containing the old data(MT_ROM mapping is
    read only, so the cacheline cannot be dirty), and the subsequent dump
    operation obtains new data from the DDR.
    
    Fixes: 7a1be318 ("ARM: 9012/1: move device tree mapping out of linear region")
    Suggested-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Signed-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
    Reviewed-by: default avatarArd Biesheuvel <ardb@kernel.org>
    Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
    Signed-off-by: default avatarRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
    598f0a99
mmu.c 49.4 KB