From patchwork Wed Feb 1 22:15:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Baicar X-Patchwork-Id: 9550727 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 AB16360424 for ; Wed, 1 Feb 2017 22:15:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9474B26C2F for ; Wed, 1 Feb 2017 22:15:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 894DF2847E; Wed, 1 Feb 2017 22:15:48 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no 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 3631F26C2F for ; Wed, 1 Feb 2017 22:15:48 +0000 (UTC) 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 1cZ3Bq-0001Yp-91; Wed, 01 Feb 2017 22:15:46 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cZ3Bm-0001XA-Mk for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2017 22:15:44 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4DD13607F0; Wed, 1 Feb 2017 22:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485987322; bh=t+JxIP8b6HlC9zIppa1A2OA0tU7wqu3gDotiXJLO5e8=; h=From:To:Cc:Subject:Date:From; b=BimdCYcO6RRgvv/E5rkopSYwF22d1FNVuKd53jJp8JKVu0S4LkGiOvL2t5OLMtxRI desWHjQ21enBUhmTU5K0cQbo1ZZFjMV3bUug6EIe8u1QialaKYg9BC/8v96KfHKOvu I3qmdcnlENnmkN9d3zC61Wm2UAJ/U24ClQyhfOTo= Received: from tbaicar-lnx.qualcomm.com (unknown [129.46.14.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: tbaicar@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1B71C60768; Wed, 1 Feb 2017 22:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485987322; bh=t+JxIP8b6HlC9zIppa1A2OA0tU7wqu3gDotiXJLO5e8=; h=From:To:Cc:Subject:Date:From; b=BimdCYcO6RRgvv/E5rkopSYwF22d1FNVuKd53jJp8JKVu0S4LkGiOvL2t5OLMtxRI desWHjQ21enBUhmTU5K0cQbo1ZZFjMV3bUug6EIe8u1QialaKYg9BC/8v96KfHKOvu I3qmdcnlENnmkN9d3zC61Wm2UAJ/U24ClQyhfOTo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 1B71C60768 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=tbaicar@codeaurora.org From: Tyler Baicar To: catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, james.morse@arm.com, akpm@linux-foundation.org, zjzhang@codeaurora.org, sandeepa.s.prabhu@gmail.com, shijie.huang@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling Date: Wed, 1 Feb 2017 15:15:18 -0700 Message-Id: <1485987318-9145-1-git-send-email-tbaicar@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170201_141542_790240_8C71B01A X-CRM114-Status: GOOD ( 15.35 ) 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: Tyler Baicar 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 From: "Jonathan (Zhixiong) Zhang" Add VM_FAULT_HWPOISON[_LARGE] handling to the arm64 page fault handler. Handling of VM_FAULT_HWPOISON[_LARGE] is very similar to VM_FAULT_OOM, the only difference is that a different si_code (BUS_MCEERR_AR) is passed to user space and si_addr_lsb field is initialized. Signed-off-by: Jonathan (Zhixiong) Zhang Signed-off-by: Tyler Baicar --- arch/arm64/mm/fault.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 156169c..50857f9 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -193,9 +194,10 @@ static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr, */ static void __do_user_fault(struct task_struct *tsk, unsigned long addr, unsigned int esr, unsigned int sig, int code, - struct pt_regs *regs) + struct pt_regs *regs, int fault) { struct siginfo si; + unsigned lsb = 0; if (unhandled_signal(tsk, sig) && show_unhandled_signals_ratelimited()) { pr_info("%s[%d]: unhandled %s (%d) at 0x%08lx, esr 0x%03x\n", @@ -211,6 +213,17 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr, si.si_errno = 0; si.si_code = code; si.si_addr = (void __user *)addr; + /* + * Either small page or large page may be poisoned. + * In other words, VM_FAULT_HWPOISON_LARGE and + * VM_FAULT_HWPOISON are mutually exclusive. + */ + if (fault & VM_FAULT_HWPOISON_LARGE) + lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault)); + else if (fault & VM_FAULT_HWPOISON) + lsb = PAGE_SHIFT; + si.si_addr_lsb = lsb; + force_sig_info(sig, &si, tsk); } @@ -224,7 +237,7 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re * handle this fault with. */ if (user_mode(regs)) - __do_user_fault(tsk, addr, esr, SIGSEGV, SEGV_MAPERR, regs); + __do_user_fault(tsk, addr, esr, SIGSEGV, SEGV_MAPERR, regs, 0); else __do_kernel_fault(mm, addr, esr, regs); } @@ -426,7 +439,17 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, */ sig = SIGBUS; code = BUS_ADRERR; - } else { + } +#ifdef CONFIG_MEMORY_FAILURE + else if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) { + pr_err( + "Killing %s:%d due to hardware memory corruption fault at %lx\n", + tsk->comm, tsk->pid, addr); + sig = SIGBUS; + code = BUS_MCEERR_AR; + } +#endif + else { /* * Something tried to access memory that isn't in our memory * map. @@ -436,7 +459,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, SEGV_ACCERR : SEGV_MAPERR; } - __do_user_fault(tsk, addr, esr, sig, code, regs); + __do_user_fault(tsk, addr, esr, sig, code, regs, fault); return 0; no_context: