Skip to content

Commit 5829614

Browse files
committed
Merge branch 'net-sysctl-sentinel'
Joel Granados says: ==================== sysctl: Remove sentinel elements from networking What? These commits remove the sentinel element (last empty element) from the sysctl arrays of all the files under the "net/" directory that register a sysctl array. The merging of the preparation patches [4] to mainline allows us to just remove sentinel elements without changing behavior. This is safe because the sysctl registration code (register_sysctl() and friends) use the array size in addition to checking for a sentinel [1]. Why? By removing the sysctl sentinel elements we avoid kernel bloat as ctl_table arrays get moved out of kernel/sysctl.c into their own respective subsystems. This move was started long ago to avoid merge conflicts; the sentinel removal bit came after Mathew Wilcox suggested it to avoid bloating the kernel by one element as arrays moved out. This patchset will reduce the overall build time size of the kernel and run time memory bloat by about ~64 bytes per declared ctl_table array (more info here [5]). When are we done? There are 4 patchest (25 commits [2]) that are still outstanding to completely remove the sentinels: files under "net/" (this patchset), files under "kernel/" dir, misc dirs (files under mm/ security/ and others) and the final set that removes the unneeded check for ->procname == NULL. Testing: * Ran sysctl selftests (./tools/testing/selftests/sysctl/sysctl.sh) * Ran this through 0-day with no errors or warnings Savings in vmlinux: A total of 64 bytes per sentinel is saved after removal; I measured in x86_64 to give an idea of the aggregated savings. The actual savings will depend on individual kernel configuration. * bloat-o-meter - The "yesall" config saves 3976 bytes (bloat-o-meter output [6]) - A reduced config [3] saves 1263 bytes (bloat-o-meter output [7]) Savings in allocated memory: None in this set but will occur when the superfluous allocations are removed from proc_sysctl.c. I include it here for context. The estimated savings during boot for config [3] are 6272 bytes. See [8] for how to measure it. Comments/feedback greatly appreciated Changes in v6: - Rebased onto net-next/main. - Besides re-running my cocci scripts, I ran a new find script [9]. Found 0 hits in net/ - Moved "i" variable declaraction out of for() in sysctl_core_net_init - Removed forgotten sentinel in mpls_table - Removed CONFIG_AX25_DAMA_SLAVE guard from net/ax25/ax25_ds_timer.c. It is not needed because that file is compiled only when CONFIG_AX25_DAMA_SLAVE is set. - When traversing smc_table, stop on ARRAY_SIZE instead of ARRAY_SIZE-1. - Link to v5: https://lore.kernel.org/r/20240426-jag-sysctl_remset_net-v5-0-e3b12f6111a6@samsung.com Changes in v5: - Added net files with additional variable to my test .config so the typo can be caught next time. - Fixed typo tabel_size -> table_size - Link to v4: https://lore.kernel.org/r/20240425-jag-sysctl_remset_net-v4-0-9e82f985777d@samsung.com Changes in v4: - Keep reverse xmas tree order when introducing new variables - Use a table_size variable to keep the value of ARRAY_SIZE - Separated the original "networking: Remove the now superfluous sentinel elements from ctl_table arra" into smaller commits to ease review - Merged x.25 and ax.25 commits together. - Removed any SOB from the commits that were changed - Link to v3: https://lore.kernel.org/r/20240412-jag-sysctl_remset_net-v3-0-11187d13c211@samsung.com Changes in v3: - Reworkded ax.25 - Added a BUILD_BUG_ON for the ax.25 commit - Added a CONFIG_AX25_DAMA_SLAVE guard where needed - Link to v2: https://lore.kernel.org/r/20240328-jag-sysctl_remset_net-v2-0-52c9fad9a1af@samsung.com Changes in v2: - Rebased to v6.9-rc1 - Removed unneeded comment from sysctl_net_ax25.c - Link to v1: https://lore.kernel.org/r/20240314-jag-sysctl_remset_net-v1-0-aa26b44d29d9@samsung.com ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents a17ef9e + 78a7b5d commit 5829614

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+48
-119
lines changed

include/net/ax25.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ enum {
139139
AX25_VALUES_N2, /* Default N2 value */
140140
AX25_VALUES_PACLEN, /* AX.25 MTU */
141141
AX25_VALUES_PROTOCOL, /* Std AX.25, DAMA Slave, DAMA Master */
142+
#ifdef CONFIG_AX25_DAMA_SLAVE
142143
AX25_VALUES_DS_TIMEOUT, /* DAMA Slave timeout */
144+
#endif
143145
AX25_MAX_VALUES /* THIS MUST REMAIN THE LAST ENTRY OF THIS LIST */
144146
};
145147

net/appletalk/sysctl_net_atalk.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ static struct ctl_table atalk_table[] = {
4040
.mode = 0644,
4141
.proc_handler = proc_dointvec_jiffies,
4242
},
43-
{ },
4443
};
4544

4645
static struct ctl_table_header *atalk_table_header;

net/ax25/ax25_dev.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ void ax25_dev_device_up(struct net_device *dev)
7878
ax25_dev->values[AX25_VALUES_N2] = AX25_DEF_N2;
7979
ax25_dev->values[AX25_VALUES_PACLEN] = AX25_DEF_PACLEN;
8080
ax25_dev->values[AX25_VALUES_PROTOCOL] = AX25_DEF_PROTOCOL;
81+
82+
#ifdef CONFIG_AX25_DAMA_SLAVE
8183
ax25_dev->values[AX25_VALUES_DS_TIMEOUT]= AX25_DEF_DS_TIMEOUT;
84+
#endif
8285

8386
#if defined(CONFIG_AX25_DAMA_SLAVE) || defined(CONFIG_AX25_DAMA_MASTER)
8487
ax25_ds_setup_timer(ax25_dev);

net/ax25/ax25_ds_timer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void ax25_ds_set_timer(ax25_dev *ax25_dev)
5555
ax25_dev->dama.slave_timeout =
5656
msecs_to_jiffies(ax25_dev->values[AX25_VALUES_DS_TIMEOUT]) / 10;
5757
mod_timer(&ax25_dev->dama.slave_timer, jiffies + HZ);
58+
return;
5859
}
5960

6061
/*

net/ax25/sysctl_net_ax25.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ static const struct ctl_table ax25_param_table[] = {
141141
.extra2 = &max_ds_timeout
142142
},
143143
#endif
144-
145-
{ } /* that's all, folks! */
146144
};
147145

148146
int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
@@ -155,6 +153,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
155153
if (!table)
156154
return -ENOMEM;
157155

156+
BUILD_BUG_ON(ARRAY_SIZE(ax25_param_table) != AX25_MAX_VALUES);
158157
for (k = 0; k < AX25_MAX_VALUES; k++)
159158
table[k].data = &ax25_dev->values[k];
160159

net/bridge/br_netfilter_hooks.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,6 @@ static struct ctl_table brnf_table[] = {
12261226
.mode = 0644,
12271227
.proc_handler = brnf_sysctl_call_tables,
12281228
},
1229-
{ }
12301229
};
12311230

12321231
static inline void br_netfilter_sysctl_default(struct brnf_net *brnf)

net/core/neighbour.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,7 +3733,7 @@ static int neigh_proc_base_reachable_time(struct ctl_table *ctl, int write,
37333733

37343734
static struct neigh_sysctl_table {
37353735
struct ctl_table_header *sysctl_header;
3736-
struct ctl_table neigh_vars[NEIGH_VAR_MAX + 1];
3736+
struct ctl_table neigh_vars[NEIGH_VAR_MAX];
37373737
} neigh_sysctl_template __read_mostly = {
37383738
.neigh_vars = {
37393739
NEIGH_SYSCTL_ZERO_INTMAX_ENTRY(MCAST_PROBES, "mcast_solicit"),
@@ -3784,7 +3784,6 @@ static struct neigh_sysctl_table {
37843784
.extra2 = SYSCTL_INT_MAX,
37853785
.proc_handler = proc_dointvec_minmax,
37863786
},
3787-
{},
37883787
},
37893788
};
37903789

@@ -3812,8 +3811,6 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
38123811
if (dev) {
38133812
dev_name_source = dev->name;
38143813
/* Terminate the table early */
3815-
memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
3816-
sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
38173814
neigh_vars_size = NEIGH_VAR_BASE_REACHABLE_TIME_MS + 1;
38183815
} else {
38193816
struct neigh_table *tbl = p->tbl;

net/core/sysctl_net_core.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ static struct ctl_table net_core_table[] = {
661661
.proc_handler = proc_dointvec_minmax,
662662
.extra1 = SYSCTL_ZERO,
663663
},
664-
{ }
665664
};
666665

667666
static struct ctl_table netns_core_table[] = {
@@ -698,7 +697,6 @@ static struct ctl_table netns_core_table[] = {
698697
.extra2 = SYSCTL_ONE,
699698
.proc_handler = proc_dou8vec_minmax,
700699
},
701-
{ }
702700
};
703701

704702
static int __init fb_tunnels_only_for_init_net_sysctl_setup(char *str)
@@ -716,20 +714,21 @@ __setup("fb_tunnels=", fb_tunnels_only_for_init_net_sysctl_setup);
716714

717715
static __net_init int sysctl_core_net_init(struct net *net)
718716
{
719-
struct ctl_table *tbl, *tmp;
717+
size_t table_size = ARRAY_SIZE(netns_core_table);
718+
struct ctl_table *tbl;
720719

721720
tbl = netns_core_table;
722721
if (!net_eq(net, &init_net)) {
722+
int i;
723723
tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
724724
if (tbl == NULL)
725725
goto err_dup;
726726

727-
for (tmp = tbl; tmp->procname; tmp++)
728-
tmp->data += (char *)net - (char *)&init_net;
727+
for (i = 0; i < table_size; ++i)
728+
tbl[i].data += (char *)net - (char *)&init_net;
729729
}
730730

731-
net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl,
732-
ARRAY_SIZE(netns_core_table));
731+
net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl, table_size);
733732
if (net->core.sysctl_hdr == NULL)
734733
goto err_reg;
735734

net/dccp/sysctl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ static struct ctl_table dccp_default_table[] = {
9090
.mode = 0644,
9191
.proc_handler = proc_dointvec_ms_jiffies,
9292
},
93-
94-
{ }
9593
};
9694

9795
static struct ctl_table_header *dccp_table_header;

net/ieee802154/6lowpan/reassembly.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ static struct ctl_table lowpan_frags_ns_ctl_table[] = {
338338
.mode = 0644,
339339
.proc_handler = proc_dointvec_jiffies,
340340
},
341-
{ }
342341
};
343342

344343
/* secret interval has been deprecated */
@@ -351,7 +350,6 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
351350
.mode = 0644,
352351
.proc_handler = proc_dointvec_jiffies,
353352
},
354-
{ }
355353
};
356354

357355
static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
@@ -370,10 +368,8 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
370368
goto err_alloc;
371369

372370
/* Don't export sysctls to unprivileged users */
373-
if (net->user_ns != &init_user_ns) {
374-
table[0].procname = NULL;
371+
if (net->user_ns != &init_user_ns)
375372
table_size = 0;
376-
}
377373
}
378374

379375
table[0].data = &ieee802154_lowpan->fqdir->high_thresh;

0 commit comments

Comments
 (0)