diff mbox series

[v4,-next,14/15] sh: vdso: move the sysctl to arch/sh/kernel/vsyscall/vsyscall.c

Message ID 20241228145746.2783627-15-yukaixiong@huawei.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series sysctl: move sysctls from vm_table into its own files | expand

Commit Message

yukaixiong Dec. 28, 2024, 2:57 p.m. UTC
When CONFIG_SUPERH and CONFIG_VSYSCALL are defined,
vdso_enabled belongs to arch/sh/kernel/vsyscall/vsyscall.c.
So, move it into its own file. After this patch is applied,
all sysctls of vm_table would be moved. So, delete vm_table.

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vdso_table
v3:
 - change the title
---
---
 arch/sh/kernel/vsyscall/vsyscall.c | 14 ++++++++++++++
 kernel/sysctl.c                    | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)

Comments

Geert Uytterhoeven Jan. 3, 2025, 11:11 a.m. UTC | #1
Hi Kaixiong,

On Sat, Dec 28, 2024 at 4:07 PM Kaixiong Yu <yukaixiong@huawei.com> wrote:
> When CONFIG_SUPERH and CONFIG_VSYSCALL are defined,
> vdso_enabled belongs to arch/sh/kernel/vsyscall/vsyscall.c.
> So, move it into its own file. After this patch is applied,
> all sysctls of vm_table would be moved. So, delete vm_table.
>
> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
> Reviewed-by: Kees Cook <kees@kernel.org>
> ---
> v4:
>  - const qualify struct ctl_table vdso_table

Thanks for your patch!

I gave this a try on landisk, and /proc/sys/vm/vdso_enabled
disappeared.

> --- a/arch/sh/kernel/vsyscall/vsyscall.c
> +++ b/arch/sh/kernel/vsyscall/vsyscall.c
> @@ -55,6 +67,8 @@ int __init vsyscall_init(void)
>                &vsyscall_trapa_start,
>                &vsyscall_trapa_end - &vsyscall_trapa_start);
>
> +       register_sysctl_init("vm", vdso_table);

    "failed when register_sysctl_sz vdso_table to vm"

Adding some debug prints shows that kzalloc() in
__register_sysctl_table() fails, presumably because it is called too
early in the boot process.

> +
>         return 0;
>  }

Moving the call to register_sysctl_init() into its own fs_initcall(),
like the gmail-whitespace-damaged patch below, fixes that.

--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -67,11 +67,17 @@ int __init vsyscall_init(void)
               &vsyscall_trapa_start,
               &vsyscall_trapa_end - &vsyscall_trapa_start);

-       register_sysctl_init("vm", vdso_table);
+       return 0;
+}

+static int __init vm_sysctl_init(void)
+{
+       register_sysctl_init("vm", vdso_table);
        return 0;
 }

+fs_initcall(vm_sysctl_init);
+
 /* Setup a VMA at program startup for the vsyscall page */
 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 {

Gr{oetje,eeting}s,

                        Geert
Joel Granados Jan. 6, 2025, 11:59 a.m. UTC | #2
On Sat, Dec 28, 2024 at 10:57:45PM +0800, Kaixiong Yu wrote:
> When CONFIG_SUPERH and CONFIG_VSYSCALL are defined,
> vdso_enabled belongs to arch/sh/kernel/vsyscall/vsyscall.c.
> So, move it into its own file. After this patch is applied,
> all sysctls of vm_table would be moved. So, delete vm_table.
> 
> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
> Reviewed-by: Kees Cook <kees@kernel.org>
> ---
> v4:
>  - const qualify struct ctl_table vdso_table
> v3:
>  - change the title
> ---
> ---
>  arch/sh/kernel/vsyscall/vsyscall.c | 14 ++++++++++++++
>  kernel/sysctl.c                    | 14 --------------
>  2 files changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
> index add35c51e017..898132f34e6a 100644
> --- a/arch/sh/kernel/vsyscall/vsyscall.c
> +++ b/arch/sh/kernel/vsyscall/vsyscall.c
> @@ -14,6 +14,7 @@
>  #include <linux/module.h>
>  #include <linux/elf.h>
>  #include <linux/sched.h>
> +#include <linux/sysctl.h>
>  #include <linux/err.h>
>  
>  /*
> @@ -30,6 +31,17 @@ static int __init vdso_setup(char *s)
>  }
>  __setup("vdso=", vdso_setup);
>  
> +static const struct ctl_table vdso_table[] = {
> +	{
> +		.procname	= "vdso_enabled",
> +		.data		= &vdso_enabled,
> +		.maxlen		= sizeof(vdso_enabled),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec,
> +		.extra1		= SYSCTL_ZERO,
> +	},
> +};
> +
>  /*
>   * These symbols are defined by vsyscall.o to mark the bounds
>   * of the ELF DSO images included therein.
> @@ -55,6 +67,8 @@ int __init vsyscall_init(void)
>  	       &vsyscall_trapa_start,
>  	       &vsyscall_trapa_end - &vsyscall_trapa_start);
>  
> +	register_sysctl_init("vm", vdso_table);
> +
>  	return 0;
>  }
>  
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 7ff07b7560b4..cebd0ef5d19d 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2012,23 +2012,9 @@ static struct ctl_table kern_table[] = {
>  #endif
>  };
>  
As you mentioned in the commit message, this patch has two objectives.
1. It moves the vdso_enabled table and 2. It removes the vm_table.
Please separate these two in such a way that the second (removal of
vm_table) can be done at the end and is not related to any particular
table under vm_table. I prefer it that way so that the removal of
vm_table does not block the upstreaming of a move that is already
reviewed and ready.


> -static struct ctl_table vm_table[] = {
> -#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
> -	{
> -		.procname	= "vdso_enabled",
> -		.data		= &vdso_enabled,
> -		.maxlen		= sizeof(vdso_enabled),
> -		.mode		= 0644,
> -		.proc_handler	= proc_dointvec,
> -		.extra1		= SYSCTL_ZERO,
> -	},
> -#endif
> -};
> -
>  int __init sysctl_init_bases(void)
>  {
>  	register_sysctl_init("kernel", kern_table);
> -	register_sysctl_init("vm", vm_table);
>  
>  	return 0;
>  }
> -- 
> 2.34.1
>
yukaixiong Jan. 9, 2025, 2:33 a.m. UTC | #3
On 2025/1/3 19:11, Geert Uytterhoeven wrote:
> Hi Kaixiong,
>
> On Sat, Dec 28, 2024 at 4:07 PM Kaixiong Yu <yukaixiong@huawei.com> wrote:
>> When CONFIG_SUPERH and CONFIG_VSYSCALL are defined,
>> vdso_enabled belongs to arch/sh/kernel/vsyscall/vsyscall.c.
>> So, move it into its own file. After this patch is applied,
>> all sysctls of vm_table would be moved. So, delete vm_table.
>>
>> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
>> Reviewed-by: Kees Cook <kees@kernel.org>
>> ---
>> v4:
>>   - const qualify struct ctl_table vdso_table
> Thanks for your patch!
>
> I gave this a try on landisk, and /proc/sys/vm/vdso_enabled
> disappeared.
>
>> --- a/arch/sh/kernel/vsyscall/vsyscall.c
>> +++ b/arch/sh/kernel/vsyscall/vsyscall.c
>> @@ -55,6 +67,8 @@ int __init vsyscall_init(void)
>>                 &vsyscall_trapa_start,
>>                 &vsyscall_trapa_end - &vsyscall_trapa_start);
>>
>> +       register_sysctl_init("vm", vdso_table);
>      "failed when register_sysctl_sz vdso_table to vm"
>
> Adding some debug prints shows that kzalloc() in
> __register_sysctl_table() fails, presumably because it is called too
> early in the boot process.
>
>> +
>>          return 0;
>>   }
> Moving the call to register_sysctl_init() into its own fs_initcall(),
> like the gmail-whitespace-damaged patch below, fixes that.
>
> --- a/arch/sh/kernel/vsyscall/vsyscall.c
> +++ b/arch/sh/kernel/vsyscall/vsyscall.c
> @@ -67,11 +67,17 @@ int __init vsyscall_init(void)
>                 &vsyscall_trapa_start,
>                 &vsyscall_trapa_end - &vsyscall_trapa_start);
>
> -       register_sysctl_init("vm", vdso_table);
> +       return 0;
> +}
>
> +static int __init vm_sysctl_init(void)
> +{
> +       register_sysctl_init("vm", vdso_table);
>          return 0;
>   }
>
> +fs_initcall(vm_sysctl_init);
> +
>   /* Setup a VMA at program startup for the vsyscall page */
>   int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
>   {
>
> Gr{oetje,eeting}s,
>
>                          Geert

Thank you so much for your test and fix patch !

I will fix it in patches series v5.

Best ...
yukaixiong Jan. 9, 2025, 2:40 a.m. UTC | #4
On 2025/1/6 19:59, Joel Granados wrote:
> On Sat, Dec 28, 2024 at 10:57:45PM +0800, Kaixiong Yu wrote:
>> When CONFIG_SUPERH and CONFIG_VSYSCALL are defined,
>> vdso_enabled belongs to arch/sh/kernel/vsyscall/vsyscall.c.
>> So, move it into its own file. After this patch is applied,
>> all sysctls of vm_table would be moved. So, delete vm_table.
>>
>> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
>> Reviewed-by: Kees Cook <kees@kernel.org>
>> ---
>> v4:
>>   - const qualify struct ctl_table vdso_table
>> v3:
>>   - change the title
>> ---
>> ---
>>   arch/sh/kernel/vsyscall/vsyscall.c | 14 ++++++++++++++
>>   kernel/sysctl.c                    | 14 --------------
>>   2 files changed, 14 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
>> index add35c51e017..898132f34e6a 100644
>> --- a/arch/sh/kernel/vsyscall/vsyscall.c
>> +++ b/arch/sh/kernel/vsyscall/vsyscall.c
>> @@ -14,6 +14,7 @@
>>   #include <linux/module.h>
>>   #include <linux/elf.h>
>>   #include <linux/sched.h>
>> +#include <linux/sysctl.h>
>>   #include <linux/err.h>
>>   
>>   /*
>> @@ -30,6 +31,17 @@ static int __init vdso_setup(char *s)
>>   }
>>   __setup("vdso=", vdso_setup);
>>   
>> +static const struct ctl_table vdso_table[] = {
>> +	{
>> +		.procname	= "vdso_enabled",
>> +		.data		= &vdso_enabled,
>> +		.maxlen		= sizeof(vdso_enabled),
>> +		.mode		= 0644,
>> +		.proc_handler	= proc_dointvec,
>> +		.extra1		= SYSCTL_ZERO,
>> +	},
>> +};
>> +
>>   /*
>>    * These symbols are defined by vsyscall.o to mark the bounds
>>    * of the ELF DSO images included therein.
>> @@ -55,6 +67,8 @@ int __init vsyscall_init(void)
>>   	       &vsyscall_trapa_start,
>>   	       &vsyscall_trapa_end - &vsyscall_trapa_start);
>>   
>> +	register_sysctl_init("vm", vdso_table);
>> +
>>   	return 0;
>>   }
>>   
>> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
>> index 7ff07b7560b4..cebd0ef5d19d 100644
>> --- a/kernel/sysctl.c
>> +++ b/kernel/sysctl.c
>> @@ -2012,23 +2012,9 @@ static struct ctl_table kern_table[] = {
>>   #endif
>>   };
>>   
> As you mentioned in the commit message, this patch has two objectives.
> 1. It moves the vdso_enabled table and 2. It removes the vm_table.
> Please separate these two in such a way that the second (removal of
> vm_table) can be done at the end and is not related to any particular
> table under vm_table. I prefer it that way so that the removal of
> vm_table does not block the upstreaming of a move that is already
> reviewed and ready.
>
Thank you for your advice ! I will modify it in series patches v5.
>> -static struct ctl_table vm_table[] = {
>> -#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
>> -	{
>> -		.procname	= "vdso_enabled",
>> -		.data		= &vdso_enabled,
>> -		.maxlen		= sizeof(vdso_enabled),
>> -		.mode		= 0644,
>> -		.proc_handler	= proc_dointvec,
>> -		.extra1		= SYSCTL_ZERO,
>> -	},
>> -#endif
>> -};
>> -
>>   int __init sysctl_init_bases(void)
>>   {
>>   	register_sysctl_init("kernel", kern_table);
>> -	register_sysctl_init("vm", vm_table);
>>   
>>   	return 0;
>>   }
>> -- 
>> 2.34.1
>>
diff mbox series

Patch

diff --git a/arch/sh/kernel/vsyscall/vsyscall.c b/arch/sh/kernel/vsyscall/vsyscall.c
index add35c51e017..898132f34e6a 100644
--- a/arch/sh/kernel/vsyscall/vsyscall.c
+++ b/arch/sh/kernel/vsyscall/vsyscall.c
@@ -14,6 +14,7 @@ 
 #include <linux/module.h>
 #include <linux/elf.h>
 #include <linux/sched.h>
+#include <linux/sysctl.h>
 #include <linux/err.h>
 
 /*
@@ -30,6 +31,17 @@  static int __init vdso_setup(char *s)
 }
 __setup("vdso=", vdso_setup);
 
+static const struct ctl_table vdso_table[] = {
+	{
+		.procname	= "vdso_enabled",
+		.data		= &vdso_enabled,
+		.maxlen		= sizeof(vdso_enabled),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+		.extra1		= SYSCTL_ZERO,
+	},
+};
+
 /*
  * These symbols are defined by vsyscall.o to mark the bounds
  * of the ELF DSO images included therein.
@@ -55,6 +67,8 @@  int __init vsyscall_init(void)
 	       &vsyscall_trapa_start,
 	       &vsyscall_trapa_end - &vsyscall_trapa_start);
 
+	register_sysctl_init("vm", vdso_table);
+
 	return 0;
 }
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 7ff07b7560b4..cebd0ef5d19d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2012,23 +2012,9 @@  static struct ctl_table kern_table[] = {
 #endif
 };
 
-static struct ctl_table vm_table[] = {
-#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
-	{
-		.procname	= "vdso_enabled",
-		.data		= &vdso_enabled,
-		.maxlen		= sizeof(vdso_enabled),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec,
-		.extra1		= SYSCTL_ZERO,
-	},
-#endif
-};
-
 int __init sysctl_init_bases(void)
 {
 	register_sysctl_init("kernel", kern_table);
-	register_sysctl_init("vm", vm_table);
 
 	return 0;
 }