Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1103389pxa; Thu, 20 Aug 2020 02:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMgnuRVecrnJY7QigMIAQ+fwR59PBQd0NuzUWB4010mOcNwZcRR6ZfafhW1bek3TOhdIsg X-Received: by 2002:a17:906:b5a:: with SMTP id v26mr2448659ejg.515.1597915967475; Thu, 20 Aug 2020 02:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597915967; cv=none; d=google.com; s=arc-20160816; b=BVglmh8St8EJ151GaoaxSWsK5QBL294OVj6Xpa3PkG8CcYqhh8gWhdi7bu6BU/8dnS zn8/gNfxuwEzPyyo+ivHC3n2Zu4Kor4PVWi5+7r3+dfz441rOsbYKs0Rvkise7aurY6f Ej/AuT8jcJ6VF/bCJWzVf+rTcA7fL5mNifZuCby8nmx0rRZF/jDLQ8zCXvy1WX4hOQju 6ndLgydTjMq245hIH3OJvuMPEy5APv9Lyi69OxXKhhkCzc1LKsx6VPqMVn2ROBrUUbP8 RbQmoAeSxkoLi6dLWnWHjAz6ZtJs/0AVXdOvPh8q1E5CKBX+CeUpGzE3ym/hlAmC7SAo giCQ== 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=Bg6r221YKrDU5TGP38cbzNUFa03ucgv3jyo09fV0d8c=; b=A07MNgQTQHmdCAq6t+qUFkaYCXjTNSRiBmW29yysMzitlonFVKZLzPvJ8eeHGUBiCw sqfOFb1REBQheFX70Uwh0RbaPDbfFmTGdk+Kt/6HCGBbEfF4EbIJd6LSnSwQBPEDklj3 3WXqmuW9S4HXMQGrHquMbU/DleEYIwlD1RkT6R9GPkHfFut54EmG6HMdSp7WxG4OfRVK kulNged51EeyfL1rW2+hEqdmEw3GLBBdOIuIvmdBDvhni2M2gGl5Fe0hYtO8uSLvyWyN K+QKJQdhwJVKiFjn2U+pCiNTnE1tGRylLm3413axXeRB4zG8KhnbW9u/fat6/TEGRyUP QkZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VYeEZYJ/"; 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=fail (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 d14si963083edx.156.2020.08.20.02.32.23; Thu, 20 Aug 2020 02:32:47 -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="VYeEZYJ/"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727926AbgHTJbw (ORCPT + 99 others); Thu, 20 Aug 2020 05:31:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:42824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728226AbgHTJbW (ORCPT ); Thu, 20 Aug 2020 05:31:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 035D8207DE; Thu, 20 Aug 2020 09:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915881; bh=FlEwQBX94KrxCPiD4PuGRd2JWinm9GizSS6oM0z5SQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VYeEZYJ/F4n7/Jr4hs5lo0a29n8YyZk97amED8cUIVvRMQnCWBE0QJWGI38AyKCwT GBRW3FFopKzGEBrAbH5t+uz40Sm0ipvmWe5e12UnVtkKs3LMdx+QgYozLLXWw7Bq6R elIipAwAYyTgFE/tEUOhiIzJg6MAlhlivwBuUhSs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qais Yousef , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.8 168/232] sched/uclamp: Fix a deadlock when enabling uclamp static key Date: Thu, 20 Aug 2020 11:20:19 +0200 Message-Id: <20200820091620.954076640@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Qais Yousef [ Upstream commit e65855a52b479f98674998cb23b21ef5a8144b04 ] The following splat was caught when setting uclamp value of a task: BUG: sleeping function called from invalid context at ./include/linux/percpu-rwsem.h:49 cpus_read_lock+0x68/0x130 static_key_enable+0x1c/0x38 __sched_setscheduler+0x900/0xad8 Fix by ensuring we enable the key outside of the critical section in __sched_setscheduler() Fixes: 46609ce22703 ("sched/uclamp: Protect uclamp fast path code with static key") Signed-off-by: Qais Yousef Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20200716110347.19553-4-qais.yousef@arm.com Signed-off-by: Sasha Levin --- kernel/sched/core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index db1e99756c400..f788cd61df212 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1248,6 +1248,15 @@ static int uclamp_validate(struct task_struct *p, if (upper_bound > SCHED_CAPACITY_SCALE) return -EINVAL; + /* + * We have valid uclamp attributes; make sure uclamp is enabled. + * + * We need to do that here, because enabling static branches is a + * blocking operation which obviously cannot be done while holding + * scheduler locks. + */ + static_branch_enable(&sched_uclamp_used); + return 0; } @@ -1278,8 +1287,6 @@ static void __setscheduler_uclamp(struct task_struct *p, if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_CLAMP))) return; - static_branch_enable(&sched_uclamp_used); - if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) { uclamp_se_set(&p->uclamp_req[UCLAMP_MIN], attr->sched_util_min, true); -- 2.25.1