Re: [PATCH v3 00/11] sysctl: treewide: constify ctl_table argument of sysctl handlers

2024-05-12 Thread Joel Granados
On Sat, May 11, 2024 at 11:51:18AM +0200, Thomas Weißschuh wrote:
> Hi Kees,
> 
> On 2024-05-08 10:11:35+, Kees Cook wrote:
> > On Wed, Apr 24, 2024 at 08:12:34PM -0700, Jakub Kicinski wrote:
> > > On Tue, 23 Apr 2024 09:54:35 +0200 Thomas Weißschuh wrote:
> > > > The series was split from my larger series sysctl-const series [0].
> > > > It only focusses on the proc_handlers but is an important step to be
> > > > able to move all static definitions of ctl_table into .rodata.
> > > 
> > > Split this per subsystem, please.
> > 
> > I've done a few painful API transitions before, and I don't think the
> > complexity of these changes needs a per-subsystem constification pass. I
> > think this series is the right approach, but that patch 11 will need
> > coordination with Linus. We regularly do system-wide prototype changes
> > like this right at the end of the merge window before -rc1 comes out.
> 
> That sounds good.
> 
> > The requirements are pretty simple: it needs to be a obvious changes
> > (this certainly is) and as close to 100% mechanical as possible. I think
> > patch 11 easily qualifies. Linus should be able to run the same Coccinelle
> > script and get nearly the same results, etc. And all the other changes
> > need to have landed. This change also has no "silent failure" conditions:
> > anything mismatched will immediately stand out.
> 
> Unfortunately coccinelle alone is not sufficient, as some helpers with
> different prototypes are called by handlers and themselves are calling
> handler and therefore need to change in the same commit.
> But if I add a diff for those on top of the coccinelle script to the
> changelog it should be obvious.
Judging by Kees' comment on "100% mechanical", it might be better just
having the diff and have Linus apply than rather than two step process?
Have not these types of PRs, so am interested in what folks think.

> 
> > So, have patches 1-10 go via their respective subsystems, and once all
> > of those are in Linus's tree, send patch 11 as a stand-alone PR.
> 
> Ack, I'll do that with the cover letter information requested by Joel.
> 
> > (From patch 11, it looks like the seccomp read/write function changes
> > could be split out? I'll do that now...)
> 
> Thanks!
> 
> Thomas

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v3 00/11] sysctl: treewide: constify ctl_table argument of sysctl handlers

2024-05-12 Thread Joel Granados
On Wed, May 08, 2024 at 10:11:35AM -0700, Kees Cook wrote:
> On Wed, Apr 24, 2024 at 08:12:34PM -0700, Jakub Kicinski wrote:
> > On Tue, 23 Apr 2024 09:54:35 +0200 Thomas Wei�schuh wrote:
> > > The series was split from my larger series sysctl-const series [0].
> > > It only focusses on the proc_handlers but is an important step to be
> > > able to move all static definitions of ctl_table into .rodata.
> > 
> > Split this per subsystem, please.
> 
Thx for stepping in to move this forward.

> I've done a few painful API transitions before, and I don't think the
> complexity of these changes needs a per-subsystem constification pass. I
> think this series is the right approach, but that patch 11 will need
> coordination with Linus. We regularly do system-wide prototype changes
> like this right at the end of the merge window before -rc1 comes out.
This would be more for 6.11, as I expect the other subsystems to freeze
for the merge window.

> 
> The requirements are pretty simple: it needs to be a obvious changes
> (this certainly is) and as close to 100% mechanical as possible. I think
> patch 11 easily qualifies. Linus should be able to run the same Coccinelle
> script and get nearly the same results, etc. And all the other changes
The coccinelle script is not enough. But that patch 11 should still be
trivial enough to go in before -rc1. right?

> need to have landed. This change also has no "silent failure" conditions:
> anything mismatched will immediately stand out.
> 
> So, have patches 1-10 go via their respective subsystems, and once all
> of those are in Linus's tree, send patch 11 as a stand-alone PR.
Thomas: I can take the sysctl subsystem related patches ("[PATCH v3
10/11] sysctl: constify ctl_table arguments of utility function"), while
you push the others to their respective subsystems (If you have not
already)

> 
> (From patch 11, it looks like the seccomp read/write function changes
> could be split out? I'll do that now...)
I saw that that patch has the necessary reviews. Get back to me if you
need me to take a quick look at it.

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v3 00/11] sysctl: treewide: constify ctl_table argument of sysctl handlers

2024-05-08 Thread Joel Granados
On Fri, May 03, 2024 at 04:09:40PM +0200, Thomas Weißschuh wrote:
> Hey Joel,
> 
...
> > # Motivation
> > As I read it, the motivation for these constification efforts are:
> > 1. It provides increased safety: Having things in .rodata section reduces 
> > the
> >attack surface. This is especially relevant for structures that have 
> > function
> >pointers (like ctl_table); having these in .rodata means that these 
> > pointers
> >always point to the "intended" function and cannot be changed.
> > 2. Compiler optimizations: This was just a comment in the patchsets that I 
> > have
> >mentioned ([3,4,5]). Do you know what optimizations specifically? Does it
> >have to do with enhancing locality for the data in .rodata? Do you have 
> > other
> >specific optimizations in mind?
> 
> I don't know about anything that would make it faster.
> It's more about safety and transmission of intent to API users,
> especially callback implementers.
Noted.

...
> > # Show the move
> > I created [8] because there is no easy way to validate which objects made it
> > into .rodata. I ran [8] for your Dec 2nd patcheset [7] and there are less in
> > .rodata than I expected (the results are in [9]) Why is that? Is it 
> > something
> > that has not been posted to the lists yet? 
> 
> Constifying the APIs only *allows* the actual table to be constified
> themselves.
> Then each table definition will have to be touched and "const" added.
That is what I thought. thx for clarifying.

> 
> See patches 17 and 18 in [7] for two examples.
> 
> Some tables in net/ are already "const" as the static definitions are
> never registered themselves but only their copies are.
> 
...

best

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v3 00/11] sysctl: treewide: constify ctl_table argument of sysctl handlers

2024-05-08 Thread Joel Granados
Kees

Could you comment on the feasibility of this alternative from the
Control Flow Integrity perspective. My proposal is to change the
proc_handler to void* and back in the same release. So there would not
be a kernel released with a void* proc_handler.

> > However, there is an alternative way to do this that allows chunking. We
> > first define the proc_handler as a void pointer (casting it where it is
> > being used) [1]. Then we could do the constification by subsystem (like
> > Jakub proposes). Finally we can "revert the void pointer change so we
> > don't have one size fit all pointer as our proc_handler [2].
> > 
> > Here are some comments about the alternative:
> > 1. We would need to make the first argument const in all the derived
> >proc_handlers [3] 
> > 2. There would be no undefined behavior for two reasons:
> >2.1. There is no case where we change the first argument. We know
> > this because there are no compile errors after we make it const.
> >2.2. We would always go from non-const to const. This is the case
> > because all the stuff that is unchanged in non-const.
> > 3. If the idea sticks, it should go into mainline as one patchset. I
> >would not like to have a void* proc_handler in a kernel release.
> > 4. I think this is a "win/win" solution were the constification goes
> >through and it is divided in such a way that it is reviewable.
> > 
> > I would really like to hear what ppl think about this "heretic"
> > alternative. @Thomas, @Luis, @Kees @Jakub?
> 
> Thanks for that alternative, I'm not a big fan though.
> 
> Besides the wonky syntax, Control Flow Integrity should trap on
> this construct. Functions are called through different pointers than
> their actual types which is exactly what CFI is meant to prevent.
> 
> Maybe people find it easier to review when using
> "--word-diff" and/or "-U0" with git diff/show.
> There is really nothing going an besides adding a few "const"s.
> 
> But if the consensus prefers this solution, I'll be happy to adopt it.
> 
> > [1] 
> > https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/commit/?h=jag/constfy_treewide_alternative=4a383503b1ea650d4e12c1f5838974e879f5aa6f
> > [2] 
> > https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/commit/?h=jag/constfy_treewide_alternative=a3be65973d27ec2933b9e81e1bec60be3a9b460d
> > [3] proc_dostring, proc_dobool, proc_dointvec
> 
> 
> Thomas

Best
-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v3 00/11] sysctl: treewide: constify ctl_table argument of sysctl handlers

2024-05-03 Thread Joel Granados
ruct ctl_table ']
ctl_table_structs = remove_tokens_re(exec_cmd( cmd ), regex_patterns)

cmd = "readelf -X -Ws build/vmlinux"
regex_patterns = ['.*OBJECT.*']
output_lines = filter_in_lines(exec_cmd( cmd ), regex_patterns);

regex_patterns = ['^.*OBJECT', '[ \t]+[A-Z]+[ \t]+[A-Z]+.*\(.*\)[ \t]+']
obj_elems = remove_tokens_re( output_lines, regex_patterns, uniq=False)

regex_patterns = ['^.*\(', '\)[ ]+.*$']
sec_names = remove_tokens_re( output_lines, regex_patterns, uniq=False)

for i in range(len(sec_names)):
obj_name = obj_elems[i]
if obj_name in ctl_table_structs:
print ("section: {}\t\tobj_name : {}". format(sec_names[i], 
obj_name))

[9]
section: .rodataobj_name : kern_table
section: .rodataobj_name : sysctl_mount_point
section: .rodataobj_name : addrconf_sysctl
section: .rodataobj_name : ax25_param_table
section: .rodataobj_name : mpls_table
section: .rodataobj_name : mpls_dev_table
section: .data  obj_name : sld_sysctls
section: .data  obj_name : kern_panic_table
section: .data  obj_name : kern_exit_table
section: .data  obj_name : vm_table
section: .data  obj_name : signal_debug_table
section: .data  obj_name : usermodehelper_table
section: .data  obj_name : kern_reboot_table
section: .data  obj_name : user_table
section: .bss   obj_name : sched_core_sysctls
section: .data  obj_name : sched_fair_sysctls
section: .data  obj_name : sched_rt_sysctls
section: .data  obj_name : sched_dl_sysctls
section: .data  obj_name : printk_sysctls
section: .data  obj_name : pid_ns_ctl_table_vm
section: .data  obj_name : seccomp_sysctl_table
section: .data  obj_name : uts_kern_table
section: .data  obj_name : vm_oom_kill_table
section: .data  obj_name : vm_page_writeback_sysctls
section: .data  obj_name : page_alloc_sysctl_table
section: .data  obj_name : hugetlb_table
section: .data  obj_name : fs_stat_sysctls
section: .data  obj_name : fs_exec_sysctls
section: .data  obj_name : fs_pipe_sysctls
section: .data  obj_name : namei_sysctls
section: .data  obj_name : fs_dcache_sysctls
section: .data  obj_name : inodes_sysctls
section: .data  obj_name : fs_namespace_sysctls
section: .data  obj_name : dnotify_sysctls
section: .data  obj_name : inotify_table
section: .data  obj_name : epoll_table
section: .data  obj_name : aio_sysctls
section: .data  obj_name : locks_sysctls
section: .data  obj_name : coredump_sysctls
section: .data  obj_name : fs_shared_sysctls
section: .data  obj_name : fs_dqstats_table
section: .data  obj_name : root_table
section: .data  obj_name : pty_table
section: .data  obj_name : xfs_table
section: .data  obj_name : ipc_sysctls
section: .data  obj_name : key_sysctls
section: .data  obj_name : kernel_io_uring_disabled_table
section: .data  obj_name : tty_table
section: .data  obj_name : random_table
section: .data  obj_name : scsi_table
section: .data  obj_name : iwcm_ctl_table
section: .data  obj_name : net_core_table
section: .data  obj_name : netns_core_table
section: .bss   obj_name : nf_log_sysctl_table
section: .data  obj_name : nf_log_sysctl_ftable
section: .data  obj_name : vs_vars
section: .data  obj_name : vs_vars_table
section: .data  obj_name : ipv4_route_netns_table
section: .data  obj_name : ipv4_route_table
section: .data  obj_name : ip4_frags_ns_ctl_table
section: .data  obj_name : ip4_frags_ctl_table
section: .data  obj_name : ctl_forward_entry
section: .data  obj_name : ipv4_table
section: .data  obj_name : ipv4_net_table
section: .data  obj_name : unix_table
section: .data  obj_name : ipv6_route_table_template
section: .data  obj_name : ipv6_icmp_table_template
section: .data  obj_name : ip6_frags_ns_ctl_table
section: .data  obj_name : ip6_frags_ctl_table
section: .data  obj_name : ipv6_table_template
section: .data  obj_name : ipv6_rotable
section: .data  obj_name : sctp_net_table
section: .data  obj_name : sctp_table
section: .data  obj_name : smc_table
section: .data  obj_name : lowpan_frags_ns_ctl_table
section: .data  obj_name : lowpan_frags_ctl_table

--

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v3 00/11] sysctl: treewide: constify ctl_table argument of sysctl handlers

2024-04-25 Thread Joel Granados
On Wed, Apr 24, 2024 at 08:12:34PM -0700, Jakub Kicinski wrote:
> On Tue, 23 Apr 2024 09:54:35 +0200 Thomas Weißschuh wrote:
> > The series was split from my larger series sysctl-const series [0].
> > It only focusses on the proc_handlers but is an important step to be
> > able to move all static definitions of ctl_table into .rodata.
> 
> Split this per subsystem, please.
It is tricky to do that because it changes the first argument (ctl*) to
const in the proc_handler function type defined in sysclt.h:
"
-typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer,
+typedef int proc_handler(const struct ctl_table *ctl, int write, void *buffer,
size_t *lenp, loff_t *ppos);
"
This means that all the proc_handlers need to change at the same time.

However, there is an alternative way to do this that allows chunking. We
first define the proc_handler as a void pointer (casting it where it is
being used) [1]. Then we could do the constification by subsystem (like
Jakub proposes). Finally we can "revert the void pointer change so we
don't have one size fit all pointer as our proc_handler [2].

Here are some comments about the alternative:
1. We would need to make the first argument const in all the derived
   proc_handlers [3] 
2. There would be no undefined behavior for two reasons:
   2.1. There is no case where we change the first argument. We know
this because there are no compile errors after we make it const.
   2.2. We would always go from non-const to const. This is the case
because all the stuff that is unchanged in non-const.
3. If the idea sticks, it should go into mainline as one patchset. I
   would not like to have a void* proc_handler in a kernel release.
4. I think this is a "win/win" solution were the constification goes
   through and it is divided in such a way that it is reviewable.

I would really like to hear what ppl think about this "heretic"
alternative. @Thomas, @Luis, @Kees @Jakub?

Best

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/commit/?h=jag/constfy_treewide_alternative=4a383503b1ea650d4e12c1f5838974e879f5aa6f
[2] 
https://git.kernel.org/pub/scm/linux/kernel/git/joel.granados/linux.git/commit/?h=jag/constfy_treewide_alternative=a3be65973d27ec2933b9e81e1bec60be3a9b460d
[3] proc_dostring, proc_dobool, proc_dointvec

--

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v3 0/7] sysctl: Remove sentinel elements from arch

2023-10-11 Thread Joel Granados
On Tue, Oct 10, 2023 at 03:22:34PM -0700, Luis Chamberlain wrote:
> On Mon, Oct 02, 2023 at 01:30:35PM +0200, Joel Granados via B4 Relay wrote:
> > V3:
> > * Removed the ia64 patch to avoid conflicts with the ia64 removal
> > * Rebased onto v6.6-rc4
> > * Kept/added the trailing comma for the ctl_table arrays. This was a comment
> >   that we received "drivers/*" patch set.
> > * Link to v2: 
> > https://lore.kernel.org/r/20230913-jag-sysctl_remove_empty_elem_arch-v2-0-d1bd13a29...@samsung.com
> 
> Thanks! I replaced the v2 with this v3 on sysctl-next.
perfect
> 
>   Luis

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v2 00/15] sysctl: Remove sentinel elements from drivers

2023-10-09 Thread Joel Granados
On Sun, Oct 08, 2023 at 09:28:00AM +1100, Michael Ellerman wrote:
> Joel Granados  writes:
> > On Mon, Oct 02, 2023 at 12:27:18PM +, Christophe Leroy wrote:
> >> Le 02/10/2023 à 10:55, Joel Granados via B4 Relay a écrit :
> >> > From: Joel Granados 
> >> > 
> > <--- snip --->
> >> >  - The "yesall" config saves 2432 bytes [4]
> >> >  - The "tiny" config saves 64 bytes [5]
> >> >  * memory usage:
> >> >  In this case there were no bytes saved because I do not have any
> >> >  of the drivers in the patch. To measure it comment the printk in
> >> >  `new_dir` and uncomment the if conditional in `new_links` [3].
> >> > 
> >> > ---
> >> > Changes in v2:
> >> > - Left the dangling comma in the ctl_table arrays.
> >> > - Link to v1: 
> >> > https://lore.kernel.org/r/20230928-jag-sysctl_remove_empty_elem_drivers-v1-0-e59120fca...@samsung.com
> >> > 
> >> > Comments/feedback greatly appreciated
> >> 
> >> Same problem on powerpc CI tests, all boot target failed, most of them 
> >> with similar OOPS, see 
> >> https://protect2.fireeye.com/v1/url?k=9496ce12-f51ddb24-9497455d-000babff9b5d-d6b001302bd0fd0d=1=044c4c09-2b44-4ded-a682-a5afe9b8beec=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Flinuxppc-dev%2Fpatch%2F20231002-jag-sysctl_remove_empty_elem_drivers-v2-15-02dd0d46f71e%40samsung.com%2F
> > I found the culprit!. Here you are rebasing on top of v6.5.0-rc6 "INFO:
> > Looking for kernel version: 6.5.0-rc6-gbf2ac4d7d596". The error makes
> > sense becuase in that version we have not introduced the stopping
> > criteria based on the ctl_table array size, so the loop continues
> > looking for an empty sentinel past valid memory (and does not find it).
> > The ctl_table check catches it but then fails to do a proper error
> > because we have already tried to access invalid memory. The solution
> > here is to make sure to rebase in on top of the latest rc in v6.6.
> 
> Thanks for tracking it down.
> 
> This is my fault, previously Russell would update the branch that the CI
> uses as its base. Now that he has left I need to do that myself, but had
> forgotten.
> 
> Sorry for the noise.
no worries. It was very helpfull to have two runs to compare with. That
was actually the thing that helped me find the issue.

Best
> 
> cheers

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH v2 00/15] sysctl: Remove sentinel elements from drivers

2023-10-03 Thread Joel Granados
On Mon, Oct 02, 2023 at 12:27:18PM +, Christophe Leroy wrote:
> 
> 
> Le 02/10/2023 à 10:55, Joel Granados via B4 Relay a écrit :
> > From: Joel Granados 
> > 
<--- snip --->
> >  - The "yesall" config saves 2432 bytes [4]
> >  - The "tiny" config saves 64 bytes [5]
> >  * memory usage:
> >  In this case there were no bytes saved because I do not have any
> >  of the drivers in the patch. To measure it comment the printk in
> >  `new_dir` and uncomment the if conditional in `new_links` [3].
> > 
> > ---
> > Changes in v2:
> > - Left the dangling comma in the ctl_table arrays.
> > - Link to v1: 
> > https://lore.kernel.org/r/20230928-jag-sysctl_remove_empty_elem_drivers-v1-0-e59120fca...@samsung.com
> > 
> > Comments/feedback greatly appreciated
> 
> Same problem on powerpc CI tests, all boot target failed, most of them 
> with similar OOPS, see 
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20231002-jag-sysctl_remove_empty_elem_drivers-v2-15-02dd0d46f...@samsung.com/
I found the culprit!. Here you are rebasing on top of v6.5.0-rc6 "INFO:
Looking for kernel version: 6.5.0-rc6-gbf2ac4d7d596". The error makes
sense becuase in that version we have not introduced the stopping
criteria based on the ctl_table array size, so the loop continues
looking for an empty sentinel past valid memory (and does not find it).
The ctl_table check catches it but then fails to do a proper error
because we have already tried to access invalid memory. The solution
here is to make sure to rebase in on top of the latest rc in v6.6.

> 
> What is strange is that I pushed your series into my github account, and 
> got no failure, see https://github.com/chleroy/linux/actions/runs/6378951278
And here it works because you use the latest rc : "INFO: Looking for
kernel version: 6.6.0-rc3-g23d4b5db743c"

> 
> Christophe
> 
> > 
> > Best
> > 
> > Joel
> > 
> > [1]
> > We are able to remove a sentinel table without behavioral change by
> > introducing a table_size argument in the same place where procname is
> > checked for NULL. The idea is for it to keep stopping when it hits
> > ->procname == NULL, while the sentinel is still present. And when the
> > sentinel is removed, it will stop on the table_size. You can go to
> > (https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/)
> > for more information.
> > 
> > [2]
> > Links Related to the ctl_table sentinel removal:
> > * Good summary from Luis sent with the "pull request" for the
> >preparation patches.
> >https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/
> > * Another very good summary from Luis.
> >https://lore.kernel.org/all/zmfizkfkvxuft...@bombadil.infradead.org/
> > * This is a patch set that replaces register_sysctl_table with 
> > register_sysctl
> >https://lore.kernel.org/all/20230302204612.782387-1-mcg...@kernel.org/
> > * Patch set to deprecate register_sysctl_paths()
> >https://lore.kernel.org/all/20230302202826.776286-1-mcg...@kernel.org/
> > * Here there is an explicit expectation for the removal of the sentinel 
> > element.
> >https://lore.kernel.org/all/20230321130908.6972-1-frank...@vivo.com
> > * The "ARRAY_SIZE" approach was mentioned (proposed?) in this thread
> >https://lore.kernel.org/all/20220220060626.15885-1-tangm...@uniontech.com
> > 
> > [3]
> > To measure the in memory savings apply this on top of this patchset.
> > 
> > "
> > diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
> > index c88854df0b62..e0073a627bac 100644
> > --- a/fs/proc/proc_sysctl.c
> > +++ b/fs/proc/proc_sysctl.c
> > @@ -976,6 +976,8 @@ static struct ctl_dir *new_dir(struct ctl_table_set 
> > *set,
> >  table[0].procname = new_name;
> >  table[0].mode = S_IFDIR|S_IRUGO|S_IXUGO;
> >  init_header(>header, set->dir.header.root, set, node, table, 
> > 1);
> > +   // Counts additional sentinel used for each new dir.
> > +   printk("%ld sysctl saved mem kzalloc \n", sizeof(struct ctl_table));
> > 
> >  return new;
> >   }
> > @@ -1199,6 +1201,9 @@ static struct ctl_table_header *new_links(struct 
> > ctl_dir *dir, struct ctl_table_
> >  link_name += len;
> >  link++;
> >  }
> > +   // Counts additional sentinel used for each new registration
> > +   //if ((head->ctl_table + head->ctl_table_size

[PATCH v3 5/7] riscv: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from riscv_v_default_vstate_table. This removal
is safe because register_sysctl implicitly uses ARRAY_SIZE() in addition
to checking for the sentinel.

Signed-off-by: Joel Granados 
---
 arch/riscv/kernel/vector.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c
index 8d92fb6c522c..578b6292487e 100644
--- a/arch/riscv/kernel/vector.c
+++ b/arch/riscv/kernel/vector.c
@@ -255,7 +255,6 @@ static struct ctl_table riscv_v_default_vstate_table[] = {
.mode   = 0644,
.proc_handler   = proc_dobool,
},
-   { }
 };
 
 static int __init riscv_v_sysctl_init(void)

-- 
2.30.2



[PATCH v3 2/7] arm: Remove now superfluous sentinel elem from ctl_table arrays

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Removed the sentinel as well as the explicit size from ctl_isa_vars. The
size is redundant as the initialization sets it. Changed
insn_emulation->sysctl from a 2 element array of struct ctl_table to a
simple struct. This has no consequence for the sysctl registration as it
is forwarded as a pointer. Removed sentinel from sve_defatul_vl_table,
sme_default_vl_table, tagged_addr_sysctl_table and
armv8_pmu_sysctl_table.

This removal is safe because register_sysctl_sz and register_sysctl use
the array size in addition to checking for the sentinel.

Signed-off-by: Joel Granados 
---
 arch/arm/kernel/isa.c| 4 ++--
 arch/arm64/kernel/armv8_deprecated.c | 8 +++-
 arch/arm64/kernel/fpsimd.c   | 2 --
 arch/arm64/kernel/process.c  | 1 -
 drivers/perf/arm_pmuv3.c | 1 -
 5 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/arch/arm/kernel/isa.c b/arch/arm/kernel/isa.c
index 20218876bef2..905b1b191546 100644
--- a/arch/arm/kernel/isa.c
+++ b/arch/arm/kernel/isa.c
@@ -16,7 +16,7 @@
 
 static unsigned int isa_membase, isa_portbase, isa_portshift;
 
-static struct ctl_table ctl_isa_vars[4] = {
+static struct ctl_table ctl_isa_vars[] = {
{
.procname   = "membase",
.data   = _membase, 
@@ -35,7 +35,7 @@ static struct ctl_table ctl_isa_vars[4] = {
.maxlen = sizeof(isa_portshift),
.mode   = 0444,
.proc_handler   = proc_dointvec,
-   }, {}
+   },
 };
 
 static struct ctl_table_header *isa_sysctl_header;
diff --git a/arch/arm64/kernel/armv8_deprecated.c 
b/arch/arm64/kernel/armv8_deprecated.c
index e459cfd33711..dd6ce86d4332 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -52,10 +52,8 @@ struct insn_emulation {
int min;
int max;
 
-   /*
-* sysctl for this emulation + a sentinal entry.
-*/
-   struct ctl_table sysctl[2];
+   /* sysctl for this emulation */
+   struct ctl_table sysctl;
 };
 
 #define ARM_OPCODE_CONDTEST_FAIL   0
@@ -558,7 +556,7 @@ static void __init register_insn_emulation(struct 
insn_emulation *insn)
update_insn_emulation_mode(insn, INSN_UNDEF);
 
if (insn->status != INSN_UNAVAILABLE) {
-   sysctl = >sysctl[0];
+   sysctl = >sysctl;
 
sysctl->mode = 0644;
sysctl->maxlen = sizeof(int);
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 91e44ac7150f..9afd0eb0cf88 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -589,7 +589,6 @@ static struct ctl_table sve_default_vl_table[] = {
.proc_handler   = vec_proc_do_default_vl,
.extra1 = _info[ARM64_VEC_SVE],
},
-   { }
 };
 
 static int __init sve_sysctl_init(void)
@@ -613,7 +612,6 @@ static struct ctl_table sme_default_vl_table[] = {
.proc_handler   = vec_proc_do_default_vl,
.extra1 = _info[ARM64_VEC_SME],
},
-   { }
 };
 
 static int __init sme_sysctl_init(void)
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 0fcc4eb1a7ab..610e13c3d41b 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -724,7 +724,6 @@ static struct ctl_table tagged_addr_sysctl_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   { }
 };
 
 static int __init tagged_addr_init(void)
diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
index 8fcaa26f0f8a..c0307b9181c3 100644
--- a/drivers/perf/arm_pmuv3.c
+++ b/drivers/perf/arm_pmuv3.c
@@ -1175,7 +1175,6 @@ static struct ctl_table armv8_pmu_sysctl_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   { }
 };
 
 static void armv8_pmu_register_sysctl_table(void)

-- 
2.30.2



[PATCH v3 7/7] c-sky: Remove now superfluous sentinel element from ctl_talbe array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from alignment_tbl ctl_table array. This removal is safe
because register_sysctl_init implicitly uses ARRAY_SIZE() in addition to
checking for the sentinel.

Acked-by: Guo Ren 
Signed-off-by: Joel Granados 
---
 arch/csky/abiv1/alignment.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/csky/abiv1/alignment.c b/arch/csky/abiv1/alignment.c
index b60259daed1b..e5b8b4b2109a 100644
--- a/arch/csky/abiv1/alignment.c
+++ b/arch/csky/abiv1/alignment.c
@@ -329,7 +329,6 @@ static struct ctl_table alignment_tbl[5] = {
.mode = 0666,
.proc_handler = _dointvec
},
-   {}
 };
 
 static int __init csky_alignment_init(void)

-- 
2.30.2



[PATCH v3 6/7] powerpc: Remove now superfluous sentinel element from ctl_table arrays

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from powersave_nap_ctl_table and nmi_wd_lpm_factor_ctl_table.
This removal is safe because register_sysctl implicitly uses ARRAY_SIZE()
in addition to checking for the sentinel.

Signed-off-by: Joel Granados 
---
 arch/powerpc/kernel/idle.c| 1 -
 arch/powerpc/platforms/pseries/mobility.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index b1c0418b25c8..30b56c67fa61 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -105,7 +105,6 @@ static struct ctl_table powersave_nap_ctl_table[] = {
.mode   = 0644,
.proc_handler   = proc_dointvec,
},
-   {}
 };
 
 static int __init
diff --git a/arch/powerpc/platforms/pseries/mobility.c 
b/arch/powerpc/platforms/pseries/mobility.c
index 0161226d8fec..1798f0f14d58 100644
--- a/arch/powerpc/platforms/pseries/mobility.c
+++ b/arch/powerpc/platforms/pseries/mobility.c
@@ -61,7 +61,6 @@ static struct ctl_table nmi_wd_lpm_factor_ctl_table[] = {
.mode   = 0644,
.proc_handler   = proc_douintvec_minmax,
},
-   {}
 };
 
 static int __init register_nmi_wd_lpm_factor_sysctl(void)

-- 
2.30.2



[PATCH v3 4/7] x86/vdso: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from abi_table2. This removal is safe because
register_sysctl implicitly uses ARRAY_SIZE() in addition to checking for
the sentinel.

Signed-off-by: Joel Granados 
---
 arch/x86/entry/vdso/vdso32-setup.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/entry/vdso/vdso32-setup.c 
b/arch/x86/entry/vdso/vdso32-setup.c
index f3b3cacbcbb0..76e4e74f35b5 100644
--- a/arch/x86/entry/vdso/vdso32-setup.c
+++ b/arch/x86/entry/vdso/vdso32-setup.c
@@ -67,7 +67,6 @@ static struct ctl_table abi_table2[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   {}
 };
 
 static __init int ia32_binfmt_init(void)

-- 
2.30.2



[PATCH v3 3/7] arch/x86: Remove now superfluous sentinel elem from ctl_table arrays

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from sld_sysctl and itmt_kern_table. This
removal is safe because register_sysctl_init and register_sysctl
implicitly use the array size in addition to checking for the sentinel.

Reviewed-by: Ingo Molnar 
Acked-by: Dave Hansen  # for x86
Signed-off-by: Joel Granados 
---
 arch/x86/kernel/cpu/intel.c | 1 -
 arch/x86/kernel/itmt.c  | 1 -
 2 files changed, 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index be4045628fd3..d9bb53f49a4d 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -1016,7 +1016,6 @@ static struct ctl_table sld_sysctls[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   {}
 };
 
 static int __init sld_mitigate_sysctl_init(void)
diff --git a/arch/x86/kernel/itmt.c b/arch/x86/kernel/itmt.c
index ee4fe8cdb857..9a7c03d47861 100644
--- a/arch/x86/kernel/itmt.c
+++ b/arch/x86/kernel/itmt.c
@@ -74,7 +74,6 @@ static struct ctl_table itmt_kern_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   {}
 };
 
 static struct ctl_table_header *itmt_sysctl_header;

-- 
2.30.2



[PATCH v3 1/7] S390: Remove now superfluous sentinel elem from ctl_table arrays

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which will
reduce the overall build time size of the kernel and run time memory
bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove the sentinel element from appldata_table, s390dbf_table,
topology_ctl_table, cmm_table and page_table_sysctl. Reduced the memory
allocation in appldata_register_ops by 1 effectively removing the
sentinel from ops->ctl_table.

This removal is safe because register_sysctl_sz and register_sysctl use
the array size in addition to checking for the sentinel.

Tested-by: Alexander Gordeev 
Acked-by: Heiko Carstens 
Signed-off-by: Joel Granados 
---
 arch/s390/appldata/appldata_base.c | 4 +---
 arch/s390/kernel/debug.c   | 1 -
 arch/s390/kernel/topology.c| 1 -
 arch/s390/mm/cmm.c | 1 -
 arch/s390/mm/pgalloc.c | 1 -
 5 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/s390/appldata/appldata_base.c 
b/arch/s390/appldata/appldata_base.c
index 3b0994625652..c2978cb03b36 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -63,7 +63,6 @@ static struct ctl_table appldata_table[] = {
.mode   = S_IRUGO | S_IWUSR,
.proc_handler   = appldata_interval_handler,
},
-   { },
 };
 
 /*
@@ -351,8 +350,7 @@ int appldata_register_ops(struct appldata_ops *ops)
if (ops->size > APPLDATA_MAX_REC_SIZE)
return -EINVAL;
 
-   /* The last entry must be an empty one */
-   ops->ctl_table = kcalloc(2, sizeof(struct ctl_table), GFP_KERNEL);
+   ops->ctl_table = kcalloc(1, sizeof(struct ctl_table), GFP_KERNEL);
if (!ops->ctl_table)
return -ENOMEM;
 
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index a85e0c3e7027..85328a0ef3b6 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -978,7 +978,6 @@ static struct ctl_table s390dbf_table[] = {
.mode   = S_IRUGO | S_IWUSR,
.proc_handler   = s390dbf_procactive,
},
-   { }
 };
 
 static struct ctl_table_header *s390dbf_sysctl_header;
diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 68adf1de..be8467b25953 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -636,7 +636,6 @@ static struct ctl_table topology_ctl_table[] = {
.mode   = 0644,
.proc_handler   = topology_ctl_handler,
},
-   { },
 };
 
 static int __init topology_init(void)
diff --git a/arch/s390/mm/cmm.c b/arch/s390/mm/cmm.c
index f47515313226..f8b13f247646 100644
--- a/arch/s390/mm/cmm.c
+++ b/arch/s390/mm/cmm.c
@@ -332,7 +332,6 @@ static struct ctl_table cmm_table[] = {
.mode   = 0644,
.proc_handler   = cmm_timeout_handler,
},
-   { }
 };
 
 #ifdef CONFIG_CMM_IUCV
diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c
index 07fc660a24aa..75e1039f2ec5 100644
--- a/arch/s390/mm/pgalloc.c
+++ b/arch/s390/mm/pgalloc.c
@@ -30,7 +30,6 @@ static struct ctl_table page_table_sysctl[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   { }
 };
 
 static int __init page_table_register_sysctl(void)

-- 
2.30.2



[PATCH v3 0/7] sysctl: Remove sentinel elements from arch

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

What?
These commits remove the sentinel element (last empty element) from the
sysctl arrays of all the files under the "arch/" directory that use a
sysctl array for registration. The merging of the preparation patches
(in https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
to mainline allows us to just remove sentinel elements without changing
behavior. This is now safe because the sysctl registration code
(register_sysctl() and friends) use the array size in addition to
checking for a sentinel ([1] for more info).

These commits are part of a bigger set (bigger patchset here
https://github.com/Joelgranados/linux/tree/tag/sysctl_remove_empty_elem_V4)
that remove the ctl_table sentinel. The idea is to make the review
process easier by chunking the 52 commits into manageable pieces. By
sending out one chunk at a time, they can be reviewed separately without
noise from parallel sets. After the "arch/" commits in this set are
reviewed, I will continue with drivers/*, fs/*, kernel/*, net/* and
miscellaneous. The final set will remove the unneeded check for
->procname == NULL.

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. I
have consolidated some links that shed light on the history of this
effort [2].

V2:
* Added clarification both in the commit messages and the coverletter as
  to why this patch is safe to apply.
* Added {Acked,Reviewed,Tested}-by from list
* Link to v1: 
https://lore.kernel.org/r/20230906-jag-sysctl_remove_empty_elem_arch-v1-0-3935d4854...@samsung.com

V3:
* Removed the ia64 patch to avoid conflicts with the ia64 removal
* Rebased onto v6.6-rc4
* Kept/added the trailing comma for the ctl_table arrays. This was a comment
  that we received "drivers/*" patch set.
* Link to v2: 
https://lore.kernel.org/r/20230913-jag-sysctl_remove_empty_elem_arch-v2-0-d1bd13a29...@samsung.com

Testing:
* Ran sysctl selftests (./tools/testing/selftests/sysctl/sysctl.sh)
* Ran this through 0-day with no errors or warnings

Size saving after removing all sentinels:
  A consequence of eventually removing all the sentinels (64 bytes per
  sentinel) is the bytes we save. These are *not* numbers that we will
  get after this patch set; these are the numbers that we will get after
  removing all the sentinels. I included them here because they are
  relevant and to get an idea of just how much memory we are talking
  about.
* bloat-o-meter:
- The "yesall" configuration results save 9158 bytes (bloat-o-meter 
output here
  
https://lore.kernel.org/all/20230621091000.424843-1-j.grana...@samsung.com/)
- The "tiny" config + CONFIG_SYSCTL save 1215 bytes (bloat-o-meter 
output here
  
https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/)
* memory usage:
we save some bytes in main memory as well. In my testing kernel
I measured a difference of 7296 bytes. I include the way to
measure in [3]

Size saving after this patchset:
  Here I give the values that I measured for the architecture that I'm
  running (x86_64). This can give an approximation of how many bytes are
  saved for each arch. I won't publish for all the archs because I don't
  have access to all of them.
* bloat-o-meter
- The "yesall" config saves 192 bytes (bloat-o-meter output [4])
- The "tiny" config saves 64 bytes (bloat-o-meter output [5])
* memory usage:
In this case there were no bytes saved. To measure it comment the
printk in `new_dir` and uncomment the if conditional in `new_links`
[3].

Comments/feedback greatly appreciated

Best
Joel

[1]
https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/

[2]
Links Related to the ctl_table sentinel removal:
* Good summary from Luis sent with the "pull request" for the
  preparation patches.
  https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/
* Another very good summary from Luis.
  https://lore.kernel.org/all/zmfizkfkvxuft...@bombadil.infradead.org/
* This is a patch set that replaces register_sysctl_table with register_sysctl
  https://lore.kernel.org/all/20230302204612.782387-1-mcg...@kernel.org/
* Patch set to deprecate register_sysctl_paths()
  https://lore.kernel.org/all/20230302202826.776286-1-mcg...@kernel.org/
* Here there is an explicit expectation for the removal of the sentinel element.
  https://lore.kernel.org/all/20230321130908.6972-1-frank...@vivo.com
* The "

[PATCH v2 10/15] vrf: Remove the now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from vrf_table

Signed-off-by: Joel Granados 
---
 drivers/net/vrf.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index a3408e4e1491..db766941b78f 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -1963,7 +1963,6 @@ static const struct ctl_table vrf_table[] = {
/* set by the vrf_netns_init */
.extra1 = NULL,
},
-   { },
 };
 
 static int vrf_netns_init_sysctl(struct net *net, struct netns_vrf *nn_vrf)

-- 
2.30.2



[PATCH v2 14/15] Drivers: hv: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from hv_ctl_table

Signed-off-by: Joel Granados 
---
 drivers/hv/hv_common.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index ccad7bca3fd3..4372f5d146ab 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -148,7 +148,6 @@ static struct ctl_table hv_ctl_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE
},
-   {}
 };
 
 static int hv_die_panic_notify_crash(struct notifier_block *self,

-- 
2.30.2



[PATCH v2 15/15] intel drm: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from oa_table

Signed-off-by: Joel Granados 
---
 drivers/gpu/drm/i915/i915_perf.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 04bc1f4a1115..23e769aa214c 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4896,7 +4896,6 @@ static struct ctl_table oa_table[] = {
 .extra1 = SYSCTL_ZERO,
 .extra2 = _sample_rate_hard_limit,
 },
-   {}
 };
 
 static u32 num_perf_groups_per_gt(struct intel_gt *gt)

-- 
2.30.2



[PATCH v2 11/15] sgi-xp: Remove the now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from xpc_sys_xpc_hb and xpc_sys_xpc

Signed-off-by: Joel Granados 
---
 drivers/misc/sgi-xp/xpc_main.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
index 6da509d692bb..3186421e82c3 100644
--- a/drivers/misc/sgi-xp/xpc_main.c
+++ b/drivers/misc/sgi-xp/xpc_main.c
@@ -110,7 +110,6 @@ static struct ctl_table xpc_sys_xpc_hb[] = {
 .proc_handler = proc_dointvec_minmax,
 .extra1 = _hb_check_min_interval,
 .extra2 = _hb_check_max_interval},
-   {}
 };
 static struct ctl_table xpc_sys_xpc[] = {
{
@@ -121,7 +120,6 @@ static struct ctl_table xpc_sys_xpc[] = {
 .proc_handler = proc_dointvec_minmax,
 .extra1 = _disengage_min_timelimit,
 .extra2 = _disengage_max_timelimit},
-   {}
 };
 
 static struct ctl_table_header *xpc_sysctl;

-- 
2.30.2



[PATCH v2 13/15] raid: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from raid_table

Signed-off-by: Joel Granados 
---
 drivers/md/md.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index a104a025084d..3bdff9e03188 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -305,7 +305,6 @@ static struct ctl_table raid_table[] = {
.mode   = S_IRUGO|S_IWUSR,
.proc_handler   = proc_dointvec,
},
-   { }
 };
 
 static int start_readonly;

-- 
2.30.2



[PATCH v2 12/15] fw loader: Remove the now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from firmware_config_table

Signed-off-by: Joel Granados 
---
 drivers/base/firmware_loader/fallback_table.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/base/firmware_loader/fallback_table.c 
b/drivers/base/firmware_loader/fallback_table.c
index e5ac098d0742..8432ab2c3b3c 100644
--- a/drivers/base/firmware_loader/fallback_table.c
+++ b/drivers/base/firmware_loader/fallback_table.c
@@ -44,7 +44,6 @@ static struct ctl_table firmware_config_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   { }
 };
 
 static struct ctl_table_header *firmware_config_sysct_table_header;

-- 
2.30.2



[PATCH v2 04/15] tty: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from tty_table

Signed-off-by: Joel Granados 
---
 drivers/tty/tty_io.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 8a94e5a43c6d..b3ae062912f5 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3608,7 +3608,6 @@ static struct ctl_table tty_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   { }
 };
 
 /*

-- 
2.30.2



[PATCH v2 05/15] scsi: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from scsi_table and sg_sysctls.

Signed-off-by: Joel Granados 
---
 drivers/scsi/scsi_sysctl.c | 1 -
 drivers/scsi/sg.c  | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/scsi/scsi_sysctl.c b/drivers/scsi/scsi_sysctl.c
index 7f0914ea168f..093774d77534 100644
--- a/drivers/scsi/scsi_sysctl.c
+++ b/drivers/scsi/scsi_sysctl.c
@@ -18,7 +18,6 @@ static struct ctl_table scsi_table[] = {
  .maxlen   = sizeof(scsi_logging_level),
  .mode = 0644,
  .proc_handler = proc_dointvec },
-   { }
 };
 
 static struct ctl_table_header *scsi_table_header;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 0d8afffd1683..86210e4dd0d3 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1650,7 +1650,6 @@ static struct ctl_table sg_sysctls[] = {
.mode   = 0444,
.proc_handler   = proc_dointvec,
},
-   {}
 };
 
 static struct ctl_table_header *hdr;

-- 
2.30.2



[PATCH v2 07/15] macintosh: Remove the now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from mac_hid_files

Signed-off-by: Joel Granados 
---
 drivers/macintosh/mac_hid.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index d8c4d5664145..1ae3539beff5 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -236,7 +236,6 @@ static struct ctl_table mac_hid_files[] = {
.mode   = 0644,
.proc_handler   = proc_dointvec,
},
-   { }
 };
 
 static struct ctl_table_header *mac_hid_sysctl_header;

-- 
2.30.2



[PATCH v2 06/15] parport: Remove the now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove the unneeded ctl_tables that were used to register intermediate
parport directories; only the path is needed at this point. From
parport_device_sysctl_table we removed: devices_root_dir, port_dir,
parport_dir and dev_dir. From parport_default_sysctl_table we removed:
default_dir, parport_dir and dev_dir. Reduce the size by one of the
ctl_table arrays that were not removed

Assign different sizes to the vars array in parport_sysctl_table
depending on CONFIG_PARPORT_1284; this is necessary now that the sysctl
register function uses ARRAY_SIZE to calculate the elements within.
Remove the sentinel element from parport_sysctl_template,
parport_device_sysctl_table and parport_default_sysctl_table.

Signed-off-by: Joel Granados 
---
 drivers/parport/procfs.c | 28 +++-
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
index 4e5b972c3e26..532d5cbbd344 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -259,8 +259,12 @@ PARPORT_MAX_SPINTIME_VALUE;
 struct parport_sysctl_table {
struct ctl_table_header *port_header;
struct ctl_table_header *devices_header;
-   struct ctl_table vars[12];
-   struct ctl_table device_dir[2];
+#ifdef CONFIG_PARPORT_1284
+   struct ctl_table vars[10];
+#else
+   struct ctl_table vars[5];
+#endif /* IEEE 1284 support */
+   struct ctl_table device_dir[1];
 };
 
 static const struct parport_sysctl_table parport_sysctl_template = {
@@ -341,7 +345,6 @@ static const struct parport_sysctl_table 
parport_sysctl_template = {
.proc_handler   = do_autoprobe
},
 #endif /* IEEE 1284 support */
-   {}
},
{
{
@@ -351,19 +354,14 @@ static const struct parport_sysctl_table 
parport_sysctl_template = {
.mode   = 0444,
.proc_handler   = do_active_device
},
-   {}
},
 };
 
 struct parport_device_sysctl_table
 {
struct ctl_table_header *sysctl_header;
-   struct ctl_table vars[2];
-   struct ctl_table device_dir[2];
-   struct ctl_table devices_root_dir[2];
-   struct ctl_table port_dir[2];
-   struct ctl_table parport_dir[2];
-   struct ctl_table dev_dir[2];
+   struct ctl_table vars[1];
+   struct ctl_table device_dir[1];
 };
 
 static const struct parport_device_sysctl_table
@@ -379,7 +377,6 @@ parport_device_sysctl_template = {
.extra1 = (void*) _min_timeslice_value,
.extra2 = (void*) _max_timeslice_value
},
-   {}
},
{
{
@@ -388,17 +385,13 @@ parport_device_sysctl_template = {
.maxlen = 0,
.mode   = 0555,
},
-   {}
}
 };
 
 struct parport_default_sysctl_table
 {
struct ctl_table_header *sysctl_header;
-   struct ctl_table vars[3];
-   struct ctl_table default_dir[2];
-   struct ctl_table parport_dir[2];
-   struct ctl_table dev_dir[2];
+   struct ctl_table vars[2];
 };
 
 static struct parport_default_sysctl_table
@@ -423,7 +416,6 @@ parport_default_sysctl_table = {
.extra1 = (void*) _min_spintime_value,
.extra2 = (void*) _max_spintime_value
},
-   {}
}
 };
 
@@ -443,7 +435,9 @@ int parport_proc_register(struct parport *port)
t->vars[0].data = >spintime;
for (i = 0; i < 5; i++) {
t->vars[i].extra1 = port;
+#ifdef CONFIG_PARPORT_1284
t->vars[5 + i].extra2 = >probe_info[i];
+#endif /* IEEE 1284 support */
}
 
port_name_len = strnlen(port->name, PARPORT_NAME_MAX_LEN);

-- 
2.30.2



[PATCH v2 02/15] hpet: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove the last empty element from hpet_table.

Signed-off-by: Joel Granados 
---
 drivers/char/hpet.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index ee71376f174b..f09c79081b01 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -728,7 +728,6 @@ static struct ctl_table hpet_table[] = {
 .mode = 0644,
 .proc_handler = proc_dointvec,
 },
-   {}
 };
 
 static struct ctl_table_header *sysctl_header;

-- 
2.30.2



[PATCH v2 08/15] infiniband: Remove the now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from iwcm_ctl_table and ucma_ctl_table

Signed-off-by: Joel Granados 
---
 drivers/infiniband/core/iwcm.c | 1 -
 drivers/infiniband/core/ucma.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 2b47073c61a6..0301fcad4b48 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -111,7 +111,6 @@ static struct ctl_table iwcm_ctl_table[] = {
.mode   = 0644,
.proc_handler   = proc_dointvec,
},
-   { }
 };
 
 /*
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index bf42650f125b..5f5ad8faf86e 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -71,7 +71,6 @@ static struct ctl_table ucma_ctl_table[] = {
.mode   = 0644,
.proc_handler   = proc_dointvec,
},
-   { }
 };
 
 struct ucma_file {

-- 
2.30.2



[PATCH v2 03/15] xen: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from balloon_table

Signed-off-by: Joel Granados 
---
 drivers/xen/balloon.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 586a1673459e..976c6cdf9ee6 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -94,7 +94,6 @@ static struct ctl_table balloon_table[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
},
-   { }
 };
 
 #else

-- 
2.30.2



[PATCH v2 00/15] sysctl: Remove sentinel elements from drivers

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

What?
These commits remove the sentinel element (last empty element) from the
sysctl arrays of all the files under the "drivers/" directory that use a
sysctl array for registration. The merging of the preparation patches
(in https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
to mainline allows us to just remove sentinel elements without changing
behavior (more info here [1]).

These commits are part of a bigger set (here
https://github.com/Joelgranados/linux/tree/tag/sysctl_remove_empty_elem_V4)
that remove the ctl_table sentinel. Make the review process easier by
chunking the commits into manageable pieces. Each chunk can be reviewed
separately without noise from parallel sets.

Now that the architecture chunk has been mostly reviewed [6], we send
the "drivers/" directory. Once this one is done, it will be follwed by
"fs/*", "kernel/*", "net/*" and miscellaneous. The final set will remove
the unneeded check for ->procname == NULL.

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. I
have consolidated some links that shed light on the history of this
effort [2].

Testing:
* Ran sysctl selftests (./tools/testing/selftests/sysctl/sysctl.sh)
* Ran this through 0-day with no errors or warnings

Size saving after removing all sentinels:
  These are the bytes that we save after removing all the sentinels
  (this plus all the other chunks). I included them to get an idea of
  how much memory we are talking about.
* bloat-o-meter:
- The "yesall" configuration results save 9158 bytes
  
https://lore.kernel.org/all/20230621091000.424843-1-j.grana...@samsung.com/
- The "tiny" config + CONFIG_SYSCTL save 1215 bytes
  
https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/
* memory usage:
In memory savings are measured to be 7296 bytes. (here is how to
measure [3])

Size saving after this patchset:
* bloat-o-meter
- The "yesall" config saves 2432 bytes [4]
- The "tiny" config saves 64 bytes [5]
* memory usage:
In this case there were no bytes saved because I do not have any
of the drivers in the patch. To measure it comment the printk in
`new_dir` and uncomment the if conditional in `new_links` [3].

---
Changes in v2:
- Left the dangling comma in the ctl_table arrays.
- Link to v1: 
https://lore.kernel.org/r/20230928-jag-sysctl_remove_empty_elem_drivers-v1-0-e59120fca...@samsung.com

Comments/feedback greatly appreciated

Best

Joel

[1]
We are able to remove a sentinel table without behavioral change by
introducing a table_size argument in the same place where procname is
checked for NULL. The idea is for it to keep stopping when it hits
->procname == NULL, while the sentinel is still present. And when the
sentinel is removed, it will stop on the table_size. You can go to 
(https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/)
for more information.

[2]
Links Related to the ctl_table sentinel removal:
* Good summary from Luis sent with the "pull request" for the
  preparation patches.
  https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/
* Another very good summary from Luis.
  https://lore.kernel.org/all/zmfizkfkvxuft...@bombadil.infradead.org/
* This is a patch set that replaces register_sysctl_table with register_sysctl
  https://lore.kernel.org/all/20230302204612.782387-1-mcg...@kernel.org/
* Patch set to deprecate register_sysctl_paths()
  https://lore.kernel.org/all/20230302202826.776286-1-mcg...@kernel.org/
* Here there is an explicit expectation for the removal of the sentinel element.
  https://lore.kernel.org/all/20230321130908.6972-1-frank...@vivo.com
* The "ARRAY_SIZE" approach was mentioned (proposed?) in this thread
  https://lore.kernel.org/all/20220220060626.15885-1-tangm...@uniontech.com

[3]
To measure the in memory savings apply this on top of this patchset.

"
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index c88854df0b62..e0073a627bac 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -976,6 +976,8 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
table[0].procname = new_name;
table[0].mode = S_IFDIR|S_IRUGO|S_IXUGO;
init_header(>header, set->dir.header.root, set, node, table, 1);
+   // Counts additional sentinel used for each new dir.
+   printk("%ld s

[PATCH v2 09/15] char-misc: Remove the now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from impi_table and random_table

Signed-off-by: Joel Granados 
---
 drivers/char/ipmi/ipmi_poweroff.c | 1 -
 drivers/char/random.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_poweroff.c 
b/drivers/char/ipmi/ipmi_poweroff.c
index 870659d91db2..941d2dcc8c9d 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -656,7 +656,6 @@ static struct ctl_table ipmi_table[] = {
  .maxlen   = sizeof(poweroff_powercycle),
  .mode = 0644,
  .proc_handler = proc_dointvec },
-   { }
 };
 
 static struct ctl_table_header *ipmi_table_header;
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 3cb37760dfec..4a9c79391dee 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1683,7 +1683,6 @@ static struct ctl_table random_table[] = {
.mode   = 0444,
.proc_handler   = proc_do_uuid,
},
-   { }
 };
 
 /*

-- 
2.30.2



[PATCH v2 01/15] cdrom: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from cdrom_table

Signed-off-by: Joel Granados 
---
 drivers/cdrom/cdrom.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index cc2839805983..a5e07270e0d4 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -3655,7 +3655,6 @@ static struct ctl_table cdrom_table[] = {
.mode   = 0644,
.proc_handler   = cdrom_sysctl_handler
},
-   { }
 };
 static struct ctl_table_header *cdrom_sysctl_header;
 

-- 
2.30.2



Re: [PATCH 00/15] sysctl: Remove sentinel elements from drivers

2023-10-02 Thread Joel Granados
On Thu, Sep 28, 2023 at 04:31:30PM +, Christophe Leroy wrote:
> 
> 
> Le 28/09/2023 à 15:21, Joel Granados via B4 Relay a écrit :
> > From: Joel Granados 
> 
> Automatic test fails on powerpc, see 
> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20230928-jag-sysctl_remove_empty_elem_drivers-v1-15-e59120fca...@samsung.com/
From this I got to this URL
https://github.com/linuxppc/linux-snowpatch/actions/runs/6339718136/job/17221399242
and saw this message "sysctl table check failed: dev/tty/ No proc_handler".
This means that we hit the check for entry->proc_handler in
sysctl_check_table.

> 
> Kernel attempted to read user page (1a111316) - exploit attempt? (uid: 0)
> BUG: Unable to handle kernel data access on read at 0x1a111316
> Faulting instruction address: 0xc0545338
> Oops: Kernel access of bad area, sig: 11 [#1]
> BE PAGE_SIZE=4K PowerPC 44x Platform
> Modules linked in:
> CPU: 0 PID: 1 Comm: swapper Not tainted 6.5.0-rc6-gdef13277bacb #1
> Hardware name: amcc,bamboo 440GR Rev. B 0x422218d3 PowerPC 44x Platform
> NIP:  c0545338 LR: c0548468 CTR: 
> REGS: c084fae0 TRAP: 0300   Not tainted  (6.5.0-rc6-gdef13277bacb)
> MSR:  00021000   CR: 84004288  XER: 
> DEAR: 1a111316 ESR: 
> GPR00: c0548468 c084fbd0 c0888000 c084fc99  c084fc7c 1a110316 
> 000a
> GPR08:  c084fd18 1a111316 04ff 22000282  c00027c0 
> 
> GPR16:   c004 c003d544 0001 c003eb2c 096023d4 
> 
> GPR24: c0636502 c0636502 c084fc74 c0588510 c084fc68 c084fc7c c084fc99 
> 0002
> NIP [c0545338] string+0x78/0x148
> LR [c0548468] vsnprintf+0x3d8/0x824
> Call Trace:
> [c084fbd0] [c084fc7c] 0xc084fc7c (unreliable)
> [c084fbe0] [c0548468] vsnprintf+0x3d8/0x824
> [c084fc30] [c0072dec] vprintk_store+0x17c/0x4c8
> [c084fcc0] [c007322c] vprintk_emit+0xf4/0x2a0
> [c084fd00] [c0073d04] _printk+0x60/0x88
> [c084fd40] [c01ab63c] sysctl_err+0x78/0xa4
> [c084fd80] [c01ab404] __register_sysctl_table+0x6a0/0x6c4
> [c084fde0] [c06a585c] __register_sysctl_init+0x30/0x78
> [c084fe00] [c06a8cc8] tty_init+0x44/0x168
> [c084fe30] [c00023c4] do_one_initcall+0x64/0x2a0
> [c084fea0] [c068f060] kernel_init_freeable+0x184/0x230
> [c084fee0] [c00027e4] kernel_init+0x24/0x124
> [c084ff00] [c000f1fc] ret_from_kernel_user_thread+0x14/0x1c
I followed this trace and proc_handler is correctly defined in tty_table
(struct ctl_table) in drivers/tty/tty_io.c:tty_init and there is not
path that changes these values.
Additionally, we then fail trying to print instead of continuing with
the initialization. My conjecture is that this might be due to something
different than tht sysctl register call.

Does this happen consistenly or is this just a one off issue?

To what branch are these patches being applied to?

I'm going to post my V2 and keep working on this issue if it pops up
again.

Thx for the report

Best

> --- interrupt: 0 at 0x0
> NIP:   LR:  CTR: 
> REGS: c084ff10 TRAP:    Not tainted  (6.5.0-rc6-gdef13277bacb)
> MSR:   <>  CR:   XER: 
> 
> GPR00:        
> 
> GPR08:        
> 
> GPR16:        
> 
> GPR24:        
> 
> NIP [] 0x0
> LR [] 0x0
> --- interrupt: 0
> Code: 91610008 90e1000c 4bffd0b5 80010014 38210010 7c0803a6 4e800020 
> 409d0008 9923 38630001 38840001 4240ffd0 <7d2a20ae> 7f851840 
> 5528063e 2c08
> ---[ end trace  ]---
> 
> note: swapper[1] exited with irqs disabled
> Kernel panic - not syncing: Attempted to kill init! exitcode=0x000b
> 
> 
> > 
> > What?
> > These commits remove the sentinel element (last empty element) from the
> > sysctl arrays of all the files under the "drivers/" directory that use a
> > sysctl array for registration. The merging of the preparation patches
> > (in https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > to mainline allows us to just remove sentinel elements without changing
> > behavior (more info here [1]).
<--- snip --->
> >   drivers/macintosh/mac_hid.c   |  3 +-
> >   drivers/md/md.c   |  3 +-
> >   drivers/misc/sgi-xp/xpc_main.c|  6 ++--
> >   drivers/net/vrf.c |  3 +-
> >   drivers/parport/procfs.c  | 42 
> > ---
> >   drivers/scsi/scsi_sysctl.c  

Re: [PATCH 01/15] cdrom: Remove now superfluous sentinel element from ctl_table array

2023-10-02 Thread Joel Granados
On Sat, Sep 30, 2023 at 05:52:17PM +0100, Phillip Potter wrote:
> On Fri, Sep 29, 2023 at 02:17:30PM +0200, Joel Granados wrote:
> > On Thu, Sep 28, 2023 at 03:36:55PM +0200, Greg Kroah-Hartman wrote:
> > > On Thu, Sep 28, 2023 at 03:21:26PM +0200, Joel Granados via B4 Relay 
> > > wrote:
> > > > From: Joel Granados 
> > > > 
> > > > This commit comes at the tail end of a greater effort to remove the
> > > > empty elements at the end of the ctl_table arrays (sentinels) which
> > > > will reduce the overall build time size of the kernel and run time
> > > > memory bloat by ~64 bytes per sentinel (further information Link :
> > > > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > > > 
> > > > Remove sentinel element from cdrom_table
> > > > 
> > > > Signed-off-by: Joel Granados 
> > > > ---
> > > >  drivers/cdrom/cdrom.c | 3 +--
> > > >  1 file changed, 1 insertion(+), 2 deletions(-)
> > > > 
> > > > diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
> > > > index cc2839805983..451907ade389 100644
> > > > --- a/drivers/cdrom/cdrom.c
> > > > +++ b/drivers/cdrom/cdrom.c
> > > > @@ -3654,8 +3654,7 @@ static struct ctl_table cdrom_table[] = {
> > > > .maxlen = sizeof(int),
> > > > .mode   = 0644,
> > > > .proc_handler   = cdrom_sysctl_handler
> > > > -   },
> > > > -   { }
> > > > +   }
> > > 
> > > You should have the final entry as "}," so as to make any future
> > > additions to the list to only contain that entry, that's long been the
> > > kernel style for lists like this.
> > Will send a V2 with this included. Thx.
> > 
> > > 
> > > So your patches will just remove one line, not 2 and add 1, making it a
> > > smaller diff.
> > indeed.
> > 
> > > 
> > > thanks,
> > > 
> > > greg k-h
> > 
> > -- 
> > 
> > Joel Granados
> 
> Hi Joel,
> 
> Thank you for your patch. I look forward to seeing V2, and will be happy
> to review it.
Am following a reported oops. Once I straighten that out, I'll send out
a V2

Bet

> 
> Regards,
> Phil

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH 14/15] hyper-v/azure: Remove now superfluous sentinel element from ctl_table array

2023-09-29 Thread Joel Granados
On Thu, Sep 28, 2023 at 03:26:16PM +, Wei Liu wrote:
> Please change the prefix to "Drivers: hv:" in the subject line in the
> two patches.
I'll change the commit message for the 14/15 patch from "hyper-v/azure"
to "Drivers: hv:". But I only see one patch that needs this. Which is
the other one?

best
> 
> On Thu, Sep 28, 2023 at 03:21:39PM +0200, Joel Granados via B4 Relay wrote:
> > From: Joel Granados 
> > 
> > This commit comes at the tail end of a greater effort to remove the
> > empty elements at the end of the ctl_table arrays (sentinels) which
> > will reduce the overall build time size of the kernel and run time
> > memory bloat by ~64 bytes per sentinel (further information Link :
> > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > 
> > Remove sentinel from hv_ctl_table
> > 
> > Signed-off-by: Joel Granados 
> > ---
> >  drivers/hv/hv_common.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> > index ccad7bca3fd3..bc7d678030aa 100644
> > --- a/drivers/hv/hv_common.c
> > +++ b/drivers/hv/hv_common.c
> > @@ -147,8 +147,7 @@ static struct ctl_table hv_ctl_table[] = {
> > .proc_handler   = proc_dointvec_minmax,
> > .extra1 = SYSCTL_ZERO,
> > .extra2 = SYSCTL_ONE
> > -   },
> > -   {}
> > +   }
> 
> Please keep the comma at the end.
> 
> >  };
> >  
> >  static int hv_die_panic_notify_crash(struct notifier_block *self,
> > 
> > -- 
> > 2.30.2
> > 

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH 01/15] cdrom: Remove now superfluous sentinel element from ctl_table array

2023-09-29 Thread Joel Granados
On Thu, Sep 28, 2023 at 03:36:55PM +0200, Greg Kroah-Hartman wrote:
> On Thu, Sep 28, 2023 at 03:21:26PM +0200, Joel Granados via B4 Relay wrote:
> > From: Joel Granados 
> > 
> > This commit comes at the tail end of a greater effort to remove the
> > empty elements at the end of the ctl_table arrays (sentinels) which
> > will reduce the overall build time size of the kernel and run time
> > memory bloat by ~64 bytes per sentinel (further information Link :
> > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > 
> > Remove sentinel element from cdrom_table
> > 
> > Signed-off-by: Joel Granados 
> > ---
> >  drivers/cdrom/cdrom.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
> > index cc2839805983..451907ade389 100644
> > --- a/drivers/cdrom/cdrom.c
> > +++ b/drivers/cdrom/cdrom.c
> > @@ -3654,8 +3654,7 @@ static struct ctl_table cdrom_table[] = {
> > .maxlen = sizeof(int),
> > .mode   = 0644,
> > .proc_handler   = cdrom_sysctl_handler
> > -   },
> > -   { }
> > +   }
> 
> You should have the final entry as "}," so as to make any future
> additions to the list to only contain that entry, that's long been the
> kernel style for lists like this.
Will send a V2 with this included. Thx.

> 
> So your patches will just remove one line, not 2 and add 1, making it a
> smaller diff.
indeed.

> 
> thanks,
> 
> greg k-h

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH 14/15] hyper-v/azure: Remove now superfluous sentinel element from ctl_table array

2023-09-29 Thread Joel Granados
On Thu, Sep 28, 2023 at 03:26:16PM +, Wei Liu wrote:
> Please change the prefix to "Drivers: hv:" in the subject line in the
> two patches.
> 
> On Thu, Sep 28, 2023 at 03:21:39PM +0200, Joel Granados via B4 Relay wrote:
> > From: Joel Granados 
> > 
> > This commit comes at the tail end of a greater effort to remove the
> > empty elements at the end of the ctl_table arrays (sentinels) which
> > will reduce the overall build time size of the kernel and run time
> > memory bloat by ~64 bytes per sentinel (further information Link :
> > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > 
> > Remove sentinel from hv_ctl_table
> > 
> > Signed-off-by: Joel Granados 
> > ---
> >  drivers/hv/hv_common.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> > index ccad7bca3fd3..bc7d678030aa 100644
> > --- a/drivers/hv/hv_common.c
> > +++ b/drivers/hv/hv_common.c
> > @@ -147,8 +147,7 @@ static struct ctl_table hv_ctl_table[] = {
> > .proc_handler   = proc_dointvec_minmax,
> > .extra1 = SYSCTL_ZERO,
> > .extra2 = SYSCTL_ONE
> > -   },
> > -   {}
> > +   }
> 
> Please keep the comma at the end.
My V2 will have this.

> 
> >  };
> >  
> >  static int hv_die_panic_notify_crash(struct notifier_block *self,
> > 
> > -- 
> > 2.30.2
> > 

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH 11/15] sgi-xp: Remove the now superfluous sentinel element from ctl_table array

2023-09-29 Thread Joel Granados
On Thu, Sep 28, 2023 at 12:51:15PM -0500, Steve Wahl wrote:
> On Thu, Sep 28, 2023 at 03:21:36PM +0200, Joel Granados via B4 Relay wrote:
> > From: Joel Granados 
> > 
> > This commit comes at the tail end of a greater effort to remove the
> > empty elements at the end of the ctl_table arrays (sentinels) which
> > will reduce the overall build time size of the kernel and run time
> > memory bloat by ~64 bytes per sentinel (further information Link :
> > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > 
> > Remove sentinel from xpc_sys_xpc_hb and xpc_sys_xpc
> > 
> > Signed-off-by: Joel Granados 
> > ---
> >  drivers/misc/sgi-xp/xpc_main.c | 6 ++
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
> > index 6da509d692bb..c898092ff3ac 100644
> > --- a/drivers/misc/sgi-xp/xpc_main.c
> > +++ b/drivers/misc/sgi-xp/xpc_main.c
> > @@ -109,8 +109,7 @@ static struct ctl_table xpc_sys_xpc_hb[] = {
> >  .mode = 0644,
> >  .proc_handler = proc_dointvec_minmax,
> >  .extra1 = _hb_check_min_interval,
> > -.extra2 = _hb_check_max_interval},
> > -   {}
> > +.extra2 = _hb_check_max_interval}
> >  };
> >  static struct ctl_table xpc_sys_xpc[] = {
> > {
> > @@ -120,8 +119,7 @@ static struct ctl_table xpc_sys_xpc[] = {
> >  .mode = 0644,
> >  .proc_handler = proc_dointvec_minmax,
> >  .extra1 = _disengage_min_timelimit,
> > -.extra2 = _disengage_max_timelimit},
> > -   {}
> > +.extra2 = _disengage_max_timelimit}
> >  };
> >  
> >  static struct ctl_table_header *xpc_sysctl;
> > 
> > -- 
> > 2.30.2
> > 
> 
> I assume you'll match the rest of the changes with regards to the
> trailing comma.
If you are refering to Greg's comments. yes. I'll send a V2 with the
trailing comma.

Best

> 
> Reviewed-by: Steve Wahl 
> 
> -- 
> Steve Wahl, Hewlett Packard Enterprise

-- 

Joel Granados


signature.asc
Description: PGP signature


[PATCH 06/15] parport: Remove the now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove the unneeded ctl_tables that were used to register intermediate
parport directories; only the path is needed at this point. From
parport_device_sysctl_table we removed: devices_root_dir, port_dir,
parport_dir and dev_dir. From parport_default_sysctl_table we removed:
default_dir, parport_dir and dev_dir. Reduce the size by one of the
ctl_table arrays that were not removed

Assign different sizes to the vars array in parport_sysctl_table
depending on CONFIG_PARPORT_1284; this is necessary now that the sysctl
register function uses ARRAY_SIZE to calculate the elements within.
Remove the sentinel element from parport_sysctl_template,
parport_device_sysctl_table and parport_default_sysctl_table.

Signed-off-by: Joel Granados 
---
 drivers/parport/procfs.c | 42 ++
 1 file changed, 18 insertions(+), 24 deletions(-)

diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
index 4e5b972c3e26..4118b3e52223 100644
--- a/drivers/parport/procfs.c
+++ b/drivers/parport/procfs.c
@@ -259,8 +259,12 @@ PARPORT_MAX_SPINTIME_VALUE;
 struct parport_sysctl_table {
struct ctl_table_header *port_header;
struct ctl_table_header *devices_header;
-   struct ctl_table vars[12];
-   struct ctl_table device_dir[2];
+#ifdef CONFIG_PARPORT_1284
+   struct ctl_table vars[10];
+#else
+   struct ctl_table vars[5];
+#endif /* IEEE 1284 support */
+   struct ctl_table device_dir[1];
 };
 
 static const struct parport_sysctl_table parport_sysctl_template = {
@@ -303,9 +307,9 @@ static const struct parport_sysctl_table 
parport_sysctl_template = {
.maxlen = 0,
.mode   = 0444,
.proc_handler   = do_hardware_modes
-   },
+   }
 #ifdef CONFIG_PARPORT_1284
-   {
+   , {
.procname   = "autoprobe",
.data   = NULL,
.maxlen = 0,
@@ -339,9 +343,8 @@ static const struct parport_sysctl_table 
parport_sysctl_template = {
.maxlen = 0,
.mode   = 0444,
.proc_handler   = do_autoprobe
-   },
+   }
 #endif /* IEEE 1284 support */
-   {}
},
{
{
@@ -350,20 +353,15 @@ static const struct parport_sysctl_table 
parport_sysctl_template = {
.maxlen = 0,
.mode   = 0444,
.proc_handler   = do_active_device
-   },
-   {}
+   }
},
 };
 
 struct parport_device_sysctl_table
 {
struct ctl_table_header *sysctl_header;
-   struct ctl_table vars[2];
-   struct ctl_table device_dir[2];
-   struct ctl_table devices_root_dir[2];
-   struct ctl_table port_dir[2];
-   struct ctl_table parport_dir[2];
-   struct ctl_table dev_dir[2];
+   struct ctl_table vars[1];
+   struct ctl_table device_dir[1];
 };
 
 static const struct parport_device_sysctl_table
@@ -378,8 +376,7 @@ parport_device_sysctl_template = {
.proc_handler   = proc_doulongvec_ms_jiffies_minmax,
.extra1 = (void*) _min_timeslice_value,
.extra2 = (void*) _max_timeslice_value
-   },
-   {}
+   }
},
{
{
@@ -387,18 +384,14 @@ parport_device_sysctl_template = {
.data   = NULL,
.maxlen = 0,
.mode   = 0555,
-   },
-   {}
+   }
}
 };
 
 struct parport_default_sysctl_table
 {
struct ctl_table_header *sysctl_header;
-   struct ctl_table vars[3];
-   struct ctl_table default_dir[2];
-   struct ctl_table parport_dir[2];
-   struct ctl_table dev_dir[2];
+   struct ctl_table vars[2];
 };
 
 static struct parport_default_sysctl_table
@@ -422,8 +415,7 @@ parport_default_sysctl_table = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = (void*) _min_spintime_value,
.extra2 = (void*) _max_spintime_value
-   },
-   {}
+   }
}
 };
 
@@ -443,7 +435,9 @@ int parport_proc_register(struct parport *port)
t->vars[0].data = >spintime;
for (i = 0; i < 5; i++) {
  

[PATCH 02/15] hpet: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove the last empty element from hpet_table.

Signed-off-by: Joel Granados 
---
 drivers/char/hpet.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index ee71376f174b..11f466fea5ed 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -727,8 +727,7 @@ static struct ctl_table hpet_table[] = {
 .maxlen = sizeof(int),
 .mode = 0644,
 .proc_handler = proc_dointvec,
-},
-   {}
+   }
 };
 
 static struct ctl_table_header *sysctl_header;

-- 
2.30.2



[PATCH 08/15] infiniband: Remove the now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from iwcm_ctl_table and ucma_ctl_table

Signed-off-by: Joel Granados 
---
 drivers/infiniband/core/iwcm.c | 3 +--
 drivers/infiniband/core/ucma.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 2b47073c61a6..fefb9ae75789 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -110,8 +110,7 @@ static struct ctl_table iwcm_ctl_table[] = {
.maxlen = sizeof(default_backlog),
.mode   = 0644,
.proc_handler   = proc_dointvec,
-   },
-   { }
+   }
 };
 
 /*
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index bf42650f125b..92ad24ddf12a 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -70,8 +70,7 @@ static struct ctl_table ucma_ctl_table[] = {
.maxlen = sizeof max_backlog,
.mode   = 0644,
.proc_handler   = proc_dointvec,
-   },
-   { }
+   }
 };
 
 struct ucma_file {

-- 
2.30.2



[PATCH 15/15] intel drm: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from oa_table

Signed-off-by: Joel Granados 
---
 drivers/gpu/drm/i915/i915_perf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 04bc1f4a1115..97ef6d2ad037 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4895,8 +4895,7 @@ static struct ctl_table oa_table[] = {
 .proc_handler = proc_dointvec_minmax,
 .extra1 = SYSCTL_ZERO,
 .extra2 = _sample_rate_hard_limit,
-},
-   {}
+   }
 };
 
 static u32 num_perf_groups_per_gt(struct intel_gt *gt)

-- 
2.30.2



[PATCH 12/15] fw loader: Remove the now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from firmware_config_table

Signed-off-by: Joel Granados 
---
 drivers/base/firmware_loader/fallback_table.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/base/firmware_loader/fallback_table.c 
b/drivers/base/firmware_loader/fallback_table.c
index e5ac098d0742..968aef19e118 100644
--- a/drivers/base/firmware_loader/fallback_table.c
+++ b/drivers/base/firmware_loader/fallback_table.c
@@ -43,8 +43,7 @@ static struct ctl_table firmware_config_table[] = {
.proc_handler   = proc_douintvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 static struct ctl_table_header *firmware_config_sysct_table_header;

-- 
2.30.2



[PATCH 10/15] vrf: Remove the now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from vrf_table

Signed-off-by: Joel Granados 
---
 drivers/net/vrf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
index a3408e4e1491..94eed8708467 100644
--- a/drivers/net/vrf.c
+++ b/drivers/net/vrf.c
@@ -1962,8 +1962,7 @@ static const struct ctl_table vrf_table[] = {
.proc_handler   = vrf_shared_table_handler,
/* set by the vrf_netns_init */
.extra1 = NULL,
-   },
-   { },
+   }
 };
 
 static int vrf_netns_init_sysctl(struct net *net, struct netns_vrf *nn_vrf)

-- 
2.30.2



[PATCH 13/15] raid: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from raid_table

Signed-off-by: Joel Granados 
---
 drivers/md/md.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index a104a025084d..3866d8f754a0 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -304,8 +304,7 @@ static struct ctl_table raid_table[] = {
.maxlen = sizeof(int),
.mode   = S_IRUGO|S_IWUSR,
.proc_handler   = proc_dointvec,
-   },
-   { }
+   }
 };
 
 static int start_readonly;

-- 
2.30.2



[PATCH 11/15] sgi-xp: Remove the now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from xpc_sys_xpc_hb and xpc_sys_xpc

Signed-off-by: Joel Granados 
---
 drivers/misc/sgi-xp/xpc_main.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
index 6da509d692bb..c898092ff3ac 100644
--- a/drivers/misc/sgi-xp/xpc_main.c
+++ b/drivers/misc/sgi-xp/xpc_main.c
@@ -109,8 +109,7 @@ static struct ctl_table xpc_sys_xpc_hb[] = {
 .mode = 0644,
 .proc_handler = proc_dointvec_minmax,
 .extra1 = _hb_check_min_interval,
-.extra2 = _hb_check_max_interval},
-   {}
+.extra2 = _hb_check_max_interval}
 };
 static struct ctl_table xpc_sys_xpc[] = {
{
@@ -120,8 +119,7 @@ static struct ctl_table xpc_sys_xpc[] = {
 .mode = 0644,
 .proc_handler = proc_dointvec_minmax,
 .extra1 = _disengage_min_timelimit,
-.extra2 = _disengage_max_timelimit},
-   {}
+.extra2 = _disengage_max_timelimit}
 };
 
 static struct ctl_table_header *xpc_sysctl;

-- 
2.30.2



[PATCH 14/15] hyper-v/azure: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from hv_ctl_table

Signed-off-by: Joel Granados 
---
 drivers/hv/hv_common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index ccad7bca3fd3..bc7d678030aa 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -147,8 +147,7 @@ static struct ctl_table hv_ctl_table[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE
-   },
-   {}
+   }
 };
 
 static int hv_die_panic_notify_crash(struct notifier_block *self,

-- 
2.30.2



[PATCH 05/15] scsi: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from scsi_table and sg_sysctls.

Signed-off-by: Joel Granados 
---
 drivers/scsi/scsi_sysctl.c | 3 +--
 drivers/scsi/sg.c  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_sysctl.c b/drivers/scsi/scsi_sysctl.c
index 7f0914ea168f..c74da88b20d3 100644
--- a/drivers/scsi/scsi_sysctl.c
+++ b/drivers/scsi/scsi_sysctl.c
@@ -17,8 +17,7 @@ static struct ctl_table scsi_table[] = {
  .data = _logging_level,
  .maxlen   = sizeof(scsi_logging_level),
  .mode = 0644,
- .proc_handler = proc_dointvec },
-   { }
+ .proc_handler = proc_dointvec }
 };
 
 static struct ctl_table_header *scsi_table_header;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 0d8afffd1683..22a59c5e22eb 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1649,8 +1649,7 @@ static struct ctl_table sg_sysctls[] = {
.maxlen = sizeof(int),
.mode   = 0444,
.proc_handler   = proc_dointvec,
-   },
-   {}
+   }
 };
 
 static struct ctl_table_header *hdr;

-- 
2.30.2



[PATCH 04/15] tty: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from tty_table

Signed-off-by: Joel Granados 
---
 drivers/tty/tty_io.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 8a94e5a43c6d..2f925dc54a20 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -3607,8 +3607,7 @@ static struct ctl_table tty_table[] = {
.proc_handler   = proc_dointvec,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 /*

-- 
2.30.2



[PATCH 09/15] char-misc: Remove the now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from impi_table and random_table

Signed-off-by: Joel Granados 
---
 drivers/char/ipmi/ipmi_poweroff.c | 3 +--
 drivers/char/random.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_poweroff.c 
b/drivers/char/ipmi/ipmi_poweroff.c
index 870659d91db2..b65ab51bf9fa 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -655,8 +655,7 @@ static struct ctl_table ipmi_table[] = {
  .data = _powercycle,
  .maxlen   = sizeof(poweroff_powercycle),
  .mode = 0644,
- .proc_handler = proc_dointvec },
-   { }
+ .proc_handler = proc_dointvec }
 };
 
 static struct ctl_table_header *ipmi_table_header;
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 3cb37760dfec..4040715cba19 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1682,8 +1682,7 @@ static struct ctl_table random_table[] = {
.procname   = "uuid",
.mode   = 0444,
.proc_handler   = proc_do_uuid,
-   },
-   { }
+   }
 };
 
 /*

-- 
2.30.2



[PATCH 07/15] macintosh: Remove the now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from mac_hid_files

Signed-off-by: Joel Granados 
---
 drivers/macintosh/mac_hid.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index d8c4d5664145..5a228c7d9aeb 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -235,8 +235,7 @@ static struct ctl_table mac_hid_files[] = {
.maxlen = sizeof(int),
.mode   = 0644,
.proc_handler   = proc_dointvec,
-   },
-   { }
+   }
 };
 
 static struct ctl_table_header *mac_hid_sysctl_header;

-- 
2.30.2



[PATCH 03/15] xen: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from balloon_table

Signed-off-by: Joel Granados 
---
 drivers/xen/balloon.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 586a1673459e..091eb2931ac4 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -93,8 +93,7 @@ static struct ctl_table balloon_table[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 #else

-- 
2.30.2



[PATCH 00/15] sysctl: Remove sentinel elements from drivers

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

What?
These commits remove the sentinel element (last empty element) from the
sysctl arrays of all the files under the "drivers/" directory that use a
sysctl array for registration. The merging of the preparation patches
(in https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
to mainline allows us to just remove sentinel elements without changing
behavior (more info here [1]).

These commits are part of a bigger set (here
https://github.com/Joelgranados/linux/tree/tag/sysctl_remove_empty_elem_V4)
that remove the ctl_table sentinel. Make the review process easier by
chunking the commits into manageable pieces. Each chunk can be reviewed
separately without noise from parallel sets.

Now that the architecture chunk has been mostly reviewed [6], we send
the "drivers/" directory. Once this one is done, it will be follwed by
"fs/*", "kernel/*", "net/*" and miscellaneous. The final set will remove
the unneeded check for ->procname == NULL.

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. I
have consolidated some links that shed light on the history of this
effort [2].

Testing:
* Ran sysctl selftests (./tools/testing/selftests/sysctl/sysctl.sh)
* Ran this through 0-day with no errors or warnings

Size saving after removing all sentinels:
  These are the bytes that we save after removing all the sentinels
  (this plus all the other chunks). I included them to get an idea of
  how much memory we are talking about.
* bloat-o-meter:
- The "yesall" configuration results save 9158 bytes
  
https://lore.kernel.org/all/20230621091000.424843-1-j.grana...@samsung.com/
- The "tiny" config + CONFIG_SYSCTL save 1215 bytes
  
https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/
* memory usage:
In memory savings are measured to be 7296 bytes. (here is how to
measure [3])

Size saving after this patchset:
* bloat-o-meter
- The "yesall" config saves 2432 bytes [4]
- The "tiny" config saves 64 bytes [5]
* memory usage:
In this case there were no bytes saved because I do not have any
of the drivers in the patch. To measure it comment the printk in
`new_dir` and uncomment the if conditional in `new_links` [3].

Comments/feedback greatly appreciated

Best
Joel

[1]
We are able to remove a sentinel table without behavioral change by
introducing a table_size argument in the same place where procname is
checked for NULL. The idea is for it to keep stopping when it hits
->procname == NULL, while the sentinel is still present. And when the
sentinel is removed, it will stop on the table_size. You can go to 
(https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/)
for more information.

[2]
Links Related to the ctl_table sentinel removal:
* Good summary from Luis sent with the "pull request" for the
  preparation patches.
  https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/
* Another very good summary from Luis.
  https://lore.kernel.org/all/zmfizkfkvxuft...@bombadil.infradead.org/
* This is a patch set that replaces register_sysctl_table with register_sysctl
  https://lore.kernel.org/all/20230302204612.782387-1-mcg...@kernel.org/
* Patch set to deprecate register_sysctl_paths()
  https://lore.kernel.org/all/20230302202826.776286-1-mcg...@kernel.org/
* Here there is an explicit expectation for the removal of the sentinel element.
  https://lore.kernel.org/all/20230321130908.6972-1-frank...@vivo.com
* The "ARRAY_SIZE" approach was mentioned (proposed?) in this thread
  https://lore.kernel.org/all/20220220060626.15885-1-tangm...@uniontech.com

[3]
To measure the in memory savings apply this on top of this patchset.

"
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index c88854df0b62..e0073a627bac 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -976,6 +976,8 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
table[0].procname = new_name;
table[0].mode = S_IFDIR|S_IRUGO|S_IXUGO;
init_header(>header, set->dir.header.root, set, node, table, 1);
+   // Counts additional sentinel used for each new dir.
+   printk("%ld sysctl saved mem kzalloc \n", sizeof(struct ctl_table));

return new;
 }
@@ -1199,6 +1201,9 @@ static struct ctl_table_header *new_links(struct ctl_dir 
*dir, struct ctl_table_

[PATCH 01/15] cdrom: Remove now superfluous sentinel element from ctl_table array

2023-09-28 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from cdrom_table

Signed-off-by: Joel Granados 
---
 drivers/cdrom/cdrom.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index cc2839805983..451907ade389 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -3654,8 +3654,7 @@ static struct ctl_table cdrom_table[] = {
.maxlen = sizeof(int),
.mode   = 0644,
.proc_handler   = cdrom_sysctl_handler
-   },
-   { }
+   }
 };
 static struct ctl_table_header *cdrom_sysctl_header;
 

-- 
2.30.2



[PATCH v2 3/8] arch/x86: Remove now superfluous sentinel elem from ctl_table arrays

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from sld_sysctl and itmt_kern_table. This
removal is safe because register_sysctl_init and register_sysctl
implicitly use the array size in addition to checking for the sentinel.

Reviewed-by: Ingo Molnar 
Acked-by: Dave Hansen  # for x86
Signed-off-by: Joel Granados 
---
 arch/x86/kernel/cpu/intel.c | 3 +--
 arch/x86/kernel/itmt.c  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index be4045628fd3..e63391b82624 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -1015,8 +1015,7 @@ static struct ctl_table sld_sysctls[] = {
.proc_handler   = proc_douintvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   {}
+   }
 };
 
 static int __init sld_mitigate_sysctl_init(void)
diff --git a/arch/x86/kernel/itmt.c b/arch/x86/kernel/itmt.c
index ee4fe8cdb857..5f2ccff38297 100644
--- a/arch/x86/kernel/itmt.c
+++ b/arch/x86/kernel/itmt.c
@@ -73,8 +73,7 @@ static struct ctl_table itmt_kern_table[] = {
.proc_handler   = sched_itmt_update_handler,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   {}
+   }
 };
 
 static struct ctl_table_header *itmt_sysctl_header;

-- 
2.30.2



[PATCH v2 2/8] arm: Remove now superfluous sentinel elem from ctl_table arrays

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Removed the sentinel as well as the explicit size from ctl_isa_vars. The
size is redundant as the initialization sets it. Changed
insn_emulation->sysctl from a 2 element array of struct ctl_table to a
simple struct. This has no consequence for the sysctl registration as it
is forwarded as a pointer. Removed sentinel from sve_defatul_vl_table,
sme_default_vl_table, tagged_addr_sysctl_table and
armv8_pmu_sysctl_table.

This removal is safe because register_sysctl_sz and register_sysctl use
the array size in addition to checking for the sentinel.

Signed-off-by: Joel Granados 
---
 arch/arm/kernel/isa.c| 4 ++--
 arch/arm64/kernel/armv8_deprecated.c | 8 +++-
 arch/arm64/kernel/fpsimd.c   | 6 ++
 arch/arm64/kernel/process.c  | 3 +--
 drivers/perf/arm_pmuv3.c | 3 +--
 5 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/arch/arm/kernel/isa.c b/arch/arm/kernel/isa.c
index 20218876bef2..0b9c28077092 100644
--- a/arch/arm/kernel/isa.c
+++ b/arch/arm/kernel/isa.c
@@ -16,7 +16,7 @@
 
 static unsigned int isa_membase, isa_portbase, isa_portshift;
 
-static struct ctl_table ctl_isa_vars[4] = {
+static struct ctl_table ctl_isa_vars[] = {
{
.procname   = "membase",
.data   = _membase, 
@@ -35,7 +35,7 @@ static struct ctl_table ctl_isa_vars[4] = {
.maxlen = sizeof(isa_portshift),
.mode   = 0444,
.proc_handler   = proc_dointvec,
-   }, {}
+   }
 };
 
 static struct ctl_table_header *isa_sysctl_header;
diff --git a/arch/arm64/kernel/armv8_deprecated.c 
b/arch/arm64/kernel/armv8_deprecated.c
index e459cfd33711..dd6ce86d4332 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -52,10 +52,8 @@ struct insn_emulation {
int min;
int max;
 
-   /*
-* sysctl for this emulation + a sentinal entry.
-*/
-   struct ctl_table sysctl[2];
+   /* sysctl for this emulation */
+   struct ctl_table sysctl;
 };
 
 #define ARM_OPCODE_CONDTEST_FAIL   0
@@ -558,7 +556,7 @@ static void __init register_insn_emulation(struct 
insn_emulation *insn)
update_insn_emulation_mode(insn, INSN_UNDEF);
 
if (insn->status != INSN_UNAVAILABLE) {
-   sysctl = >sysctl[0];
+   sysctl = >sysctl;
 
sysctl->mode = 0644;
sysctl->maxlen = sizeof(int);
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 91e44ac7150f..db3ad1ba8272 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -588,8 +588,7 @@ static struct ctl_table sve_default_vl_table[] = {
.mode   = 0644,
.proc_handler   = vec_proc_do_default_vl,
.extra1 = _info[ARM64_VEC_SVE],
-   },
-   { }
+   }
 };
 
 static int __init sve_sysctl_init(void)
@@ -612,8 +611,7 @@ static struct ctl_table sme_default_vl_table[] = {
.mode   = 0644,
.proc_handler   = vec_proc_do_default_vl,
.extra1 = _info[ARM64_VEC_SME],
-   },
-   { }
+   }
 };
 
 static int __init sme_sysctl_init(void)
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 0fcc4eb1a7ab..48861cdc3aae 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -723,8 +723,7 @@ static struct ctl_table tagged_addr_sysctl_table[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 static int __init tagged_addr_init(void)
diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
index e5a2ac4155f6..c4aa6a8d1b05 100644
--- a/drivers/perf/arm_pmuv3.c
+++ b/drivers/perf/arm_pmuv3.c
@@ -1172,8 +1172,7 @@ static struct ctl_table armv8_pmu_sysctl_table[] = {
.proc_handler   = armv8pmu_proc_user_access_handler,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 static void armv8_pmu_register_sysctl_table(void)

-- 
2.30.2



[PATCH v2 8/8] c-sky: Remove now superfluous sentinel element from ctl_talbe array

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from alignment_tbl ctl_table array. This removal is safe
because register_sysctl_init implicitly uses ARRAY_SIZE() in addition to
checking for the sentinel.

Acked-by: Guo Ren 
Signed-off-by: Joel Granados 
---
 arch/csky/abiv1/alignment.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/csky/abiv1/alignment.c b/arch/csky/abiv1/alignment.c
index b60259daed1b..0d75ce7b0328 100644
--- a/arch/csky/abiv1/alignment.c
+++ b/arch/csky/abiv1/alignment.c
@@ -328,8 +328,7 @@ static struct ctl_table alignment_tbl[5] = {
.maxlen = sizeof(align_usr_count),
.mode = 0666,
.proc_handler = _dointvec
-   },
-   {}
+   }
 };
 
 static int __init csky_alignment_init(void)

-- 
2.30.2



[PATCH v2 4/8] x86/vdso: Remove now superfluous sentinel element from ctl_table array

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from abi_table2. This removal is safe because
register_sysctl implicitly uses ARRAY_SIZE() in addition to checking for
the sentinel.

Signed-off-by: Joel Granados 
---
 arch/x86/entry/vdso/vdso32-setup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/entry/vdso/vdso32-setup.c 
b/arch/x86/entry/vdso/vdso32-setup.c
index f3b3cacbcbb0..37b761802181 100644
--- a/arch/x86/entry/vdso/vdso32-setup.c
+++ b/arch/x86/entry/vdso/vdso32-setup.c
@@ -66,8 +66,7 @@ static struct ctl_table abi_table2[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   {}
+   }
 };
 
 static __init int ia32_binfmt_init(void)

-- 
2.30.2



[PATCH v2 7/8] ia64: Remove now superfluous sentinel element from ctl_table array

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from kdump_ctl_table. This removal is safe because
register_sysctl implicitly uses ARRAY_SIZE() in addition to checking for
the sentinel.

Signed-off-by: Joel Granados 
---
 arch/ia64/kernel/crash.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/ia64/kernel/crash.c b/arch/ia64/kernel/crash.c
index 88b3ce3e66cd..fbf8893a570c 100644
--- a/arch/ia64/kernel/crash.c
+++ b/arch/ia64/kernel/crash.c
@@ -231,8 +231,7 @@ static struct ctl_table kdump_ctl_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec,
-   },
-   { }
+   }
 };
 #endif
 

-- 
2.30.2



[PATCH v2 6/8] powerpc: Remove now superfluous sentinel element from ctl_table arrays

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from powersave_nap_ctl_table and nmi_wd_lpm_factor_ctl_table.
This removal is safe because register_sysctl implicitly uses ARRAY_SIZE()
in addition to checking for the sentinel.

Signed-off-by: Joel Granados 
---
 arch/powerpc/kernel/idle.c| 3 +--
 arch/powerpc/platforms/pseries/mobility.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index b1c0418b25c8..a8591f5fa70e 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -104,8 +104,7 @@ static struct ctl_table powersave_nap_ctl_table[] = {
.maxlen = sizeof(int),
.mode   = 0644,
.proc_handler   = proc_dointvec,
-   },
-   {}
+   }
 };
 
 static int __init
diff --git a/arch/powerpc/platforms/pseries/mobility.c 
b/arch/powerpc/platforms/pseries/mobility.c
index 0161226d8fec..d82b0c802fbb 100644
--- a/arch/powerpc/platforms/pseries/mobility.c
+++ b/arch/powerpc/platforms/pseries/mobility.c
@@ -60,8 +60,7 @@ static struct ctl_table nmi_wd_lpm_factor_ctl_table[] = {
.maxlen = sizeof(int),
.mode   = 0644,
.proc_handler   = proc_douintvec_minmax,
-   },
-   {}
+   }
 };
 
 static int __init register_nmi_wd_lpm_factor_sysctl(void)

-- 
2.30.2



[PATCH v2 5/8] riscv: Remove now superfluous sentinel element from ctl_table array

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from riscv_v_default_vstate_table. This removal
is safe because register_sysctl implicitly uses ARRAY_SIZE() in addition
to checking for the sentinel.

Signed-off-by: Joel Granados 
---
 arch/riscv/kernel/vector.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c
index 8d92fb6c522c..a1ae68b2ac0f 100644
--- a/arch/riscv/kernel/vector.c
+++ b/arch/riscv/kernel/vector.c
@@ -254,8 +254,7 @@ static struct ctl_table riscv_v_default_vstate_table[] = {
.maxlen = sizeof(riscv_v_implicit_uacc),
.mode   = 0644,
.proc_handler   = proc_dobool,
-   },
-   { }
+   }
 };
 
 static int __init riscv_v_sysctl_init(void)

-- 
2.30.2



[PATCH v2 0/8] sysctl: Remove sentinel elements from arch

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

What?
These commits remove the sentinel element (last empty element) from the
sysctl arrays of all the files under the "arch/" directory that use a
sysctl array for registration. The merging of the preparation patches
(in https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
to mainline allows us to just remove sentinel elements without changing
behavior. This is now safe because the sysctl registration code
(register_sysctl() and friends) use the array size in addition to
checking for a sentinel ([1] for more info).

These commits are part of a bigger set (bigger patchset here
https://github.com/Joelgranados/linux/tree/tag/sysctl_remove_empty_elem_V4)
that remove the ctl_table sentinel. The idea is to make the review
process easier by chunking the 52 commits into manageable pieces. By
sending out one chunk at a time, they can be reviewed separately without
noise from parallel sets. After the "arch/" commits in this set are
reviewed, I will continue with drivers/*, fs/*, kernel/*, net/* and
miscellaneous. The final set will remove the unneeded check for
->procname == NULL.

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. I
have consolidated some links that shed light on the history of this
effort [2].

V2:
* Added clarification both in the commit messages and the coverletter as
  to why this patch is safe to apply.
* Added {Acked,Reviewed,Tested}-by from list
* Link to v1: 
https://lore.kernel.org/r/20230906-jag-sysctl_remove_empty_elem_arch-v1-0-3935d4854...@samsung.com

Testing:
* Ran sysctl selftests (./tools/testing/selftests/sysctl/sysctl.sh)
* Ran this through 0-day with no errors or warnings

Size saving after removing all sentinels:
  A consequence of eventually removing all the sentinels (64 bytes per
  sentinel) is the bytes we save. These are *not* numbers that we will
  get after this patch set; these are the numbers that we will get after
  removing all the sentinels. I included them here because they are
  relevant and to get an idea of just how much memory we are talking
  about.
* bloat-o-meter:
- The "yesall" configuration results save 9158 bytes (bloat-o-meter 
output here
  
https://lore.kernel.org/all/20230621091000.424843-1-j.grana...@samsung.com/)
- The "tiny" config + CONFIG_SYSCTL save 1215 bytes (bloat-o-meter 
output here
  
https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/)
* memory usage:
we save some bytes in main memory as well. In my testing kernel
I measured a difference of 7296 bytes. I include the way to
measure in [3]

Size saving after this patchset:
  Here I give the values that I measured for the architecture that I'm
  running (x86_64). This can give an approximation of how many bytes are
  saved for each arch. I won't publish for all the archs because I don't
  have access to all of them.
* bloat-o-meter
- The "yesall" config saves 192 bytes (bloat-o-meter output [4])
- The "tiny" config saves 64 bytes (bloat-o-meter output [5])
* memory usage:
In this case there were no bytes saved. To measure it comment the
printk in `new_dir` and uncomment the if conditional in `new_links`
[3].

Comments/feedback greatly appreciated

Best
Joel

[1]
https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/

[2]
Links Related to the ctl_table sentinel removal:
* Good summary from Luis sent with the "pull request" for the
  preparation patches.
  https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/
* Another very good summary from Luis.
  https://lore.kernel.org/all/zmfizkfkvxuft...@bombadil.infradead.org/
* This is a patch set that replaces register_sysctl_table with register_sysctl
  https://lore.kernel.org/all/20230302204612.782387-1-mcg...@kernel.org/
* Patch set to deprecate register_sysctl_paths()
  https://lore.kernel.org/all/20230302202826.776286-1-mcg...@kernel.org/
* Here there is an explicit expectation for the removal of the sentinel element.
  https://lore.kernel.org/all/20230321130908.6972-1-frank...@vivo.com
* The "ARRAY_SIZE" approach was mentioned (proposed?) in this thread
  https://lore.kernel.org/all/20220220060626.15885-1-tangm...@uniontech.com

[3]
To measure the in memory savings apply this on top of this patchset.

"
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index c88854df0b62..e0073a627bac 100644
--- a/fs/

[PATCH v2 1/8] S390: Remove now superfluous sentinel elem from ctl_table arrays

2023-09-13 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which will
reduce the overall build time size of the kernel and run time memory
bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove the sentinel element from appldata_table, s390dbf_table,
topology_ctl_table, cmm_table and page_table_sysctl. Reduced the memory
allocation in appldata_register_ops by 1 effectively removing the
sentinel from ops->ctl_table.

This removal is safe because register_sysctl_sz and register_sysctl use
the array size in addition to checking for the sentinel.

Tested-by: Alexander Gordeev 
Acked-by: Heiko Carstens 
Signed-off-by: Joel Granados 
---
 arch/s390/appldata/appldata_base.c | 6 ++
 arch/s390/kernel/debug.c   | 3 +--
 arch/s390/kernel/topology.c| 3 +--
 arch/s390/mm/cmm.c | 3 +--
 arch/s390/mm/pgalloc.c | 3 +--
 5 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/arch/s390/appldata/appldata_base.c 
b/arch/s390/appldata/appldata_base.c
index 3b0994625652..872a644b1fd1 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -62,8 +62,7 @@ static struct ctl_table appldata_table[] = {
.procname   = "interval",
.mode   = S_IRUGO | S_IWUSR,
.proc_handler   = appldata_interval_handler,
-   },
-   { },
+   }
 };
 
 /*
@@ -351,8 +350,7 @@ int appldata_register_ops(struct appldata_ops *ops)
if (ops->size > APPLDATA_MAX_REC_SIZE)
return -EINVAL;
 
-   /* The last entry must be an empty one */
-   ops->ctl_table = kcalloc(2, sizeof(struct ctl_table), GFP_KERNEL);
+   ops->ctl_table = kcalloc(1, sizeof(struct ctl_table), GFP_KERNEL);
if (!ops->ctl_table)
return -ENOMEM;
 
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index a85e0c3e7027..150e2bfff0b3 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -977,8 +977,7 @@ static struct ctl_table s390dbf_table[] = {
.maxlen = sizeof(int),
.mode   = S_IRUGO | S_IWUSR,
.proc_handler   = s390dbf_procactive,
-   },
-   { }
+   }
 };
 
 static struct ctl_table_header *s390dbf_sysctl_header;
diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 68adf1de..9dcfac416669 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -635,8 +635,7 @@ static struct ctl_table topology_ctl_table[] = {
.procname   = "topology",
.mode   = 0644,
.proc_handler   = topology_ctl_handler,
-   },
-   { },
+   }
 };
 
 static int __init topology_init(void)
diff --git a/arch/s390/mm/cmm.c b/arch/s390/mm/cmm.c
index f47515313226..8937aa7090b3 100644
--- a/arch/s390/mm/cmm.c
+++ b/arch/s390/mm/cmm.c
@@ -331,8 +331,7 @@ static struct ctl_table cmm_table[] = {
.procname   = "cmm_timeout",
.mode   = 0644,
.proc_handler   = cmm_timeout_handler,
-   },
-   { }
+   }
 };
 
 #ifdef CONFIG_CMM_IUCV
diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c
index 07fc660a24aa..e8cecd31715f 100644
--- a/arch/s390/mm/pgalloc.c
+++ b/arch/s390/mm/pgalloc.c
@@ -29,8 +29,7 @@ static struct ctl_table page_table_sysctl[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 static int __init page_table_register_sysctl(void)

-- 
2.30.2



Re: [PATCH 3/8] arch/x86: Remove sentinel elem from ctl_table arrays

2023-09-07 Thread Joel Granados
On Wed, Sep 06, 2023 at 11:58:47PM +0200, Ingo Molnar wrote:
> 
> * Dave Hansen  wrote:
> 
> > On 9/6/23 03:03, Joel Granados via B4 Relay wrote:
> > > This commit comes at the tail end of a greater effort to remove the
> > > empty elements at the end of the ctl_table arrays (sentinels) which
> > > will reduce the overall build time size of the kernel and run time
> > > memory bloat by ~64 bytes per sentinel (further information Link :
> > > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > > 
> > > Remove sentinel element from sld_sysctl and itmt_kern_table.
> > 
> > There's a *LOT* of content to read for a reviewer to figure out what's
> > going on here between all the links.  I would have appreciated one more
> > sentence here, maybe:
> > 
> > This is now safe because the sysctl registration code
> > (register_sysctl()) implicitly uses ARRAY_SIZE() in addition
> > to checking for a sentinel.
> > 
> > That needs to be more prominent _somewhere_.  Maybe here, or maybe in
> > the cover letter, but _somewhere_.
> > 
> > That said, feel free to add this to the two x86 patches:
> > 
> > Acked-by: Dave Hansen  # for x86
> 
> Absolutely needs to be in the title as well, something like:
> 
>arch/x86: Remove now superfluous sentinel elem from ctl_table arrays
Done. Will wait to see if other ppl have more comments to send out V2

Thx.
> 
> With that propagated into the whole series:
> 
>Reviewed-by: Ingo Molnar 
> 
> Thanks,
> 
>   Ingo

-- 

Joel Granados


signature.asc
Description: PGP signature


Re: [PATCH 3/8] arch/x86: Remove sentinel elem from ctl_table arrays

2023-09-07 Thread Joel Granados
On Wed, Sep 06, 2023 at 07:45:09AM -0700, Dave Hansen wrote:
> On 9/6/23 03:03, Joel Granados via B4 Relay wrote:
> > This commit comes at the tail end of a greater effort to remove the
> > empty elements at the end of the ctl_table arrays (sentinels) which
> > will reduce the overall build time size of the kernel and run time
> > memory bloat by ~64 bytes per sentinel (further information Link :
> > https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
> > 
> > Remove sentinel element from sld_sysctl and itmt_kern_table.
> 
> There's a *LOT* of content to read for a reviewer to figure out what's
> going on here between all the links.  I would have appreciated one more
> sentence here, maybe:
> 
>   This is now safe because the sysctl registration code
>   (register_sysctl()) implicitly uses ARRAY_SIZE() in addition
>   to checking for a sentinel.
Thx for the feedback. This is a great sentence to add at the end of the
first paragraph instead of the link. I'll add it with a few changes as
there are more than just one register function and the use of ARRAY_SIZE
is implicit most of the time.

  This is now safe because the sysctl registration code
  (register_sysctl() and friends) use the array size in addition to
  checking for a sentinel.

I have changed my cover letter in case I send a V2 and for the other
batches that are coming after the architecture one.

> 
> That needs to be more prominent _somewhere_.  Maybe here, or maybe in
> the cover letter, but _somewhere_.
This is also a good point. I think having it in both the cover letter
and each of the commits is an added value.

> 
> That said, feel free to add this to the two x86 patches:
> 
> Acked-by: Dave Hansen  # for x86

Best

-- 

Joel Granados


signature.asc
Description: PGP signature


[PATCH 1/8] S390: Remove sentinel elem from ctl_table arrays

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove the sentinel element from appldata_table, s390dbf_table,
topology_ctl_table, cmm_table and page_table_sysctl. Reduced the
memory allocation in appldata_register_ops by 1 effectively removing the
sentinel from ops->ctl_table.

Signed-off-by: Joel Granados 
---
 arch/s390/appldata/appldata_base.c | 6 ++
 arch/s390/kernel/debug.c   | 3 +--
 arch/s390/kernel/topology.c| 3 +--
 arch/s390/mm/cmm.c | 3 +--
 arch/s390/mm/pgalloc.c | 3 +--
 5 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/arch/s390/appldata/appldata_base.c 
b/arch/s390/appldata/appldata_base.c
index 3b0994625652..872a644b1fd1 100644
--- a/arch/s390/appldata/appldata_base.c
+++ b/arch/s390/appldata/appldata_base.c
@@ -62,8 +62,7 @@ static struct ctl_table appldata_table[] = {
.procname   = "interval",
.mode   = S_IRUGO | S_IWUSR,
.proc_handler   = appldata_interval_handler,
-   },
-   { },
+   }
 };
 
 /*
@@ -351,8 +350,7 @@ int appldata_register_ops(struct appldata_ops *ops)
if (ops->size > APPLDATA_MAX_REC_SIZE)
return -EINVAL;
 
-   /* The last entry must be an empty one */
-   ops->ctl_table = kcalloc(2, sizeof(struct ctl_table), GFP_KERNEL);
+   ops->ctl_table = kcalloc(1, sizeof(struct ctl_table), GFP_KERNEL);
if (!ops->ctl_table)
return -ENOMEM;
 
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index a85e0c3e7027..150e2bfff0b3 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -977,8 +977,7 @@ static struct ctl_table s390dbf_table[] = {
.maxlen = sizeof(int),
.mode   = S_IRUGO | S_IWUSR,
.proc_handler   = s390dbf_procactive,
-   },
-   { }
+   }
 };
 
 static struct ctl_table_header *s390dbf_sysctl_header;
diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 68adf1de..9dcfac416669 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -635,8 +635,7 @@ static struct ctl_table topology_ctl_table[] = {
.procname   = "topology",
.mode   = 0644,
.proc_handler   = topology_ctl_handler,
-   },
-   { },
+   }
 };
 
 static int __init topology_init(void)
diff --git a/arch/s390/mm/cmm.c b/arch/s390/mm/cmm.c
index f47515313226..8937aa7090b3 100644
--- a/arch/s390/mm/cmm.c
+++ b/arch/s390/mm/cmm.c
@@ -331,8 +331,7 @@ static struct ctl_table cmm_table[] = {
.procname   = "cmm_timeout",
.mode   = 0644,
.proc_handler   = cmm_timeout_handler,
-   },
-   { }
+   }
 };
 
 #ifdef CONFIG_CMM_IUCV
diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c
index 07fc660a24aa..e8cecd31715f 100644
--- a/arch/s390/mm/pgalloc.c
+++ b/arch/s390/mm/pgalloc.c
@@ -29,8 +29,7 @@ static struct ctl_table page_table_sysctl[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 static int __init page_table_register_sysctl(void)

-- 
2.30.2



[PATCH 2/8] arm: Remove sentinel elem from ctl_table arrays

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Removed the sentinel as well as the explicit size from ctl_isa_vars. The
size is redundant as the initialization sets it.
Changed insn_emulation->sysctl from a 2 element array of struct
ctl_table to a simple struct. This has no consequence for the sysctl
registration as it is forwarded as a pointer.
Removed sentinel from sve_defatul_vl_table, sme_default_vl_table,
tagged_addr_sysctl_table and armv8_pmu_sysctl_table.

Signed-off-by: Joel Granados 
---
 arch/arm/kernel/isa.c| 4 ++--
 arch/arm64/kernel/armv8_deprecated.c | 8 +++-
 arch/arm64/kernel/fpsimd.c   | 6 ++
 arch/arm64/kernel/process.c  | 3 +--
 drivers/perf/arm_pmuv3.c | 3 +--
 5 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/arch/arm/kernel/isa.c b/arch/arm/kernel/isa.c
index 20218876bef2..0b9c28077092 100644
--- a/arch/arm/kernel/isa.c
+++ b/arch/arm/kernel/isa.c
@@ -16,7 +16,7 @@
 
 static unsigned int isa_membase, isa_portbase, isa_portshift;
 
-static struct ctl_table ctl_isa_vars[4] = {
+static struct ctl_table ctl_isa_vars[] = {
{
.procname   = "membase",
.data   = _membase, 
@@ -35,7 +35,7 @@ static struct ctl_table ctl_isa_vars[4] = {
.maxlen = sizeof(isa_portshift),
.mode   = 0444,
.proc_handler   = proc_dointvec,
-   }, {}
+   }
 };
 
 static struct ctl_table_header *isa_sysctl_header;
diff --git a/arch/arm64/kernel/armv8_deprecated.c 
b/arch/arm64/kernel/armv8_deprecated.c
index e459cfd33711..dd6ce86d4332 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -52,10 +52,8 @@ struct insn_emulation {
int min;
int max;
 
-   /*
-* sysctl for this emulation + a sentinal entry.
-*/
-   struct ctl_table sysctl[2];
+   /* sysctl for this emulation */
+   struct ctl_table sysctl;
 };
 
 #define ARM_OPCODE_CONDTEST_FAIL   0
@@ -558,7 +556,7 @@ static void __init register_insn_emulation(struct 
insn_emulation *insn)
update_insn_emulation_mode(insn, INSN_UNDEF);
 
if (insn->status != INSN_UNAVAILABLE) {
-   sysctl = >sysctl[0];
+   sysctl = >sysctl;
 
sysctl->mode = 0644;
sysctl->maxlen = sizeof(int);
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 91e44ac7150f..db3ad1ba8272 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -588,8 +588,7 @@ static struct ctl_table sve_default_vl_table[] = {
.mode   = 0644,
.proc_handler   = vec_proc_do_default_vl,
.extra1 = _info[ARM64_VEC_SVE],
-   },
-   { }
+   }
 };
 
 static int __init sve_sysctl_init(void)
@@ -612,8 +611,7 @@ static struct ctl_table sme_default_vl_table[] = {
.mode   = 0644,
.proc_handler   = vec_proc_do_default_vl,
.extra1 = _info[ARM64_VEC_SME],
-   },
-   { }
+   }
 };
 
 static int __init sme_sysctl_init(void)
diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
index 0fcc4eb1a7ab..48861cdc3aae 100644
--- a/arch/arm64/kernel/process.c
+++ b/arch/arm64/kernel/process.c
@@ -723,8 +723,7 @@ static struct ctl_table tagged_addr_sysctl_table[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 static int __init tagged_addr_init(void)
diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c
index e5a2ac4155f6..c4aa6a8d1b05 100644
--- a/drivers/perf/arm_pmuv3.c
+++ b/drivers/perf/arm_pmuv3.c
@@ -1172,8 +1172,7 @@ static struct ctl_table armv8_pmu_sysctl_table[] = {
.proc_handler   = armv8pmu_proc_user_access_handler,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   { }
+   }
 };
 
 static void armv8_pmu_register_sysctl_table(void)

-- 
2.30.2



[PATCH 8/8] c-sky: rm sentinel element from ctl_talbe array

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from alignment_tbl ctl_table array.

Signed-off-by: Joel Granados 
---
 arch/csky/abiv1/alignment.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/csky/abiv1/alignment.c b/arch/csky/abiv1/alignment.c
index b60259daed1b..0d75ce7b0328 100644
--- a/arch/csky/abiv1/alignment.c
+++ b/arch/csky/abiv1/alignment.c
@@ -328,8 +328,7 @@ static struct ctl_table alignment_tbl[5] = {
.maxlen = sizeof(align_usr_count),
.mode = 0666,
.proc_handler = _dointvec
-   },
-   {}
+   }
 };
 
 static int __init csky_alignment_init(void)

-- 
2.30.2



[PATCH 6/8] powerpc: Remove sentinel element from ctl_table arrays

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from powersave_nap_ctl_table and
nmi_wd_lpm_factor_ctl_table.

Signed-off-by: Joel Granados 
---
 arch/powerpc/kernel/idle.c| 3 +--
 arch/powerpc/platforms/pseries/mobility.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index b1c0418b25c8..a8591f5fa70e 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -104,8 +104,7 @@ static struct ctl_table powersave_nap_ctl_table[] = {
.maxlen = sizeof(int),
.mode   = 0644,
.proc_handler   = proc_dointvec,
-   },
-   {}
+   }
 };
 
 static int __init
diff --git a/arch/powerpc/platforms/pseries/mobility.c 
b/arch/powerpc/platforms/pseries/mobility.c
index 0161226d8fec..d82b0c802fbb 100644
--- a/arch/powerpc/platforms/pseries/mobility.c
+++ b/arch/powerpc/platforms/pseries/mobility.c
@@ -60,8 +60,7 @@ static struct ctl_table nmi_wd_lpm_factor_ctl_table[] = {
.maxlen = sizeof(int),
.mode   = 0644,
.proc_handler   = proc_douintvec_minmax,
-   },
-   {}
+   }
 };
 
 static int __init register_nmi_wd_lpm_factor_sysctl(void)

-- 
2.30.2



[PATCH 3/8] arch/x86: Remove sentinel elem from ctl_table arrays

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from sld_sysctl and itmt_kern_table.

Signed-off-by: Joel Granados 
---
 arch/x86/kernel/cpu/intel.c | 3 +--
 arch/x86/kernel/itmt.c  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index be4045628fd3..e63391b82624 100644
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -1015,8 +1015,7 @@ static struct ctl_table sld_sysctls[] = {
.proc_handler   = proc_douintvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   {}
+   }
 };
 
 static int __init sld_mitigate_sysctl_init(void)
diff --git a/arch/x86/kernel/itmt.c b/arch/x86/kernel/itmt.c
index ee4fe8cdb857..5f2ccff38297 100644
--- a/arch/x86/kernel/itmt.c
+++ b/arch/x86/kernel/itmt.c
@@ -73,8 +73,7 @@ static struct ctl_table itmt_kern_table[] = {
.proc_handler   = sched_itmt_update_handler,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   {}
+   }
 };
 
 static struct ctl_table_header *itmt_sysctl_header;

-- 
2.30.2



[PATCH 5/8] riscv: Remove sentinel element from ctl_table array

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from riscv_v_default_vstate_table.

Signed-off-by: Joel Granados 
---
 arch/riscv/kernel/vector.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c
index 8d92fb6c522c..a1ae68b2ac0f 100644
--- a/arch/riscv/kernel/vector.c
+++ b/arch/riscv/kernel/vector.c
@@ -254,8 +254,7 @@ static struct ctl_table riscv_v_default_vstate_table[] = {
.maxlen = sizeof(riscv_v_implicit_uacc),
.mode   = 0644,
.proc_handler   = proc_dobool,
-   },
-   { }
+   }
 };
 
 static int __init riscv_v_sysctl_init(void)

-- 
2.30.2



[PATCH 7/8] ia64: Remove sentinel element from ctl_table array

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel from kdump_ctl_table.

Signed-off-by: Joel Granados 
---
 arch/ia64/kernel/crash.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/ia64/kernel/crash.c b/arch/ia64/kernel/crash.c
index 88b3ce3e66cd..fbf8893a570c 100644
--- a/arch/ia64/kernel/crash.c
+++ b/arch/ia64/kernel/crash.c
@@ -231,8 +231,7 @@ static struct ctl_table kdump_ctl_table[] = {
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec,
-   },
-   { }
+   }
 };
 #endif
 

-- 
2.30.2



[PATCH 0/8] sysctl: Remove sentinel elements from arch

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

What?
These commits remove the sentinel element (last empty element) from the
sysctl arrays of all the files under the "arch/" directory that use a
sysctl array for registration. The merging of the preparation patches
(in https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)
to mainline allows us to just remove sentinel elements without changing
behavior (more info on how this was done here [1]).

These commits are part of a bigger set (bigger patchset here
https://github.com/Joelgranados/linux/tree/tag/sysctl_remove_empty_elem_V4)
that remove the ctl_table sentinel. The idea is to make the review
process easier by chunking the 52 commits into manageable pieces. By
sending out one chunk at a time, they can be reviewed separately without
noise from parallel sets. After the "arch/" commits in this set are
reviewed, I will continue with drivers/*, fs/*, kernel/*, net/* and
miscellaneous. The final set will remove the unneeded check for
->procname == NULL.

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. I
have consolidated some links that shed light on the history of this
effort [2].

Testing:
* Ran sysctl selftests (./tools/testing/selftests/sysctl/sysctl.sh)
* Ran this through 0-day with no errors or warnings

Size saving after removing all sentinels:
  A consequence of eventually removing all the sentinels (64 bytes per
  sentinel) is the bytes we save. These are *not* numbers that we will
  get after this patch set; these are the numbers that we will get after
  removing all the sentinels. I included them here because they are
  relevant and to get an idea of just how much memory we are talking
  about.
* bloat-o-meter:
- The "yesall" configuration results save 9158 bytes (bloat-o-meter 
output here
  
https://lore.kernel.org/all/20230621091000.424843-1-j.grana...@samsung.com/)
- The "tiny" config + CONFIG_SYSCTL save 1215 bytes (bloat-o-meter 
output here
  
https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/)
* memory usage:
we save some bytes in main memory as well. In my testing kernel
I measured a difference of 7296 bytes. I include the way to
measure in [3]

Size saving after this patchset:
  Here I give the values that I measured for the architecture that I'm
  running (x86_64). This can give an approximation of how many bytes are
  saved for each arch. I won't publish for all the archs because I don't
  have access to all of them.
* bloat-o-meter
- The "yesall" config saves 192 bytes (bloat-o-meter output [4])
- The "tiny" config saves 64 bytes (bloat-o-meter output [5])
* memory usage:
In this case there were no bytes saved. To measure it comment the
printk in `new_dir` and uncomment the if conditional in `new_links`
[3].

Comments/feedback greatly appreciated

Best
Joel

[1]
We are able to remove a sentinel table without behavioral change by
introducing a table_size argument in the same place where procname is
checked for NULL. The idea is for it to keep stopping when it hits
->procname == NULL, while the sentinel is still present. And when the
sentinel is removed, it will stop on the table_size. You can go to 
(https://lore.kernel.org/all/20230809105006.1198165-1-j.grana...@samsung.com/)
for more information.

[2]
Links Related to the ctl_table sentinel removal:
* Good summary from Luis sent with the "pull request" for the
  preparation patches.
  https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/
* Another very good summary from Luis.
  https://lore.kernel.org/all/zmfizkfkvxuft...@bombadil.infradead.org/
* This is a patch set that replaces register_sysctl_table with register_sysctl
  https://lore.kernel.org/all/20230302204612.782387-1-mcg...@kernel.org/
* Patch set to deprecate register_sysctl_paths()
  https://lore.kernel.org/all/20230302202826.776286-1-mcg...@kernel.org/
* Here there is an explicit expectation for the removal of the sentinel element.
  https://lore.kernel.org/all/20230321130908.6972-1-frank...@vivo.com
* The "ARRAY_SIZE" approach was mentioned (proposed?) in this thread
  https://lore.kernel.org/all/20220220060626.15885-1-tangm...@uniontech.com

[3]
To measure the in memory savings apply this on top of this patchset.

"
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index c88854df0b62..e0073a627bac 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc

[PATCH 4/8] x86 vdso: rm sentinel element from ctl_table array

2023-09-06 Thread Joel Granados via B4 Relay
From: Joel Granados 

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/zo5yx5jfoggi%2f...@bombadil.infradead.org/)

Remove sentinel element from abi_table2.

Signed-off-by: Joel Granados 
---
 arch/x86/entry/vdso/vdso32-setup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/entry/vdso/vdso32-setup.c 
b/arch/x86/entry/vdso/vdso32-setup.c
index f3b3cacbcbb0..37b761802181 100644
--- a/arch/x86/entry/vdso/vdso32-setup.c
+++ b/arch/x86/entry/vdso/vdso32-setup.c
@@ -66,8 +66,7 @@ static struct ctl_table abi_table2[] = {
.proc_handler   = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_ONE,
-   },
-   {}
+   }
 };
 
 static __init int ia32_binfmt_init(void)

-- 
2.30.2



Re: [PATCH 09/11] sysctl: Remove the end element in sysctl table arrays

2023-06-21 Thread Joel Granados
On Wed, Jun 21, 2023 at 04:15:46PM +0300, Jani Nikula wrote:
> On Wed, 21 Jun 2023, Joel Granados  wrote:
> > On Wed, Jun 21, 2023 at 02:16:55PM +0300, Jani Nikula wrote:
> >> On Wed, 21 Jun 2023, Joel Granados  wrote:
> >> > Remove the empty end element from all the arrays that are passed to the
> >> > register sysctl calls. In some files this means reducing the explicit
> >> > array size by one. Also make sure that we are using the size in
> >> > ctl_table_header instead of evaluating the .procname element.
> >> 
> >> Where's the harm in removing the end elements driver by driver? This is
> >> an unwieldy patch to handle.
> >
> > I totally agree. Its a big one!!! but I'm concerned of breaking 
> > bisectibility:
> > * I could for example separate all the removes into separate commits and
> >   then have a final commit that removes the check for the empty element.
> >   But this will leave the tree in a state where the for loop will have
> >   undefined behavior when it looks for the empty end element. It might
> >   or might not work (probably not :) until the final commit where I fix
> >   that.
> >
> > * I could also change the logic that looks for the final element,
> >   commit that first and then remove the empty element one commit per
> >   driver after that. But then for all the arrays that still have an
> >   empty element, there would again be undefined behavior as it would
> >   think that the last element is valid (when it is really the sentinel).
> >
> > Any ideas on how to get around these?
> 
> First add size to the register calls, and allow the last one to be
> sentinel but do not require the sentinel.
> 
> Start removing sentinels, adjusting the size passed in.
This is a great idea! and I think I don't even have to adjust the size
because if I change the logic to stop on the sentinel or the size; so when
the sentinel is there, it will stop before the size. And when the
sentinel is not there, it will stop on the correct size.

There might be issues with indirection calls. And there might also be
lots of places where I need to adjust a for loop (as dan has pointed
out) but its worth a try for V2.

Best
> 
> Once enough sentinels have been removed, add warning if the final entry
> is a sentinel.
> 
> Never really remove the check? (But surely you can rework the logic to
> not count the number of elements up front, only while iterating.)
> 
> 
> BR,
> Jani.
> 
> >> 
> >> > diff --git a/drivers/gpu/drm/i915/i915_perf.c 
> >> > b/drivers/gpu/drm/i915/i915_perf.c
> >> > index f43950219ffc..e4d7372afb10 100644
> >> > --- a/drivers/gpu/drm/i915/i915_perf.c
> >> > +++ b/drivers/gpu/drm/i915/i915_perf.c
> >> > @@ -4884,24 +4884,23 @@ int i915_perf_remove_config_ioctl(struct 
> >> > drm_device *dev, void *data,
> >> >  
> >> >  static struct ctl_table oa_table[] = {
> >> >  {
> >> > - .procname = "perf_stream_paranoid",
> >> > - .data = _perf_stream_paranoid,
> >> > - .maxlen = sizeof(i915_perf_stream_paranoid),
> >> > - .mode = 0644,
> >> > - .proc_handler = proc_dointvec_minmax,
> >> > - .extra1 = SYSCTL_ZERO,
> >> > - .extra2 = SYSCTL_ONE,
> >> > - },
> >> > +.procname = "perf_stream_paranoid",
> >> > +.data = _perf_stream_paranoid,
> >> > +.maxlen = sizeof(i915_perf_stream_paranoid),
> >> > +.mode = 0644,
> >> > +.proc_handler = proc_dointvec_minmax,
> >> > +.extra1 = SYSCTL_ZERO,
> >> > +.extra2 = SYSCTL_ONE,
> >> > +},
> >> >  {
> >> > - .procname = "oa_max_sample_rate",
> >> > - .data = _oa_max_sample_rate,
> >> > - .maxlen = sizeof(i915_oa_max_sample_rate),
> >> > - .mode = 0644,
> >> > - .proc_handler = proc_dointvec_minmax,
> >> > - .extra1 = SYSCTL_ZERO,
> >> > - .extra2 = _sample_rate_hard_limit,
> >> > - },
> >> > -{}
> >> > +.procname = "oa_max_sample_rate",
> >> > +.data = _oa_max_sample_rate,
> >> > +.maxlen = sizeof(i915_oa_max_sample_rate),
> >> > +.mode = 0644,
> >> > + 

Re: [PATCH 09/11] sysctl: Remove the end element in sysctl table arrays

2023-06-21 Thread Joel Granados
On Wed, Jun 21, 2023 at 02:16:55PM +0300, Jani Nikula wrote:
> On Wed, 21 Jun 2023, Joel Granados  wrote:
> > Remove the empty end element from all the arrays that are passed to the
> > register sysctl calls. In some files this means reducing the explicit
> > array size by one. Also make sure that we are using the size in
> > ctl_table_header instead of evaluating the .procname element.
> 
> Where's the harm in removing the end elements driver by driver? This is
> an unwieldy patch to handle.

I totally agree. Its a big one!!! but I'm concerned of breaking bisectibility:
* I could for example separate all the removes into separate commits and
  then have a final commit that removes the check for the empty element.
  But this will leave the tree in a state where the for loop will have
  undefined behavior when it looks for the empty end element. It might
  or might not work (probably not :) until the final commit where I fix
  that.

* I could also change the logic that looks for the final element,
  commit that first and then remove the empty element one commit per
  driver after that. But then for all the arrays that still have an
  empty element, there would again be undefined behavior as it would
  think that the last element is valid (when it is really the sentinel).

Any ideas on how to get around these?
> 
> > diff --git a/drivers/gpu/drm/i915/i915_perf.c 
> > b/drivers/gpu/drm/i915/i915_perf.c
> > index f43950219ffc..e4d7372afb10 100644
> > --- a/drivers/gpu/drm/i915/i915_perf.c
> > +++ b/drivers/gpu/drm/i915/i915_perf.c
> > @@ -4884,24 +4884,23 @@ int i915_perf_remove_config_ioctl(struct drm_device 
> > *dev, void *data,
> >  
> >  static struct ctl_table oa_table[] = {
> > {
> > -.procname = "perf_stream_paranoid",
> > -.data = _perf_stream_paranoid,
> > -.maxlen = sizeof(i915_perf_stream_paranoid),
> > -.mode = 0644,
> > -.proc_handler = proc_dointvec_minmax,
> > -.extra1 = SYSCTL_ZERO,
> > -.extra2 = SYSCTL_ONE,
> > -},
> > +   .procname = "perf_stream_paranoid",
> > +   .data = _perf_stream_paranoid,
> > +   .maxlen = sizeof(i915_perf_stream_paranoid),
> > +   .mode = 0644,
> > +   .proc_handler = proc_dointvec_minmax,
> > +   .extra1 = SYSCTL_ZERO,
> > +   .extra2 = SYSCTL_ONE,
> > +   },
> > {
> > -.procname = "oa_max_sample_rate",
> > -.data = _oa_max_sample_rate,
> > -.maxlen = sizeof(i915_oa_max_sample_rate),
> > -.mode = 0644,
> > -.proc_handler = proc_dointvec_minmax,
> > -.extra1 = SYSCTL_ZERO,
> > -.extra2 = _sample_rate_hard_limit,
> > -},
> > -   {}
> > +   .procname = "oa_max_sample_rate",
> > +   .data = _oa_max_sample_rate,
> > +   .maxlen = sizeof(i915_oa_max_sample_rate),
> > +   .mode = 0644,
> > +   .proc_handler = proc_dointvec_minmax,
> > +   .extra1 = SYSCTL_ZERO,
> > +   .extra2 = _sample_rate_hard_limit,
> > +   }
> >  };
> 
> The existing indentation is off, but fixing it doesn't really belong in
> this patch.

Agreed. But I actually was trying to fix something that checkpatch
flagged. I'll change these back (which will cause this patch to be
flagged).

An alternative solution would be to fix the indentation as part of the
preparation patches. Tell me what you think.

Thx

> 
> BR,
> Jani.
> 
> 
> -- 
> Jani Nikula, Intel Open Source Graphics Center

-- 

Joel Granados


signature.asc
Description: PGP signature


[PATCH 09/11] sysctl: Remove the end element in sysctl table arrays

2023-06-21 Thread Joel Granados
Remove the empty end element from all the arrays that are passed to the
register sysctl calls. In some files this means reducing the explicit
array size by one. Also make sure that we are using the size in
ctl_table_header instead of evaluating the .procname element.

Signed-off-by: Joel Granados 
---
 arch/arm/kernel/isa.c |  4 +-
 arch/arm64/kernel/armv8_deprecated.c  |  8 ++--
 arch/arm64/kernel/fpsimd.c|  6 +--
 arch/arm64/kernel/process.c   |  3 +-
 arch/ia64/kernel/crash.c  |  3 +-
 arch/powerpc/kernel/idle.c|  3 +-
 arch/powerpc/platforms/pseries/mobility.c |  3 +-
 arch/s390/appldata/appldata_base.c|  7 ++--
 arch/s390/kernel/debug.c  |  3 +-
 arch/s390/kernel/topology.c   |  3 +-
 arch/s390/mm/cmm.c|  3 +-
 arch/s390/mm/pgalloc.c|  3 +-
 arch/x86/entry/vdso/vdso32-setup.c|  3 +-
 arch/x86/kernel/cpu/intel.c   |  3 +-
 arch/x86/kernel/itmt.c|  3 +-
 crypto/fips.c |  3 +-
 drivers/base/firmware_loader/fallback_table.c |  3 +-
 drivers/cdrom/cdrom.c |  3 +-
 drivers/char/hpet.c   | 13 +++---
 drivers/char/ipmi/ipmi_poweroff.c |  3 +-
 drivers/char/random.c |  3 +-
 drivers/gpu/drm/i915/i915_perf.c  | 33 +++
 drivers/hv/hv_common.c|  3 +-
 drivers/infiniband/core/iwcm.c|  3 +-
 drivers/infiniband/core/ucma.c|  3 +-
 drivers/macintosh/mac_hid.c   |  3 +-
 drivers/md/md.c   |  3 +-
 drivers/misc/sgi-xp/xpc_main.c|  6 +--
 drivers/net/vrf.c |  3 +-
 drivers/parport/procfs.c  | 42 ---
 drivers/perf/arm_pmuv3.c  |  3 +-
 drivers/scsi/scsi_sysctl.c|  3 +-
 drivers/scsi/sg.c |  3 +-
 drivers/tty/tty_io.c  |  3 +-
 drivers/xen/balloon.c |  3 +-
 fs/aio.c  |  3 +-
 fs/cachefiles/error_inject.c  |  3 +-
 fs/coda/sysctl.c  |  3 +-
 fs/coredump.c |  3 +-
 fs/dcache.c   |  3 +-
 fs/devpts/inode.c |  3 +-
 fs/eventpoll.c|  3 +-
 fs/exec.c |  3 +-
 fs/file_table.c   |  3 +-
 fs/inode.c|  3 +-
 fs/lockd/svc.c|  3 +-
 fs/locks.c|  3 +-
 fs/namei.c|  3 +-
 fs/namespace.c|  3 +-
 fs/nfs/nfs4sysctl.c   |  3 +-
 fs/nfs/sysctl.c   |  3 +-
 fs/notify/dnotify/dnotify.c   |  3 +-
 fs/notify/fanotify/fanotify_user.c|  3 +-
 fs/notify/inotify/inotify_user.c  |  3 +-
 fs/ntfs/sysctl.c  |  3 +-
 fs/ocfs2/stackglue.c  |  3 +-
 fs/pipe.c |  3 +-
 fs/proc/proc_sysctl.c |  8 ++--
 fs/quota/dquot.c  |  3 +-
 fs/sysctls.c  |  3 +-
 fs/userfaultfd.c  |  3 +-
 fs/verity/signature.c |  3 +-
 fs/xfs/xfs_sysctl.c   |  4 +-
 init/do_mounts_initrd.c   |  3 +-
 ipc/ipc_sysctl.c  |  3 +-
 ipc/mq_sysctl.c   |  3 +-
 kernel/acct.c |  3 +-
 kernel/bpf/syscall.c  |  3 +-
 kernel/delayacct.c|  3 +-
 kernel/exit.c |  3 +-
 kernel/hung_task.c|  3 +-
 kernel/kexec_core.c   |  3 +-
 kernel/kprobes.c  |  3 +-
 kernel/latencytop.c   |  3 +-
 kernel/locking/lockdep.c  |  3 +-
 kernel/panic.c|  3 +-
 kernel/pid_namespace.c|  3 +-
 kernel/pid_sysctl.h   |  3 +-
 kernel/printk/sysctl.c|  3 +-
 kernel/reboot.c   |  3 +-
 kernel/sched/autogroup.c  |  3 +-
 kernel/sched/core.c   |  3 +-
 kernel/sched/deadline.c   |  3 +-
 kernel/sched/fair.c   |  3 +-
 kernel/sched/rt.c

[PATCH 07/11] sysctl: Add size to register_sysctl

2023-06-21 Thread Joel Granados
In order to remove the end element from the ctl_table struct arrays, we
explicitly define the size when registering the targes.
We add a size argument to register_sysctl and change all the callers to
pass the ARRAY_SIZE of their table arg.

Signed-off-by: Joel Granados 
---
 arch/arm/kernel/isa.c |  2 +-
 arch/arm64/kernel/armv8_deprecated.c  |  2 +-
 arch/arm64/kernel/fpsimd.c|  6 +++--
 arch/arm64/kernel/process.c   |  3 ++-
 arch/ia64/kernel/crash.c  |  3 ++-
 arch/powerpc/kernel/idle.c|  3 ++-
 arch/powerpc/platforms/pseries/mobility.c |  3 ++-
 arch/s390/appldata/appldata_base.c|  4 +++-
 arch/s390/kernel/debug.c  |  3 ++-
 arch/s390/kernel/topology.c   |  3 ++-
 arch/s390/mm/cmm.c|  3 ++-
 arch/s390/mm/pgalloc.c|  3 ++-
 arch/x86/entry/vdso/vdso32-setup.c|  2 +-
 arch/x86/kernel/itmt.c|  3 ++-
 crypto/fips.c |  3 ++-
 drivers/base/firmware_loader/fallback_table.c |  6 ++---
 drivers/cdrom/cdrom.c |  3 ++-
 drivers/char/hpet.c   |  3 ++-
 drivers/char/ipmi/ipmi_poweroff.c |  3 ++-
 drivers/gpu/drm/i915/i915_perf.c  |  3 ++-
 drivers/hv/hv_common.c|  3 ++-
 drivers/macintosh/mac_hid.c   |  3 ++-
 drivers/md/md.c   |  3 ++-
 drivers/misc/sgi-xp/xpc_main.c|  6 +++--
 drivers/parport/procfs.c  | 11 +
 drivers/perf/arm_pmuv3.c  |  3 ++-
 drivers/scsi/scsi_sysctl.c|  3 ++-
 drivers/scsi/sg.c |  3 ++-
 fs/cachefiles/error_inject.c  |  3 ++-
 fs/coda/sysctl.c  |  3 ++-
 fs/devpts/inode.c |  3 ++-
 fs/eventpoll.c|  2 +-
 fs/lockd/svc.c|  3 ++-
 fs/nfs/nfs4sysctl.c   |  3 ++-
 fs/nfs/sysctl.c   |  3 ++-
 fs/notify/fanotify/fanotify_user.c|  3 ++-
 fs/notify/inotify/inotify_user.c  |  3 ++-
 fs/ntfs/sysctl.c  |  3 ++-
 fs/ocfs2/stackglue.c  |  3 ++-
 fs/proc/proc_sysctl.c | 23 ++-
 fs/verity/signature.c |  4 +++-
 fs/xfs/xfs_sysctl.c   |  3 ++-
 include/linux/sysctl.h|  6 +++--
 kernel/pid_sysctl.h   |  2 +-
 kernel/time/timer.c   |  2 +-
 kernel/ucount.c   |  2 +-
 kernel/utsname_sysctl.c   |  2 +-
 lib/test_sysctl.c |  9 +---
 net/sunrpc/sysctl.c   |  3 ++-
 net/sunrpc/xprtrdma/svc_rdma.c|  3 ++-
 net/sunrpc/xprtrdma/transport.c   |  4 +++-
 net/sunrpc/xprtsock.c |  4 +++-
 net/sysctl_net.c  |  2 +-
 security/apparmor/lsm.c   |  3 ++-
 security/loadpin/loadpin.c|  3 ++-
 security/yama/yama_lsm.c  |  3 ++-
 56 files changed, 133 insertions(+), 76 deletions(-)

diff --git a/arch/arm/kernel/isa.c b/arch/arm/kernel/isa.c
index 20218876bef2..561432e3c55a 100644
--- a/arch/arm/kernel/isa.c
+++ b/arch/arm/kernel/isa.c
@@ -46,5 +46,5 @@ register_isa_ports(unsigned int membase, unsigned int 
portbase, unsigned int por
isa_membase = membase;
isa_portbase = portbase;
isa_portshift = portshift;
-   isa_sysctl_header = register_sysctl("bus/isa", ctl_isa_vars);
+   isa_sysctl_header = register_sysctl("bus/isa", ctl_isa_vars, 
ARRAY_SIZE(ctl_isa_vars));
 }
diff --git a/arch/arm64/kernel/armv8_deprecated.c 
b/arch/arm64/kernel/armv8_deprecated.c
index 1febd412b4d2..68ed60a521a6 100644
--- a/arch/arm64/kernel/armv8_deprecated.c
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -569,7 +569,7 @@ static void __init register_insn_emulation(struct 
insn_emulation *insn)
sysctl->extra2 = >max;
sysctl->proc_handler = emulation_proc_handler;
 
-   register_sysctl("abi", sysctl);
+   register_sysctl("abi", sysctl, 1);
}
 }
 
diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 2fbafa5cc7ac..ecfb2ef6a036 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -595,7 +595,8 @@ static struct ctl_table sve_default_vl_table[] = {
 static int __init sve_sysctl_init(void)
 {
if (system_supports_sve())
-   if (!register_sysctl("abi", sve_d