Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp366277yba; Wed, 15 May 2019 02:48:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuRgjpO6OtHKKBdqWYjvfFVVRXe0Wk3E2DmGaAj3gWr/C0mlre8Q9BI27KThupOr6Mk6bi X-Received: by 2002:a62:62c3:: with SMTP id w186mr44945880pfb.73.1557913719796; Wed, 15 May 2019 02:48:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557913719; cv=none; d=google.com; s=arc-20160816; b=jQQWeZOGycamUBoYtfc8iOIwgM/qKXYaIeXu4nO2pQ/wnY0CcX3hGgOiJxasE/r3Ec wAlqr6p6JDm0sj7HyxGhTWOXfkEuGx692ndNJetduZBpnb98PufalJwYAIYvYZXkcKo4 GRuVQvjpIeUwBXYz9wgUsdxaH+bWCxE4tW9wcb/grEvkRrG/LJkrvUeEjKBSebuPAQiS YYXixys8kfh5j3VZ/QKNlfSpi7FQFr0lP2vjXLGV7wzLpL9BdoVdb5jZI43cc9DLCYHp QwDB1jMqXBcZ+bc+nobUBBH1YNClsX4lgE7y65iyRWXJ4Fs6/DxMS3e233btl7oi/elr ZT9A== 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=tTZfVXf14JXfKlEJImMYbZhnsCUQHLDC76nSQQWt6TU=; b=gpbVdwJLbCZXAHBVUb0FbZH4b4k4EoUKauJ2fUVg6HgvnH8h69wvO7cSdOcSQX3D+Z v2qqOuIkZRGTO8lwNcETDLQa2MsHwcTew1ODHu2FL7Nv3iXunEjwgArxzRBPY0HI0wdO wIf83jJrh8q7cmrvLUChXWN0j72CqDqcpTgIXoe6yyHuaDpQy0tCfznORgaiUWLLjIuT Vn94MLZZrzdYg6ALto5W06goKqCQgeD5SvsRj9DSLQxBs90cxkf9vmvl6i08SftJMYXN 79j/ugKd4QNoFCheb+1EPQ8IPaXEHE6PGb1GlvpewL3ZJhxZx4E/TOT6xUHBxJDOn9ze DFMQ== 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 d4si1684116pfr.82.2019.05.15.02.48.25; Wed, 15 May 2019 02:48:39 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbfEOJpv (ORCPT + 99 others); Wed, 15 May 2019 05:45:51 -0400 Received: from foss.arm.com ([217.140.101.70]:39294 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbfEOJps (ORCPT ); Wed, 15 May 2019 05:45:48 -0400 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 52674A78; Wed, 15 May 2019 02:45:48 -0700 (PDT) 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 37C443F703; Wed, 15 May 2019 02:45:45 -0700 (PDT) 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 v9 05/16] sched/core: Allow sched_setattr() to use the current policy Date: Wed, 15 May 2019 10:44:48 +0100 Message-Id: <20190515094459.10317-6-patrick.bellasi@arm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515094459.10317-1-patrick.bellasi@arm.com> References: <20190515094459.10317-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 this 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. Add support for the SETPARAM_POLICY policy, which is already used by the sched_setparam() POSIX syscall, to the sched_setattr() non-POSIX syscall. Signed-off-by: Patrick Bellasi Cc: Ingo Molnar Cc: Peter Zijlstra --- Changes in v9: Message-ID: <20190509145901.um7rrsslg7de4blf@e110439-lin> - get rid of not necessary SCHED_POLICY_MAX define - update sched_setattr() syscall to just force the current policy on SCHED_FLAG_KEEP_POLICY --- include/uapi/linux/sched.h | 4 +++- kernel/sched/core.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h index 22627f80063e..261b6e43846c 100644 --- a/include/uapi/linux/sched.h +++ b/include/uapi/linux/sched.h @@ -50,9 +50,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 dac73a5959b6..43b29b2efa4c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4863,6 +4863,8 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, if ((int)attr.sched_policy < 0) return -EINVAL; + if (attr.sched_flags & SCHED_FLAG_KEEP_POLICY) + attr.sched_policy = SETPARAM_POLICY; rcu_read_lock(); retval = -ESRCH; -- 2.21.0