Re: f_ops flag to speed up compatible ioctls in linux kernel

Michael S. Tsirkin
2004-09-01T08:17:16Z

Quoting Lee Revell (rlrevell@joe-job.com) "Re: f_ops flag to speed up compatible ioctls in linux kernel":
> By adding a new ioctl you are adding a new use of the BKL. It has been
> suggested on dri-devel that this should be fixed. Is this even
> possible?
>
> Lee

I dont know - can the lock be released before the call to
filp->f_op->ioctl ?

I assume the reason its there is for legacy code - existing ioctls
may be assuming the BKL is taken, but maybe there could be another
flag in f_ops to let sys_ioctl release the lock before doing the call ...

Like this - would that be safe?

--- linux-2.6.8.1/fs/ioctl.c 2004-08-14 13:54:51.000000000 +0300
+++ linux-2.6.8.1-built/fs/ioctl.c 2004-09-01 11:14:59.944417160 +0300
@@ -126,6 +126,14 @@
error = -ENOTTY;
if (S_ISREG(filp->f_dentry->d_inode->i_mode))
error = file_ioctl(filp, cmd, arg);
+ else if (filp->f_op && filp->f_op->ioctl &&
+ (filp->f_op->fops_flags & FOPS_IOCTL_NOLOCK)) {
+ {
+ unlock_kernel();
+ error = filp->f_op->ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
+ goto out;
+
+ }
else if (filp->f_op && filp->f_op->ioctl)
error = filp->f_op->ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
}