Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5430286yba; Wed, 8 May 2019 13:14:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxT1T50zTsH4LqrZ+4SZMpuSLMJy5sbypseKafi7gmb5egeslZyEnD1tciSEZS9sIrmvG6g X-Received: by 2002:a63:a84c:: with SMTP id i12mr28090pgp.115.1557346445154; Wed, 08 May 2019 13:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557346445; cv=none; d=google.com; s=arc-20160816; b=oKQ+6O5NzHnWWQ+zSwLRM7TMZ6yBskbxswmM9QTGvPH4Arhtswdl+eyAxrPeyd1apl SWviFXHJC5c72NYVYkGJjnn1rvVkqPMDkbo+Dn8uzVchz+GHOk58wRMk0f7T8gaOWdr1 M4jAAf7g/lFbsZ/AE+umoMh3npMEKMQgwrOXYFb6HG0yI6NZLUx6RcK4vP8kbZySsrnq 8/bhDiSbsG+xnFPJaxSJiUxwpk5UzS17VUnzRKaF+pl4WixI9Jktu+xZ5l2ThEGWOFrz Y/jLS4/HZLftrZu2OWDPfhzA8YOSeGALyrPTFyTOCn6le7vwBDT9zwKikQZfxPINLyQZ F5Pg== 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:dkim-signature; bh=k86bIbJQYyAtCnJQ/9r7wNszrHqG9KBOaSii4mKHzlw=; b=ZfwXHQNy+Gl/f7QsAqZLagYz/XPy0p2Q7z8s7ToOhcq2L155iZUNnphULBAkVC8vHP Q3SQyA876TJ8hVP1rrBT2c49+8TrMHytX+B2UwNi5lQwkWujJmbELLX5k1uAhYwYcX4P HDOAL9gTOFprTCnT59paKBYcEVjq1wuxzSaZ7Rm/l+kFGiD3cfaTA4Oe4xACO4EUuVaU vtOH5h4jm+1pUjthV0rWo/tu4FFViDd1ZuFBHlqxBElSbwynF/+zYD6Ul3luIKmhFp2V 80dw4pqxD8NSbSYgXI+6b24Vk25JjkLZ0Zgy97UXjsmzxm/rd4a4NKCWpALDS3kWfQGi JSPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=SVVtCFeU; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v20si5867167pgb.361.2019.05.08.13.13.18; Wed, 08 May 2019 13:14:05 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=SVVtCFeU; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727509AbfEHTVl (ORCPT + 99 others); Wed, 8 May 2019 15:21:41 -0400 Received: from merlin.infradead.org ([205.233.59.134]:52460 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726687AbfEHTVl (ORCPT ); Wed, 8 May 2019 15:21:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=k86bIbJQYyAtCnJQ/9r7wNszrHqG9KBOaSii4mKHzlw=; b=SVVtCFeU3ylj97tn0HhXzkEUO dP3wY5ZEVrg1Zjk/SewUndpbZJYyav5FsXRHnS7xXFnDgaSHrrOPALGEH0HnZH27IVZ4MjclKV83K kYv0WFJK9t0WsOf3TWiv1X2PLSQAcK4TVbauzOsfdkdQV+iZVpsjqfUWb2sKdfWBKQbo7f4PSWjtE yE9LYpGpEjXMIkmNKu7AsHHUgx1NpdTsQE7PURNLqaoJ1YJ7obGfNwq4iRxY+Z0OLilehI0XD4L7y +J/SbWmLOvHCI7hUOp8F/GKZbEFe+KYnimnUCsbmfcrhB0w6qi2q5mFZ0gnC13mHsVq5hbW/ioHje 100YUWVtg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOS8D-0003hQ-6K; Wed, 08 May 2019 19:21:33 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 368AD98030A; Wed, 8 May 2019 21:21:31 +0200 (CEST) Date: Wed, 8 May 2019 21:21:31 +0200 From: Peter Zijlstra To: Patrick Bellasi Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v8 05/16] sched/core: Allow sched_setattr() to use the current policy Message-ID: <20190508192131.GD32547@worktop.programming.kicks-ass.net> References: <20190402104153.25404-1-patrick.bellasi@arm.com> <20190402104153.25404-6-patrick.bellasi@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190402104153.25404-6-patrick.bellasi@arm.com> 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 Tue, Apr 02, 2019 at 11:41:41AM +0100, Patrick Bellasi wrote: > diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h > index 22627f80063e..075c610adf45 100644 > --- a/include/uapi/linux/sched.h > +++ b/include/uapi/linux/sched.h > @@ -40,6 +40,8 @@ > /* SCHED_ISO: reserved but not implemented yet */ > #define SCHED_IDLE 5 > #define SCHED_DEADLINE 6 > +/* Must be the last entry: used to sanity check attr.policy values */ > +#define SCHED_POLICY_MAX SCHED_DEADLINE This is a wee bit sad to put in a uapi header; but yeah, where else :/ Another option would be something like: enum { SCHED_NORMAL = 0, SCHED_FIFO = 1, SCHED_RR = 2, SCHED_BATCH = 3, /* SCHED_ISO = 4, reserved */ SCHED_IDLE = 5, SCHED_DEADLINE = 6, SCHED_POLICY_NR }; > /* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */ > #define SCHED_RESET_ON_FORK 0x40000000 > @@ -50,9 +52,11 @@ > #define SCHED_FLAG_RESET_ON_FORK 0x01 > #define SCHED_FLAG_RECLAIM 0x02 > #define SCHED_FLAG_DL_OVERRUN 0x04 > +#define SCHED_FLAG_KEEP_POLICY 0x08 > > #define SCHED_FLAG_ALL (SCHED_FLAG_RESET_ON_FORK | \ > SCHED_FLAG_RECLAIM | \ > - SCHED_FLAG_DL_OVERRUN) > + SCHED_FLAG_DL_OVERRUN | \ > + SCHED_FLAG_KEEP_POLICY) > > #endif /* _UAPI_LINUX_SCHED_H */ > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index d368ac26b8aa..20efb32e1a7e 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -4907,8 +4907,17 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, > if (retval) > return retval; > > - if ((int)attr.sched_policy < 0) > + /* > + * A valid policy is always required from userspace, unless > + * SCHED_FLAG_KEEP_POLICY is set and the current policy > + * is enforced for this call. > + */ > + if (attr.sched_policy > SCHED_POLICY_MAX && > + !(attr.sched_flags & SCHED_FLAG_KEEP_POLICY)) { > return -EINVAL; > + } And given I just looked at those darn SCHED_* things, I now note the above does 'funny' things when passed: attr.policy=4. > + if (attr.sched_flags & SCHED_FLAG_KEEP_POLICY) > + attr.sched_policy = SETPARAM_POLICY; > > rcu_read_lock(); > retval = -ESRCH;