linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] stacktrace: Use PF_KTHREAD to check for kernel threads
@ 2019-07-02 15:53 Thomas Gleixner
  2019-07-02 16:17 ` Mark Rutland
  2019-07-03  7:07 ` [tip:core/stacktrace] " tip-bot for Thomas Gleixner
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Gleixner @ 2019-07-02 15:53 UTC (permalink / raw)
  To: LKML; +Cc: Josh Poimboeuf, Peter Zijlstra, Steven Rostedt

!current->mm is not a reliable indicator for kernel threads as they might
temporarily use a user mm. Check for PF_KTHREAD instead.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
--- a/kernel/stacktrace.c
+++ b/kernel/stacktrace.c
@@ -228,7 +228,7 @@ unsigned int stack_trace_save_user(unsig
 	};
 
 	/* Trace user stack if not a kernel thread */
-	if (!current->mm)
+	if (current->flags & PF_KTHREAD)
 		return 0;
 
 	arch_stack_walk_user(consume_entry, &c, task_pt_regs(current));

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] stacktrace: Use PF_KTHREAD to check for kernel threads
  2019-07-02 15:53 [PATCH] stacktrace: Use PF_KTHREAD to check for kernel threads Thomas Gleixner
@ 2019-07-02 16:17 ` Mark Rutland
  2019-07-03  7:07 ` [tip:core/stacktrace] " tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Rutland @ 2019-07-02 16:17 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: LKML, Josh Poimboeuf, Peter Zijlstra, Steven Rostedt

On Tue, Jul 02, 2019 at 05:53:35PM +0200, Thomas Gleixner wrote:
> !current->mm is not a reliable indicator for kernel threads as they might
> temporarily use a user mm. Check for PF_KTHREAD instead.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

FWIW:

Acked-by: Mark Rutland <mark.rutland@arm.com>

As a heads-up, I started looking into cleaning up bogus mm checks
tree-wide, since there are a number that look suspicious (e.g. arm64's
arch_dup_task_struct() and x86's __kernel_fpu_begin()).

I was hoping to add an is_kthread(tsk) helper to push people in the
right direction [1].

Thanks,
Mark.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=sched/kthread-cleanup

> ---
> --- a/kernel/stacktrace.c
> +++ b/kernel/stacktrace.c
> @@ -228,7 +228,7 @@ unsigned int stack_trace_save_user(unsig
>  	};
>  
>  	/* Trace user stack if not a kernel thread */
> -	if (!current->mm)
> +	if (current->flags & PF_KTHREAD)
>  		return 0;
>  
>  	arch_stack_walk_user(consume_entry, &c, task_pt_regs(current));

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:core/stacktrace] stacktrace: Use PF_KTHREAD to check for kernel threads
  2019-07-02 15:53 [PATCH] stacktrace: Use PF_KTHREAD to check for kernel threads Thomas Gleixner
  2019-07-02 16:17 ` Mark Rutland
@ 2019-07-03  7:07 ` tip-bot for Thomas Gleixner
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Thomas Gleixner @ 2019-07-03  7:07 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: rostedt, tglx, hpa, peterz, linux-kernel, mark.rutland, mingo, jpoimboe

Commit-ID:  7e8e6816c6495a1168f9a7a50125d82c23e59300
Gitweb:     https://git.kernel.org/tip/7e8e6816c6495a1168f9a7a50125d82c23e59300
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 2 Jul 2019 17:53:35 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 3 Jul 2019 09:04:06 +0200

stacktrace: Use PF_KTHREAD to check for kernel threads

!current->mm is not a reliable indicator for kernel threads as they might
temporarily use a user mm. Check for PF_KTHREAD instead.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1907021750100.1802@nanos.tec.linutronix.de

---
 kernel/stacktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c
index 36139de0a3c4..c8d0f05721a1 100644
--- a/kernel/stacktrace.c
+++ b/kernel/stacktrace.c
@@ -228,7 +228,7 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size)
 	};
 
 	/* Trace user stack if not a kernel thread */
-	if (!current->mm)
+	if (current->flags & PF_KTHREAD)
 		return 0;
 
 	arch_stack_walk_user(consume_entry, &c, task_pt_regs(current));

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-03  7:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-02 15:53 [PATCH] stacktrace: Use PF_KTHREAD to check for kernel threads Thomas Gleixner
2019-07-02 16:17 ` Mark Rutland
2019-07-03  7:07 ` [tip:core/stacktrace] " tip-bot for Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).