From: Andrew Morton Subject: Re: [patch 14/14] byteswap: try to avoid __builtin_constant_p gcc bug Date: Thu, 5 May 2016 23:40:24 -0700 Message-ID: <20160505234024.2cc6be8b99984b58a0fb47ab@linux-foundation.org> References: <572bd5bf.t2mI2xihNNeJy8Ji%akpm@linux-foundation.org> <20160505223927.ae8e90df53ccabe2da5c818b@linux-foundation.org> Reply-To: linux-kernel@vger.kernel.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Received: from mail.linuxfoundation.org ([140.211.169.12]:39941 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757912AbcEFGk0 (ORCPT ); Fri, 6 May 2016 02:40:26 -0400 In-Reply-To: Sender: mm-commits-owner@vger.kernel.org List-Id: mm-commits@vger.kernel.org To: Linus Torvalds Cc: quinn.tran@qlogic.com, mm-commits@vger.kernel.org, hubicka@ucw.cz, mingo@kernel.org, jpoimboe@redhat.com, martin.petersen@oracle.com, dvlasenk@redhat.com, Thomas Graf , himanshu.madhani@qlogic.com, arnd@arndb.de, mjambor@suse.cz, peterz@infradead.org, James.Bottomley@hansenpartnership.com, rientjes@google.com It works for me, not for Stephen. http://marc.info/?l=linux-next&m=146251069526621&w=2 It's safest to revert for now, I think. We're chasing three different gcc glitches here. We'll presumably have it fixed up tomorrow but first someone will need to find a big-endian gcc which fails. On Thu, 5 May 2016 23:27:16 -0700 Linus Torvalds wrote: > Argh, too late, it's already there. > > I'd there possibly a simple fix, or should I revert? > > Linus > On May 5, 2016 22:39, "Andrew Morton" wrote: > > > Argh, please drop - Stephen just hit a build fail in linux-next. > > > > On Thu, 05 May 2016 16:22:39 -0700 akpm@linux-foundation.org wrote: > > > > > From: Arnd Bergmann > > > Subject: byteswap: try to avoid __builtin_constant_p gcc bug > > > > > > This is another attempt to avoid a regression in wwn_to_u64() after that > > > started using get_unaligned_be64(), which in turn ran into a bug on > > > gcc-4.9 through 6.1. > > > > > > The regression got introduced due to the combination of two separate > > > workarounds (e3bde9568d99 ("include/linux/unaligned: force inlining of > > > byteswap operations") and ef3fb2422ffe ("scsi: fc: use > > get/put_unaligned64 > > > for wwn access")) that each try to sidestep distinct problems with gcc > > > behavior (code growth and increased stack usage). Unfortunately after > > > both have been applied, a more serious gcc bug has been uncovered, > > leading > > > to incorrect object code that discards part of a function and causes > > > undefined behavior. > > > > > > As part of this problem is how __builtin_constant_p gets evaluated on an > > > argument passed by reference into an inline function, this avoids the use > > > of __builtin_constant_p() for all architectures that set > > > CONFIG_ARCH_USE_BUILTIN_BSWAP. Most architectures do not set > > > ARCH_SUPPORTS_OPTIMIZED_INLINING, which means they probably do not suffer > > > from the problem in the qla2xxx driver, but they might still run into it > > > elsewhere. > > > > > > Both of the original workarounds were only merged in the 4.6 kernel, and > > > the bug that is fixed by this patch should only appear if both are there, > > > so we probably don't need to backport the fix. On the other hand, it > > > works by simplifying the code path and should not have any negative > > > effects. > > > > > > [arnd@arndb.de: fix older gcc warnings] > > > (http://lkml.kernel.org/r/12243652.bxSxEgjgfk@wuerfel) > > > Link: https://lkml.org/lkml/headers/2016/4/12/1103 > > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122 > > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70232 > > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646 > > > Fixes: e3bde9568d99 ("include/linux/unaligned: force inlining of > > byteswap operations") > > > Fixes: ef3fb2422ffe ("scsi: fc: use get/put_unaligned64 for wwn access") > > > Link: http://lkml.kernel.org/r/1780465.XdtPJpi8Tt@wuerfel > > > Signed-off-by: Arnd Bergmann > > > Reviewed-by: Josh Poimboeuf > > > Tested-by: Josh Poimboeuf # on gcc-5.3 > > > Tested-by: Quinn Tran > > > Cc: Martin Jambor > > > Cc: "Martin K. Petersen" > > > Cc: James Bottomley > > > Cc: Denys Vlasenko > > > Cc: Thomas Graf > > > Cc: Peter Zijlstra > > > Cc: David Rientjes > > > Cc: Ingo Molnar > > > Cc: Himanshu Madhani > > > Cc: Jan Hubicka > > > Signed-off-by: Andrew Morton > > > --- > > > > > > include/uapi/linux/swab.h | 24 +++++++++++++++--------- > > > 1 file changed, 15 insertions(+), 9 deletions(-) > > > > > > diff -puN > > include/uapi/linux/swab.h~byteswap-try-to-avoid-__builtin_constant_p-gcc-bug-v2 > > include/uapi/linux/swab.h > > > --- > > a/include/uapi/linux/swab.h~byteswap-try-to-avoid-__builtin_constant_p-gcc-bug-v2 > > > +++ a/include/uapi/linux/swab.h > > > @@ -45,9 +45,7 @@ > > > > > > static inline __attribute_const__ __u16 __fswab16(__u16 val) > > > { > > > -#ifdef __HAVE_BUILTIN_BSWAP16__ > > > - return __builtin_bswap16(val); > > > -#elif defined (__arch_swab16) > > > +#if defined (__arch_swab16) > > > return __arch_swab16(val); > > > #else > > > return ___constant_swab16(val); > > > @@ -56,9 +54,7 @@ static inline __attribute_const__ __u16 > > > > > > static inline __attribute_const__ __u32 __fswab32(__u32 val) > > > { > > > -#ifdef __HAVE_BUILTIN_BSWAP32__ > > > - return __builtin_bswap32(val); > > > -#elif defined(__arch_swab32) > > > +#if defined(__arch_swab32) > > > return __arch_swab32(val); > > > #else > > > return ___constant_swab32(val); > > > @@ -67,9 +63,7 @@ static inline __attribute_const__ __u32 > > > > > > static inline __attribute_const__ __u64 __fswab64(__u64 val) > > > { > > > -#ifdef __HAVE_BUILTIN_BSWAP64__ > > > - return __builtin_bswap64(val); > > > -#elif defined (__arch_swab64) > > > +#if defined (__arch_swab64) > > > return __arch_swab64(val); > > > #elif defined(__SWAB_64_THRU_32__) > > > __u32 h = val >> 32; > > > @@ -102,28 +96,40 @@ static inline __attribute_const__ __u32 > > > * __swab16 - return a byteswapped 16-bit value > > > * @x: value to byteswap > > > */ > > > +#ifdef __HAVE_BUILTIN_BSWAP16__ > > > +#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) > > > +#else > > > #define __swab16(x) \ > > > (__builtin_constant_p((__u16)(x)) ? \ > > > ___constant_swab16(x) : \ > > > __fswab16(x)) > > > +#endif > > > > > > /** > > > * __swab32 - return a byteswapped 32-bit value > > > * @x: value to byteswap > > > */ > > > +#ifdef __HAVE_BUILTIN_BSWAP32__ > > > +#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x)) > > > +#else > > > #define __swab32(x) \ > > > (__builtin_constant_p((__u32)(x)) ? \ > > > ___constant_swab32(x) : \ > > > __fswab32(x)) > > > +#endif > > > > > > /** > > > * __swab64 - return a byteswapped 64-bit value > > > * @x: value to byteswap > > > */ > > > +#ifdef __HAVE_BUILTIN_BSWAP64__ > > > +#define __swab64(x) (__u64)__builtin_bswap64((__u64)(x)) > > > +#else > > > #define __swab64(x) \ > > > (__builtin_constant_p((__u64)(x)) ? \ > > > ___constant_swab64(x) : \ > > > __fswab64(x)) > > > +#endif > > > > > > /** > > > * __swahw32 - return a word-swapped 32-bit value > > > _ > >