Messages in this thread Patch in this message | | | Date | Sun, 26 Sep 2010 14:53:54 +0300 | From | Michael Shigorin <> | Subject | Re: fs hang in 2.6.27.y | Fwd: [Bug 15658] New: [PATCH] x86 constant_test_bit() prone to misoptimization with gcc-4.4 |
| |
On Thu, Sep 23, 2010 at 04:50:22PM -0700, Andrew Morton wrote: > Working around a gcc-4.4 bug is a good thing, and the patch cleans the > code up anyway - is there a reason for casting away the `volatile const'?
It turned out that I translated the original assumption of _gcc_ fault (from our bugzilla) when the latter conclusion was that it was correctly optimizing the code given that addr wasn't marked as volatile. My fault, sorry; fixed the commit comment this time.
> I changed the patch cosmetics a bit, see below. > We don't have a Signed-off-by: for this patch - it would be > good to have one, please. We should at least have yours, as > you sent the patch.
The simplicity of adding that somewhat went over my head -- please find attached the corrected original patch against HEAD with Signed-off-by: for both of us. led@ didn't change cosmetics -- thanks for providing it anyways.
> Also, we prefer to have real names in kernel commits. > Does "Led" refer to Alexander Chumachenko?
(just in case) Yes.
-- ---- WBR, Michael Shigorin <mike@altlinux.ru> ------ Linux.Kiev http://www.linux.kiev.ua/ From 70e6a20b3720e522633f4b791f2f35e817d7ced3 Mon Sep 17 00:00:00 2001 From: Led <ledest@gmail.com> Date: Thu, 1 Apr 2010 15:34:52 +0300 Subject: [PATCH] x86: avoid 'constant_test_bit()' misoptimization due to cast to non-volatile
While debugging bit_spin_lock() hang, it was tracked down to gcc-4.4 misoptimization of non-inlined constant_test_bit() due to non-volatile addr when 'const volatile unsigned long *addr' cast to 'unsigned long *' with subsequent unconditional jump to pause (and not to the test) leading to hang.
Compiling with gcc-4.3 or disabling CONFIG_OPTIMIZE_INLINING yields inlined constant_test_bit() and correct jump, thus working around the kernel bug.
Other arches than asm-x86 may implement this slightly differently; 2.6.29 mitigates the misoptimization by changing the function prototype (commit c4295fbb6048d85f0b41c5ced5cbf63f6811c46c) but probably fixing the issue itself is better.
Signed-off-by: Alexander Chumachenko <ledest@gmail.com> Signed-off-by: Michael Shigorin <mike@osdn.org.ua>
--- arch/x86/include/asm/bitops.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h index 545776e..bafd80d 100644 --- a/arch/x86/include/asm/bitops.h +++ b/arch/x86/include/asm/bitops.h @@ -309,7 +309,7 @@ static inline int test_and_change_bit(int nr, volatile unsigned long *addr) static __always_inline int constant_test_bit(unsigned int nr, const volatile unsigned long *addr) { return ((1UL << (nr % BITS_PER_LONG)) & - (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; + (addr[nr / BITS_PER_LONG])) != 0; } static inline int variable_test_bit(int nr, volatile const unsigned long *addr) -- 1.7.2.3 [unhandled content-type:application/pgp-signature] | |