Skip to content

Commit a2aa52a

Browse files
author
Ingo Molnar
committed
x86/fault: Clean up the page fault oops decoder a bit
- Make the oops messages a bit less scary (don't mention 'HW errors') - Turn 'PROT USER' (which is visually easily confused with PROT_USER) into individual bit descriptors: "[PROT] [USER]". This also makes "[normal kernel read fault]" more apparent. - De-abbreviate variables to make the code easier to read - Use vertical alignment where appropriate. - Add comment about string size limits and the helper function. - Remove unnecessary line breaks. Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@surriel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Yu-cheng Yu <yu-cheng.yu@intel.com> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent a1a371c commit a2aa52a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

arch/x86/mm/fault.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -603,21 +603,23 @@ static void show_ldttss(const struct desc_ptr *gdt, const char *name, u16 index)
603603
name, index, addr, (desc.limit0 | (desc.limit1 << 16)));
604604
}
605605

606-
static void errstr(unsigned long ec, char *buf, unsigned long mask,
607-
const char *txt)
606+
/*
607+
* This helper function transforms the #PF error_code bits into
608+
* "[PROT] [USER]" type of descriptive, almost human-readable error strings:
609+
*/
610+
static void err_str_append(unsigned long error_code, char *buf, unsigned long mask, const char *txt)
608611
{
609-
if (ec & mask) {
612+
if (error_code & mask) {
610613
if (buf[0])
611614
strcat(buf, " ");
612615
strcat(buf, txt);
613616
}
614617
}
615618

616619
static void
617-
show_fault_oops(struct pt_regs *regs, unsigned long error_code,
618-
unsigned long address)
620+
show_fault_oops(struct pt_regs *regs, unsigned long error_code, unsigned long address)
619621
{
620-
char errtxt[64];
622+
char err_txt[64];
621623

622624
if (!oops_may_print())
623625
return;
@@ -646,15 +648,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
646648
address < PAGE_SIZE ? "NULL pointer dereference" : "paging request",
647649
(void *)address);
648650

649-
errtxt[0] = 0;
650-
errstr(error_code, errtxt, X86_PF_PROT, "PROT");
651-
errstr(error_code, errtxt, X86_PF_WRITE, "WRITE");
652-
errstr(error_code, errtxt, X86_PF_USER, "USER");
653-
errstr(error_code, errtxt, X86_PF_RSVD, "RSVD");
654-
errstr(error_code, errtxt, X86_PF_INSTR, "INSTR");
655-
errstr(error_code, errtxt, X86_PF_PK, "PK");
656-
pr_alert("HW error: %s\n", error_code ? errtxt :
657-
"normal kernel read fault");
651+
err_txt[0] = 0;
652+
653+
/*
654+
* Note: length of these appended strings including the separation space and the
655+
* zero delimiter must fit into err_txt[].
656+
*/
657+
err_str_append(error_code, err_txt, X86_PF_PROT, "[PROT]" );
658+
err_str_append(error_code, err_txt, X86_PF_WRITE, "[WRITE]");
659+
err_str_append(error_code, err_txt, X86_PF_USER, "[USER]" );
660+
err_str_append(error_code, err_txt, X86_PF_RSVD, "[RSVD]" );
661+
err_str_append(error_code, err_txt, X86_PF_INSTR, "[INSTR]");
662+
err_str_append(error_code, err_txt, X86_PF_PK, "[PK]" );
663+
664+
pr_alert("#PF error: %s\n", error_code ? err_txt : "[normal kernel read fault]");
665+
658666
if (!(error_code & X86_PF_USER) && user_mode(regs)) {
659667
struct desc_ptr idt, gdt;
660668
u16 ldtr, tr;

0 commit comments

Comments
 (0)