From patchwork Wed Jan 20 08:24:22 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: 12031663 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 9CC84C433E6 for ; Wed, 20 Jan 2021 08:24:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5D2C423131 for ; Wed, 20 Jan 2021 08:24:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D2C423131 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 5F20A6B0005; Wed, 20 Jan 2021 03:24:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A4276B0006; Wed, 20 Jan 2021 03:24:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BA436B0007; Wed, 20 Jan 2021 03:24:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id 35FA96B0005 for ; Wed, 20 Jan 2021 03:24:37 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E875C180AD801 for ; Wed, 20 Jan 2021 08:24:36 +0000 (UTC) X-FDA: 77725466952.06.yard75_220286527559 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id C5F80100393DA for ; Wed, 20 Jan 2021 08:24:36 +0000 (UTC) X-HE-Tag: yard75_220286527559 X-Filterd-Recvd-Size: 5575 Received: from mail.kingsoft.com (mail.kingsoft.com [114.255.44.145]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 Jan 2021 08:24:32 +0000 (UTC) X-AuditID: 0a580157-f39ff7000005df43-84-6007e36e1efe 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 9A.85.57155.E63E7006; Wed, 20 Jan 2021 16:01:50 +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; Wed, 20 Jan 2021 16:24:22 +0800 Date: Wed, 20 Jan 2021 16:24:22 +0800 From: Aili Yao To: , , , Subject: [PATCH v5] mm,hwpoison: send SIGBUS to PF_MCE_EARLY processes on action required events Message-ID: <20210120162422.0ed3dd56.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+NgFprLLMWRmVeSWpSXmKPExsXCFcGooJv3mD3B4NABQ4t7a/6zWlxsPMBo cWZakQOzx6ZPk9g9XlzdyOKx+XR1AHMUl01Kak5mWWqRvl0CV0bP/4csBf8kKuYumsHawDhD pIuRk0NCwERi18Y9zF2MXBxCAtOZJM7f3ADlvGCU+P73MHsXIwcHi4CqxP8/zCANbEDmrnuz WEFsEYEUiVkzPoHFhQWSJNa8fAtm8wpYSXybs5AJpJVfQEziVYMxxC57ied/z0KVCEqcnPmE BcRmFtCROLHqGDOELS+x/e0cMFtIQFHi8JJf7BC9ShJHumewQdixEsvmvWKdwCgwC8moWUhG zUIyagEj8ypGluLcdMNNjJAQDN/BOK/po94hRiYOxkOMEhzMSiK8TX/ZEoR4UxIrq1KL8uOL SnNSiw8xSnOwKInz6jsDpQTSE0tSs1NTC1KLYLJMHJxSDUzcUp1LNPXXtD4+tabL6+kU04wf iuFfdk+XPXo70jKh+VOOnP76vVI/locE7Tu33OPjB/P223uPzJlqvLRB49zGvmMTSmX4/Xi7 L4upyRjHaq1tP3L48l6V3RxRH6dXbJXoWLU3lOF89IN9Gw8Idyyqeve4wqR76pqoLK2qpDKn +YJBa21bGHrS/m6xa23Se7H/n0j4xxsBdu3ZlVujGJ1ljSxYZ5VuUZn645vnksiDSv3LPqv2 aRjNEDDp01u4rd5s4YLM4zInP10pmeV/44qxlNGUhVoHxdjvprW7rONRlmCxVdzRKSRppG2o aPG/asIcgecWf2v2aWYcnn7y4dOD07UOS81gNXw0fxqj2zUlluKMREMt5qLiRADTyoYSsAIA AA== 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. Acked-by: Naoya Horiguchi Signed-off-by: Aili Yao Reviewed-by: Oscar Salvador --- mm/memory-failure.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 5a38e9eade94..441fe2787cd4 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -243,9 +243,12 @@ 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 (tk->tsk == current) + ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)tk->addr, addr_lsb); + else + 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,10 +443,13 @@ 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) @@ -457,8 +463,6 @@ static struct task_struct *task_early_kill(struct task_struct *tsk, */ if (tsk->mm == current->mm) return current; - else - return NULL; } return find_early_kill_thread(tsk); }