public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2.6.12.5 1/2] lib: allow idr to be used in irq context
@ 2005-08-16 22:03 Luben Tuikov
  2005-08-17 16:01 ` Jim Houston
  0 siblings, 1 reply; 18+ messages in thread
From: Luben Tuikov @ 2005-08-16 22:03 UTC (permalink / raw)
  To: Linux Kernel Mailing List, SCSI Mailing List, Dave Jones,
	Jeff Garzik
  Cc: Jim Houston

Hi,

This patch allows idr to be used in irq context.

idr_pre_get() is necessary to be called before
idr_get_new() is called.  No locking is necessary when
calling idr_pre_get().

But idr_get_new(), idr_find() and idr_remove()
must be serialized with respect to each other.

All of the aforementioned, may end up in alloc_layer()
or free_layer() which grabs the idp lock using spin_lock.

If idr_get_new() or idr_remove() is used in IRQ context,
then we may get a lockup when idr_pre_get was called
in process context and an IRQ interrupted while it held
the idp lock.

This patch changes the spin_lock to spin_lock_irqsave,
and spin_unlock to spin_unlock_irqrestore, to allow
idr_get_new(), idr_find() and idr_remove() to be
called from IRQ context, while idr_pre_get() to be
called in process context.

Signed-off-by: Luben Tuikov <luben_tuikov@adaptec.com>

--- linux-2.6.12.5/lib/idr.c.old	2005-08-16 17:20:08.000000000 -0400
+++ linux-2.6.12.5/lib/idr.c	2005-08-16 17:22:16.000000000 -0400
@@ -37,27 +37,29 @@
 static struct idr_layer *alloc_layer(struct idr *idp)
 {
 	struct idr_layer *p;
+	unsigned long flags;
 
-	spin_lock(&idp->lock);
+	spin_lock_irqsave(&idp->lock, flags);
 	if ((p = idp->id_free)) {
 		idp->id_free = p->ary[0];
 		idp->id_free_cnt--;
 		p->ary[0] = NULL;
 	}
-	spin_unlock(&idp->lock);
+	spin_unlock_irqrestore(&idp->lock, flags);
 	return(p);
 }
 
 static void free_layer(struct idr *idp, struct idr_layer *p)
 {
+	unsigned long flags;
 	/*
 	 * Depends on the return element being zeroed.
 	 */
-	spin_lock(&idp->lock);
+	spin_lock_irqsave(&idp->lock, flags);
 	p->ary[0] = idp->id_free;
 	idp->id_free = p;
 	idp->id_free_cnt++;
-	spin_unlock(&idp->lock);
+	spin_unlock_irqrestore(&idp->lock, flags);
 }
 
 /**
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: [PATCH 2.6.12.5 1/2] lib: allow idr to be used in irq context
@ 2005-08-21 20:40 Luben Tuikov
  0 siblings, 0 replies; 18+ messages in thread
From: Luben Tuikov @ 2005-08-21 20:40 UTC (permalink / raw)
  To: James Bottomley, luben_tuikov
  Cc: Andrew Morton, Jim Houston, Linux Kernel, SCSI Mailing List,
	Dave Jones, Jeff Garzik

--- Luben Tuikov <luben_tuikov@adaptec.com> wrote:
> --- James Bottomley <James.Bottomley@SteelEye.com> wrote:
> > However, there is an infrastructure in the block layer called the
> > generic tag infrastructure which was designed precisely for this purpose
> > and which is designed to operate in IRQ context.
> 
> James, I'm sure you're well aware that,
>    - a request_queue is LU-bound,
>    - a SCSI _transport_ (*ANY*) can _only_ address domain devices, but
>      _not_ LUs.  LUs are *not* seen on the domain.

Another thing very important to mention is that the layering
infrastructure should _not_ be broken, whereby LLDD are required
to use block layer tags.

First, there may not be one to one correspondence accross layers.

Second, a tag on a layer identifies that particular _layer_ object.
It should not be used across layers or across several layers:
Block->Scsi Core->LLDD.

Third, although SCSI task tags are a SAM concept, they are defined
by the protocol in use and generated and assigned by the Initiator
port.  The block layer is _not_ an Initiator port.  SCSI Core is
also _not_ an Initiator port.

SCSI Core should be impervious to task tags, i.e. to the Q in
I_T_L_Q nexus.  The Q is never visible to it.

      Luben


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

end of thread, other threads:[~2005-08-23 17:15 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-16 22:03 [PATCH 2.6.12.5 1/2] lib: allow idr to be used in irq context Luben Tuikov
2005-08-17 16:01 ` Jim Houston
2005-08-21  8:25   ` Andrew Morton
2005-08-21 15:49     ` Luben Tuikov
2005-08-21 16:06       ` James Bottomley
2005-08-21 17:27         ` Luben Tuikov
2005-08-21 22:03           ` James Bottomley
2005-08-22  0:33             ` Luben Tuikov
2005-08-22  3:15               ` James Bottomley
2005-08-22  3:52                 ` Andrew Morton
2005-08-22 14:28                   ` James Bottomley
2005-08-22 16:51                     ` Luben Tuikov
2005-08-22 21:53                     ` James Bottomley
2005-08-22 22:09                       ` Andrew Morton
2005-08-23 17:15                         ` James Bottomley
2005-08-22 16:33                   ` Luben Tuikov
2005-08-22 14:06         ` Luben Tuikov
  -- strict thread matches above, loose matches on Subject: below --
2005-08-21 20:40 Luben Tuikov

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