Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752853AbcD0WBc (ORCPT ); Wed, 27 Apr 2016 18:01:32 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:62236 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750777AbcD0WBb (ORCPT ); Wed, 27 Apr 2016 18:01:31 -0400 From: Arnd Bergmann To: Martin Jambor Cc: "Martin K. Petersen" , James Bottomley , Josh Poimboeuf , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Denys Vlasenko , Thomas Graf , Peter Zijlstra , David Rientjes , Andrew Morton , Ingo Molnar , Himanshu Madhani , qla2xxx-upstream@qlogic.com, Jan Hubicka Subject: [PATCH, RFT] byteswap: try to avoid __builtin_constant_p gcc bug Date: Thu, 28 Apr 2016 00:00:36 +0200 Message-ID: <25937441.NbUvhTZ9vo@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <20160427110503.GB24887@virgil.suse.cz> References: <20160419085221.GA29087@gmail.com> <5298237.1Guzp0G04x@wuerfel> <20160427110503.GB24887@virgil.suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:2zqIQyJ+NHA8qeUEiNlJ8sShSi86gwzvAaVCw4Zla1qSVj89hWu juNVizlNSa2ogKkBcfgdta4+/nasDSluCxguMmKvKyRc0gODqq3KC4loVsNQqpoPs2EKN/D NLnALMN3a6BM1Ue/sJ+ndcKPYErIyu5DGs0j5T6fJ7gyhV0ogNME0mTgO9JYXNiqX4ndc7u lUVhSESsAuvpftJKm5JJw== X-UI-Out-Filterresults: notjunk:1;V01:K0:kW/BWjdAQRc=:6XHtl6AL7OhSBGq2QgdVDb xTBuwNZiQRFIK9CvlXMAEsgWZi3cmWJenBW01f63YQVe7m12yAgUgp9aI8xoyIMM16cwZMigy 3n6fL14xZl86wigN8m98ftHHGXZQ/17nTwV7J8AVMUVwk4R5C+aChrA2l9ExBzC8tZQsfzSXi dJMXy70XHu4lfuRp1KpXzaJsR2APZOs/U++qbjiefOcoyXN2RVsSVLDjrQ3Jb8WnXqfJbc093 UYevRYK62XPkpsEOxVmFO06RNmDqTpHIVbUT8PuwUM9P5cDLJV5v4GCiQ9dn44y7tYwTS95xY /1Os73/QWV8RLhXcyC7aQkfvGHQv/GyLgYPbo3Pq1Z2FDXUNJ+zgcbXyu/higUvrupE6UQdfl PYmZxClVnA42zFYUfbHuDE3z27G46RnwVpaSko2hvQai4DFcDABtODi6BndAQLrBYA4ZykEwb oXG4brYWY6wDrUHVx+6z1/wfuhAFYDAfPIbqLx/jLdqNMCvROz+N79mGE2T2ULmUOYCyuAObf VM/k+oDw0CB879dTvC+Mhp6u8/KdbQjsA1gPFQ6FzsRih5NcLeaou/JWwTuWAEzkObZBDBN75 p2KSi6BxFBfOsFkymX8+HWdbtYYqB3UqGwSxxXVDQeX+9gm/pf/4cnIJ253WlKhVkbSNDFpdn Rzoi5r8PD2z5GiFuPUswSkA61IqZbGniqf808EYk1oj1IuB0cZVOElF3KyB9/kHpeq2XHKpq1 O2C7owFIksjVz4Ef Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3026 Lines: 98 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. As part of the 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. I have not been able to reproduce the original problem, so I don't know if this patch solves it, but at least it leads to simpler code doing the same thing, so at least there should be no downsides. Please test. Signed-off-by: Arnd Bergmann diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h index 3f10e5317b46..de56fd54428d 100644 --- a/include/uapi/linux/swab.h +++ b/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 __fswab16(__u16 val) 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 __fswab32(__u32 val) 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 __fswahb32(__u32 val) * __swab16 - return a byteswapped 16-bit value * @x: value to byteswap */ +#ifdef __HAVE_BUILTIN_BSWAP16__ +#define __swab16(x) __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) __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) __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