sysctl: Allow /proc/sys without sys_sysctl
PATCH 1/1 sysctl: Allow /proc/sys without sys_sysctl
Since sys_sysctl is deprecated start allow it to be compiled out. This should catch any remaining user space code that cares, and paves the way for further sysctl cleanups.
--- arch/ia64/ia32/sys_ia32.c | 2 - arch/mips/kernel/linux32.c | 4 + arch/powerpc/kernel/sys_ppc32.c | 2 - arch/s390/kernel/compat_linux.c | 2 - arch/sparc64/kernel/sys_sparc32.c | 2 - arch/x86_64/ia32/sys_ia32.c | 2 - fs/Kconfig | 19 +++++++ init/Kconfig | 31 ++++++----- kernel/sysctl.c | 101 ++++++++++--------------------------- 9 files changed, 71 insertions(+), 94 deletions(-)
arch/ia64/ia32/sys_ia32.c +1 -1
@@ -1942,7 +1942,7 @@ struct sysctl32 {unsigned int __unused[4 ]; }; -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL asmlinkage long sys32_sysctl (struct sysctl32 __user *args) {
arch/mips/kernel/linux32.c +2 -2
@@ -991,7 +991,7 @@ struct sysctl_args32unsigned int __unused[4 ]; }; -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL asmlinkage long sys32_sysctl (struct sysctl_args32 __user *args) {
@@ -1032,7 +1032,7 @@ asmlinkage long sys32_sysctl(struct sysc return error; } -#endif /* CONFIG_SYSCTL */ +#endif /* CONFIG_SYSCTL_SYSCALL */ asmlinkage long sys32_newuname (struct new_utsname __user * name) {
arch/powerpc/kernel/sys_ppc32.c +1 -1
@@ -740,7 +740,7 @@ asmlinkage long compat_sys_umask(u32 masreturn sys_umask ((int )mask); } -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL struct __sysctl_args32 { u32 name; int nlen;
arch/s390/kernel/compat_linux.c +1 -1
@@ -703,7 +703,7 @@ asmlinkage long sys32_sendfile64(int outreturn ret; } -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL struct __sysctl_args32 { u32 name; int nlen;
arch/sparc64/kernel/sys_sparc32.c +1 -1
@@ -1016,7 +1016,7 @@ struct __sysctl_args32 {asmlinkage long sys32_sysctl (struct __sysctl_args32 __user *args) { -#ifndef CONFIG_SYSCTL +#ifndef CONFIG_SYSCTL_SYSCALL return -ENOSYS ;#else struct __sysctl_args32 tmp;
arch/x86_64/ia32/sys_ia32.c +1 -1
@@ -645,7 +645,7 @@ sys32_pause(void) } -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL struct sysctl_ia32 { unsigned int name; int nlen;
fs/Kconfig +19 -0
@@ -829,6 +829,25 @@ config PROC_VMCORE help Exports the dump image of crashed kernel in ELF format. +config PROC_SYSCTL + bool "Sysctl support (/proc/sys)" if EMBEDDED + depends on PROC_FS + select SYSCTL + default y + ---help--- + The sysctl interface provides a means of dynamically changing + certain kernel parameters and variables on the fly without requiring + a recompile of the kernel or reboot of the system. The primary + interface is through /proc/sys. If you say Y here a tree of + modifiable sysctl entries will be generated beneath the + /proc/sys directory. They are explained in the files + in <file:Documentation/sysctl/>. Note that enabling this + option will enlarge the kernel by at least 8 KB. + + As it is generally a good thing, you should say Y here unless + building a kernel for install/rescue disks or your system is very + limited in memory. + config SYSFS bool "sysfs file system support" if EMBEDDED default y
init/Kconfig +17 -14
@@ -213,21 +213,24 @@ config TASK_DELAY_ACCT Say N if unsure. config SYSCTL - bool "Sysctl support" if EMBEDDED - default y + bool + +config SYSCTL_SYSCALL + bool "Sysctl syscall support" + default n + select SYSCTL ---help--- - The sysctl interface provides a means of dynamically changing - certain kernel parameters and variables on the fly without requiring - a recompile of the kernel or reboot of the system. The primary - interface consists of a system call, but if you say Y to "/proc - file system support", a tree of modifiable sysctl entries will be - generated beneath the /proc/sys directory. They are explained in the - files in <file:Documentation/sysctl/>. Note that enabling this - option will enlarge the kernel by at least 8 KB. - - As it is generally a good thing, you should say Y here unless - building a kernel for install/rescue disks or your system is very - limited in memory. + Enable the deprecated sysctl system call. sys_sysctl uses + binary paths that have been found to be a major pain to maintain + and use. The interface in /proc/sys is now the primary and what + everyone uses. + + Nothing has been using the binary sysctl interface for some time + time now so nothing should break if you disable sysctl syscall + support, and you kernel will get marginally smaller. + + Unless you have an application that uses the sys_syscall interface + you should probably say N here. config UTS_NS bool "UTS Namespaces"
kernel/sysctl.c +28 -73
184 lines not on this page · raw message
Signature · 1 line
1.4.1.gac83a
Quoted 4 lines · On Mon, 10 Jul 2006 16:38:59 -0600 Eric W. Biederman wrote:
Since
sys_sysctlis deprecated start allow it to be compiled out. This should catch any remaining user space code that cares, and paves the way for further sysctl cleanups.
Where is it documented and users notified that sys_sysctl is deprecated? Sounds like it should be added to Documentation/feature-removal-schedule.txt.
Quoted 363 lines
Signed-off-by Eric W. Biederman <[email protected]>--- arch/ia64/ia32/sys_ia32.c | 2 - arch/mips/kernel/linux32.c | 4 + arch/powerpc/kernel/sys_ppc32.c | 2 - arch/s390/kernel/compat_linux.c | 2 - arch/sparc64/kernel/sys_sparc32.c | 2 - arch/x86_64/ia32/sys_ia32.c | 2 - fs/Kconfig | 19 +++++++ init/Kconfig | 31 ++++++----- kernel/sysctl.c | 101 ++++++++++--------------------------- 9 files changed, 71 insertions(+), 94 deletions(-)arch/ia64/ia32/sys_ia32.c +1
-1@@ -1942,7 +1942,7 @@ struct sysctl32 {unsigned int __unused[4 ]; }; -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL asmlinkage long sys32_sysctl (struct sysctl32 __user *args) {arch/mips/kernel/linux32.c +2
-2@@ -991,7 +991,7 @@ struct sysctl_args32unsigned int __unused[4 ]; }; -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL asmlinkage long sys32_sysctl (struct sysctl_args32 __user *args) {@@ -1032,7 +1032,7 @@ asmlinkage long sys32_sysctl(struct sysc return error; } -#endif /* CONFIG_SYSCTL */ +#endif /* CONFIG_SYSCTL_SYSCALL */ asmlinkage long sys32_newuname (struct new_utsname __user * name) {arch/powerpc/kernel/sys_ppc32.c +1
-1@@ -740,7 +740,7 @@ asmlinkage long compat_sys_umask(u32 masreturn sys_umask ((int )mask); } -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL struct __sysctl_args32 { u32 name; int nlen;arch/s390/kernel/compat_linux.c +1
-1@@ -703,7 +703,7 @@ asmlinkage long sys32_sendfile64(int outreturn ret; } -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL struct __sysctl_args32 { u32 name; int nlen;arch/sparc64/kernel/sys_sparc32.c +1
-1@@ -1016,7 +1016,7 @@ struct __sysctl_args32 {asmlinkage long sys32_sysctl (struct __sysctl_args32 __user *args) { -#ifndef CONFIG_SYSCTL +#ifndef CONFIG_SYSCTL_SYSCALL return -ENOSYS ;#else struct __sysctl_args32 tmp;arch/x86_64/ia32/sys_ia32.c +1
-1@@ -645,7 +645,7 @@ sys32_pause(void) } -#ifdef CONFIG_SYSCTL +#ifdef CONFIG_SYSCTL_SYSCALL struct sysctl_ia32 { unsigned int name; int nlen;fs/Kconfig +19
-0@@ -829,6 +829,25 @@ config PROC_VMCORE help Exports the dump image of crashed kernel in ELF format. +config PROC_SYSCTL + bool "Sysctl support (/proc/sys)" if EMBEDDED + depends on PROC_FS + select SYSCTL + default y + ---help--- + The sysctl interface provides a means of dynamically changing + certain kernel parameters and variables on the fly without requiring + a recompile of the kernel or reboot of the system. The primary + interface is through /proc/sys. If you say Y here a tree of + modifiable sysctl entries will be generated beneath the + /proc/sys directory. They are explained in the files + in <file:Documentation/sysctl/>. Note that enabling this + option will enlarge the kernel by at least 8 KB. + + As it is generally a good thing, you should say Y here unless + building a kernel for install/rescue disks or your system is very + limited in memory. + config SYSFS bool "sysfs file system support" if EMBEDDED default yinit/Kconfig +17
-14@@ -213,21 +213,24 @@ config TASK_DELAY_ACCT Say N if unsure. config SYSCTL - bool "Sysctl support" if EMBEDDED - default y + bool + +config SYSCTL_SYSCALL + bool "Sysctl syscall support" + default n + select SYSCTL ---help--- - The sysctl interface provides a means of dynamically changing - certain kernel parameters and variables on the fly without requiring - a recompile of the kernel or reboot of the system. The primary - interface consists of a system call, but if you say Y to "/proc - file system support", a tree of modifiable sysctl entries will be - generated beneath the /proc/sys directory. They are explained in the - files in <file:Documentation/sysctl/>. Note that enabling this - option will enlarge the kernel by at least 8 KB. - - As it is generally a good thing, you should say Y here unless - building a kernel for install/rescue disks or your system is very - limited in memory. + Enable the deprecated sysctl system call. sys_sysctl uses + binary paths that have been found to be a major pain to maintain + and use. The interface in /proc/sys is now the primary and what + everyone uses. + + Nothing has been using the binary sysctl interface for some time + time now so nothing should break if you disable sysctl syscall + support, and you kernel will get marginally smaller. + + Unless you have an application that uses the sys_syscall interface + you should probably say N here. config UTS_NS bool "UTS Namespaces"kernel/sysctl.c +27
-67@@ -140,8 +140,11 @@ #ifdef CONFIG_RT_MUTEXESextern int max_lock_depth;#endif +#ifdef CONFIG_SYSCTL_SYSCALL static int parse_table (int __user *,int ,void __user *,size_t __user *,void __user *,size_t ,ctl_table *,void **); +#endif +#ifndef CONFIG_UTS_NS static int proc_do_uts_string (ctl_table *table,int write,struct file *filp,void __user *buffer,size_t *lenp,loff_t *ppos);@@ -173,7 +176,7 @@ #endif/* /proc declarations: */ -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_PROC_SYSCTL static ssize_t proc_readsys (struct file *,char __user *,size_t ,loff_t *);static ssize_t proc_writesys (struct file *,const char __user *,size_t ,loff_t *);@@ -1252,12 +1255,13 @@ static void start_unregistering(struct cvoid __init sysctl_init (void ) { -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_PROC_SYSCTL register_proc_table (root_table, proc_sys_root, &root_table_header);init_irq_proc ();#endif } +#ifdef CONFIG_SYSCTL_SYSCALL int do_sysctl (int __user *name,int nlen,void __user *oldval,size_t __user *oldlenp,void __user *newval,size_t newlen) {@@ -1311,6 +1315,7 @@ asmlinkage long sys_sysctl(struct __syscunlock_kernel (); return error; } +#endif /* CONFIG_SYSCTL_SYSCALL */ /* * ctl_perm does NOT grant the superuser all rights automatically, because @@ -1337,6 +1342,7 @@ static inline int ctl_perm(ctl_table *tareturn test_perm (table->mode, op); } +#ifdef CONFIG_SYSCTL_SYSCALL static int parse_table(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, void __user *newval, size_t newlen,@@ -1426,6 +1432,7 @@ int do_sysctl_strategy (ctl_table *table }return 0 ; } +#endif /* CONFIG_SYSCTL_SYSCALL */ /** * register_sysctl_table - register a sysctl hierarchy @@ -1513,7 +1520,7 @@ struct ctl_table_header *register_sysctlelse list_add_tail (&tmp->ctl_entry, &root_table_header.ctl_entry);spin_unlock (&sysctl_lock); -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_PROC_SYSCTL register_proc_table (table, proc_sys_root, tmp);#endif return tmp;@@ -1531,18 +1538,31 @@ void unregister_sysctl_table(struct ctl_might_sleep ();spin_lock (&sysctl_lock);start_unregistering (header); -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_PROC_SYSCTL unregister_proc_table (header->ctl_table, proc_sys_root);#endif spin_unlock (&sysctl_lock); kfree(header); } +#else /* !CONFIG_SYSCTL */ +struct ctl_table_header *register_sysctl_table (ctl_table * table, +int insert_at_head) +{ +return NULL ; +} + +void unregister_sysctl_table (struct ctl_table_header * table) +{ +} + +#endif /* CONFIG_SYSCTL */ +/* * /proc/sys support */ -#ifdef CONFIG_PROC_FS +#ifdef CONFIG_PROC_SYSCTL /* Scan the sysctl entries in table and add them all into /proc */ static void register_proc_table (ctl_table * table,struct proc_dir_entry *root,void *set)@@ -2520,6 +2540,7 @@ int proc_doulongvec_ms_jiffies_minmax(ct#endif /* CONFIG_PROC_FS */ +#ifdef CONFIG_SYSCTL_SYSCALL /* * General sysctl support routines */ @@ -2662,7 +2683,7 @@ int sysctl_ms_jiffies(ctl_table *table, return 1; } -#else /* CONFIG_SYSCTL */ +#else /* CONFIG_SYSCTL_SYSCALL */ asmlinkage long sys_sysctl (struct __sysctl_args __user *args)@@ -2698,73 +2719,7 @@ int sysctl_ms_jiffies(ctl_table *table,return -ENOSYS ; } -int proc_dostring (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_dointvec (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_dointvec_bset (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_dointvec_minmax (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_dointvec_jiffies (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_dointvec_userhz_jiffies (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_dointvec_ms_jiffies (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_doulongvec_minmax (ctl_table *table,int write,struct file *filp, -void __user *buffer,size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -int proc_doulongvec_ms_jiffies_minmax (ctl_table *table,int write, -struct file *filp, -void __user *buffer, -size_t *lenp,loff_t *ppos) -{ -return -ENOSYS ; -} - -struct ctl_table_header *register_sysctl_table (ctl_table * table, -int insert_at_head) -{ -return NULL ; -}
kernel/sysctl.c int sysctl_ms_jiffies(ctl_table *table, · line 2725
Quoted 10 lines
kernel/sysctl.c +1
-6- -void unregister_sysctl_table (struct ctl_table_header * table) -{ -} - -#endif /* CONFIG_SYSCTL */ +#endif /* CONFIG_SYSCTL_SYSCALL */ /* * No sense putting this after each symbol definition, twice,
---
~Randy
Quoted 10 lines · Randy.Dunlap
Quoted 4 lines · On Mon, 10 Jul 2006 16:38:59 -0600 Eric W. Biederman wrote:
Since
sys_sysctlis deprecated start allow it to be compiled out. This should catch any remaining user space code that cares, and paves the way for further sysctl cleanups.Where is it documented and users notified that
sys_sysctlis deprecated? Sounds like it should be added toDocumentation/feature-removal-schedule.txt.
The deprecation I believe actually predates feature-remove-schedule.txt
Quoted 5 lines
From
include/linux/sysctl.h****************************************************************
****************************************************************
**
Quoted 7 lines
** The values in this file are exported to user space via ** the sysctl() binary interface. However this interface ** is unstable and deprecated and will be removed in the future. ** For a stable interface use /proc/sys.**
****************************************************************
****************************************************************
And I can't actually find any user space applications that continue to use sys_sysctl.
So the combination of the two patches and makes the deprecation official, and makes it a compile time option so we can disable sys_sysctl now, but still have recourse if some parts of user space need the code.
Currently the we dup the internal helpers which makes maintenance of the code a nightmare.
Eric
Quoted 1 line · On Mon, 10 Jul 2006 16:38:59 -0600 [email protected] (Eric W. Biederman)…
Since
sys_sysctlis deprecated start allow it to be compiled out.
This could be a tough one to get rid of (looks at sys_bdflush() again).
I'd suggest we put a sys_bdflush()-style warning in there, see what that flushes out.
Quoted 9 lines · Andrew Morton
Quoted 1 line · On Mon, 10 Jul 2006 16:38:59 -0600 [email protected] (Eric W. Biederman)…
Since
sys_sysctlis deprecated start allow it to be compiled out.This could be a tough one to get rid of (looks at
sys_bdflush()again).I'd suggest we put a sys_bdflush()-style warning in there, see what that flushes out.
Sounds sane. I know I have booted several kernels with it compiled out but just because you can do without it doesn't mean that something isn't using it.
Hmm. The question is where do I want the put the warning message?
When the code is compiled out?
When the code is compiled in?
Probably both places at this point, and using the rate limited printk I think instead of just the 5 printks that sys_bdflush uses...
I will cook up an incremental patch once I get some sleep.
Eric
Quoted 12 lines · On Tue, 11 Jul 2006 00:57:35 -0600 [email protected] (Eric W. Biederman)…
Quoted 9 lines · Andrew Morton
Quoted 1 line · On Mon, 10 Jul 2006 16:38:59 -0600 [email protected] (Eric W. Biederman)…
Since
sys_sysctlis deprecated start allow it to be compiled out.This could be a tough one to get rid of (looks at
sys_bdflush()again).I'd suggest we put a sys_bdflush()-style warning in there, see what that flushes out.
Quoted 8 lines
Sounds sane. I know I have booted several kernels with it compiled out but just because you can do without it doesn't mean that something isn't using it.
Hmm. The question is where do I want the put the warning message?
When the code is compiled out?
When the code is compiled in?
Both. We want to find out who is using it.
Quoted 2 lines
Probably both places at this point, and using the rate limited printk I think instead of just the 5 printks that
sys_bdflushuses...
No, I think five is enough. If something's using sys_sysctl() then it might be using it a lot - there's no point in irritating people over it.
Quoted 24 lines · Andrew Morton
Quoted 12 lines · On Tue, 11 Jul 2006 00:57:35 -0600 [email protected] (Eric W. Biederman)…
Quoted 9 lines · Andrew Morton
Quoted 1 line · On Mon, 10 Jul 2006 16:38:59 -0600 [email protected] (Eric W. Biederman)…
Since
sys_sysctlis deprecated start allow it to be compiled out.This could be a tough one to get rid of (looks at
sys_bdflush()again).I'd suggest we put a sys_bdflush()-style warning in there, see what that flushes out.
Quoted 8 lines
Sounds sane. I know I have booted several kernels with it compiled out but just because you can do without it doesn't mean that something isn't using it.
Hmm. The question is where do I want the put the warning message?
When the code is compiled out?
When the code is compiled in?
Quoted 7 lines
Both. We want to find out who is using it.
Quoted 2 lines
Probably both places at this point, and using the rate limited printk I think instead of just the 5 printks that
sys_bdflushuses...No, I think five is enough. If something's using
sys_sysctl()then it might be using it a lot - there's no point in irritating people over it.
You are right, especially if that user is glibc. Here is my updated patch:
From: Eric W. Biederman <[email protected]>
Subject: [PATCH] sysctl: Scream if someone uses sys_sysctl
As far as I can tell we never use sys_sysctl so I never expect to see these messages. But if we do see these it means that there are user space applications that need to be fixed before we can safely remove sys_sysctl.
Limited to only 5 messages in case something like glibc is using sys_sysctl.
--- kernel/sysctl.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
kernel/sysctl.c +12 -0
@@ -1303,9 +1303,15 @@ int do_sysctl(int __user *name, int nlenasmlinkage long sys_sysctl (struct __sysctl_args __user *args) { +static int msg_count;struct __sysctl_args tmp;int error; +if (msg_count++ <5 ) +printk (KERN_INFO +"warning: process `%s' used the obsolete sysctl " +"system call\n" , current->comm); +if (copy_from_user (&tmp, args,sizeof (tmp)))return -EFAULT ;
@@ -2688,6 +2694,12 @@ #else /* CONFIG_SYSCTL_SYSCALL */asmlinkage long sys_sysctl (struct __sysctl_args __user *args) { +static int msg_count; + +if (msg_coutn++ <5 ) +printk (KERN_INFO +"warning: process `%s' used the removed sysctl " +"system call\n" , current->comm);return -ENOSYS ; }
Signature · 1 line
1.4.1.gac83a
Quoted 21 lines · On Tue, 11 Jul 2006 01:52:57 -0600 [email protected] (Eric W. Biederman)…
As far as I can tell we never use
sys_sysctlso I never expect to see these messages. But if we do see these it means that there are user space applications that need to be fixed before we can safely removesys_sysctl.Limited to only 5 messages in case something like glibc is using
sys_sysctl.Signed-off-by Eric W. Biederman <[email protected]>--- kernel/sysctl.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)kernel/sysctl.c +1
-0@@ -1303,9 +1303,15 @@ int do_sysctl(int __user *name, int nlenasmlinkage long sys_sysctl (struct __sysctl_args __user *args) { +static int msg_count;
kernel/sysctl.c int do_sysctl(int __user *name, int nlen · line 1316
Quoted 10 lines
kernel/sysctl.c +5
-0struct __sysctl_args tmp;int error; +if (msg_count++ <5 ) +printk (KERN_INFO +"warning: process `%s' used the obsolete sysctl " +"system call\n" , current->comm); +if (copy_from_user (&tmp, args,sizeof (tmp)))return -EFAULT ;
That'll print it five times per 4 billion calls ;)
kernel/sysctl.c #else /* CONFIG_SYSCTL_SYSCALL */ · line 2699
Quoted 7 lines
kernel/sysctl.c +3
-0@@ -2688,6 +2694,12 @@ #else /* CONFIG_SYSCTL_SYSCALL */asmlinkage long sys_sysctl (struct __sysctl_args __user *args) { +static int msg_count; + +if (msg_coutn++ <5 )
That'll have trouble compiling.
Go to bed, man. I'll fix it up.
PATCH 1/1 sysctl: Scream if someone uses sys_sysctl
In reply to Andrew MortonAs far as I can tell we never use sys_sysctl so I never expect to see these messages. But if we do see these it means that there are user space applications that need to be fixed before we can safely remove sys_sysctl.
---
Since this patch was trivial I just wipped up this incremental version. The code compiles is all I know.
kernel/sysctl.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
kernel/sysctl.c +9 -0
@@ -1306,6 +1306,11 @@ asmlinkage long sys_sysctl(struct __syscstruct __sysctl_args tmp;int error; +if (printk_ratelimit ()) +printk (KERN_INFO +"warning: process `%s' used the obsolete sysctl " +"system call\n" , current->comm); +if (copy_from_user (&tmp, args,sizeof (tmp)))return -EFAULT ;
@@ -2688,6 +2693,10 @@ #else /* CONFIG_SYSCTL_SYSCALL */asmlinkage long sys_sysctl (struct __sysctl_args __user *args) { +if (printk_ratelimit ()) +printk (KERN_INFO +"warning: process `%s' used the removed sysctl " +"system call\n" , current->comm);return -ENOSYS ; }
Signature · 1 line
1.4.1.gac83a
Quoted 2 lines · [email protected] (Eric W. Biederman) writes:
Since
sys_sysctlis deprecated start allow it to be compiled out. This should catch any remaining user space code that cares,
I tried this long ago, but found that glibc uses sysctl in each program to get the kernel version. It probably handles ENOSYS, but there might be slowdowns or subtle problems from it not knowing the kernel version.
So I think it's ok to remove the big sysctl, but at a very minimal replacement that just handles (CTL_KERN, KERN_VERSION) is needed.
Also it's useful to printk for the rest at least for some time so we know what uses it.
-Andi
Quoted 5 lines · Andi Kleen
Quoted 2 lines · [email protected] (Eric W. Biederman) writes:
Since
sys_sysctlis deprecated start allow it to be compiled out. This should catch any remaining user space code that cares,
Quoted 7 lines
I tried this long ago, but found that glibc uses sysctl in each program to get the kernel version. It probably handles ENOSYS, but there might be slowdowns or subtle problems from it not knowing the kernel version.
So I think it's ok to remove the big sysctl, but at a very minimal replacement that just handles (
CTL_KERN,KERN_VERSION) is needed.
If glibc is looking at kernel.osrelease it might make sense. If glibc is looking at kernel.version which is just the build number and date I can't imagine a correct usage.
If this usage is still common in glibc we can decide what to do when the warnings pop up.
Quoted 2 lines
Also it's useful to printk for the rest at least for some time so we know what uses it.
Yes. Andrew and I discussed that and when he picked up a patch. A printk was added to warn of people using the interface.
Eric
Quoted 10 lines · Eric W. Biederman
Quoted 9 lines · Andi Kleen
Quoted 2 lines · [email protected] (Eric W. Biederman) writes:
Since
sys_sysctlis deprecated start allow it to be compiled out. This should catch any remaining user space code that cares,I tried this long ago, but found that glibc uses sysctl in each program to get the kernel version. It probably handles ENOSYS, but there might be slowdowns or subtle problems from it not knowing the kernel version.
Quoted 6 lines
Quoted 2 lines
So I think it's ok to remove the big sysctl, but at a very minimal replacement that just handles (
CTL_KERN,KERN_VERSION) is needed.If glibc is looking at kernel.osrelease it might make sense. If glibc is looking at kernel.version which is just the build number and date I can't imagine a correct usage.
It's KERN_VERSION
Quoted 1 line
From my
/bin/ls:
_sysctl({{CTL_KERN, KERN_VERSION}, 2, 0xbfc8e1e0, 30, (nil), 0}) = 0
Quoted 2 lines
If this usage is still common in glibc we can decide what to do when the warnings pop up.
printk for everything would annoy basically everybody. Not a good idea.
-Andi
Quoted 18 lines · Andi Kleen
Quoted 10 lines · Eric W. Biederman
Quoted 9 lines · Andi Kleen
Quoted 2 lines · [email protected] (Eric W. Biederman) writes:
Since
sys_sysctlis deprecated start allow it to be compiled out. This should catch any remaining user space code that cares,I tried this long ago, but found that glibc uses sysctl in each program to get the kernel version. It probably handles ENOSYS, but there might be slowdowns or subtle problems from it not knowing the kernel version.
Quoted 6 lines
Quoted 2 lines
So I think it's ok to remove the big sysctl, but at a very minimal replacement that just handles (
CTL_KERN,KERN_VERSION) is needed.If glibc is looking at kernel.osrelease it might make sense. If glibc is looking at kernel.version which is just the build number and date I can't imagine a correct usage.
Quoted 5 lines
It's
KERN_VERSIONQuoted 1 line
From my
/bin/ls:
_sysctl({{CTL_KERN, KERN_VERSION}, 2, 0xbfc8e1e0, 30, (nil), 0})= 0
Yep. I found it.
In glibc (2.3.6, 2.4, and CVS) nptl/sysdeps/unix/sysv/linux/smp.h
Quoted 26 lines
/* Test whether the machine has more than one processor. This is not the
best test but good enough. More complicated tests would require `malloc' which is not available at that time. */
static inline intis_smp_system(void)
{
static const int sysctl_args[] = {CTL_KERN,KERN_VERSION}; char buf[512];
size_treslen = sizeof (buf);/* Try reading the number using `sysctl' first. */ if (
__sysctl((int *)sysctl_args,sizeof (sysctl_args) / sizeof (sysctl_args[0]), buf, &reslen, NULL, 0) < 0) { /* This was not successful. Now try reading the /proc filesystem. */ int fd = open_not_cancel_2 ("/proc/sys/kernel/version", O_RDONLY); if (__builtin_expect (fd, 0) == -1 || (reslen = read_not_cancel (fd, buf, sizeof (buf))) <= 0) /* This also didn't work. We give up and say it's a UP machine. */ buf[0] = '\0'; close_not_cancel_no_status (fd); }
Quoted 2 lines
return strstr (buf, "SMP") != NULL;
}
So it will correctly handle that sysctl being compiled out, and the fallback to using /proc. The code seems to have been doing that since it was added to glibc in 2000.
It only uses it to see if it should busy wait when taking a mutex.
If the kernel has SMP support is lousy predictor if it makes sense for glibc to busy wait. Darn optimizations for the contended case.
Quoted 4 lines
Quoted 2 lines
If this usage is still common in glibc we can decide what to do when the warnings pop up.
printk for everything would annoy basically everybody. Not a good idea.
Well everything isn't using pthreads. Why ls uses pthreads is beyond me.
Anyway it looks like it's time to send of a patch.
Eric
Quoted 4 lines
So it will correctly handle that sysctl being compiled out, and the fallback to using /proc. The code seems to have been doing that since it was added to glibc in 2000.
Using /proc is extremly slow for this. You added significant cost to each program startup.
I still think it's a good idea to simulate that sysctl and printk the others.
-Andi
Quoted 5 lines · Andi Kleen
Quoted 3 lines
So it will correctly handle that sysctl being compiled out, and the fallback to using /proc. The code seems to have been doing that since it was added to glibc in 2000.
Using /proc is extremly slow for this.
How so it is the same code in the kernel. Is open much slower than sys_sysctl?
Quoted 1 line
You added significant cost to each program startup.
Not each program only the ones that use pthreads.
Quoted 2 lines
I still think it's a good idea to simulate that sysctl and printk the others.
To reduce the noise something like that makes sense. I'm going to see if I can get glibc to use uname which should have the same effect.
Eric
Quoted 10 lines · Eric W. Biederman
Quoted 5 lines · Andi Kleen
Quoted 3 lines
So it will correctly handle that sysctl being compiled out, and the fallback to using /proc. The code seems to have been doing that since it was added to glibc in 2000.
Using /proc is extremly slow for this.
How so it is the same code in the kernel. Is open much slower than
sys_sysctl?
Yes, the VFS adds quite a lot of overhead with its zillions of locks and other complicated things.
I have also people complaining about /proc/cpuinfo overhead.
Quoted 4 lines
Quoted 2 lines
You added significant cost to each program startup.
Not each program only the ones that use pthreads.
In modern glibc it's basically everything
Quoted 5 lines
Quoted 2 lines
I still think it's a good idea to simulate that sysctl and printk the others.
To reduce the noise something like that makes sense. I'm going to see if I can get glibc to use uname which should have the same effect.
And still printk for all old binaries? Not a good idea.
You have to check for this case in the printk stub anyways and if you check for it you can as well emulate it
(with a big fat comment that this won't be done for any other sysctl)
-Andi
Quoted 9 lines · Andi Kleen
Quoted 8 lines · Eric W. Biederman
Quoted 5 lines · Andi Kleen
Quoted 3 lines
So it will correctly handle that sysctl being compiled out, and the fallback to using /proc. The code seems to have been doing that since it was added to glibc in 2000.
Using /proc is extremly slow for this.
Quoted 7 lines
Quoted 2 lines
How so it is the same code in the kernel. Is open much slower than
sys_sysctl?Yes, the VFS adds quite a lot of overhead with its zillions of locks and other complicated things.
I have also people complaining about
/proc/cpuinfooverhead.
Yes. I just confirmed that /proc/sys access is about an order of magnitude slower. I goofed and forgot to add you to the cc list but I just sent a patch to Ulrich to switch glibc to using uname for this case. uname is even faster than sysctl.
I am very curious to understand where the overhead is coming from. It may just be the VFS or it may be stupidities in the /proc implementation. If things are really as bad as they appear it puts a serious damper on the plan9 style everything is a filesystem approach.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
You added significant cost to each program startup.
Not each program only the ones that use pthreads.
In modern glibc it's basically everything
It shouldn't be. You can support be thread safe without pulling
in glibc. But yes it is common.
Quoted 11 lines
Quoted 5 lines
Quoted 2 lines
I still think it's a good idea to simulate that sysctl and printk the others.
To reduce the noise something like that makes sense. I'm going to see if I can get glibc to use uname which should have the same effect.
And still printk for all old binaries? Not a good idea.
You have to check for this case in the printk stub anyways and if you check for it you can as well emulate it
(with a big fat comment that this won't be done for any other sysctl)
I will see how it goes.
Eric
What is the motivation behind killing the sys_sysctl call anyway? Sure its more ugly esthetically but it works.
Is it because of the desire to virtualize all namespaces?
Quoted 2 lines · Stephen Hemminger
What is the motivation behind killing the
sys_sysctlcall anyway? Sure its more ugly esthetically but it works.
it "works" but the thing is that the number space is NOT stable, and as such it's a really bad ABI
Quoted 6 lines · Arjan van de Ven
Quoted 2 lines · Stephen Hemminger
What is the motivation behind killing the
sys_sysctlcall anyway? Sure its more ugly esthetically but it works.it "works" but the thing is that the number space is NOT stable, and as such it's a really bad ABI
To be fair, the older, "base" numbers are actually stable, such as what glibc is depending on, have in practice been quite stable. It's only the newer fields that tend to be unstable.
But that means we can afford to do an orderly migration away from it; it's not something that has to be urgently done within a few weeks or even a few months.
- Ted
Quoted 7 lines · Theodore Tso
Quoted 5 lines · Arjan van de Ven
Quoted 2 lines · Stephen Hemminger
What is the motivation behind killing the
sys_sysctlcall anyway? Sure its more ugly esthetically but it works.it "works" but the thing is that the number space is NOT stable, and as such it's a really bad ABI
Quoted 8 lines
To be fair, the older, "base" numbers are actually stable, such as what glibc is depending on, have in practice been quite stable. It's only the newer fields that tend to be unstable.
But that means we can afford to do an orderly migration away from it; it's not something that has to be urgently done within a few weeks or even a few months.
Another alternative would be to publish a limited set of sysctl numbers that will be maintained forever.
-hpa