From: Luben Tuikov <luben_tuikov@adaptec.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
SCSI Mailing List <linux-scsi@vger.kernel.org>,
Dave Jones <davej@redhat.com>, Jeff Garzik <jgarzik@pobox.com>
Cc: Jim Houston <jim.houston@ccur.com>
Subject: [PATCH 2.4.12.5 1/2] lib: allow idr to be used in irq context
Date: Tue, 16 Aug 2005 17:55:50 -0400 [thread overview]
Message-ID: <430260E6.4090108@adaptec.com> (raw)
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);
}
/**
reply other threads:[~2005-08-16 21:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=430260E6.4090108@adaptec.com \
--to=luben_tuikov@adaptec.com \
--cc=davej@redhat.com \
--cc=jgarzik@pobox.com \
--cc=jim.houston@ccur.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).