From patchwork Wed Mar 18 16:51:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 45975 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4B5AF2153C for ; Wed, 18 Mar 2015 16:51:46 +0000 (UTC) Received: by lams18 with SMTP id s18sf8416877lam.2 for ; Wed, 18 Mar 2015 09:51:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=QLBnhis19qQ12URd7l4ndebK0FwCI1CZaJgHzixrv6A=; b=krmNQqRWI5CuqKzH+bU76Re3BwCgOpztshMz6apCgn+Cn7u+ZckpP3A+iZ39Kgv6Kx rcDX6QmzKbEhWge+ehq7L7B5KQlnYDcdXjJeWycSJo8u5SuKSzHGFPseqX4+Vc3uAt2E uGmIt63RRW9IAZjjVgrt1UQqy+8KEr1X78p6Wv3R/mT/Zld7KjWunJrUzgWoRZ89W4Lv ANugs18+dhjwItMpa6AVIA5fFHWa9g7yp4fiZZ1b98+opZ2Gf0Y+wxf+IpvK8ZN9rmH/ 8GVGFxdcTGojcP+MkIXPYNzCowDIpc4ABL2wJ0xSH2ZarqN11YEXgneyFMLkrruNyg09 yO6Q== X-Gm-Message-State: ALoCoQmBmkRJg5012nfNZtFZDGqFBJ2z8gK4lpurH0H9ZwhLB05Ey35UunED08N3cNFetT2UWYvn X-Received: by 10.152.6.41 with SMTP id x9mr11251596lax.10.1426697505316; Wed, 18 Mar 2015 09:51:45 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.104 with SMTP id r8ls171499lar.48.gmail; Wed, 18 Mar 2015 09:51:45 -0700 (PDT) X-Received: by 10.112.210.230 with SMTP id mx6mr34277346lbc.64.1426697505040; Wed, 18 Mar 2015 09:51:45 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id da11si13307646lad.115.2015.03.18.09.51.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Mar 2015 09:51:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by ladw1 with SMTP id w1so41154104lad.0 for ; Wed, 18 Mar 2015 09:51:45 -0700 (PDT) X-Received: by 10.152.206.70 with SMTP id lm6mr66384958lac.35.1426697504825; Wed, 18 Mar 2015 09:51:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1277313lbj; Wed, 18 Mar 2015 09:51:44 -0700 (PDT) X-Received: by 10.180.8.165 with SMTP id s5mr8623826wia.16.1426697504150; Wed, 18 Mar 2015 09:51:44 -0700 (PDT) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com. [209.85.212.177]) by mx.google.com with ESMTPS id lt4si4522640wic.104.2015.03.18.09.51.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Mar 2015 09:51:44 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.177 as permitted sender) client-ip=209.85.212.177; Received: by wixw10 with SMTP id w10so67049594wix.0 for ; Wed, 18 Mar 2015 09:51:43 -0700 (PDT) X-Received: by 10.194.142.205 with SMTP id ry13mr147422433wjb.73.1426697503874; Wed, 18 Mar 2015 09:51:43 -0700 (PDT) Received: from wychelm.lan (cpc4-aztw19-0-0-cust71.18-1.cable.virginm.net. [82.33.25.72]) by mx.google.com with ESMTPSA id gd6sm3899599wib.17.2015.03.18.09.51.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Mar 2015 09:51:43 -0700 (PDT) From: Daniel Thompson To: Arnd Bergmann Cc: Daniel Thompson , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal Subject: [PATCH] bug: Recursion avoidance for WARN_ONCE() and friends Date: Wed, 18 Mar 2015 16:51:27 +0000 Message-Id: <1426697487-2515-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.1.0 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Currently WARN_ONCE() and similar macros set __warned *after* calling the underlying macro. This risks infinite recursion if WARN_ONCE() is used to implement sanity tests in any code that can be called by printk. This can be fixed by restructuring the macros to set __warned before calling further macros. Signed-off-by: Daniel Thompson --- Notes: I discovered this problem when I temporarily added sanity tests to the irqflags macros during some of my development work but I suspect the scope is a little wider. I admit I was tempted to throw this change away after I had finished debugging but for two things prompted me to post it. 1. It did cost me a few minutes head scratching and I'd like to spare others the pain. 2. I realized the new code is potentially (and very fractionally) more efficient: the register containing address of __warned can be reused and a cache hit is a near certainty for the write. Don't get too excited about the efficiency gains though they are extremely modest. Measures as code size benefit and using v4.0-rc4 the results are: Kernel GCC version Code size reduction arm multi_v7_defconfig Linaro 4.8-2014.01 224 bytes arm64 defconfig Linaro 4.9-2014.09 32 bytes i386_defconfig Redhat 4.9.2-6 62 bytes x86_64_defconfig Redhat 4.9.2-6 380 bytes include/asm-generic/bug.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) -- 2.1.0 diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index 630dd2372238..f8c8a819c563 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -110,9 +110,10 @@ extern void warn_slowpath_null(const char *file, const int line); static bool __section(.data.unlikely) __warned; \ int __ret_warn_once = !!(condition); \ \ - if (unlikely(__ret_warn_once)) \ - if (WARN_ON(!__warned)) \ - __warned = true; \ + if (unlikely(__ret_warn_once) && !__warned) { \ + __warned = true; \ + WARN_ON(true); \ + } \ unlikely(__ret_warn_once); \ }) @@ -120,9 +121,10 @@ extern void warn_slowpath_null(const char *file, const int line); static bool __section(.data.unlikely) __warned; \ int __ret_warn_once = !!(condition); \ \ - if (unlikely(__ret_warn_once)) \ - if (WARN(!__warned, format)) \ - __warned = true; \ + if (unlikely(__ret_warn_once) && !__warned) { \ + __warned = true; \ + WARN(true, format); \ + } \ unlikely(__ret_warn_once); \ }) @@ -130,9 +132,10 @@ extern void warn_slowpath_null(const char *file, const int line); static bool __section(.data.unlikely) __warned; \ int __ret_warn_once = !!(condition); \ \ - if (unlikely(__ret_warn_once)) \ - if (WARN_TAINT(!__warned, taint, format)) \ - __warned = true; \ + if (unlikely(__ret_warn_once) && !__warned) { \ + __warned = true; \ + WARN_TAINT(true, taint, format); \ + } \ unlikely(__ret_warn_once); \ })