kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [JANITOR PROPOSAL] Switch ioctl functions to ->unlocked_ioctl
@ 2008-01-08 16:40 Andi Kleen
  2008-01-08 17:05 ` Cyrill Gorcunov
                   ` (5 more replies)
  0 siblings, 6 replies; 42+ messages in thread
From: Andi Kleen @ 2008-01-08 16:40 UTC (permalink / raw)
  To: linux-kernel, kernel-janitors, paolo.ciarrocchi, gorcunov


Here's a proposal for some useful code transformations the kernel janitors
could do as opposed to running checkpatch.pl.

Most ioctl handlers still running implicitely under the big kernel 
lock (BKL). But long term Linux is trying to get away from that. There is a new
->unlocked_ioctl entry point that allows ioctls without BKL, but the code
needs to be explicitely converted to use this.

The first step of getting rid of the BKL is typically to make it visible
in the source. Once it is visible people will have incentive to eliminate it.
That is how the BKL conversion project for Linux long ago started too.
On 2.0 all system calls were still implicitely BKL and in 2.1 the
lock/unlock_kernel()s were moved into the various syscall functions and then
step by step eliminated.

And now it's time to do the same for all the ioctls too.

So my proposal is to convert the ->ioctl handlers all over the tree 
to ->unlocked_ioctl with explicit lock_kernel()/unlock_kernel.

It is not a completely trivial conversion. You will have to 
at least read the source, although not completely understand it.
But it is not very difficult.

Rough recipe:

Grep the source tree for "struct file_operations". You should
fine something like

static int xyz_ioctl(struct inode *i, struct file *f, unsigned cmd, unsigned long arg) 
{
	switch (cmd) { 
	case IOCTL1:
		err = ...;
		...	
		break;
	case IOCTL2:
		...
		err = ...;
		break;
	default:
		err = -ENOTTY;
	} 
	return err;
}
...

struct file_operations xyz_ops = {
	...
	.ioctl = xyz_ioctl
};

The conversion is now to change the prototype of xyz_ioctl to 

static long xyz_ioctl(struct file *f, unsigned cmd, unsigned long arg)
{
}

This means return type from int to long and drop the struct inode * argument

Then add lock_kernel() to the entry point and unlock_kernel() to all exit points.
So you should get

static long xyz_ioctl(struct file *f, unsigned cmd, unsigned long arg)
{
	lock_kernel();
	...
	unlock_kernel();
	return err;
}

The only thing you need to watch out for is that all returns get an unlock_kernel.
so e.g. if the ioctl handler has early error exits they all need an own unlock_kernel()
(if you prefer it you can also use a goto to handle this, but just adding own
unlock_kernels is easier) 

so e.g. if you have

case IOCTL1:

	...
	if (something failed)
		return -EIO;

you would convert it to

	if (something failed) { 
		unlock_kernel();
		return -EIO;
	}

It is very important that all returns have an unlock_kernel(), please always
double and triple check that!

Then change

	.ioctl = xyz_ioctl

to 

	.unlocked_ioctl = xyz_ioctl

Then compile ideally test the result and submit it.

-Andi



^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2008-03-06 14:54 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-08 16:40 [JANITOR PROPOSAL] Switch ioctl functions to ->unlocked_ioctl Andi Kleen
2008-01-08 17:05 ` Cyrill Gorcunov
2008-01-08 18:52 ` Alexey Dobriyan
2008-01-08 19:58 ` Paolo Ciarrocchi
2008-01-08 20:00   ` Matthew Wilcox
2008-01-08 20:03     ` Paolo Ciarrocchi
2008-01-08 20:16       ` Matthew Wilcox
2008-01-08 20:21         ` Matthew Wilcox
2008-01-08 20:26           ` Paolo Ciarrocchi
2008-01-08 23:55           ` Dmitri Vorobiev
2008-03-06 14:54       ` supervising, text processing, semantic "patching" (Re: [JANITOR PROPOSAL] Switch ioctl functions to Oleg Verych
2008-01-08 20:22   ` [JANITOR PROPOSAL] Switch ioctl functions to ->unlocked_ioctl Rik van Riel
2008-01-08 20:42   ` Andi Kleen
2008-01-08 20:45     ` Paolo Ciarrocchi
2008-01-08 23:06     ` [JANITOR PROPOSAL] Switch ioctl functions to ->unlocked_ioctl II Andi Kleen
2008-01-08 23:43       ` Paolo Ciarrocchi
2008-01-09  0:03         ` Andi Kleen
2008-01-09 20:12   ` [JANITOR PROPOSAL] Switch ioctl functions to ->unlocked_ioctl Matt Mackall
2008-01-09 22:40     ` Alasdair G Kergon
2008-01-09 22:46       ` Andi Kleen
2008-01-09 22:45         ` Alasdair G Kergon
2008-01-09 22:58           ` Chris Friesen
2008-01-09 23:05             ` Alasdair G Kergon
2008-01-09 23:31               ` Vadim Lobanov
2008-01-10  0:00                 ` Alasdair G Kergon
2008-01-10  4:59                   ` Vadim Lobanov
2008-01-10  8:34           ` Christoph Hellwig
2008-01-10  9:49       ` Daniel Phillips
2008-01-10 11:39         ` Alasdair G Kergon
2008-01-10 22:55           ` Daniel Phillips
2008-01-11  8:33   ` Pavel Machek
2008-01-08 23:50 ` Kevin Winchester
2008-01-09  0:09   ` Andi Kleen
2008-01-09  0:17     ` Kevin Winchester
2008-01-09  0:27       ` Andi Kleen
2008-01-09 10:34 ` Andre Noll
2008-01-09 13:17   ` Richard Knutsson
2008-01-09 13:33     ` Andre Noll
2008-01-10  8:52 ` Rolf Eike Beer
2008-01-10  9:25   ` Andi Kleen
2008-01-10 10:02     ` Rolf Eike Beer
2008-01-10 10:06       ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).