Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1480317imj; Fri, 8 Feb 2019 02:07:16 -0800 (PST) X-Google-Smtp-Source: AHgI3IYSTmogb9Km4ZGJSs69FCZ6ZL0QjVOY6pd1vgE2uHKWsXWzCbp2DI6E3Ang3wudMe96BI8I X-Received: by 2002:a17:902:722:: with SMTP id 31mr21946802pli.271.1549620435949; Fri, 08 Feb 2019 02:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549620435; cv=none; d=google.com; s=arc-20160816; b=xD4Ht+YJQ7tXsrjOnH6oE8v5Gng9Y11teOxNGH2K7XmgQHqw95Za+1c+LxQLu4KZU6 IkqO19BlXC1uLJN1LwGEKOUYjwBANM+UaqTM39WS62AMDhIMyzV7L9DUGMPskSlSLzIv pXM1h8afgMVcc3lgg6NmyhWE1PBAEaa0ULowmPdL1Ck1qcJSJkAtLUleyY8vvatB4nlv yMIPiOBxH77PJmsuRIf3QfoQiiz69yqLSCFYiAh71fucKeVN68cOuPBK+d6oz+2quscO xVS23H1kiFMREKwje49jYp2+RcAQHUjoRt5bTS8DSR+NOw5UClbPkGsL24eA1acW0tJl K07w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5C+TfxiGit99NZuecnFylp+Sjk/1HVy2+a6645EI8iM=; b=vPSjXJyG7wgxeU1JYlz3QlCvzzTrxEa6tkJgPNsbUNF+s4o8JTV+jo1//oOgPP5SGp Ae3h+e0bCkuYN9Jm3hrKg89+W+HhgvHSqPJbFRIZes3Um1mpLQPW90KF/JrNB2HRz8/T VDweMISTQED0Ti+QNigGJ2U8cENva2NYUVtQfQpdL6PxKz8YU4cFHeFeoLdecP43gmiY /HJbXY8Z2wihhgbay267sca1vaG8Rtvs1YoxWt+OkTBh1TReRv8JZ5pVOfEFPD8Zjf7v RO/3Q1GoCt3fuweiC+AoYwEW62dQ4MVS8NOlKEVLStWjRCZZ5g4z+hDw109KNogDbqU8 Lrmw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si1771633pgq.139.2019.02.08.02.06.59; Fri, 08 Feb 2019 02:07:15 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727660AbfBHKG2 (ORCPT + 99 others); Fri, 8 Feb 2019 05:06:28 -0500 Received: from foss.arm.com ([217.140.101.70]:47516 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726598AbfBHKG1 (ORCPT ); Fri, 8 Feb 2019 05:06:27 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 948F915AB; Fri, 8 Feb 2019 02:06:26 -0800 (PST) Received: from e110439-lin.cambridge.arm.com (e110439-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7DD643F557; Fri, 8 Feb 2019 02:06:23 -0800 (PST) From: Patrick Bellasi To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , 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: [PATCH v7 04/15] sched/core: Allow sched_setattr() to use the current policy Date: Fri, 8 Feb 2019 10:05:43 +0000 Message-Id: <20190208100554.32196-5-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190208100554.32196-1-patrick.bellasi@arm.com> References: <20190208100554.32196-1-patrick.bellasi@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The sched_setattr() syscall mandates that a policy is always specified. This requires to always know which policy a task will have when attributes are configured and it makes it impossible to add more generic task attributes valid across different scheduling policies. Reading the policy before setting generic tasks attributes is racy since we cannot be sure it is not changed concurrently. Introduce the required support to change generic task attributes without affecting the current task policy. This is done by adding an attribute flag (SCHED_FLAG_KEEP_POLICY) to enforce the usage of the current policy. This is done by extending to the sched_setattr() non-POSIX syscall with the SETPARAM_POLICY policy already used by the sched_setparam() POSIX syscall. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra --- Changes in v7: Message-ID: <20190125135646.j4j2onitam4mwvcw@google.com> - fix definition of SCHED_POLICY_MAX --- include/uapi/linux/sched.h | 6 +++++- kernel/sched/core.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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 /* 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 c0429bcbe09a..26c5ede8ebca 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4924,8 +4924,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; + } + if (attr.sched_flags & SCHED_FLAG_KEEP_POLICY) + attr.sched_policy = SETPARAM_POLICY; rcu_read_lock(); retval = -ESRCH; -- 2.20.1