Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1506837imu; Thu, 13 Dec 2018 16:59:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/WC0d8yPO8dB4fFC4B0BxEgoiw4zlcay0bn8xcDt2qHl2RBs7TsCMzHocLVl4XtD9K7lqMx X-Received: by 2002:a17:902:bd4a:: with SMTP id b10mr965536plx.232.1544749162439; Thu, 13 Dec 2018 16:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544749162; cv=none; d=google.com; s=arc-20160816; b=PrgIiKhVlk+x438HzjuHiUbG5/Y9vLMnUjt1hPoupRU6SkRV5bC0PF15eWww+i56FD dUgUErj9VL6TvKipptLuL6/PM9NmWJDU9QrIBINgAbl97uEiqMgPPDDX7qMBP0YMCSlN ianrFXIVqZHezv8dIuKgnrF7sOXdIi35rrSy2btysJat8g3zkIsS3Enw+1P7DSU8l8hA OxB9zSvqufliUVq/PTmI3KwbG5ADdWYpksfDbHp1gukrDjZS0C4rBiwNBbw1li+Njzh8 7z5WKfAzWLUbzyc+EnWhDdiU2cwFZWhUYB8o5R0Rg/5UGOaLuWuZ8q7moSBH/YMAJ6Ql AzsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=8liAxMrODt9BcVdkgo6WxTyrK93IQlturT+te81hFNk=; b=k/HYx9siZDPGz84jkkcIPq6mGPQR9Hhgn3ppQIcfLgeM/WZk56OkxCZ+HAw694jyp/ Ma97soYcizSWGeAmXJtQiRiOvTCtan6N/+ZdkrccBPsZVMBWw1oXQe+X2IQWobF6ao1t hiauzgR0Uuupwwuv+4jqG+2IKJ25EeoEix+Q/FXz/mtw+WL9odrihX9jX54l8Ns6Fu6/ aFJoyQQlubZurw1IHTTl40vC3HibWXihz58t8Xhx94zaRGs71H8nbnTeOO4ZQsfRmal3 asop2eBXLRb8Oj/SuGTHbmxtM9pjtmyTEtyoanAblX+aGnm3m6nF0gcLaRQN0B26QHi/ XXBA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si2706751pgh.533.2018.12.13.16.59.07; Thu, 13 Dec 2018 16:59:22 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728925AbeLNA53 (ORCPT + 99 others); Thu, 13 Dec 2018 19:57:29 -0500 Received: from ozlabs.org ([203.11.71.1]:48269 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726254AbeLNA53 (ORCPT ); Thu, 13 Dec 2018 19:57:29 -0500 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 43GBwQ2Q8Rz9s9G; Fri, 14 Dec 2018 11:57:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au From: Michael Ellerman To: Christophe Leroy , Benjamin Herrenschmidt , Paul Mackerras Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH] powerpc/mm: make NULL pointer deferences explicit on bad page faults. In-Reply-To: <42e7e2e9b74af526523fb5a1451fdb29cfe2687a.1539060806.git.christophe.leroy@c-s.fr> References: <42e7e2e9b74af526523fb5a1451fdb29cfe2687a.1539060806.git.christophe.leroy@c-s.fr> Date: Fri, 14 Dec 2018 11:57:26 +1100 Message-ID: <87zht9udqh.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Christophe, You know it's the trivial patches that are going to get lots of review comments :) Christophe Leroy writes: > As several other arches including x86, this patch makes it explicit > that a bad page fault is a NULL pointer dereference when the fault > address is lower than PAGE_SIZE I'm being pedantic, but it's not necessarily a NULL pointer dereference. It might just be a direct access to a low address, eg: char *p = 0x100; *p = 0; That's not a NULL pointer dereference. But other arches do print this so I guess it's OK to add, and in most cases it will be an actual NULL pointer dereference. I wonder though if we should use 4096 rather than PAGE_SIZE, given that's the actual value other arches are using. We support 256K pages on some systems, which is getting quite large. > diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c > index d51cf5f4e45e..501a1eadb3e9 100644 > --- a/arch/powerpc/mm/fault.c > +++ b/arch/powerpc/mm/fault.c > @@ -631,13 +631,16 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig) > switch (TRAP(regs)) { > case 0x300: > case 0x380: > - printk(KERN_ALERT "Unable to handle kernel paging request for " > - "data at address 0x%08lx\n", regs->dar); > + pr_alert("Unable to handle kernel %s for data at address 0x%08lx\n", > + regs->dar < PAGE_SIZE ? "NULL pointer dereference" : > + "paging request", > + regs->dar); This is now too long I think, with printk time you get: [ 1096.450711] Unable to handle kernel NULL pointer dereference for data at address 0x00000000 Which is 93 columns. It's true on many systems it doesn't really matter any more, but it would still be good if it was shorter. I like that on x86 they prefix it with "BUG:", just to avoid any confusion. What if we had for the NULL pointer case: BUG: Kernel NULL pointer dereference at 0x00000000 And for the normal case: BUG: Unable to handle kernel data access at 0x00000000 Note on the very next line we print: Faulting instruction address: 0xc000000000795cc8 So there should be no confusion about whether "at" refers to the data address or the instruction address. > case 0x400: > case 0x480: > - printk(KERN_ALERT "Unable to handle kernel paging request for " > - "instruction fetch\n"); > + pr_alert("Unable to handle kernel %s for instruction fetch\n", > + regs->nip < PAGE_SIZE ? "NULL pointer dereference" : > + "paging request"); I don't really like using "NULL pointer dereference" here, that terminology makes me think of a load/store, I think it confuses things rather than making it clearer. What about: BUG: Unable to handle kernel instruction fetch at 0x00000000 > break; > case 0x600: > printk(KERN_ALERT "Unable to handle kernel paging request for " It would be good to clean up these other cases as well. They seem to be trying to use the "page request for" terminology which leads to them being very wordy. I assume that was done to help people grepping kernel logs for errors, but I think we should not worry about that if we have the "BUG:" prefix. So we have: printk(KERN_ALERT "Unable to handle kernel paging request for " "unaligned access at address 0x%08lx\n", regs->dar); What about: BUG: Unable to handle kernel unaligned access at 0x00000000 And: printk(KERN_ALERT "Unable to handle kernel paging request for " "unknown fault\n"); What about: BUG: Unable to handle unknown paging fault at 0x00000000 Thoughts? cheers