Skip to content

kthread detection cleanup

Mark Rutland lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 15 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9sched/core: add is_kthread() helperinclude/linux/sched.h+12 -14 replies
2/9sched: treewide: use is_kthread()arch/alpha/kernel/process.c arch/arc/kernel/process.c arch/arm/kernel/process.c +57 more+76 -764 replies
3/9kmemleak: correctly check for kthreadsmm/kmemleak.c+3 -31 reply
4/9arm/perf: correctly check for kthreadsarch/arm/kernel/perf_callchain.c+1 -10 replies
5/9arm64: correctly check for ktrheadsarch/arm64/kernel/process.c+1 -11 reply
6/9sparc/perf: correctly check for kthreadsarch/sparc/kernel/perf_event.c+1 -11 reply
7/9x86/lbr: correctly check for kthreadsarch/x86/events/intel/lbr.c+1 -10 replies
8/9x86/fpu: correctly check for kthreadsarch/x86/include/asm/fpu/internal.h+1 -13 replies
9/9samples/kretprobe: correctly check for kthreadssamples/kprobes/kretprobe_example.c+1 -10 replies

Reviews trailers per patch

5 of 9 patches have a Reviewed-by or Acked-by.

PatchGeert UytterhoevenSebastian Andrzej SiewiorValentin SchneiderDavid S. MillerCatalin Marinas
1/9
2/9A-b A-b R-b
3/9A-b
4/9
5/9A-b
6/9A-b
7/9
8/9A-b
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v1 thread

Cover letter [PATCH 0/9] kthread detection cleanup

A reasonable amount of kernel code looks at task_struct::mm to determine whether a thread is a kthread or a real user task. This isn't quite right, since kthreads can have a non-NULL mm when calling use_mm().

The correct way to check whether a task is a kthread is to check whether PF_KTHREAD is set in task_struct::flags, but doing so is a bit unwieldy.

To make this a bit nicer, this series adds a new is_kthread(tsk) helper, converts existing code to make use of it, and fixes up a number of erroneous checks of current->mm. Hopefully this will push people to use the right approach in future.

I'm sure there are other instances in the kernel tree where we don't check this correctly. In this series I'm just trying to fix the instances I'm reasonably confident are incorrect.

This series is based on v5.3-rc3, and I've pushed it out to my sched/kthread-cleanup branch on kernel.org [1,2].

Thanks,
Mark.

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

Mark Rutland (9):
sched/core: add is_kthread() helper
sched: treewide: use is_kthread()
kmemleak: correctly check for kthreads
arm/perf: correctly check for kthreads
arm64: correctly check for ktrheads
sparc/perf: correctly check for kthreads
x86/lbr: correctly check for kthreads
x86/fpu: correctly check for kthreads
samples/kretprobe: correctly check for kthreads

 arch/alpha/kernel/process.c         |  2 +-
 arch/arc/kernel/process.c           |  2 +-
 arch/arm/kernel/perf_callchain.c    |  2 +-
 arch/arm/kernel/process.c           |  2 +-
 arch/arm/mm/init.c                  |  2 +-
 arch/arm64/kernel/process.c         |  6 +++---
 arch/c6x/kernel/process.c           |  2 +-
 arch/csky/kernel/process.c          |  2 +-
 arch/h8300/kernel/process.c         |  2 +-
 arch/hexagon/kernel/process.c       |  2 +-
 arch/ia64/kernel/process.c          |  2 +-
 arch/m68k/kernel/process.c          |  2 +-
 arch/microblaze/kernel/process.c    |  2 +-
 arch/mips/kernel/process.c          |  4 ++--
 arch/nds32/kernel/process.c         |  4 ++--
 arch/nios2/kernel/process.c         |  2 +-
 arch/openrisc/kernel/process.c      |  2 +-
 arch/parisc/kernel/process.c        |  2 +-
 arch/powerpc/kernel/process.c       |  2 +-
 arch/riscv/kernel/process.c         |  2 +-
 arch/s390/kernel/process.c          |  2 +-
 arch/sh/kernel/process_32.c         |  2 +-
 arch/sh/kernel/process_64.c         |  2 +-
 arch/sparc/kernel/perf_event.c      |  2 +-
 arch/sparc/kernel/process_32.c      |  2 +-
 arch/sparc/kernel/process_64.c      |  2 +-
 arch/um/kernel/process.c            |  2 +-
 arch/unicore32/kernel/process.c     |  2 +-
 arch/x86/events/intel/lbr.c         |  2 +-
 arch/x86/include/asm/fpu/internal.h |  2 +-
 arch/x86/kernel/fpu/core.c          |  2 +-
 arch/x86/kernel/process_32.c        |  2 +-
 arch/x86/kernel/process_64.c        |  2 +-
 arch/xtensa/kernel/process.c        |  2 +-
 block/blk-cgroup.c                  |  2 +-
 drivers/tty/sysrq.c                 |  2 +-
 fs/coredump.c                       |  2 +-
 fs/file_table.c                     |  4 ++--
 fs/namespace.c                      |  2 +-
 fs/proc/base.c                      |  4 ++--
 include/linux/cgroup.h              |  2 +-
 include/linux/sched.h               | 13 ++++++++++++-
 kernel/cgroup/freezer.c             |  4 ++--
 kernel/events/core.c                |  2 +-
 kernel/exit.c                       |  2 +-
 kernel/fork.c                       |  6 +++---
 kernel/freezer.c                    |  4 ++--
 kernel/futex.c                      |  2 +-
 kernel/kthread.c                    |  6 +++---
 kernel/livepatch/transition.c       |  2 +-
 kernel/ptrace.c                     |  2 +-
 kernel/sched/core.c                 |  8 ++++----
 kernel/sched/idle.c                 |  2 +-
 kernel/sched/wait.c                 |  2 +-
 kernel/signal.c                     |  2 +-
 kernel/stacktrace.c                 |  2 +-
 lib/is_single_threaded.c            |  2 +-
 mm/kmemleak.c                       |  6 +++---
 mm/memcontrol.c                     |  2 +-
 mm/oom_kill.c                       |  4 ++--
 mm/page_alloc.c                     |  2 +-
 mm/vmacache.c                       |  2 +-
 mm/vmscan.c                         |  2 +-
 samples/kprobes/kretprobe_example.c |  2 +-
 security/smack/smack_access.c       |  2 +-
 security/smack/smack_lsm.c          |  4 ++--
 security/yama/yama_lsm.c            |  2 +-
 67 files changed, 97 insertions(+), 86 deletions(-)
Signature · 1 line
2.11.0