Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9600587imu; Wed, 5 Dec 2018 07:24:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/XpdhPGvLu2n+AZXEdzq+W3a1ck6r6ujZjWsiyk0BcLPpBKqhrUXqbHoFJ2x96veNHSk9P3 X-Received: by 2002:a63:cc12:: with SMTP id x18mr20662865pgf.33.1544023480693; Wed, 05 Dec 2018 07:24:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544023480; cv=none; d=google.com; s=arc-20160816; b=rhaAMKh9ReUf18lfKp5RnYcJvkttX/I4lKWBHCLsTVL8ySWNDBaHVgNTnmbOLy8o9O tMFmHxYhWLpnz+T29C/YYuVwiPNF8XB0GydFYDNK5ceeBMRIbChMosEWrqeJy3ceUGBb alFoLXEc/FYL/znxwFwIBMltCx2TOYye7gzaVlFybGQFRKe5T+ak/gobNPYmij/VPlre 152LX7zgqsTkx0PwtVwdTTlXiPny3hYbxR8d7IqKsvhm6mNGpNkeiGpWO2SSpUHOu8W6 xPXIjWOtl7+w66AhOygCeCeIIG0JptA5OHQsxwrtUeXpiwpSwJ/9IReJbr3t1SvMrarM 0Elw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0Xk49H8RQGvzaxPsTG/8/9eyjFPxzCm0mq1+YeOQyH0=; b=Q/kE96CfoREA/xSxdE64c0xeTfGY1f1TwqFwQJBgPWUkjiUlVDl1kXI+Shwj8P3/KW FuiDdTk7LN9NpXf0d05AmZPf3dtZBhCUwFv4PKwxWBlWPxVw2ObgrAzhnMvIqMKw1W81 z+3629dNCeJfzJCH7v/1rtMUms2Sb/160NxkLZgjUx9yCSWcKlt0CP8lvEriA6SnJqrd Gq4ODTDispexOaqVdL3IazMpG8a2Txtj2OYtHR706NaHkABoM1jFyFFYv27uqhvqpgMs uT1MHQ+AOD4iDjl2fbWV9bGpv5+XralyBci0rNb9uvR1fqyUJSlRpb1m734jRhYPN6FG vAXQ== 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 t12si19570068plq.190.2018.12.05.07.24.22; Wed, 05 Dec 2018 07:24:40 -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 S1727916AbeLEPXi (ORCPT + 99 others); Wed, 5 Dec 2018 10:23:38 -0500 Received: from mga05.intel.com ([192.55.52.43]:57635 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbeLEPXh (ORCPT ); Wed, 5 Dec 2018 10:23:37 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2018 07:23:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,317,1539673200"; d="scan'208";a="115877161" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.154]) by orsmga002.jf.intel.com with ESMTP; 05 Dec 2018 07:23:36 -0800 Date: Wed, 5 Dec 2018 07:23:36 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: Ingo Molnar , X86 ML , LKML , Yu-cheng Yu , Dave Hansen , Peter Zijlstra , Borislav Petkov Subject: Re: [PATCH 6/5] x86/fault: Clean up the page fault oops decoder a bit Message-ID: <20181205152336.GA31197@linux.intel.com> References: <11212acb25980cd1b3030875cd9502414fbb214d.1542841400.git.luto@kernel.org> <20181122084119.GA44720@gmail.com> <20181127153202.GA27075@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 04, 2018 at 11:22:25AM -0800, Andy Lutomirski wrote: > On Tue, Nov 27, 2018 at 7:32 AM Sean Christopherson > wrote: > > 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 didn't recall why I chose to negate error_code until I revisited the actual code. The "READ" case is a combination of !WRITE && !USER, i.e. doesn't fit into an existing err_str_append() call. So we'd end up with an extra err_str_append() call that would also have a null message for the positive test, which seemed unnecessarily complex and more convoluted than simply negating error_code. E.g.: diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 2ff25ad33233..48b420621825 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -607,12 +607,17 @@ static void show_ldttss(const struct desc_ptr *gdt, const char *name, u16 index) * 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) +static void err_str_append(unsigned long error_code, char *buf, unsigned long mask, + const char *pos, const char *neg) { - if (error_code & mask) { + if ((error_code & mask) == mask && pos) { if (buf[0]) strcat(buf, " "); - strcat(buf, txt); + strcat(buf, pos); + } else if (!(error_code & mask) && neg) { + if (buf[0]) + strcat(buf, " "); + strcat(buf, neg); } } @@ -654,14 +659,15 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code, unsigned long ad * 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]"); + err_str_append(error_code, err_txt, X86_PF_PROT, "[PROT]" , NULL); + err_str_append(error_code, err_txt, X86_PF_WRITE, "[WRITE]", NULL); + err_str_append(error_code, err_txt, X86_PF_USER, "[USER]" , "[SUPERVISOR]"); + err_str_append(error_code, err_txt, X86_PF_RSVD, "[RSVD]" , NULL); + err_str_append(error_code, err_txt, X86_PF_INSTR, "[INSTR]", NULL); + err_str_append(error_code, err_txt, X86_PF_PK, "[PK]" , NULL); + err_str_append(error_code, err_txt, X86_PF_WRITE | X86_PF_INSTR, NULL, + "[READ]"); + pr_alert("#PF error code: %s\n", err_txt); if (!(error_code & X86_PF_USER) && user_mode(regs)) { struct desc_ptr idt, gdt;