All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning
@ 2016-07-14  8:15 Wanpeng Li
  2016-07-14 11:26 ` Peter Zijlstra
  2016-08-10 18:05 ` [tip:locking/core] locking/pvqspinlock: Fix double hash race tip-bot for Wanpeng Li
  0 siblings, 2 replies; 5+ messages in thread
From: Wanpeng Li @ 2016-07-14  8:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: Wanpeng Li, Peter Zijlstra (Intel), Ingo Molnar, Waiman Long,
	Davidlohr Bueso

From: Wanpeng Li <wanpeng.li@hotmail.com>

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.

Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Waiman Long <Waiman.Long@hpe.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
v1 -> v2:
 * adjust patch description

 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);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning
  2016-07-14  8:15 [PATCH v2] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning Wanpeng Li
@ 2016-07-14 11:26 ` Peter Zijlstra
  2016-07-14 11:28   ` Wanpeng Li
  2016-07-14 14:56   ` Waiman Long
  2016-08-10 18:05 ` [tip:locking/core] locking/pvqspinlock: Fix double hash race tip-bot for Wanpeng Li
  1 sibling, 2 replies; 5+ messages in thread
From: Peter Zijlstra @ 2016-07-14 11:26 UTC (permalink / raw)
  To: Wanpeng Li
  Cc: linux-kernel, Wanpeng Li, Ingo Molnar, Waiman Long,
	Davidlohr Bueso

On Thu, Jul 14, 2016 at 04:15:56PM +0800, Wanpeng Li wrote:
> 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.
> 

> -		WRITE_ONCE(pn->state, vcpu_halted);
> +		WRITE_ONCE(pn->state, vcpu_hashed);
                                           ^^^^^^

The Changelog meant so say vcpu_hashed, surely?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning
  2016-07-14 11:26 ` Peter Zijlstra
@ 2016-07-14 11:28   ` Wanpeng Li
  2016-07-14 14:56   ` Waiman Long
  1 sibling, 0 replies; 5+ messages in thread
From: Wanpeng Li @ 2016-07-14 11:28 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel@vger.kernel.org, Wanpeng Li, Ingo Molnar,
	Waiman Long, Davidlohr Bueso

2016-07-14 19:26 GMT+08:00 Peter Zijlstra <peterz@infradead.org>:
> On Thu, Jul 14, 2016 at 04:15:56PM +0800, Wanpeng Li wrote:
>> 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.
>>
>
>> -             WRITE_ONCE(pn->state, vcpu_halted);
>> +             WRITE_ONCE(pn->state, vcpu_hashed);
>                                            ^^^^^^
>
> The Changelog meant so say vcpu_hashed, surely?

Oh, there is a typo in changelog, I will fix it.

Regards,
Wanpeng Li

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning
  2016-07-14 11:26 ` Peter Zijlstra
  2016-07-14 11:28   ` Wanpeng Li
@ 2016-07-14 14:56   ` Waiman Long
  1 sibling, 0 replies; 5+ messages in thread
From: Waiman Long @ 2016-07-14 14:56 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Wanpeng Li, linux-kernel, Wanpeng Li, Ingo Molnar,
	Davidlohr Bueso

On 07/14/2016 07:26 AM, Peter Zijlstra wrote:
> On Thu, Jul 14, 2016 at 04:15:56PM +0800, Wanpeng Li wrote:
>> 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.
>>
>> -		WRITE_ONCE(pn->state, vcpu_halted);
>> +		WRITE_ONCE(pn->state, vcpu_hashed);
>                                             ^^^^^^
>
> The Changelog meant so say vcpu_hashed, surely?

Do you have chance to review the "Fix missed PV wakeup & support PPC" 
patch (https://lkml.org/lkml/2016/5/31/677) that I had sent out a while 
ago? That patch addressed a similar pv_hash leakage and collision problem.

Cheers,
Longman

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip:locking/core] locking/pvqspinlock: Fix double hash race
  2016-07-14  8:15 [PATCH v2] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning Wanpeng Li
  2016-07-14 11:26 ` Peter Zijlstra
@ 2016-08-10 18:05 ` tip-bot for Wanpeng Li
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Wanpeng Li @ 2016-08-10 18:05 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, mingo, hpa, Waiman.Long, peterz, wanpeng.li, tglx,
	akpm, xinhui.pan, dave, paulmck, torvalds

Commit-ID:  229ce631574761870a2ac938845fadbd07f35caa
Gitweb:     http://git.kernel.org/tip/229ce631574761870a2ac938845fadbd07f35caa
Author:     Wanpeng Li <wanpeng.li@hotmail.com>
AuthorDate: Thu, 14 Jul 2016 16:15:56 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
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 <wanpeng.li@hotmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <Waiman.Long@hpe.com>
Link: http://lkml.kernel.org/r/1468484156-4521-1-git-send-email-wanpeng.li@hotmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-08-10 21:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-14  8:15 [PATCH v2] locking/pvqspinlock: restore/set vcpu_hashed state after failing adaptive locking spinning Wanpeng Li
2016-07-14 11:26 ` Peter Zijlstra
2016-07-14 11:28   ` Wanpeng Li
2016-07-14 14:56   ` Waiman Long
2016-08-10 18:05 ` [tip:locking/core] locking/pvqspinlock: Fix double hash race tip-bot for Wanpeng Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.