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: 94113 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2777915qgi; Thu, 16 Feb 2017 17:20:06 -0800 (PST) X-Received: by 10.84.143.195 with SMTP id 61mr7398297plz.46.1487294406598; Thu, 16 Feb 2017 17:20:06 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t64si3004599pgd.164.2017.02.16.17.20.06; Thu, 16 Feb 2017 17:20:06 -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=pass header.i=@linaro.org; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754972AbdBQBUE (ORCPT + 25 others); Thu, 16 Feb 2017 20:20:04 -0500 Received: from mail-pg0-f48.google.com ([74.125.83.48]:36555 "EHLO mail-pg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754255AbdBQBUD (ORCPT ); Thu, 16 Feb 2017 20:20:03 -0500 Received: by mail-pg0-f48.google.com with SMTP id v184so10598995pgv.3 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=Aem7fr2aKxUGlmPohHKlgW7Ez3W1U62zwqv2+VwwaVhH1TxOQtgfUVcv1BWn+8TaLN a51qksBMMLoUyc/rrMw+4e6fJfV76DPlulDfj0FEiUTogvfZ0Y0JUNFtp60cQDKZnG2Q Ym63J+Z2G/lJ2mX6urdq+epdb6erYqH1JRj+dxikuIO+XkPHx/NWafuX1/+/1ugR+lJS BPwY5TybTmjpjT7srlRRIntCzZuZVI4oG35iSPypa1GxWW4v7+V4vTiCEtMvya12rXZ6 B4orj+ZkGrrXscMuqhPVxQqivGoIGavqt/8mhSFyJ8p3+qtV0kp5WtEnATaOl5oUxkex YIcg== X-Gm-Message-State: AMke39kwtgA+arsLL+NETFq5RfyupXm7TGOKbslipk/Vk6bpTozk+Ha4d/8RALT+Ts5eFmdO 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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, James Morse , Laura Abbott , Mark Rutland 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.10.0.297.gf6727b0 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;