Commit 9043442b authored by Juergen Gross's avatar Juergen Gross Committed by Ingo Molnar

locking/paravirt: Use new static key for controlling call of virt_spin_lock()

There are cases where a guest tries to switch spinlocks to bare metal
behavior (e.g. by setting "xen_nopvspin" boot parameter). Today this
has the downside of falling back to unfair test and set scheme for
qspinlocks due to virt_spin_lock() detecting the virtualized
environment.

Add a static key controlling whether virt_spin_lock() should be
called or not. When running on bare metal set the new key to false.
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarWaiman Long <longman@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: akataria@vmware.com
Cc: boris.ostrovsky@oracle.com
Cc: chrisw@sous-sol.org
Cc: hpa@zytor.com
Cc: jeremy@goop.org
Cc: rusty@rustcorp.com.au
Cc: virtualization@lists.linux-foundation.org
Cc: xen-devel@lists.xenproject.org
Link: http://lkml.kernel.org/r/20170906173625.18158-2-jgross@suse.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent af1a34f2
#ifndef _ASM_X86_QSPINLOCK_H #ifndef _ASM_X86_QSPINLOCK_H
#define _ASM_X86_QSPINLOCK_H #define _ASM_X86_QSPINLOCK_H
#include <linux/jump_label.h>
#include <asm/cpufeature.h> #include <asm/cpufeature.h>
#include <asm-generic/qspinlock_types.h> #include <asm-generic/qspinlock_types.h>
#include <asm/paravirt.h> #include <asm/paravirt.h>
...@@ -46,10 +47,14 @@ static inline void queued_spin_unlock(struct qspinlock *lock) ...@@ -46,10 +47,14 @@ static inline void queued_spin_unlock(struct qspinlock *lock)
#endif #endif
#ifdef CONFIG_PARAVIRT #ifdef CONFIG_PARAVIRT
DECLARE_STATIC_KEY_TRUE(virt_spin_lock_key);
void native_pv_lock_init(void) __init;
#define virt_spin_lock virt_spin_lock #define virt_spin_lock virt_spin_lock
static inline bool virt_spin_lock(struct qspinlock *lock) static inline bool virt_spin_lock(struct qspinlock *lock)
{ {
if (!static_cpu_has(X86_FEATURE_HYPERVISOR)) if (!static_branch_likely(&virt_spin_lock_key))
return false; return false;
/* /*
...@@ -65,6 +70,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock) ...@@ -65,6 +70,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock)
return true; return true;
} }
#else
static inline void native_pv_lock_init(void)
{
}
#endif /* CONFIG_PARAVIRT */ #endif /* CONFIG_PARAVIRT */
#include <asm-generic/qspinlock.h> #include <asm-generic/qspinlock.h>
......
...@@ -115,8 +115,18 @@ unsigned paravirt_patch_jmp(void *insnbuf, const void *target, ...@@ -115,8 +115,18 @@ unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
return 5; return 5;
} }
/* Neat trick to map patch type back to the call within the DEFINE_STATIC_KEY_TRUE(virt_spin_lock_key);
* corresponding structure. */
void __init native_pv_lock_init(void)
{
if (!static_cpu_has(X86_FEATURE_HYPERVISOR))
static_branch_disable(&virt_spin_lock_key);
}
/*
* Neat trick to map patch type back to the call within the
* corresponding structure.
*/
static void *get_call_destination(u8 type) static void *get_call_destination(u8 type)
{ {
struct paravirt_patch_template tmpl = { struct paravirt_patch_template tmpl = {
......
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#include <asm/i8259.h> #include <asm/i8259.h>
#include <asm/realmode.h> #include <asm/realmode.h>
#include <asm/misc.h> #include <asm/misc.h>
#include <asm/qspinlock.h>
/* Number of siblings per CPU package */ /* Number of siblings per CPU package */
int smp_num_siblings = 1; int smp_num_siblings = 1;
...@@ -1384,6 +1385,7 @@ void __init native_smp_prepare_boot_cpu(void) ...@@ -1384,6 +1385,7 @@ void __init native_smp_prepare_boot_cpu(void)
/* already set me in cpu_online_mask in boot_cpu_init() */ /* already set me in cpu_online_mask in boot_cpu_init() */
cpumask_set_cpu(me, cpu_callout_mask); cpumask_set_cpu(me, cpu_callout_mask);
cpu_set_state_online(me); cpu_set_state_online(me);
native_pv_lock_init();
} }
void __init native_smp_cpus_done(unsigned int max_cpus) void __init native_smp_cpus_done(unsigned int max_cpus)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment