From patchwork Fri Feb 17 01:19:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9578591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 167896049F for ; Fri, 17 Feb 2017 01:20:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0485728687 for ; Fri, 17 Feb 2017 01:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECA9F2869F; Fri, 17 Feb 2017 01:20:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6353328687 for ; Fri, 17 Feb 2017 01:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=cmD4BA2XBNWlgWy8objiAPnPv1FquECh/u2OV1cd70E=; b=Ut0 86De7s2Vk/wU9u8fAXpjVlR3up5jD2PAyrn9RwBrpIRlWP+nvVeV7vFPR7n8ktMlUBC9c3VjOiLVq G5oVm3dR1obvVclrn7OYPfFFLx0w6M6btfoBkOxexuiEgkqw05X6MFZWyC3r5pv3FtAT82DiLPpuN fcfpt4ZLmhjgNnF3I35bbx/kp2W3ZRmmb66uEeAoyJ3jpPSoP1uYJ5SJE1sJHYaHTq+fS5zZ4LAi4 v6GVh49fHyeEC+4O3dg4MbpWi1TnDlRM5qkMEvwhzR+XJ0NwLKqMainzWo3nuvL504EP5qJkRgY4h aighhgkgN5jH1R6EgyCcHBUvt8AGcPA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceXDo-0006sK-Aa; Fri, 17 Feb 2017 01:20:28 +0000 Received: from mail-pg0-x233.google.com ([2607:f8b0:400e:c05::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ceXDk-00052E-Fk for linux-arm-kernel@lists.infradead.org; Fri, 17 Feb 2017 01:20:26 +0000 Received: by mail-pg0-x233.google.com with SMTP id t188so10631623pgt.2 for ; Thu, 16 Feb 2017 17:20:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=2w6BGvKbXo8q0vw/M39+AjveWFCp6ax6Rix1lp0eOQw=; b=Ts9FFxQLWwwRY438mfgEXq9JOMby93LBQArb+V59weqJecEm8jz2HcW5r/xLnq/0tS i7u+fdDa6HeogCw9jvNiDlg9pH+x/PPokDrethoziK8r7bSd72b06KfPDXgTJ9k7W9T7 HS2Km37/m+ekojPtB39hfGkYw13f+i6GK0PaY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2w6BGvKbXo8q0vw/M39+AjveWFCp6ax6Rix1lp0eOQw=; b=hp49OYlKwO1oEkqWeMuao5ualQnVUQL7C9rnLRjdY8DTqBS8g/y9ZQZfkzM8q23aOj E7zQ2CLfZH2SpYUhKa+C5jb6rIA/NltDoEu9SNZ27an9iGl0EyG/WJa1dhTH7ycF0zet EyZgeMhk0o5CR4ODEsSGc+q7wZ8sZyQW31Xmkm/LV+wfKULQ065OyQAILUMwgqkmHWhN nM4eIpZMlvNYt5U0luTqRYr0v2Twf8RymES+QWiIjVwhgIwodUHts5dZAEkrAfqmen2d pf/7YryoOBBo5qxu9uikj4K6I4iZX5PC7evjPC2i8xK5JAldqji2RrsFKOFH5F/UkkY2 tIMg== X-Gm-Message-State: AMke39nDlHZvG8QDgJkSf7AdFhcMbzcd8DJKL3o7kpen/N12sve66eXXm1OY43FF2GeSCJsB X-Received: by 10.84.128.33 with SMTP id 30mr7439674pla.128.1487294402243; Thu, 16 Feb 2017 17:20:02 -0800 (PST) Received: from localhost.localdomain (ip68-101-172-78.sd.sd.cox.net. [68.101.172.78]) by smtp.gmail.com with ESMTPSA id u82sm15782982pfd.7.2017.02.16.17.20.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Feb 2017 17:20:01 -0800 (PST) From: Stephen Boyd To: Catalin Marinas , Will Deacon Subject: [PATCH v2] arm64: print a fault message when attempting to write RO memory Date: Thu, 16 Feb 2017 17:19:59 -0800 Message-Id: <20170217011959.26754-1-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170216_172024_562921_5B092686 X-CRM114-Status: GOOD ( 14.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Laura Abbott , James Morse , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: James Morse Cc: Laura Abbott Cc: Mark Rutland Signed-off-by: Stephen Boyd --- Changes from v1: * Move into __do_kernel_fault() (Mark Rutland) arch/arm64/mm/fault.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) 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 @@ -160,12 +160,28 @@ static bool is_el1_instruction_abort(unsigned int esr) return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_CUR; } +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; +} + /* * 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)) { + 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"; + + 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; -} - static bool is_el0_instruction_abort(unsigned int esr) { return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_LOW;