From: Joel Granados <joel.granados@kernel.org>
To: wen.yang@linux.dev
Cc: David Laight <david.laight.linux@gmail.com>,
Kees Cook <kees@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2 0/6] sysctl: replace overloaded extra pointers with typed bounds and core stride
Date: Tue, 24 Nov 2026 14:26:12 +0100 [thread overview]
Message-ID: <awV04op6IxD2NWQA@hobbes> (raw)
In-Reply-To: <cover.1794844686.git.wen.yang@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 9928 bytes --]
On Tue, Nov 17, 2026 at 12:07:32AM +0800, wen.yang@linux.dev wrote:
> From: Wen Yang <wen.yang@linux.dev>
Thx for taking the time to put this out. This gives perspective and adds
to the discussion of how best to move forward with "struct ctl_table".
>
> struct ctl_table has long relied on extra1 and extra2 pointers to serve
> multiple unrelated duties, including range limits and caller-specific
> context. This series addresses both:
>
> 1. Replace bound pointers with plain unsigned long min and max fields
> directly in struct ctl_table.
>
> 2. Replace per-entry context pointers with a core stride mechanism,
> allowing callers to register arrays of structures embedding struct
> ctl_table and recover enclosing context via standard container_of().
I think having these two at the same time is not the way to go. We need
to figure out where to put the non-bound context pointers first. And
after that is settled, we address the bound pointers.
Yes, we are doing the first to get to the later, but mixing them just
adds to the confusion. One thing at a time!
>
> This RFC focuses on the core stride infrastructure and two representative
> complex users (netfilter nf_log and IPv4 devinet), as suggested by Joel
> Granados. The remaining treewide callers are converted in a single
My suggestion was **not** for this implementation specifically. I
suggested you create an RFC to clearly understand your idea. Apologies
if that was not clear.
> squashed commit to ensure the tree builds and tests pass cleanly.
>
> Changes from v1:
> =================
> v1: https://lore.kernel.org/all/cover.1793204511.git.wen.yang@linux.dev/
>
> 1. Abandoned per-entry 'void *priv' (David Laight):
Though not adding yet another entry in ctl_table is commendable, I
prefer adding a priv entry over the stride mechanism in this series.
Here are my thoughts:
1. The type should set the stride in sysctl core. The situation where
the stride of a type might be different from its size should be avoided.
In these cases I would prefer a whole new type.
2. Having ctl_table as the grounding entry inside another struct and, at
the same time, it be a regular (non-grounding) entry is asking for
trouble.
- A proc_handler assumes there is a containing entry around only to
realize that it was passed just a pointer.
- The core might start overlaying clt_table entries to deal with
namespaces [1], [2], [3]
> - v1 added 'priv' to struct ctl_table, incurring 8 bytes on 64-bit and
> 4 bytes on 32-bit for all ~1,000 entries across thousands of dynamic
> instances, even though <7% of entries need context.
Just a quick comment here: If you want to get rid of 8/4 bytes with the
ctl_table struct, you might want to look at struct ctl_table_poll, which
(to my knowledge) is only used in one ctl_table array. Finding a way to
service utsname while at the same time removing that entry is much more
of a low hanging fruit IMO.
> - Refactor: context lives outside struct ctl_table via core stride;
> callers embed ctl_table at offset 0 of their own record and recover
> context with standard container_of().
> - Cost: zero growth in struct ctl_table (56/32 bytes) and zero growth
> in struct ctl_table_header (88/52 bytes, packing u16 stride and type).
>
> 2. Eliminated slot wrappers & index coupling (Joel Granados, David Laight):
> - An intermediate prototype discussed on the list used slot-indexed
> container recovery, requiring 32 wrapper functions in devinet and 11
> in nf_log.
> - Refactor: with core stride, the core passes the exact registered
> entry pointer to the handler, so handlers use container_of() directly
> and all 43 wrappers disappear without touching proc_handler
> signatures.
>
> 3. KUnit purity & dependency fix (0-day robot):
> - Removed register_sysctl() calls from KUnit; tests invoke
> proc_handler directly so no live /proc/sys nodes are modified.
> - Added 'depends on SYSCTL' to SYSCTL_KUNIT_TEST in lib/Kconfig.debug,
> fixing undefined symbols when built as a module with SYSCTL=n.
>
> 4. Baseline rebase & conflict resolution:
> - Rebased onto next-20261111 (aaa2f954c21b).
Thx for clarifying the base. It really helps with rebasing and
reviewing. Personally I prefer it be on top of one of the "rc"
candidates (like 7.4-rc3); with the only exception of dependencies
existing in next. Also, rebasing on the "rc" candidates might be easier
for sashiko to understand [4]
> - Added proc_dointvec_jiffies_minmax and proc_dointvec_ms_jiffies_minmax
> to sysctl_check_table().
>
> 5. Added Coccinelle verification script (Joel Granados):
> - A 17-rule script (patch and context modes) maps all 15 SYSCTL_*
> constants through one lookup table instead of repeating two rules
> per constant.
> - Bounds that point at a variable (&foo_min, &foo_max) are left
> untouched and reported: in several callers (power/main.c, i915_perf,
> ipc_sysctl, pid, sched/rt, rds, xprtsock) that variable is updated
> at boot or at run time, so inlining its initial value would silently
> freeze a live bound. The script also flags .min/.max fields holding
> a pointer or a legacy macro.
>
> 6. Streamlined RFC series layout (Joel Granados):
> - Reduced from 39 patches in v1 to 6 focused patches (core
> infrastructure, unit test, two complex stride consumers, coccinelle
> script.
Very nice!. This meant that I could just ignore that last commit and
focus on the core of your idea.
>
> Key Design Points:
> ==================
>
> 1. Zero Memory Growth:
> - struct ctl_table keeps its exact size (56 bytes on 64-bit, 32 bytes on
> 32-bit). No 'priv' field is added.
> - u16 ctl_table_stride is introduced into struct ctl_table_header.
> Together with u16 type, it occupies the existing alignment padding
> hole on 64-bit (88 bytes unchanged) and keeps 52 bytes on 32-bit.
> Registration rejects stride values that exceed U16_MAX.
> - Headers are allocated once per table registration (~240 sites
> in-tree), not per entry (thousands in-tree).
>
> 2. Eliminates some Wrapper Functions:
> - net/ipv4 devinet: registers strided struct devinet_sysctl_entry,
> eliminating 32 per-attribute wrapper functions.
> - Handlers recover their context using standard container_of() without
> changing any proc_handler signatures.
>
> 3. Standalone Stride API vs. Existing _sz:
> register_sysctl_stride() and register_net_sysctl_stride() are added
> alongside register_*_sz() so existing callers remain untouched. If
> preferred, stride can instead be folded into register_*_sz() as an
> element-size parameter (similar to bsearch()).
>
> 4. Fixes & Cleanups:
> - Fixes net.core sysctl write permissions in init_net (mode 0222 is
> now cleared only for non-init network namespaces).
> - Cleans up redundant '.min = 0' initializers treewide.
> - Provides a Coccinelle script (scripts/coccinelle/api/sysctl/) for
> automated conversion and proof of no leftover extra1/extra2 uses.
Did you consider the relation between the stride approach and namespaces?
The network subsys duplicates ctl_table arrays to have a unique value
per namespace. Would this still be possible with the stride approach?
Would it be orthogonal?
>
> Series Structure:
> =================
> - Patch 1: Core stride infrastructure and numeric bounds.
> - Patch 2: KUnit unit test coverage (21 tests, pure handler execution).
> - Patch 3: netfilter nf_log stride migration (11 wrappers removed).
> - Patch 4: net/ipv4 devinet stride migration (32 wrappers removed).
> - Patch 5: Coccinelle script for detection and conversion.
>
> Testing:
> ========
> - KUnit sysctl_test: pass:21 fail:0 (UML).
> - x86_64 defconfig build of kernel/, fs/proc/, net/ passed.
> - Coccinelle: full-tree MODE=context finds 0 leftovers after conversion
> and 822 before it; MODE=patch converts the legacy net/unix table.
>
>
> Wen Yang (5):
> sysctl: add numeric bounds and core stride infrastructure
> sysctl: cover numeric bounds and table containers in KUnit
> netfilter: embed logger sysctl context using stride
> net/ipv4: embed device sysctl context using stride
> scripts/coccinelle: add script to detect and convert sysctl bounds
>
> fs/proc/proc_sysctl.c | 82 +-
> include/linux/sysctl.h | 43 +-
> include/net/net_namespace.h | 10 +
> kernel/sysctl-test.c | 776 +++++++++++++++++-
> kernel/sysctl.c | 38 +-
> lib/Kconfig.debug | 1 +
> net/ipv4/devinet.c | 190 +++--
> net/netfilter/nf_log.c | 84 +-
> net/sysctl_net.c | 31 +-
> .../api/sysctl/sysctl_numeric_bounds.cocci | 276 +++++++
> 10 files changed, 1339 insertions(+), 192 deletions(-)
> create mode 100644 scripts/coccinelle/api/sysctl/sysctl_numeric_bounds.cocci
>
> base-commit: aaa2f954c21b205a0bcd0961e5b2be4e82e58455
> --
> 2.25.1
>
Thanks for working this through, and for reducing it to the real users;
that is what made the trade-offs visible. Having now understood your
idea, I don't think it is the right direction and would rather not take
it into the sysctl tree.
Best
[1] https://lore.kernel.org/all/cover.1787770053.git.legion@kernel.org
[2] https://lore.kernel.org/all/cover.1789987960.git.legion@kernel.org
[3] https://lore.kernel.org/all/cover.1790439358.git.legion@kernel.org
[4] https://sashiko.dev/#/patchset/cover.1794844686.git.wen.yang%40linux.dev
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
prev parent reply other threads:[~2026-11-24 13:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 16:07 wen.yang
2026-11-16 16:07 ` [RFC PATCH v2 1/5] sysctl: add numeric bounds and core stride infrastructure wen.yang
2026-11-16 16:07 ` [RFC PATCH v2 2/5] sysctl: cover numeric bounds and table containers in KUnit wen.yang
2026-11-16 16:07 ` [RFC PATCH v2 3/5] netfilter: embed logger sysctl context using stride wen.yang
2026-11-16 16:07 ` [RFC PATCH v2 4/5] net/ipv4: embed device " wen.yang
2026-11-16 16:07 ` [RFC PATCH v2 5/5] scripts/coccinelle: add script to detect and convert sysctl bounds wen.yang
2026-11-16 21:40 ` [RFC PATCH v2 0/6] sysctl: replace overloaded extra pointers with typed bounds and core stride David Laight
2026-11-17 17:01 ` Wen Yang
2026-11-17 18:10 ` David Laight
2026-11-24 13:26 ` Joel Granados [this message]
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=awV04op6IxD2NWQA@hobbes \
--to=joel.granados@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wen.yang@linux.dev \
/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®