lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201112054445.GA1257287@ubuntu>
Date:   Thu, 12 Nov 2020 13:44:45 +0800
From:   Yun Hsiang <hsiang023167@...il.com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     Dietmar Eggemann <dietmar.eggemann@....com>,
        linux-kernel@...r.kernel.org, qais.yousef@....com,
        patrick.bellasi@...bug.net, kernel test robot <lkp@...el.com>
Subject: Re: [PATCH v5 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET
 flag to reset uclamp

On Wed, Nov 11, 2020 at 07:04:41PM +0100, Peter Zijlstra wrote:
> On Wed, Nov 11, 2020 at 06:41:07PM +0100, Dietmar Eggemann wrote:
> > diff --git a/include/uapi/linux/sched/types.h b/include/uapi/linux/sched/types.h
> > index c852153ddb0d..b9165f17dddc 100644
> > --- a/include/uapi/linux/sched/types.h
> > +++ b/include/uapi/linux/sched/types.h
> > @@ -115,8 +115,8 @@ struct sched_attr {
> >  	__u64 sched_period;
> >  
> >  	/* Utilization hints */
> > -	__u32 sched_util_min;
> > -	__u32 sched_util_max;
> > +	__s32 sched_util_min;
> > +	__s32 sched_util_max;
> 
> So that's UAPI, not sure we can change the type here.

+1
I am also concerned about changing UAPI.
But if we can chage sched_util_{min/max} to __s32, use -1 to reset is better than
adding flags.

> 
> >  };
> >  
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 3dc415f58bd7..caaa2a8434b9 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -1413,17 +1413,24 @@ int sysctl_sched_uclamp_handler(struct ctl_table *table, int write,
> >  static int uclamp_validate(struct task_struct *p,
> >  			   const struct sched_attr *attr)
> >  {
> > -	unsigned int lower_bound = p->uclamp_req[UCLAMP_MIN].value;
> > -	unsigned int upper_bound = p->uclamp_req[UCLAMP_MAX].value;
> > +	int util_min = p->uclamp_req[UCLAMP_MIN].value;
> > +	int util_max = p->uclamp_req[UCLAMP_MAX].value;
> >  
> > -	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN)
> > -		lower_bound = attr->sched_util_min;
> > -	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX)
> > -		upper_bound = attr->sched_util_max;
> > +	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) {
> > +		util_min = attr->sched_util_min;
> >  
> > -	if (lower_bound > upper_bound)
> > -		return -EINVAL;
> > -	if (upper_bound > SCHED_CAPACITY_SCALE)
> > +		if (util_min < -1 || util_min > SCHED_CAPACITY_SCALE)
> > +			return -EINVAL;
> > +	}
> > +
> > +	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) {
> > +		util_max = attr->sched_util_max;
> > +
> > +		if (util_max < -1 || util_max > SCHED_CAPACITY_SCALE)
> > +			return -EINVAL;
> > +	}
> 
> Luckily we can write that range as a single branch like:
> 
> 	if (util_{min,max} + 1 > SCHED_CAPACITY_SCALE+1)
> 
> which assumes u32 :-)
> 
> > +
> > +	if (util_min != -1 && util_max != -1 && util_min > util_max)
> >  		return -EINVAL;
> 
> I think that will compile as is, otherwise write it like ~0u, which is
> the same bit pattern.
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ