From patchwork Fri Jan 22 05:24:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?eWFvYWlsaSBb5LmI54ix5YipXQ==?= X-Patchwork-Id: 12038339 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,URIBL_BLOCKED, 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 2E525C433DB for ; Fri, 22 Jan 2021 05:24:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB4AC23122 for ; Fri, 22 Jan 2021 05:24:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB4AC23122 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kingsoft.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 16AC76B0006; Fri, 22 Jan 2021 00:24:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 11B176B0007; Fri, 22 Jan 2021 00:24:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F24E26B0008; Fri, 22 Jan 2021 00:24:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0243.hostedemail.com [216.40.44.243]) by kanga.kvack.org (Postfix) with ESMTP id DCE936B0006 for ; Fri, 22 Jan 2021 00:24:40 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9194E180ABF4C for ; Fri, 22 Jan 2021 05:24:40 +0000 (UTC) X-FDA: 77732271120.15.jam59_4d0e1e227569 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 6E2371814B0C7 for ; Fri, 22 Jan 2021 05:24:40 +0000 (UTC) X-HE-Tag: jam59_4d0e1e227569 X-Filterd-Recvd-Size: 6036 Received: from mail.kingsoft.com (mail.kingsoft.com [114.255.44.145]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Jan 2021 05:24:36 +0000 (UTC) X-AuditID: 0a580157-f39ff7000005df43-e0-600a5c33bbe0 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-1-NODE-87) with SMTP id 69.92.57155.33C5A006; Fri, 22 Jan 2021 13:01:39 +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; Fri, 22 Jan 2021 13:24:25 +0800 Date: Fri, 22 Jan 2021 13:24:24 +0800 From: Aili Yao To: , , , Subject: [PATCH v6] mm,hwpoison: Send SIGBUS to PF_MCE_EARLY processes on action required events Message-ID: <20210122132424.313c8f5f.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 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+NgFprDLMWRmVeSWpSXmKPExsXCFcGooGscw5Vg0PjUyuLemv+sFhcbDzBa nJlW5MDssenTJHaPF1c3snhsPl0dwBzFZZOSmpNZllqkb5fAlXH+RGzBcZmKtZf2sjUwfhPr YuTkkBAwkVjQsIqli5GLQ0hgOpPE89ufWCGcF4wSE37PZO5i5OBgEVCVOL3DDKSBDcjcdW8W K4gtIpAi8bRvFwuILSyQJHFw9g52EJtXwEpi08QHTCCt/AJiEq8ajCF22Us8/3uWGaJEUOLk zCdgrcwCOhInVh1jhrDlJba/nQNmCwkoShxe8osdoldJ4kj3DDYIO1Zi2bxXrBMYBWYhGTUL yahZSEYtYGRexchSnJtuuIkREoDhOxjnNX3UO8TIxMF4iFGCg1lJhPeRJUeCEG9KYmVValF+ fFFpTmrxIUZpDhYlcV59Z7YEIYH0xJLU7NTUgtQimCwTB6dUA1N8Jt/p7cvFOB68++V2Yj9P eEpIW13A8pvvVC6K7hRc8L/h3cwm37dxdduyilY67/5S0+Sp37s2cO9PS4nqlaJ97m1qET0P n4s7OFcHnLtjtU7+8PcVOqdnB9b5JGa1/u3tTdn2Mrx9Q2GVZxtDcnLXmilf9oXfuWZ1ceUx 4xnV9p7P/jMevHl3nVtG+vq16azJdxJ6gu+sWxap8WC2SMBb+9yeGoGY33IL1O00l1wyulkm dNPj+J3twdkH+bf2iBzceelI52uLLa+6hbQ8Zt132bO5yrD4P8/MDbt5N+sYHiy7y3Jt2Y6P 38taVPWM3kc9nvH1+Ionm65cvfzM54ZSP9fjn3Lz7HYenf7SrkZaiaU4I9FQi7moOBEA+WiD 9q8CAAA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When a memory uncorrected error is triggered by process who accessed the address with error, It's Action Required Case for only current process which triggered this; This Action Required case means Action optional to other process who share the same page. Usually killing current process will be sufficient, other processes sharing the same page will get be signaled when they really touch the poisoned page. But there is another scenario that other processes sharing the same page want to be signaled early with PF_MCE_EARLY set,In this case, we should get them into kill list and signal BUS_MCEERR_AO to them. So in this patch, task_early_kill will check current process if force_early is set, and if not current,the code will fallback to find_early_kill_thread() to check if there is PF_MCE_EARLY process who cares the error. In kill_proc(), BUS_MCEERR_AR is only send to current, other processes in kill list will be signaled with BUS_MCEERR_AO. Reviewed-by: Oscar Salvador Acked-by: Naoya Horiguchi Signed-off-by: Aili Yao --- mm/memory-failure.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 5a38e9eade94..3fd483e6c2fb 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -243,9 +243,13 @@ static int kill_proc(struct to_kill *tk, unsigned long pfn, int flags) pfn, t->comm, t->pid); if (flags & MF_ACTION_REQUIRED) { - WARN_ON_ONCE(t != current); - ret = force_sig_mceerr(BUS_MCEERR_AR, + if (t == current) + ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)tk->addr, addr_lsb); + else + /* Signal other processes sharing the page if they have PF_MCE_EARLY set. */ + ret = send_sig_mceerr(BUS_MCEERR_AO, (void __user *)tk->addr, + addr_lsb, t); } else { /* * Don't use force here, it's convenient if the signal @@ -440,26 +444,26 @@ static struct task_struct *find_early_kill_thread(struct task_struct *tsk) * Determine whether a given process is "early kill" process which expects * to be signaled when some page under the process is hwpoisoned. * Return task_struct of the dedicated thread (main thread unless explicitly - * specified) if the process is "early kill," and otherwise returns NULL. + * specified) if the process is "early kill" and otherwise returns NULL. * - * Note that the above is true for Action Optional case, but not for Action - * Required case where SIGBUS should sent only to the current thread. + * Note that the above is true for Action Optional case. For Action Required + * case, it's only meaningful to the current thread which need to be signaled + * with SIGBUS, this error is Action Optional for other non current + * processes sharing the same error page,if the process is "early kill", the + * task_struct of the dedicated thread will also be returned. */ static struct task_struct *task_early_kill(struct task_struct *tsk, int force_early) { if (!tsk->mm) return NULL; - if (force_early) { - /* - * Comparing ->mm here because current task might represent - * a subthread, while tsk always points to the main thread. - */ - if (tsk->mm == current->mm) - return current; - else - return NULL; - } + /* + * Comparing ->mm here because current task might represent + * a subthread, while tsk always points to the main thread. + */ + if (force_early && tsk->mm == current->mm) + return current; + return find_early_kill_thread(tsk); }