Skip to contentSkip to conversation

sched/core: Fix wrong burst unit in cgroup2 cpu.max write

PATCH In review Kailun Qin 2 participants 2 messages Sep 10, 2021

Subsystems (2)
lore
Share & tools
lore

Kailun Qin

author
#0 lore raw

PATCH 1/1 sched/core: Fix wrong burst unit in cgroup2 cpu.max write

In cpu_max_write(), as the eventual tg_set_cfs_bandwidth() operates on the burst in nsec which is input from tg_get_cfs_burst() in usec, it should be converted into nsec accordingly.

If not, this may cause a write into cgroup2 cpu.max to unexpectedly change an already set cpu.max.burst.

This patch addresses the above issue.

---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index c4462c454ab9..fc9fcc56149f 100644
@@ -10711,7 +10711,7 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
 {
 	struct task_group *tg = css_tg(of_css(of));
 	u64 period = tg_get_cfs_period(tg);
-	u64 burst = tg_get_cfs_burst(tg);
+	u64 burst = (u64)tg_get_cfs_burst(tg) * NSEC_PER_USEC;
 	u64 quota;
 	int ret;
 
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Kailun Qin

In cpu_max_write(), as the eventual tg_set_cfs_bandwidth() operates on the burst in nsec which is input from tg_get_cfs_burst() in usec, it should be converted into nsec accordingly.

If not, this may cause a write into cgroup2 cpu.max to unexpectedly change an already set cpu.max.burst.

This patch addresses the above issue.

Oh, huh, cpu_period_quota_parse is confusing and changes the units in period. (It might make more sense to make all that interaction clearer somehow, but this is probably fine)

It's probably also better to just use tg->cfs_bandwidth.burst directly rather than do an unnecessary div+multiply.

For whichever version:

Quoted 16 lines
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index c4462c454ab9..fc9fcc56149f 100644
@@ -10711,7 +10711,7 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of,
 {
 	struct task_group *tg = css_tg(of_css(of));
 	u64 period = tg_get_cfs_period(tg);
-	u64 burst = tg_get_cfs_burst(tg);
+	u64 burst = (u64)tg_get_cfs_burst(tg) * NSEC_PER_USEC;
 	u64 quota;
 	int ret;