* [PATCH] get_task_exe_file: check PF_KTHREAD locklessly
@ 2024-11-19 14:35 Mateusz Guzik
2024-11-19 15:05 ` Oleg Nesterov
2024-11-22 6:35 ` Andrew Morton
0 siblings, 2 replies; 3+ messages in thread
From: Mateusz Guzik @ 2024-11-19 14:35 UTC (permalink / raw)
To: akpm; +Cc: oleg, linux-kernel, Mateusz Guzik
Same thing as 8ac5dc66599c ("get_task_mm: check PF_KTHREAD lockless")
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
kernel/fork.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 22f43721d031..759902828e13 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1500,12 +1500,13 @@ struct file *get_task_exe_file(struct task_struct *task)
struct file *exe_file = NULL;
struct mm_struct *mm;
+ if (task->flags & PF_KTHREAD)
+ return NULL;
+
task_lock(task);
mm = task->mm;
- if (mm) {
- if (!(task->flags & PF_KTHREAD))
- exe_file = get_mm_exe_file(mm);
- }
+ if (mm)
+ exe_file = get_mm_exe_file(mm);
task_unlock(task);
return exe_file;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] get_task_exe_file: check PF_KTHREAD locklessly
2024-11-19 14:35 [PATCH] get_task_exe_file: check PF_KTHREAD locklessly Mateusz Guzik
@ 2024-11-19 15:05 ` Oleg Nesterov
2024-11-22 6:35 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2024-11-19 15:05 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: akpm, linux-kernel
On 11/19, Mateusz Guzik wrote:
>
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1500,12 +1500,13 @@ struct file *get_task_exe_file(struct task_struct *task)
> struct file *exe_file = NULL;
> struct mm_struct *mm;
>
> + if (task->flags & PF_KTHREAD)
> + return NULL;
> +
> task_lock(task);
> mm = task->mm;
> - if (mm) {
> - if (!(task->flags & PF_KTHREAD))
> - exe_file = get_mm_exe_file(mm);
> - }
> + if (mm)
> + exe_file = get_mm_exe_file(mm);
> task_unlock(task);
> return exe_file;
Acked-by: Oleg Nesterov <oleg@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] get_task_exe_file: check PF_KTHREAD locklessly
2024-11-19 14:35 [PATCH] get_task_exe_file: check PF_KTHREAD locklessly Mateusz Guzik
2024-11-19 15:05 ` Oleg Nesterov
@ 2024-11-22 6:35 ` Andrew Morton
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2024-11-22 6:35 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: oleg, linux-kernel
On Tue, 19 Nov 2024 15:35:26 +0100 Mateusz Guzik <mjguzik@gmail.com> wrote:
> Same thing as 8ac5dc66599c ("get_task_mm: check PF_KTHREAD lockless")
We prefer that patches have fuller changelogs, please.
I copied the 8ac5dc66599c changelog text into this patch's changelog.
From: Mateusz Guzik <mjguzik@gmail.com>
Subject: get_task_exe_file: check PF_KTHREAD locklessly
Date: Tue, 19 Nov 2024 15:35:26 +0100
Same thing as 8ac5dc66599c ("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/20241119143526.704986-1-mjguzik@gmail.com
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
kernel/fork.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
--- a/kernel/fork.c~get_task_exe_file-check-pf_kthread-locklessly
+++ a/kernel/fork.c
@@ -1496,12 +1496,13 @@ struct file *get_task_exe_file(struct ta
struct file *exe_file = NULL;
struct mm_struct *mm;
+ if (task->flags & PF_KTHREAD)
+ return NULL;
+
task_lock(task);
mm = task->mm;
- if (mm) {
- if (!(task->flags & PF_KTHREAD))
- exe_file = get_mm_exe_file(mm);
- }
+ if (mm)
+ exe_file = get_mm_exe_file(mm);
task_unlock(task);
return exe_file;
}
_
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-22 6:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-19 14:35 [PATCH] get_task_exe_file: check PF_KTHREAD locklessly Mateusz Guzik
2024-11-19 15:05 ` Oleg Nesterov
2024-11-22 6:35 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox