From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932837AbdBQLAq (ORCPT ); Fri, 17 Feb 2017 06:00:46 -0500 Received: from foss.arm.com ([217.140.101.70]:52822 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752574AbdBQLAp (ORCPT ); Fri, 17 Feb 2017 06:00:45 -0500 Message-ID: <58A6D7D7.1030704@arm.com> Date: Fri, 17 Feb 2017 11:00:39 +0000 From: James Morse User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.6.0 MIME-Version: 1.0 To: Stephen Boyd CC: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Laura Abbott , Mark Rutland Subject: Re: [PATCH v2] arm64: print a fault message when attempting to write RO memory References: <20170217011959.26754-1-stephen.boyd@linaro.org> In-Reply-To: <20170217011959.26754-1-stephen.boyd@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Stephen, On 17/02/17 01:19, Stephen Boyd wrote: > If a page is marked read only we should print out that fact, > instead of printing out that there was a page fault. Right now we > get a cryptic error message that something went wrong with an > unhandled fault, but we don't evaluate the esr to figure out that > it was a read/write permission fault. > > Instead of seeing: > > Unable to handle kernel paging request at virtual address ffff000008e460d8 > pgd = ffff800003504000 > [ffff000008e460d8] *pgd=0000000083473003, *pud=0000000083503003, *pmd=0000000000000000 > Internal error: Oops: 9600004f [#1] PREEMPT SMP > > we'll see: > > Unable to handle kernel write to read-only memory at virtual address ffff000008e760d8 > pgd = ffff80003d3de000 > [ffff000008e760d8] *pgd=0000000083472003, *pud=0000000083435003, *pmd=0000000000000000 > Internal error: Oops: 9600004f [#1] PREEMPT SMP This looks like a good idea.. > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > index 156169c6981b..8bd4e7f11c70 100644 > --- a/arch/arm64/mm/fault.c > +++ b/arch/arm64/mm/fault.c > /* > * The kernel tried to access some page that wasn't present. > */ > static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr, > unsigned int esr, struct pt_regs *regs) > { > + const char *msg; > /* > * Are we prepared to handle this kernel fault? > * We are almost certainly not prepared to handle instruction faults. > @@ -177,9 +193,19 @@ static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr, > * No handler, we'll have to terminate things with extreme prejudice. > */ > bust_spinlocks(1); > - pr_alert("Unable to handle kernel %s at virtual address %08lx\n", > - (addr < PAGE_SIZE) ? "NULL pointer dereference" : > - "paging request", addr); > + > + if (is_permission_fault(esr, regs)) { is_permission_fault() was previously guarded with a 'addrpstate & PSR_PAN_BIT); return false; ---%<--- ... should fix this. > + if (esr & ESR_ELx_WNR) > + msg = "write to read-only memory"; > + else > + msg = "read from unreadable memory"; > + } else if (addr < PAGE_SIZE) > + msg = "NULL pointer dereference"; > + else > + msg = "paging request"; Nit: {} all the way down! > + > + pr_alert("Unable to handle kernel %s at virtual address %08lx\n", msg, > + addr); > > show_pte(mm, addr); > die("Oops", regs, esr); > @@ -269,21 +295,6 @@ static int __do_page_fault(struct mm_struct *mm, unsigned long addr, > return fault; > } > -static inline bool is_permission_fault(unsigned int esr, struct pt_regs *regs) > -{ > - unsigned int ec = ESR_ELx_EC(esr); > - unsigned int fsc_type = esr & ESR_ELx_FSC_TYPE; > - > - if (ec != ESR_ELx_EC_DABT_CUR && ec != ESR_ELx_EC_IABT_CUR) > - return false; > - > - if (system_uses_ttbr0_pan()) > - return fsc_type == ESR_ELx_FSC_FAULT && > - (regs->pstate & PSR_PAN_BIT); > - else > - return fsc_type == ESR_ELx_FSC_PERM; > -} Thanks! James