From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934665AbbI2LCG (ORCPT ); Tue, 29 Sep 2015 07:02:06 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:32848 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934243AbbI2LCA (ORCPT ); Tue, 29 Sep 2015 07:02:00 -0400 Date: Tue, 29 Sep 2015 12:56:03 +0200 From: Peter Zijlstra To: mingo@kernel.org Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, fweisbec@gmail.com, oleg@redhat.com, umgwanakikbuti@gmail.com, tglx@linutronix.de, rostedt@goodmis.org Subject: [RFC][PATCH v2 12/11] sched: Add preempt_count invariant check Message-ID: <20150929105603.GG11639@twins.programming.kicks-ass.net> References: <20150929092825.540553633@infradead.org> <20150929102755.GD3816@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150929102755.GD3816@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ingo requested I keep my debug check for the preempt_count invariant. Requested-by: Ingo Molnar Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/preempt.h | 2 +- include/linux/sched.h | 17 +++++++++-------- kernel/sched/core.c | 5 +++++ 3 files changed, 15 insertions(+), 9 deletions(-) --- a/include/asm-generic/preempt.h +++ b/include/asm-generic/preempt.h @@ -24,7 +24,7 @@ static __always_inline void preempt_coun * must be macros to avoid header recursion hell */ #define init_task_preempt_count(p) do { \ - task_thread_info(p)->preempt_count = 2*PREEMPT_DISABLED; \ + task_thread_info(p)->preempt_count = INIT_PREEMPT_COUNT; \ } while (0) #define init_idle_preempt_count(p, cpu) do { \ --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -599,17 +599,18 @@ struct task_cputime_atomic { .sum_exec_runtime = ATOMIC64_INIT(0), \ } -#ifdef CONFIG_PREEMPT_COUNT -#define PREEMPT_DISABLED (1 + PREEMPT_ENABLED) -#else -#define PREEMPT_DISABLED PREEMPT_ENABLED -#endif +#define PREEMPT_DISABLED (PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED) /* - * Disable preemption until the scheduler is running. - * Reset by start_kernel()->sched_init()->init_idle(). + * Initial preempt_count value; reflects the preempt_count schedule invariant + * which states that during schedule preempt_count() == 2. + * + * This also results in the kernel starting with preemption disabled until + * the scheduler is initialized, see: + * + * start_kernel()->sched_init()->init_idle(). */ -#define INIT_PREEMPT_COUNT PREEMPT_DISABLED +#define INIT_PREEMPT_COUNT (2*PREEMPT_DISABLE_OFFSET + PREEMPT_ENABLED) /** * struct thread_group_cputimer - thread group interval timer counts --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2503,6 +2503,11 @@ static struct rq *finish_task_switch(str struct mm_struct *mm = rq->prev_mm; long prev_state; + if (unlikely(WARN_ONCE(preempt_count() != 2*PREEMPT_DISABLE_OFFSET, + "corrupted preempt_count: %s/%d/0x%x\n", + current->comm, current->pid, preempt_count()))) + preempt_count_set(INIT_PREEMPT_COUNT); + rq->prev_mm = NULL; /*