From: David Woodhouse <dwmw2@infradead.org>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: Races in sleep_on()
Date: Thu, 22 Jan 2004 12:57:52 +0000 [thread overview]
Message-ID: <1074776272.28136.64.camel@hades.cambridge.redhat.com> (raw)
In-Reply-To: <20040122005436.5895d7bb.akpm@osdl.org>
On Thu, 2004-01-22 at 00:54 -0800, Andrew Morton wrote:
> > Yes. That's why I advocated the BUG_ON(!BKL) a _long_ time ago. Arjan
> > had a huge list of bogus callers even in 2.4.
>
> So... do me a patch which does a WARN_ON()? Make sure that it shuts
> itself up after the first five messages so people don't hate us too much.
>
> To get best coverage you'll need to make the !CONFIG_SMP&&!CONFIG_PREEMPT
> version of lock_kernel() set a flag or something.
Since the spinlock is a NOP anyway there doesn't seem to be any harm in
just letting the UP version use the same code as the SMP/PREEMPT
versions.
I've done the _timeout versions too, despite the frequent whinge that
'it's OK if we miss wakeups because we time out eventually anyway'. That
argument was never acceptable to me anyway.
===== include/linux/smp_lock.h 1.7 vs edited =====
--- 1.7/include/linux/smp_lock.h Mon Jan 19 23:38:11 2004
+++ edited/include/linux/smp_lock.h Thu Jan 22 09:15:17 2004
@@ -5,7 +5,9 @@
#include <linux/sched.h>
#include <linux/spinlock.h>
-#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
+#define BKL_DEBUG /* For testing for sleep_on() abuse */
+
+#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT) || defined(BKL_DEBUG)
extern spinlock_t kernel_flag;
===== kernel/sched.c 1.236 vs edited =====
--- 1.236/kernel/sched.c Mon Jan 19 23:38:12 2004
+++ edited/kernel/sched.c Thu Jan 22 10:49:55 2004
@@ -1903,10 +1903,21 @@
__remove_wait_queue(q, &wait); \
spin_unlock_irqrestore(&q->lock, flags);
+#define SLEEP_ON_BKLCHECK \
+ if (unlikely(!kernel_locked()) && \
+ sleep_on_bkl_warnings < 10) { \
+ sleep_on_bkl_warnings++; \
+ WARN_ON(1); \
+ }
+
+static int sleep_on_bkl_warnings;
+
void interruptible_sleep_on(wait_queue_head_t *q)
{
SLEEP_ON_VAR
+ SLEEP_ON_BKLCHECK
+
current->state = TASK_INTERRUPTIBLE;
SLEEP_ON_HEAD
@@ -1920,6 +1931,8 @@
{
SLEEP_ON_VAR
+ SLEEP_ON_BKLCHECK
+
current->state = TASK_INTERRUPTIBLE;
SLEEP_ON_HEAD
@@ -1935,6 +1948,8 @@
{
SLEEP_ON_VAR
+ SLEEP_ON_BKLCHECK
+
current->state = TASK_UNINTERRUPTIBLE;
SLEEP_ON_HEAD
@@ -1947,6 +1962,8 @@
long sleep_on_timeout(wait_queue_head_t *q, long timeout)
{
SLEEP_ON_VAR
+
+ SLEEP_ON_BKLCHECK
current->state = TASK_UNINTERRUPTIBLE;
--
dwmw2
parent reply other threads:[~2004-01-22 12:58 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20040122005436.5895d7bb.akpm@osdl.org>]
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=1074776272.28136.64.camel@hades.cambridge.redhat.com \
--to=dwmw2@infradead.org \
--cc=akpm@osdl.org \
--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®