linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-kernel@vger.kernel.org
Cc: ak@linux.intel.com, akpm@linux-foundation.org,
	bigeasy@linutronix.de, bp@suse.de, catalin.marinas@arm.com,
	davem@davemloft.net, hch@lst.de, kan.liang@intel.com,
	mark.rutland@arm.com, mingo@kernel.org, peterz@infradead.org,
	riel@surriel.com, will@kernel.org
Subject: [PATCH 0/9] kthread detection cleanup
Date: Wed, 14 Aug 2019 11:41:22 +0100	[thread overview]
Message-ID: <20190814104131.20190-1-mark.rutland@arm.com> (raw)

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(-)

-- 
2.11.0


             reply	other threads:[~2019-08-14 10:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-14 10:41 Mark Rutland [this message]
2019-08-14 10:41 ` [PATCH 1/9] sched/core: add is_kthread() helper Mark Rutland
2019-08-14 11:26   ` Geert Uytterhoeven
2019-08-14 11:32     ` Mark Rutland
2019-08-19  8:52       ` Ingo Molnar
2019-08-21 11:21         ` Peter Zijlstra
2019-08-14 10:41 ` [PATCH 2/9] sched: treewide: use is_kthread() Mark Rutland
2019-08-14 11:27   ` Geert Uytterhoeven
2019-08-14 12:39   ` Sebastian Andrzej Siewior
2019-08-14 13:35     ` Mark Rutland
2019-08-14 13:37   ` Valentin Schneider
2019-08-14 10:41 ` [PATCH 3/9] kmemleak: correctly check for kthreads Mark Rutland
2019-08-14 16:39   ` Catalin Marinas
2019-08-14 10:41 ` [PATCH 4/9] arm/perf: " Mark Rutland
2019-08-14 10:41 ` [PATCH 5/9] arm64: correctly check for ktrheads Mark Rutland
2019-08-14 16:40   ` Catalin Marinas
2019-08-14 10:41 ` [PATCH 6/9] sparc/perf: correctly check for kthreads Mark Rutland
2019-08-14 16:26   ` David Miller
2019-08-14 10:41 ` [PATCH 7/9] x86/lbr: " Mark Rutland
2019-08-14 10:41 ` [PATCH 8/9] x86/fpu: " Mark Rutland
2019-08-14 13:07   ` Sebastian Andrzej Siewior
2019-08-14 13:39     ` Mark Rutland
2019-08-14 14:55       ` Sebastian Andrzej Siewior
2019-08-14 10:41 ` [PATCH 9/9] samples/kretprobe: " Mark Rutland
2019-08-14 13:43 ` [PATCH 0/9] kthread detection cleanup Valentin Schneider

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190814104131.20190-1-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=bp@suse.de \
    --cc=catalin.marinas@arm.com \
    --cc=davem@davemloft.net \
    --cc=hch@lst.de \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).