From mboxrd@z Thu Jan 1 00:00:00 1970 From: Raghavendra K T Subject: Re: [PATCH V3] x86 spinlock: Fix memory corruption on completing completions Date: Thu, 12 Feb 2015 20:58:16 +0530 Message-ID: <54DCC690.1070103@linux.vnet.ibm.com> References: <1423741647-2156-1-git-send-email-raghavendra.kt@linux.vnet.ibm.com> <20150212150059.GA23123@twins.programming.kicks-ass.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, torvalds@linux-foundation.org, konrad.wilk@oracle.com, pbonzini@redhat.com, paulmck@linux.vnet.ibm.com, waiman.long@hp.com, davej@redhat.com, oleg@redhat.com, x86@kernel.org, jeremy@goop.org, paul.gortmaker@windriver.com, ak@linux.intel.com, jasowang@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, xen-devel@lists.xenproject.org, riel@redhat.com, borntraeger@de.ibm.com, akpm@linux-foundation.org, a.ryabinin@samsung.com, sasha.levin@oracle.com, dave@stgolabs.net To: Peter Zijlstra Return-path: In-Reply-To: <20150212150059.GA23123@twins.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 02/12/2015 08:30 PM, Peter Zijlstra wrote: > On Thu, Feb 12, 2015 at 05:17:27PM +0530, Raghavendra K T wrote: [...] >> >> Linus suggested that we should not do any writes to lock after unlock(), >> and we can move slowpath clearing to fastpath lock. >> >> So this patch implements the fix with: >> 1. Moving slowpath flag to head (Oleg). >> 2. use xadd to avoid read/write after unlock that checks the need for >> unlock_kick (Linus). > > Maybe spend a few more words explaining these things; something like: > > Unlocked locks don't care about the slowpath flag; therefore we can keep > it set after the last unlock, as long as we clear it again on the first > (try)lock -- this removes the write after unlock. Nit: I 'll reword a bit here since slowpath flag would result in unnecessary kick but otherwise harmless IMO. something like: Unlocked locks don't care about the slowpath flag; therefore we can keep it set after the last unlock, and clear it again on the first (try)lock. -- this removes the write after unlock. note that keeping slowpath flag would result in unnecessary kicks. > By moving the slowpath flag from the tail to the head ticket we avoid > the need to access both the head and tail tickets on unlock. > > We can further avoid the need for a read-after-release by using xadd; > the prev head value will include the slowpath flag and indicate if we > need to do PV kicking of suspended spinners -- on modern chips xadd > isn't (much) more expensive than an add + load. > > Its 'obvious' now, but maybe not so much after we've all not looked at > this for a few months. > Absolutely correct. Thanks Peter for the detailed and very helpful writeup.