Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757243AbbEEJSF (ORCPT ); Tue, 5 May 2015 05:18:05 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:54689 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031207AbbEEJRf (ORCPT ); Tue, 5 May 2015 05:17:35 -0400 Date: Tue, 5 May 2015 11:17:14 +0200 From: Peter Zijlstra To: Tahsin Erdogan Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, Waiman.Long@hp.com, borntraeger@de.ibm.com, oleg@redhat.com, raghavendra.kt@linux.vnet.ibm.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] x86/spinlocks: Fix regression in spinlock contention detection Message-ID: <20150505091714.GF21418@twins.programming.kicks-ass.net> References: <1430799331-20445-1-git-send-email-tahsin@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1430799331-20445-1-git-send-email-tahsin@google.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1926 Lines: 42 On Mon, May 04, 2015 at 09:15:31PM -0700, Tahsin Erdogan wrote: > A spinlock is regarded as contended when there is at least one waiter. > Currently, the code that checks whether there are any waiters rely on > tail value being greater than head. However, this is not true if tail > reaches the max value and wraps back to zero, so arch_spin_is_contended() > incorrectly returns 0 (not contended) when tail is smaller than head. > > The original code (before regression) handled this case by casting the > (tail - head) to an unsigned value. This change simply restores that > behavior. > > Fixes: d6abfdb20223 ("x86/spinlocks/paravirt: Fix memory corruption on > unlock") > Signed-off-by: Tahsin Erdogan > --- > arch/x86/include/asm/spinlock.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h > index cf87de3..64b6117 100644 > --- a/arch/x86/include/asm/spinlock.h > +++ b/arch/x86/include/asm/spinlock.h > @@ -169,7 +169,7 @@ static inline int arch_spin_is_contended(arch_spinlock_t *lock) > struct __raw_tickets tmp = READ_ONCE(lock->tickets); > > tmp.head &= ~TICKET_SLOWPATH_FLAG; > - return (tmp.tail - tmp.head) > TICKET_LOCK_INC; > + return (__ticket_t)(tmp.tail - tmp.head) > TICKET_LOCK_INC; I'm not seeing it, everything in that expression is of __ticket_t type (tail, head and TICKET_LOCK_INC), nothing should cause it to be cast to another type due to conversion rules. Or does - always cast to a signed type? Lemme go grab the C rules again. I'm not seeing it.. Please explain better, iow. your changelog fails to properly explain the problem. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/