From patchwork Wed Apr 22 12:54:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 47414 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D0BCD2121F for ; Wed, 22 Apr 2015 12:54:35 +0000 (UTC) Received: by wgiv13 with SMTP id v13sf51860975wgi.3 for ; Wed, 22 Apr 2015 05:54:35 -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:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=QLBnhis19qQ12URd7l4ndebK0FwCI1CZaJgHzixrv6A=; b=WPscb2lV84bfT7ERj15snRsAbAT5GUCvsiKilriqhK9PWOECYfisH9SnX1ln+f8wej 6mH2MzduncOh6AENepVdoGT87Jc3SmEhMmwBSiowZECZaXmFUEH2BOc1AKw/9pnq0Oo7 Xwy6g9I8qhj5U9Y9HgvosE8JEy5nEL7+6IJUGoE9mj4S32j0YOpcfu608AWxxDxuGhGO DzFN/bAlyqj7pHGrodw3HXxgxTXvw0W+Ewxk5a/ghfvAGHu+FDr7mZyhcL7U7sS1+1tv Y39NYa9chVLg1v00tdtx7N0JEIPRlfz1FGb/BP2SggMcoe/j0DvmgoXe3G6nzOiFfU5A jvBw== X-Gm-Message-State: ALoCoQmHdnwfiVYY1JVZBVBWcty1dDVSc5P3qm+/W4ItkwjfOYPf0ckPS7FW4JPYPgODNCDipy8C X-Received: by 10.180.106.136 with SMTP id gu8mr1429383wib.6.1429707275170; Wed, 22 Apr 2015 05:54:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.204 with SMTP id ba12ls189266lab.41.gmail; Wed, 22 Apr 2015 05:54:35 -0700 (PDT) X-Received: by 10.113.10.134 with SMTP id ea6mr24306502lbd.29.1429707275014; Wed, 22 Apr 2015 05:54:35 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id r7si3711126laa.83.2015.04.22.05.54.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2015 05:54:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbqq2 with SMTP id qq2so179156357lbb.3 for ; Wed, 22 Apr 2015 05:54:34 -0700 (PDT) X-Received: by 10.112.198.74 with SMTP id ja10mr12895410lbc.19.1429707274795; Wed, 22 Apr 2015 05:54:34 -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.67.65 with SMTP id l1csp1247216lbt; Wed, 22 Apr 2015 05:54:34 -0700 (PDT) X-Received: by 10.194.157.39 with SMTP id wj7mr51181827wjb.57.1429707273945; Wed, 22 Apr 2015 05:54:33 -0700 (PDT) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com. [209.85.212.182]) by mx.google.com with ESMTPS id do5si8926323wib.50.2015.04.22.05.54.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2015 05:54:33 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.212.182 as permitted sender) client-ip=209.85.212.182; Received: by wiun10 with SMTP id n10so56100005wiu.1 for ; Wed, 22 Apr 2015 05:54:33 -0700 (PDT) X-Received: by 10.194.7.97 with SMTP id i1mr51709322wja.107.1429707273693; Wed, 22 Apr 2015 05:54:33 -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 i13sm24320296wic.13.2015.04.22.05.54.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2015 05:54:32 -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: [RESEND PATCH] bug: Recursion avoidance for WARN_ONCE() and friends Date: Wed, 22 Apr 2015 13:54:17 +0100 Message-Id: <1429707257-9591-1-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1426697487-2515-1-git-send-email-daniel.thompson@linaro.org> References: <1426697487-2515-1-git-send-email-daniel.thompson@linaro.org> 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.217.170 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); \ })