arm64: translate register values to physical addresses in kernel panics
PATCH 1/1 arm64: translate register values to physical addresses in kernel panics
When debugging a kernel panic it is sometimes useful to know the physical address of any virtual addresses stored in registers. Therefore, pass all register values through AT S1E1R and print the resulting PAR_EL1 value next to the register.
---
Not sure if this should land in this form (I imagine there could be all kinds of parsers that are expecting the existing format) but maybe behind an option. Let me know what you think.
arch/arm64/kernel/process.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
arch/arm64/kernel/process.c +14 -2
@@ -197,6 +197,18 @@ static void print_pstate(struct pt_regs *regs) } } +static unsigned long at (unsigned long addr) +{ +unsigned long pa; + + __asm__ __volatile__("at s1e1r, %1\n" +"mrs %0, par_el1\n" + :"=r" (pa) + :"r" (addr) + :"memory" ); +return pa; +} +void __show_regs (struct pt_regs *regs) {int i, top_reg;
@@ -231,10 +243,10 @@ void __show_regs(struct pt_regs *regs) i = top_reg;while (i >=0 ) { -printk ("x%-2d: %016llx" , i, regs->regs[i]); +printk ("x%-2d: %016llx (%016llx)" , i, regs->regs[i],at (regs->regs[i]));while (i-- %3 ) -pr_cont (" x%-2d: %016llx" , i, regs->regs[i]); +pr_cont (" x%-2d: %016llx (%016llx)" , i, regs->regs[i],at (regs->regs[i]));pr_cont ("\n" ); }
Signature · 1 line
2.37.1.595.g718a3a8f04-goog
Catalin Marinas
maintainerQuoted 4 lines · Peter Collingbourne
When debugging a kernel panic it is sometimes useful to know the physical address of any virtual addresses stored in registers. Therefore, pass all register values through AT S1E1R and print the resulting
PAR_EL1value next to the register.
I don't see much value in this but I haven't come across a use-case yet. For page faults the kernel prints the content of the PTE and that's what I'm usually interested in.
Quoted 3 lines
Not sure if this should land in this form (I imagine there could be all kinds of parsers that are expecting the existing format) but maybe behind an option. Let me know what you think.
While that's not considered user ABI, there might be some scripts parsing it, though I suspect they don't pay attention to the registers (I might be wrong though).
arch/arm64/kernel/process.c static void print_pstate(struct pt_regs *regs) · line 210
Quoted 11 lines
arch/arm64/kernel/process.c +11
-0+static unsigned long at (unsigned long addr) +{ +unsigned long pa; + + __asm__ __volatile__("at s1e1r, %1\n" +"mrs %0, par_el1\n" + :"=r" (pa) + :"r" (addr) + :"memory" ); +return pa; +}
This should take the translation fault into account. If PAR_EL1.F is 1, the other bits can't be treated as a physical address. Also if you want the actual address, it's also worth masking out the non-relevant bits from PAR_EL1 and adding the offset from 'addr' into the lower 12 bits.
arch/arm64/kernel/process.c void __show_regs(struct pt_regs *regs) · line 249
Quoted 13 lines
void
__show_regs(struct pt_regs *regs)
{arch/arm64/kernel/process.c +2
-2int i, top_reg;@@ -231,10 +243,10 @@ void __show_regs(struct pt_regs *regs) i = top_reg;while (i >=0 ) { -printk ("x%-2d: %016llx" , i, regs->regs[i]); +printk ("x%-2d: %016llx (%016llx)" , i, regs->regs[i],at (regs->regs[i]));while (i-- %3 ) -pr_cont (" x%-2d: %016llx" , i, regs->regs[i]); +pr_cont (" x%-2d: %016llx (%016llx)" , i, regs->regs[i],at (regs->regs[i]));
How long are the lines printed here? Maybe a better option without cluttering the register values is to do another pass through the register and print the potential VA->PA translations (only those kernel addresses that do not fault). If one is interested they could look them up on the following lines.
Signature · 1 line
Catalin