Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp991903imm; Thu, 6 Sep 2018 13:28:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZyoczU7PZs11V7sSmfiuV+AOPuCbtWQB2QTpi5ghrXNXclyAjstjbNe1ZXyVYmEnyY/y/S X-Received: by 2002:a63:455d:: with SMTP id u29-v6mr4628368pgk.342.1536265699634; Thu, 06 Sep 2018 13:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536265699; cv=none; d=google.com; s=arc-20160816; b=xutJf2xJ5bYrGjYwaWhgaGZSXqXaOiO523UcGFBbeuBix7mQPqk+W7jOq1DunQtH72 VE1u89RWgG6HSI2j50oMGQb5TlimDvOK/SFg6lUglvlL49DDIsLGlGIU8NNzbIYiC79+ C1qVN0TsG5nC7QQByRGiQyMviZkF6M7K7B9EHAY2oPB2+heL7N5qgQ4/z4pH1WPu0Gia 9zrYCdcSIR9pr0DdfHgjSgD2T7bsff8KENbq9fOldH319DfVpGUtnOvKQ3P7mnsj90in Ct/tZRPl6vzweXQSYnEPhpekh2ivy1UiGOIajXLiQywqcrnnimKRjSoJItu3RmimNSdz +FLQ== 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=v/lJjyLSLShu5S9woPjdJb/KurTvIUtx/3OlEN0Q8Rw=; b=V0dNrche3sViAB77GvmiGvyZRboOsv8Fqdw27srbkM9TLUF+MsrKKffhGXrt5FZhGG oVymZ4Tv3gOI7K1sPp9wALrtIdxkiBhmKIU0ffQRWHCoMorJxwBr0alYKUKPwcG0J9PD SK3OhA+m4eql2hebf3fheWKT97d/p+/5eOvEOYPH8krTApmNzASN9N4BOvNT9DpjjBYd XrB+dH+jrzOfcKDk0vUX4Pccbq7eOE/Py0TEK1OiXy5ZSPc5PIfM6FkutlEqT3qcbSAk ZlUuZMJw+GEWeSiGGgjzGfon20trgCTvQE5Af3b7dA0552nJo6LtVk9qfdK1Uq9tiBUD HGfw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v38-v6si6624969plg.179.2018.09.06.13.28.03; Thu, 06 Sep 2018 13:28:19 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729664AbeIFSsx (ORCPT + 99 others); Thu, 6 Sep 2018 14:48:53 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:51804 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729350AbeIFSsx (ORCPT ); Thu, 6 Sep 2018 14:48:53 -0400 Received: by mail-wm0-f66.google.com with SMTP id y2-v6so11581860wma.1 for ; Thu, 06 Sep 2018 07:13:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=v/lJjyLSLShu5S9woPjdJb/KurTvIUtx/3OlEN0Q8Rw=; b=Uop5mS/zogcX+xNjvlEqD2gAu4cro25gbaaEEpZAsu63PQZ8+lq5uWIc+2yOSg8X0F XevwmEpOo/ZFjm6AFy/W3m32Q5DwA0EgmCD27ajKPozgZhaJB1vM2wFOnsw2HzEw9Cjw wqAXDK6715EnNLRYjU5Ee8JzEQOAGnBwIkVbvpdsvvrTKqjFqKk5QNo5wPY4eE81R0Iv xRkmfcwL71y5egSPaWFwO9BwwDAXTkGY41m+tkLcQ9EQZRcFmB25/Syo24w0KhHZ1Z6C eN7NdeTvZVgcQLM8wn1BXacdQKupR/agvTLtfZQjNSdSTTE1NQvGnozYWZx+buFUdRjm /j3Q== X-Gm-Message-State: APzg51A1jVNqa1pwcZqU3lhLyeAM0Kdnx5umJOFp0Sls+GVaEpwD6b92 YzUrub5SLWTF9AEhGsVGsFKLWw== X-Received: by 2002:a1c:bc86:: with SMTP id m128-v6mr2134052wmf.147.1536243186450; Thu, 06 Sep 2018 07:13:06 -0700 (PDT) Received: from localhost.localdomain ([151.15.227.30]) by smtp.gmail.com with ESMTPSA id a203-v6sm3625151wmh.31.2018.09.06.07.13.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 07:13:05 -0700 (PDT) Date: Thu, 6 Sep 2018 16:13:03 +0200 From: Juri Lelli To: Patrick Bellasi Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Tejun Heo , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v4 02/16] sched/core: uclamp: map TASK's clamp values into CPU's clamp groups Message-ID: <20180906141303.GE27626@localhost.localdomain> References: <20180828135324.21976-1-patrick.bellasi@arm.com> <20180828135324.21976-3-patrick.bellasi@arm.com> <20180905104545.GB20267@localhost.localdomain> <20180906134846.GB25636@e110439-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180906134846.GB25636@e110439-lin> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/09/18 14:48, Patrick Bellasi wrote: > Hi Juri! > > On 05-Sep 12:45, Juri Lelli wrote: > > Hi, > > > > On 28/08/18 14:53, Patrick Bellasi wrote: > > > > [...] > > > > > static inline int __setscheduler_uclamp(struct task_struct *p, > > > const struct sched_attr *attr) > > > { > > > - if (attr->sched_util_min > attr->sched_util_max) > > > - return -EINVAL; > > > - if (attr->sched_util_max > SCHED_CAPACITY_SCALE) > > > - return -EINVAL; > > > + int group_id[UCLAMP_CNT] = { UCLAMP_NOT_VALID }; > > > + int lower_bound, upper_bound; > > > + struct uclamp_se *uc_se; > > > + int result = 0; > > > > > > - p->uclamp[UCLAMP_MIN] = attr->sched_util_min; > > > - p->uclamp[UCLAMP_MAX] = attr->sched_util_max; > > > + mutex_lock(&uclamp_mutex); > > > > This is going to get called from an rcu_read_lock() section, which is a > > no-go for using mutexes: > > > > sys_sched_setattr -> > > rcu_read_lock() > > ... > > sched_setattr() -> > > __sched_setscheduler() -> > > ... > > __setscheduler_uclamp() -> > > ... > > mutex_lock() > > Rightm, great catch, thanks! > > > Guess you could fix the issue by getting the task struct after find_ > > process_by_pid() in sys_sched_attr() and then calling sched_setattr() > > after rcu_read_lock() (putting the task struct at the end). Peter > > actually suggested this mod to solve a different issue. > > I guess you mean something like this ? > > ---8<--- > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -5792,10 +5792,15 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, > rcu_read_lock(); > retval = -ESRCH; > p = find_process_by_pid(pid); > - if (p != NULL) > - retval = sched_setattr(p, &attr); > + if (likely(p)) > + get_task_struct(p); > rcu_read_unlock(); > > + if (likely(p)) { > + retval = sched_setattr(p, &attr); > + put_task_struct(p); > + } > + > return retval; > } > ---8<--- This should do the job yes.