From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 9E247C433E1 for ; Fri, 5 Jun 2020 01:37:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6281F2074B for ; Fri, 5 Jun 2020 01:37:26 +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 6281F2074B 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) Received: by kanga.kvack.org (Postfix, from userid 40) id EC0A3280002; Thu, 4 Jun 2020 21:37:25 -0400 (EDT) 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-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-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); } /* -- 2.7.0