From: Andrew Morton <akpm@osdl.org>
To: "Serge E. Hallyn" <serue@us.ibm.com>
Cc: hugh@veritas.com, serue@us.ibm.com, torvalds@osdl.org,
linux-kernel@vger.kernel.org
Subject: Re: please revert kthread from loop.c
Date: Tue, 11 Jul 2006 17:17:52 -0700 [thread overview]
Message-ID: <20060711171752.4993903a.akpm@osdl.org> (raw)
In-Reply-To: <20060711194932.GA27176@sergelap.austin.ibm.com>
"Serge E. Hallyn" <serue@us.ibm.com> wrote:
>
> Convert loop.c from the deprecated kernel_thread to kthread.
>
I think you have a racelet here:
> + }
> spin_unlock_irq(&lo->lo_lock);
>
> - BUG_ON(!bio);
> - loop_handle_bio(lo, bio);
> -
> - /*
> - * upped both for pending work and tear-down, lo_pending
> - * will hit zero then
> - */
> - if (unlikely(!pending))
> - break;
> + __set_current_state(TASK_INTERRUPTIBLE);
> + schedule();
> }
>
> - complete(&lo->lo_done);
> return 0;
> }
: if (kthread_should_stop()) {
: spin_unlock_irq(&lo->lo_lock);
: break;
: }
: spin_unlock_irq(&lo->lo_lock);
:
: __set_current_state(TASK_INTERRUPTIBLE);
: schedule();
:
If the wake_up_process() is delivered before the __set_current_state(),
we'll miss the wakeup.
If so, this should plug it. The same race is not possible against the
loop_set_fd() wakeup because the thread isn't running at that stage, yes?
diff -puN drivers/block/loop.c~kthread-convert-loopc-to-kthread-race-fix drivers/block/loop.c
--- a/drivers/block/loop.c~kthread-convert-loopc-to-kthread-race-fix
+++ a/drivers/block/loop.c
@@ -525,8 +525,8 @@ static int loop_make_request(request_que
goto out;
lo->lo_pending++;
loop_add_bio(lo, old_bio);
- spin_unlock_irq(&lo->lo_lock);
wake_up_process(lo->lo_thread);
+ spin_unlock_irq(&lo->lo_lock);
return 0;
out:
@@ -600,9 +600,8 @@ static int loop_thread(void *data)
spin_unlock_irq(&lo->lo_lock);
break;
}
- spin_unlock_irq(&lo->lo_lock);
-
__set_current_state(TASK_INTERRUPTIBLE);
+ spin_unlock_irq(&lo->lo_lock);
schedule();
}
_
next prev parent reply other threads:[~2006-07-12 0:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-26 18:39 Hugh Dickins
2006-06-27 5:46 ` Serge E. Hallyn
2006-06-28 18:41 ` Hugh Dickins
2006-06-28 19:08 ` Serge E. Hallyn
2006-07-11 19:49 ` Serge E. Hallyn
2006-07-12 0:17 ` Andrew Morton [this message]
2006-07-12 3:26 ` Serge E. Hallyn
2006-07-12 3:46 ` Andrew Morton
2006-07-12 14:31 ` Serge E. Hallyn
2006-07-12 23:02 ` Serge E. Hallyn
2006-07-13 9:38 ` Andrew Morton
2006-07-13 13:36 ` Serge E. Hallyn
2006-07-13 14:57 ` Andrew Morton
2006-07-20 17:00 ` Serge E. Hallyn
2006-07-12 15:13 ` Hugh Dickins
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=20060711171752.4993903a.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=hugh@veritas.com \
--cc=linux-kernel@vger.kernel.org \
--cc=serue@us.ibm.com \
--cc=torvalds@osdl.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®