* [PATCH] get_task_mm: check PF_KTHREAD lockless
@ 2024-06-26 19:10 Oleg Nesterov
2024-06-27 7:49 ` Michal Hocko
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2024-06-26 19:10 UTC (permalink / raw)
To: Andrew Morton; +Cc: Eric W. Biederman, Michal Hocko, linux-kernel
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.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/fork.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 4c361d2bdc12..d3dc623a1247 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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
- mmget(mm);
- }
+ if (mm)
+ mmget(mm);
task_unlock(task);
return mm;
}
--
2.25.1.362.g51ebf55
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] get_task_mm: check PF_KTHREAD lockless
2024-06-26 19:10 [PATCH] get_task_mm: check PF_KTHREAD lockless Oleg Nesterov
@ 2024-06-27 7:49 ` Michal Hocko
0 siblings, 0 replies; 2+ messages in thread
From: Michal Hocko @ 2024-06-27 7:49 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Andrew Morton, Eric W. Biederman, linux-kernel
On Wed 26-06-24 21:10:17, Oleg Nesterov wrote:
> 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.
>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!
> ---
> kernel/fork.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 4c361d2bdc12..d3dc623a1247 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -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
> - mmget(mm);
> - }
> + if (mm)
> + mmget(mm);
> task_unlock(task);
> return mm;
> }
> --
> 2.25.1.362.g51ebf55
>
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-27 7:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-26 19:10 [PATCH] get_task_mm: check PF_KTHREAD lockless Oleg Nesterov
2024-06-27 7:49 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox