From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Schwidefsky Subject: Re: compiler bug gcc4.6/4.7 with ACCESS_ONCE and workarounds Date: Wed, 12 Nov 2014 10:28:24 +0100 Message-ID: <20141112102824.55a4c178@mschwide> References: <1415360716-9670-2-git-send-email-borntraeger@de.ibm.com> <54611D86.4040306@de.ibm.com> <54627CBF.2000704@de.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Linus Torvalds Cc: Christian Borntraeger , Paul McKenney , Ingo Molnar , Paolo Bonzini , KVM , Linux Kernel Mailing List , Heiko Carstens , Andreas Krebbel , Cornelia Huck , "linux-arch@vger.kernel.org" List-Id: linux-arch.vger.kernel.org On Tue, 11 Nov 2014 16:36:06 -0800 Linus Torvalds wrote: > On Tue, Nov 11, 2014 at 4:33 PM, Linus Torvalds > wrote: > > > > I guess as a workaround it is fine, as long as we don't lose sight of > > trying to eventually do a better job. > > Oh, and when it comes to the actual gcc bug - do you have any reason > to believe that it's somehow triggered more easily by something > particular in the arch/s390/kvm/gaccess.c code? > > IOW, why does this problem not hit the x86 spinlocks that also use > volatile pointers to aggregate types? Or does it? This looks similiar to what we had on s390: old.tickets = ACCESS_ONCE(lock->tickets) In theory x86 should be affected as well. On s390 we have lots of instruction that operate on memory and the cost model of gcc makes the compiler more inclined to access memory multiple times. My guess would be that once the value is cached in a register the cost model for x86 will usually make sure that the value is not read a second time. But this is no guarantee. -- blue skies, Martin. "Reality continues to ruin my life." - Calvin. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:53525 "EHLO e06smtp11.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752582AbaKLJ2b (ORCPT ); Wed, 12 Nov 2014 04:28:31 -0500 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 12 Nov 2014 09:28:29 -0000 Date: Wed, 12 Nov 2014 10:28:24 +0100 From: Martin Schwidefsky Subject: Re: compiler bug gcc4.6/4.7 with ACCESS_ONCE and workarounds Message-ID: <20141112102824.55a4c178@mschwide> In-Reply-To: References: <1415360716-9670-2-git-send-email-borntraeger@de.ibm.com> <54611D86.4040306@de.ibm.com> <54627CBF.2000704@de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Linus Torvalds Cc: Christian Borntraeger , Paul McKenney , Ingo Molnar , Paolo Bonzini , KVM , Linux Kernel Mailing List , Heiko Carstens , Andreas Krebbel , Cornelia Huck , "linux-arch@vger.kernel.org" Message-ID: <20141112092824.m9Z_U8vmbieISnSeVbec1TRLJH4a1n5NnXYua8rQGZ8@z> On Tue, 11 Nov 2014 16:36:06 -0800 Linus Torvalds wrote: > On Tue, Nov 11, 2014 at 4:33 PM, Linus Torvalds > wrote: > > > > I guess as a workaround it is fine, as long as we don't lose sight of > > trying to eventually do a better job. > > Oh, and when it comes to the actual gcc bug - do you have any reason > to believe that it's somehow triggered more easily by something > particular in the arch/s390/kvm/gaccess.c code? > > IOW, why does this problem not hit the x86 spinlocks that also use > volatile pointers to aggregate types? Or does it? This looks similiar to what we had on s390: old.tickets = ACCESS_ONCE(lock->tickets) In theory x86 should be affected as well. On s390 we have lots of instruction that operate on memory and the cost model of gcc makes the compiler more inclined to access memory multiple times. My guess would be that once the value is cached in a register the cost model for x86 will usually make sure that the value is not read a second time. But this is no guarantee. -- blue skies, Martin. "Reality continues to ruin my life." - Calvin.