[RFC PATCH 20/39] sysctl: refresh dynamic scheduler and PID bounds per call
From: wen . yang
Date: Wed Oct 28 2026 - 12:44:25 EST
From: Wen Yang <wen.yang@xxxxxxxxx>
Read current scheduler and PID limits into local tables before validation.
Suggested-by: Joel Granados <joel.granados@xxxxxxxxxx>
Signed-off-by: Wen Yang <wen.yang@xxxxxxxxx>
---
kernel/fork.c | 8 ++++----
kernel/pid.c | 16 +++++++++++++---
kernel/pid_namespace.c | 6 +++---
kernel/pid_sysctl.h | 6 +++---
kernel/sched/deadline.c | 29 +++++++++++++++++++++++++----
kernel/sched/rt.c | 13 ++++++++-----
6 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 18b6dd851642..44947ef38cb4 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -3364,13 +3364,11 @@ static int sysctl_max_threads(const struct ctl_table *table, int write,
struct ctl_table t;
int ret;
int threads = max_threads;
- int min = 1;
- int max = MAX_THREADS;
t = *table;
t.data = &threads;
- t.extra1 = &min;
- t.extra2 = &max;
+ t.min = 1;
+ t.max = MAX_THREADS;
ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos);
if (ret || !write)
@@ -3388,6 +3386,8 @@ static const struct ctl_table fork_sysctl_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = sysctl_max_threads,
+ .min = 1,
+ .max = MAX_THREADS,
},
};
diff --git a/kernel/pid.c b/kernel/pid.c
index adf721606768..21ffdc3d4ea7 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -766,15 +766,25 @@ static struct ctl_table_root pid_table_root = {
.set_ownership = pid_table_root_set_ownership,
};
+static int pid_max_handler(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ struct ctl_table tmp = *table;
+
+ tmp.min = (unsigned long)READ_ONCE(pid_max_min);
+ tmp.max = (unsigned long)READ_ONCE(pid_max_max);
+ return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+}
+
static const struct ctl_table pid_table[] = {
{
.procname = "pid_max",
.data = &init_pid_ns.pid_max,
.maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
- .extra1 = &pid_max_min,
- .extra2 = &pid_max_max,
+ .proc_handler = pid_max_handler,
+ .min = (unsigned long)INT_MIN,
+ .max = INT_MAX,
},
};
#endif
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 127a5fd23e70..fe173ec63cb2 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -297,7 +297,7 @@ static int pid_ns_ctl_handler(const struct ctl_table *table, int write,
next = idr_get_cursor(&pid_ns->idr) - 1;
tmp.data = &next;
- tmp.extra2 = &pid_ns->pid_max;
+ tmp.max = READ_ONCE(pid_ns->pid_max);
ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
if (!ret && write)
idr_set_cursor(&pid_ns->idr, next + 1);
@@ -311,8 +311,8 @@ static const struct ctl_table pid_ns_ctl_table[] = {
.maxlen = sizeof(int),
.mode = 0666, /* permissions are checked in the handler */
.proc_handler = pid_ns_ctl_handler,
- .extra1 = SYSCTL_ZERO,
- .extra2 = &init_pid_ns.pid_max,
+ .min = 0,
+ .max = INT_MAX,
},
};
#endif /* CONFIG_CHECKPOINT_RESTORE */
diff --git a/kernel/pid_sysctl.h b/kernel/pid_sysctl.h
index 5d8f981de7c5..a7b90380285d 100644
--- a/kernel/pid_sysctl.h
+++ b/kernel/pid_sysctl.h
@@ -23,7 +23,7 @@ static int pid_mfd_noexec_dointvec_minmax(const struct ctl_table *table,
scope = max(READ_ONCE(ns->memfd_noexec_scope), parent_scope);
table_copy.data = &scope;
- table_copy.extra1 = &parent_scope;
+ table_copy.min = (unsigned long)parent_scope;
err = proc_dointvec_minmax(&table_copy, write, buf, lenp, ppos);
if (!err && write)
@@ -38,8 +38,8 @@ static const struct ctl_table pid_ns_ctl_table_vm[] = {
.maxlen = sizeof(init_pid_ns.memfd_noexec_scope),
.mode = 0644,
.proc_handler = pid_mfd_noexec_dointvec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_TWO,
+ .min = 0,
+ .max = 2,
},
};
static inline void register_pid_ns_sysctl_table_vm(void)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index c0ebdcde5fe5..bf27abdd5c33 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -19,6 +19,7 @@
#include <linux/cpuset.h>
#include <linux/sched/clock.h>
#include <linux/sched/deadline.h>
+#include <linux/sched/isolation.h>
#include <uapi/linux/sched/types.h>
#include "sched.h"
#include "pelt.h"
@@ -31,22 +32,42 @@
static unsigned int sysctl_sched_dl_period_max = 1 << 22; /* ~4 seconds */
static unsigned int sysctl_sched_dl_period_min = 100; /* 100 us */
#ifdef CONFIG_SYSCTL
+static int sched_dl_period_max_handler(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ struct ctl_table tmp = *table;
+
+ tmp.min = READ_ONCE(sysctl_sched_dl_period_min);
+ return proc_douintvec_minmax(&tmp, write, buffer, lenp, ppos);
+}
+
+static int sched_dl_period_min_handler(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ struct ctl_table tmp = *table;
+
+ tmp.max = READ_ONCE(sysctl_sched_dl_period_max);
+ return proc_douintvec_minmax(&tmp, write, buffer, lenp, ppos);
+}
+
static const struct ctl_table sched_dl_sysctls[] = {
{
.procname = "sched_deadline_period_max_us",
.data = &sysctl_sched_dl_period_max,
.maxlen = sizeof(unsigned int),
.mode = 0644,
- .proc_handler = proc_douintvec_minmax,
- .extra1 = (void *)&sysctl_sched_dl_period_min,
+ .proc_handler = sched_dl_period_max_handler,
+ .min = 0,
+ .max = UINT_MAX,
},
{
.procname = "sched_deadline_period_min_us",
.data = &sysctl_sched_dl_period_min,
.maxlen = sizeof(unsigned int),
.mode = 0644,
- .proc_handler = proc_douintvec_minmax,
- .extra2 = (void *)&sysctl_sched_dl_period_max,
+ .proc_handler = sched_dl_period_min_handler,
+ .min = 0,
+ .max = UINT_MAX,
},
};
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 1535046a23ff..26e9b2ac8838 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -36,8 +36,8 @@ static const struct ctl_table sched_rt_sysctls[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = sched_rt_handler,
- .extra1 = SYSCTL_ONE,
- .extra2 = SYSCTL_INT_MAX,
+ .min = 1,
+ .max = INT_MAX,
},
{
.procname = "sched_rt_runtime_us",
@@ -45,8 +45,8 @@ static const struct ctl_table sched_rt_sysctls[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = sched_rt_handler,
- .extra1 = SYSCTL_NEG_ONE,
- .extra2 = (void *)&sysctl_sched_rt_period,
+ .min = (unsigned long)-1,
+ .max = INT_MAX,
},
{
.procname = "sched_rr_timeslice_ms",
@@ -2872,6 +2872,7 @@ static int sched_rt_global_validate(void)
static int sched_rt_handler(const struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos)
{
+ struct ctl_table tmp = *table;
int old_period, old_runtime;
static DEFINE_MUTEX(mutex);
int ret;
@@ -2881,7 +2882,9 @@ static int sched_rt_handler(const struct ctl_table *table, int write, void *buff
old_period = sysctl_sched_rt_period;
old_runtime = sysctl_sched_rt_runtime;
- ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+ if (table->data == &sysctl_sched_rt_runtime)
+ tmp.max = READ_ONCE(sysctl_sched_rt_period);
+ ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
if (!ret && write) {
ret = sched_rt_global_validate();
--
2.25.1