lkml.org 
[lkml]   [2016]   [Mar]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] bug: Set warn variable before calling WARN()
    On Tue, Mar 01, 2016 at 11:09:39AM -0500, Steven Rostedt wrote:
    > This has hit me a couple of times already. I would be debugging code
    > and the system would simply hang and then reboot. Finally, I found that
    > the problem was caused by WARN_ON_ONCE() and friends.
    >
    > The macro WARN_ON_ONCE(condition) is defined as:
    >
    > static bool __section(.data.unlikely) __warned;
    > int __ret_warn_once = !!(condition);
    >
    > if (unlikely(__ret_warn_once))
    > if (WARN_ON(!__warned))
    > __warned = true;
    >
    > unlikely(__ret_warn_once);
    >
    > Which looks great and all. But what I have hit, is an issue when
    > WARN_ON() itself hits the same WARN_ON_ONCE() code. Because, the
    > variable __warned is not yet set. Then it too calls WARN_ON() and that
    > triggers the warning again. It keeps doing this until the stack is
    > overflowed and the system crashes.
    >
    > By setting __warned first before calling WARN_ON() makes the original
    > WARN_ON_ONCE() really only warn once, and not an infinite amount of
    > times if the WARN_ON() also triggers the warning.
    >
    > Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

    Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

    \
     
     \ /
      Last update: 2016-03-01 18:21    [W:3.225 / U:0.452 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site