Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp600647pxj; Thu, 10 Jun 2021 08:17:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHJQMge4yNjxcWu/PqtCAwCqDr6GDI3Wz7OOQI5G7akwUe9k2pqv2hduwz2wPUFdMqljUE X-Received: by 2002:aa7:d3ca:: with SMTP id o10mr5365647edr.197.1623338236395; Thu, 10 Jun 2021 08:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623338236; cv=none; d=google.com; s=arc-20160816; b=mkNI+aQg1TXKFdE1OdG75tkiCxNEU8bdakqg7lrm085dFqQNByR/6QtvuI8i6S5R18 640NZmxXQZ7C3RfqTpozr8G8GDqqwPaT9/W3wbjuO8jHI6X78Xkey21ZC+Wtije1tnfG 1C7pHld8fAIsvqifxNnd1PbwBbVEg8NexAHsajm+yrh1GPaqqGrmmZ1c0IGjYSts/Wn/ MpKhBeCWdiwtGlD1SrrjRj/Yj5G+hzzHgo4qo+8IxS8EUBkIw1oTYqDQ54HjTwPkaYIC 3/h7C34z0zkiCNPpranDKT9rnP/8e16UQwXKo9PfYZY6MakgLw4hQCiUwQ/vk6Kp+dV/ 1flA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=sQgN6aRIek9SPblHyHkiCGSXCvzKGScP3r+Gjit2HM0=; b=huasxWPCaUyqNQfJe3tEAwPYRkJU9NXlKTEhLdMsx5ewZKVrdCM0JSGUYuqUFnLqfB Buia/+RXUm4D78bek6f10NARkR7GkwQ+KcfOK7dS7MJwBmMjtRzrvcVDgq/mlhO2e0/T OWIr798S9YyaAsKg6w/zdB9qbsNtBv289szfGOdn+B8E1oMHGDzMdL4ckVTJEM6xLudD iaxDGb2nVxwMi8cOs47NWpcItgEr4u2b5Ype0+QMp/56cwMNfUPr/6ApiDtpq+EABO1q Y6w2iwotdAgoBkqPNyYiRGMytMQtun+UM4apSqntASSXoZ8sIlj/5krTWG7uD14R9RYv 6b1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YpdwTQLC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si2424648ejc.734.2021.06.10.08.16.52; Thu, 10 Jun 2021 08:17:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YpdwTQLC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbhFJPQf (ORCPT + 99 others); Thu, 10 Jun 2021 11:16:35 -0400 Received: from mail-yb1-f202.google.com ([209.85.219.202]:39479 "EHLO mail-yb1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231325AbhFJPQV (ORCPT ); Thu, 10 Jun 2021 11:16:21 -0400 Received: by mail-yb1-f202.google.com with SMTP id r5-20020a2582850000b02905381b1b616eso36391273ybk.6 for ; Thu, 10 Jun 2021 08:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sQgN6aRIek9SPblHyHkiCGSXCvzKGScP3r+Gjit2HM0=; b=YpdwTQLCYrhX2otGsuGW0gM31oSnBx1INqZeP24FmNOe0qmPIXq4M7HFmlGWAlKFSe Vy3gf/yTuKMBy4a4L58I2sCyd7lZPRDPmdtsbNDUPBILbFC7op9v0pezJD6QoQUlmiWn 629OnqkFUTawr7KK0ZkzWGpJEq2UQ7OsqpKkfDq7+iKEsvJ+VaNVNeGyKR6Wt5hTgKp5 6Kkx3+SEsVwbK8cVZw9GCLWVHw1gMO38kQvvVk5GS7yyo/U8keNwUuG2Ff+YM2Tb9G4G pGhRbDPITnu4MW1lXdlYWMbFxj0Ao6Pq3d1ktDJezPyjxUSGz7VDzF2LH+GH6hykjBUd vUxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sQgN6aRIek9SPblHyHkiCGSXCvzKGScP3r+Gjit2HM0=; b=IpkJ31ULJbqyru8Bs33lvBdII+9jEJhXNM1EqRXm3pwLlAZvo6uaH4f6PiFyWxtDqm rMnX8Zlk9QuaM4+elPO3E0+RT1QjKWX0SfPpeN20CHxV1Qj4V/HE3Bhg53e5H8Q5ouh3 oHVLQ5L9n6HuJ38kxU7wHemuHBU7qK5P5hWBzCOWqc4b00p42qAJ119W18IYldEpwLGs y4iAoAv9hzfIwB/fsLg3h9qxHurAsARKouH0qD5CthMzCm+I4Nd7XSRLqDd69/DEVmsJ Nl/kWh6HG+dZfuWvGNGrDNjn3gPR0z/xUPwrGadJEFNmvQjHhhR1lmC+YBQVAW6j6VLu stpA== X-Gm-Message-State: AOAM533GlVan3GaNgcUOCx/cfLmwH7q20sMK1c4ZotPIoygriQjd4kLy iWC8qNMWbT8K8YtppcezbOWn2TKeusM/ X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a25:4256:: with SMTP id p83mr8343434yba.212.1623337998372; Thu, 10 Jun 2021 08:13:18 -0700 (PDT) Date: Thu, 10 Jun 2021 15:13:05 +0000 In-Reply-To: <20210610151306.1789549-1-qperret@google.com> Message-Id: <20210610151306.1789549-3-qperret@google.com> Mime-Version: 1.0 References: <20210610151306.1789549-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH v2 2/3] sched: Skip priority checks with SCHED_FLAG_KEEP_PARAMS From: Quentin Perret To: mingo@redhat.com, peterz@infradead.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, qais.yousef@arm.com, rickyiu@google.com, wvw@google.com, patrick.bellasi@matbug.net, xuewen.yan94@gmail.com Cc: linux-kernel@vger.kernel.org, kernel-team@android.com, Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SCHED_FLAG_KEEP_PARAMS can be passed to sched_setattr to specify that the call must not touch scheduling parameters (nice or priority). This is particularly handy for uclamp when used in conjunction with SCHED_FLAG_KEEP_POLICY as that allows to issue a syscall that only impacts uclamp values. However, sched_setattr always checks whether the priorities and nice values passed in sched_attr are valid first, even if those never get used down the line. This is useless at best since userspace can trivially bypass this check to set the uclamp values by specifying low priorities. However, it is cumbersome to do so as there is no single expression of this that skips both RT and CFS checks at once. As such, userspace needs to query the task policy first with e.g. sched_getattr and then set sched_attr.sched_priority accordingly. This is racy and slower than a single call. As the priority and nice checks are useless when SCHED_FLAG_KEEP_PARAMS is specified, simply inherit them in this case to match the policy inheritance of SCHED_FLAG_KEEP_POLICY. Reported-by: Wei Wang Signed-off-by: Quentin Perret --- kernel/sched/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 3b213402798e..1d4aedbbcf96 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6585,6 +6585,10 @@ SYSCALL_DEFINE3(sched_setattr, pid_t, pid, struct sched_attr __user *, uattr, rcu_read_unlock(); if (likely(p)) { + if (attr.sched_flags & SCHED_FLAG_KEEP_PARAMS) { + attr.sched_priority = p->rt_priority; + attr.sched_nice = task_nice(p); + } retval = sched_setattr(p, &attr); put_task_struct(p); } -- 2.32.0.272.g935e593368-goog