Skip to content

Commit 8f4f163

Browse files
committed
csky: optimize kernel panic print.
Use STACKTRACE to optimize panic print more pretty and align registers printing. Signed-off-by: Guo Ren <ren_guo@c-sky.com>
1 parent 0ea2dc7 commit 8f4f163

3 files changed

Lines changed: 41 additions & 56 deletions

File tree

‎arch/csky/kernel/dumpstack.c‎

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,39 @@ int kstack_depth_to_print = 48;
77

88
void show_trace(unsigned long *stack)
99
{
10-
unsigned long *endstack;
10+
unsigned long *stack_end;
11+
unsigned long *stack_start;
12+
unsigned long *fp;
1113
unsigned long addr;
12-
int i;
1314

14-
pr_info("Call Trace:\n");
15-
addr = (unsigned long)stack + THREAD_SIZE - 1;
16-
endstack = (unsigned long *)(addr & -THREAD_SIZE);
17-
i = 0;
18-
while (stack + 1 <= endstack) {
19-
addr = *stack++;
20-
/*
21-
* If the address is either in the text segment of the
22-
* kernel, or in the region which contains vmalloc'ed
23-
* memory, it *may* be the address of a calling
24-
* routine; if so, print it so that someone tracing
25-
* down the cause of the crash will be able to figure
26-
* out the call path that was taken.
27-
*/
28-
if (__kernel_text_address(addr)) {
29-
#ifndef CONFIG_KALLSYMS
30-
if (i % 5 == 0)
31-
pr_cont("\n ");
15+
addr = (unsigned long) stack & THREAD_MASK;
16+
stack_start = (unsigned long *) addr;
17+
stack_end = (unsigned long *) (addr + THREAD_SIZE);
18+
19+
fp = stack;
20+
pr_info("\nCall Trace:");
21+
22+
while (fp > stack_start && fp < stack_end) {
23+
#ifdef CONFIG_STACKTRACE
24+
addr = fp[1];
25+
fp = (unsigned long *) fp[0];
26+
#else
27+
addr = *fp++;
3228
#endif
33-
pr_cont(" [<%08lx>] %pS\n", addr, (void *)addr);
34-
i++;
35-
}
29+
if (__kernel_text_address(addr))
30+
pr_cont("\n[<%08lx>] %pS", addr, (void *)addr);
3631
}
3732
pr_cont("\n");
3833
}
3934

4035
void show_stack(struct task_struct *task, unsigned long *stack)
4136
{
42-
unsigned long *p;
43-
unsigned long *endstack;
44-
int i;
45-
4637
if (!stack) {
4738
if (task)
48-
stack = (unsigned long *)task->thread.esp0;
39+
stack = (unsigned long *)thread_saved_fp(task);
4940
else
5041
stack = (unsigned long *)&stack;
5142
}
52-
endstack = (unsigned long *)
53-
(((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE);
5443

55-
pr_info("Stack from %08lx:", (unsigned long)stack);
56-
p = stack;
57-
for (i = 0; i < kstack_depth_to_print; i++) {
58-
if (p + 1 > endstack)
59-
break;
60-
if (i % 8 == 0)
61-
pr_cont("\n ");
62-
pr_cont(" %08lx", *p++);
63-
}
64-
pr_cont("\n");
6544
show_trace(stack);
6645
}

‎arch/csky/kernel/ptrace.c‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ asmlinkage void syscall_trace(int why, struct pt_regs *regs)
241241
regs->regs[SYSTRACE_SAVENUM] = saved_why;
242242
}
243243

244+
extern void show_stack(struct task_struct *task, unsigned long *stack);
244245
void show_regs(struct pt_regs *fp)
245246
{
246247
unsigned long *sp;
@@ -263,35 +264,37 @@ void show_regs(struct pt_regs *fp)
263264
(int) (((unsigned long) current) + 2 * PAGE_SIZE));
264265
}
265266

266-
pr_info("PC: 0x%08lx\n", (long)fp->pc);
267+
pr_info("PC: 0x%08lx (%pS)\n", (long)fp->pc, (void *)fp->pc);
268+
pr_info("LR: 0x%08lx (%pS)\n", (long)fp->lr, (void *)fp->lr);
269+
pr_info("SP: 0x%08lx\n", (long)fp);
267270
pr_info("orig_a0: 0x%08lx\n", fp->orig_a0);
268271
pr_info("PSR: 0x%08lx\n", (long)fp->sr);
269272

270-
pr_info("a0: 0x%08lx a1: 0x%08lx a2: 0x%08lx a3: 0x%08lx\n",
271-
fp->a0, fp->a1, fp->a2, fp->a3);
273+
pr_info(" a0: 0x%08lx a1: 0x%08lx a2: 0x%08lx a3: 0x%08lx\n",
274+
fp->a0, fp->a1, fp->a2, fp->a3);
272275
#if defined(__CSKYABIV2__)
273-
pr_info("r4: 0x%08lx r5: 0x%08lx r6: 0x%08lx r7: 0x%08lx\n",
276+
pr_info(" r4: 0x%08lx r5: 0x%08lx r6: 0x%08lx r7: 0x%08lx\n",
274277
fp->regs[0], fp->regs[1], fp->regs[2], fp->regs[3]);
275-
pr_info("r8: 0x%08lx r9: 0x%08lx r10: 0x%08lx r11: 0x%08lx\n",
278+
pr_info(" r8: 0x%08lx r9: 0x%08lx r10: 0x%08lx r11: 0x%08lx\n",
276279
fp->regs[4], fp->regs[5], fp->regs[6], fp->regs[7]);
277-
pr_info("r12 0x%08lx r13: 0x%08lx r15: 0x%08lx\n",
280+
pr_info("r12: 0x%08lx r13: 0x%08lx r15: 0x%08lx\n",
278281
fp->regs[8], fp->regs[9], fp->lr);
279-
pr_info("r16:0x%08lx r17: 0x%08lx r18: 0x%08lx r19: 0x%08lx\n",
282+
pr_info("r16: 0x%08lx r17: 0x%08lx r18: 0x%08lx r19: 0x%08lx\n",
280283
fp->exregs[0], fp->exregs[1], fp->exregs[2], fp->exregs[3]);
281-
pr_info("r20 0x%08lx r21: 0x%08lx r22: 0x%08lx r23: 0x%08lx\n",
284+
pr_info("r20: 0x%08lx r21: 0x%08lx r22: 0x%08lx r23: 0x%08lx\n",
282285
fp->exregs[4], fp->exregs[5], fp->exregs[6], fp->exregs[7]);
283-
pr_info("r24 0x%08lx r25: 0x%08lx r26: 0x%08lx r27: 0x%08lx\n",
286+
pr_info("r24: 0x%08lx r25: 0x%08lx r26: 0x%08lx r27: 0x%08lx\n",
284287
fp->exregs[8], fp->exregs[9], fp->exregs[10], fp->exregs[11]);
285-
pr_info("r28 0x%08lx r29: 0x%08lx r30: 0x%08lx tls: 0x%08lx\n",
288+
pr_info("r28: 0x%08lx r29: 0x%08lx r30: 0x%08lx tls: 0x%08lx\n",
286289
fp->exregs[12], fp->exregs[13], fp->exregs[14], fp->tls);
287-
pr_info("hi 0x%08lx lo: 0x%08lx\n",
290+
pr_info(" hi: 0x%08lx lo: 0x%08lx\n",
288291
fp->rhi, fp->rlo);
289292
#else
290-
pr_info("r6: 0x%08lx r7: 0x%08lx r8: 0x%08lx r9: 0x%08lx\n",
293+
pr_info(" r6: 0x%08lx r7: 0x%08lx r8: 0x%08lx r9: 0x%08lx\n",
291294
fp->regs[0], fp->regs[1], fp->regs[2], fp->regs[3]);
292-
pr_info("r10: 0x%08lx r11: 0x%08lx r12: 0x%08lx r13: 0x%08lx\n",
295+
pr_info("r10: 0x%08lx r11: 0x%08lx r12: 0x%08lx r13: 0x%08lx\n",
293296
fp->regs[4], fp->regs[5], fp->regs[6], fp->regs[7]);
294-
pr_info("r14 0x%08lx r1: 0x%08lx r15: 0x%08lx\n",
297+
pr_info("r14: 0x%08lx r1: 0x%08lx r15: 0x%08lx\n",
295298
fp->regs[8], fp->regs[9], fp->lr);
296299
#endif
297300

@@ -313,4 +316,7 @@ void show_regs(struct pt_regs *fp)
313316
pr_cont("%08x ", (int) *sp++);
314317
}
315318
pr_cont("\n");
319+
320+
show_stack(NULL, (unsigned long *)fp->regs[4]);
321+
return;
316322
}

‎arch/csky/mm/fault.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
188188
* terminate things with extreme prejudice.
189189
*/
190190
bust_spinlocks(1);
191-
pr_alert("Unable to %s at vaddr: %08lx, epc: %08lx\n",
192-
__func__, address, regs->pc);
191+
pr_alert("Unable to handle kernel paging request at virtual "
192+
"address 0x%08lx, pc: 0x%08lx\n", address, regs->pc);
193193
die_if_kernel("Oops", regs, write);
194194

195195
out_of_memory:

0 commit comments

Comments
 (0)