From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Nicolas Pitre <nico@cam.org>
Cc: Linus Torvalds <torvalds@osdl.org>,
Russell King <rmk@arm.linux.org.uk>,
lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] fix race with preempt_enable()
Date: Thu, 22 Dec 2005 18:09:15 +1100 [thread overview]
Message-ID: <43AA511B.9040400@yahoo.com.au> (raw)
In-Reply-To: <Pine.LNX.4.64.0512211135550.26663@localhost.localdomain>
Nicolas Pitre wrote:
> Currently a simple
>
> void foo(void) { preempt_enable(); }
>
> produces the following code on ARM:
>
> foo:
> bic r3, sp, #8128
> bic r3, r3, #63
> ldr r2, [r3, #4]
> ldr r1, [r3, #0]
> sub r2, r2, #1
> tst r1, #4
> str r2, [r3, #4]
> blne preempt_schedule
> mov pc, lr
>
> The problem is that the TIF_NEED_RESCHED flag is loaded _before_ the
> preemption count is stored back, hence any interrupt coming within that
> 3 instruction window causing TIF_NEED_RESCHED to be set won't be
> seen and scheduling won't happen as it should.
>
> Nothing currently prevents gcc from performing that reordering. There
> is already a barrier() before the decrement of the preemption count, but
> another one is needed between this and the TIF_NEED_RESCHED flag test
> for proper code ordering.
>
Nice catch, this is not ARM specific either of course.
kernel/sched.c:preempt_schedule() has an equivalent barrier after
subtracting the preempt count and before checking TIF_NEED_RESCHED,
so I think this is the correct fix.
Linus will you apply?
> Signed-off-by: Nicolas Pitre <nico@cam.org>
>
> ---
>
> diff --git a/include/linux/preempt.h b/include/linux/preempt.h
> index d9a2f52..5769d14 100644
> --- a/include/linux/preempt.h
> +++ b/include/linux/preempt.h
> @@ -48,6 +48,7 @@ do { \
> #define preempt_enable() \
> do { \
> preempt_enable_no_resched(); \
> + barrier(); \
> preempt_check_resched(); \
> } while (0)
>
--
SUSE Labs, Novell Inc.
Send instant messages to your online friends http://au.messenger.yahoo.com
prev parent reply other threads:[~2005-12-22 7:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-21 17:26 [PATCH] fix race with preempt_enable() Nicolas Pitre
2005-12-22 7:09 ` Nick Piggin [this message]
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=43AA511B.9040400@yahoo.com.au \
--to=nickpiggin@yahoo.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=nico@cam.org \
--cc=rmk@arm.linux.org.uk \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.