linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Laura Abbott <labbott@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Jiri Slaby <jslaby@suse.cz>, John Stultz <john.stultz@linaro.org>
Subject: [PATCH 4.10 01/27] give up on gcc ilog2() constant optimizations
Date: Fri, 24 Mar 2017 18:58:19 +0100	[thread overview]
Message-ID: <20170324151226.050469549@linuxfoundation.org> (raw)
In-Reply-To: <20170324151225.973768798@linuxfoundation.org>

4.10-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Linus Torvalds <torvalds@linux-foundation.org>

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 <labbott@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>,
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 include/linux/log2.h       |   13 ++-----------
 tools/include/linux/log2.h |   13 ++-----------
 2 files changed, 4 insertions(+), 22 deletions(-)

--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -16,12 +16,6 @@
 #include <linux/bitops.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()
@@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(uns
 #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(uns
 		(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)				\
--- 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(uns
 #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(uns
 		(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)				\

  reply	other threads:[~2017-03-24 17:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 17:58 [PATCH 4.10 00/27] 4.10.6-stable review Greg Kroah-Hartman
2017-03-24 17:58 ` Greg Kroah-Hartman [this message]
2017-03-24 17:58 ` [PATCH 4.10 02/27] qla2xxx: Fix memory leak for abts processing Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 03/27] qla2xxx: Fix request queue corruption Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 04/27] parisc: Optimize flush_kernel_vmap_range and invalidate_kernel_vmap_range Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 05/27] parisc: support R_PARISC_SECREL32 relocation in modules Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 06/27] parisc: Fix system shutdown halt Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 07/27] perf/core: Fix use-after-free in perf_release() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 08/27] perf/core: Fix event inheritance on fork() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 09/27] md/r5cache: fix set_syndrome_sources() for data in cache Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 10/27] xprtrdma: Squelch kbuild sparse complaint Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 11/27] NFS prevent double free in async nfs4_exchange_id Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 12/27] cpufreq: Fix and clean up show_cpuinfo_cur_freq() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 13/27] powerpc/boot: Fix zImage TOC alignment Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 14/27] hwrng: omap - write registers after enabling the clock Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 15/27] hwrng: omap - use devm_clk_get() instead of of_clk_get() Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 16/27] hwrng: omap - Do not access INTMASK_REG on EIP76 Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 17/27] md/raid1/10: fix potential deadlock Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 18/27] target/pscsi: Fix TYPE_TAPE + TYPE_MEDIMUM_CHANGER export Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 19/27] scsi: lpfc: Add shutdown method for kexec Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 20/27] scsi: libiscsi: add lock around task lists to fix list corruption regression Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 21/27] scsi: mpt3sas: Avoid sleeping in interrupt context Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 22/27] target: Fix VERIFY_16 handling in sbc_parse_cdb Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 23/27] isdn/gigaset: fix NULL-deref at probe Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 24/27] gfs2: Avoid alignment hole in struct lm_lockname Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 25/27] percpu: acquire pcpu_lock when updating pcpu_nr_empty_pop_pages Greg Kroah-Hartman
2017-03-24 17:58 ` [PATCH 4.10 26/27] cgroup/pids: remove spurious suspicious RCU usage warning Greg Kroah-Hartman
2017-03-25  0:00 ` [PATCH 4.10 00/27] 4.10.6-stable review Shuah Khan
2017-03-26  8:19   ` Greg Kroah-Hartman
2017-03-25  4:18 ` Guenter Roeck
2017-03-26  8:51   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170324151226.050469549@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=john.stultz@linaro.org \
    --cc=jslaby@suse.cz \
    --cc=labbott@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).