Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp45056pxb; Mon, 13 Sep 2021 12:29:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/ArvCKc5gGTpnNEsJpPNQzBpXnQGwmJvtj7A4/siXW47yAn1NlLMYqL4nWKkNghjb8wBE X-Received: by 2002:a05:6402:3487:: with SMTP id v7mr14811057edc.102.1631561374470; Mon, 13 Sep 2021 12:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631561374; cv=none; d=google.com; s=arc-20160816; b=udIJmpEKDXoyv+mhpGTUSOJL0P9MXLWBDkerwF7CryXC2UBa5wjFeZSFv7mhYf8oa4 tVvuh0sVLB71CLgcxcoQkbX3wIVu2NWXASo9FmDPAa+sPYJIqvCu/LnhFEgrD0n2IOD8 UVwziJqUvpN9XSz1jtzfs2M4L/4JoItemYqTWUaz+80zY12P5V8m6wSl6dNWYgN01XZk Vvy2ffEKZkK9PbfiUnEyKfuwsi0tsgxaIZqzdHHUXMRz5UNWRxlOSQBYHnJLvNn+AnvB mdbhU3An8kUmH4cfXpVgBXz2CexoXbAGuyRynD4H+s9Y1zBZpbbDn+H21tu0xJYdnNzQ Ajlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YIQ8MeJLq1omGPvmZti191qp1Pd2ASzb4re0UdHsWEA=; b=SKrNA6IT/0uoGf4ECQ90QJD/oWxeLG+V1Ymv5LIiipMGUjzzzqlI8sHY+Qwdgthaql 6fkjtDrfqzgpW1e7jmdmloiS/ydobFvFkgph6iuHwWHw2lRyUocyxjO6fnLtXmufWAui a36LcrZrC3Efi5F+WRO2DVDd1+PVV6uFIKGbGG4KxaGitYLXTttQysjV1LYJt0WPOKVH oo8BD8YF8/H0phhH1DuDqLhj96qBj1RJWqfhapbhpaxus/pV9+d/ifPfRTYlm3tUgf9b FlT0M1Wf3PAOCAd8fep1m9ByG066urC4K+iweGo9LeepRonpRoRFCkTaehyD4uRU7ByV zBKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YHYBLui9; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m2si7847469eds.578.2021.09.13.12.29.10; Mon, 13 Sep 2021 12:29:34 -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=@linuxfoundation.org header.s=korg header.b=YHYBLui9; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242683AbhIMNeS (ORCPT + 99 others); Mon, 13 Sep 2021 09:34:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:34844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240146AbhIMNT4 (ORCPT ); Mon, 13 Sep 2021 09:19:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3AF39610FB; Mon, 13 Sep 2021 13:17:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539074; bh=TfMGfZX9sfpLJumnJiPgehJ4165p7DZonxEnbP0Pkr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YHYBLui9JGz+kgGRGnyr7i/3rnMdRIqAMdtlMo+c8Askh3R0psmGgr4LHQohyx65r 5KHJUdSpLRUKVUjJKssKhKva0mEOnIQUgHDWBpZIbgcHgbCu3ggnGTaDn9UKbDZnYZ aFXcD1vS+tlFX6trp8OJj+g625RAuzqAOfTvGbi4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rick Yiu , Quentin Perret , "Peter Zijlstra (Intel)" , Qais Yousef , Dietmar Eggemann , Sasha Levin Subject: [PATCH 5.4 032/144] sched: Fix UCLAMP_FLAG_IDLE setting Date: Mon, 13 Sep 2021 15:13:33 +0200 Message-Id: <20210913131049.029454996@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quentin Perret [ Upstream commit ca4984a7dd863f3e1c0df775ae3e744bff24c303 ] The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last uclamp active task (that is, when buckets.tasks reaches 0 for all buckets) to maintain the last uclamp.max and prevent blocked util from suddenly becoming visible. However, there is an asymmetry in how the flag is set and cleared which can lead to having the flag set whilst there are active tasks on the rq. Specifically, the flag is cleared in the uclamp_rq_inc() path, which is called at enqueue time, but set in uclamp_rq_dec_id() which is called both when dequeueing a task _and_ in the update_uclamp_active() path. As a result, when both uclamp_rq_{dec,ind}_id() are called from update_uclamp_active(), the flag ends up being set but not cleared, hence leaving the runqueue in a broken state. Fix this by clearing the flag in update_uclamp_active() as well. Fixes: e496187da710 ("sched/uclamp: Enforce last task's UCLAMP_MAX") Reported-by: Rick Yiu Signed-off-by: Quentin Perret Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Qais Yousef Tested-by: Dietmar Eggemann Link: https://lore.kernel.org/r/20210805102154.590709-2-qperret@google.com Signed-off-by: Sasha Levin --- kernel/sched/core.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 8294debf68c4..5dc43d37e6a2 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1110,6 +1110,23 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p) uclamp_rq_dec_id(rq, p, clamp_id); } +static inline void uclamp_rq_reinc_id(struct rq *rq, struct task_struct *p, + enum uclamp_id clamp_id) +{ + if (!p->uclamp[clamp_id].active) + return; + + uclamp_rq_dec_id(rq, p, clamp_id); + uclamp_rq_inc_id(rq, p, clamp_id); + + /* + * Make sure to clear the idle flag if we've transiently reached 0 + * active tasks on rq. + */ + if (clamp_id == UCLAMP_MAX && (rq->uclamp_flags & UCLAMP_FLAG_IDLE)) + rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE; +} + static inline void uclamp_update_active(struct task_struct *p) { @@ -1133,12 +1150,8 @@ uclamp_update_active(struct task_struct *p) * affecting a valid clamp bucket, the next time it's enqueued, * it will already see the updated clamp bucket value. */ - for_each_clamp_id(clamp_id) { - if (p->uclamp[clamp_id].active) { - uclamp_rq_dec_id(rq, p, clamp_id); - uclamp_rq_inc_id(rq, p, clamp_id); - } - } + for_each_clamp_id(clamp_id) + uclamp_rq_reinc_id(rq, p, clamp_id); task_rq_unlock(rq, p, &rf); } -- 2.30.2