Commit 8ac5dc66 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Andrew Morton
Browse files

get_task_mm: check PF_KTHREAD lockless

Nowadays PF_KTHREAD is sticky and it was never protected by ->alloc_lock. 
Move the PF_KTHREAD check outside of task_lock() section to make this code
more understandable.

Link: https://lkml.kernel.org/r/20240626191017.GA20031@redhat.com


Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent d73d0035
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -1536,14 +1536,13 @@ struct mm_struct *get_task_mm(struct task_struct *task)
{
	struct mm_struct *mm;

	if (task->flags & PF_KTHREAD)
		return NULL;

	task_lock(task);
	mm = task->mm;
	if (mm) {
		if (task->flags & PF_KTHREAD)
			mm = NULL;
		else
	if (mm)
		mmget(mm);
	}
	task_unlock(task);
	return mm;
}