All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Ruppert <christian.ruppert@abilis.com>
To: Vineet Gupta <Vineet.Gupta1@synopsys.com>
Cc: tglx@linutronix.de,
	Pierrick Hascoet <pierrick.hascoet@abilis.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] timer: Fix possible issues with non serialized timer_pending( )
Date: Wed, 3 Apr 2013 10:53:14 +0200	[thread overview]
Message-ID: <20130403085313.GA9321@ab42.lan> (raw)
In-Reply-To: <1364553218-31255-1-git-send-email-vgupta@synopsys.com>

We have tested the patch in several configurations and boards using
tests which previously crashed the kernel in less than an hour. The
crashes in question could not be reproduced in long term tests (3 days)
and nightly tests with the patch. I can thus confirm that this fixes a
real issue.

On Fri, Mar 29, 2013 at 04:03:38PM +0530, Vineet Gupta wrote:
> When stress testing ARC Linux from 3.9-rc3, we've hit a serialization
> issue when mod_timer() races with itself. This is on a FPGA board and
> kernel .config among others has !SMP and !PREEMPT_COUNT.
> 
> The issue happens in mod_timer( ) because timer_pending( ) based early
> exit check is NOT done inside the timer base spinlock - as a networking
> optimization.
> 
> The value used in there, timer->entry.next is also used further in call
> chain (all inlines though) for actual list manipulation. However if the
> register containing this pointer remains live across the spinlock (in a
> UP setup with !PREEMPT_COUNT there's nothing forcing gcc to reload) then
> a stale value of next pointer causes incorrect list manipulation,
> observed with following sequence in our tests.
> 
> [...]
> 
> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
> Reported-by: Christian Ruppert <christian.ruppert@abilis.com>
Tested-by: Christian Ruppert <christian.ruppert@abilis.com>

> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Christian Ruppert <christian.ruppert@abilis.com>
> Cc: Pierrick Hascoet <pierrick.hascoet@abilis.com>
> Cc: linux-kernel@vger.kernel.org
> ---
>  include/linux/timer.h |   11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/timer.h b/include/linux/timer.h
> index 8c5a197..1537104 100644
> --- a/include/linux/timer.h
> +++ b/include/linux/timer.h
> @@ -168,7 +168,16 @@ static inline void init_timer_on_stack_key(struct timer_list *timer,
>   */
>  static inline int timer_pending(const struct timer_list * timer)
>  {
> -	return timer->entry.next != NULL;
> +	int pending = timer->entry.next != NULL;
> +
> +	/*
> +	 * The check above enables timer fast path - early exit.
> +	 * However most of the call sites are not protected by timer->base
> +	 * spinlock. If the caller (say mod_timer) races with itself, it
> +	 * can use the stale "next" pointer. See commit log for details.
> +	 */
> +	barrier();
> +	return pending;
>  }
>  
>  extern void add_timer_on(struct timer_list *timer, int cpu);
> -- 
> 1.7.10.4
> 

-- 
  Christian Ruppert              ,          <christian.ruppert@abilis.com>
                                /|
  Tel: +41/(0)22 816 19-42     //|                 3, Chemin du Pré-Fleuri
                             _// | bilis Systems   CH-1228 Plan-les-Ouates

  parent reply	other threads:[~2013-04-03  9:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-29 10:33 [PATCH] timer: Fix possible issues with non serialized timer_pending( ) Vineet Gupta
2013-04-03  7:20 ` Vineet Gupta
2013-04-03  8:53 ` Christian Ruppert [this message]
2013-04-03 12:36 ` Thomas Gleixner
2013-04-03 13:03   ` Christian Ruppert
2013-04-03 13:10     ` [RFC] Add implicit barriers to irqsave/restore class of functions Christian Ruppert
2013-04-03 13:29       ` Vineet Gupta
2013-04-04  8:26         ` Christian Ruppert
2013-04-04 16:13       ` Peter Zijlstra
2013-04-05  4:27         ` Vineet Gupta
2013-04-03 14:11   ` [PATCH] [PATCH] Gaurantee spinlocks implicit barrier for !PREEMPT_COUNT Vineet Gupta
2013-04-04 15:28     ` Christian Ruppert
2013-04-05  4:36       ` Vineet Gupta
2013-04-06 13:34         ` Vineet Gupta
2013-04-06 16:13           ` Linus Torvalds
2013-04-06 18:01             ` Linus Torvalds
2013-04-06 19:54               ` Jacquiot, Aurelien
2013-04-06 19:54                 ` Jacquiot, Aurelien
2013-04-09 16:33               ` [PATCH] tile: comment assumption about __insn_mtspr for <asm/irqflags.h> Chris Metcalf
2013-04-09 16:33                 ` Chris Metcalf
2013-04-08  4:20             ` [PATCH] [PATCH] Gaurantee spinlocks implicit barrier for !PREEMPT_COUNT Vineet Gupta
2013-04-08  4:48               ` Linus Torvalds
2013-04-08 13:37                 ` Peter Zijlstra
2013-04-08 14:31                   ` Steven Rostedt
2013-04-08 14:50                     ` Linus Torvalds
2013-04-08 14:59                       ` Steven Rostedt
2013-04-08 15:07                         ` Linus Torvalds
2013-04-09 14:32                           ` Linus Torvalds
2013-04-10  7:12                             ` Peter Zijlstra
2013-04-08 14:05                 ` Steven Rostedt
2013-04-08  4:49               ` Linus Torvalds

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=20130403085313.GA9321@ab42.lan \
    --to=christian.ruppert@abilis.com \
    --cc=Vineet.Gupta1@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pierrick.hascoet@abilis.com \
    --cc=tglx@linutronix.de \
    /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.