Search code examples
clinux-kernelarmcpu-cache

Why ARMv7-A crashes when flushing the stack pointer from the cache


I am trying to evict the memory address in which the stack pointer is pointing to it in an ARM Cortex-A8 processor. I am trying to do that with the below code:

cpy r3, sp
mcr p15, 0x0, r3, cr7, cr6, 0x1

I have run the above code in a loadable kernel module. after running the above code in the kernel, OS crashes and needs a restart. but the above instructions work fine for flushing a variable from the cache.

Can anyone give me any advice to solve the problem?


Solution

  • Thanks to artless noise, actually ARM cortex-a8 has 3 types of command for cache manipulation based on Modified Virtual address:

    Invalidate (C6, 1) (just invalidate the cache line)
    Clean (C10, 1) (Update memory if the cache line is dirty)
    Clean & Invalidate (C14, 1) (Update memory then invalidate cache line)
    

    and as you can see in the question I used Invalidate instruction and it caused that memory to have invalid data for the stack. but after using Clean&Invalidate instruction the problem was solved. so the final code is as below:

    cpy r3, sp
    mcr p15, 0x0, r3, cr7, cr14, 0x1
    DSB SY