From: Ron Niles <Ron.Niles@falconstor.com>
To: linux-kernel@vger.kernel.org
Subject: Oops from local semaphore race condition
Date: Mon, 20 May 2002 20:11:57 -0400 [thread overview]
Message-ID: <E79B8AB303080F4096068F046CD1D89B934C94@exchange1.FalconStor.Net> (raw)
Many places in the kernel (mostly drivers, like in scsi_error.c,
scsi_sleep()) have the following construct:
void function(void)
{
DECLARE_MUTEX_LOCKED(sem);
/* let another thread do the work and up() when done */
notify_handler(&sem);
down(&sem);
}
I have used this construct very often and under stress testing my driver got
a few Oops in __up_wakeup, as if the semaphore went corrupt. Then I realized
it can possibly go corrupt, due to a race condition which lets down()
continue before up() is complete:
down decrements sem->counter to -1
up increments sem->counter to 0
down enters __down, but does not sleep since sem->counter has already been
incremented
up enters __up, tries to wake_up(&sem->wait) but sem is now garbage since
function has exited.
I think this race is possible only on SMP. This problem seems to show up
more if I have heavy irq activity which I guess will interrupt down()
between the --sem->counter and __down(), and also interrupt up() between
++sem->counter and __up().
I am interested in some opinions:
(1) does the following up_atomic() function instead of up() indeed fix the
race condition?
(2) it is worthwile to put it into semaphore.c and semaphore.h?
(3) is it worthwhile to fix the condition in scsi modules and other drivers
that do this?
void up_atomic(struct semaphore *sem)
{
spin_lock_irq(&semaphore_lock);
up(sem);
spin_unlock_irq(&semaphore_lock);
}
next reply other threads:[~2002-05-21 0:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-21 0:11 Ron Niles [this message]
2002-05-21 12:26 ` David Woodhouse
2002-05-21 19:41 Ron Niles
2002-05-21 21:16 ` Bob Miller
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=E79B8AB303080F4096068F046CD1D89B934C94@exchange1.FalconStor.Net \
--to=ron.niles@falconstor.com \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®