Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2527334imu; Thu, 29 Nov 2018 06:26:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/WagPAHLLrzwTj42KfkuyFsobz2NPE4fKxekunUWdgPGxkrFKnuU/rrxohdBxqTEdGgH7H/ X-Received: by 2002:a62:ca05:: with SMTP id n5mr1600774pfg.154.1543501573771; Thu, 29 Nov 2018 06:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501573; cv=none; d=google.com; s=arc-20160816; b=dNv5g9ytG9cM7+JFSjx2Apcihr3VXhWwQWHJy4X+3mXYBJMXDnrt/4U5/mgRiFpzt/ P5jlnUgzp3CPZhzNvdniPdgxDdtkSAu0RnlICNCPMH9hfT5ULIdJLVQfPm7YchCqiMAN Tiipwj3GNvpI4pi9jZNnTUUfjcKxOPwE9FdekkqixKpc6a4tGOfjN3cMMv9byIgszNfq ChxE+Xg7EhjrIEqP+Z2DZTk5w7RMMjsIttA1lyxKob8HW0uqVQ+JJE3SqFrC6QVN4ZKi aALASWnI7Fe3TyUYN364QN//BMKmgGGZiOIS4ZvjS2BEAv2/DmERsKo8hncVyrXtsbWA kzrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8KTx8YJiaaMZHwMH89I88+LGtwcpPxmSU2DaanZF4Ms=; b=vxb4Fw1q1yVRndRE3lOaZWlc0PQZZYHLhA516y+GLe5xlCSwPZWb/o5MXQ66OmE7od FMuToWayoM14bzI4L8a4eE4JyCh9rt7KVSCaPpYiihmnDF/6bwc/SX9Z8A7HlvmGn1sx hKhEMGRn/5Sy/pfOUV+wgD5U2jXXz45Au3r7BmsUmC/sTbDNgh5PAn8nSq3YDXAjugku lbzvoKZ89kAtAqN98qOX05LO87YIN793fX2JT+6XmeAThKgx6KkiJjtx5FktO4+Pzq8p uUmX9aE/ZbC38lGxWAn3UDjGw/P4aBrUDwr3iE4M5iuIaBFGwIrXOvzP2Hr68ntKNPHx CS/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="l/2RXDDi"; 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 a2si2202648pgm.154.2018.11.29.06.25.53; Thu, 29 Nov 2018 06:26:13 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="l/2RXDDi"; 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 S1732394AbeK3B3N (ORCPT + 99 others); Thu, 29 Nov 2018 20:29:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:55448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731250AbeK3B3N (ORCPT ); Thu, 29 Nov 2018 20:29:13 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6576205C9; Thu, 29 Nov 2018 14:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501421; bh=vgNjUOhjL5ZJ9pTV9PWuDsAe44lkfx3uW1GVjTuAPgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l/2RXDDiHc43CbR6bD9W48/wtaXxFvc2zqDtOaoIzquDspKpEi019/eChfpIjNOx9 /OG5QVrpYtlBpBAilYgAH/TGlFE96kUkfvijZ9XoG/zOD2p68EanK8l8MPktF9E+7l xA4LyR41GZPb3XCuzRBWcJOyNCaIAVQT8R2Yh1Gs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laurent Dufour , "Steven Rostedt (VMware)" , "Peter Zijlstra (Intel)" , Andrew Morton , Linus Torvalds , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.9 83/92] sched/core: Allow __sched_setscheduler() in interrupts when PI is not used Date: Thu, 29 Nov 2018 15:12:52 +0100 Message-Id: <20181129140113.332024968@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140106.520639693@linuxfoundation.org> References: <20181129140106.520639693@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Steven Rostedt (VMware) commit 896bbb2522587e3b8eb2a0d204d43ccc1042a00d upstream. 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. Reported-by: Laurent Dufour Tested-by: Laurent Dufour Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Peter Zijlstra (Intel) Cc: Andrew Morton Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: dbc7f069b93a ("sched: Use replace normalize_task() with __sched_setscheduler()") Link: http://lkml.kernel.org/r/20170308124654.10e598f2@gandalf.local.home Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- kernel/sched/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4087,8 +4087,8 @@ static int __sched_setscheduler(struct t 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) {