Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp908411imu; Fri, 7 Dec 2018 10:46:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/WigiMRKKYsnW6cGqC/pgt1T7b+shOpc8MxYdGpTkO/0HbP69mHU2MTt5F1hzTKJvCbLMmT X-Received: by 2002:a62:184e:: with SMTP id 75mr3285168pfy.28.1544208390232; Fri, 07 Dec 2018 10:46:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544208390; cv=none; d=google.com; s=arc-20160816; b=oiIjj0hBkl5OHSXdqscejIt71anG4AgEKAUoz0LrNH6b5rEhTSDIKIsD8H6urSlPgB A4tRynEJNTDoNbGtZCKhxiHYdNXMSRckUGlUZwvDnQbq25XUkCwOc6iTvBGkPhGyVpgr l5lb6pPsPi+zmG6iMlfYVBCbNUnDsKHxCHRjOQIzG5fyi3lJcEvW8QcTvYpN+7boHG2F qLOZ9sDG58SHC5LhEhg/GBM0UzcRH2atyDmGF6PbZCU5d9OsFBElTLsf0KGx5g4hkiDc Gda/Qf6KaO5l6+s4QZyQhm4Kx4HLFF7XotggBV3Lb3ncHRNmhEmddre/nBKJUIgf3nSm NhRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=kw+oxDIkjjvvlwq7OudPCGGou0G7xlLPtyDUGeQzlKU=; b=dnx5MEawq2X3zw5XKmlmV/o9CgOhT/zGFifaQt42xIXpL/ywdhhWUbkPSIHXKAIQ8S Cck5GkCRMtvxoWvIDSo2Y5jzBEoYF9t5GA5Ai63CLGEY8XPDTB7mpH0YtDWOCZDfwQTh Vx9CxuL7fUmSzw7o4hH9mNuqC3wFmFH7ezwRzOMKnk7rJFafCnzXrH2q4xyW3cHzRD0O 5DMF9iJIX1ESRWJI9DWIOMK6ObG5rjvirndvG0fa7dRjlyfPpb+XbCzwqLtTiOh6o3uB ZN2lP/wXDztIFovccyJZfHYsX5c0P7E+M5uteX4fmsF9QqVZ2v2hVCRmnkvwvjf3jgiU 4rAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69si3485914pgd.290.2018.12.07.10.46.15; Fri, 07 Dec 2018 10:46:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726172AbeLGSoc (ORCPT + 99 others); Fri, 7 Dec 2018 13:44:32 -0500 Received: from mga18.intel.com ([134.134.136.126]:4013 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbeLGSob (ORCPT ); Fri, 7 Dec 2018 13:44:31 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Dec 2018 10:44:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,327,1539673200"; d="scan'208";a="107838178" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.154]) by fmsmga008.fm.intel.com with ESMTP; 07 Dec 2018 10:44:30 -0800 From: Sean Christopherson To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, Linus Torvalds , Rik van Riel , Yu-cheng Yu , Ingo Molnar Subject: [PATCH] x86/fault: Decode and print #PF oops in human readable form Date: Fri, 7 Dec 2018 10:44:23 -0800 Message-Id: <20181207184423.1962-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Linus pointed out[1] that deciphering the raw #PF error code and printing a more human readable message are two different things, e.g. not-executable, not-writable, protection keys and even SGX faults are all some form of permission violation faults, and a #PF with the USER bit cleared in the error code does not indicate that the fault originated in kernel code. Remove the per-bit decoding of the error code and instead print the raw error code followed by a brief description of what caused the fault, the effective privilege level of the faulting access, and whether the fault originated in user code or kernel code. This provides the user with the information needed to do basic triage on 99.9% oopses without polluting the message with information that is useless the vast majority of the time, e.g. an oops on a protection keys violation is beyond rare, stating that an oops *wasn't* due to a keys violation is pointless noise. [1] https://lkml.kernel.org/r/CAHk-=whk_fsnxVMvF1T2fFCaP2WrvSybABrLQCWLJyCvHw6NKA@mail.gmail.com Suggested-by: Linus Torvalds Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rik van Riel Cc: Thomas Gleixner Cc: Yu-cheng Yu Cc: linux-kernel@vger.kernel.org Cc: Ingo Molnar Signed-off-by: Sean Christopherson --- arch/x86/mm/fault.c | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 2ff25ad33233..85de05d41f58 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -603,24 +603,9 @@ static void show_ldttss(const struct desc_ptr *gdt, const char *name, u16 index) name, index, addr, (desc.limit0 | (desc.limit1 << 16))); } -/* - * This helper function transforms the #PF error_code bits into - * "[PROT] [USER]" type of descriptive, almost human-readable error strings: - */ -static void err_str_append(unsigned long error_code, char *buf, unsigned long mask, const char *txt) -{ - if (error_code & mask) { - if (buf[0]) - strcat(buf, " "); - strcat(buf, txt); - } -} - static void show_fault_oops(struct pt_regs *regs, unsigned long error_code, unsigned long address) { - char err_txt[64]; - if (!oops_may_print()) return; @@ -648,27 +633,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code, unsigned long ad address < PAGE_SIZE ? "NULL pointer dereference" : "paging request", (void *)address); - err_txt[0] = 0; - - /* - * Note: length of these appended strings including the separation space and the - * zero delimiter must fit into err_txt[]. - */ - err_str_append(error_code, err_txt, X86_PF_PROT, "[PROT]" ); - err_str_append(error_code, err_txt, X86_PF_WRITE, "[WRITE]"); - err_str_append(error_code, err_txt, X86_PF_USER, "[USER]" ); - err_str_append(error_code, err_txt, X86_PF_RSVD, "[RSVD]" ); - err_str_append(error_code, err_txt, X86_PF_INSTR, "[INSTR]"); - err_str_append(error_code, err_txt, X86_PF_PK, "[PK]" ); - - pr_alert("#PF error: %s\n", error_code ? err_txt : "[normal kernel read fault]"); + pr_alert("#PF: error_code(0x%04lx) - %s\n", error_code, + !(error_code & X86_PF_PROT) ? "not-present page" : + (error_code & X86_PF_RSVD) ? "reserved bit violation" : + "permissions violation"); + pr_alert("#PF: %s-privileged %s from %s code\n", + (error_code & X86_PF_USER) ? "user" : "supervisor", + (error_code & X86_PF_INSTR) ? "instruction fetch" : + (error_code & X86_PF_WRITE) ? "write access" : + "read access", + user_mode(regs) ? "user" : "kernel"); if (!(error_code & X86_PF_USER) && user_mode(regs)) { struct desc_ptr idt, gdt; u16 ldtr, tr; - pr_alert("This was a system access from user code\n"); - /* * This can happen for quite a few reasons. The more obvious * ones are faults accessing the GDT, or LDT. Perhaps -- 2.19.2