Skip to content

Commit 4ee4810

Browse files
committed
Merge tag 'x86-core-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 debug fixlets from Ingo Molnar: "Improve x86 debuggability: print registers with the same log level as the backtrace" * tag 'x86-core-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/dumpstack: Show registers dump with trace's log level x86/dumpstack: Add log_lvl to __show_regs() x86/dumpstack: Add log_lvl to show_iret_regs()
2 parents 37e8822 + ef2ff0f commit 4ee4810

File tree

4 files changed

+57
-51
lines changed

4 files changed

+57
-51
lines changed

arch/x86/include/asm/kdebug.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ extern void die(const char *, struct pt_regs *,long);
3636
void die_addr(const char *str, struct pt_regs *regs, long err, long gp_addr);
3737
extern int __must_check __die(const char *, struct pt_regs *, long);
3838
extern void show_stack_regs(struct pt_regs *regs);
39-
extern void __show_regs(struct pt_regs *regs, enum show_regs_mode);
40-
extern void show_iret_regs(struct pt_regs *regs);
39+
extern void __show_regs(struct pt_regs *regs, enum show_regs_mode,
40+
const char *log_lvl);
41+
extern void show_iret_regs(struct pt_regs *regs, const char *log_lvl);
4142
extern unsigned long oops_begin(void);
4243
extern void oops_end(unsigned long, struct pt_regs *, int signr);
4344

arch/x86/kernel/dumpstack.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ void show_ip(struct pt_regs *regs, const char *loglvl)
133133
show_opcodes(regs, loglvl);
134134
}
135135

136-
void show_iret_regs(struct pt_regs *regs)
136+
void show_iret_regs(struct pt_regs *regs, const char *log_lvl)
137137
{
138-
show_ip(regs, KERN_DEFAULT);
139-
printk(KERN_DEFAULT "RSP: %04x:%016lx EFLAGS: %08lx", (int)regs->ss,
138+
show_ip(regs, log_lvl);
139+
printk("%sRSP: %04x:%016lx EFLAGS: %08lx", log_lvl, (int)regs->ss,
140140
regs->sp, regs->flags);
141141
}
142142

143143
static void show_regs_if_on_stack(struct stack_info *info, struct pt_regs *regs,
144-
bool partial)
144+
bool partial, const char *log_lvl)
145145
{
146146
/*
147147
* These on_stack() checks aren't strictly necessary: the unwind code
@@ -153,7 +153,7 @@ static void show_regs_if_on_stack(struct stack_info *info, struct pt_regs *regs,
153153
* they can be printed in the right context.
154154
*/
155155
if (!partial && on_stack(info, regs, sizeof(*regs))) {
156-
__show_regs(regs, SHOW_REGS_SHORT);
156+
__show_regs(regs, SHOW_REGS_SHORT, log_lvl);
157157

158158
} else if (partial && on_stack(info, (void *)regs + IRET_FRAME_OFFSET,
159159
IRET_FRAME_SIZE)) {
@@ -162,7 +162,7 @@ static void show_regs_if_on_stack(struct stack_info *info, struct pt_regs *regs,
162162
* full pt_regs might not have been saved yet. In that case
163163
* just print the iret frame.
164164
*/
165-
show_iret_regs(regs);
165+
show_iret_regs(regs, log_lvl);
166166
}
167167
}
168168

@@ -217,7 +217,7 @@ void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
217217
printk("%s <%s>\n", log_lvl, stack_name);
218218

219219
if (regs)
220-
show_regs_if_on_stack(&stack_info, regs, partial);
220+
show_regs_if_on_stack(&stack_info, regs, partial, log_lvl);
221221

222222
/*
223223
* Scan the stack, printing any text addresses we find. At the
@@ -278,7 +278,7 @@ void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
278278
/* if the frame has entry regs, print them */
279279
regs = unwind_get_entry_regs(&state, &partial);
280280
if (regs)
281-
show_regs_if_on_stack(&stack_info, regs, partial);
281+
show_regs_if_on_stack(&stack_info, regs, partial, log_lvl);
282282
}
283283

284284
if (stack_name)
@@ -352,7 +352,7 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
352352
oops_exit();
353353

354354
/* Executive summary in case the oops scrolled away */
355-
__show_regs(&exec_summary_regs, SHOW_REGS_ALL);
355+
__show_regs(&exec_summary_regs, SHOW_REGS_ALL, KERN_DEFAULT);
356356

357357
if (!signr)
358358
return;
@@ -444,9 +444,12 @@ void die_addr(const char *str, struct pt_regs *regs, long err, long gp_addr)
444444

445445
void show_regs(struct pt_regs *regs)
446446
{
447+
enum show_regs_mode print_kernel_regs;
448+
447449
show_regs_print_info(KERN_DEFAULT);
448450

449-
__show_regs(regs, user_mode(regs) ? SHOW_REGS_USER : SHOW_REGS_ALL);
451+
print_kernel_regs = user_mode(regs) ? SHOW_REGS_USER : SHOW_REGS_ALL;
452+
__show_regs(regs, print_kernel_regs, KERN_DEFAULT);
450453

451454
/*
452455
* When in-kernel, we also print out the stack at the time of the fault..

arch/x86/kernel/process_32.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656

5757
#include "process.h"
5858

59-
void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
59+
void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
60+
const char *log_lvl)
6061
{
6162
unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
6263
unsigned long d0, d1, d2, d3, d6, d7;
@@ -67,14 +68,14 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
6768
else
6869
savesegment(gs, gs);
6970

70-
show_ip(regs, KERN_DEFAULT);
71+
show_ip(regs, log_lvl);
7172

72-
printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
73-
regs->ax, regs->bx, regs->cx, regs->dx);
74-
printk(KERN_DEFAULT "ESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n",
75-
regs->si, regs->di, regs->bp, regs->sp);
76-
printk(KERN_DEFAULT "DS: %04x ES: %04x FS: %04x GS: %04x SS: %04x EFLAGS: %08lx\n",
77-
(u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, regs->ss, regs->flags);
73+
printk("%sEAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
74+
log_lvl, regs->ax, regs->bx, regs->cx, regs->dx);
75+
printk("%sESI: %08lx EDI: %08lx EBP: %08lx ESP: %08lx\n",
76+
log_lvl, regs->si, regs->di, regs->bp, regs->sp);
77+
printk("%sDS: %04x ES: %04x FS: %04x GS: %04x SS: %04x EFLAGS: %08lx\n",
78+
log_lvl, (u16)regs->ds, (u16)regs->es, (u16)regs->fs, gs, regs->ss, regs->flags);
7879

7980
if (mode != SHOW_REGS_ALL)
8081
return;
@@ -83,8 +84,8 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
8384
cr2 = read_cr2();
8485
cr3 = __read_cr3();
8586
cr4 = __read_cr4();
86-
printk(KERN_DEFAULT "CR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n",
87-
cr0, cr2, cr3, cr4);
87+
printk("%sCR0: %08lx CR2: %08lx CR3: %08lx CR4: %08lx\n",
88+
log_lvl, cr0, cr2, cr3, cr4);
8889

8990
get_debugreg(d0, 0);
9091
get_debugreg(d1, 1);
@@ -98,10 +99,10 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
9899
(d6 == DR6_RESERVED) && (d7 == 0x400))
99100
return;
100101

101-
printk(KERN_DEFAULT "DR0: %08lx DR1: %08lx DR2: %08lx DR3: %08lx\n",
102-
d0, d1, d2, d3);
103-
printk(KERN_DEFAULT "DR6: %08lx DR7: %08lx\n",
104-
d6, d7);
102+
printk("%sDR0: %08lx DR1: %08lx DR2: %08lx DR3: %08lx\n",
103+
log_lvl, d0, d1, d2, d3);
104+
printk("%sDR6: %08lx DR7: %08lx\n",
105+
log_lvl, d6, d7);
105106
}
106107

107108
void release_thread(struct task_struct *dead_task)

arch/x86/kernel/process_64.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,40 @@
6262
#include "process.h"
6363

6464
/* Prints also some state that isn't saved in the pt_regs */
65-
void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
65+
void __show_regs(struct pt_regs *regs, enum show_regs_mode mode,
66+
const char *log_lvl)
6667
{
6768
unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L, fs, gs, shadowgs;
6869
unsigned long d0, d1, d2, d3, d6, d7;
6970
unsigned int fsindex, gsindex;
7071
unsigned int ds, es;
7172

72-
show_iret_regs(regs);
73+
show_iret_regs(regs, log_lvl);
7374

7475
if (regs->orig_ax != -1)
7576
pr_cont(" ORIG_RAX: %016lx\n", regs->orig_ax);
7677
else
7778
pr_cont("\n");
7879

79-
printk(KERN_DEFAULT "RAX: %016lx RBX: %016lx RCX: %016lx\n",
80-
regs->ax, regs->bx, regs->cx);
81-
printk(KERN_DEFAULT "RDX: %016lx RSI: %016lx RDI: %016lx\n",
82-
regs->dx, regs->si, regs->di);
83-
printk(KERN_DEFAULT "RBP: %016lx R08: %016lx R09: %016lx\n",
84-
regs->bp, regs->r8, regs->r9);
85-
printk(KERN_DEFAULT "R10: %016lx R11: %016lx R12: %016lx\n",
86-
regs->r10, regs->r11, regs->r12);
87-
printk(KERN_DEFAULT "R13: %016lx R14: %016lx R15: %016lx\n",
88-
regs->r13, regs->r14, regs->r15);
80+
printk("%sRAX: %016lx RBX: %016lx RCX: %016lx\n",
81+
log_lvl, regs->ax, regs->bx, regs->cx);
82+
printk("%sRDX: %016lx RSI: %016lx RDI: %016lx\n",
83+
log_lvl, regs->dx, regs->si, regs->di);
84+
printk("%sRBP: %016lx R08: %016lx R09: %016lx\n",
85+
log_lvl, regs->bp, regs->r8, regs->r9);
86+
printk("%sR10: %016lx R11: %016lx R12: %016lx\n",
87+
log_lvl, regs->r10, regs->r11, regs->r12);
88+
printk("%sR13: %016lx R14: %016lx R15: %016lx\n",
89+
log_lvl, regs->r13, regs->r14, regs->r15);
8990

9091
if (mode == SHOW_REGS_SHORT)
9192
return;
9293

9394
if (mode == SHOW_REGS_USER) {
9495
rdmsrl(MSR_FS_BASE, fs);
9596
rdmsrl(MSR_KERNEL_GS_BASE, shadowgs);
96-
printk(KERN_DEFAULT "FS: %016lx GS: %016lx\n",
97-
fs, shadowgs);
97+
printk("%sFS: %016lx GS: %016lx\n",
98+
log_lvl, fs, shadowgs);
9899
return;
99100
}
100101

@@ -112,12 +113,12 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
112113
cr3 = __read_cr3();
113114
cr4 = __read_cr4();
114115

115-
printk(KERN_DEFAULT "FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
116-
fs, fsindex, gs, gsindex, shadowgs);
117-
printk(KERN_DEFAULT "CS: %04lx DS: %04x ES: %04x CR0: %016lx\n", regs->cs, ds,
118-
es, cr0);
119-
printk(KERN_DEFAULT "CR2: %016lx CR3: %016lx CR4: %016lx\n", cr2, cr3,
120-
cr4);
116+
printk("%sFS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n",
117+
log_lvl, fs, fsindex, gs, gsindex, shadowgs);
118+
printk("%sCS: %04lx DS: %04x ES: %04x CR0: %016lx\n",
119+
log_lvl, regs->cs, ds, es, cr0);
120+
printk("%sCR2: %016lx CR3: %016lx CR4: %016lx\n",
121+
log_lvl, cr2, cr3, cr4);
121122

122123
get_debugreg(d0, 0);
123124
get_debugreg(d1, 1);
@@ -129,14 +130,14 @@ void __show_regs(struct pt_regs *regs, enum show_regs_mode mode)
129130
/* Only print out debug registers if they are in their non-default state. */
130131
if (!((d0 == 0) && (d1 == 0) && (d2 == 0) && (d3 == 0) &&
131132
(d6 == DR6_RESERVED) && (d7 == 0x400))) {
132-
printk(KERN_DEFAULT "DR0: %016lx DR1: %016lx DR2: %016lx\n",
133-
d0, d1, d2);
134-
printk(KERN_DEFAULT "DR3: %016lx DR6: %016lx DR7: %016lx\n",
135-
d3, d6, d7);
133+
printk("%sDR0: %016lx DR1: %016lx DR2: %016lx\n",
134+
log_lvl, d0, d1, d2);
135+
printk("%sDR3: %016lx DR6: %016lx DR7: %016lx\n",
136+
log_lvl, d3, d6, d7);
136137
}
137138

138139
if (boot_cpu_has(X86_FEATURE_OSPKE))
139-
printk(KERN_DEFAULT "PKRU: %08x\n", read_pkru());
140+
printk("%sPKRU: %08x\n", log_lvl, read_pkru());
140141
}
141142

142143
void release_thread(struct task_struct *dead_task)

0 commit comments

Comments
 (0)