Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9857954imu; Wed, 5 Dec 2018 11:28:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/W8VDfd8j2lTL8E//NixOCZXq5zNk/Kk6BNunG1PeO254sH/IykzVthol88ZF+b3x5YgqV2 X-Received: by 2002:a63:88c7:: with SMTP id l190mr21103395pgd.110.1544038107555; Wed, 05 Dec 2018 11:28:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544038107; cv=none; d=google.com; s=arc-20160816; b=QBSCK8efaR0ZUzNAwuLe5RzKtkYxmDbmC+2P2CBSYzPcTA05ZennnRkkLWRCTbnRG1 e8BcCaROUP2zauCaIopN8G3xNIZKzvX8v5cm32tstGyhYP3sB50QscHOx1K7Rx+aKiYW Ingih0Ei9UyaK/keXN+/3+UlZBQiHhDGjsQtLce/zgdQdhRauJH7Kh6YUms9qKevfrWS JzUoCW9LR1USe72yRTbokcD9vZrmvHRQepn53+UgInZbSoYAYs5jTudA3CHWCxCKkzv3 AfFPaEZxOGhx6hNZ5BgbrQKRbkuvtWpNxZYSCYl7Zp68zySHL0x5fC109Dcd4OUx5c/n Vyhw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=LFJn1UEgu7qruDBYY7f07dl0/ndfGC7Ev9Idmq2934Q=; b=QwlJuqyKsAUajtGA7V4SYACGSyLA0JTxFLAqwhqlUCOn61ciYO4XbCyHBsLe95cokC fneig5oCGvzluJWlxxajmarVuqAP/x3u6IQi7NxrILhKNcdyLGzKaz9p2RQbXCm+VdGT Qd5hEHMbHnqoUPNXLd7lt6No4IaCxgpF2LI0q4EpK1Vsm9qDGoINR6kUDrZBTbVHOHfb T84tHv57Li4JLIaRQFyT2n6NNR2Orp/w5QXdqTAV+qZK8Zy5sJwGhkM2pdXVjPKtTc5K CRAn4OTP4mE+ZrpooxTIlr919JT/3z6Z0tccXX3JO4ikAxyEeZ/vQVIXCyUvoK8OZ2PW rj9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=QHCI2yVL; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w75si21210655pfd.55.2018.12.05.11.28.11; Wed, 05 Dec 2018 11:28:27 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=QHCI2yVL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727679AbeLET1e (ORCPT + 99 others); Wed, 5 Dec 2018 14:27:34 -0500 Received: from merlin.infradead.org ([205.233.59.134]:41830 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbeLET1d (ORCPT ); Wed, 5 Dec 2018 14:27:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LFJn1UEgu7qruDBYY7f07dl0/ndfGC7Ev9Idmq2934Q=; b=QHCI2yVL9fFKnAMHLbLj5pD1N4 tX6wczw5yScz1gDbv2JjSABo0hoyabsgZWxemz4dm5NF+nVjS3x4Kc5DPi7sNHPpejBYtCfRyK1xx 0Dxzi1SXKhcroOuAnEvbnL28jG1zFOBJBqJ94mraeuAETFk8moDaGWEpXrZE0DiMGzBjDnz8Af6Th Y7VYlT5OK3yW+onb7MZMlTwLCESeCwqjBpEFDQPJUW4Q8lV5CXNxu2+pkCEODP9SvQs5y2htkCPUD wlfvYtS03tlANQxGg8SJ2aSsMCQz4JhKlhje3sF1KXKkuMtlEJZrZ5GxMi5S3oCU64Z//TiYU3JLg 3LmmZu8g==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUcpH-0007eE-Tk; Wed, 05 Dec 2018 19:27:16 +0000 Subject: Re: [PATCH] x86/fault: Print "SUPERVISOR" and "READ" when decoding #PF oops To: Sean Christopherson , 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 References: <20181205163624.1842-1-sean.j.christopherson@intel.com> From: Randy Dunlap Message-ID: Date: Wed, 5 Dec 2018 11:27:13 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <20181205163624.1842-1-sean.j.christopherson@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/5/18 8:36 AM, Sean Christopherson wrote: > ...instead of manually handling the case where error_code=0, e.g. to > display "[SUPERVISOR] [READ]" instead of "normal kernel read fault". > > This makes the zero case consistent with all other messages and also > provides additional information for other error code combinations, > e.g. error_code==1 will display "[PROT] [SUPERVISOR] [READ]" instead > of simply "[PROT]". > > Print unique names for the negative cases as opposed to e.g. "[!USER]" > to avoid mixups due to users missing a single "!" character, and to be > more concise for the !INSTR && !WRITE case. > > Print "SUPERVISOR" in favor of "KERNEL" to reduce the likelihood that > the message is misinterpreted as a generic kernel/software error and > to be consistent with the SDM's nomenclature. > > An alternative to passing a negated error code to err_str_append() would > be to expand err_str_append() to take a second string for the negative > test, but that approach complicates handling the "[READ]" case, which > looks for !INSTR && !WRITE, e.g. it would require an extra call to > err_str_append() and logic in err_str_append() to allow null messages > for both the positive and negative tests. Printing "[INSTR] [READ]" > wouldn't be the end of the world, but a little bit of trickery in the > kernel is a relatively small price to pay in exchange for the ability > to unequivocally know the access type by reading a single word. > > Now that all components of the message use the [] format, > explicitly state that it's the error *code* that's being printed and > group the err_str_append() calls by type so that the resulting print > messages are consistent, e.g. the deciphered codes will always be: > > [PROT] [USER|SUPERVISOR] [WRITE|INSTR|READ] [RSDV] [PK] RSVD but it's correct in the patch. BTW, what does PK mean? thanks. > > 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 | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index 2ff25ad33233..0b4ce5d2b461 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -609,7 +609,7 @@ static void show_ldttss(const struct desc_ptr *gdt, const char *name, u16 index) > */ > static void err_str_append(unsigned long error_code, char *buf, unsigned long mask, const char *txt) > { > - if (error_code & mask) { > + if ((error_code & mask) == mask) { > if (buf[0]) > strcat(buf, " "); > strcat(buf, txt); > @@ -655,13 +655,16 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code, unsigned long ad > * 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_USER, "[SUPERVISOR]"); > + err_str_append(error_code, err_txt, X86_PF_WRITE, "[WRITE]"); > err_str_append(error_code, err_txt, X86_PF_INSTR, "[INSTR]"); > + err_str_append(~error_code, err_txt, X86_PF_WRITE | X86_PF_INSTR, > + "[READ]"); > + err_str_append(error_code, err_txt, X86_PF_RSVD, "[RSVD]" ); > 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: %s\n", err_txt); > > if (!(error_code & X86_PF_USER) && user_mode(regs)) { > struct desc_ptr idt, gdt; > -- ~Randy