From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EEB7C433DB for ; Thu, 28 Jan 2021 12:00:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4B2164DD8 for ; Thu, 28 Jan 2021 12:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231468AbhA1MAa (ORCPT ); Thu, 28 Jan 2021 07:00:30 -0500 Received: from mail.kingsoft.com ([114.255.44.146]:41174 "EHLO mail.kingsoft.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231377AbhA1MAA (ORCPT ); Thu, 28 Jan 2021 07:00:00 -0500 X-Greylist: delayed 945 seconds by postgrey-1.27 at vger.kernel.org; Thu, 28 Jan 2021 06:59:59 EST X-AuditID: 0a580155-713ff700000550c6-8c-60129d2b0143 Received: from mail.kingsoft.com (localhost [10.88.1.32]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.kingsoft.com (SMG-2-NODE-85) with SMTP id B7.E6.20678.B2D92106; Thu, 28 Jan 2021 19:16:59 +0800 (HKT) Received: from aili-OptiPlex-7020 (172.16.253.254) by KSBJMAIL2.kingsoft.cn (10.88.1.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 28 Jan 2021 19:43:27 +0800 Date: Thu, 28 Jan 2021 19:43:26 +0800 From: Aili Yao To: , , CC: , Subject: [PATCH] x86/fault: Send SIGBUS to user process always for hwpoison page access. Message-ID: <20210128194326.71895e92.yaoaili@kingsoft.com> Organization: Kingsoft X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [172.16.253.254] X-ClientProxiedBy: KSBJMAIL1.kingsoft.cn (10.88.1.31) To KSBJMAIL2.kingsoft.cn (10.88.1.32) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrMLMWRmVeSWpSXmKPExsXCFcGooKs9VyjB4MUkJovLu+awWVxsPMBo 8ebCPRaLHxseszqweCze85LJY9OqTjaPF1c3snh83iQXwBLFZZOSmpNZllqkb5fAlbH20mrG gg6Bike377A1ME7l7WLk5JAQMJG4++sGcxcjF4eQwHQmiW1fDzFCOC8YJS6+PAHkcHCwCKhK fLhuCNLABmTuujeLFcQWEXCTOPj9MTuIzSxgI/F4xzQWEFtYIEri1ZQOJpBWXgEriR0H0kBM fgExiVcNxhBr7SWe/z3LDGLzCghKnJz5hAViio7EiVXHmCFseYntb+eA2UICihKHl/xih+hV kjjSPYMNwo6VWDbvFesERsFZSEbNQjJqFpJRCxiZVzGyFOemG21ihIRr6A7GGU0f9Q4xMnEw HmKU4GBWEuF9O0coQYg3JbGyKrUoP76oNCe1+BCjNAeLkjhvuQNfgpBAemJJanZqakFqEUyW iYNTqoEpMHFnVffZS2vtv/9+9s/d21tMOqD9tf+/T/+4mk7UNtfYps2pffV8jptMlbD3/aNX 5jx45BSrpWMSuGadS8dE/fd33oV83iL+7fGi6XO8GGvrb/vyBhwz21/OJL6na97iC7dlIhJy d7tpTD2xP/lFb8/BLw5pz3cdy9pw4s+f7dOOPOvPj0+t/8qjZ1Jo/WL51oQ5r05kFTTJ2PnP qb/7U+2//hyjRWH/zBgqBN+d42BLjv40JeKuhPLR+qlbhZKeTrE7wySy+6eHZMdXcVEWbc+i aLOc7iD3qWunzo3YL1KsVPNCK3H6VekdNy+Uboz/sncr67ufa6fY/b/N++F+XlPeGe9PnbPK N5hdnniRTYmlOCPRUIu5qDgRAF5VeATGAgAA Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org when one page is already hwpoisoned by AO action, process may not be killed, the process mapping this page may make a syscall include this page and result to trigger a VM_FAULT_HWPOISON fault, as it's in kernel mode it may be fixed by fixup_exception, current code will just return error code to user process. This is not suffient, we should send a SIGBUS to the process and log the info to console, as we can't trust the process will handle the error correctly. Suggested-by: Feng Yang Signed-off-by: Aili Yao --- arch/x86/mm/fault.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index f1f1b5a0956a..36d1e385512b 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -662,7 +662,16 @@ no_context(struct pt_regs *regs, unsigned long error_code, * In this case we need to make sure we're not recursively * faulting through the emulate_vsyscall() logic. */ +#ifdef CONFIG_MEMORY_FAILURE + if (si_code == BUS_MCEERR_AR && signal == SIGBUS) + pr_err("MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n", + current->comm, current->pid, address); + + if ((current->thread.sig_on_uaccess_err && signal) || + (si_code == BUS_MCEERR_AR && signal == SIGBUS)) { +#else if (current->thread.sig_on_uaccess_err && signal) { +#endif sanitize_error_code(address, &error_code); set_signal_archinfo(address, error_code); @@ -927,7 +936,14 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address, { /* Kernel mode? Handle exceptions or die: */ if (!(error_code & X86_PF_USER)) { +#ifdef CONFIG_MEMORY_FAILURE + if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) + no_context(regs, error_code, address, SIGBUS, BUS_MCEERR_AR); + else + no_context(regs, error_code, address, SIGBUS, BUS_ADRERR); +#else no_context(regs, error_code, address, SIGBUS, BUS_ADRERR); +#endif return; } -- 2.25.1