Skip to contentSkip to conversation

sched/deadline: Use proc_douintvec_minmax() limit minimum value

PATCH Applied Yajun Deng 4 participants 5 messages Jun 7, 2022 – Jun 13, 2022 Scheduler

lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH v2 1/1 sched/deadline: Use proc_douintvec_minmax() limit minimum value

sysctl_sched_dl_period_max and sysctl_sched_dl_period_min are unsigned integer, but proc_dointvec() wouldn't return error even if we set a negative number.

Use proc_douintvec_minmax() instead of proc_dointvec(). Add extra1 for sysctl_sched_dl_period_max and extra2 for sysctl_sched_dl_period_min.

It's just an optimization for match data and proc_handler in struct ctl_table. The 'if (period < min || period > max)' in __checkparam_dl() will work fine even if there hasn't this patch.

v2:
- update the log message.

---
 kernel/sched/deadline.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/sched/deadline.c +4 -2
index b5152961b743..5867e186c39a 100644
@@ -30,14 +30,16 @@ static struct ctl_table sched_dl_sysctls[] = {
 		.data           = &sysctl_sched_dl_period_max,
 		.maxlen         = sizeof(unsigned int),
 		.mode           = 0644,
-		.proc_handler   = proc_dointvec,
+		.proc_handler   = proc_douintvec_minmax,
+		.extra1         = (void *)&sysctl_sched_dl_period_min,
 	},
 	{
 		.procname       = "sched_deadline_period_min_us",
 		.data           = &sysctl_sched_dl_period_min,
 		.maxlen         = sizeof(unsigned int),
 		.mode           = 0644,
-		.proc_handler   = proc_dointvec,
+		.proc_handler   = proc_douintvec_minmax,
+		.extra2         = (void *)&sysctl_sched_dl_period_max,
 	},
 	{}
 };
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Yajun Deng

sysctl_sched_dl_period_max and sysctl_sched_dl_period_min are unsigned integer, but proc_dointvec() wouldn't return error even if we set a negative number.

Use proc_douintvec_minmax() instead of proc_dointvec(). Add extra1 for sysctl_sched_dl_period_max and extra2 for sysctl_sched_dl_period_min.

Quoted 8 lines

It's just an optimization for match data and proc_handler in struct ctl_table. The 'if (period < min || period > max)' in __checkparam_dl() will work fine even if there hasn't this patch.

v2:
- update the log message.

-- Daniel

maintainer Acked-by on v2 1/1
#2 lore raw
In reply to Yajun Deng

Hi,

Quoted 11 lines · Yajun Deng

sysctl_sched_dl_period_max and sysctl_sched_dl_period_min are unsigned integer, but proc_dointvec() wouldn't return error even if we set a negative number.

Use proc_douintvec_minmax() instead of proc_dointvec(). Add extra1 for sysctl_sched_dl_period_max and extra2 for sysctl_sched_dl_period_min.

It's just an optimization for match data and proc_handler in struct ctl_table. The 'if (period < min || period > max)' in __checkparam_dl() will work fine even if there hasn't this patch.

Quoted 5 lines

v2:
- update the log message.

---

Guess I'm not opposed to the change, even if, as the changelog also says, we should be already checking for sane values.

That said,

Thanks,
Juri

#3 lore raw
Quoted 2 lines · Juri Lelli

Guess I'm not opposed to the change, even if, as the changelog also says, we should be already checking for sane values.

I share this opinion.

-- Daniel

merge bot Applied
#4 lore raw
In reply to Yajun Deng
The following commit has been merged into the sched/core branch of tip:

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     2ed81e765417ec2526f901366167a13294ef09ce
Gitweb:        https://git.kernel.org/tip/2ed81e765417ec2526f901366167a13294ef09ce
Author:        Yajun Deng <[email protected]>
AuthorDate:    Tue, 07 Jun 2022 18:18:07 +08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 13 Jun 2022 10:30:00 +02:00

sched/deadline: Use proc_douintvec_minmax() limit minimum value

sysctl_sched_dl_period_max and sysctl_sched_dl_period_min are unsigned integer, but proc_dointvec() wouldn't return error even if we set a negative number.

Use proc_douintvec_minmax() instead of proc_dointvec(). Add extra1 for sysctl_sched_dl_period_max and extra2 for sysctl_sched_dl_period_min.

It's just an optimization for match data and proc_handler in struct ctl_table. The 'if (period < min || period > max)' in __checkparam_dl() will work fine even if there hasn't this patch.

---
 kernel/sched/deadline.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/sched/deadline.c +4 -2
index b515296..5867e18 100644
@@ -30,14 +30,16 @@ static struct ctl_table sched_dl_sysctls[] = {
 		.data           = &sysctl_sched_dl_period_max,
 		.maxlen         = sizeof(unsigned int),
 		.mode           = 0644,
-		.proc_handler   = proc_dointvec,
+		.proc_handler   = proc_douintvec_minmax,
+		.extra1         = (void *)&sysctl_sched_dl_period_min,
 	},
 	{
 		.procname       = "sched_deadline_period_min_us",
 		.data           = &sysctl_sched_dl_period_min,
 		.maxlen         = sizeof(unsigned int),
 		.mode           = 0644,
-		.proc_handler   = proc_dointvec,
+		.proc_handler   = proc_douintvec_minmax,
+		.extra2         = (void *)&sysctl_sched_dl_period_max,
 	},
 	{}
 };