sysctl: encode the min/max values directly in the table entry
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest posting 2/25 patches 0 repliesNew
- v5 posting 1/21 patch 18 repliesSuperseded
- v4 posting 2/21 patch 3 repliesSuperseded
Earlier versions · 5
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v4 posting 1/2 | 1 patch | 0 replies | Superseded | |
| v3 posting 2/2 | 1 patch | 5 replies | Superseded | |
| v3 posting 1/2 | 1 patch | 0 replies | Superseded | |
| v2 | 1 patch | 2 replies | Superseded | |
| v1 | 1 patch | 0 replies | Superseded |
Patches in v5 posting 2/2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | sysctl: simplify the min/max boundary checkkernel/ | +73 | 0 replies | |
| 2/5 | sysctl: add helper functions to extract table->extra1/extra2fs/ include/ kernel/ | +63 | 0 replies | |
| 3/5 | sysctl: support encoding values directly in the table entryfs/ include/ | +32 | 0 replies | |
| 4/5 | sysctl: add kunit test code to check the min/max encoding of sysctl table entrieskernel/ | +581 | 0 replies | |
| 5/5 | sysctl: delete six_hundred_forty_kb to save 4 byteskernel/ | +3 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.
Cover letter [PATCH v5 0/5] sysctl: encode the min/max values directly in the table entry
Many modules use these additional static/global variables (such as two_five_five, n_65535, ue_int_max, etc.) in the boundary checking of sysctl, and they are read-only and never changed.
Eric points out:
- One of the things that happens and that is worth acknowledging is there
- is code that wraps proc_doulongvec_minmax and proc_dointvec_minmax.
- Having the minmax information separate from the data pointer makes that
- wrapping easier.
- Further the min/max information is typically separate from other kinds
- of data. So even when not wrapped it is nice just to take a quick
- glance and see what the minimums and maximums are.
- My original suggest was that we change struct ctl_table from:
- > /* A sysctl table is an array of struct ctl_table: */
- > struct ctl_table {
- > const char *procname; /* Text ID for /proc/sys */
- > void *data;
- > int maxlen;
- > umode_t mode;
- > proc_handler *proc_handler; /* Callback for text formatting */
- > struct ctl_table_poll *poll;
- > void *extra1;
- > void *extra2;
- > } __randomize_layout;
- to:
- > /* A sysctl table is an array of struct ctl_table: */
- > struct ctl_table {
- > const char *procname; /* Text ID for /proc/sys */
- > void *data;
- > int maxlen;
- > umode_t mode;
- > proc_handler *proc_handler; /* Callback for text formatting */
- > struct ctl_table_poll *poll;
- > unsigned long min;
- > unsigned long max;
- > } __randomize_layout;
- That is just replace extra1 and extra2 with min and max members. The
- members don't have any reason to be pointers. Without being pointers
- the min/max functions can just use long values to cap either ints or
- longs, and there is no room for error. The integer promotion rules
- will ensure that even negative values can be stored in unsigned long
- min and max values successfully. Plus it is all bog standard C
- so there is nothing special to learn.
- There are a bunch of fiddly little details to transition from where we
- are today. The most straightforward way I can see of making the
- transition is to add the min and max members. Come up with replacements
- for proc_doulongvec_minmax and proc_dointvec_minmax that read the new
- min and max members. Update all of the users. Update the few users
- that use extra1 or extra2 for something besides min and max. Then
- remove extra1 and extra2. At the end it is simpler and requires the
- same or a little less space.
This patch series achieves direct encoding min/max values in table entries and still maintains compatibility with existing extra1/extra2 pointers. Afterwards, we can remove these unnecessary static variables progressively and also finally kill the shared const array.
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
and
https://lore.kernel.org/all/[email protected]/
Wen Yang (5):
sysctl: simplify the min/max boundary check
sysctl: add helper functions to extract table->extra1/extra2
sysctl: support encoding values directly in the table entry
sysctl: add kunit test code to check the min/max encoding of sysctl
table entries
sysctl: delete six_hundred_forty_kb to save 4 bytes
fs/proc/proc_sysctl.c | 35 ++- include/linux/sysctl.h | 64 ++++- kernel/sysctl-test.c | 581 +++++++++++++++++++++++++++++++++++++++++ kernel/sysctl.c | 211 ++++++--------- 4 files changed, 739 insertions(+), 152 deletions(-)
Signature · 1 line
2.25.1