Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1760039imm; Sun, 15 Jul 2018 16:27:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfpqvQ7vNjN/aRhwS/xfeIMwN4BIBf1tujoXN2IZoy72l+raxWIPUyrBrEEc66sTQdqe8MU X-Received: by 2002:a65:428b:: with SMTP id j11-v6mr13312053pgp.200.1531697227600; Sun, 15 Jul 2018 16:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531697227; cv=none; d=google.com; s=arc-20160816; b=anJKGGW4Pg5txXj2JU9L3zRP63aX06eWV1TzqwI7sMEXu0kIG6RtZjPn6RJEFX3Fuq 45Y0XEQk2uiA/BurnKXmjybaSznUYI2AhXgalty6DzmM00ZVqG8ucEkHvPCgFn0KCEPa UMZfec7YJFI1ueD/UOn0dLTuXp17RNS8jPN+J2lBAcHRc6nyIyuw9xjw/Gd4EgeC7uQq tpqAvh0qR3D+vOjPrTK5twPYaTVRAKYqm8QGdm7n9B8RYeopDSis2B8JM9zLeMzVOZjT e4H9/Z4I+C+ULtNsw6p15RxJKFEMobO4r22aZbp+f55/xiofR6isXK5MhbjYKL+T88Xe ykrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=PJFDH0Ofj9X8Iko+7c1jTlp4SOVlZ4LRc0TrT8FBgLE=; b=FPpdCM8FVIBEak1ubPYXAOuc1RhXP17fQUsHdNa03aW2M/jmRI+LljrfjXzsOsExlD WczTkYKoT2eFyDN3ptWt1e6npV1Jnxi5/SJ9twxqemdk3+ZIhARQU/NhwFWn36rBSIkX N2ji/0/Uvjvcjax9Y43Vv82Nu1osx9UBeTQnKTpRKMETI3TktJo5lqhbko+L5Zcp49SX CzVkhvrdW5DhTaiZckQUilZBl7zfdX8Xv1TY3I4eOMvKPLH7wXUOWTNiqS+N4LU6SfIZ KoaoOvTDTdgYklm1tyD48MNzs51R5Nbnntg+n90SGA9rZ0CasrEv8R4BvGwW8nD08icZ NKDA== 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 v12-v6si28354192plo.264.2018.07.15.16.26.39; Sun, 15 Jul 2018 16:27:07 -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 S1727522AbeGOXuW (ORCPT + 99 others); Sun, 15 Jul 2018 19:50:22 -0400 Received: from terminus.zytor.com ([198.137.202.136]:52477 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727005AbeGOXuW (ORCPT ); Sun, 15 Jul 2018 19:50:22 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6FNOqio920883 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 15 Jul 2018 16:24:52 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6FNOqO0920880; Sun, 15 Jul 2018 16:24:52 -0700 Date: Sun, 15 Jul 2018 16:24:52 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Juri Lelli Message-ID: Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, hpa@zytor.com, mark.rutland@arm.com, mingo@kernel.org, torvalds@linux-foundation.org, peterz@infradead.org, juri.lelli@redhat.com, luca.abeni@santannapisa.it, bristot@redhat.com Reply-To: hpa@zytor.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, bristot@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, luca.abeni@santannapisa.it, mark.rutland@arm.com, mingo@kernel.org, torvalds@linux-foundation.org In-Reply-To: <20180711072948.27061-1-juri.lelli@redhat.com> References: <20180711072948.27061-1-juri.lelli@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/urgent] sched/deadline: Fix switched_from_dl() warning Git-Commit-ID: e117cb52bdb4d376b711bee34af6434c9e314b3b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: e117cb52bdb4d376b711bee34af6434c9e314b3b Gitweb: https://git.kernel.org/tip/e117cb52bdb4d376b711bee34af6434c9e314b3b Author: Juri Lelli AuthorDate: Wed, 11 Jul 2018 09:29:48 +0200 Committer: Ingo Molnar CommitDate: Sun, 15 Jul 2018 23:47:33 +0200 sched/deadline: Fix switched_from_dl() warning Mark noticed that syzkaller is able to reliably trigger the following warning: dl_rq->running_bw > dl_rq->this_bw WARNING: CPU: 1 PID: 153 at kernel/sched/deadline.c:124 switched_from_dl+0x454/0x608 Kernel panic - not syncing: panic_on_warn set ... CPU: 1 PID: 153 Comm: syz-executor253 Not tainted 4.18.0-rc3+ #29 Hardware name: linux,dummy-virt (DT) Call trace: dump_backtrace+0x0/0x458 show_stack+0x20/0x30 dump_stack+0x180/0x250 panic+0x2dc/0x4ec __warn_printk+0x0/0x150 report_bug+0x228/0x2d8 bug_handler+0xa0/0x1a0 brk_handler+0x2f0/0x568 do_debug_exception+0x1bc/0x5d0 el1_dbg+0x18/0x78 switched_from_dl+0x454/0x608 __sched_setscheduler+0x8cc/0x2018 sys_sched_setattr+0x340/0x758 el0_svc_naked+0x30/0x34 syzkaller reproducer runs a bunch of threads that constantly switch between DEADLINE and NORMAL classes while interacting through futexes. The splat above is caused by the fact that if a DEADLINE task is setattr back to NORMAL while in non_contending state (blocked on a futex - inactive timer armed), its contribution to running_bw is not removed before sub_rq_bw() gets called (!task_on_rq_queued() branch) and the latter sees running_bw > this_bw. Fix it by removing a task contribution from running_bw if the task is not queued and in non_contending state while switched to a different class. Reported-by: Mark Rutland Signed-off-by: Juri Lelli Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Daniel Bristot de Oliveira Reviewed-by: Luca Abeni Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: claudio@evidence.eu.com Cc: rostedt@goodmis.org Link: http://lkml.kernel.org/r/20180711072948.27061-1-juri.lelli@redhat.com Signed-off-by: Ingo Molnar --- kernel/sched/deadline.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index fbfc3f1d368a..10c7b51c0d1f 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2290,8 +2290,17 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p) if (task_on_rq_queued(p) && p->dl.dl_runtime) task_non_contending(p); - if (!task_on_rq_queued(p)) + if (!task_on_rq_queued(p)) { + /* + * Inactive timer is armed. However, p is leaving DEADLINE and + * might migrate away from this rq while continuing to run on + * some other class. We need to remove its contribution from + * this rq running_bw now, or sub_rq_bw (below) will complain. + */ + if (p->dl.dl_non_contending) + sub_running_bw(&p->dl, &rq->dl); sub_rq_bw(&p->dl, &rq->dl); + } /* * We cannot use inactive_task_timer() to invoke sub_running_bw()