X-Received: by 10.112.130.71 with SMTP id oc7mr4900511lbb.23.1429902622533;
        Fri, 24 Apr 2015 12:10:22 -0700 (PDT)
X-BeenThere: linux.kernel@googlegroups.com
Received: by 10.153.6.35 with SMTP id cr3ls452074lad.47.gmail; Fri, 24 Apr
 2015 12:10:03 -0700 (PDT)
X-Received: by 10.152.3.70 with SMTP id a6mr4945000laa.0.1429902603362;
        Fri, 24 Apr 2015 12:10:03 -0700 (PDT)
MIME-Version: 1.0
Path: rq4ni23027lbb.1!nntp.google.com!goblin2!goblin.stu.neva.ru!aioe.org!bofh.it!news.nic.it!robomod
From: Waiman Long <Waima...@hp.com>
Newsgroups: linux.kernel
Subject: [PATCH v16 10/14] pvqspinlock, x86: Enable PV qspinlock for KVM
Date: Fri, 24 Apr 2015 21:10:03 +0200
Message-ID: <piR99-86R-31@gated-at.bofh.it>
References: <piQZr-7FS-3@gated-at.bofh.it>
X-Original-To: Thomas Gleixner <tg...@linutronix.de>,
	Ingo Molnar <mi...@redhat.com>,
	"H. Peter Anvin" <h...@zytor.com>,
	Peter Zijlstra <pet...@infradead.org>
X-Mailer: git-send-email 1.7.1
Sender: rob...@news.nic.it
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-...@vger.kernel.org
Approved: rob...@news.nic.it
Lines: 101
Organization: linux.* mail to news gateway
X-Original-Cc: linux...@vger.kernel.org, x...@kernel.org,
	linux-...@vger.kernel.org,
	virtual...@lists.linux-foundation.org,
	xen-...@lists.xenproject.org, k...@vger.kernel.org,
	Paolo Bonzini <paolo....@gmail.com>,
	Konrad Rzeszutek Wilk <konra...@oracle.com>,
	Boris Ostrovsky <boris.o...@oracle.com>,
	"Paul E. McKenney" <pau...@linux.vnet.ibm.com>,
	Rik van Riel <ri...@redhat.com>,
	Linus Torvalds <torv...@linux-foundation.org>,
	Raghavendra K T <raghave...@linux.vnet.ibm.com>,
	David Vrabel <david....@citrix.com>,
	Oleg Nesterov <ol...@redhat.com>,
	Daniel J Blueman <dan...@numascale.com>,
	Scott J Norton <scott....@hp.com>,
	Douglas Hatch <doug....@hp.com>,
	Waiman Long <Waima...@hp.com>
X-Original-Date: Fri, 24 Apr 2015 14:56:39 -0400
X-Original-Message-ID: <1429901803-29771-11-git...@hp.com>
X-Original-References: <1429901803-29771-1-git...@hp.com>
X-Original-Sender: linux-ker...@vger.kernel.org

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 <Waima...@hp.com>
---
 arch/x86/kernel/kvm.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 kernel/Kconfig.locks  |    2 +-
 2 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index e354cc6..4bb42c0 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_QUEUE_SPINLOCK
+
+#include <asm/qspinlock.h>
+
+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_QUEUE_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_QUEUE_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_QUEUE_SPINLOCK
+	__pv_init_lock_hash();
+	pv_lock_ops.queue_spin_lock_slowpath = __pv_queue_spin_lock_slowpath;
+	pv_lock_ops.queue_spin_unlock = PV_CALLEE_SAVE(__pv_queue_spin_unlock);
+	pv_lock_ops.wait = kvm_wait;
+	pv_lock_ops.kick = kvm_kick_cpu;
+#else /* !CONFIG_QUEUE_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 c6a8f7c..537b13e 100644
--- a/kernel/Kconfig.locks
+++ b/kernel/Kconfig.locks
@@ -240,7 +240,7 @@ config ARCH_USE_QUEUE_SPINLOCK
 
 config QUEUE_SPINLOCK
 	def_bool y if ARCH_USE_QUEUE_SPINLOCK
-	depends on SMP && !PARAVIRT_SPINLOCKS
+	depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN)
 
 config ARCH_USE_QUEUE_RWLOCK
 	bool
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

