Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Oleg Nesterov <oleg@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Andrew Morton
8ac5dc66 d73d0035

+5 -6
+5 -6
kernel/fork.c
··· 1536 1536 { 1537 1537 struct mm_struct *mm; 1538 1538 1539 + if (task->flags & PF_KTHREAD) 1540 + return NULL; 1541 + 1539 1542 task_lock(task); 1540 1543 mm = task->mm; 1541 - if (mm) { 1542 - if (task->flags & PF_KTHREAD) 1543 - mm = NULL; 1544 - else 1545 - mmget(mm); 1546 - } 1544 + if (mm) 1545 + mmget(mm); 1547 1546 task_unlock(task); 1548 1547 return mm; 1549 1548 }