From patchwork Wed Aug 14 10:41:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171257 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645412ily; Wed, 14 Aug 2019 03:41:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOyyuXyDQpGCX9xT4uYZT05tNOohpvLcJmEGrAifT+x0HNoiyz8AGbqhXbFeuUpMYrpfnW X-Received: by 2002:a17:90a:a404:: with SMTP id y4mr6771002pjp.58.1565779305480; Wed, 14 Aug 2019 03:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779305; cv=none; d=google.com; s=arc-20160816; b=0A6uF5p/yYsdZqZ8L6MWvQIH4v65crtIzu7wke1ZW4sJuXdgQFUfdc2HtqkTBfF9or qpDUcBVXXrtElRIRdUKegK5F5SJDgO74qBlJmV/xodn6v/67T5MJdP/Wn1U9cdR8zBtJ G7IW/F2r6e+0LXuxyFqv/ydk9Be49MptkE4yvmetLsYASYmnPLDlJKkC4XOdKcb0D2jK JDmcuUaHhFrjeNUxqf8rljCbN2SOueT4UWNy4+4D86Q01XAuNjs63GPtu6jN1JbqgqyF ItazHAhaZYPrE8r96mrkroUc4F5GXmmAvb/ZX7pRV+L69raepy/CUMaTJiBwuHuZRlco ey/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=HdY5W0mGwDCOdDZLMtw3do16jjfhpkXUOCe2yQ2GUDY=; b=L9ve2wMKB735m9qGome/mkd+Z5A55F/jwm5Xnv+BNvgARkJVMkrXJwmUQcf7o6jf4w lSJOWDMgzsJotH5kx2Z3p9SNw5DtmuiLc15rBsi5A/7I+TJI5xFZoHnSCXKpJIzjppWO QaXD8trJoktZg/0SB1+0tzaHQ3+rJkOSk6a+Xn7NUtidhxhUg+7vBKVEerCi2JarV7N4 nszw+8acd3n37dF6dcya6DK4EH2p8J5JcHk5x+lUuTZPaIWcHprB9Ax9d0H3k2XAv16w 3z3ED/HKE1y0VbIyGgo49FKwTFJxurc9oMPe4njzz0Dkd0JgIWa8kyfG8+elJ5FX/jEj mWwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k133si63889896pgc.425.2019.08.14.03.41.45; Wed, 14 Aug 2019 03:41:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727081AbfHNKln (ORCPT + 28 others); Wed, 14 Aug 2019 06:41:43 -0400 Received: from foss.arm.com ([217.140.110.172]:51832 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfHNKll (ORCPT ); Wed, 14 Aug 2019 06:41:41 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4671B360; Wed, 14 Aug 2019 03:41:41 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7ABDE3F706; Wed, 14 Aug 2019 03:41:39 -0700 (PDT) From: Mark Rutland 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 1/9] sched/core: add is_kthread() helper Date: Wed, 14 Aug 2019 11:41:23 +0100 Message-Id: <20190814104131.20190-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Code checking whether a task is a kthread isn't very consistent. Some code correctly tests task->flags & PF_THREAD, while other code checks task->mm (which can be true for a kthread which calls use_mm()). So that we can clean this up and keep the code easy to follow, let's add an obvious helper function to test whether a task is a kthread. Subsequent patches will use this as part of cleaning up and correcting open-coded tests. At the same time, let's fix up the kerneldoc for is_idle_task() for consistency with the new helper, using true/false rather than 0/1, given the functions return bool. Signed-off-by: Mark Rutland Cc: Ingo Molnar Cc: Peter Zijlstra --- include/linux/sched.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/include/linux/sched.h b/include/linux/sched.h index 9f51932bd543..b7e96409d75f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1621,13 +1621,24 @@ extern struct task_struct *idle_task(int cpu); * is_idle_task - is the specified task an idle task? * @p: the task in question. * - * Return: 1 if @p is an idle task. 0 otherwise. + * Return: true if @p is an idle task, false otherwise. */ static inline bool is_idle_task(const struct task_struct *p) { return !!(p->flags & PF_IDLE); } +/** + * is_kthread - is the specified task a kthread + * @p: the task in question. + * + * Return: true if @p is a kthread, false otherwise. + */ +static inline bool is_kthread(const struct task_struct *p) +{ + return !!(p->flags & PF_KTHREAD); +} + extern struct task_struct *curr_task(int cpu); extern void ia64_set_curr_task(int cpu, struct task_struct *p); From patchwork Wed Aug 14 10:41:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171258 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645468ily; Wed, 14 Aug 2019 03:41:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHT1XUoxg03XEO+cCjUQvoCA1wvpfAq9F40AxnMLMVZEay0uo5X5PwgveKAfPot+aQaduh X-Received: by 2002:a63:ff0c:: with SMTP id k12mr36774920pgi.186.1565779308430; Wed, 14 Aug 2019 03:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779308; cv=none; d=google.com; s=arc-20160816; b=jNGp3OWtoSg+bTGk4e+7pvgeubri8YqZWWUgJawLJMuoE9pZ2MmGENtTVJD6rjny+l FQb328iQSMK7LZQIlhZhgYEMFmRTXNRvfNdCGhpgOui9tsMnbFV4/6skRlUYys3h5P7r dBuHICmvxzTaOrjWsr/ghEtwH0sBTftb8Pad6/i+W7F0Io9aNH2wgkeIekXgQJmU+yiv 1wwzvZ/qb8bP9depN3qcOJZvoJAgE47GhtbfdB4Cz6mDbWnvPMuEcyPQZpBvG1Vfpb6o 6jg3CoCOMOks5f0n7f7HOgaINDoodshlGTFcF9yA+zgAnBKymObxw+D6a8YCLr0od7fq Dxww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=U7nBp0iQEd4CuYmDLVeGOBZwcuTFNXnamZHYPp8u5fw=; b=z/ABM58hkkvEFVHnrysuvM8pV3j5p3YPJDH+cKWC/SKdtehEl02bEIAE7c5ChIgzqK 59abD9oVdcXyUMn9Pr2Yn7ldXa738fdnEslVf+1ZIlWn1JDajEuAFhlNME/0SrBSoE9v nkPmaI82Q7Xy9tACAUN4kswE0bgZHTIgnyIs4KihSCovO+01brc7pwxJEfQXrMTRbY1l 2Shnaaw629bfogy5hJ4Iqtqta2ymJoWxhDD2yrAfDZmgS3uIoUQ49Z4d1l0NnldpxxXQ 7JoesrdXEiyUCJ6Hc8pQ4hoiX8zQjdzbVxmVO1znczL4FtWD4hc4wXXyS0DD5e7IqP3S jBOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67si71503363pfv.74.2019.08.14.03.41.48; Wed, 14 Aug 2019 03:41:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbfHNKlr (ORCPT + 28 others); Wed, 14 Aug 2019 06:41:47 -0400 Received: from foss.arm.com ([217.140.110.172]:51858 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfHNKlo (ORCPT ); Wed, 14 Aug 2019 06:41:44 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E5A811570; Wed, 14 Aug 2019 03:41:43 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E41503F706; Wed, 14 Aug 2019 03:41:41 -0700 (PDT) From: Mark Rutland 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 2/9] sched: treewide: use is_kthread() Date: Wed, 14 Aug 2019 11:41:24 +0100 Message-Id: <20190814104131.20190-3-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have is_kthread(), let's convert existing open-coded checks of the form: task->flags & PF_KTHREAD ... over to the new helper, which makes things a little easier to read, and sets a consistent example for new code to follow. Generated with coccinelle: ---- virtual patch @ depends on patch @ expression E; @@ - (E->flags & PF_KTHREAD) + is_kthread(E) ---- ... though this didn't pick up the instance in , which I fixed up manually. Instances checking multiple PF_* flags at ocne are left as-is for now. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Cc: Ingo Molnar Cc: Peter Zijlstra --- arch/alpha/kernel/process.c | 2 +- arch/arc/kernel/process.c | 2 +- arch/arm/kernel/process.c | 2 +- arch/arm/mm/init.c | 2 +- arch/arm64/kernel/process.c | 4 ++-- 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/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/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 +- 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/memcontrol.c | 2 +- mm/oom_kill.c | 4 ++-- mm/page_alloc.c | 2 +- mm/vmacache.c | 2 +- mm/vmscan.c | 2 +- security/smack/smack_access.c | 2 +- security/smack/smack_lsm.c | 4 ++-- security/yama/yama_lsm.c | 2 +- 60 files changed, 76 insertions(+), 76 deletions(-) -- 2.11.0 Acked-by: Geert Uytterhoeven Acked-by: Sebastian Andrzej Siewior Reviewed-by: Valentin Schneider diff --git a/arch/alpha/kernel/process.c b/arch/alpha/kernel/process.c index 48b81d015d8a..e99ec5fab586 100644 --- a/arch/alpha/kernel/process.c +++ b/arch/alpha/kernel/process.c @@ -251,7 +251,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp, childti->pcb.ksp = (unsigned long) childstack; childti->pcb.flags = 1; /* set FEN, clear everything else */ - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ memset(childstack, 0, sizeof(struct switch_stack) + sizeof(struct pt_regs)); diff --git a/arch/arc/kernel/process.c b/arch/arc/kernel/process.c index e1889ce3faf9..f4cf6e9311cd 100644 --- a/arch/arc/kernel/process.c +++ b/arch/arc/kernel/process.c @@ -200,7 +200,7 @@ int copy_thread(unsigned long clone_flags, childksp[0] = 0; /* fp */ childksp[1] = (unsigned long)ret_from_fork; /* blink */ - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(c_regs, 0, sizeof(struct pt_regs)); c_callee->r13 = kthread_arg; diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index f934a6739fc0..899ead9b1336 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -242,7 +242,7 @@ copy_thread(unsigned long clone_flags, unsigned long stack_start, thread->cpu_domain = get_domain(); #endif - if (likely(!(p->flags & PF_KTHREAD))) { + if (likely(!is_kthread(p))) { *childregs = *current_pt_regs(); childregs->ARM_r0 = 0; if (stack_start) diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 16d373d587c4..0b568802d400 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -625,7 +625,7 @@ static void update_sections_early(struct section_perm perms[], int n) struct task_struct *t, *s; for_each_process(t) { - if (t->flags & PF_KTHREAD) + if (is_kthread(t)) continue; for_each_thread(t, s) set_section_perms(perms, n, true, s->mm); diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index f674f28df663..288012687c29 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -367,7 +367,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, */ fpsimd_flush_task_state(p); - if (likely(!(p->flags & PF_KTHREAD))) { + if (likely(!is_kthread(p))) { *childregs = *current_pt_regs(); childregs->regs[0] = 0; @@ -454,7 +454,7 @@ static void ssbs_thread_switch(struct task_struct *next) * Nothing to do for kernel threads, but 'regs' may be junk * (e.g. idle task) so check the flags and bail early. */ - if (unlikely(next->flags & PF_KTHREAD)) + if (unlikely(is_kthread(next))) return; /* If the mitigation is enabled, then we leave SSBS clear. */ diff --git a/arch/c6x/kernel/process.c b/arch/c6x/kernel/process.c index cb9c8b63cddd..942bc45b7395 100644 --- a/arch/c6x/kernel/process.c +++ b/arch/c6x/kernel/process.c @@ -112,7 +112,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, childregs = task_pt_regs(p); - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* case of __kernel_thread: we return to supervisor space */ memset(childregs, 0, sizeof(struct pt_regs)); childregs->sp = (unsigned long)(childregs + 1); diff --git a/arch/csky/kernel/process.c b/arch/csky/kernel/process.c index e555740c0be5..671b061ee785 100644 --- a/arch/csky/kernel/process.c +++ b/arch/csky/kernel/process.c @@ -52,7 +52,7 @@ int copy_thread(unsigned long clone_flags, /* setup ksp for switch_to !!! */ p->thread.ksp = (unsigned long)childstack; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(childregs, 0, sizeof(struct pt_regs)); childstack->r15 = (unsigned long) ret_from_kernel_thread; childstack->r8 = kthread_arg; diff --git a/arch/h8300/kernel/process.c b/arch/h8300/kernel/process.c index e35cdf092e07..e9beda6d5760 100644 --- a/arch/h8300/kernel/process.c +++ b/arch/h8300/kernel/process.c @@ -114,7 +114,7 @@ int copy_thread(unsigned long clone_flags, childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(childregs, 0, sizeof(struct pt_regs)); childregs->retpc = (unsigned long) ret_from_kernel_thread; childregs->er4 = topstk; /* arg */ diff --git a/arch/hexagon/kernel/process.c b/arch/hexagon/kernel/process.c index ac07f5f4b76b..1f9e6787d07d 100644 --- a/arch/hexagon/kernel/process.c +++ b/arch/hexagon/kernel/process.c @@ -73,7 +73,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, sizeof(*ss)); ss->lr = (unsigned long)ret_from_fork; p->thread.switch_sp = ss; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(childregs, 0, sizeof(struct pt_regs)); /* r24 <- fn, r25 <- arg */ ss->r24 = usp; diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c index 968b5f33e725..3d75db83b333 100644 --- a/arch/ia64/kernel/process.c +++ b/arch/ia64/kernel/process.c @@ -376,7 +376,7 @@ copy_thread(unsigned long clone_flags, ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */ - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { if (unlikely(!user_stack_base)) { /* fork_idle() called us */ return 0; diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c index 4e77a06735c1..1adacbf17513 100644 --- a/arch/m68k/kernel/process.c +++ b/arch/m68k/kernel/process.c @@ -138,7 +138,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, */ p->thread.fs = get_fs().seg; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ memset(frame, 0, sizeof(struct fork_frame)); frame->regs.sr = PS_S; diff --git a/arch/microblaze/kernel/process.c b/arch/microblaze/kernel/process.c index 6527ec22f158..e5f5d4c04152 100644 --- a/arch/microblaze/kernel/process.c +++ b/arch/microblaze/kernel/process.c @@ -60,7 +60,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, struct pt_regs *childregs = task_pt_regs(p); struct thread_info *ti = task_thread_info(p); - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* if we're creating a new kernel thread then just zeroing all * the registers. That's OK for a brand new thread.*/ memset(childregs, 0, sizeof(struct pt_regs)); diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index 339870ed92f7..8a5a2216558e 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -87,7 +87,7 @@ void exit_thread(struct task_struct *tsk) * User threads may have allocated a delay slot emulation frame. * If so, clean up that allocation. */ - if (!(current->flags & PF_KTHREAD)) + if (!is_kthread(current)) dsemul_thread_cleanup(tsk); } @@ -132,7 +132,7 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp, /* Put the stack after the struct pt_regs. */ childksp = (unsigned long) childregs; p->thread.cp0_status = read_c0_status() & ~(ST0_CU2|ST0_CU1); - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ unsigned long status = p->thread.cp0_status; memset(childregs, 0, sizeof(struct pt_regs)); diff --git a/arch/nds32/kernel/process.c b/arch/nds32/kernel/process.c index 9712fd474f2c..5d88ca5d3621 100644 --- a/arch/nds32/kernel/process.c +++ b/arch/nds32/kernel/process.c @@ -156,7 +156,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start, memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context)); - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(childregs, 0, sizeof(struct pt_regs)); /* kernel thread fn */ p->thread.cpu_context.r6 = stack_start; @@ -207,7 +207,7 @@ struct task_struct *_switch_fpu(struct task_struct *prev, struct task_struct *ne #if !IS_ENABLED(CONFIG_LAZY_FPU) unlazy_fpu(prev); #endif - if (!(next->flags & PF_KTHREAD)) + if (!is_kthread(next)) clear_fpu(task_pt_regs(next)); return prev; } diff --git a/arch/nios2/kernel/process.c b/arch/nios2/kernel/process.c index 509e7855e8dc..f13eb8c23fc8 100644 --- a/arch/nios2/kernel/process.c +++ b/arch/nios2/kernel/process.c @@ -109,7 +109,7 @@ int copy_thread(unsigned long clone_flags, struct switch_stack *childstack = ((struct switch_stack *)childregs) - 1; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(childstack, 0, sizeof(struct switch_stack) + sizeof(struct pt_regs)); diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c index b06f84f6676f..cf79967202dd 100644 --- a/arch/openrisc/kernel/process.c +++ b/arch/openrisc/kernel/process.c @@ -168,7 +168,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp, sp -= sizeof(struct pt_regs); kregs = (struct pt_regs *)sp; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(kregs, 0, sizeof(struct pt_regs)); kregs->gpr[20] = usp; /* fn, kernel thread */ kregs->gpr[22] = arg; diff --git a/arch/parisc/kernel/process.c b/arch/parisc/kernel/process.c index ecc5c2771208..774ebf61323e 100644 --- a/arch/parisc/kernel/process.c +++ b/arch/parisc/kernel/process.c @@ -220,7 +220,7 @@ copy_thread(unsigned long clone_flags, unsigned long usp, extern void * const ret_from_kernel_thread; extern void * const child_return; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ memset(cregs, 0, sizeof(struct pt_regs)); if (!usp) /* idle thread */ diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 8fc4de0d22b4..411c7e8046eb 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -1615,7 +1615,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, /* Copy registers */ sp -= sizeof(struct pt_regs); childregs = (struct pt_regs *) sp; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ memset(childregs, 0, sizeof(struct pt_regs)); childregs->gpr[1] = sp + sizeof(struct pt_regs); diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c index f23794bd1e90..08b6dfc6dc54 100644 --- a/arch/riscv/kernel/process.c +++ b/arch/riscv/kernel/process.c @@ -96,7 +96,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, struct pt_regs *childregs = task_pt_regs(p); /* p->thread holds context to be restored by __switch_to() */ - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* Kernel thread */ const register unsigned long gp __asm__ ("gp"); memset(childregs, 0, sizeof(struct pt_regs)); diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c index 63873aa6693f..4802a4014f15 100644 --- a/arch/s390/kernel/process.c +++ b/arch/s390/kernel/process.c @@ -113,7 +113,7 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long new_stackp, frame->sf.gprs[9] = (unsigned long) frame; /* Store access registers to kernel stack of new process. */ - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ memset(&frame->childregs, 0, sizeof(struct pt_regs)); frame->childregs.psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT | diff --git a/arch/sh/kernel/process_32.c b/arch/sh/kernel/process_32.c index a094633874c3..8cd8f2025bf0 100644 --- a/arch/sh/kernel/process_32.c +++ b/arch/sh/kernel/process_32.c @@ -137,7 +137,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, childregs = task_pt_regs(p); p->thread.sp = (unsigned long) childregs; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(childregs, 0, sizeof(struct pt_regs)); p->thread.pc = (unsigned long) ret_from_kernel_thread; childregs->regs[4] = arg; diff --git a/arch/sh/kernel/process_64.c b/arch/sh/kernel/process_64.c index c2844a2e18cd..9c9c6b1efc17 100644 --- a/arch/sh/kernel/process_64.c +++ b/arch/sh/kernel/process_64.c @@ -389,7 +389,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1; p->thread.sp = (unsigned long) childregs; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(childregs, 0, sizeof(struct pt_regs)); childregs->regs[2] = (unsigned long)arg; childregs->regs[3] = (unsigned long)usp; diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c index 26cca65e9246..0c9ec7c8b8ad 100644 --- a/arch/sparc/kernel/process_32.c +++ b/arch/sparc/kernel/process_32.c @@ -338,7 +338,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, ti->ksp = (unsigned long) new_stack; p->thread.kregs = childregs; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { extern int nwindows; unsigned long psr; memset(new_stack, 0, STACKFRAME_SZ + TRACEREG_SZ); diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c index 4282116e28e7..e98db3ba97c1 100644 --- a/arch/sparc/kernel/process_64.c +++ b/arch/sparc/kernel/process_64.c @@ -632,7 +632,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, sizeof(struct sparc_stackf)); t->fpsaved[0] = 0; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { memset(child_trap_frame, 0, child_stack_sz); __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] = (current_pt_regs()->tstate + 1) & TSTATE_CWP; diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 67c0d1a860e9..58d26a08719d 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -157,7 +157,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg, struct task_struct * p) { void (*handler)(void); - int kthread = current->flags & PF_KTHREAD; + int kthread = is_kthread(current); int ret = 0; p->thread = (struct thread_struct) INIT_THREAD; diff --git a/arch/unicore32/kernel/process.c b/arch/unicore32/kernel/process.c index b4fd3a604a18..a48ee8b317b9 100644 --- a/arch/unicore32/kernel/process.c +++ b/arch/unicore32/kernel/process.c @@ -228,7 +228,7 @@ copy_thread(unsigned long clone_flags, unsigned long stack_start, memset(&thread->cpu_context, 0, sizeof(struct cpu_context_save)); thread->cpu_context.sp = (unsigned long)childregs; - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { thread->cpu_context.pc = (unsigned long)ret_from_kernel_thread; thread->cpu_context.r4 = stack_start; thread->cpu_context.r5 = stk_sz; diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 12c70840980e..52a7ac55f89a 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -91,7 +91,7 @@ void kernel_fpu_begin(void) this_cpu_write(in_kernel_fpu, true); - if (!(current->flags & PF_KTHREAD) && + if (!is_kthread(current) && !test_thread_flag(TIF_NEED_FPU_LOAD)) { set_thread_flag(TIF_NEED_FPU_LOAD); /* diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c index b8ceec4974fe..8263c37fac2b 100644 --- a/arch/x86/kernel/process_32.c +++ b/arch/x86/kernel/process_32.c @@ -134,7 +134,7 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp, p->thread.sp0 = (unsigned long) (childregs+1); memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps)); - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ memset(childregs, 0, sizeof(struct pt_regs)); frame->bx = sp; /* function */ diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index af64519b2695..85375eb3cff1 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -397,7 +397,7 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp, savesegment(ds, p->thread.ds); memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps)); - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { /* kernel thread */ memset(childregs, 0, sizeof(struct pt_regs)); frame->bx = sp; /* function */ diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c index db278a9e80c7..1dc0c67a55b3 100644 --- a/arch/xtensa/kernel/process.c +++ b/arch/xtensa/kernel/process.c @@ -217,7 +217,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn, p->thread.sp = (unsigned long)childregs; - if (!(p->flags & PF_KTHREAD)) { + if (!is_kthread(p)) { struct pt_regs *regs = current_pt_regs(); unsigned long usp = usp_thread_fn ? usp_thread_fn : regs->areg[1]; diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 55a7dc227dfb..44ea9f371e60 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1739,7 +1739,7 @@ void blkcg_maybe_throttle_current(void) */ void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay) { - if (unlikely(current->flags & PF_KTHREAD)) + if (unlikely(is_kthread(current))) return; if (!blk_get_queue(q)) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 573b2055173c..3101dba0281d 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -336,7 +336,7 @@ static void send_sig_all(int sig) read_lock(&tasklist_lock); for_each_process(p) { - if (p->flags & PF_KTHREAD) + if (is_kthread(p)) continue; if (is_global_init(p)) continue; diff --git a/fs/coredump.c b/fs/coredump.c index b1ea7dfbd149..03ecf67d783e 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -412,7 +412,7 @@ static int zap_threads(struct task_struct *tsk, struct mm_struct *mm, for_each_process(g) { if (g == tsk->group_leader) continue; - if (g->flags & PF_KTHREAD) + if (is_kthread(g)) continue; for_each_thread(g, p) { diff --git a/fs/file_table.c b/fs/file_table.c index b07b53f24ff5..ce793b771a18 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -335,7 +335,7 @@ void fput_many(struct file *file, unsigned int refs) if (atomic_long_sub_and_test(refs, &file->f_count)) { struct task_struct *task = current; - if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) { + if (likely(!in_interrupt() && !is_kthread(task))) { init_task_work(&file->f_u.fu_rcuhead, ____fput); if (!task_work_add(task, &file->f_u.fu_rcuhead, true)) return; @@ -368,7 +368,7 @@ void __fput_sync(struct file *file) { if (atomic_long_dec_and_test(&file->f_count)) { struct task_struct *task = current; - BUG_ON(!(task->flags & PF_KTHREAD)); + BUG_ON(!is_kthread(task)); __fput(file); } } diff --git a/fs/namespace.c b/fs/namespace.c index d28d30b13043..7af913a0aee2 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1173,7 +1173,7 @@ static void mntput_no_expire(struct mount *mnt) if (likely(!(mnt->mnt.mnt_flags & MNT_INTERNAL))) { struct task_struct *task = current; - if (likely(!(task->flags & PF_KTHREAD))) { + if (likely(!is_kthread(task))) { init_task_work(&mnt->mnt_rcu, __cleanup_mnt); if (!task_work_add(task, &mnt->mnt_rcu, true)) return; diff --git a/fs/proc/base.c b/fs/proc/base.c index ebea9501afb8..0036d241ba31 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1098,7 +1098,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) continue; /* do not touch kernel threads or the global init */ - if (p->flags & PF_KTHREAD || is_global_init(p)) + if (is_kthread(p) || is_global_init(p)) continue; task_lock(p); @@ -1695,7 +1695,7 @@ void task_dump_owner(struct task_struct *task, umode_t mode, kuid_t uid; kgid_t gid; - if (unlikely(task->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(task))) { *ruid = GLOBAL_ROOT_UID; *rgid = GLOBAL_ROOT_GID; return; diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index f6b048902d6c..96f47db6281a 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -907,7 +907,7 @@ static inline bool cgroup_task_freeze(struct task_struct *task) { bool ret; - if (task->flags & PF_KTHREAD) + if (is_kthread(task)) return false; rcu_read_lock(); diff --git a/kernel/cgroup/freezer.c b/kernel/cgroup/freezer.c index 8cf010680678..eb55085f7b97 100644 --- a/kernel/cgroup/freezer.c +++ b/kernel/cgroup/freezer.c @@ -199,7 +199,7 @@ static void cgroup_do_freeze(struct cgroup *cgrp, bool freeze) * Ignore kernel threads here. Freezing cgroups containing * kthreads isn't supported. */ - if (task->flags & PF_KTHREAD) + if (is_kthread(task)) continue; cgroup_freeze_task(task, freeze); } @@ -227,7 +227,7 @@ void cgroup_freezer_migrate_task(struct task_struct *task, /* * Kernel threads are not supposed to be frozen at all. */ - if (task->flags & PF_KTHREAD) + if (is_kthread(task)) return; /* diff --git a/kernel/events/core.c b/kernel/events/core.c index 0463c1151bae..7cb753cf32cd 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5951,7 +5951,7 @@ static void perf_sample_regs_user(struct perf_regs *regs_user, if (user_mode(regs)) { regs_user->abi = perf_reg_abi(current); regs_user->regs = regs; - } else if (!(current->flags & PF_KTHREAD)) { + } else if (!is_kthread(current)) { perf_get_regs_user(regs_user, regs, regs_user_copy); } else { regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE; diff --git a/kernel/exit.c b/kernel/exit.c index 5b4a5dcce8f8..e53b291735d4 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -448,7 +448,7 @@ void mm_update_next_owner(struct mm_struct *mm) * Search through everything else, we should not get here often. */ for_each_process(g) { - if (g->flags & PF_KTHREAD) + if (is_kthread(g)) continue; for_each_thread(g, c) { if (c->mm == mm) diff --git a/kernel/fork.c b/kernel/fork.c index 2852d0e76ea3..d2e401d04971 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -459,7 +459,7 @@ void free_task(struct task_struct *tsk) ftrace_graph_exit_task(tsk); put_seccomp_filter(tsk); arch_release_task_struct(tsk); - if (tsk->flags & PF_KTHREAD) + if (is_kthread(tsk)) free_kthread_struct(tsk); free_task_struct(tsk); } @@ -1167,7 +1167,7 @@ struct file *get_task_exe_file(struct task_struct *task) task_lock(task); mm = task->mm; if (mm) { - if (!(task->flags & PF_KTHREAD)) + if (!is_kthread(task)) exe_file = get_mm_exe_file(mm); } task_unlock(task); @@ -1191,7 +1191,7 @@ struct mm_struct *get_task_mm(struct task_struct *task) task_lock(task); mm = task->mm; if (mm) { - if (task->flags & PF_KTHREAD) + if (is_kthread(task)) mm = NULL; else mmget(mm); diff --git a/kernel/freezer.c b/kernel/freezer.c index c0738424bb43..d1c2855cfde4 100644 --- a/kernel/freezer.c +++ b/kernel/freezer.c @@ -51,7 +51,7 @@ bool freezing_slow_path(struct task_struct *p) if (pm_nosig_freezing || cgroup_freezing(p)) return true; - if (pm_freezing && !(p->flags & PF_KTHREAD)) + if (pm_freezing && !is_kthread(p)) return true; return false; @@ -140,7 +140,7 @@ bool freeze_task(struct task_struct *p) return false; } - if (!(p->flags & PF_KTHREAD)) + if (!is_kthread(p)) fake_signal_wake_up(p); else wake_up_state(p, TASK_INTERRUPTIBLE); diff --git a/kernel/futex.c b/kernel/futex.c index 6d50728ef2e7..3b100d17aa9d 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1249,7 +1249,7 @@ static int attach_to_pi_owner(u32 __user *uaddr, u32 uval, union futex_key *key, if (!p) return handle_exit_race(uaddr, uval, NULL); - if (unlikely(p->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(p))) { put_task_struct(p); return -EPERM; } diff --git a/kernel/kthread.c b/kernel/kthread.c index 621467c33fef..2c505d2e228c 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -72,7 +72,7 @@ static inline void set_kthread_struct(void *kthread) static inline struct kthread *to_kthread(struct task_struct *k) { - WARN_ON(!(k->flags & PF_KTHREAD)); + WARN_ON(!is_kthread(k)); return (__force void *)k->set_child_tid; } @@ -1205,7 +1205,7 @@ void kthread_associate_blkcg(struct cgroup_subsys_state *css) { struct kthread *kthread; - if (!(current->flags & PF_KTHREAD)) + if (!is_kthread(current)) return; kthread = to_kthread(current); if (!kthread) @@ -1231,7 +1231,7 @@ struct cgroup_subsys_state *kthread_blkcg(void) { struct kthread *kthread; - if (current->flags & PF_KTHREAD) { + if (is_kthread(current)) { kthread = to_kthread(current); if (kthread) return kthread->blkcg_css; diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c index cdf318d86dd6..3091d4eae48f 100644 --- a/kernel/livepatch/transition.c +++ b/kernel/livepatch/transition.c @@ -358,7 +358,7 @@ static void klp_send_signals(void) * Meanwhile the task could migrate itself and the action * would be meaningless. It is not serious though. */ - if (task->flags & PF_KTHREAD) { + if (is_kthread(task)) { /* * Wake up a kthread which sleeps interruptedly and * still has not been migrated. diff --git a/kernel/ptrace.c b/kernel/ptrace.c index cb9ddcc08119..025ed158a1d4 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -376,7 +376,7 @@ static int ptrace_attach(struct task_struct *task, long request, audit_ptrace(task); retval = -EPERM; - if (unlikely(task->flags & PF_KTHREAD)) + if (unlikely(is_kthread(task))) goto out; if (same_thread_group(task, current)) goto out; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2b037f195473..4c4a0494c39b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1323,7 +1323,7 @@ void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) static inline bool is_per_cpu_kthread(struct task_struct *p) { - if (!(p->flags & PF_KTHREAD)) + if (!is_kthread(p)) return false; if (p->nr_cpus_allowed != 1) @@ -1518,7 +1518,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, rq = task_rq_lock(p, &rf); update_rq_clock(rq); - if (p->flags & PF_KTHREAD) { + if (is_kthread(p)) { /* * Kernel threads are allowed on online && !active CPUs */ @@ -1544,7 +1544,7 @@ static int __set_cpus_allowed_ptr(struct task_struct *p, do_set_cpus_allowed(p, new_mask); - if (p->flags & PF_KTHREAD) { + if (is_kthread(p)) { /* * For kernel threads that do indeed end up on online && * !active we want to ensure they are strict per-CPU threads. @@ -6649,7 +6649,7 @@ void normalize_rt_tasks(void) /* * Only normalize user tasks: */ - if (p->flags & PF_KTHREAD) + if (is_kthread(p)) continue; p->se.exec_start = 0; diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 80940939b733..dbf38ba93991 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -321,7 +321,7 @@ void play_idle(unsigned long duration_ms) */ WARN_ON_ONCE(current->policy != SCHED_FIFO); WARN_ON_ONCE(current->nr_cpus_allowed != 1); - WARN_ON_ONCE(!(current->flags & PF_KTHREAD)); + WARN_ON_ONCE(!is_kthread(current)); WARN_ON_ONCE(!(current->flags & PF_NO_SETAFFINITY)); WARN_ON_ONCE(!duration_ms); diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c index c1e566a114ca..a68429685d2b 100644 --- a/kernel/sched/wait.c +++ b/kernel/sched/wait.c @@ -380,7 +380,7 @@ EXPORT_SYMBOL(autoremove_wake_function); static inline bool is_kthread_should_stop(void) { - return (current->flags & PF_KTHREAD) && kthread_should_stop(); + return is_kthread(current) && kthread_should_stop(); } /* diff --git a/kernel/signal.c b/kernel/signal.c index e667be6907d7..a6e7ea47ae47 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1085,7 +1085,7 @@ static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struc /* * Skip useless siginfo allocation for SIGKILL and kernel threads. */ - if ((sig == SIGKILL) || (t->flags & PF_KTHREAD)) + if ((sig == SIGKILL) || is_kthread(t)) goto out_set; /* diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c index f5440abb7532..bb05fac6e786 100644 --- a/kernel/stacktrace.c +++ b/kernel/stacktrace.c @@ -229,7 +229,7 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size) mm_segment_t fs; /* Trace user stack if not a kernel thread */ - if (current->flags & PF_KTHREAD) + if (is_kthread(current)) return 0; fs = get_fs(); diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c index 8c98b20bfc41..bbb3fa4c01a4 100644 --- a/lib/is_single_threaded.c +++ b/lib/is_single_threaded.c @@ -28,7 +28,7 @@ bool current_is_single_threaded(void) ret = false; rcu_read_lock(); for_each_process(p) { - if (unlikely(p->flags & PF_KTHREAD)) + if (unlikely(is_kthread(p))) continue; if (unlikely(p == task->group_leader)) continue; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index cdbb7a84cb6e..a3965ca6037d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2668,7 +2668,7 @@ static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg, static inline bool memcg_kmem_bypass(void) { - if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD)) + if (in_interrupt() || !current->mm || is_kthread(current)) return true; return false; } diff --git a/mm/oom_kill.c b/mm/oom_kill.c index eda2e2a0bdc6..06dde52d7abb 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -162,7 +162,7 @@ static bool oom_unkillable_task(struct task_struct *p) { if (is_global_init(p)) return true; - if (p->flags & PF_KTHREAD) + if (is_kthread(p)) return true; return false; } @@ -919,7 +919,7 @@ static void __oom_kill_process(struct task_struct *victim, const char *message) * No use_mm() user needs to read from the userspace so we are * ok to reap it. */ - if (unlikely(p->flags & PF_KTHREAD)) + if (unlikely(is_kthread(p))) continue; do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_TGID); } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 272c6de1bf4e..4863f9812b90 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -831,7 +831,7 @@ static inline struct capture_control *task_capc(struct zone *zone) struct capture_control *capc = current->capture_control; return capc && - !(current->flags & PF_KTHREAD) && + !is_kthread(current) && !capc->page && capc->cc->zone == zone && capc->cc->direct_compaction ? capc : NULL; diff --git a/mm/vmacache.c b/mm/vmacache.c index cdc32a3b02fa..153ae62b2276 100644 --- a/mm/vmacache.c +++ b/mm/vmacache.c @@ -30,7 +30,7 @@ */ static inline bool vmacache_valid_mm(struct mm_struct *mm) { - return current->mm == mm && !(current->flags & PF_KTHREAD); + return current->mm == mm && !is_kthread(current); } void vmacache_update(unsigned long addr, struct vm_area_struct *newvma) diff --git a/mm/vmscan.c b/mm/vmscan.c index dbdc46a84f63..16defb76cb2b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3110,7 +3110,7 @@ static bool throttle_direct_reclaim(gfp_t gfp_mask, struct zonelist *zonelist, * committing a transaction where throttling it could forcing other * processes to block on log_wait_commit(). */ - if (current->flags & PF_KTHREAD) + if (is_kthread(current)) goto out; /* diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c index f1c93a7be9ec..1ec30f956852 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c @@ -671,7 +671,7 @@ bool smack_privileged(int cap) /* * All kernel tasks are privileged */ - if (unlikely(current->flags & PF_KTHREAD)) + if (unlikely(is_kthread(current))) return true; return smack_privileged_cred(cap, current_cred()); diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 4c5e5a438f8b..182debb9f114 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -2257,7 +2257,7 @@ static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags) /* * Sockets created by kernel threads receive web label. */ - if (unlikely(current->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(current))) { ssp->smk_in = &smack_known_web; ssp->smk_out = &smack_known_web; } else { @@ -2761,7 +2761,7 @@ static int smack_socket_post_create(struct socket *sock, int family, /* * Sockets created by kernel threads receive web label. */ - if (unlikely(current->flags & PF_KTHREAD)) { + if (unlikely(is_kthread(current))) { ssp = sock->sk->sk_security; ssp->smk_in = &smack_known_web; ssp->smk_out = &smack_known_web; diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index 94dc346370b1..99a8bd60beb0 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c @@ -79,7 +79,7 @@ static void report_access(const char *access, struct task_struct *target, assert_spin_locked(&target->alloc_lock); /* for target->comm */ - if (current->flags & PF_KTHREAD) { + if (is_kthread(current)) { /* I don't think kthreads call task_work_run() before exiting. * Imagine angry ranting about procfs here. */ From patchwork Wed Aug 14 10:41:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171260 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645574ily; Wed, 14 Aug 2019 03:41:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/dcbsdWN1wMC9IXk2beRcrHYTLNrJdfyOQN21Bsllw4XhW4LxEGLiVIAc1NI/iZYcrdNu X-Received: by 2002:a62:e109:: with SMTP id q9mr12401709pfh.71.1565779315060; Wed, 14 Aug 2019 03:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779315; cv=none; d=google.com; s=arc-20160816; b=qlJNPgKOp97zwTG/vwl6CCzI5jxZ+29AU5CRmRNJjtN9lgtYqJ8jA/mKEOkyK+Yyz/ DvLum1Y8BQnhwz+j7dopkdnMbAgbDymAIo3uXTWSpmEwV1hJumUJxSwdsANEyiMTWkf7 S0tlaZYYX+v4vsW/2bova+UEsIyrLWJnT4gpJ+g+ypyYlE8oBEF9LwOWtOGzaVyIRYlE L2A7hMGkc69mLuuRcT5zEe+PWM1Vl5BVH7mSxzoTmKtB372mqhn97y9k+yYumVVJyXq7 nhUXRkQ8cFVq9CGEm+8V1KuVNJOQ5pHs6RMGQrl4FZoE/duU6xlPFl2m3qGcR/F/7UzX /WVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=H5RIRfAWx3VZiYyMFatbho5ZtawrDs1nrodYDvMNz+Y=; b=Hw+o+SB+13JyLsxohvs1DlAL3O6xM1QCNAuB07Sj2L+2a52gV8MxkEEbO+97VUdwHJ q/D2JSqpPYVq74vioWXyBh7lJkMk06hSlJW+Q7mUEGH4cdludxylXdbl3662Sjqezz5Q vyTNuSH5yM2CrHCvruVKTWpkYmLQV0hrPmqowW0DT6E2wfpJ8h2UR25gJkMtXtjZ6ydu NIPmN6maw2d5nwl7KLmkHcrZGERd0KjAttxYZ0Hok2LUsacMzU+eKoV0RtyQEao+bzxO C/jSPp4SzxiDoU/wLqLlPXhijGSCNB/Zcb1Dj2aNea2T0UP6MvrlQiPD5wEBQWEQq8DR TLOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l6si67659284pgg.489.2019.08.14.03.41.54; Wed, 14 Aug 2019 03:41:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727478AbfHNKlx (ORCPT + 28 others); Wed, 14 Aug 2019 06:41:53 -0400 Received: from foss.arm.com ([217.140.110.172]:51882 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727122AbfHNKlq (ORCPT ); Wed, 14 Aug 2019 06:41:46 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 66B151576; Wed, 14 Aug 2019 03:41:46 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9024D3F706; Wed, 14 Aug 2019 03:41:44 -0700 (PDT) From: Mark Rutland 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 3/9] kmemleak: correctly check for kthreads Date: Wed, 14 Aug 2019 11:41:25 +0100 Message-Id: <20190814104131.20190-4-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In general, a non-NULL current->mm doesn't imply that current is a kthread, as kthreads can install an mm via use_mm(), and so it's preferable to use is_kthread() to determine whether a thread is a kthread. For consistency, let's use is_kthread() here. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Ingo Molnar Cc: Peter Zijlstra --- mm/kmemleak.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.11.0 Acked-by: Catalin Marinas diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 6e9e8cca663e..42ea3c14b577 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1290,10 +1290,10 @@ static int scan_should_stop(void) * This function may be called from either process or kthread context, * hence the need to check for both stop conditions. */ - if (current->mm) - return signal_pending(current); - else + if (is_kthread(current)) return kthread_should_stop(); + else + return signal_pending(current); return 0; } From patchwork Wed Aug 14 10:41:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171259 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645524ily; Wed, 14 Aug 2019 03:41:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqynBY5Mp2Sagudr/NRRG3gLVgf37YmHrkGe2s2/LqzXuBKiFb/j9Hgy/vSQ4lrbzn0x088c X-Received: by 2002:a17:902:7686:: with SMTP id m6mr42196239pll.239.1565779312042; Wed, 14 Aug 2019 03:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779312; cv=none; d=google.com; s=arc-20160816; b=pYWX5IngaSt3UyeM+AvmhRmhGO2CLG+hEF2oO5jGiLL6JBkOzXvEquv68NP3fdwdSs Y+QvypyTIUqyWvLDM36Xy9OkXhH+gsoc8kAz62I45wa65iyDcjCFobPWViLlzXZ2OW9n trComgNvGBIcqOvDmn+jG/UB2rRF4wYUM9q/ExKDuvILKA5M6lavx5DORXgMpYBB/XDQ COq9gO2Ldg/TqHFxhesu3gg650W7dzj+3eqQqScdxE4QASecwu73lKJ3zy8RZGy5mfsx L423dfsIoL9FpqUeRxVO6GzkMAeAM320J32TaIMqiY0pLr97gRdKBMHyXytHdexQln2g wnOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=STwRrp6FO8bML5SY3a+cNpBO8zs0tXXXaHQIkQKcLpU=; b=IDRuHRbbNimJE3G3/cCeKZNSoeY6o9fijZ9DdkMYfqhkdS9Z3+xJjNwmZ6nFjXmQcV dfPB8yISOg+fK687Id/m82XuD58tR4KCLm/VhhPkc1zz8Chu4Dx6qg7A4DRiIxV22dNg lhODcJSLTJ+nFMWXyU2oDlF5yBblx/0gz63uUUlQ8ms+C9pmvyO0ui2S/DMur50LqKky UMv40tZY+jzlEzBtVeVRoLndAQZ6kBjchRWE9zGG9purOpSnDVZDDfnUfa78P/uKQQum KKy14n7ugsmV8HSixDC0AGOUuuwwpD8tAUkHqQmTy9BM4u7rAroUMMmLKJYEDI170VxD ksBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67si71503363pfv.74.2019.08.14.03.41.51; Wed, 14 Aug 2019 03:41:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727424AbfHNKlu (ORCPT + 28 others); Wed, 14 Aug 2019 06:41:50 -0400 Received: from foss.arm.com ([217.140.110.172]:51906 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfHNKlt (ORCPT ); Wed, 14 Aug 2019 06:41:49 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EB6AE28; Wed, 14 Aug 2019 03:41:48 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 210CD3F706; Wed, 14 Aug 2019 03:41:47 -0700 (PDT) From: Mark Rutland 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 4/9] arm/perf: correctly check for kthreads Date: Wed, 14 Aug 2019 11:41:26 +0100 Message-Id: <20190814104131.20190-5-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The arm perf_callchain_user() functions looks at current->mm, apparently to determine whether the thread is a kthread without any valid user context. In general, a non-NULL current->mm doesn't imply that current is a kthread, as kthreads can install an mm via use_mm(), and so it's preferable to use is_kthread() to determine whether a thread is a kthread. For consistency, let's use is_kthread() here. Signed-off-by: Mark Rutland Cc: Will Deacon Cc: Ingo Molnar Cc: Peter Zijlstra --- arch/arm/kernel/perf_callchain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm/kernel/perf_callchain.c b/arch/arm/kernel/perf_callchain.c index 3b69a76d341e..5c920f2c46a8 100644 --- a/arch/arm/kernel/perf_callchain.c +++ b/arch/arm/kernel/perf_callchain.c @@ -71,7 +71,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs perf_callchain_store(entry, regs->ARM_pc); - if (!current->mm) + if (is_kthread(current)) return; tail = (struct frame_tail __user *)regs->ARM_fp - 1; From patchwork Wed Aug 14 10:41:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171265 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645859ily; Wed, 14 Aug 2019 03:42:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxpeb6huR2WQESoYz0ne7XpgBRhJOvxZINNQS9oo9oYZIYGXsoZpMm4L5dXCrNt7xxy2iN X-Received: by 2002:a65:68c8:: with SMTP id k8mr37920459pgt.192.1565779331815; Wed, 14 Aug 2019 03:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779331; cv=none; d=google.com; s=arc-20160816; b=m5o6QkhZjFKUfDV3b6a32K8DOQnVsr6Idw7RhIQIO1ZXMMd6ove81RmK6GsQm6BCNO n8MT/YZLjoofQwsYN0EGHMsxYhX+nZt9JKIezpKqIJNzHrAOE8WLKRGPK+Pi4yy1uqf/ KoYplIl7LHgKn6Qzgyy+MNxALzUu1+Rr0vjGDscqoz4nAe9i7LdQrou9+letPOYem315 +DST5aJyDncgg2KlFdCvsemz8zg81/zMZzqbRq/GB5Y3zkwsguZuTmmcgTWPkBGA9YVK bwMZGQ1JN2GvoTVHcmNbrff9FTdfC2f8UdwBhADHJZa7jwLB/0EhgPOeVnETA/5+sG90 9tsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=xuTQ86ouXiu31GwocfnnpFVIJAV43V3prL4/XODupWw=; b=YnydwKDsiNGoLhRenOlS1mzp3dhQ/mI1NUqF+6jeG4bltDO4M+Kae3f5WRqiVmQU+j l8rDQeBrkg5m6opPKrOJrEQpJp462ZZOggyHsznpcvhbxyebxzXzkfF7Gqpqqpx5kaNm CD+bBpE+NUTerKYPzRBK6GYavK2Yg3x6dfbCI87YC25nF0duCd/wpUSfr9oJCQAnooA2 /g36FYZyvqaapi9C4mFoXBOrFMAv4RoNnleaSmhD+rMqx2CKdnTYMuLPoCTBWzx+D/pY RfvV/YjVxvoUlNy6eobhwHyPLXO0pq1b4X5IT7J0r+CnKlY5QKff9GP4hoP7nnK0aA9E f/3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si62165051plo.104.2019.08.14.03.42.11; Wed, 14 Aug 2019 03:42:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727577AbfHNKl7 (ORCPT + 28 others); Wed, 14 Aug 2019 06:41:59 -0400 Received: from foss.arm.com ([217.140.110.172]:51934 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727456AbfHNKlv (ORCPT ); Wed, 14 Aug 2019 06:41:51 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 648A1360; Wed, 14 Aug 2019 03:41:51 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8E2F63F706; Wed, 14 Aug 2019 03:41:49 -0700 (PDT) From: Mark Rutland 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 5/9] arm64: correctly check for ktrheads Date: Wed, 14 Aug 2019 11:41:27 +0100 Message-Id: <20190814104131.20190-6-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit: 6eb6c80187c55b7f ("arm64: kernel thread don't need to save fpsimd context.") ... we skip saving the fpsimd state for kernel threads in arch_dup_task_struct(). We determine whether current is a kthread by looking at current->mm. In general, a non-NULL current->mm doesn't imply that current is a kthread, as kthreads can install an mm via use_mm(), and so it's preferable to use is_kthread() to determine whether a thread is a kthread. For consistency, let's use is_kthread() here. Signed-off-by: Mark Rutland Cc: Catalin Marinas Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Will Deacon --- arch/arm64/kernel/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 Acked-by: Catalin Marinas diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 288012687c29..82b0a7a257cd 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -335,7 +335,7 @@ void arch_release_task_struct(struct task_struct *tsk) */ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) { - if (current->mm) + if (!is_kthread(current)) fpsimd_preserve_current_state(); *dst = *src; From patchwork Wed Aug 14 10:41:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171261 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645599ily; Wed, 14 Aug 2019 03:41:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKFtdwMKLlbx0T2SkifmuRp5PF+ovp1ek4gOVg1g0wJdg6Q8cReCYOIjSz9Vs/oVmzPaT2 X-Received: by 2002:a17:902:7612:: with SMTP id k18mr41310550pll.48.1565779317268; Wed, 14 Aug 2019 03:41:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779317; cv=none; d=google.com; s=arc-20160816; b=lxi1HEJDsQeSjHSJ7jdDnl+vxHi48vZIgKl6GmLd7PaTHVci0pnp+RghPYnzDNcUo4 kZPH2Ei+7nWc+ZogrvhsCrKbRhxsLB7knAHi7cc1UI3MVla1aRRpEXLgGcqaK+OjlFy/ NH68hFqhmUyVQ9z7P3WwBq/BhiwTbx42wDy/raKvZhvjzbpfwqd6l4s3p4t0pURf6bGc 4iNdtphSnqItoINHeasyHPBiqlZM7R22u7Yg00dTKqtmcv+RKSlrISiD2IbRLGyrRh7M aEc7o1oo0gtYxM5cmh1YCx7IEhPGWmKdoVoNHJ4buBmRdKwB7rH6uJZMyDQE1tkH9UEm vTuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=JLRB1Xb2d8S6utCGsxi7rjJQZGK3NGMdrX1IsI11MQY=; b=L5BKrkyS+5krwL3BBEpmDtsVbkjNOOlFsjai/M87XFfo5E0cG4QXDkx15AanVvDZbC rKo50LwNloL/ADK2fzut/dBoww0GGoRwqdLRao/WZoznSiheGsVcZNWgS947WThuMlx/ vvTMXLq41elcvOcmFG3TZ23E3TkSZcKWpYC8r4Qg/KwO8FMsNCJ9zbyJu60DNnj580tO xsPjJk/TOvP1BsuAsbszLMGzuEEXzSv7lO/pAHWTJTyIw9TmGDj/D1ZQexPSPslW2wRH /Ss5K4tjLI6boShWc2p7uS4lF/WQocnj1CwY6QitmZbIOgHDhWjaSKdtnwwkvhzXW210 P8Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l6si67659284pgg.489.2019.08.14.03.41.57; Wed, 14 Aug 2019 03:41:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727542AbfHNKl4 (ORCPT + 28 others); Wed, 14 Aug 2019 06:41:56 -0400 Received: from foss.arm.com ([217.140.110.172]:51958 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbfHNKly (ORCPT ); Wed, 14 Aug 2019 06:41:54 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D5D3B1596; Wed, 14 Aug 2019 03:41:53 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0B51E3F706; Wed, 14 Aug 2019 03:41:51 -0700 (PDT) From: Mark Rutland 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 6/9] sparc/perf: correctly check for kthreads Date: Wed, 14 Aug 2019 11:41:28 +0100 Message-Id: <20190814104131.20190-7-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sparc perf_callchain_user() functions looks at current->mm, apparently to determine whether the thread is a kthread without any valid user context. In general, a non-NULL current->mm doesn't imply that current is a kthread, as kthreads can install an mm via use_mm(), and so it's preferable to use is_kthread() to determine whether a thread is a kthread. For consistency, let's use is_kthread() here. Signed-off-by: Mark Rutland Cc: David S. Miller Cc: Ingo Molnar Cc: Peter Zijlstra --- arch/sparc/kernel/perf_event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 Acked-by: David S. Miller diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c index a58ae9c42803..ef7b1a03bea9 100644 --- a/arch/sparc/kernel/perf_event.c +++ b/arch/sparc/kernel/perf_event.c @@ -1858,7 +1858,7 @@ perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs perf_callchain_store(entry, regs->tpc); - if (!current->mm) + if (is_kthread(current)) return; flushw_user(); From patchwork Wed Aug 14 10:41:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171262 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645694ily; Wed, 14 Aug 2019 03:42:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8nRR08FIi0KEzVvG5EqVKA0M58aZ8R0MQ9222bNCn7E0tKJFn6NzC0Je//meteKX5fqME X-Received: by 2002:a17:90a:b393:: with SMTP id e19mr6646085pjr.118.1565779322601; Wed, 14 Aug 2019 03:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779322; cv=none; d=google.com; s=arc-20160816; b=hhAYAw3FsHpAedAWXouui38klGa7Gm9BSkxI7Luh+5udn7Ii3kqwCjeX/eQPMB77KB 6tt+Vdjvkw+zYjFdrSCiwTX6kRB92WZw1hIEpwbhtnF/+EdTIdHaADEU97vUZAa8WkH7 bU2PgH54MrTsGgse5IXWy+Se1RleFNbXkh9oRHI8anklvTQjzGcW2vI47dvFSLafpir9 UlktGp3aTCKNjFM9PFS5gwFv6TAoxjmU5f+k5eHmY5Ltl3zD5XDWk4m8SAsoPxqnSufd S13TnH3ConSwxAwgDH0wb6MdENJiHWhQzVIiPFAnnWOD+4HTaICzSHxHJJ/1RHhS5lz5 yRSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=EdhipERRetj+TCrj5nGZD1UXw54NwkPXvlUwxvs4T9o=; b=WTdoGCRwWHVK93y8HkTsuLBUH+0d7kXQkBxl0yn2z+MXQ1KV7b3QcMn2owstxTnGCA nKPTudbTR/685vzKhr13Dr5yVpF+Yqe8iAlznsRgd3GEoXxmoNF10Lmys8LOugDItisF zHLshPC07mo1VdOpR0QZZGDZFYZH0gRnGIO9s5WaXYSu73r5LSiEItIJMurIw+AXBXvE xmrgEBAhae83uR2jZaw69mOMQg05eYtiRNF0RIWo+IHd3R7muiFD86hg2MO7DgTan79G 8tbpxFjChirKIUWXVpiUJsoxmix+Ww7/2B/8sQbYAxGjABCYky0SjeGyRTiRWWpqw46b 2tWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si67050421pgr.514.2019.08.14.03.42.02; Wed, 14 Aug 2019 03:42:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727610AbfHNKmB (ORCPT + 28 others); Wed, 14 Aug 2019 06:42:01 -0400 Received: from foss.arm.com ([217.140.110.172]:51982 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbfHNKl4 (ORCPT ); Wed, 14 Aug 2019 06:41:56 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 59CC81570; Wed, 14 Aug 2019 03:41:56 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 846FD3F706; Wed, 14 Aug 2019 03:41:54 -0700 (PDT) From: Mark Rutland 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 7/9] x86/lbr: correctly check for kthreads Date: Wed, 14 Aug 2019 11:41:29 +0100 Message-Id: <20190814104131.20190-8-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The x86 lbr branch_type() functions looks at current->mm, apparently to determine whether the thread is a kthread without any valid user context. In general, a non-NULL current->mm doesn't imply that current is a kthread, as kthreads can install an mm via use_mm(), and so it's preferable to use is_kthread() to determine whether a thread is a kthread. For consistency, let's use is_kthread() here. Signed-off-by: Mark Rutland Cc: Andi Kleen Cc: Ingo Molnar Cc: Kan Liang Cc: Peter Zijlstra --- arch/x86/events/intel/lbr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index 6f814a27416b..ed2b7e57a249 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -857,7 +857,7 @@ static int branch_type(unsigned long from, unsigned long to, int abort) * can happen if measuring at the user level only * and we interrupt in a kernel thread, e.g., idle. */ - if (!current->mm) + if (is_kthread(current)) return X86_BR_NONE; /* may fail if text not present */ From patchwork Wed Aug 14 10:41:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171263 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645737ily; Wed, 14 Aug 2019 03:42:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAr2iQfA+2N2HqXBYCVB9CpnRCTipIhCAu+Ub5FMQUXaCtMXw5rl97J00VpHTV/q+aqlgP X-Received: by 2002:a17:902:830c:: with SMTP id bd12mr42838968plb.237.1565779324986; Wed, 14 Aug 2019 03:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779324; cv=none; d=google.com; s=arc-20160816; b=XPEGpS0JPm4G9/A6CDRjo84J675bjNCmpuESssQavNVniiwIvv7BQ6gtI+p2yUHfcf oGS4Nwc1t4e47zzDQUHgYfxjoLPdZ2kpCEc8O1NyZ/5Ve0XKWHgfouWQeL7rsjLP876r j4huHV13Dt/n5xYSRX68jDUSGcE0AThW3uGogHxh2J5NFMRCxPzdXua2WADHI27y+Uw8 xt5uHBExPGKyUM4UrEOin6u5woEuy8+72zqcT1HhhMAE2k+b+YbmIUbkC5mfeXwzMMiD ACniIpScEKQiqfE71xKY7Zx+zT0ylRcPuw3HhpSB2xlHbMxaV2GXKsC74+l68weB4dKF tMIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=LJ9lxStny/Kz6Ifmw1iSFUoWZEd/oFrXGADW9zcK2kc=; b=lOB1xXO5lcDJoctBTbYuxzZYnVt2ucJ+VeiJi4K/1I/cne41S/QlRIVjQKgJwTBRo6 slNYO5QKD6HiAgPnm4/Vqyiap8JSnoSFcK5Y4knzW8c30wzeeAfCMjQ9qatNFHZCJDQf 8Q6ftnyDzhNaJt+hjOXe+CuCJYgvj8q08UlxXw8FGzRg/+XA6olUr+UhdppQ21+ti4TW blIVilNZ4dSf8dXke7lYpaYnRVSLjPa9wT/+Z89xjeDgOi6454FIgdP43BGcaeVCoiGr pbpntLL8LPL1j1nyzLSo1MSJkE3TE9oAWnYLsgPRscqEYdCcv53YiE3rTejr0MFCbgXr FYZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si67050421pgr.514.2019.08.14.03.42.04; Wed, 14 Aug 2019 03:42:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727638AbfHNKmD (ORCPT + 28 others); Wed, 14 Aug 2019 06:42:03 -0400 Received: from foss.arm.com ([217.140.110.172]:52008 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727573AbfHNKl7 (ORCPT ); Wed, 14 Aug 2019 06:41:59 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C58AA1597; Wed, 14 Aug 2019 03:41:58 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 056CB3F706; Wed, 14 Aug 2019 03:41:56 -0700 (PDT) From: Mark Rutland 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 8/9] x86/fpu: correctly check for kthreads Date: Wed, 14 Aug 2019 11:41:30 +0100 Message-Id: <20190814104131.20190-9-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Per commit: 0cecca9d03c964ab ("x86/fpu: Eager switch PKRU state") ... switch_fpu_state() is trying to distinguish user threads from kthreads, such that kthreads consistently use init_pkru_value. It does do by looking at current->mm. In general, a non-NULL current->mm doesn't imply that current is a kthread, as kthreads can install an mm via use_mm(), and so it's preferable to use is_kthread() to determine whether a thread is a kthread. For consistency, let's use is_kthread() here. Signed-off-by: Mark Rutland Cc: Borislav Petkov Cc: Christoph Hellwig Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Rik van Riel Cc: Sebastian Andrzej Siewior --- arch/x86/include/asm/fpu/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 Acked-by: Sebastian Andrzej Siewior diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index 4c95c365058a..ed3d85fa7c67 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -607,7 +607,7 @@ static inline void switch_fpu_finish(struct fpu *new_fpu) * PKRU state is switched eagerly because it needs to be valid before we * return to userland e.g. for a copy_to_user() operation. */ - if (current->mm) { + if (!is_kthread(current)) { pk = get_xsave_addr(&new_fpu->state.xsave, XFEATURE_PKRU); if (pk) pkru_val = pk->pkru; From patchwork Wed Aug 14 10:41:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 171264 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp645793ily; Wed, 14 Aug 2019 03:42:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqydPO/XEzUCy5J0sHupjdWy1IDINbWImJj5592j/mG3m196qfoA4lEhKAnLHpsQGsNaAAdp X-Received: by 2002:a17:90a:b016:: with SMTP id x22mr6750112pjq.116.1565779328848; Wed, 14 Aug 2019 03:42:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565779328; cv=none; d=google.com; s=arc-20160816; b=saHEXILg5st+cvbPcNkuDaAGA6yt01iBvl21KtIeo8RDoR7WzBuDHfUM/IeB6/dyRh 41kOJbL16+8tkLe5rinsdPNnZQNzpebgTMDP4gS0ztO811kVDic5B7H1izl28dwz6FYC p3qjuA/gpGXHsIMJ/ch8AJKxizM+8En9o0bxDCf+aWaXKPRsc6e6mRSeiszBqks9cJlt loJ/0GDxRAYROv1T5QQPhkEuzlUcdy4DE4XIoBJmzIn3L6CNJ3hT7/X9lFkIvaQQ10Gj FMsVUqbthAqhS5FPLBCJ4+cnrq/R4kcE4e4hQwjFW2svTDAZeotATDQwWHmutm8QImb/ X4jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=WtptYsngeFBPUz6M4DkJn+HFZHVWXjAsFaA3NcOCgic=; b=h6s9nO739iJCT4ruFsM5WfCq8fN25ytN0OtoT/B7JyjdtKDU1oNVcUKxmiMI3HgTcQ YooWwGRDCehdP+W1/g4ADg7O5QLCGneOHIVCV2BoezSovkbSeCETu7xEUnhD/vKaOW5+ 8V9yqjRrNbP3Pmu8HLHn11+HMvy4hX/0avRXjVYt7JtAskk3/NpJE/XFpcKUSwiYWhQi 7w0cS0rKA1mJyC82e5sCV6lkyPzKXQlSeBQX1HisFzt0HgFeX8hTg0FOGhity38Nf7jn bYMky1H+ysX3ZEhMrHL2hXstYjPTfLf71EBkijtd0GGR2yGNZatF5dFfwDQrvIRp6Y2P AmLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14si62165051plo.104.2019.08.14.03.42.08; Wed, 14 Aug 2019 03:42:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727662AbfHNKmH (ORCPT + 28 others); Wed, 14 Aug 2019 06:42:07 -0400 Received: from foss.arm.com ([217.140.110.172]:52030 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726821AbfHNKmB (ORCPT ); Wed, 14 Aug 2019 06:42:01 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4741815AD; Wed, 14 Aug 2019 03:42:01 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6EE2A3F706; Wed, 14 Aug 2019 03:41:59 -0700 (PDT) From: Mark Rutland 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 9/9] samples/kretprobe: correctly check for kthreads Date: Wed, 14 Aug 2019 11:41:31 +0100 Message-Id: <20190814104131.20190-10-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190814104131.20190-1-mark.rutland@arm.com> References: <20190814104131.20190-1-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In general, a non-NULL current->mm doesn't imply that current is a kthread, as kthreads can install an mm via use_mm(), and so it's preferable to use is_kthread() to determine whether a thread is a kthread. For consistency, let's use is_kthread() here. Signed-off-by: Mark Rutland Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Andrew Morton --- samples/kprobes/kretprobe_example.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.11.0 diff --git a/samples/kprobes/kretprobe_example.c b/samples/kprobes/kretprobe_example.c index 186315ca88b3..d6e0bf196f0e 100644 --- a/samples/kprobes/kretprobe_example.c +++ b/samples/kprobes/kretprobe_example.c @@ -41,7 +41,7 @@ static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) { struct my_data *data; - if (!current->mm) + if (is_kthread(current)) return 1; /* Skip kernel threads */ data = (struct my_data *)ri->data;