Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753457AbbEHN3j (ORCPT ); Fri, 8 May 2015 09:29:39 -0400 Received: from terminus.zytor.com ([198.137.202.10]:48595 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752805AbbEHN3g (ORCPT ); Fri, 8 May 2015 09:29:36 -0400 Date: Fri, 8 May 2015 06:28:16 -0700 From: tip-bot for Waiman Long Message-ID: Cc: doug.hatch@hp.com, Waiman.Long@hp.com, scott.norton@hp.com, paolo.bonzini@gmail.com, hpa@zytor.com, akpm@linux-foundation.org, daniel@numascale.com, oleg@redhat.com, mingo@kernel.org, raghavendra.kt@linux.vnet.ibm.com, paulmck@linux.vnet.ibm.com, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, bp@alien8.de, peterz@infradead.org, tglx@linutronix.de, torvalds@linux-foundation.org, david.vrabel@citrix.com, linux-kernel@vger.kernel.org, riel@redhat.com Reply-To: torvalds@linux-foundation.org, david.vrabel@citrix.com, peterz@infradead.org, boris.ostrovsky@oracle.com, tglx@linutronix.de, bp@alien8.de, konrad.wilk@oracle.com, paulmck@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, riel@redhat.com, hpa@zytor.com, Waiman.Long@hp.com, paolo.bonzini@gmail.com, scott.norton@hp.com, doug.hatch@hp.com, raghavendra.kt@linux.vnet.ibm.com, mingo@kernel.org, oleg@redhat.com, akpm@linux-foundation.org, daniel@numascale.com In-Reply-To: <1429901803-29771-11-git-send-email-Waiman.Long@hp.com> References: <1429901803-29771-11-git-send-email-Waiman.Long@hp.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/pvqspinlock, x86: Enable PV qspinlock for KVM Git-Commit-ID: bf0c7c34adc286bec3a5a38c00c773ba1b2d0396 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 Content-Length: 4112 Lines: 129 Commit-ID: bf0c7c34adc286bec3a5a38c00c773ba1b2d0396 Gitweb: http://git.kernel.org/tip/bf0c7c34adc286bec3a5a38c00c773ba1b2d0396 Author: Waiman Long AuthorDate: Fri, 24 Apr 2015 14:56:39 -0400 Committer: Ingo Molnar CommitDate: Fri, 8 May 2015 12:37:17 +0200 locking/pvqspinlock, x86: Enable PV qspinlock for KVM This patch adds the necessary KVM specific code to allow KVM to support the CPU halting and kicking operations needed by the queue spinlock PV code. Signed-off-by: Waiman Long Signed-off-by: Peter Zijlstra (Intel) Cc: Andrew Morton Cc: Boris Ostrovsky Cc: Borislav Petkov Cc: Daniel J Blueman Cc: David Vrabel Cc: Douglas Hatch Cc: H. Peter Anvin Cc: Konrad Rzeszutek Wilk Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Paolo Bonzini Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Raghavendra K T Cc: Rik van Riel Cc: Scott J Norton Cc: Thomas Gleixner Cc: virtualization@lists.linux-foundation.org Cc: xen-devel@lists.xenproject.org Link: http://lkml.kernel.org/r/1429901803-29771-11-git-send-email-Waiman.Long@hp.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/kvm.c | 43 +++++++++++++++++++++++++++++++++++++++++++ kernel/Kconfig.locks | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 9435620..6c21d93 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -584,6 +584,39 @@ static void kvm_kick_cpu(int cpu) kvm_hypercall2(KVM_HC_KICK_CPU, flags, apicid); } + +#ifdef CONFIG_QUEUED_SPINLOCK + +#include + +static void kvm_wait(u8 *ptr, u8 val) +{ + unsigned long flags; + + if (in_nmi()) + return; + + local_irq_save(flags); + + if (READ_ONCE(*ptr) != val) + goto out; + + /* + * halt until it's our turn and kicked. Note that we do safe halt + * for irq enabled case to avoid hang when lock info is overwritten + * in irq spinlock slowpath and no spurious interrupt occur to save us. + */ + if (arch_irqs_disabled_flags(flags)) + halt(); + else + safe_halt(); + +out: + local_irq_restore(flags); +} + +#else /* !CONFIG_QUEUED_SPINLOCK */ + enum kvm_contention_stat { TAKEN_SLOW, TAKEN_SLOW_PICKUP, @@ -817,6 +850,8 @@ static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket) } } +#endif /* !CONFIG_QUEUED_SPINLOCK */ + /* * Setup pv_lock_ops to exploit KVM_FEATURE_PV_UNHALT if present. */ @@ -828,8 +863,16 @@ void __init kvm_spinlock_init(void) if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) return; +#ifdef CONFIG_QUEUED_SPINLOCK + __pv_init_lock_hash(); + pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath; + pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock); + pv_lock_ops.wait = kvm_wait; + pv_lock_ops.kick = kvm_kick_cpu; +#else /* !CONFIG_QUEUED_SPINLOCK */ pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(kvm_lock_spinning); pv_lock_ops.unlock_kick = kvm_unlock_kick; +#endif } static __init int kvm_spinlock_init_jump(void) diff --git a/kernel/Kconfig.locks b/kernel/Kconfig.locks index 95fdad8..4379eef 100644 --- a/kernel/Kconfig.locks +++ b/kernel/Kconfig.locks @@ -240,7 +240,7 @@ config ARCH_USE_QUEUED_SPINLOCK config QUEUED_SPINLOCK def_bool y if ARCH_USE_QUEUED_SPINLOCK - depends on SMP && !PARAVIRT_SPINLOCKS + depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN) config ARCH_USE_QUEUE_RWLOCK bool -- 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/