Kill the bkl in procfs
Subsystems (10)
cover Kill the bkl in procfs
Hi,
This patchset drops any use of the big kernel lock from procfs. May be there is still one or two NULL llseek somewhere but I think we have fixed 99% of those that were in the procfs core.
Users of procfs implementing an ioctl have not been easy to spot automatically (there are hundreds of procfs users) as there are many indirect ways to register a procfs, depending on the subsystem you are.
So for those who want to verify the reliability of this check, you can look at the script there:
http://tglx.de/~fweisbec/seek.py
Beware it's very dirty! The hardcoded path are those I had to check manually (or that I added to the automatic check). One day I should learn how to use Coccinelle instead.
In the worst case, the remaining ones this script or my eyes forgot will trigger a warning.
Thanks.
Arnd Bergmann (1):
procfs: Kill BKL in llseek on proc base
Frederic Weisbecker (5):
procfs: Use generic_file_llseek in /proc/kcore
procfs: Use generic_file_llseek in /proc/kmsg
procfs: Use generic_file_llseek in /proc/vmcore
procfs: Push down the bkl from ioctl
procfs: Kill the bkl in ioctl
drivers/char/i8k.c | 53 +++++++++++++++------ drivers/isdn/divert/divert_procfs.c | 90 ++++++++++++++++++++++------------- fs/proc/base.c | 10 ++++- fs/proc/inode.c | 4 +- fs/proc/kcore.c | 1 + fs/proc/kmsg.c | 1 + fs/proc/vmcore.c | 1 + net/sunrpc/cache.c | 20 ++++++-- 8 files changed, 123 insertions(+), 57 deletions(-)
PATCH 1/6 procfs: Kill BKL in llseek on proc base
From: Arnd Bergmann <[email protected]>
We don't use the BKL elsewhere, so use generic_file_llseek so we can avoid default_llseek taking the BKL.
--- fs/proc/base.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
fs/proc/base.c +9 -1
@@ -728,6 +728,7 @@ out_no_task:static const struct file_operations proc_info_file_operations = { .read = proc_info_read, + .llseek = generic_file_llseek, };static int proc_single_show (struct seq_file *m,void *v)
@@ -985,6 +986,7 @@ out_no_task:static const struct file_operations proc_environ_operations = { .read = environ_read, + .llseek = generic_file_llseek, }; static ssize_t oom_adjust_read(struct file *file, char __user *buf,
@@ -1058,6 +1060,7 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,static const struct file_operations proc_oom_adjust_operations = { .read = oom_adjust_read, .write = oom_adjust_write, + .llseek = generic_file_llseek, };#ifdef CONFIG_AUDITSYSCALL
@@ -1129,6 +1132,7 @@ out_free_page:static const struct file_operations proc_loginuid_operations = { .read = proc_loginuid_read, .write = proc_loginuid_write, + .llseek = generic_file_llseek, }; static ssize_t proc_sessionid_read(struct file * file, char __user * buf,
@@ -1149,6 +1153,7 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf,static const struct file_operations proc_sessionid_operations = { .read = proc_sessionid_read, + .llseek = generic_file_llseek, };#endif
@@ -1200,6 +1205,7 @@ static ssize_t proc_fault_inject_write(struct file * file,static const struct file_operations proc_fault_inject_operations = { .read = proc_fault_inject_read, .write = proc_fault_inject_write, + .llseek = generic_file_llseek, };#endif
@@ -1941,7 +1947,7 @@ static ssize_t proc_fdinfo_read(struct file *file, char __user *buf, }static const struct file_operations proc_fdinfo_file_operations = { - .open = nonseekable_open, + .open = nonseekable_open, .read = proc_fdinfo_read, };
@@ -2225,6 +2231,7 @@ out_no_task:static const struct file_operations proc_pid_attr_operations = { .read = proc_pid_attr_read, .write = proc_pid_attr_write, + .llseek = generic_file_llseek, };static const struct pid_entry attr_dir_stuff[] = {
@@ -2345,6 +2352,7 @@ static ssize_t proc_coredump_filter_write(struct file *file,static const struct file_operations proc_coredump_filter_operations = { .read = proc_coredump_filter_read, .write = proc_coredump_filter_write, + .llseek = generic_file_llseek, };#endif
Signature · 1 line
1.6.2.3
Re: [PATCH 1/6] procfs: Kill BKL in llseek on proc base
fs/proc/base.c out_no_task: · line 731
Quoted 7 lines · Frederic Weisbecker
fs/proc/base.c +1
-0@@ -728,6 +728,7 @@ out_no_task: static const struct file_operations proc_info_file_operations = { .read = proc_info_read, + .llseek = generic_file_llseek,
There is no warning for default default_llseek case. This should be done same way as proc ioctls.
Re: [PATCH 1/6] procfs: Kill BKL in llseek on proc base
Quoted 11 lines · Alexey Dobriyan
fs/proc/base.c out_no_task: · line 731
Quoted 7 lines · Frederic Weisbecker
fs/proc/base.c +1
-0@@ -728,6 +728,7 @@ out_no_task: static const struct file_operations proc_info_file_operations = { .read = proc_info_read, + .llseek = generic_file_llseek,There is no warning for default
default_llseekcase. This should be done same way as proc ioctls.
I don't think we should. We have overriden the llseek for the procfs users located in the proc core (just fs/proc) but we haven't touched all of the external users, and since there are hundreds of them, I guess a lot don't implement llseek.
We would need to first override those that are visible upstream and warn for the further ones after this step only.
PATCH 2/6 procfs: Use generic_file_llseek in /proc/kcore
In reply to Frederic Weisbecker/proc/kcore has no llseek and then falls down to use default_llseek. This is racy against read_kcore() that directly manipulates fpos but it doesn't hold the bkl there so using it in llseek doesn't protect anything.
Let's use generic_file_llseek() instead.
--- fs/proc/kcore.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/proc/kcore.c +1 -0
@@ -557,6 +557,7 @@ static int open_kcore(struct inode *inode, struct file *filp)static const struct file_operations proc_kcore_operations = { .read = read_kcore, .open = open_kcore, + .llseek = generic_file_llseek, };#ifdef CONFIG_MEMORY_HOTPLUG
Signature · 1 line
1.6.2.3
Re: [PATCH 2/6] procfs: Use generic_file_llseek in /proc/kcore
Quoted 4 lines · Frederic Weisbecker
/proc/kcorehas no llseek and then falls down to usedefault_llseek. This is racy againstread_kcore()that directly manipulates fpos but it doesn't hold the bkl there so using it in llseek doesn't protect anything.
PATCH 3/6 procfs: Use generic_file_llseek in /proc/kmsg
In reply to Frederic WeisbeckerNo need to hold the bkl to seek here, none of the other fops callbacks use it.
Use generic_file_llseek explicitly.
--- fs/proc/kmsg.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/proc/kmsg.c +1 -0
@@ -53,6 +53,7 @@ static const struct file_operations proc_kmsg_operations = { .poll = kmsg_poll, .open = kmsg_open, .release = kmsg_release, + .llseek = generic_file_llseek, };static int __init proc_kmsg_init (void )
Signature · 1 line
1.6.2.3
Re: [PATCH 3/6] procfs: Use generic_file_llseek in /proc/kmsg
Quoted 5 lines · Frederic Weisbecker
No need to hold the bkl to seek here, none of the other fops callbacks use it.
Use
generic_file_llseekexplicitly.
PATCH 4/6 procfs: Use generic_file_llseek in /proc/vmcore
In reply to Frederic Weisbecker/proc/vmcore has no llseek and then falls down to use default_llseek. This is racy against read_vmcore() that directly manipulates fpos but it doesn't hold the bkl there so using it in llseek doesn't protect anything.
Let's use generic_file_llseek() instead.
--- fs/proc/vmcore.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/proc/vmcore.c +1 -0
@@ -162,6 +162,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,static const struct file_operations proc_vmcore_operations = { .read = read_vmcore, + .lseek = generic_file_llseek, };static struct vmcore *__init get_new_element (void )
Signature · 1 line
1.6.2.3
Re: [PATCH 4/6] procfs: Use generic_file_llseek in /proc/vmcore
Quoted 7 lines · Frederic Weisbecker
/proc/vmcorehas no llseek and then falls down to usedefault_llseek. This is racy againstread_vmcore()that directly manipulates fpos but it doesn't hold the bkl there so using it in llseek doesn't protect anything.Let's use
generic_file_llseek()instead.
PATCH 5/6 procfs: Push down the bkl from ioctl
In reply to Frederic WeisbeckerPush down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into unlocked_ioctl and push down the Devil inside.
--- drivers/char/i8k.c | 53 +++++++++++++++------ drivers/isdn/divert/divert_procfs.c | 90 ++++++++++++++++++++++------------- net/sunrpc/cache.c | 20 ++++++-- 3 files changed, 109 insertions(+), 54 deletions(-)
drivers/char/i8k.c +38 -15
@@ -23,6 +23,7 @@#include <linux/seq_file.h> #include <linux/dmi.h> #include <linux/capability.h> +#include <linux/smp_lock.h> #include <asm/uaccess.h> #include <asm/io.h>
@@ -82,8 +83,7 @@ module_param(fan_mult, int, 0);MODULE_PARM_DESC (fan_mult,"Factor to multiply fan speed with" );static int i8k_open_fs (struct inode *inode,struct file *file); -static int i8k_ioctl (struct inode *,struct file *,unsigned int , -unsigned long ); +static long i8k_ioctl (struct file *,unsigned int ,unsigned long );static const struct file_operations i8k_fops = { .owner =THIS_MODULE ,
@@ -91,7 +91,7 @@ static const struct file_operations i8k_fops = { .read = seq_read, .llseek = seq_lseek, .release = single_release, - .ioctl = i8k_ioctl, + .unlocked_ioctl = i8k_ioctl, };struct smm_regs {
@@ -307,8 +307,7 @@ static int i8k_get_dell_signature(int req_fn)return regs.eax ==1145651527 && regs.edx ==1145392204 ?0 :-1 ; } -static int i8k_ioctl (struct inode *ip,struct file *fp,unsigned int cmd, -unsigned long arg) +static long i8k_ioctl (struct file *fp,unsigned int cmd,unsigned long arg) {int val =0 ;int speed;
@@ -318,6 +317,9 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,if (!argp)return -EINVAL ; +/* Pushed down from procfs ioctl handler */ +lock_kernel (); +switch (cmd) {case I8K_BIOS_VERSION : val =i8k_get_bios_version ();
@@ -341,57 +343,78 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,break ;case I8K_GET_SPEED : -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_get_fan_speed (val);break ;case I8K_GET_FAN : -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_get_fan_status (val);break ;case I8K_SET_FAN : -if (restricted && !capable (CAP_SYS_ADMIN )) +if (restricted && !capable (CAP_SYS_ADMIN )) { +unlock_kernel ();return -EPERM ; + } -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } -if (copy_from_user (&speed, argp +1 ,sizeof (int ))) +if (copy_from_user (&speed, argp +1 ,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_set_fan (val, speed);break ;default : +unlock_kernel ();return -EINVAL ; } -if (val <0 ) -return val; +if (val <0 ) { +unlock_kernel (); +return -val; + }switch (cmd) {case I8K_BIOS_VERSION : -if (copy_to_user (argp, &val,4 )) +if (copy_to_user (argp, &val,4 )) { +unlock_kernel ();return -EFAULT ; + }break ;case I8K_MACHINE_ID : -if (copy_to_user (argp, buff,16 )) +if (copy_to_user (argp, buff,16 )) { +unlock_kernel ();return -EFAULT ; + }break ;default : -if (copy_to_user (argp, &val,sizeof (int ))) +if (copy_to_user (argp, &val,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + }break ; } +unlock_kernel (); +return 0 ; }
drivers/isdn/divert/divert_procfs.c +56 -34
152 lines not on this page · raw message
net/sunrpc/cache.c +15 -5
@@ -1331,12 +1331,22 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)return cache_poll (filp, wait, cd); } -static int cache_ioctl_procfs (struct inode *inode,struct file *filp, -unsigned int cmd,unsigned long arg) +static long cache_ioctl_procfs (struct file *filp, +unsigned int cmd,unsigned long arg) { -struct cache_detail *cd =PDE (inode)->data; +long ret; +struct cache_detail *cd; +struct inode *inode = filp->f_path.dentry->d_inode; -return cache_ioctl (inode, filp, cmd, arg, cd); +/* Pushed down from procfs ioctl handler */ +lock_kernel (); + + cd =PDE (inode)->data; + ret =cache_ioctl (inode, filp, cmd, arg, cd); + +unlock_kernel (); + +return ret; }static int cache_open_procfs (struct inode *inode,struct file *filp)
@@ -1359,7 +1369,7 @@ static const struct file_operations cache_file_operations_procfs = { .read = cache_read_procfs, .write = cache_write_procfs, .poll = cache_poll_procfs, - .ioctl = cache_ioctl_procfs, /* for FIONREAD */ + .unlocked_ioctl = cache_ioctl_procfs, /* for FIONREAD */ .open = cache_open_procfs, .release = cache_release_procfs, };
Signature · 1 line
1.6.2.3
Re: [PATCH 5/6] procfs: Push down the bkl from ioctl
Quoted 11 lines · Frederic Weisbecker
net/sunrpc/cache.c +2
-2@@ -1331,12 +1331,22 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait) return cache_poll(filp, wait, cd); } -static int cache_ioctl_procfs (struct inode *inode,struct file *filp, - unsigned int cmd, unsigned long arg) +static long cache_ioctl_procfs (struct file *filp, + unsigned int cmd, unsigned long arg) {
net/sunrpc/cache.c static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait) · line 1344
Quoted 10 lines
net/sunrpc/cache.c +7
-2- struct cache_detail *cd = PDE(inode)->data; + long ret; + struct cache_detail *cd; + struct inode *inode = filp->f_path.dentry->d_inode; - return cache_ioctl(inode, filp, cmd, arg, cd); + /* Pushed down from procfs ioctl handler */ + lock_kernel(); + + cd = PDE(inode)->data;
->data is not under BKL at all.
Quoted 1 line
net/sunrpc/cache.c +1
-0+ ret = cache_ioctl(inode, filp, cmd, arg, cd);
Re: [PATCH 5/6] procfs: Push down the bkl from ioctl
Quoted 18 lines · Alexey Dobriyan
Quoted 16 lines · Frederic Weisbecker
net/sunrpc/cache.c +5
-3@@ -1331,12 +1331,22 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait) return cache_poll(filp, wait, cd); } -static int cache_ioctl_procfs (struct inode *inode,struct file *filp, - unsigned int cmd, unsigned long arg) +static long cache_ioctl_procfs (struct file *filp, + unsigned int cmd, unsigned long arg) { - struct cache_detail *cd = PDE(inode)->data; + long ret; + struct cache_detail *cd; + struct inode *inode = filp->f_path.dentry->d_inode;
Quoted 7 lines
net/sunrpc/cache.c static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait) · line 1344
Quoted 5 lines
net/sunrpc/cache.c +4
-1- return cache_ioctl(inode, filp, cmd, arg, cd); + /* Pushed down from procfs ioctl handler */ + lock_kernel(); + + cd = PDE(inode)->data;->data is not under BKL at all.
Yeah. It's a very rough pushdown, I haven't looked at any bit to figure out what could need to be protected or not. I even did not know what does PDE. So I kept a plain bkl path. I just thought any further thinking should be done in a further patch.
But I can move the bkl after in this same patch if you prefer.
Thanks.
PATCH v2 1/1 procfs: Push down the bkl from ioctl
In reply to Alexey DobriyanPush down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into unlocked_ioctl and push down the Devil inside.
v2: PDE(inode)->data doesn't need to be under bkl
--- drivers/char/i8k.c | 53 +++++++++++++++------ drivers/isdn/divert/divert_procfs.c | 90 ++++++++++++++++++++++------------- net/sunrpc/cache.c | 20 ++++++-- 3 files changed, 109 insertions(+), 54 deletions(-)
drivers/char/i8k.c +38 -15
@@ -23,6 +23,7 @@#include <linux/seq_file.h> #include <linux/dmi.h> #include <linux/capability.h> +#include <linux/smp_lock.h> #include <asm/uaccess.h> #include <asm/io.h>
@@ -82,8 +83,7 @@ module_param(fan_mult, int, 0);MODULE_PARM_DESC (fan_mult,"Factor to multiply fan speed with" );static int i8k_open_fs (struct inode *inode,struct file *file); -static int i8k_ioctl (struct inode *,struct file *,unsigned int , -unsigned long ); +static long i8k_ioctl (struct file *,unsigned int ,unsigned long );static const struct file_operations i8k_fops = { .owner =THIS_MODULE ,
@@ -91,7 +91,7 @@ static const struct file_operations i8k_fops = { .read = seq_read, .llseek = seq_lseek, .release = single_release, - .ioctl = i8k_ioctl, + .unlocked_ioctl = i8k_ioctl, };struct smm_regs {
@@ -307,8 +307,7 @@ static int i8k_get_dell_signature(int req_fn)return regs.eax ==1145651527 && regs.edx ==1145392204 ?0 :-1 ; } -static int i8k_ioctl (struct inode *ip,struct file *fp,unsigned int cmd, -unsigned long arg) +static long i8k_ioctl (struct file *fp,unsigned int cmd,unsigned long arg) {int val =0 ;int speed;
@@ -318,6 +317,9 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,if (!argp)return -EINVAL ; +/* Pushed down from procfs ioctl handler */ +lock_kernel (); +switch (cmd) {case I8K_BIOS_VERSION : val =i8k_get_bios_version ();
@@ -341,57 +343,78 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,break ;case I8K_GET_SPEED : -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_get_fan_speed (val);break ;case I8K_GET_FAN : -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_get_fan_status (val);break ;case I8K_SET_FAN : -if (restricted && !capable (CAP_SYS_ADMIN )) +if (restricted && !capable (CAP_SYS_ADMIN )) { +unlock_kernel ();return -EPERM ; + } -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } -if (copy_from_user (&speed, argp +1 ,sizeof (int ))) +if (copy_from_user (&speed, argp +1 ,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_set_fan (val, speed);break ;default : +unlock_kernel ();return -EINVAL ; } -if (val <0 ) -return val; +if (val <0 ) { +unlock_kernel (); +return -val; + }switch (cmd) {case I8K_BIOS_VERSION : -if (copy_to_user (argp, &val,4 )) +if (copy_to_user (argp, &val,4 )) { +unlock_kernel ();return -EFAULT ; + }break ;case I8K_MACHINE_ID : -if (copy_to_user (argp, buff,16 )) +if (copy_to_user (argp, buff,16 )) { +unlock_kernel ();return -EFAULT ; + }break ;default : -if (copy_to_user (argp, &val,sizeof (int ))) +if (copy_to_user (argp, &val,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + }break ; } +unlock_kernel (); +return 0 ; }
drivers/isdn/divert/divert_procfs.c +56 -34
152 lines not on this page · raw message
net/sunrpc/cache.c +15 -5
@@ -1331,12 +1331,22 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)return cache_poll (filp, wait, cd); } -static int cache_ioctl_procfs (struct inode *inode,struct file *filp, -unsigned int cmd,unsigned long arg) +static long cache_ioctl_procfs (struct file *filp, +unsigned int cmd,unsigned long arg) { -struct cache_detail *cd =PDE (inode)->data; +long ret; +struct cache_detail *cd; +struct inode *inode = filp->f_path.dentry->d_inode; -return cache_ioctl (inode, filp, cmd, arg, cd); +/* Pushed down from procfs ioctl handler */ +lock_kernel (); + + cd =PDE (inode)->data; + ret =cache_ioctl (inode, filp, cmd, arg, cd); + +unlock_kernel (); + +return ret; }static int cache_open_procfs (struct inode *inode,struct file *filp)
@@ -1359,7 +1369,7 @@ static const struct file_operations cache_file_operations_procfs = { .read = cache_read_procfs, .write = cache_write_procfs, .poll = cache_poll_procfs, - .ioctl = cache_ioctl_procfs, /* for FIONREAD */ + .unlocked_ioctl = cache_ioctl_procfs, /* for FIONREAD */ .open = cache_open_procfs, .release = cache_release_procfs, };
Signature · 1 line
1.6.2.3
PATCH v3 1/1 procfs: Push down the bkl from ioctl
Push down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into unlocked_ioctl and push down the Devil inside.
v2: PDE(inode)->data doesn't need to be under bkl
v3: And don't forget to git-add the result
--- drivers/char/i8k.c | 53 +++++++++++++++------ drivers/isdn/divert/divert_procfs.c | 90 ++++++++++++++++++++++------------- net/sunrpc/cache.c | 17 +++++-- 3 files changed, 107 insertions(+), 53 deletions(-)
drivers/char/i8k.c +38 -15
@@ -23,6 +23,7 @@#include <linux/seq_file.h> #include <linux/dmi.h> #include <linux/capability.h> +#include <linux/smp_lock.h> #include <asm/uaccess.h> #include <asm/io.h>
@@ -82,8 +83,7 @@ module_param(fan_mult, int, 0);MODULE_PARM_DESC (fan_mult,"Factor to multiply fan speed with" );static int i8k_open_fs (struct inode *inode,struct file *file); -static int i8k_ioctl (struct inode *,struct file *,unsigned int , -unsigned long ); +static long i8k_ioctl (struct file *,unsigned int ,unsigned long );static const struct file_operations i8k_fops = { .owner =THIS_MODULE ,
@@ -91,7 +91,7 @@ static const struct file_operations i8k_fops = { .read = seq_read, .llseek = seq_lseek, .release = single_release, - .ioctl = i8k_ioctl, + .unlocked_ioctl = i8k_ioctl, };struct smm_regs {
@@ -307,8 +307,7 @@ static int i8k_get_dell_signature(int req_fn)return regs.eax ==1145651527 && regs.edx ==1145392204 ?0 :-1 ; } -static int i8k_ioctl (struct inode *ip,struct file *fp,unsigned int cmd, -unsigned long arg) +static long i8k_ioctl (struct file *fp,unsigned int cmd,unsigned long arg) {int val =0 ;int speed;
@@ -318,6 +317,9 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,if (!argp)return -EINVAL ; +/* Pushed down from procfs ioctl handler */ +lock_kernel (); +switch (cmd) {case I8K_BIOS_VERSION : val =i8k_get_bios_version ();
@@ -341,57 +343,78 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,break ;case I8K_GET_SPEED : -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_get_fan_speed (val);break ;case I8K_GET_FAN : -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_get_fan_status (val);break ;case I8K_SET_FAN : -if (restricted && !capable (CAP_SYS_ADMIN )) +if (restricted && !capable (CAP_SYS_ADMIN )) { +unlock_kernel ();return -EPERM ; + } -if (copy_from_user (&val, argp,sizeof (int ))) +if (copy_from_user (&val, argp,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } -if (copy_from_user (&speed, argp +1 ,sizeof (int ))) +if (copy_from_user (&speed, argp +1 ,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + } val =i8k_set_fan (val, speed);break ;default : +unlock_kernel ();return -EINVAL ; } -if (val <0 ) -return val; +if (val <0 ) { +unlock_kernel (); +return -val; + }switch (cmd) {case I8K_BIOS_VERSION : -if (copy_to_user (argp, &val,4 )) +if (copy_to_user (argp, &val,4 )) { +unlock_kernel ();return -EFAULT ; + }break ;case I8K_MACHINE_ID : -if (copy_to_user (argp, buff,16 )) +if (copy_to_user (argp, buff,16 )) { +unlock_kernel ();return -EFAULT ; + }break ;default : -if (copy_to_user (argp, &val,sizeof (int ))) +if (copy_to_user (argp, &val,sizeof (int ))) { +unlock_kernel ();return -EFAULT ; + }break ; } +unlock_kernel (); +return 0 ; }
drivers/isdn/divert/divert_procfs.c +56 -34
152 lines not on this page · raw message
net/sunrpc/cache.c +13 -4
@@ -1331,12 +1331,21 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)return cache_poll (filp, wait, cd); } -static int cache_ioctl_procfs (struct inode *inode,struct file *filp, -unsigned int cmd,unsigned long arg) +static long cache_ioctl_procfs (struct file *filp, +unsigned int cmd,unsigned long arg) { +long ret; +struct inode *inode = filp->f_path.dentry->d_inode;struct cache_detail *cd =PDE (inode)->data; -return cache_ioctl (inode, filp, cmd, arg, cd); +/* Pushed down from procfs ioctl handler */ +lock_kernel (); + + ret =cache_ioctl (inode, filp, cmd, arg, cd); + +unlock_kernel (); + +return ret; }static int cache_open_procfs (struct inode *inode,struct file *filp)
@@ -1359,7 +1368,7 @@ static const struct file_operations cache_file_operations_procfs = { .read = cache_read_procfs, .write = cache_write_procfs, .poll = cache_poll_procfs, - .ioctl = cache_ioctl_procfs, /* for FIONREAD */ + .unlocked_ioctl = cache_ioctl_procfs, /* for FIONREAD */ .open = cache_open_procfs, .release = cache_release_procfs, };
Signature · 1 line
1.6.2.3
PATCH v4 1/1 procfs: Push down the bkl from ioctl
I have updated this patch because the direct pushdown into the handler was rather invasive and error prone.
Instead I've used wrappers.
Arnd I've kept your ack, hope it's still fine for you.
Thanks.
---
Quoted 1 line
From
d79b6f4de5db0103ceb4734e42ad101d836d61d9Mon Sep 17 00:00:00 2001
From: Frederic Weisbecker <[email protected]>
Date: Tue, 30 Mar 2010 07:27:50 +0200
Subject: [PATCH v4] procfs: Push down the bkl from ioctl
Push down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into unlocked_ioctl and push down the Devil inside.
v2: PDE(inode)->data doesn't need to be under bkl
v3: And don't forget to git-add the result
v4: Use wrappers to pushdown instead of an invasive and error prone
handlers surgery.
--- drivers/char/i8k.c | 21 ++++++++++++++++----- drivers/isdn/divert/divert_procfs.c | 18 ++++++++++++++---- net/sunrpc/cache.c | 14 ++++++++++---- 3 files changed, 40 insertions(+), 13 deletions(-)
drivers/char/i8k.c +16 -5
@@ -23,6 +23,7 @@#include <linux/seq_file.h> #include <linux/dmi.h> #include <linux/capability.h> +#include <linux/smp_lock.h> #include <asm/uaccess.h> #include <asm/io.h>
@@ -82,8 +83,7 @@ module_param(fan_mult, int, 0);MODULE_PARM_DESC (fan_mult,"Factor to multiply fan speed with" );static int i8k_open_fs (struct inode *inode,struct file *file); -static int i8k_ioctl (struct inode *,struct file *,unsigned int , -unsigned long ); +static long i8k_ioctl (struct file *,unsigned int ,unsigned long );static const struct file_operations i8k_fops = { .owner =THIS_MODULE ,
@@ -91,7 +91,7 @@ static const struct file_operations i8k_fops = { .read = seq_read, .llseek = seq_lseek, .release = single_release, - .ioctl = i8k_ioctl, + .unlocked_ioctl = i8k_ioctl, };struct smm_regs {
@@ -307,8 +307,8 @@ static int i8k_get_dell_signature(int req_fn)return regs.eax ==1145651527 && regs.edx ==1145392204 ?0 :-1 ; } -static int i8k_ioctl (struct inode *ip,struct file *fp,unsigned int cmd, -unsigned long arg) +static int +i8k_ioctl_unlocked (struct file *fp,unsigned int cmd,unsigned long arg) {int val =0 ;int speed;
@@ -395,6 +395,17 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,return 0 ; } +static long i8k_ioctl (struct file *fp,unsigned int cmd,unsigned long arg) +{ +long ret; + +lock_kernel (); + ret =i8k_ioctl_unlocked (fp, cmd, arg); +unlock_kernel (); + +return ret; +} +/* * Print the information for /proc/i8k. */
drivers/isdn/divert/divert_procfs.c +14 -4
@@ -19,6 +19,7 @@#include <linux/sched.h> #include <linux/isdnif.h> #include <net/net_namespace.h> +#include <linux/smp_lock.h> #include "isdn_divert.h"
@@ -176,9 +177,7 @@ isdn_divert_close(struct inode *ino, struct file *filep)/*********/ /* IOCTL */ /*********/ -static int -isdn_divert_ioctl (struct inode *inode,struct file *file, -uint cmd,ulong arg) +static int isdn_divert_ioctl_unlocked (struct file *file,uint cmd,ulong arg) {divert_ioctl dioctl;int i;
@@ -257,6 +256,17 @@ isdn_divert_ioctl(struct inode *inode, struct file *file,return copy_to_user ((void __user *)arg, &dioctl,sizeof (dioctl)) ? -EFAULT :0 ; }/* isdn_divert_ioctl */ +static long isdn_divert_ioctl (struct file *file,uint cmd,ulong arg) +{ +long ret; + +lock_kernel (); + ret =isdn_divert_ioctl_unlocked (file, cmd, arg); +unlock_kernel (); + +return ret; +} +static const struct file_operations isdn_fops = { .owner =THIS_MODULE ,
@@ -264,7 +274,7 @@ static const struct file_operations isdn_fops = .read = isdn_divert_read, .write = isdn_divert_write, .poll = isdn_divert_poll, - .ioctl = isdn_divert_ioctl, + .unlocked_ioctl = isdn_divert_ioctl, .open = isdn_divert_open, .release = isdn_divert_close, };
net/sunrpc/cache.c +10 -4
@@ -1331,12 +1331,18 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)return cache_poll (filp, wait, cd); } -static int cache_ioctl_procfs (struct inode *inode,struct file *filp, -unsigned int cmd,unsigned long arg) +static long cache_ioctl_procfs (struct file *filp, +unsigned int cmd,unsigned long arg) { +long ret; +struct inode *inode = filp->f_path.dentry->d_inode;struct cache_detail *cd =PDE (inode)->data; -return cache_ioctl (inode, filp, cmd, arg, cd); +lock_kernel (); + ret =cache_ioctl (inode, filp, cmd, arg, cd); +unlock_kernel (); + +return ret; }static int cache_open_procfs (struct inode *inode,struct file *filp)
@@ -1359,7 +1365,7 @@ static const struct file_operations cache_file_operations_procfs = { .read = cache_read_procfs, .write = cache_write_procfs, .poll = cache_poll_procfs, - .ioctl = cache_ioctl_procfs, /* for FIONREAD */ + .unlocked_ioctl = cache_ioctl_procfs, /* for FIONREAD */ .open = cache_open_procfs, .release = cache_release_procfs, };
Signature · 1 line
1.6.2.3
Re: [PATCH 5/6] procfs: Push down the bkl from ioctl
In reply to Frederic WeisbeckerQuoted 3 lines · Frederic Weisbecker
Push down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into
unlocked_ioctland push down the Devil inside.
Looks good to me. I would have used a single unlock and return statement in i8k_ioctl and isdn_divert_ioctl, with goto instead of adding an unlock to each return, but it doesn't matter much.
Re: [PATCH 5/6] procfs: Push down the bkl from ioctl
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Frederic Weisbecker
Push down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into
unlocked_ioctland push down the Devil inside.Looks good to me. I would have used a single unlock and return statement in
i8k_ioctlandisdn_divert_ioctl, with goto instead of adding an unlock to each return, but it doesn't matter much.
I did that first, but actually that didn't make much difference:
ret = foo; unlock_kernel()
goto end; VS return foo;
Quoted 2 lines
Acked-by Arnd Bergmann <[email protected]>
Thanks.
Arnd Bergmann
maintainerRe: [PATCH 5/6] procfs: Push down the bkl from ioctl
Quoted 11 lines · On Tuesday 30 March 2010 20:27:12 Frederic Weisbecker wrote:
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Frederic Weisbecker
Push down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into
unlocked_ioctland push down the Devil inside.Looks good to me. I would have used a single unlock and return statement in
i8k_ioctlandisdn_divert_ioctl, with goto instead of adding an unlock to each return, but it doesn't matter much.
Quoted 4 lines
I did that first, but actually that didn't make much difference:
ret = foo;
unlock_kernel()
goto end; VS return foo;
Yes, the amount of code needed is comparable, but it is much easier to validate that you did not miss an unlock when you know that there is a single return statement in the function. It also helps the next person that may want to replace the BKL with a different lock.
Arnd
Re: [PATCH 5/6] procfs: Push down the bkl from ioctl
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · On Tuesday 30 March 2010 20:27:12 Frederic Weisbecker wrote:
Quoted 8 lines · Arnd Bergmann
Quoted 3 lines · Frederic Weisbecker
Push down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into
unlocked_ioctland push down the Devil inside.Looks good to me. I would have used a single unlock and return statement in
i8k_ioctlandisdn_divert_ioctl, with goto instead of adding an unlock to each return, but it doesn't matter much.I did that first, but actually that didn't make much difference:
Quoted 7 lines
Quoted 2 lines
ret = foo;
unlock_kernel()
goto end; VS return foo;Yes, the amount of code needed is comparable, but it is much easier to validate that you did not miss an unlock when you know that there is a single return statement in the function. It also helps the next person that may want to replace the BKL with a different lock.
Ah you're right!
PATCH 6/6 procfs: Kill the bkl in ioctl
In reply to Frederic WeisbeckerThere are no more users of procfs that implement the ioctl callback. Drop the bkl from this path and warn on any use of this callback.
--- fs/proc/inode.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/proc/inode.c +2 -2
@@ -231,9 +231,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigneif (rv == -ENOIOCTLCMD ) rv = -EINVAL ; }else if (ioctl) { -lock_kernel (); +WARN_ONCE (1 ,"Procfs ioctl handlers must use unlocked_ioctl, " +"%pf will be called without the Bkl held\n" , ioctl); rv =ioctl (file->f_path.dentry->d_inode, file, cmd, arg); -unlock_kernel (); }pde_users_dec (pde);
Signature · 1 line
1.6.2.3
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
fs/proc/inode.c static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne · line 236
Quoted 11 lines · Frederic Weisbecker
fs/proc/inode.c +2
-2@@ -231,9 +231,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne if (rv == -ENOIOCTLCMD) rv = -EINVAL; } else if (ioctl) { - lock_kernel(); + WARN_ONCE(1, "Procfs ioctl handlers must use unlocked_ioctl, " + "%pf will be called without the Bkl held\n", ioctl); rv = ioctl(file->f_path.dentry->d_inode, file, cmd, arg); - unlock_kernel();
Then delete the branch.
Or go through formal feature-removal procedure.
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 15 lines · Alexey Dobriyan
fs/proc/inode.c static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne · line 236
Quoted 11 lines · Frederic Weisbecker
fs/proc/inode.c +2
-2@@ -231,9 +231,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne if (rv == -ENOIOCTLCMD) rv = -EINVAL; } else if (ioctl) { - lock_kernel(); + WARN_ONCE(1, "Procfs ioctl handlers must use unlocked_ioctl, " + "%pf will be called without the Bkl held\n", ioctl); rv = ioctl(file->f_path.dentry->d_inode, file, cmd, arg); - unlock_kernel();Then delete the branch.
Or go through formal feature-removal procedure.
I thought about it. I even started to write something in this feature-removal file but realized that I can't remove the .ioctl() callback from file operations. We still need to check the user hasn't made the mistake of implementing it.
What I can plan as a feature removal, though, is to keep the warning but don't actually call the ioctl.
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 18 lines · Frederic Weisbecker
Quoted 15 lines · Alexey Dobriyan
fs/proc/inode.c static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne · line 236
Quoted 11 lines · Frederic Weisbecker
fs/proc/inode.c +2
-2@@ -231,9 +231,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigneif (rv == -ENOIOCTLCMD ) rv = -EINVAL ; }else if (ioctl) { -lock_kernel (); +WARN_ONCE (1 ,"Procfs ioctl handlers must use unlocked_ioctl, " +"%pf will be called without the Bkl held\n" , ioctl); rv =ioctl (file->f_path.dentry->d_inode, file, cmd, arg); -unlock_kernel ();Then delete the branch.
Or go through formal feature-removal procedure.
Quoted 7 lines
I thought about it. I even started to write something in this feature-removal file but realized that I can't remove the .ioctl() callback from file operations. We still need to check the user hasn't made the mistake of implementing it.
What I can plan as a feature removal, though, is to keep the warning but don't actually call the ioctl.
I believe we can actually remove ioctl from file_operations. The patch I did to convert all users to ".unlocked_ioctl = default_ioctl," should really catch all cases, and I think we can enforce this by renaming fops->ioctl to locked_ioctl or old_ioctl to make sure we didn't miss any, and then mandate that this one is only used when unlocked_ioctl is set to default_ioctl.
I also remember going through procfs ioctl operations some time ago and finding exactly three users, which I believe are the same ones that Frederic found.
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 24 lines · Arnd Bergmann
Quoted 23 lines · Frederic Weisbecker
Quoted 15 lines · Alexey Dobriyan
fs/proc/inode.c static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne · line 236
Quoted 11 lines · Frederic Weisbecker
fs/proc/inode.c +2
-2@@ -231,9 +231,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigneif (rv == -ENOIOCTLCMD ) rv = -EINVAL ; }else if (ioctl) { -lock_kernel (); +WARN_ONCE (1 ,"Procfs ioctl handlers must use unlocked_ioctl, " +"%pf will be called without the Bkl held\n" , ioctl); rv =ioctl (file->f_path.dentry->d_inode, file, cmd, arg); -unlock_kernel ();Then delete the branch.
Or go through formal feature-removal procedure.I thought about it. I even started to write something in this feature-removal file but realized that I can't remove the .ioctl() callback from file operations. We still need to check the user hasn't made the mistake of implementing it.
Quoted 8 lines
Quoted 2 lines
What I can plan as a feature removal, though, is to keep the warning but don't actually call the ioctl.
I believe we can actually remove ioctl from
file_operations. The patch I did to convert all users to ".unlocked_ioctl =default_ioctl," should really catch all cases, and I think we can enforce this by renamingfops->ioctltolocked_ioctlorold_ioctlto make sure we didn't miss any, and then mandate that this one is only used whenunlocked_ioctlis set todefault_ioctl.
I just looked at the patch in question and noted that the changelog is pretty high, but how could it be else.
Actually it's not that large, but highly spread:
Documentation/DocBook/kernel-hacking.tmpl | 2 +- Documentation/filesystems/vfs.txt | 3 +- arch/arm/kernel/etm.c | 1 + arch/cris/arch-v10/drivers/ds1302.c | 3 ++ arch/cris/arch-v10/drivers/gpio.c | 2 + arch/cris/arch-v10/drivers/i2c.c | 2 + arch/cris/arch-v10/drivers/pcf8563.c | 3 ++ arch/cris/arch-v10/drivers/sync_serial.c | 4 ++- arch/cris/arch-v32/drivers/cryptocop.c | 4 ++- arch/cris/arch-v32/drivers/i2c.c | 2 + arch/cris/arch-v32/drivers/mach-a3/gpio.c | 2 + arch/cris/arch-v32/drivers/mach-fs/gpio.c | 2 + arch/cris/arch-v32/drivers/pcf8563.c | 5 +++- arch/cris/arch-v32/drivers/sync_serial.c | 4 ++- arch/ia64/kernel/perfmon.c | 2 + arch/ia64/sn/kernel/sn2/sn_hwperf.c | 2 + arch/m68k/bvme6000/rtc.c | 2 + arch/m68k/mvme16x/rtc.c | 2 + arch/um/drivers/harddog_kern.c | 2 + arch/um/drivers/hostaudio_kern.c | 3 ++ arch/um/drivers/mmapper_kern.c | 3 ++ drivers/block/DAC960.c | 3 +- drivers/block/paride/pg.c | 2 + drivers/block/paride/pt.c | 2 + drivers/block/pktcdvd.c | 3 ++ drivers/char/apm-emulation.c | 2 + drivers/char/applicom.c | 2 + drivers/char/ds1302.c | 1 + drivers/char/ds1620.c | 2 + drivers/char/dtlk.c | 2 + drivers/char/generic_nvram.c | 2 + drivers/char/genrtc.c | 2 + drivers/char/i8k.c | 2 + drivers/char/ip2/ip2main.c | 1 + drivers/char/ipmi/ipmi_devintf.c | 2 + drivers/char/ipmi/ipmi_watchdog.c | 2 + drivers/char/istallion.c | 1 + drivers/char/lp.c | 1 + drivers/char/mmtimer.c | 1 + drivers/char/nwflash.c | 1 + drivers/char/raw.c | 4 +++ drivers/char/rio/rio_linux.c | 1 + drivers/char/stallion.c | 1 + drivers/char/sx.c | 1 + drivers/char/uv_mmtimer.c | 1 + drivers/char/viotape.c | 1 + drivers/firewire/core-cdev.c | 2 + drivers/gpu/drm/i810/i810_dma.c | 2 + drivers/gpu/drm/i830/i830_dma.c | 2 + drivers/hid/usbhid/hiddev.c | 3 +- drivers/hwmon/fschmd.c | 2 + drivers/ide/ide-tape.c | 2 + drivers/ieee1394/dv1394.c | 2 + drivers/ieee1394/raw1394.c | 2 + drivers/ieee1394/video1394.c | 4 ++- drivers/infiniband/core/ucm.c | 2 + drivers/infiniband/core/ucma.c | 2 + drivers/infiniband/core/user_mad.c | 7 +++- drivers/infiniband/core/uverbs_main.c | 10 +++++-- drivers/input/misc/hp_sdc_rtc.c | 2 + drivers/input/misc/uinput.c | 1 + drivers/isdn/capi/capi.c | 1 + drivers/isdn/divert/divert_procfs.c | 2 + drivers/isdn/i4l/isdn_common.c | 1 + drivers/isdn/mISDN/timerdev.c | 3 ++ drivers/macintosh/ans-lcd.c | 2 + drivers/macintosh/nvram.c | 2 + drivers/macintosh/via-pmu.c | 2 + drivers/media/dvb/bt8xx/dst_ca.c | 1 + drivers/media/dvb/dvb-core/dmxdev.c | 3 ++ drivers/media/dvb/dvb-core/dvb_ca_en50221.c | 3 ++ drivers/media/dvb/dvb-core/dvb_frontend.c | 5 +++- drivers/media/dvb/dvb-core/dvb_net.c | 3 ++ drivers/media/dvb/firewire/firedtv-ci.c | 3 ++ drivers/media/dvb/ttpci/av7110.c | 3 ++ drivers/media/dvb/ttpci/av7110_av.c | 5 +++ drivers/media/dvb/ttpci/av7110_ca.c | 3 ++ drivers/media/video/cpia.c | 2 + drivers/media/video/v4l2-dev.c | 2 + drivers/mtd/mtdchar.c | 1 + drivers/mtd/ubi/cdev.c | 2 + drivers/net/ppp_generic.c | 4 ++- drivers/net/wireless/airo.c | 9 ++++++ drivers/net/wireless/ray_cs.c | 3 ++ drivers/rtc/rtc-m41t80.c | 1 + drivers/s390/char/fs3270.c | 1 + drivers/s390/char/tape_char.c | 2 +- drivers/s390/cio/chsc_sch.c | 2 + drivers/s390/crypto/zcrypt_api.c | 1 + drivers/s390/scsi/zfcp_cfdc.c | 2 + drivers/sbus/char/envctrl.c | 1 + drivers/sbus/char/openprom.c | 1 + drivers/scsi/3w-9xxx.c | 2 + drivers/scsi/3w-sas.c | 2 + drivers/scsi/3w-xxxx.c | 2 + drivers/scsi/aacraid/linit.c | 1 + drivers/scsi/dpt_i2o.c | 2 + drivers/scsi/gdth.c | 2 + drivers/scsi/megaraid.c | 2 + drivers/scsi/megaraid/megaraid_mm.c | 2 + drivers/scsi/megaraid/megaraid_sas.c | 1 + drivers/scsi/mpt2sas/mpt2sas_ctl.c | 1 + drivers/scsi/osd/osd_uld.c | 2 + drivers/scsi/osst.c | 2 + drivers/scsi/pmcraid.c | 2 + drivers/scsi/sg.c | 2 + drivers/scsi/st.c | 1 + drivers/spi/spidev.c | 2 + drivers/staging/b3dfg/b3dfg.c | 2 + drivers/staging/comedi/comedi_fops.c | 2 + drivers/staging/dream/pmem.c | 3 ++ drivers/staging/dream/qdsp5/audio_aac.c | 2 + drivers/staging/dream/qdsp5/audio_mp3.c | 2 + drivers/staging/poch/poch.c | 3 ++ drivers/staging/sep/sep_driver.c | 3 ++ drivers/staging/vme/devices/vme_user.c | 2 + drivers/telephony/ixj.c | 1 + drivers/usb/class/usblp.c | 2 + drivers/usb/gadget/printer.c | 1 + drivers/usb/misc/idmouse.c | 2 + drivers/usb/misc/iowarrior.c | 1 + drivers/usb/misc/rio500.c | 1 + drivers/usb/misc/vstusb.c | 2 + fs/autofs/root.c | 1 + fs/autofs4/dev-ioctl.c | 2 + fs/btrfs/super.c | 1 + fs/coda/pioctl.c | 3 ++ fs/coda/psdev.c | 2 + fs/ecryptfs/file.c | 2 + fs/ecryptfs/miscdev.c | 2 + fs/hfsplus/dir.c | 2 + fs/hfsplus/inode.c | 2 + fs/ioctl.c | 11 ++------ fs/ncpfs/dir.c | 2 + fs/ncpfs/file.c | 1 + fs/read_write.c | 34 ------------------------ fs/smbfs/dir.c | 2 + fs/smbfs/file.c | 1 + fs/udf/dir.c | 2 + fs/udf/file.c | 1 + include/linux/fs.h | 5 --- include/linux/smp_lock.h | 5 +++ lib/kernel_lock.c | 37 +++++++++++++++++++++++++- net/socket.c | 1 + sound/core/control.c | 2 + sound/core/oss/pcm_oss.c | 2 + sound/core/pcm_native.c | 2 + sound/core/seq/seq_clientmgr.c | 2 + sound/oss/au1550_ac97.c | 30 +++++++++++---------- sound/oss/dmasound/dmasound_core.c | 2 + sound/oss/msnd_pinnacle.c | 2 + sound/oss/sh_dac_audio.c | 3 ++ sound/oss/soundcard.c | 1 + sound/oss/swarm_cs4297a.c | 3 ++ sound/oss/vwsnd.c | 2 + sound/soc/soc-core.c | 2 + virt/kvm/kvm_main.c | 4 +++ 157 files changed, 372 insertions(+), 80 deletions(-)
I wonder if we should actually just turn all these into unlocked_ioctl directly. And then bring a warn on ioctl, and finally schedule the removal of this callback.
What do you think?
You plan looks good but I fear this actually carries the problem forward in that we won't be able to remove .ioctl after that.
I can handle that if you agree.
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 10 lines · On Wednesday 31 March 2010 19:22:11 Frederic Weisbecker wrote:
Quoted 5 lines · Arnd Bergmann
I believe we can actually remove ioctl from
file_operations. The patch I did to convert all users to ".unlocked_ioctl =default_ioctl," should really catch all cases, and I think we can enforce this by renamingfops->ioctltolocked_ioctlorold_ioctlto make sure we didn't miss any, and then mandate that this one is only used whenunlocked_ioctlis set todefault_ioctl.I just looked at the patch in question and noted that the changelog is pretty high, but how could it be else.
Actually it's not that large, but highly spread:
<snip>
Quoted 8 lines
157 files changed, 372 insertions(+), 80 deletions(-)I wonder if we should actually just turn all these into
unlocked_ioctldirectly. And then bring a warn on ioctl, and finally schedule the removal of this callback.What do you think?
I don't think the warning helps all that much, at least not across an entire release. We could leave it in for the merge window and fix all users for -rc1, then submit a patch that kills everything that came in during the merge window and remove it completely in -rc2.
Getting rid of ioctl completely is a lot of work though, covering the entire lot of ~150 device drivers. I think the patch as is (or the variant renaming .ioctl to .locked_ioctl) is far less work and has less potential of introducing regressions.
Quoted 4 lines
You plan looks good but I fear this actually carries the problem forward in that we won't be able to remove .ioctl after that.
I can handle that if you agree.
I don't think we really need to get rid of it this soon in the obsolete drivers, pushing down the BKL into an unlocked_ioctl function only slightly shifts the problem around, since the driver still depends on the BKL then and gets disabled if you build with CONFIG_BKL=n.
IMHO, a better use of your time would be to completely remove the BKL along with the ioctl function from any of the drivers in this lists that looks like it could be relevant to real users.
In the meantime, we can move the declaration of the .locked_ioctl callback into an #ifdef CONFIG_BKL, to make sure nobody builds a driver with an ioctl function that does not get called.
Another crazy idea I had was to simply turn the BKL into a regular mutex as soon as we can show that all remaining users are of the non-recursive kind and don't rely on the autorelease-on-sleep. Doing that would be much easier without the pushdown into .unlocked_ioctl than it would be with it.
Arnd
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 5 lines · On Wednesday 31 March 2010 22:21:23 Arnd Bergmann wrote:
Another crazy idea I had was to simply turn the BKL into a regular mutex as soon as we can show that all remaining users are of the non-recursive kind and don't rely on the autorelease-on-sleep. Doing that would be much easier without the pushdown into .unlocked_ioctl than it would be with it.
I just looked at all the users of lock_kernel remaining with my patch series. For 90% of them, it is completely obvious that they don't rely on nested locking, and they very much look like they don't need the autorelease either, because the BKL was simply pushed down into the open, ioctl and llseek functions.
There are a few file systems (udf, ncpfs, autofs, coda, ...) and some network protocols (appletalk, ipx, irnet and x25) for which it is not obviously, though still quite likely, the case.
So we could actually remove the BKL recursion code soon, or even turn all of it into a regular mutex, at least as an experimental option.
The recursive users that I've removed in my series are the block, tty, input and sound subsystems, as well as the init code.
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 2 lines
The recursive users that I've removed in my series are the block, tty, input and sound subsystems, as well as the init code.
There are some very subtle recursive cases in the tty code - hangup triggered close and consoles being an absolute gem I've just had to debug in my lock removal bits so far...
Alan
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 6 lines · Alan Cox
Quoted 2 lines
The recursive users that I've removed in my series are the block, tty, input and sound subsystems, as well as the init code.
There are some very subtle recursive cases in the tty code - hangup triggered close and consoles being an absolute gem I've just had to debug in my lock removal bits so far...
Yes, I've seen some of them. What I meant above is that with CONFIG_TTY_MUTEX=y, the TTY code no longer uses the BKL in a nested way, and quite likely no either code does either.
The TTY code with my patch now has tty_lock() for all cases that I concluded are never nested in another tty_lock, and tty_lock_nested() for those I did not understand or that I know they are nested (the latter type usually comes with a comment). The only difference between the two is a WARN_ON(tty_locked()) in tty_lock, so we can see where the analysis was wrong.
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Arnd BergmannQuoted 17 lines · Arnd Bergmann
Quoted 5 lines · On Wednesday 31 March 2010 22:21:23 Arnd Bergmann wrote:
Another crazy idea I had was to simply turn the BKL into a regular mutex as soon as we can show that all remaining users are of the non-recursive kind and don't rely on the autorelease-on-sleep. Doing that would be much easier without the pushdown into .unlocked_ioctl than it would be with it.
I just looked at all the users of
lock_kernelremaining with my patch series. For 90% of them, it is completely obvious that they don't rely on nested locking, and they very much look like they don't need the autorelease either, because the BKL was simply pushed down into the open, ioctl and llseek functions.There are a few file systems (udf, ncpfs, autofs, coda, ...) and some network protocols (appletalk, ipx, irnet and x25) for which it is not obviously, though still quite likely, the case.
Quoted 5 lines
So we could actually remove the BKL recursion code soon, or even turn all of it into a regular mutex, at least as an experimental option.
The recursive users that I've removed in my series are the block, tty, input and sound subsystems, as well as the init code.
This is a solution that has been tried more than once already. But Linus has told he wouldn't pull something that turns the bkl into a mutex or a semaphore.
Plus it's quite hard to tell that it does or not auto-release somewhere This is often something you can really spot on runtime or on small path only.
The simple fact the bkl is not always a leaf lock makes it need the auto-release, otherwise you experience very bad unexpected lock dependencies.
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 3 lines · Frederic Weisbecker
This is a solution that has been tried more than once already. But Linus has told he wouldn't pull something that turns the bkl into a mutex or a semaphore.
Ok. Starting from the same observation of simplicity in the remaining code, we should also be able to find a semi-automatic way of turning the BKL usage in these drivers into a per-module mutex.
Quoted 3 lines
Plus it's quite hard to tell that it does or not auto-release somewhere This is often something you can really spot on runtime or on small path only.
Well, the autorelease by itself is not needed anywhere. What is needed is the consequence of autorelease avoiding AB-BA type deadlocks.
Quoted 3 lines
The simple fact the bkl is not always a leaf lock makes it need the auto-release, otherwise you experience very bad unexpected lock dependencies.
I'm arguing that we can probably show the BKL to be the outermost lock for the majority of the remaining drivers, which only get it from their open(), ioctl() or llseek() functions, which are all called without any locks held. If the BKL is a regular mutex, lockdep should warn of the other cases.
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Arnd BergmannQuoted 18 lines · ----- "Arnd Bergmann
Quoted 1 line · On Wednesday 31 March 2010 22:21:23 Arnd Bergmann wrote:
Another crazy idea I had was to simply turn the BKL into a regular
mutex
Quoted 1 line
as soon as we can show that all remaining users are of the
non-recursive
Quoted 1 line
kind and don't rely on the autorelease-on-sleep. Doing that would
be
Quoted 1 line
much easier without the pushdown into .unlocked_ioctl than it would
be
Quoted 1 line
with it.
I just looked at all the users of
lock_kernelremaining with my patch series. For 90% of them, it is completely obvious that they don't rely
on nested locking, and they very much look like they don't need the autorelease either, because the BKL was simply pushed down into the open, ioctl and llseek functions.
Quoted 6 lines
There are a few file systems (udf, ncpfs, autofs, coda, ...) and some network protocols (appletalk, ipx, irnet and x25) for which it is not obviously, though still quite likely, the case.
So we could actually remove the BKL recursion code soon, or even turn all of it into a regular mutex, at least as an experimental option.
Well, that would be quite similar to what we do in real-time with the "Big Kernel Semaphore". However, Linus didn't want that pushed into mainstream. As an experimental tree it's fine, but we're really stuck with removing the BKL one by one until it's gone.
Quoted 6 lines
The recursive users that I've removed in my series are the block, tty,
input and sound subsystems, as well as the init code.Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Arnd BergmannQuoted 34 lines · Arnd Bergmann
Quoted 10 lines · On Wednesday 31 March 2010 19:22:11 Frederic Weisbecker wrote:
Quoted 5 lines · Arnd Bergmann
I believe we can actually remove ioctl from
file_operations. The patch I did to convert all users to ".unlocked_ioctl =default_ioctl," should really catch all cases, and I think we can enforce this by renamingfops->ioctltolocked_ioctlorold_ioctlto make sure we didn't miss any, and then mandate that this one is only used whenunlocked_ioctlis set todefault_ioctl.I just looked at the patch in question and noted that the changelog is pretty high, but how could it be else.
Actually it's not that large, but highly spread:<snip>
Quoted 8 lines
157 files changed, 372 insertions(+), 80 deletions(-)I wonder if we should actually just turn all these into
unlocked_ioctldirectly. And then bring a warn on ioctl, and finally schedule the removal of this callback.What do you think?
I don't think the warning helps all that much, at least not across an entire release. We could leave it in for the merge window and fix all users for -rc1, then submit a patch that kills everything that came in during the merge window and remove it completely in -rc2.
Getting rid of ioctl completely is a lot of work though, covering the entire lot of ~150 device drivers. I think the patch as is (or the variant renaming .ioctl to .locked_ioctl) is far less work and has less potential of introducing regressions.
Quoted 3 lines
You plan looks good but I fear this actually carries the problem forward in that we won't be able to remove .ioctl after that.
Quoted 6 lines
Quoted 1 line
I can handle that if you agree.
I don't think we really need to get rid of it this soon in the obsolete drivers, pushing down the BKL into an
unlocked_ioctlfunction only slightly shifts the problem around, since the driver still depends on the BKL then and gets disabled if you build withCONFIG_BKL=n.
Hmm, yeah you're right actually. Since we have this CONFIG_BKL thing plus a future check to prevent from people implementing new ioctl (checking ioctl without default_ioctl), it's actually better than a big pushdown as it's less invasive.
Quoted 3 lines
In the meantime, we can move the declaration of the .locked_ioctl callback into an #ifdef
CONFIG_BKL, to make sure nobody builds a driver with an ioctl function that does not get called.
Ok, now how to get this all merged? A single monolithic patch is probably not appropriate.
The simplest is to have a single branch with the default_ioctl implemented, and then attributed to drivers in a set cut by subsystems/drivers. And push the whole for the next -rc1.
The other solution is to push default_ioctl for this release and get the driver changes to each concerned tree. That said, I suspect a good part of them are unmaintained, hence the other solution looks better to me.
Hmm?
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 10 lines · Frederic Weisbecker
Quoted 3 lines · Arnd Bergmann
In the meantime, we can move the declaration of the .locked_ioctl callback into an #ifdef
CONFIG_BKL, to make sure nobody builds a driver with an ioctl function that does not get called.Ok, now how to get this all merged? A single monolithic patch is probably not appropriate.
Quoted 8 lines
The simplest is to have a single branch with the
default_ioctlimplemented, and then attributed to drivers in a set cut by subsystems/drivers. And push the whole for the next -rc1.The other solution is to push
default_ioctlfor this release and get the driver changes to each concerned tree. That said, I suspect a good part of them are unmaintained, hence the other solution looks better to me.
I don't care much about the unmaintained parts, we can always have a tree collecting all the patches for those drivers and merge it in -rc1.
I'd say the nicest way would be to get Linus to merge the patch below now, so we can start queuing stuff in maintainer trees on top of it, and check against linux-next what is still missing and push all of them from our branch.
Arnd
---
Subject: [PATCH] introduce CONFIG_BKL and default_ioctl
This is a preparation for the removal of the big kernel lock that introduces new interfaces for device drivers still using it.
We can start marking those device drivers as 'depends on CONFIG_BKL' now, and make that symbol optional later, when the point has come at which we are able to build a kernel without the BKL.
Similarly, device drivers that currently make use of the implicit BKL locking around the ioctl function can now get annotated by changing
.ioctl = foo_ioctl,
to
.locked_ioctl = foo_ioctl,
.unlocked_ioctl = default_ioctl,
As soon as no driver remains using the old ioctl callback, it can get removed.
--- fs/ioctl.c | 22 ++++++++++++++++++++++ include/linux/fs.h | 3 +++ include/linux/smp_lock.h | 4 ++++ lib/Kconfig.debug | 10 ++++++++++ 4 files changed, 39 insertions(+), 0 deletions(-)
fs/ioctl.c +22 -0
@@ -58,6 +58,28 @@ static long vfs_ioctl(struct file *filp, unsigned int cmd,return error; } +#ifdef CONFIG_BKL +/* +* default_ioctl - call unlocked_ioctl with BKL held +* +* Setting only the the ioctl operation but not unlocked_ioctl will become +* invalid in the future, all drivers that are not converted to unlocked_ioctl +* should set .unlocked_ioctl = default_ioctl now. +*/ +long default_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +int error = -ENOTTY ; +if (filp->f_op->locked_ioctl) { +lock_kernel (); + error = filp->f_op->locked_ioctl (filp->f_path.dentry->d_inode, + filp, cmd, arg); +unlock_kernel (); + } +return error; +} +EXPORT_SYMBOL_GPL (default_ioctl); +#endif +static int ioctl_fibmap (struct file *filp,int __user *p) {struct address_space *mapping = filp->f_mapping;
include/linux/fs.h +3 -0
@@ -1492,6 +1492,9 @@ struct file_operations {int (*readdir) (struct file *,void *,filldir_t );unsigned int (*poll) (struct file *,struct poll_table_struct *);int (*ioctl) (struct inode *,struct file *,unsigned int ,unsigned long ); +#ifdef CONFIG_BKL +int (*locked_ioctl) (struct inode *,struct file *,unsigned int ,unsigned long ); +#endif long (*unlocked_ioctl) (struct file *,unsigned int ,unsigned long );long (*compat_ioctl) (struct file *,unsigned int ,unsigned long );int (*mmap) (struct file *,struct vm_area_struct *);
include/linux/smp_lock.h +4 -0
@@ -62,4 +62,8 @@ static inline void cycle_kernel_lock(void)#define kernel_locked () 1#endif /* CONFIG_LOCK_KERNEL */ + +loff_t default_llseek (struct file *file,loff_t offset,int origin); +long default_ioctl (struct file *filp,unsigned int cmd,unsigned long arg); +#endif /* __LINUX_SMPLOCK_H */
lib/Kconfig.debug +10 -0
@@ -444,6 +444,16 @@ config DEBUG_MUTEXES This feature allows mutex semantics violations to be detected and reported. +config BKL + def_bool y + help + This is the traditional lock that is used in old code instead + of proper locking. All drivers that use the BKL should depend + on this symbol. + This configuration option will become user-selectable in the + future, as soon as it is possible to build a kernel without + it. + config DEBUG_LOCK_ALLOC bool "Lock debugging: detect incorrect freeing of live locks" depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 1 line · Arnd Bergmann
Subject: [PATCH] introduce
CONFIG_BKLanddefault_ioctl
[...]
Quoted 9 lines
fs/ioctl.c +3
-0@@ -58,6 +58,28 @@ static long vfs_ioctl(struct file *filp, unsigned int cmd,return error; } +#ifdef CONFIG_BKL +/* +* default_ioctl - call unlocked_ioctl with BKL held
[...]
fs/ioctl.c static long vfs_ioctl(struct file *filp, unsigned int cmd, · line 75
Quoted 2 lines
fs/ioctl.c +2
-0+ error = filp->f_op->locked_ioctl (filp->f_path.dentry->d_inode, + filp, cmd, arg);
Typo. default_ioctl - call locked_ioctl with BKL held
Signature · 3 lines
Stefan Richter -=====-==-=- -=-- ---== http://arcgraph.de/sr/
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Arnd BergmannQuoted 70 lines · Arnd Bergmann
Quoted 10 lines · Frederic Weisbecker
Quoted 3 lines · Arnd Bergmann
In the meantime, we can move the declaration of the .locked_ioctl callback into an #ifdef
CONFIG_BKL, to make sure nobody builds a driver with an ioctl function that does not get called.Ok, now how to get this all merged? A single monolithic patch is probably not appropriate.
Quoted 8 lines
The simplest is to have a single branch with the
default_ioctlimplemented, and then attributed to drivers in a set cut by subsystems/drivers. And push the whole for the next -rc1.The other solution is to push
default_ioctlfor this release and get the driver changes to each concerned tree. That said, I suspect a good part of them are unmaintained, hence the other solution looks better to me.I don't care much about the unmaintained parts, we can always have a tree collecting all the patches for those drivers and merge it in -rc1.
I'd say the nicest way would be to get Linus to merge the patch below now, so we can start queuing stuff in maintainer trees on top of it, and check against linux-next what is still missing and push all of them from our branch.
Arnd
---
Subject: [PATCH] introduceCONFIG_BKLanddefault_ioctlThis is a preparation for the removal of the big kernel lock that introduces new interfaces for device drivers still using it.
We can start marking those device drivers as 'depends on
CONFIG_BKL' now, and make that symbol optional later, when the point has come at which we are able to build a kernel without the BKL.Similarly, device drivers that currently make use of the implicit BKL locking around the ioctl function can now get annotated by changing
.ioctl =
foo_ioctl,to
.locked_ioctl =
foo_ioctl,
.unlocked_ioctl =default_ioctl,As soon as no driver remains using the old ioctl callback, it can get removed.
Signed-off-by Arnd Bergmann <[email protected]>--- fs/ioctl.c | 22 ++++++++++++++++++++++ include/linux/fs.h | 3 +++ include/linux/smp_lock.h | 4 ++++ lib/Kconfig.debug | 10 ++++++++++ 4 files changed, 39 insertions(+), 0 deletions(-)fs/ioctl.c +0
-0@@ -58,6 +58,28 @@ static long vfs_ioctl(struct file *filp, unsigned int cmd,return error; }
fs/ioctl.c static long vfs_ioctl(struct file *filp, unsigned int cmd, · line 70
Quoted 10 lines
fs/ioctl.c +10
-0+#ifdef CONFIG_BKL +/* +* default_ioctl - call unlocked_ioctl with BKL held +* +* Setting only the the ioctl operation but not unlocked_ioctl will become +* invalid in the future, all drivers that are not converted to unlocked_ioctl +* should set .unlocked_ioctl = default_ioctl now. +*/ +long default_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{
Do you mind if I rename this to deprecated_ioctl()? This "default" naming suggests a fallback everyone that don't need tricky things should use.
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 3 lines · Frederic Weisbecker
Do you mind if I rename this to
deprecated_ioctl()? This "default" naming suggests a fallback everyone that don't need tricky things should use.
Sounds good. The idea was to keep the naming consistent with default_llseek, but after the discussion on llseek, we will probably do something else with it anyway.
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Arnd BergmannQuoted 48 lines · Arnd Bergmann
Quoted 10 lines · Frederic Weisbecker
Quoted 3 lines · Arnd Bergmann
In the meantime, we can move the declaration of the .locked_ioctl callback into an #ifdef
CONFIG_BKL, to make sure nobody builds a driver with an ioctl function that does not get called.Ok, now how to get this all merged? A single monolithic patch is probably not appropriate.
Quoted 8 lines
The simplest is to have a single branch with the
default_ioctlimplemented, and then attributed to drivers in a set cut by subsystems/drivers. And push the whole for the next -rc1.The other solution is to push
default_ioctlfor this release and get the driver changes to each concerned tree. That said, I suspect a good part of them are unmaintained, hence the other solution looks better to me.I don't care much about the unmaintained parts, we can always have a tree collecting all the patches for those drivers and merge it in -rc1.
I'd say the nicest way would be to get Linus to merge the patch below now, so we can start queuing stuff in maintainer trees on top of it, and check against linux-next what is still missing and push all of them from our branch.
Arnd
---
Subject: [PATCH] introduceCONFIG_BKLanddefault_ioctlThis is a preparation for the removal of the big kernel lock that introduces new interfaces for device drivers still using it.
We can start marking those device drivers as 'depends on
CONFIG_BKL' now, and make that symbol optional later, when the point has come at which we are able to build a kernel without the BKL.Similarly, device drivers that currently make use of the implicit BKL locking around the ioctl function can now get annotated by changing
.ioctl =
foo_ioctl,to
Quoted 7 lines
.locked_ioctl =
foo_ioctl,
.unlocked_ioctl =default_ioctl,As soon as no driver remains using the old ioctl callback, it can get removed.
Signed-off-by Arnd Bergmann <[email protected]>
Al, we would like to make this for 2.6.34, so that we can start converting the drivers that use bkl'ed ioctl to this new scheme in the relevant maintainers trees.
Can we get your ack?
Thanks.
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Arnd BergmannQuoted 48 lines · Arnd Bergmann
Quoted 10 lines · Frederic Weisbecker
Quoted 3 lines · Arnd Bergmann
In the meantime, we can move the declaration of the .locked_ioctl callback into an #ifdef
CONFIG_BKL, to make sure nobody builds a driver with an ioctl function that does not get called.Ok, now how to get this all merged? A single monolithic patch is probably not appropriate.
Quoted 8 lines
The simplest is to have a single branch with the
default_ioctlimplemented, and then attributed to drivers in a set cut by subsystems/drivers. And push the whole for the next -rc1.The other solution is to push
default_ioctlfor this release and get the driver changes to each concerned tree. That said, I suspect a good part of them are unmaintained, hence the other solution looks better to me.I don't care much about the unmaintained parts, we can always have a tree collecting all the patches for those drivers and merge it in -rc1.
I'd say the nicest way would be to get Linus to merge the patch below now, so we can start queuing stuff in maintainer trees on top of it, and check against linux-next what is still missing and push all of them from our branch.
Arnd
---
Subject: [PATCH] introduceCONFIG_BKLanddefault_ioctlThis is a preparation for the removal of the big kernel lock that introduces new interfaces for device drivers still using it.
We can start marking those device drivers as 'depends on
CONFIG_BKL' now, and make that symbol optional later, when the point has come at which we are able to build a kernel without the BKL.Similarly, device drivers that currently make use of the implicit BKL locking around the ioctl function can now get annotated by changing
.ioctl =
foo_ioctl,to
Quoted 7 lines
.locked_ioctl =
foo_ioctl,
.unlocked_ioctl =default_ioctl,As soon as no driver remains using the old ioctl callback, it can get removed.
Signed-off-by Arnd Bergmann <[email protected]>
Al, we would like to make this for 2.6.34, so that we can start converting the drivers that use bkl'ed ioctl to this new scheme in the relevant maintainers trees.
Can we get your ack?
Thanks.
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Frederic WeisbeckerQuoted 8 lines · Frederic Weisbecker
Quoted 5 lines · Arnd Bergmann
I believe we can actually remove ioctl from
file_operations. The patch I did to convert all users to ".unlocked_ioctl =default_ioctl," should really catch all cases, and I think we can enforce this by renamingfops->ioctltolocked_ioctlorold_ioctlto make sure we didn't miss any, and then mandate that this one is only used whenunlocked_ioctlis set todefault_ioctl.
Quoted 4 lines
I just looked at the patch in question and noted that the changelog is pretty high, but how could it be else.
Actually it's not that large, but highly spread:
[Documentation/ arch/, drivers/, drivers/, and more drivers/, fs/, include/, lib/, net/, sound/, virt/]
Quoted 6 lines
157 files changed, 372 insertions(+), 80 deletions(-)I wonder if we should actually just turn all these into
unlocked_ioctldirectly. And then bring a warn on ioctl, and finally schedule the removal of this callback.
A side note: A considerable portion of this particular commit in Arnd's git actually does not deal with .ioctl->.unlocked_ioctl at all, but purely with .llseek. Many(?) of these changes deal with .ioctl and .llseek together. (Arnd also says so in the last paragraph of his changelog.)
IOW there are less .ioctl implementations left than one could think from a look at the diffstat.
Signature · 3 lines
Stefan Richter -=====-==-=- -=-- ----= http://arcgraph.de/sr/
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 5 lines · Stefan Richter
Quoted 4 lines
I wonder if we should actually just turn all these into
unlocked_ioctldirectly. And then bring a warn on ioctl, and finally schedule the removal of this callback.
Quoted 8 lines
A side note: A considerable portion of this particular commit in Arnd's git actually does not deal with .ioctl->.unlocked_ioctl at all, but purely with .llseek. Many(?) of these changes deal with .ioctl and .llseek together. (Arnd also says so in the last paragraph of his changelog.)
IOW there are less .ioctl implementations left than one could think from a look at the diffstat.
Given our recent discussions on the llseek topic, it's probably better to revert most of the changes that purely deal with llseek. My current idea is to use an explicit default_llseek only if one of the following is given:
- we convert ioctl to unlocked_ioctl in the same file_operations, or
- the module uses the big kernel lock explicitly elsewhere.
Even then, there may be a number of cases where we can show it not to be necessary, e.g. when the driver does not care about f_pos. Concurrent llseek is racy by nature, so in most drivers, using the BKL in llseek does not gain anything over using i_mutex.
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 22 lines · Arnd Bergmann
Quoted 5 lines · Stefan Richter
Quoted 4 lines
I wonder if we should actually just turn all these into
unlocked_ioctldirectly. And then bring a warn on ioctl, and finally schedule the removal of this callback.Quoted 8 lines
A side note: A considerable portion of this particular commit in Arnd's git actually does not deal with .ioctl->.unlocked_ioctl at all, but purely with .llseek. Many(?) of these changes deal with .ioctl and .llseek together. (Arnd also says so in the last paragraph of his changelog.)
IOW there are less .ioctl implementations left than one could think from a look at the diffstat.
Given our recent discussions on the llseek topic, it's probably better to revert most of the changes that purely deal with llseek. My current idea is to use an explicit
default_llseekonly if one of the following is given:- we convert ioctl to
unlocked_ioctlin the samefile_operations, or
- the module uses the big kernel lock explicitly elsewhere.
Quoted 6 lines
Even then, there may be a number of cases where we can show it not to be necessary, e.g. when the driver does not care about
f_pos. Concurrent llseek is racy by nature, so in most drivers, using the BKL in llseek does not gain anything over usingi_mutex.Arnd
So you mean we should attribute explicit default_llseek to the evil places instead of explicit generic_file_llseek in the safe ones? That's not a bad idea as it would result in much less changes.
The problem happens the day you switch to generic_file_llseek() as the new default llseek(), how do you prove that all remaining fops that don't implement .llseek don't use the bkl? There will be hundreds of them and saying "we've looked all of them and they don't need it" will be a scary justification.
On the opposite, attributing explicit generic_file_llseek or non_seekable_open on the safe places and default_llseek on the dozens of others doubtful places is easier to get a safe conclusion.
But yeah we should try, at least attributing explicit default_llseek won't harm, quite the opposite.
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 10 lines · Frederic Weisbecker
So you mean we should attribute explicit
default_llseekto the evil places instead of explicitgeneric_file_llseekin the safe ones? That's not a bad idea as it would result in much less changes.The problem happens the day you switch to
generic_file_llseek()as the new defaultllseek(), how do you prove that all remaining fops that don't implement .llseek don't use the bkl? There will be hundreds of them and saying "we've looked all of them and they don't need it" will be a scary justification.
Quoted 7 lines
On the opposite, attributing explicit
generic_file_llseekornon_seekable_openon the safe places anddefault_llseekon the dozens of others doubtful places is easier to get a safe conclusion.But yeah we should try, at least attributing explicit
default_llseekwon't harm, quite the opposite.
Note that an lssek that actually does something is the wrong default, even if we have it that way currently. If the default is changed it should be changed to give the semantics that nonseekable_open() gives us. Given that you guys are so motivated to do something in this area it might be a good idea to do this in a few simple steps:
- make sure every file operation either has a ->llseek instead or calls nonseekable_open from ->open
- remove nonseekable_open and all calls to it
- switch all users of no_llseek to not set a ->llsek after auditing that there's no corner case where we want to allow pread/pwrite but not lseek, which is rather unlikely
- walk through the instances now using default_llseek and chose a better implementation for this particular instance. Often this will be just removing the the lssek method as not allowing seeks is the right thing to do for character drivers, even if it is a behaviour change from the current version which usually is the result of sloppy coding.
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 19 lines · Christoph Hellwig
Quoted 10 lines · Frederic Weisbecker
So you mean we should attribute explicit
default_llseekto the evil places instead of explicitgeneric_file_llseekin the safe ones? That's not a bad idea as it would result in much less changes.The problem happens the day you switch to
generic_file_llseek()as the new defaultllseek(), how do you prove that all remaining fops that don't implement .llseek don't use the bkl? There will be hundreds of them and saying "we've looked all of them and they don't need it" will be a scary justification.Quoted 7 lines
On the opposite, attributing explicit
generic_file_llseekornon_seekable_openon the safe places anddefault_llseekon the dozens of others doubtful places is easier to get a safe conclusion.But yeah we should try, at least attributing explicit
default_llseekwon't harm, quite the opposite.
Quoted 8 lines
Note that an lssek that actually does something is the wrong default, even if we have it that way currently. If the default is changed it should be changed to give the semantics that
nonseekable_open()gives us. Given that you guys are so motivated to do something in this area it might be a good idea to do this in a few simple steps:- make sure every file operation either has a ->llseek instead or calls
nonseekable_openfrom ->open
I still think it would be better to always set llseek if we do that, even if nonseekable_open is already there. I can come up with scripts that check that case, but checking that the open function always calls nonseekable_open when it returns success is beyond my grep skills ;-)
Quoted 4 lines
- remove
nonseekable_openand all calls to it
- switch all users ofno_llseekto not set a ->llsek after auditing that there's no corner case where we want to allow pread/pwrite but not lseek, which is rather unlikely
This parts seems fine.
Quoted 6 lines
- walk through the instances now using
default_llseekand chose a better implementation for this particular instance. Often this will be just removing the the lssek method as not allowing seeks is the right thing to do for character drivers, even if it is a behaviour change from the current version which usually is the result of sloppy coding.
This part is really hard. While in many cases, the driver maintainer might know what user space is potentially opening some character device, it's really hard to tell for outsiders whether the behaviour should be no_llseek (then the default) or noop_llseek to work around broken user space.
I think the rule set for the conversion needs to be one that can be done purely based on the code. How about this:
For each file operation {
if (uses f_pos) {
if (same module uses BKL)
-> default_llseek
else
-> generic_file_llseek
} else {
if (driver maintained)
-> no_llseek (with maintainer ACK)
else
-> noop_llseek
}
}Once that is done, we can turn the default into nonseekable behavior and start removing instances of explicit no_llseek and nonseekable_open.
Should we also rename default_llseek to deprecated_llseek in the process, to go along with the approach for ioctl?
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 49 lines · Arnd Bergmann
Quoted 19 lines · Christoph Hellwig
Quoted 10 lines · Frederic Weisbecker
So you mean we should attribute explicit
default_llseekto the evil places instead of explicitgeneric_file_llseekin the safe ones? That's not a bad idea as it would result in much less changes.The problem happens the day you switch to
generic_file_llseek()as the new defaultllseek(), how do you prove that all remaining fops that don't implement .llseek don't use the bkl? There will be hundreds of them and saying "we've looked all of them and they don't need it" will be a scary justification.Quoted 7 lines
On the opposite, attributing explicit
generic_file_llseekornon_seekable_openon the safe places anddefault_llseekon the dozens of others doubtful places is easier to get a safe conclusion.But yeah we should try, at least attributing explicit
default_llseekwon't harm, quite the opposite.Quoted 8 lines
Note that an lssek that actually does something is the wrong default, even if we have it that way currently. If the default is changed it should be changed to give the semantics that
nonseekable_open()gives us. Given that you guys are so motivated to do something in this area it might be a good idea to do this in a few simple steps:- make sure every file operation either has a ->llseek instead or calls
nonseekable_openfrom ->openI still think it would be better to always set llseek if we do that, even if
nonseekable_openis already there. I can come up with scripts that check that case, but checking that the open function always callsnonseekable_openwhen it returns success is beyond my grep skills ;-)Quoted 4 lines
- remove
nonseekable_openand all calls to it
- switch all users ofno_llseekto not set a ->llsek after auditing that there's no corner case where we want to allow pread/pwrite but not lseek, which is rather unlikelyThis parts seems fine.
Quoted 6 lines
- walk through the instances now using
default_llseekand chose a better implementation for this particular instance. Often this will be just removing the the lssek method as not allowing seeks is the right thing to do for character drivers, even if it is a behaviour change from the current version which usually is the result of sloppy coding.
Quoted 5 lines
This part is really hard. While in many cases, the driver maintainer might know what user space is potentially opening some character device, it's really hard to tell for outsiders whether the behaviour should be
no_llseek(then the default) ornoop_llseekto work around broken user space.
Also even if llseek is useless for a module, turning it into unseekable somehow changes the userspace ABI. I guess this is harmless 99% of the time, but still. And maintainers tend not to like that.
Quoted 4 lines
I think the rule set for the conversion needs to be one that can be done purely based on the code. How about this:
Quoted 13 lines
For each file operation {
if (uses f_pos) {
if (same module uses BKL)
-> default_llseek
else
-> generic_file_llseek
} else {
if (driver maintained)
-> no_llseek (with maintainer ACK)
else
-> noop_llseek
}
}It is also hard to determine a given driver really doesn't use the bkl. A sole lock_kernel() grep in its files is not sufficient. But a manual second pass should do the trick.
Quoted 4 lines
Once that is done, we can turn the default into nonseekable behavior and start removing instances of explicit
no_llseekandnonseekable_open.
Sounds good.
Quoted 2 lines
Should we also rename
default_llseektodeprecated_llseekin the process, to go along with the approach for ioctl?
Yeah, preferably.
Thanks.
Arnd Bergmann
maintainerRe: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 19 lines · Frederic Weisbecker
Quoted 4 lines · Arnd Bergmann
I think the rule set for the conversion needs to be one that can be done purely based on the code. How about this:
Quoted 13 lines
For each file operation { if (uses f_pos) { if (same module uses BKL) -> default_llseek else -> generic_file_llseek } else { if (driver maintained) -> no_llseek (with maintainer ACK) else -> noop_llseek } }
Quoted 3 lines
It is also hard to determine a given driver really doesn't use the bkl. A sole
lock_kernel()grep in its files is not sufficient. But a manual second pass should do the trick.
Why not? In my 2.6.33 based series, I have removed all implicit uses of the BKL, so we can be sure that it doesn't use the BKL unless the module is part of that series. The only two cases I can think of are:
- ioctl callback, which we should do in the same change, like I originally did. If a driver defines ->ioctl(), make it use deprecated_ioctl() and default_llseek()/deprecated_llseek.
- Any of the file systems from Jan's series.
Arnd
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
Quoted 29 lines · Arnd Bergmann
Quoted 19 lines · Frederic Weisbecker
Quoted 4 lines · Arnd Bergmann
I think the rule set for the conversion needs to be one that can be done purely based on the code. How about this:
Quoted 13 lines
For each file operation { if (uses f_pos) { if (same module uses BKL) -> default_llseek else -> generic_file_llseek } else { if (driver maintained) -> no_llseek (with maintainer ACK) else -> noop_llseek } }Quoted 3 lines
It is also hard to determine a given driver really doesn't use the bkl. A sole
lock_kernel()grep in its files is not sufficient. But a manual second pass should do the trick.Why not? In my 2.6.33 based series, I have removed all implicit uses of the BKL, so we can be sure that it doesn't use the BKL unless the module is part of that series. The only two cases I can think of are:
Quoted 7 lines
- ioctl callback, which we should do in the same change, like I originally did. If a driver defines ->ioctl(), make it use
deprecated_ioctl()and default_llseek()/deprecated_llseek.- Any of the file systems from Jan's series.
Arnd
Ok looks like a good plan then.
Thanks.
Re: [PATCH 6/6] procfs: Kill the bkl in ioctl
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
Quoted 2 lines
- make sure every file operation either has a ->llseek instead or calls
nonseekable_openfrom ->openI still think it would be better to always set llseek if we do that, even if
nonseekable_openis already there. I can come up with scripts that check that case, but checking that the open function always callsnonseekable_openwhen it returns success is beyond my grep skills ;-)
Yes, it's not quite easily greppable. Making no seek allowed the implicit default will fortunately allow us to get rid of that oddness.
Quoted 7 lines
Quoted 6 lines
- walk through the instances now using
default_llseekand chose a better implementation for this particular instance. Often this will be just removing the the lssek method as not allowing seeks is the right thing to do for character drivers, even if it is a behaviour change from the current version which usually is the result of sloppy coding.
Quoted 5 lines
This part is really hard. While in many cases, the driver maintainer might know what user space is potentially opening some character device, it's really hard to tell for outsiders whether the behaviour should be
no_llseek(then the default) ornoop_llseekto work around broken user space.
That's why it's last on the list.
Quoted 17 lines
I think the rule set for the conversion needs to be one that can be done purely based on the code. How about this:
For each file operation { if (uses f_pos) { if (same module uses BKL) -> default_llseek else -> generic_file_llseek } else { if (driver maintained) -> no_llseek (with maintainer ACK) else -> noop_llseek } }
Quoted 3 lines
Once that is done, we can turn the default into nonseekable behavior and start removing instances of explicit
no_llseekandnonseekable_open.
That plan sounds good to me.
Quoted 2 lines
Should we also rename
default_llseektodeprecated_llseekin the process, to go along with the approach for ioctl?
I wouldn't bother. If you can actually work on your plan default_llseek should be gone soon enough.
Quoted 16 lines · Frederic Weisbecker
Hi,
This patchset drops any use of the big kernel lock from procfs. May be there is still one or two NULL llseek somewhere but I think we have fixed 99% of those that were in the procfs core.
Users of procfs implementing an ioctl have not been easy to spot automatically (there are hundreds of procfs users) as there are many indirect ways to register a procfs, depending on the subsystem you are.
So for those who want to verify the reliability of this check, you can look at the script there:
Quoted 8 lines
Beware it's very dirty! The hardcoded path are those I had to check manually (or that I added to the automatic check). One day I should learn how to use Coccinelle instead.
In the worst case, the remaining ones this script or my eyes forgot will trigger a warning.
Thanks.
I've applied the patchset to
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
bkl/procfs
Thanks.
Quoted 22 lines
Arnd Bergmann (1):
procfs: Kill BKL in llseek on proc baseFrederic Weisbecker (5):
procfs: Usegeneric_file_llseekin/proc/kcore
procfs: Usegeneric_file_llseekin/proc/kmsg
procfs: Usegeneric_file_llseekin/proc/vmcore
procfs: Push down the bkl from ioctl
procfs: Kill the bkl in ioctldrivers/char/i8k.c | 53 +++++++++++++++------ drivers/isdn/divert/divert_procfs.c | 90 ++++++++++++++++++++++------------- fs/proc/base.c | 10 ++++- fs/proc/inode.c | 4 +- fs/proc/kcore.c | 1 + fs/proc/kmsg.c | 1 + fs/proc/vmcore.c | 1 + net/sunrpc/cache.c | 20 ++++++-- 8 files changed, 123 insertions(+), 57 deletions(-)