From: wen.yang@linux.dev
To: Joel Granados <joel.granados@kernel.org>
Cc: Wen Yang <wen.yang@linux.dev>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 02/39] test_sysctl: convert bounds to numeric values
Date: Thu, 29 Oct 2026 00:34:41 +0800 [thread overview]
Message-ID: <4f48767377d817a63f348a7725056ca4c0869ef9.1793204511.git.wen.yang@linux.dev> (raw)
In-Reply-To: <cover.1793204511.git.wen.yang@linux.dev>
From: Wen Yang <wen.yang@linux.dev>
The debug module still passes extra pointers for its numeric ranges.
Convert them to numeric min/max so it exercises the same shape as the
rest of the tree, and keep the dynamic-value entry's context in data for
now; the priv conversion comes later.
Suggested-by: Joel Granados <joel.granados@kernel.org>
Signed-off-by: Wen Yang <wen.yang@linux.dev>
---
lib/test_sysctl.c | 135 +++++++++++++++++++++++++++++++++++++---------
1 file changed, 109 insertions(+), 26 deletions(-)
diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c
index eed2cc1bea82..1411896fdbd0 100644
--- a/lib/test_sysctl.c
+++ b/lib/test_sysctl.c
@@ -15,7 +15,6 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/init.h>
-#include <linux/limits.h>
#include <linux/jiffies.h>
#include <linux/list.h>
#include <linux/module.h>
@@ -28,8 +27,6 @@
#include <linux/delay.h>
#include <linux/vmalloc.h>
-static int i_zero;
-static int i_one_hundred = 100;
static int match_int_ok = 1;
enum {
@@ -43,6 +40,12 @@ enum {
};
static struct ctl_table_header *ctl_headers[TEST_H_SIZE] = {};
+
+struct test_sysctl_range_context {
+ int value;
+ int limit;
+};
+
struct test_sysctl_data {
int int_0001;
int int_0002;
@@ -56,6 +59,11 @@ struct test_sysctl_data {
unsigned int uint_0001;
+ struct test_sysctl_range_context dynamic;
+ int int_zero;
+ unsigned long ulong_zero;
+ u8 u8_zero;
+
char string_0001[65];
#define SYSCTL_TEST_BITMAP_SIZE 65536
@@ -80,9 +88,25 @@ static struct test_sysctl_data test_data = {
.uint_0001 = 314,
+ .dynamic = { .value = 0, .limit = 100 },
+
.string_0001 = "(none)",
};
+/* The registered data is typed context, not the backing integer. */
+static int test_sysctl_dynamic_value(const struct ctl_table *table, int dir,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ struct test_sysctl_range_context *context = table->data;
+ struct ctl_table resolved = *table;
+
+ resolved.data = &context->value;
+ resolved.maxlen = sizeof(context->value);
+ resolved.min = INT_MIN;
+ resolved.max = READ_ONCE(context->limit);
+ return proc_dointvec_minmax(&resolved, dir, buffer, lenp, ppos);
+}
+
/* These are all under /proc/sys/debug/test_sysctl/ */
static const struct ctl_table test_table[] = {
{
@@ -91,8 +115,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
- .extra1 = &i_zero,
- .extra2 = &i_one_hundred,
+ .min = 0,
+ .max = 100,
},
{
.procname = "int_0002",
@@ -100,6 +124,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec,
+ .min = INT_MIN,
+ .max = INT_MAX,
},
{
.procname = "int_0003",
@@ -107,6 +133,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(test_data.int_0003),
.mode = 0644,
.proc_handler = proc_dointvec,
+ .min = INT_MIN,
+ .max = INT_MAX,
},
{
.procname = "match_int",
@@ -114,6 +142,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(match_int_ok),
.mode = 0444,
.proc_handler = proc_dointvec,
+ .min = INT_MIN,
+ .max = INT_MAX,
},
{
.procname = "boot_int",
@@ -121,8 +151,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(test_data.boot_int),
.mode = 0644,
.proc_handler = proc_dointvec,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
+ .min = 0,
+ .max = 1,
},
{
.procname = "int_jiffies",
@@ -130,6 +160,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_jiffies,
+ .min = INT_MIN,
+ .max = INT_MAX,
},
{
.procname = "int_ms_jiffies",
@@ -137,6 +169,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_ms_jiffies,
+ .min = INT_MIN,
+ .max = INT_MAX,
},
{
.procname = "int_userhz_jiffies",
@@ -144,6 +178,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec_userhz_jiffies,
+ .min = INT_MIN,
+ .max = INT_MAX,
},
{
.procname = "uint_0001",
@@ -151,6 +187,8 @@ static const struct ctl_table test_table[] = {
.maxlen = sizeof(unsigned int),
.mode = 0644,
.proc_handler = proc_douintvec,
+ .min = 0,
+ .max = UINT_MAX,
},
{
.procname = "string_0001",
@@ -166,28 +204,73 @@ static const struct ctl_table test_table[] = {
.mode = 0644,
.proc_handler = proc_do_large_bitmap,
},
+ {
+ .procname = "dynamic_limit",
+ .data = &test_data.dynamic.limit,
+ .maxlen = sizeof(test_data.dynamic.limit),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+ .min = INT_MIN,
+ .max = INT_MAX,
+ },
+ {
+ .procname = "dynamic_value",
+ .data = &test_data.dynamic,
+ .maxlen = sizeof(test_data.dynamic),
+ .mode = 0644,
+ .proc_handler = test_sysctl_dynamic_value,
+ .min = 0,
+ .max = ULONG_MAX,
+ },
+ {
+ .procname = "int_zero",
+ .data = &test_data.int_zero,
+ .maxlen = sizeof(test_data.int_zero),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_minmax,
+ .min = 0,
+ .max = 0,
+ },
+ {
+ .procname = "ulong_zero",
+ .data = &test_data.ulong_zero,
+ .maxlen = sizeof(test_data.ulong_zero),
+ .mode = 0644,
+ .proc_handler = proc_doulongvec_minmax,
+ .min = 0,
+ .max = 0,
+ },
+ {
+ .procname = "u8_zero",
+ .data = &test_data.u8_zero,
+ .maxlen = sizeof(test_data.u8_zero),
+ .mode = 0644,
+ .proc_handler = proc_dou8vec_minmax,
+ .min = 0,
+ .max = 0,
+ },
};
static void test_sysctl_calc_match_int_ok(void)
{
int i;
- struct {
+ const struct {
int defined;
int wanted;
} match_int[] = {
- {.defined = *(int *)SYSCTL_ZERO, .wanted = 0},
- {.defined = *(int *)SYSCTL_ONE, .wanted = 1},
- {.defined = *(int *)SYSCTL_TWO, .wanted = 2},
- {.defined = *(int *)SYSCTL_THREE, .wanted = 3},
- {.defined = *(int *)SYSCTL_FOUR, .wanted = 4},
- {.defined = *(int *)SYSCTL_ONE_HUNDRED, .wanted = 100},
- {.defined = *(int *)SYSCTL_TWO_HUNDRED, .wanted = 200},
- {.defined = *(int *)SYSCTL_ONE_THOUSAND, .wanted = 1000},
- {.defined = *(int *)SYSCTL_THREE_THOUSAND, .wanted = 3000},
- {.defined = *(int *)SYSCTL_INT_MAX, .wanted = INT_MAX},
- {.defined = *(int *)SYSCTL_MAXOLDUID, .wanted = 65535},
- {.defined = *(int *)SYSCTL_NEG_ONE, .wanted = -1},
+ { .defined = 0, .wanted = 0 },
+ { .defined = 1, .wanted = 1 },
+ { .defined = 2, .wanted = 2 },
+ { .defined = 3, .wanted = 3 },
+ { .defined = 4, .wanted = 4 },
+ { .defined = 100, .wanted = 100 },
+ { .defined = 200, .wanted = 200 },
+ { .defined = 1000, .wanted = 1000 },
+ { .defined = 3000, .wanted = 3000 },
+ { .defined = INT_MAX, .wanted = INT_MAX },
+ { .defined = 65535, .wanted = 65535 },
+ { .defined = -1, .wanted = -1 },
};
for (i = 0; i < ARRAY_SIZE(match_int); i++)
@@ -282,8 +365,8 @@ static const struct ctl_table table_u8_over[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_FOUR,
- .extra2 = SYSCTL_ONE_THOUSAND,
+ .min = 4,
+ .max = 1000,
},
};
@@ -294,8 +377,8 @@ static const struct ctl_table table_u8_under[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_NEG_ONE,
- .extra2 = SYSCTL_ONE_HUNDRED,
+ .min = ULONG_MAX,
+ .max = 100,
},
};
@@ -306,8 +389,8 @@ static const struct ctl_table table_u8_valid[] = {
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
- .extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_TWO_HUNDRED,
+ .min = 0,
+ .max = 200,
},
};
--
2.25.1
next prev parent reply other threads:[~2026-10-28 16:35 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 16:34 [RFC PATCH 00/39] sysctl: replace overloaded extra pointers with typed bounds and context wen.yang
2026-10-28 16:34 ` [RFC PATCH 01/39] " wen.yang
2026-10-28 21:09 ` David Laight
2026-10-28 16:34 ` wen.yang [this message]
2026-10-28 16:34 ` [RFC PATCH 03/39] sysctl: add KUnit coverage for numeric bounds and handlers wen.yang
2026-10-28 16:34 ` [RFC PATCH 04/39] sysctl: cover runtime ranges and context lifecycles in KUnit wen.yang
2026-10-28 16:34 ` [RFC PATCH 05/39] sysctl: cover priv in KUnit and the debug test module wen.yang
2026-10-28 16:34 ` [RFC PATCH 06/39] sysctl: convert core table bounds to numeric values wen.yang
2026-10-28 16:34 ` [RFC PATCH 07/39] sysctl: store architecture sysctl bounds by value wen.yang
2026-10-28 16:34 ` [RFC PATCH 08/39] sysctl: store crypto " wen.yang
2026-10-28 16:34 ` [RFC PATCH 09/39] sysctl: store device " wen.yang
2026-10-28 16:34 ` [RFC PATCH 10/39] sysctl: store filesystem " wen.yang
2026-10-28 16:34 ` [RFC PATCH 11/39] sysctl: store message-queue " wen.yang
2026-10-28 16:34 ` [RFC PATCH 12/39] sysctl: store kernel " wen.yang
2026-10-28 16:34 ` [RFC PATCH 13/39] sysctl: store memory-management " wen.yang
2026-10-28 16:34 ` [RFC PATCH 14/39] sysctl: store IPv6 scalar " wen.yang
2026-10-28 16:34 ` [RFC PATCH 15/39] sysctl: store netfilter " wen.yang
2026-10-28 16:34 ` [RFC PATCH 16/39] sysctl: store RPC " wen.yang
2026-10-28 16:34 ` [RFC PATCH 17/39] sysctl: store remaining network " wen.yang
2026-10-28 16:34 ` [RFC PATCH 18/39] sysctl: store security " wen.yang
2026-10-28 16:34 ` [RFC PATCH 19/39] io_uring: store its " wen.yang
2026-10-28 16:34 ` [RFC PATCH 20/39] sysctl: refresh dynamic scheduler and PID bounds per call wen.yang
2026-10-28 16:35 ` [RFC PATCH 21/39] sysctl: refresh device-dependent " wen.yang
2026-10-28 16:35 ` [RFC PATCH 22/39] sysctl: refresh namespace IPC " wen.yang
2026-10-28 16:35 ` [RFC PATCH 23/39] yama: preserve scope locking with numeric sysctl bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 24/39] net: refresh core sysctl limits without bound pointers wen.yang
2026-10-28 16:35 ` [RFC PATCH 25/39] sctp: resolve numeric ranges from the current namespace wen.yang
2026-10-28 16:35 ` [RFC PATCH 26/39] rds: preserve live reconnect limits with numeric bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 27/39] ipv4: preserve live and vector bounds with numeric sysctls wen.yang
2026-10-28 16:35 ` [RFC PATCH 28/39] net: refresh fragment and remaining dynamic sysctl bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 29/39] neighbour: derive sysctl ownership independently of bounds wen.yang
2026-10-28 16:35 ` [RFC PATCH 30/39] net: resolve sysctl owners from their backing data wen.yang
2026-10-28 16:35 ` [RFC PATCH 31/39] ipvs: derive sysctl ownership from numeric storage wen.yang
2026-10-28 16:35 ` [RFC PATCH 32/39] sysctl: remove obsolete nr_open bound variables wen.yang
2026-10-28 16:35 ` [RFC PATCH 33/39] ipv6: move address sysctl context to priv wen.yang
2026-10-28 16:35 ` [RFC PATCH 34/39] ipv4: move device " wen.yang
2026-10-28 16:35 ` [RFC PATCH 35/39] netfilter: move logger " wen.yang
2026-10-28 16:35 ` [RFC PATCH 36/39] parport: move device " wen.yang
2026-10-28 16:35 ` [RFC PATCH 37/39] net: move namespace " wen.yang
2026-10-28 16:35 ` [RFC PATCH 38/39] arm64: move vector-length " wen.yang
2026-10-28 16:35 ` [RFC PATCH 39/39] sysctl: remove the extra pointers and the compatibility bounds read wen.yang
2026-10-29 10:58 ` [RFC PATCH 00/39] sysctl: replace overloaded extra pointers with typed bounds and context David Laight
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=4f48767377d817a63f348a7725056ca4c0869ef9.1793204511.git.wen.yang@linux.dev \
--to=wen.yang@linux.dev \
--cc=joel.granados@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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®