Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3028727ybt; Mon, 29 Jun 2020 13:19:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyibO3s6jOBXMlXHn2xi5ang1wgXjEeO1kMVENMGV6w6oRujGak6RLIDy/fT4p9b9MKX1h/ X-Received: by 2002:a50:9b18:: with SMTP id o24mr19754676edi.335.1593461948808; Mon, 29 Jun 2020 13:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593461948; cv=none; d=google.com; s=arc-20160816; b=gP5fU2qRrGELxZMuE/EOHw0g87uyRJMDMzzM2lIzBP/dlehmZHTFgyZBYNMsu8YX22 zwIUW2BgorlgGq52WWMpHRUjMf1Z2RYjpykjTowys2L06SJO/EkUb5deGYLwyNd+sM04 svAL+fZEXawR7Th/GnXrBDSOG9ajp6ebTSyaO5HYoECNy99qxYxhBlISr8/0ULXg9CQ5 Um7jg31gmaF+OaSU2xGkF3CIi85Fnx0+ysT5xRFmeR/dKONZF57wqE4rErzGE8Ybvxmo EigHz/Y7+oFkzxdpCq/Wg/ltgfDOFZupYJOz8jdcmR7nAWPc/TN/OY74Abtzk3cYIvic 6d7A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nAhtVfyGXw31LlgFr5fFeslXOaxYF28wGRt6SVhyMGk=; b=QNCiLPQrk+r4Ol1bHzr81Ohz3kecL+dBRPSfhzJq7OOG51dzqqk5SkUb3wpjHFDn4O 8bHq5C9r5ULlZQptjeiToiRWnYKQFjZvyylBpVdPM5LTLytM9ek0cP+y5Dh8mToWk7AV Z+abbTH1BkPT3RIA25gYL7QrWcgygxcwndI+F9OXVNCtUpqVwS+WNk2psLdw1vlZ1ReF P8vIyuCXkrRhu1Hxpw4heCEizVRmhf8+laJ4IqL9S8Jvii5ExB7Oh+dT9NfRQ6Lx1Se4 TvqzwcPK8RMSJg4xIBWSCnzwQTGieKpGnGsJkJvE+uQ1ruAqojchL7DEYtSZXXssGaDy GxNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j6ziL9k0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ci12si390446ejb.448.2020.06.29.13.18.45; Mon, 29 Jun 2020 13:19:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j6ziL9k0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728968AbgF2UPT (ORCPT + 99 others); Mon, 29 Jun 2020 16:15:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:40572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732827AbgF2TaR (ORCPT ); Mon, 29 Jun 2020 15:30:17 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E3B02527D; Mon, 29 Jun 2020 15:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593444990; bh=A/iejyMXASVuRe9IDxE5ScubzxcWtQAlOBvnIvtXnDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j6ziL9k0XTfFaUigGr6gNf4GkV3D6BAQvLVE2fYSiMlT5M7hMnWla6e37ecBIdFEU mnzpYpEENHz8Mm6GcVoEbMDTRhE67snfjDPUJDi7mJwF1y3AQrCuTQJGK9koFIXHpi fpUtvCuXPnHaMgcqg+HhjFFUPGNiffM5bM7pMNJg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Juri Lelli , syzbot+119ba87189432ead09b4@syzkaller.appspotmail.com, Peter Zijlstra , Ingo Molnar , Daniel Bristot de Oliveira , Daniel Wagner , Sasha Levin Subject: [PATCH 4.19 089/131] sched/core: Fix PI boosting between RT and DEADLINE tasks Date: Mon, 29 Jun 2020 11:34:20 -0400 Message-Id: <20200629153502.2494656-90-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629153502.2494656-1-sashal@kernel.org> References: <20200629153502.2494656-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.131-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.131-rc1 X-KernelTest-Deadline: 2020-07-01T15:34+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juri Lelli [ Upstream commit 740797ce3a124b7dd22b7fb832d87bc8fba1cf6f ] syzbot reported the following warning: WARNING: CPU: 1 PID: 6351 at kernel/sched/deadline.c:628 enqueue_task_dl+0x22da/0x38a0 kernel/sched/deadline.c:1504 At deadline.c:628 we have: 623 static inline void setup_new_dl_entity(struct sched_dl_entity *dl_se) 624 { 625 struct dl_rq *dl_rq = dl_rq_of_se(dl_se); 626 struct rq *rq = rq_of_dl_rq(dl_rq); 627 628 WARN_ON(dl_se->dl_boosted); 629 WARN_ON(dl_time_before(rq_clock(rq), dl_se->deadline)); [...] } Which means that setup_new_dl_entity() has been called on a task currently boosted. This shouldn't happen though, as setup_new_dl_entity() is only called when the 'dynamic' deadline of the new entity is in the past w.r.t. rq_clock and boosted tasks shouldn't verify this condition. Digging through the PI code I noticed that what above might in fact happen if an RT tasks blocks on an rt_mutex hold by a DEADLINE task. In the first branch of boosting conditions we check only if a pi_task 'dynamic' deadline is earlier than mutex holder's and in this case we set mutex holder to be dl_boosted. However, since RT 'dynamic' deadlines are only initialized if such tasks get boosted at some point (or if they become DEADLINE of course), in general RT 'dynamic' deadlines are usually equal to 0 and this verifies the aforementioned condition. Fix it by checking that the potential donor task is actually (even if temporary because in turn boosted) running at DEADLINE priority before using its 'dynamic' deadline value. Fixes: 2d3d891d3344 ("sched/deadline: Add SCHED_DEADLINE inheritance logic") Reported-by: syzbot+119ba87189432ead09b4@syzkaller.appspotmail.com Signed-off-by: Juri Lelli Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Reviewed-by: Daniel Bristot de Oliveira Tested-by: Daniel Wagner Link: https://lkml.kernel.org/r/20181119153201.GB2119@localhost.localdomain Signed-off-by: Sasha Levin --- kernel/sched/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 0325ccf3a8e45..843394d0ea426 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3862,7 +3862,8 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) */ if (dl_prio(prio)) { if (!dl_prio(p->normal_prio) || - (pi_task && dl_entity_preempt(&pi_task->dl, &p->dl))) { + (pi_task && dl_prio(pi_task->prio) && + dl_entity_preempt(&pi_task->dl, &p->dl))) { p->dl.dl_boosted = 1; queue_flag |= ENQUEUE_REPLENISH; } else -- 2.25.1