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); } /*