diff mbox series

[v1,1/2] mm/memory-failure: prioritize prctl(PR_MCE_KILL) over vm.memory_failure_early_kill

Message ID 1591321039-22141-2-git-send-email-naoya.horiguchi@nec.com (mailing list archive)
State New, archived
Headers show
Series hwpoison: fixes signaling on memory error | expand

Commit Message

Naoya Horiguchi June 5, 2020, 1:37 a.m. UTC
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 <naoya.horiguchi@nec.com>
---
 mm/memory-failure.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
diff mbox series

Patch

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