From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932734AbdCIPSy (ORCPT ); Thu, 9 Mar 2017 10:18:54 -0500 Received: from mail.kernel.org ([198.145.29.136]:57866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754859AbdCIPSw (ORCPT ); Thu, 9 Mar 2017 10:18:52 -0500 Date: Thu, 9 Mar 2017 10:18:42 -0500 From: Steven Rostedt To: Peter Zijlstra Cc: LKML , Laurent Dufour , Andrew Morton , Thomas Gleixner , Ingo Molnar Subject: [PATCH] sched: Do not bug in __sched_setscheduler() when pi is not used Message-ID: <20170309101842.1449d49a@gandalf.local.home> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" When priority inheritance was added back in 2.6.18 to sched_setscheduler, it added a path to taking an rt-mutex wait_lock, which is not IRQ safe. As PI is not a common occurrence, lockdep will likely never trigger if sched_setscheduler was called from interrupt context. A BUG_ON() was added to trigger if __sched_setscheduler() was ever called from interrupt context because there was a possibility to take the wait_lock. Today the wait_lock is irq safe, but the path to taking it in sched_setscheduler() is the same as the path to taking it from normal context. The wait_lock is taken with raw_spin_lock_irq() and released with raw_spin_unlock_irq() which will indiscriminately enable interrupts, which would be bad in interrupt context. The problem is that normalize_rt_tasks, which is called by triggering the sysrq nice-all-RT-tasks was changed to call __sched_setscheduler(), and this is done from interrupt context! Now __sched_setscheduler() takes a "pi" parameter that is used to know if the priority inheritance should be called or not. As the BUG_ON() only cares about calling the PI code, it should only bug if called from interrupt context with the "pi" parameter set to true. Link: http://lkml.kernel.org/r/20170308124654.10e598f2@gandalf.local.home Reported-by: Laurent Dufour Tested-by: Laurent Dufour Fixes: dbc7f069b93a ("sched: Use replace normalize_task() with __sched_setscheduler()") Cc: Andrew Morton Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Peter Zijlstra Cc: stable@vger.kernel.org Signed-off-by: Steven Rostedt (VMware) --- kernel/sched/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 3b31fc0..7292fa9 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4129,8 +4129,8 @@ static int __sched_setscheduler(struct task_struct *p, int queue_flags = DEQUEUE_SAVE | DEQUEUE_MOVE; struct rq *rq; - /* May grab non-irq protected spin_locks: */ - BUG_ON(in_interrupt()); + /* The pi code expects interrupts enabled */ + BUG_ON(pi && in_interrupt()); recheck: /* Double check policy once rq lock held: */ if (policy < 0) { -- 2.9.3