Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8628977imu; Tue, 4 Dec 2018 11:24:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/VNF+MGv6HIHMj4jLXGNi6QuEszTsQ2jKB05z5tNsHIVQtEtJQn0DveiEmZQD1jyaaE7UHb X-Received: by 2002:a62:4255:: with SMTP id p82mr21032097pfa.13.1543951470447; Tue, 04 Dec 2018 11:24:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543951470; cv=none; d=google.com; s=arc-20160816; b=rirgnmHBYSXkl6AC6gFdEizQ6EtTWGZGmg4T01BXjrhzDw6GS69McG6YN0Fqauxcc4 KGjIgNV0BkVcB43uC2thKSD+Dl5LcyhAjSW0Y+z3LcaMb3UuBZ+E7MHldvQSRfoQz8Zf UlwFVaY4Kv+qfkFleCwhiSSxSwVFfVJ2Uho8EsaGPwr/QSX486YZPKzEgq02yauacnfA MKyYCj1lOshQBJpUYmdH0TRHZzWBuDD3vtfw6952z2iXO5jY5oki49E1nCnBVWSEU2uC wH48vKKCO3X33sRSoOCHx31NiIdroXJpoSZa9Xbt4us6syEGdPBL0VssyWWlVc5dPjXb GyrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=O5NtTSa7A2OPJ+mOhXzRT6tnkHu//IXm3ZrTXJT1yQw=; b=fh1DU8t2XcJH3G6Zukx04KaIWFcaPeZh6101qfSiC8dBgPUIX3VfX4Ezt2lCJV6UDH fd22zTLe9ylBC17qUDxBCCUMEqqcjpUxyKJWqqYUxcL3btArBS6wGJIu3n7BjC/+j3oJ tvsU/a6e4Ki0WtLZ2mOzcQctTpIO5sMP84FPJDvoOcefQZnBVQZ+pkHV429s7EE0ChM4 CJ28hyH2bCW3sLN3y2/tuZ6UZ6T/mdsGbuucfeF94kNfBFxH1v5E0LkEdgL35EoVO7/4 tie3DPSbI9L0acxDNQzuh1+g7ZmrVg+A/qT3hdF/6AXJ2rBZ6LgJl3JD5XEQtcxIL8z/ 1spA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aL5I9ftx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r14si17671119pfh.229.2018.12.04.11.24.15; Tue, 04 Dec 2018 11:24: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; dkim=pass header.i=@kernel.org header.s=default header.b=aL5I9ftx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726273AbeLDTWl (ORCPT + 99 others); Tue, 4 Dec 2018 14:22:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:37110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbeLDTWk (ORCPT ); Tue, 4 Dec 2018 14:22:40 -0500 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A3BB2087F for ; Tue, 4 Dec 2018 19:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543951359; bh=SfqPuQ4iYheesaOVi87RbOWTGb9cf9PC0ZMwuCJAggw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=aL5I9ftxeeRkL0lvCWuLTOCfShxR6wORpoeziaAMFObSQGN22w9/SLVZdjduCAA8U S0Arc+qOl/fIqjTHvciIbx0lF4D4o+m5ey1um4mAKXl6PZouwk6CyOt0p1w5qmekwg Uy2wDRvRlPw+v/VIX/6rk/XT9ek4bc6Jj2zxGHZE= Received: by mail-wr1-f42.google.com with SMTP id l9so17172139wrt.13 for ; Tue, 04 Dec 2018 11:22:39 -0800 (PST) X-Gm-Message-State: AA+aEWaPwYKNlXgzZAWJuVqhfE+RNgOR2HIfGc0+uQ8C7Hp9HsJ6N3tt RMoaiuPz1MBPpxBhSA8sAkcL83G2pGIxe13QEyT0EQ== X-Received: by 2002:adf:8323:: with SMTP id 32mr18446547wrd.176.1543951357608; Tue, 04 Dec 2018 11:22:37 -0800 (PST) MIME-Version: 1.0 References: <11212acb25980cd1b3030875cd9502414fbb214d.1542841400.git.luto@kernel.org> <20181122084119.GA44720@gmail.com> <20181127153202.GA27075@linux.intel.com> In-Reply-To: <20181127153202.GA27075@linux.intel.com> From: Andy Lutomirski Date: Tue, 4 Dec 2018 11:22:25 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 6/5] x86/fault: Clean up the page fault oops decoder a bit To: "Christopherson, Sean J" Cc: Ingo Molnar , Andrew Lutomirski , X86 ML , LKML , Yu-cheng Yu , Dave Hansen , Peter Zijlstra , Borislav Petkov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 27, 2018 at 7:32 AM Sean Christopherson wrote: > > On Thu, Nov 22, 2018 at 09:41:19AM +0100, Ingo Molnar wrote: > > > > * Andy Lutomirski wrote: > > > > > One of Linus' favorite hobbies seems to be looking at OOPSes and > > > decoding the error code in his head. This is not one of my favorite > > > hobbies :) > > > > > > Teach the page fault OOPS hander to decode the error code. If it's > > > a !USER fault from user mode, print an explicit note to that effect > > > and print out the addresses of various tables that might cause such > > > an error. > > > > > > With this patch applied, if I intentionally point the LDT at 0x0 and > > > run the x86 selftests, I get: > > > > > > BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 > > > HW error: normal kernel read fault > > > This was a system access from user code > > > IDT: 0xfffffe0000000000 (limit=0xfff) GDT: 0xfffffe0000001000 (limit=0x7f) > > > LDTR: 0x50 -- base=0x0 limit=0xfff7 > > > TR: 0x40 -- base=0xfffffe0000003000 limit=0x206f > > > PGD 800000000456e067 P4D 800000000456e067 PUD 4623067 PMD 0 > > > SMP PTI > > > CPU: 0 PID: 153 Comm: ldt_gdt_64 Not tainted 4.19.0+ #1317 > > > Hardware name: ... > > > RIP: 0033:0x401454 > > > > I've applied your series, with one small edit, the following message: > > > > > HW error: normal kernel read fault > > > > will IMHO confuse the heck out of users, thinking that their hardware is > > broken... > > > > Yes, the message is accurate, in MM pagefault language it's indeed the HW > > error code, but it's a language very few people speak. > > > > So I edited it over to say '#PF error code'. I also applied a few other > > minor cleanups - see the changelog below. > > I responded to the original thread a hair too late... > > What about something like this instead of manually handling the case > where error_code==0 so that we get e.g. "[KERNEL] [READ]" instead of > "normal kernel read fault"? Getting "[PROT] [KERNEL] [READ]" seems > useful. > > IMO "[normal kernel read fault]" followed by "This was a system access > from user code" is still confusing. > > --- > 8b29ee4351d5c625aa9ca2765f8da5e Mon Sep 17 00:00:00 2001 > From: Sean Christopherson > Date: Tue, 27 Nov 2018 07:09:57 -0800 > Subject: [PATCH] x86/fault: Print "KERNEL" and "READ" for #PF error codes > > ...and explicitly state that it's a "code" that's being printed. > > 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 | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index 2ff25ad33233..510e263c256b 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -660,8 +660,10 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code, unsigned long ad > 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]"); > + err_str_append(~error_code, err_txt, X86_PF_USER, "[KERNEL]"); > + err_str_append(~error_code, err_txt, X86_PF_WRITE | X86_PF_INSTR, > + "[READ]"); > + pr_alert("#PF error code: %s\n", err_txt); > Seems generally nice, but I would suggest making the bit-not-set name be another parameter to err_str_append(). I'm also slightly uneasy about making "KERNEL" look like a bit, but I guess it doesn't bother me too much. Want to send a real patch?