mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
@ 2009-10-11 13:45 John Kacur
  2009-10-11 14:37 ` Alan Cox
  2009-10-12 13:03 ` Stefan Richter
  0 siblings, 2 replies; 9+ messages in thread
From: John Kacur @ 2009-10-11 13:45 UTC (permalink / raw)
  To: linux-kernel, Thomas Gleixner
  Cc: Frederic Weisbecker, Ingo Molnar, Christoph Hellwig,
	Jonathan Corbet, Andrew Morton, Vincent Sanders, Alan Cox


Locking in ch_open is covered by the spin_lock, it serializes the calls
to idr_find and scsi_device_get. The BKL appears redundant to me here.

>From b385c85bb5c2579e542cfe55475b729325eb65e1 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Sun, 11 Oct 2009 13:06:54 +0200
Subject: [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open

Everything in ch_open is covered by a spin_lock, so the lock_kernel is redundant
Remove it.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 drivers/scsi/ch.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index fe11c1d..4ba8b67 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -579,19 +579,16 @@ ch_open(struct inode *inode, struct file *file)
 	scsi_changer *ch;
 	int minor = iminor(inode);
 
-	lock_kernel();
 	spin_lock(&ch_index_lock);
 	ch = idr_find(&ch_index_idr, minor);
 
 	if (NULL == ch || scsi_device_get(ch->device)) {
 		spin_unlock(&ch_index_lock);
-		unlock_kernel();
 		return -ENXIO;
 	}
+	file->private_data = ch;
 	spin_unlock(&ch_index_lock);
 
-	file->private_data = ch;
-	unlock_kernel();
 	return 0;
 }
 
-- 
1.6.0.6


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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 13:45 [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open John Kacur
@ 2009-10-11 14:37 ` Alan Cox
  2009-10-11 15:29   ` Arjan van de Ven
  2009-10-12 13:03 ` Stefan Richter
  1 sibling, 1 reply; 9+ messages in thread
From: Alan Cox @ 2009-10-11 14:37 UTC (permalink / raw)
  To: John Kacur
  Cc: linux-kernel, Thomas Gleixner, Frederic Weisbecker, Ingo Molnar,
	Christoph Hellwig, Jonathan Corbet, Andrew Morton,
	Vincent Sanders, linux-scsi

On Sun, 11 Oct 2009 15:45:16 +0200 (CEST)
John Kacur <jkacur@redhat.com> wrote:

[linux-scsi cc'd]

> Locking in ch_open is covered by the spin_lock, it serializes the calls
> to idr_find and scsi_device_get. The BKL appears redundant to me here.

I'm not so sure. In fact there are some quite umm interesting questions
about this code, and some of them are shared with other modules too.

Consider the following sequence

		CPU1				CPU2
	register_chrdev
		ok
						open device
						takes lock
	scsi_register_driver
		error

	unregister_chrdev
	error
	unload
						??????

We don't allocate any idr entries in open so the paths don't seem to leak
and the module itself looks correct. Looking at the bigger picture
however I am not sure what the module loader is trying to do in
kernel/module.c with the code at

     if (ret < 0) {
                /* Init routine failed: abort.  Try to protect us from
                   buggy refcounters. */
                mod->state = MODULE_STATE_GOING;
                synchronize_sched();
                module_put(mod);
                blocking_notifier_call_chain(&module_notify_list,

but it doesn't seem to be sufficient for what may go on ?

Rusty ?

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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 14:37 ` Alan Cox
@ 2009-10-11 15:29   ` Arjan van de Ven
  2009-10-11 15:54     ` Alan Cox
  0 siblings, 1 reply; 9+ messages in thread
From: Arjan van de Ven @ 2009-10-11 15:29 UTC (permalink / raw)
  To: Alan Cox
  Cc: John Kacur, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
	Ingo Molnar, Christoph Hellwig, Jonathan Corbet, Andrew Morton,
	Vincent Sanders, linux-scsi

On Sun, 11 Oct 2009 15:37:09 +0100
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> On Sun, 11 Oct 2009 15:45:16 +0200 (CEST)
> John Kacur <jkacur@redhat.com> wrote:
> 
> [linux-scsi cc'd]
> 
> > Locking in ch_open is covered by the spin_lock, it serializes the
> > calls to idr_find and scsi_device_get. The BKL appears redundant to
> > me here.
> 
> I'm not so sure. In fact there are some quite umm interesting
> questions about this code, and some of them are shared with other
> modules too.
> 
> Consider the following sequence
> 
> 		CPU1				CPU2
> 	register_chrdev
> 		ok
> 						open device
> 						takes lock


but open does not take the BKL, so the BKL is not protecting you at
all against this..



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 15:29   ` Arjan van de Ven
@ 2009-10-11 15:54     ` Alan Cox
  2009-10-11 16:03       ` Arjan van de Ven
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Cox @ 2009-10-11 15:54 UTC (permalink / raw)
  To: Arjan van de Ven
  Cc: John Kacur, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
	Ingo Molnar, Christoph Hellwig, Jonathan Corbet, Andrew Morton,
	Vincent Sanders, linux-scsi

> > I'm not so sure. In fact there are some quite umm interesting
> > questions about this code, and some of them are shared with other
> > modules too.
> > 
> > Consider the following sequence
> > 
> > 		CPU1				CPU2
> > 	register_chrdev
> > 		ok
> > 						open device
> > 						takes lock
> 
> 
> but open does not take the BKL, so the BKL is not protecting you at
> all against this..

But module load/unload does - so while the change doesn't appear to cause
any problems there is an underlying problem here that wants looking at.

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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 15:54     ` Alan Cox
@ 2009-10-11 16:03       ` Arjan van de Ven
  2009-10-11 16:14         ` Alan Cox
  0 siblings, 1 reply; 9+ messages in thread
From: Arjan van de Ven @ 2009-10-11 16:03 UTC (permalink / raw)
  To: Alan Cox
  Cc: John Kacur, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
	Ingo Molnar, Christoph Hellwig, Jonathan Corbet, Andrew Morton,
	Vincent Sanders, linux-scsi

On Sun, 11 Oct 2009 16:54:08 +0100
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> > > I'm not so sure. In fact there are some quite umm interesting
> > > questions about this code, and some of them are shared with other
> > > modules too.
> > > 
> > > Consider the following sequence
> > > 
> > > 		CPU1				CPU2
> > > 	register_chrdev
> > > 		ok
> > > 						open device
> > > 						takes lock
> > 
> > 
> > but open does not take the BKL, so the BKL is not protecting you at
> > all against this..
> 
> But module load/unload does

it does?

looking at the code.... so far failing to find where.



-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 16:03       ` Arjan van de Ven
@ 2009-10-11 16:14         ` Alan Cox
  2009-10-11 16:19           ` Arjan van de Ven
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Cox @ 2009-10-11 16:14 UTC (permalink / raw)
  To: Arjan van de Ven
  Cc: John Kacur, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
	Ingo Molnar, Christoph Hellwig, Jonathan Corbet, Andrew Morton,
	Vincent Sanders, linux-scsi

> > But module load/unload does
> 
> it does?
> 
> looking at the code.... so far failing to find where.

Interesting - it used to and there is code that still relies on that.

The more general problem of

	register_chrdev
					open
	do something
	error
	unload
					whoops

definitely needs looking at however.

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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 16:14         ` Alan Cox
@ 2009-10-11 16:19           ` Arjan van de Ven
  2009-10-11 17:09             ` Jonathan Corbet
  0 siblings, 1 reply; 9+ messages in thread
From: Arjan van de Ven @ 2009-10-11 16:19 UTC (permalink / raw)
  To: Alan Cox
  Cc: John Kacur, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
	Ingo Molnar, Christoph Hellwig, Jonathan Corbet, Andrew Morton,
	Vincent Sanders, linux-scsi

On Sun, 11 Oct 2009 17:14:03 +0100
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:

> > > But module load/unload does
> > 
> > it does?
> > 
> > looking at the code.... so far failing to find where.
> 
> Interesting - it used to and there is code that still relies on that.

I can't find that to be the case anymore though

> 
> The more general problem of
> 
> 	register_chrdev
> 					open
> 	do something
> 	error
> 	unload
> 					whoops
> 
> definitely needs looking at however.

absolutely

we used to have the same issue with networking devices,
and there it ended up with a split "allocate" and "register"




-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 16:19           ` Arjan van de Ven
@ 2009-10-11 17:09             ` Jonathan Corbet
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Corbet @ 2009-10-11 17:09 UTC (permalink / raw)
  To: Arjan van de Ven
  Cc: Alan Cox, John Kacur, linux-kernel, Thomas Gleixner,
	Frederic Weisbecker, Ingo Molnar, Christoph Hellwig,
	Andrew Morton, Vincent Sanders, linux-scsi

On Sun, 11 Oct 2009 09:19:04 -0700
Arjan van de Ven <arjan@infradead.org> wrote:

> > The more general problem of
> > 
> > 	register_chrdev
> > 					open
> > 	do something
> > 	error
> > 	unload
> > 					whoops
> > 
> > definitely needs looking at however.  
> 
> absolutely
> 
> we used to have the same issue with networking devices,
> and there it ended up with a split "allocate" and "register"

Char devs are really the same way - request_chrdev_region() and
cdev_add().  I've thought for a while that register_chrdev() should be
seen as a legacy interface and removed - LDD3 was written from that
point of view.  But that takes work, and nobody's found the issue
urgent enough to put time into...

jon

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

* Re: [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
  2009-10-11 13:45 [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open John Kacur
  2009-10-11 14:37 ` Alan Cox
@ 2009-10-12 13:03 ` Stefan Richter
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Richter @ 2009-10-12 13:03 UTC (permalink / raw)
  To: John Kacur
  Cc: linux-kernel, Thomas Gleixner, Frederic Weisbecker, Ingo Molnar,
	Christoph Hellwig, Jonathan Corbet, Andrew Morton,
	Vincent Sanders, Alan Cox, linux-scsi

On 10/11/2009 3:45 PM, John Kacur wrote:
> Locking in ch_open is covered by the spin_lock, it serializes the calls
> to idr_find and scsi_device_get. The BKL appears redundant to me here.

Superficially this looks OK (i.e. no race with driver init in general).
But I do wonder if there isn't already a race condition possible with
the current code, between ch_probe and the file operations.  ch_probe
makes a scsi_changer instance available in the IDR and creates the
corresponding character device file _before_ the scsi_changer instance
is fully initialized.

(Full quote follows for lsml)

> From b385c85bb5c2579e542cfe55475b729325eb65e1 Mon Sep 17 00:00:00 2001
> From: John Kacur <jkacur@redhat.com>
> Date: Sun, 11 Oct 2009 13:06:54 +0200
> Subject: [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open
> 
> Everything in ch_open is covered by a spin_lock, so the lock_kernel is redundant
> Remove it.
> 
> Signed-off-by: John Kacur <jkacur@redhat.com>
> ---
>  drivers/scsi/ch.c |    5 +----
>  1 files changed, 1 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
> index fe11c1d..4ba8b67 100644
> --- a/drivers/scsi/ch.c
> +++ b/drivers/scsi/ch.c
> @@ -579,19 +579,16 @@ ch_open(struct inode *inode, struct file *file)
>  	scsi_changer *ch;
>  	int minor = iminor(inode);
>  
> -	lock_kernel();
>  	spin_lock(&ch_index_lock);
>  	ch = idr_find(&ch_index_idr, minor);
>  
>  	if (NULL == ch || scsi_device_get(ch->device)) {
>  		spin_unlock(&ch_index_lock);
> -		unlock_kernel();
>  		return -ENXIO;
>  	}
> +	file->private_data = ch;
>  	spin_unlock(&ch_index_lock);
>  
> -	file->private_data = ch;
> -	unlock_kernel();
>  	return 0;
>  }
>  


-- 
Stefan Richter
-=====-==--= =-=- -==--
http://arcgraph.de/sr/

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

end of thread, other threads:[~2009-10-12 13:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-11 13:45 [PATCH RFC] [PATCH] drivers/scsi/ch.c: Remove BKL in ch_open John Kacur
2009-10-11 14:37 ` Alan Cox
2009-10-11 15:29   ` Arjan van de Ven
2009-10-11 15:54     ` Alan Cox
2009-10-11 16:03       ` Arjan van de Ven
2009-10-11 16:14         ` Alan Cox
2009-10-11 16:19           ` Arjan van de Ven
2009-10-11 17:09             ` Jonathan Corbet
2009-10-12 13:03 ` Stefan Richter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®