From patchwork Tue May 9 20:08:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khem Raj X-Patchwork-Id: 98954 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp1999607qge; Tue, 9 May 2017 13:09:01 -0700 (PDT) X-Received: by 10.84.216.21 with SMTP id m21mr2700114pli.116.1494360541721; Tue, 09 May 2017 13:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494360541; cv=none; d=google.com; s=arc-20160816; b=U29hbwKs1PbnS8edZCj5fQuT92C5uF+E/XJoqes+XvI1OzkCxQqN1ehsWYOL2g0C4W yjhl4QVnALG0LD9S94UUujbkKeOqCRHj9ojiXl1fHmxnRb+TLz/kW6U1/oQkWR5bGUPX dIpPKvlfPQx11sXDzCKQh+ihUgWfurBFbzgVsuhVYPxBCRjulTZ1q4Hd3nUZ3uCEp3UD lZDMPqb+XB0+J+HfrPr+8HAO13DaDVUX3PM/8y8dcwHd7s8QRhZIrGEsE6/JMN82PtCj aTxbFpswy7fN0dkbkAFmOGD0CAd/7QtOk+PRVt4ZMJ1ZsDRO2fcKEGMT7XF4rVeb0jss EkUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Gxev7v2AkrKjVNaADrTCqhQ++QWGMiYXA+BbWxisUSw=; b=03g5dthLLM0+APVa/rZa00JAdo4LOjLgUi26g5TlH4kt0o1G36R7AwtHEDjF3FrnHo NwpB1M6lS9lh9agwiJYmZM0ysrRkMV1Hm8h/Ypmz5VPkaW0CzPtxnGt0y/KCB0ImoD5W EU2dufqXUmm/Hp0dzQv7FWVCK5tVb/eeDfZGbJsqP8YlgGZAm8Mex5ggr9NenQZG2LfL HB7Bh3NtvjO5cSXlxaAv9//Buvx9u6KA7uhNV2I5tT1TIo+9+Yk5ZH413d60iidIsFLI FsNEhRTLtBY/5jlJx2haD4zKpSK0TzgHQfNCTGx2Pa4BJ6Ht2HBYFq7OAxcNU4RkW4/c bD+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t76si824305pgc.115.2017.05.09.13.09.01; Tue, 09 May 2017 13:09:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751095AbdEIUJA (ORCPT + 6 others); Tue, 9 May 2017 16:09:00 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36196 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750858AbdEIUI7 (ORCPT ); Tue, 9 May 2017 16:08:59 -0400 Received: by mail-pg0-f65.google.com with SMTP id 64so1209277pgb.3; Tue, 09 May 2017 13:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Gxev7v2AkrKjVNaADrTCqhQ++QWGMiYXA+BbWxisUSw=; b=h3rzNGYdpt359o4JP+A353LRAoZ3GB4oRZVD4A3HsqYJqP5eHm3aS4YShzRPWuhzxz CmxDLDAYBP74kNgBU7Imc1Y3eZCoCwYAQmnI7+FdSVSyV6LXm5SWqLuuP5Br2XXcUmCk Tzs40hss+C6auA2i7hvg568kRrt19LVxkXaPmBCenDVCa6HOp6Qn9BsYC26rJqgKEA9b UZp6+3Qc/gn4gsbGv5kW/DFySemZQusJIDbac88ZrNb7y2MXWi9j7+ypD+iX8KN4ovVH DYjTz7K+BypZLTKNETZyGM6egSntSXv+gRyY7x7MhYPGBvzHCwA6WP/D+hT5rAOnkUZI qntw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Gxev7v2AkrKjVNaADrTCqhQ++QWGMiYXA+BbWxisUSw=; b=eVZXTmcKMEiIm3M/PsROvDsqDHDiIaUCLl5LmutYnk+Od29uASTeEfRgL8fzeg4FUX 12IuKE7psqy1vuMOvEAkMAHbKATuahxqO4wFdcufjq6FQmg1EppDHFCazAbb0Q3Ei2wp NY0ntErJ6Z/vgJJizvbNmEBNTPRxQ0oavC4LzaQLWWFumpfeqgmnQAqc+/+WPsf6YMlR itP2uhbHYuwHx9jnl9J+rZ+s6ck+D6BeM0sTGV2d7IOpuE0nkpLcV5G+odqwFPhsNDjY PPIhp93S66ncRCVyvLhxETmax8V3bPnrQnomkRIuiwpryWjKcutIwFLySw2QRsdUj0J5 WfMQ== X-Gm-Message-State: AODbwcB7mQa9xARndECh8fS2Ov5EwqS4AKW2Vvu5S+2SA2M5y7w4dAbc h+xSJW8bUYU4xQ== X-Received: by 10.98.200.142 with SMTP id i14mr1957512pfk.154.1494360539058; Tue, 09 May 2017 13:08:59 -0700 (PDT) Received: from localhost.localdomain ([2601:646:8882:b8c::c232]) by smtp.gmail.com with ESMTPSA id t198sm1440147pgc.33.2017.05.09.13.08.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 May 2017 13:08:57 -0700 (PDT) From: Khem Raj To: linux-kernel@vger.kernel.org Cc: Linus Torvalds , John Stultz , Thomas Gleixner , Ard Biesheuvel , Jiri Slaby , Greg Kroah-Hartman , Khem Raj , stable@vger.kernel.org Subject: [PATCH 4.1] give up on gcc ilog2() constant optimizations Date: Tue, 9 May 2017 13:08:30 -0700 Message-Id: <20170509200830.5803-1-raj.khem@gmail.com> X-Mailer: git-send-email 2.12.2 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Linus Torvalds commit 474c90156c8dcc2fa815e6716cc9394d7930cb9c upstream. gcc-7 has an "optimization" pass that completely screws up, and generates the code expansion for the (impossible) case of calling ilog2() with a zero constant, even when the code gcc compiles does not actually have a zero constant. And we try to generate a compile-time error for anybody doing ilog2() on a constant where that doesn't make sense (be it zero or negative). So now gcc7 will fail the build due to our sanity checking, because it created that constant-zero case that didn't actually exist in the source code. There's a whole long discussion on the kernel mailing about how to work around this gcc bug. The gcc people themselevs have discussed their "feature" in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72785 but it's all water under the bridge, because while it looked at one point like it would be solved by the time gcc7 was released, that was not to be. So now we have to deal with this compiler braindamage. And the only simple approach seems to be to just delete the code that tries to warn about bad uses of ilog2(). So now "ilog2()" will just return 0 not just for the value 1, but for any non-positive value too. It's not like I can recall anybody having ever actually tried to use this function on any invalid value, but maybe the sanity check just meant that such code never made it out in public. Reported-by: Laura Abbott Cc: John Stultz , Cc: Thomas Gleixner Cc: Ard Biesheuvel Signed-off-by: Linus Torvalds Cc: Jiri Slaby Signed-off-by: Greg Kroah-Hartman Signed-off-by: Khem Raj Cc: # v4.1+ --- include/linux/log2.h | 13 ++----------- tools/include/linux/log2.h | 13 ++----------- 2 files changed, 4 insertions(+), 22 deletions(-) -- 2.12.2 diff --git a/include/linux/log2.h b/include/linux/log2.h index fd7ff3d91e6a..f38fae23bdac 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h @@ -16,12 +16,6 @@ #include /* - * deal with unrepresentable constant logarithms - */ -extern __attribute__((const, noreturn)) -int ____ilog2_NaN(void); - -/* * non-constant log of base 2 calculators * - the arch may override these in asm/bitops.h if they can be implemented * more efficiently than using fls() and fls64() @@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) #define ilog2(n) \ ( \ __builtin_constant_p(n) ? ( \ - (n) < 1 ? ____ilog2_NaN() : \ + (n) < 2 ? 0 : \ (n) & (1ULL << 63) ? 63 : \ (n) & (1ULL << 62) ? 62 : \ (n) & (1ULL << 61) ? 61 : \ @@ -148,10 +142,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) (n) & (1ULL << 4) ? 4 : \ (n) & (1ULL << 3) ? 3 : \ (n) & (1ULL << 2) ? 2 : \ - (n) & (1ULL << 1) ? 1 : \ - (n) & (1ULL << 0) ? 0 : \ - ____ilog2_NaN() \ - ) : \ + 1 ) : \ (sizeof(n) <= 4) ? \ __ilog2_u32(n) : \ __ilog2_u64(n) \ diff --git a/tools/include/linux/log2.h b/tools/include/linux/log2.h index 41446668ccce..d5677d39c1e4 100644 --- a/tools/include/linux/log2.h +++ b/tools/include/linux/log2.h @@ -13,12 +13,6 @@ #define _TOOLS_LINUX_LOG2_H /* - * deal with unrepresentable constant logarithms - */ -extern __attribute__((const, noreturn)) -int ____ilog2_NaN(void); - -/* * non-constant log of base 2 calculators * - the arch may override these in asm/bitops.h if they can be implemented * more efficiently than using fls() and fls64() @@ -78,7 +72,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) #define ilog2(n) \ ( \ __builtin_constant_p(n) ? ( \ - (n) < 1 ? ____ilog2_NaN() : \ + (n) < 2 ? 0 : \ (n) & (1ULL << 63) ? 63 : \ (n) & (1ULL << 62) ? 62 : \ (n) & (1ULL << 61) ? 61 : \ @@ -141,10 +135,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) (n) & (1ULL << 4) ? 4 : \ (n) & (1ULL << 3) ? 3 : \ (n) & (1ULL << 2) ? 2 : \ - (n) & (1ULL << 1) ? 1 : \ - (n) & (1ULL << 0) ? 0 : \ - ____ilog2_NaN() \ - ) : \ + 1 ) : \ (sizeof(n) <= 4) ? \ __ilog2_u32(n) : \ __ilog2_u64(n) \