Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2523726imu; Thu, 29 Nov 2018 06:23:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/WoCKdWbw0ynKPtZ+RID65Q9ypuMfv+P2HFznG+51zN2t376tl8UXWH5aol6yFbjlzzo19W X-Received: by 2002:a63:1e17:: with SMTP id e23mr1410361pge.130.1543501394616; Thu, 29 Nov 2018 06:23:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501394; cv=none; d=google.com; s=arc-20160816; b=mg3jBhUlzNgncf+YlMuNZCyD43x4f8K/B/H8o7vDu3uEMgn2JL8eRBiGIYgvzP0AFu 3ku187xmn+czKlq38CLlY7Qg5brZHYEeshJjwS7zkC8d84fSoZfHpN8UQxYGdedW76e5 XHT+HTPtZelnfa0QS/5QBlJoclU6JtsrOYOGtdnQp6OvY1NWqjMDt5PdTihMzExerRPr 0g6fAumZsJ/V+y+FUEWsisz9YIUb/dHP+2AfU06p137sS2bLypVmjXFmNS4//Ui7ZkjY eT3em9sD9CNw5uFTFmAuv+gLHK7tPquKe/41eLr6nKL5bNpZOYcUQC5MWMFG/AJUcOd8 45ig== 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=/odHsWrGnlFUgiLZEVFzYixqvoj0Kyszy06BtqvnDg8=; b=P7p9HpAytNGrDZzQDTLGJYEBGEtluUAhnTDY55HJD9h8GXvBHU3tMhqFdgYqzzEl1o ClGx7mOhmSk/zbQ94r6W0Yca/Uf6JcX3eoLXa4PE+ypLkTsj2Rk7Hygy6GnLV06JFaoy XCGn7QwnWasFNderw7nAbENtVzPBGDYZuCIF5xtWqjU0LjCF38K5VZefrNl4BYyQm3qj vnRi5UMmgHIoBuMnvCOCeAHxqcbVxOJTlUqXaYGJqqOoB1xPpD17H2dnBtIGT/O+J5hC wpjw+tepKb5DflWLiPR2rVT4O3RZa4bDZc/TEhTgjJnAWceOb2BF4oRGYS/nkpVQ6Pgb 2QHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mf9aZuDM; 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 v11si2161265plp.85.2018.11.29.06.22.59; Thu, 29 Nov 2018 06:23:14 -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=mf9aZuDM; 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 S1731251AbeK3BZ2 (ORCPT + 99 others); Thu, 29 Nov 2018 20:25:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:48890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729806AbeK3BZ1 (ORCPT ); Thu, 29 Nov 2018 20:25:27 -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 878BE208E7; Thu, 29 Nov 2018 14:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501196; bh=+aKTUiYgH8GZbtreLbRSNo8J0IWnU7yRjfj3thwWrx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mf9aZuDM9GFmOr0vgm/G95cjW+WPwEpRs2eJeZsRKzRglDinnaoIYeePIBp8vR4ES X82nsDamuYm1s60O8uzeJDrN93N28bJ6skx+4kRdwyhCoEHapWDtbot3Ddfo2XOx6h 744J5DZZAlfQS25SwsawcNxh7i+4L1uZelU1Osp4= 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.4 83/86] sched/core: Allow __sched_setscheduler() in interrupts when PI is not used Date: Thu, 29 Nov 2018 15:12:48 +0100 Message-Id: <20181129140116.377213541@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140109.832117862@linuxfoundation.org> References: <20181129140109.832117862@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.4-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 @@ -3822,8 +3822,8 @@ static int __sched_setscheduler(struct t struct rq *rq; int reset_on_fork; - /* 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) {