From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleg Nesterov Subject: Re: [PATCH] x86 spinlock: Fix memory corruption on completing completions Date: Wed, 11 Feb 2015 18:38:38 +0100 Message-ID: <20150211173838.GB28689@redhat.com> References: <1423234148-13886-1-git-send-email-raghavendra.kt@linux.vnet.ibm.com> <54D7D19B.1000103@goop.org> <54D87F1E.9060307@linux.vnet.ibm.com> <20150209120227.GT21418@twins.programming.kicks-ass.net> <54D9CFC7.5020007@linux.vnet.ibm.com> <20150210132634.GA30380@redhat.com> <54DB384A.2050305@linux.vnet.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <54DB384A.2050305@linux.vnet.ibm.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: Raghavendra K T Cc: Jeremy Fitzhardinge , KVM list , Peter Zijlstra , virtualization , Paul Gortmaker , Peter Anvin , Davidlohr Bueso , Andrey Ryabinin , the arch/x86 maintainers , Christian Borntraeger , Ingo Molnar , Sasha Levin , Paul McKenney , Rik van Riel , Konrad Rzeszutek Wilk , Andi Kleen , xen-devel@lists.xenproject.org, Dave Jones , Thomas Gleixner , Waiman Long , Linux Kernel Mailing List , Paolo Bonzini , Andrew List-Id: virtualization@lists.linuxfoundation.org On 02/11, Raghavendra K T wrote: > > On 02/10/2015 06:56 PM, Oleg Nesterov wrote: > >> In this case __ticket_check_and_clear_slowpath() really needs to cmpxchg >> the whole .head_tail. Plus obviously more boring changes. This needs a >> separate patch even _if_ this can work. > > Correct, but apart from this, before doing xadd in unlock, > we would have to make sure lsb bit is cleared so that we can live with 1 > bit overflow to tail which is unused. now either or both of head,tail > lsb bit may be set after unlock. Sorry, can't understand... could you spell? If TICKET_SLOWPATH_FLAG lives in .head arch_spin_unlock() could simply do head = xadd(&lock->tickets.head, TICKET_LOCK_INC); if (head & TICKET_SLOWPATH_FLAG) __ticket_unlock_kick(head); so it can't overflow to .tail? But probably I missed your concern. And we we do this, probably it makes sense to add something like bool tickets_equal(__ticket_t one, __ticket_t two) { return (one ^ two) & ~TICKET_SLOWPATH_FLAG; } and change kvm_lock_spinning() to use tickets_equal(tickets.head, want), plus it can have more users in asm/spinlock.h. Oleg.