Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2072593ybh; Fri, 24 Jul 2020 03:52:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHaoHr/ni68Tl6QJVBRW8DiOatOMRaK5RGZUwLORcA2jqAV1V9ZfmcSdFWpk00srvlAtlp X-Received: by 2002:a17:906:60c6:: with SMTP id f6mr8067973ejk.265.1595587949394; Fri, 24 Jul 2020 03:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595587949; cv=none; d=google.com; s=arc-20160816; b=CODC+cFPGsxcC0ZsmhnHhxgmQymss3u5wHXLtBvP5Uw20jZfi1i9yft8NCija5XOdW 7f5FeckmeOIOOBPeJ34g/R81PIk5G2NwzShYie6zzm4DsWkKvZ+30W2vSYhGCmEvuC3J BaVp8nQbl9xEX2393y4Ud/C/EMpJRgoalWI+kzADaCi8TBV/SCU3tP2D13YWeFeyq3q6 A1vaflfjzPEMJzuBOB0tu/ZUMqy8N6aAK5gMKTcVHnIrUcApsJ7tjgcP2L9fBIjeJo9l Qhge1qVMdupH36ukHTFaxOfICG1BjGgJ/w5db5SwS2tx85sozlG9oMQSbMAS7cic5D8B ubeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=VMCx0cu7z2VKniNNxIXmAYqZvkOLjeJB2ESD8vvGI3Y=; b=lRuL3qEdegFjrWjb6N06G4lQc3ZbmSsoFsWMS/BKhQplRCano+VvyZoZswx8XO9b5j NZEbJDtmHs3/91xv7IS0BlCYiJImNwgtyPhw97W1huYJrEGrKUbEXkLIhOU7A8MZ72Q0 MT8YP7SQvvtop0nEkaiXg0McHlyU2dxkai0xRVtVQ2Z2HP/mWAhO499nxlmfiZPmqAWc vmx06AKk0U12fi1GequeaUag1Eee5jCLCkwydGJOb9Jiux9frlAzfk8TOLeVrVny5JA4 9nxLDmnT6L9TCu4GzAZB5MoEe3VQ+eltbo1la5TXy015UX4iS1KYR8g6wsPTFaWqTy3E R6bg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id od19si352445ejb.581.2020.07.24.03.52.07; Fri, 24 Jul 2020 03:52:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbgGXKuM (ORCPT + 99 others); Fri, 24 Jul 2020 06:50:12 -0400 Received: from foss.arm.com ([217.140.110.172]:60134 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbgGXKuL (ORCPT ); Fri, 24 Jul 2020 06:50:11 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0EA5830E; Fri, 24 Jul 2020 03:50:11 -0700 (PDT) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 61A6B3F66E; Fri, 24 Jul 2020 03:50:09 -0700 (PDT) Date: Fri, 24 Jul 2020 11:50:07 +0100 From: Qais Yousef To: Peter Zijlstra Cc: Ingo Molnar , Doug Anderson , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Patrick Bellasi , Chris Redpath , Lukasz Luba , linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 3/3] sched/uclamp: Fix a deadlock when enabling uclamp static key Message-ID: <20200724105006.g42lu4a4g6pvusl4@e107158-lin.cambridge.arm.com> References: <20200716110347.19553-1-qais.yousef@arm.com> <20200716110347.19553-4-qais.yousef@arm.com> <20200724091244.GX10769@hirez.programming.kicks-ass.net> <20200724094650.hgya5j7i7lbhrocy@e107158-lin.cambridge.arm.com> <20200724104120.GY10769@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200724104120.GY10769@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/24/20 12:41, Peter Zijlstra wrote: > On Fri, Jul 24, 2020 at 10:46:50AM +0100, Qais Yousef wrote: > > On 07/24/20 11:12, Peter Zijlstra wrote: > > > On Thu, Jul 16, 2020 at 12:03:47PM +0100, Qais Yousef wrote: > > > > > > I've trimmed the Changelog to read like: > > > > +1 > > > > Should we mention the ordering issue too? Or maybe I misinterpreted the > > 'Possible unsafe locking scenario' part? > > The lock inversion was, imo, secondary. It only existed because of the > impossible lock ordering -- taking a blocking lock inside an atomic > lock. Fixing the first, avoids the second etc.. So I left it out. > > > This should work, but you'll need to sprinkle ifdef around the key. Or move it > > to uclamp_validate() > > Indeed, the patch now reads like: Maybe s/deadlock/splat/ in the subject now? I clearly focused on the secondary thing.. Sorry you had to modify the patch that much yourself. Thanks! -- Qais Yousef > > --- > Subject: sched/uclamp: Fix a deadlock when enabling uclamp static key > From: Qais Yousef > Date: Thu, 16 Jul 2020 12:03:47 +0100 > > From: Qais Yousef > > 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 > --- > kernel/sched/core.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -1252,6 +1252,15 @@ static int uclamp_validate(struct task_s > 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; > } > > @@ -1282,8 +1291,6 @@ static void __setscheduler_uclamp(struct > 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);