[PATCH v2 5/6] sysctl: mq: use typed fields for IPC namespace sysctls
From: Alexey Gladkov
Date: Mon Sep 21 2026 - 06:58:02 EST
Convert mq_sysctls. The table can now share one static array across ipc
namespaces instead of allocating and rewriting a ctl_table copy for each
registration.
Signed-off-by: Alexey Gladkov <legion@xxxxxxxxxx>
---
ipc/mq_sysctl.c | 104 ++++++++++++++++++++----------------------------
1 file changed, 43 insertions(+), 61 deletions(-)
diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
index 0dd12e1c9f53..0d57708e9ea7 100644
--- a/ipc/mq_sysctl.c
+++ b/ipc/mq_sysctl.c
@@ -14,55 +14,63 @@
#include <linux/slab.h>
#include <linux/cred.h>
-static int msg_max_limit_min = MIN_MSGMAX;
-static int msg_max_limit_max = HARD_MSGMAX;
+static unsigned int msg_max_limit_min = MIN_MSGMAX;
+static unsigned int msg_max_limit_max = HARD_MSGMAX;
-static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
-static int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
+static unsigned int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
+static unsigned int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
-static const struct ctl_table mq_sysctls[] = {
+static const struct sysctl_field mq_sysctls[] = {
{
.procname = "queues_max",
- .data = &init_ipc_ns.mq_queues_max,
- .maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec,
+ .type = SYSCTL_FIELD_UINT,
+ .data_offset = SYSCTL_FIELD_UINT_OFFSET(struct ipc_namespace,
+ mq_queues_max),
},
{
.procname = "msg_max",
- .data = &init_ipc_ns.mq_msg_max,
- .maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
- .extra1 = &msg_max_limit_min,
- .extra2 = &msg_max_limit_max,
+ .type = SYSCTL_FIELD_UINT_MINMAX,
+ .data_offset = SYSCTL_FIELD_UINT_OFFSET(struct ipc_namespace,
+ mq_msg_max),
+ .uint_limits = {
+ .min = &msg_max_limit_min,
+ .max = &msg_max_limit_max,
+ },
},
{
.procname = "msgsize_max",
- .data = &init_ipc_ns.mq_msgsize_max,
- .maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
- .extra1 = &msg_maxsize_limit_min,
- .extra2 = &msg_maxsize_limit_max,
+ .type = SYSCTL_FIELD_UINT_MINMAX,
+ .data_offset = SYSCTL_FIELD_UINT_OFFSET(struct ipc_namespace,
+ mq_msgsize_max),
+ .uint_limits = {
+ .min = &msg_maxsize_limit_min,
+ .max = &msg_maxsize_limit_max,
+ },
},
{
.procname = "msg_default",
- .data = &init_ipc_ns.mq_msg_default,
- .maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
- .extra1 = &msg_max_limit_min,
- .extra2 = &msg_max_limit_max,
+ .type = SYSCTL_FIELD_UINT_MINMAX,
+ .data_offset = SYSCTL_FIELD_UINT_OFFSET(struct ipc_namespace,
+ mq_msg_default),
+ .uint_limits = {
+ .min = &msg_max_limit_min,
+ .max = &msg_max_limit_max,
+ },
},
{
.procname = "msgsize_default",
- .data = &init_ipc_ns.mq_msgsize_default,
- .maxlen = sizeof(int),
.mode = 0644,
- .proc_handler = proc_dointvec_minmax,
- .extra1 = &msg_maxsize_limit_min,
- .extra2 = &msg_maxsize_limit_max,
+ .type = SYSCTL_FIELD_UINT_MINMAX,
+ .data_offset = SYSCTL_FIELD_UINT_OFFSET(struct ipc_namespace,
+ mq_msgsize_default),
+ .uint_limits = {
+ .min = &msg_maxsize_limit_min,
+ .max = &msg_maxsize_limit_max,
+ },
},
};
@@ -116,39 +124,17 @@ static struct ctl_table_root set_root = {
bool setup_mq_sysctls(struct ipc_namespace *ns)
{
- struct ctl_table *tbl;
+ struct sysctl_context ctx = {
+ .type = SYSCTL_CONTEXT_IPC_NS,
+ .object_size = sizeof(*ns),
+ .ns.ipc_ns = ns,
+ };
setup_sysctl_set(&ns->mq_set, &set_root, set_is_seen);
- tbl = kmemdup(mq_sysctls, sizeof(mq_sysctls), GFP_KERNEL);
- if (tbl) {
- int i;
-
- for (i = 0; i < ARRAY_SIZE(mq_sysctls); i++) {
- if (tbl[i].data == &init_ipc_ns.mq_queues_max)
- tbl[i].data = &ns->mq_queues_max;
-
- else if (tbl[i].data == &init_ipc_ns.mq_msg_max)
- tbl[i].data = &ns->mq_msg_max;
-
- else if (tbl[i].data == &init_ipc_ns.mq_msgsize_max)
- tbl[i].data = &ns->mq_msgsize_max;
-
- else if (tbl[i].data == &init_ipc_ns.mq_msg_default)
- tbl[i].data = &ns->mq_msg_default;
-
- else if (tbl[i].data == &init_ipc_ns.mq_msgsize_default)
- tbl[i].data = &ns->mq_msgsize_default;
- else
- tbl[i].data = NULL;
- }
-
- ns->mq_sysctls = __register_sysctl_table(&ns->mq_set,
- "fs/mqueue", tbl,
- ARRAY_SIZE(mq_sysctls));
- }
+ ns->mq_sysctls = register_sysctl_fields(&ns->mq_set, "fs/mqueue",
+ mq_sysctls, &ctx);
if (!ns->mq_sysctls) {
- kfree(tbl);
retire_sysctl_set(&ns->mq_set);
return false;
}
@@ -158,10 +144,6 @@ bool setup_mq_sysctls(struct ipc_namespace *ns)
void retire_mq_sysctls(struct ipc_namespace *ns)
{
- const struct ctl_table *tbl;
-
- tbl = ns->mq_sysctls->ctl_table_arg;
unregister_sysctl_table(ns->mq_sysctls);
retire_sysctl_set(&ns->mq_set);
- kfree(tbl);
}
--
2.55.0