mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
To: linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Thadeu Lima de Souza Cascardo <cascardo@canonical.com>,
	Patrick Bellasi <patrick.bellasi@arm.com>
Subject: [PATCH 2/2] sched: allow sched_getattr with old size
Date: Tue,  3 Sep 2019 14:16:45 -0300	[thread overview]
Message-ID: <20190903171645.28090-2-cascardo@canonical.com> (raw)
In-Reply-To: <20190903171645.28090-1-cascardo@canonical.com>

After commit a509a7cd7974 (sched/uclamp: Extend sched_setattr() to support
utilization clamping), using sched_getattr with size 48 will return E2BIG.

This breaks, for example, chrt.
$ chrt -p $$
chrt: failed to get pid 26306's policy: Argument list too long
$

With this fix, when using the old size, the utilization clamping values will be
absent from sched_attr. When using the new size or some larger size, they will
be present.

After the fix, chrt works again.
$ chrt -p $$
pid 4649's current scheduling policy: SCHED_OTHER
pid 4649's current scheduling priority: 0
$

The drawback with this solution is that userspace will ignore there are
non-default utilization clamps, but it's arguable whether returning E2BIG in
this case makes sense when that same userspace doesn't know about those values
anyway.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Fixes: a509a7cd7974 (sched/uclamp: Extend sched_setattr() to support utilization clamping)
Cc: Patrick Bellasi <patrick.bellasi@arm.com>
---
 kernel/sched/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0fd67281e656..0ccc7fa80da6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5183,8 +5183,10 @@ SYSCALL_DEFINE4(sched_getattr, pid_t, pid, struct sched_attr __user *, uattr,
 		attr.sched_nice = task_nice(p);
 
 #ifdef CONFIG_UCLAMP_TASK
-	attr.sched_util_min = p->uclamp_req[UCLAMP_MIN].value;
-	attr.sched_util_max = p->uclamp_req[UCLAMP_MAX].value;
+	if (size >= SCHED_ATTR_SIZE_VER1) {
+		attr.sched_util_min = p->uclamp_req[UCLAMP_MIN].value;
+		attr.sched_util_max = p->uclamp_req[UCLAMP_MAX].value;
+	}
 #endif
 
 	rcu_read_unlock();
-- 
2.20.1


  reply	other threads:[~2019-09-03 17:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03 17:16 [PATCH 1/2] sched: sched_getattr should return E2BIG, not EFBIG Thadeu Lima de Souza Cascardo
2019-09-03 17:16 ` Thadeu Lima de Souza Cascardo [this message]
2019-09-04  7:55   ` [PATCH] sched/core: Fix uclamp ABI bug, clean up and robustify sched_read_attr() ABI logic and code Ingo Molnar
2019-09-04  8:49     ` [PATCH v2] " Ingo Molnar
2019-09-04  8:55       ` [PATCH v3] " Ingo Molnar
2019-09-04  9:31         ` Dietmar Eggemann
2019-09-04 10:39           ` Ingo Molnar
2019-09-04 10:55             ` Dietmar Eggemann
2019-09-04 13:19             ` Thadeu Lima de Souza Cascardo
2019-09-04 17:53               ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190903171645.28090-2-cascardo@canonical.com \
    --to=cascardo@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=patrick.bellasi@arm.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®