From patchwork Fri Jun 5 01:37:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 11588865 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 A0A0A1392 for ; Fri, 5 Jun 2020 01:37:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 62B922074B for ; Fri, 5 Jun 2020 01:37:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TIWaCADM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62B922074B 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 F0FF28E0006; Thu, 4 Jun 2020 21:37:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EC0A3280002; Thu, 4 Jun 2020 21:37:25 -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 C9F328E0007; Thu, 4 Jun 2020 21:37:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id A96F88E0006 for ; Thu, 4 Jun 2020 21:37:25 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 703925853 for ; Fri, 5 Jun 2020 01:37:25 +0000 (UTC) X-FDA: 76893445650.22.screw98_0603ecd26d9c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 525B218038E67 for ; Fri, 5 Jun 2020 01:37:25 +0000 (UTC) X-Spam-Summary: 2,0,0,ded93a893c60d0ba,d41d8cd98f00b204,nao.horiguchi@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:2689:2899:2910:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3871:3872:3874:4250:5007:6261:6653:7903:9413:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12895:13180:13229:13255:14096:14181:14394:14687:14721:21060:21080:21324:21444:21611:21627:21666:21740:21990:30054:30070,0,RBL:209.85.215.195:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.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: screw98_0603ecd26d9c X-Filterd-Recvd-Size: 5313 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Fri, 5 Jun 2020 01:37:24 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id p30so4349906pgl.11 for ; Thu, 04 Jun 2020 18:37:24 -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=WYJmk6LxaQUhvS0guoAsIn/c7aHxpjQPCgpuCWMpKps=; b=TIWaCADMXkCb20avkJjxkzdYbcRUv+k8HTVPOhDT8/jDB7BmTAfzMgzu7FvTYuiKlK CRiIcopgFatbaj1mf1gh7FHUfPTJcZz2Z/4iLQmGoeX9tsRVXFMjvfltY2jRwkhLXw+F 32PbndNWJI4X6L1fdnkS8yOmIEjVQGB5O6XIeC9iBB19dPFhb7kdcVDy5xYOcRIGA6UB Jehq1/2UKfBa1wa8dcvZ+lYMVsM5rirG263aemD2Ln+aKptxENTN1mL6iPLfqaDX1EyT is3BsGSgvHpGTaPZuHoBg0el4L2UbzmEjYJoHAr5KAikLhZ07eshLsCZ3l5DqVNW3eRp ODig== 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=WYJmk6LxaQUhvS0guoAsIn/c7aHxpjQPCgpuCWMpKps=; b=EC19bArIMSf5vbNo9PUlpmUaXCm9vzWMQ8NA+TrQA7sCEOvJKgjV0EDofyeXjqd+XH 1bOREhiNj+ubzJnj5n9FYXKHMxkUQlVxE81CXqFmf6XAGqWzZRlu5QpCCuqCN9zLd+tE Jj45HZvRsCjyKKwBVls+iKr5m5H/N1sPwbmKxkRA3lowBs+/KJhHdjQlVwq4B0pmZ87P MtnqDbO+iqcSFsCYYhQ5aW7zmfUNBkazvt4kHfxHKmaPqsIMY2RYq1MoWXcatqfr7ID9 LVXnWYT1RSzjf4L6Ulk0VgMAVQB8eT46aGSfD80Kc13ffNzkMHMTLB0S+ze4i2upl7rI R2Rg== X-Gm-Message-State: AOAM5305UjcftF4UowBQOQxtnGDglFnDXQDkqfKti2kkR//8opJvZxvb wzp6powa8RdtQjU/3wSx9w== X-Google-Smtp-Source: ABdhPJz6qd3bnR16YeSubH5Ba9yL8sG3DbGBXXHjsVgtX8tALKm8Zli3HhH7760/D/3ybeHNXlnlFQ== X-Received: by 2002:a63:6dc8:: with SMTP id i191mr6857927pgc.414.1591321044149; Thu, 04 Jun 2020 18:37:24 -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.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jun 2020 18:37:23 -0700 (PDT) From: Naoya Horiguchi X-Google-Original-From: Naoya Horiguchi To: Andrew Morton Cc: linux-mm@kvack.org Subject: [PATCH v1 1/2] mm/memory-failure: prioritize prctl(PR_MCE_KILL) over vm.memory_failure_early_kill Date: Fri, 5 Jun 2020 10:37:18 +0900 Message-Id: <1591321039-22141-2-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: 525B218038E67 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000022, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Early-kill policy is controlled from two types of settings, one is per-process setting prctl(PR_MCE_KILL) and the other is system-wide setting vm.memory_failure_early_kill. Users expect per-process setting to override system-wide setting as many other settings do, but early-kill setting doesn't work as such. For example, if a system configures vm.memory_failure_early_kill to 1 (enabled), a process receives SIGBUS even if it's configured to explicitly disable PF_MCE_KILL by prctl(). That's not desirable for applications with their own policies. This patch is suggesting to change the priority of these two types of settings, by checking sysctl_memory_failure_early_kill only when a given process has the default kill policy. Note that this patch is solving a thread choice issue too. Originally, collect_procs() always chooses the main thread when vm.memory_failure_early_kill is 1, even if the process has a dedicated thread for memory error handling. SIGBUS should be sent to the dedicated thread if early-kill is enabled via vm.memory_failure_early_kill as we are doing for PR_MCE_KILL_EARLY processes. Signed-off-by: Naoya Horiguchi --- mm/memory-failure.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git v5.7/mm/memory-failure.c v5.7_patched/mm/memory-failure.c index dd3862f..339c07d 100644 --- v5.7/mm/memory-failure.c +++ v5.7_patched/mm/memory-failure.c @@ -402,9 +402,15 @@ static struct task_struct *find_early_kill_thread(struct task_struct *tsk) { struct task_struct *t; - for_each_thread(tsk, t) - if ((t->flags & PF_MCE_PROCESS) && (t->flags & PF_MCE_EARLY)) - return t; + for_each_thread(tsk, t) { + if (t->flags & PF_MCE_PROCESS) { + if (t->flags & PF_MCE_EARLY) + return t; + } else { + if (sysctl_memory_failure_early_kill) + return t; + } + } return NULL; } @@ -417,17 +423,11 @@ static struct task_struct *find_early_kill_thread(struct task_struct *tsk) static struct task_struct *task_early_kill(struct task_struct *tsk, int force_early) { - struct task_struct *t; if (!tsk->mm) return NULL; if (force_early) return tsk; - t = find_early_kill_thread(tsk); - if (t) - return t; - if (sysctl_memory_failure_early_kill) - return tsk; - return NULL; + return find_early_kill_thread(tsk); } /* 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); }