From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751903AbcCAQfj (ORCPT ); Tue, 1 Mar 2016 11:35:39 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:48564 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751133AbcCAQfh (ORCPT ); Tue, 1 Mar 2016 11:35:37 -0500 Date: Tue, 1 Mar 2016 17:35:31 +0100 From: Peter Zijlstra To: Steven Rostedt Cc: LKML , Andrew Morton , Ingo Molnar Subject: Re: [PATCH] bug: Set warn variable before calling WARN() Message-ID: <20160301163531.GW6356@twins.programming.kicks-ass.net> References: <20160301110939.1b786f49@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160301110939.1b786f49@gandalf.local.home> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Peter Zijlstra (Intel)