public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Shigorin <mike@osdn.org.ua>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"Volodymyr G. Lukiianyk" <volodymyrgl@gmail.com>,
	Alexander Chumachenko <ledest@gmail.com>,
	Glauber de Oliveira Costa <gcosta@redhat.com>
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
Date: Sun, 26 Sep 2010 14:53:54 +0300	[thread overview]
Message-ID: <20100926115354.GA30247@osdn.org.ua> (raw)
In-Reply-To: <20100923165022.6982ffc1.akpm@linux-foundation.org>


[-- Attachment #1.1: Type: text/plain, Size: 1146 bytes --]

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/

[-- Attachment #1.2: 0001-x86-avoid-constant_test_bit-misoptimization-due-to-c.patch --]
[-- Type: text/plain, Size: 1773 bytes --]

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


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  parent reply	other threads:[~2010-09-26 11:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-27 21:36 fs hang in 2.6.27.y | Fwd: [Bug 15658] New: [PATCH] x86 constant_test_bit() prone to misoptimization with gcc-4.4 Michael Shigorin
2010-09-23 23:50 ` Andrew Morton
2010-09-24  7:05   ` Michael Shigorin
2010-09-26 11:53   ` Michael Shigorin [this message]
2010-09-26 17:00     ` Linus Torvalds
2010-09-26 20:19       ` H. Peter Anvin
2010-09-27  4:27       ` H. Peter Anvin

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=20100926115354.GA30247@osdn.org.ua \
    --to=mike@osdn.org.ua \
    --cc=akpm@linux-foundation.org \
    --cc=gcosta@redhat.com \
    --cc=hpa@zytor.com \
    --cc=ledest@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=volodymyrgl@gmail.com \
    /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