From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751623AbcGNIWt (ORCPT ); Thu, 14 Jul 2016 04:22:49 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42937 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751028AbcGNIVZ (ORCPT ); Thu, 14 Jul 2016 04:21:25 -0400 X-IBM-Helo: d28dlp01.in.ibm.com X-IBM-MailFrom: xinhui.pan@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Date: Thu, 14 Jul 2016 16:20:56 +0800 From: xinhui User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Wanpeng Li , linux-kernel@vger.kernel.org CC: Wanpeng Li , "Peter Zijlstra (Intel)" , Ingo Molnar , Waiman Long , Davidlohr Bueso Subject: Re: [PATCH] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning References: <1468482826-4003-1-git-send-email-wanpeng.li@hotmail.com> In-Reply-To: <1468482826-4003-1-git-send-email-wanpeng.li@hotmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16071408-0048-0000-0000-000002BD1465 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16071408-0049-0000-0000-00000DB57766 Message-Id: <57874B68.8060300@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-07-14_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607140092 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2016年07月14日 15:53, Wanpeng Li wrote: > From: Wanpeng Li > > 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_halted state after failing adaptive locking > spinning. > good catching. this is hash entry leak. After apply Waiman's pathset "locking/pvqspinlock: Fix missed PV wakeup & support PPC", this is not the big problem. But we can still save another cmpxchg. So Reviewed-by: Pan Xinhui > Cc: Peter Zijlstra (Intel) > Cc: Ingo Molnar > Cc: Waiman Long > Cc: Davidlohr Bueso > Signed-off-by: Wanpeng Li > --- > 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 21ede57..ac7d20b 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); >