From patchwork Fri Jun 5 01:37:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 11588867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 883BC90 for ; Fri, 5 Jun 2020 01:37:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4B4472074B for ; Fri, 5 Jun 2020 01:37:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PJFA2lq2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B4472074B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AA36E280003; Thu, 4 Jun 2020 21:37:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A5349280002; Thu, 4 Jun 2020 21:37:27 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 859D4280003; Thu, 4 Jun 2020 21:37:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 6A978280002 for ; Thu, 4 Jun 2020 21:37:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 37BFC8248068 for ; Fri, 5 Jun 2020 01:37:27 +0000 (UTC) X-FDA: 76893445734.18.use46_2e0c05c26d9c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 1CDA9100ED2E9 for ; Fri, 5 Jun 2020 01:37:27 +0000 (UTC) X-Spam-Summary: 2,0,0,8ed6c337c216cfb3,d41d8cd98f00b204,nao.horiguchi@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2840:2899:2901:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3871:3872:3874:4250:5007:6119:6261:6653:7903:9010:9413:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12895:13141:13230:13255:14096:14181:14394:14687:14721:21060:21080:21222:21324:21444:21451:21627:21666:21990:30051:30054:30056:30083,0,RBL:209.85.214.195:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: use46_2e0c05c26d9c X-Filterd-Recvd-Size: 5685 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Jun 2020 01:37:26 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id bh7so2961008plb.11 for ; Thu, 04 Jun 2020 18:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p2jmrdUUW4eUgyiTWUxqRAcw4Llm6dw9IKb1kO+s+9E=; b=PJFA2lq2UAoyZGzb9xNsQBg9dMma8aQ3zxpePqOP9JSo0wqVVo/zgsgZaCEzLtdiOd k3SZMXBM2nVHOI7RlJbI1ufLjTO40ySd2qmjUsZt+8S6gFX6Zd5GnQ5i50JsKfA8SkBu TDTcCyzR3bP4bADNO7IliITtMW4BzKDwCjFe8BR4CuMrVnf9QQeixanH+TeOgVTdFpFZ NGxcHT7d23Vt6FMgBeKP1WESWng0v3uP0Cu9oKCS4fjm9vtWhzePvbIIvva/xy/2zoUF tQGW6WBxfXFI5Payguo3cZh2X2uJUZKtwNf0dx6h8qSstoek0F6/091YplM1buwTcroI x4tA== 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:in-reply-to :references; bh=p2jmrdUUW4eUgyiTWUxqRAcw4Llm6dw9IKb1kO+s+9E=; b=PazFBDU4s+fKlhZSab2AmZnNASwFmWTxud18h3Ij/57Afnp+iIe813DTkz5YRHtB7Q ideUZkOJMdUipyzkoMiGerVLDhqxu3iT9eGLMUI68uWvz0KZQj3itZ6PYU4D3KUzKFD5 V6Ai+mkl+5uRC4YRgUWpULjFtNqlbgWqRrXuw5tc0NY0877+I0w5OONbqKy32jZBDCCc vy4DCGLgfsFaSqSYQiUIdHnkOTcltUFYrp7j9VDXqScga4TcemWgg4L4G+6eoR92MVTL 69C1AWAsV5/08cNLAmIiSxEKkO8PYFQuP6HIgs4/GRtILwLeZbgEnyIiDhu6AWFjwti3 R47Q== X-Gm-Message-State: AOAM532+/fRhC4Apo56bLVFrGidYknQTifX/oQ/TlBRDBVuIeXrjmgVk kPMPCskkvj37ngz8cOb2qA== X-Google-Smtp-Source: ABdhPJxn/CQgk0T6ErlZfCV5pdfuPHrG+UMSxt/tagItRXOJAn+nCUjtB5RjL1bwke8Uv3ORbTBCJA== X-Received: by 2002:a17:90a:2e08:: with SMTP id q8mr192508pjd.153.1591321045640; Thu, 04 Jun 2020 18:37:25 -0700 (PDT) Received: from www9186uo.sakura.ne.jp (www9186uo.sakura.ne.jp. [153.121.56.200]) by smtp.gmail.com with ESMTPSA id f18sm4918675pga.75.2020.06.04.18.37.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2020 18:37:25 -0700 (PDT) From: Naoya Horiguchi X-Google-Original-From: Naoya Horiguchi To: Andrew Morton Cc: linux-mm@kvack.org Subject: [PATCH v1 2/2] mm/memory-failure: send SIGBUS(BUS_MCEERR_AR) only to current thread Date: Fri, 5 Jun 2020 10:37:19 +0900 Message-Id: <1591321039-22141-3-git-send-email-naoya.horiguchi@nec.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1591321039-22141-1-git-send-email-naoya.horiguchi@nec.com> References: <1591321039-22141-1-git-send-email-naoya.horiguchi@nec.com> X-Rspamd-Queue-Id: 1CDA9100ED2E9 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: Action Required memory error should happen only when a processor is about to access to a corrupted memory, so it's synchronous and only affects current process/thread. Recently commit 872e9a205c84 ("mm, memory_failure: don't send BUS_MCEERR_AO for action required error") fixed the issue that Action Required memory could unnecessarily send SIGBUS to the processes which share the error memory. But we still have another issue that we could send SIGBUS to a wrong thread. This is because collect_procs() and task_early_kill() fails to add the current process to "to-kill" list. So this patch is suggesting to fix it. With this fix, SIGBUS(BUS_MCEERR_AR) is never sent to non-current process/thread. Signed-off-by: Naoya Horiguchi Acked-by: Tony Luck Acked-by: Pankaj Gupta --- mm/memory-failure.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git v5.7/mm/memory-failure.c v5.7_patched/mm/memory-failure.c index 339c07d..fa4f9cd 100644 --- v5.7/mm/memory-failure.c +++ v5.7_patched/mm/memory-failure.c @@ -212,15 +212,13 @@ static int kill_proc(struct to_kill *tk, unsigned long pfn, int flags) short addr_lsb = tk->size_shift; int ret = 0; - if ((t->mm == current->mm) || !(flags & MF_ACTION_REQUIRED)) - pr_err("Memory failure: %#lx: Sending SIGBUS to %s:%d due to hardware memory corruption\n", + pr_err("Memory failure: %#lx: Sending SIGBUS to %s:%d due to hardware memory corruption\n", pfn, t->comm, t->pid); if (flags & MF_ACTION_REQUIRED) { - if (t->mm == current->mm) - ret = force_sig_mceerr(BUS_MCEERR_AR, + WARN_ON_ONCE(t != current); + ret = force_sig_mceerr(BUS_MCEERR_AR, (void __user *)tk->addr, addr_lsb); - /* send no signal to non-current processes */ } else { /* * Don't use force here, it's convenient if the signal @@ -419,14 +417,25 @@ static struct task_struct *find_early_kill_thread(struct task_struct *tsk) * 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. + * + * 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. */ static struct task_struct *task_early_kill(struct task_struct *tsk, int force_early) { if (!tsk->mm) return NULL; - if (force_early) - return tsk; + 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; + } return find_early_kill_thread(tsk); }