From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933717AbcHJVRk (ORCPT ); Wed, 10 Aug 2016 17:17:40 -0400 Received: from terminus.zytor.com ([198.137.202.10]:56184 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752640AbcHJSGY (ORCPT ); Wed, 10 Aug 2016 14:06:24 -0400 Date: Wed, 10 Aug 2016 11:05:45 -0700 From: tip-bot for Wanpeng Li Message-ID: Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, Waiman.Long@hpe.com, peterz@infradead.org, wanpeng.li@hotmail.com, tglx@linutronix.de, akpm@linux-foundation.org, xinhui.pan@linux.vnet.ibm.com, dave@stgolabs.net, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org Reply-To: mingo@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, wanpeng.li@hotmail.com, peterz@infradead.org, Waiman.Long@hpe.com, akpm@linux-foundation.org, tglx@linutronix.de, xinhui.pan@linux.vnet.ibm.com, dave@stgolabs.net, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org In-Reply-To: <1468484156-4521-1-git-send-email-wanpeng.li@hotmail.com> References: <1468484156-4521-1-git-send-email-wanpeng.li@hotmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/pvqspinlock: Fix double hash race Git-Commit-ID: 229ce631574761870a2ac938845fadbd07f35caa X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 229ce631574761870a2ac938845fadbd07f35caa Gitweb: http://git.kernel.org/tip/229ce631574761870a2ac938845fadbd07f35caa Author: Wanpeng Li AuthorDate: Thu, 14 Jul 2016 16:15:56 +0800 Committer: Ingo Molnar CommitDate: Wed, 10 Aug 2016 14:13:28 +0200 locking/pvqspinlock: Fix double hash race When the lock holder vCPU is racing with the queue head: CPU 0 (lock holder) CPU1 (queue head) =================== ================= spin_lock(); spin_lock(); pv_kick_node(): pv_wait_head_or_lock(): if (!lp) { lp = pv_hash(lock, pn); xchg(&l->locked, _Q_SLOW_VAL); } WRITE_ONCE(pn->state, vcpu_halted); cmpxchg(&pn->state, vcpu_halted, vcpu_hashed); WRITE_ONCE(l->locked, _Q_SLOW_VAL); (void)pv_hash(lock, pn); In this case, lock holder inserts the pv_node of queue head into the hash table and set _Q_SLOW_VAL unnecessary. This patch avoids it by restoring/setting vcpu_hashed state after failing adaptive locking spinning. Signed-off-by: Wanpeng Li Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Pan Xinhui Cc: Andrew Morton Cc: Davidlohr Bueso Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Waiman Long Link: http://lkml.kernel.org/r/1468484156-4521-1-git-send-email-wanpeng.li@hotmail.com Signed-off-by: Ingo Molnar --- kernel/locking/qspinlock_paravirt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h index 37649e6..8a99abf 100644 --- a/kernel/locking/qspinlock_paravirt.h +++ b/kernel/locking/qspinlock_paravirt.h @@ -450,7 +450,7 @@ pv_wait_head_or_lock(struct qspinlock *lock, struct mcs_spinlock *node) goto gotlock; } } - WRITE_ONCE(pn->state, vcpu_halted); + WRITE_ONCE(pn->state, vcpu_hashed); qstat_inc(qstat_pv_wait_head, true); qstat_inc(qstat_pv_wait_again, waitcnt); pv_wait(&l->locked, _Q_SLOW_VAL);