Re: [PATCH v6 11/18] perf: Use current->flags & PF_KTHREAD instead of current->mm == NULL

Steven Rostedt
2025-04-25T17:32:22Z

On Fri, 25 Apr 2025 08:09:55 -0700
Josh Poimboeuf <jpoimboe@kernel.org> wrote:

> On Fri, Apr 25, 2025 at 10:54:33AM -0400, Steven Rostedt wrote:
> > From: Steven Rostedt <rostedt@goodmis.org>
> >
> > To determine if a task is a kernel thread or not, it is more reliable to
> > use (current->flags & PF_KTHREAD) than to rely on current->mm being NULL.
> > That is because some kernel tasks (io_uring helpers) may have a mm field.
>
> There's a current->mm check in the user space unwinder (patch 1) which
> should probably also be converted.

Bah! OK.

I also plan on creating a couple of macros and running a coccinelle script
to replace all instances in the kernel of:

!(task->flags & PF_KTHREAD) into is_user_thread(task)

and

(task->flags & PF_KTHREAD) into is_kernel_thread(task)

As I've already screwed up missing the '!' (or adding it) a couple of
times. But caught it before posting the patches.

-- Steve