guard virt_spin_lock() with a static key
Subsystems (5)
Juergen Gross
maintainerPATCH v2 1/2 paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Juergen GrossThere 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.
--- arch/x86/include/asm/qspinlock.h | 11 +++++++++++ arch/x86/kernel/paravirt-spinlocks.c | 6 ++++++ arch/x86/kernel/smpboot.c | 2 ++ kernel/locking/qspinlock.c | 4 ++++ 4 files changed, 23 insertions(+)
arch/x86/include/asm/qspinlock.h +11 -0
@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <linux/jump_label.h> #include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #include <asm/paravirt.h>
@@ -46,9 +47,15 @@ static inline void queued_spin_unlock(struct qspinlock *lock)#endif #ifdef CONFIG_PARAVIRT +DECLARE_STATIC_KEY_TRUE (virt_spin_lock_key); + +void native_pv_lock_init (void )__init ; +#define virt_spin_lock virt_spin_lockstatic inline bool virt_spin_lock (struct qspinlock *lock) { +if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;
@@ -65,6 +72,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock) return true; } +#else +static inline void native_pv_lock_init (void ) +{ +}#endif /* CONFIG_PARAVIRT */ #include <asm-generic/qspinlock.h>
arch/x86/kernel/paravirt-spinlocks.c +6 -0
@@ -42,3 +42,9 @@ struct pv_lock_ops pv_lock_ops = {#endif /* SMP */ };EXPORT_SYMBOL (pv_lock_ops); + +void __init native_pv_lock_init (void ) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +static_branch_disable (&virt_spin_lock_key); +}
arch/x86/kernel/smpboot.c +2 -0
@@ -77,6 +77,7 @@#include <asm/i8259.h> #include <asm/realmode.h> #include <asm/misc.h> +#include <asm/qspinlock.h> /* Number of siblings per CPU package */ int smp_num_siblings =1 ;
@@ -1381,6 +1382,7 @@ void __init native_smp_prepare_boot_cpu(void)/* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu (me, cpu_callout_mask);cpu_set_state_online (me); +native_pv_lock_init (); }void __init native_smp_cpus_done (unsigned int max_cpus)
kernel/locking/qspinlock.c +4 -0
@@ -76,6 +76,10 @@#define MAX_NODES 4#endif +#ifdef CONFIG_PARAVIRT +DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key); +#endif +/* * Per-CPU queue node structures; we can never have more than 4 nested * contexts: task, softirq, hardirq, nmi.
Signature · 1 line
2.12.3
Juergen Gross
maintainerPATCH v2 2/2 paravirt,xen: correct xen_nopvspin case
In reply to Juergen GrossWith the boot parameter "xen_nopvspin" specified a Xen guest should not make use of paravirt spinlocks, but behave as if running on bare metal. This is not true, however, as the qspinlock code will fall back to a test-and-set scheme when it is detecting a hypervisor.
In order to avoid this disable the virt_spin_lock_key.
--- arch/x86/xen/spinlock.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/xen/spinlock.c +2 -0
@@ -10,6 +10,7 @@#include <linux/slab.h> #include <asm/paravirt.h> +#include <asm/qspinlock.h> #include <xen/interface/xen.h> #include <xen/events.h>
@@ -129,6 +130,7 @@ void __init xen_init_spinlocks(void)if (!xen_pvspin) {printk (KERN_DEBUG "xen: PV spinlocks disabled\n" ); +static_branch_disable (&virt_spin_lock_key);return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" );
Signature · 1 line
2.12.3
Juergen Gross
maintainerPATCH v2 1/2 paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Juergen GrossThere 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.
--- arch/x86/include/asm/qspinlock.h | 11 +++++++++++ arch/x86/kernel/paravirt-spinlocks.c | 6 ++++++ arch/x86/kernel/smpboot.c | 2 ++ kernel/locking/qspinlock.c | 4 ++++ 4 files changed, 23 insertions(+)
arch/x86/include/asm/qspinlock.h +11 -0
@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <linux/jump_label.h> #include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #include <asm/paravirt.h>
@@ -46,9 +47,15 @@ static inline void queued_spin_unlock(struct qspinlock *lock)#endif #ifdef CONFIG_PARAVIRT +DECLARE_STATIC_KEY_TRUE (virt_spin_lock_key); + +void native_pv_lock_init (void )__init ; +#define virt_spin_lock virt_spin_lockstatic inline bool virt_spin_lock (struct qspinlock *lock) { +if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;
@@ -65,6 +72,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock) return true; } +#else +static inline void native_pv_lock_init (void ) +{ +}#endif /* CONFIG_PARAVIRT */ #include <asm-generic/qspinlock.h>
arch/x86/kernel/paravirt-spinlocks.c +6 -0
@@ -42,3 +42,9 @@ struct pv_lock_ops pv_lock_ops = {#endif /* SMP */ };EXPORT_SYMBOL (pv_lock_ops); + +void __init native_pv_lock_init (void ) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +static_branch_disable (&virt_spin_lock_key); +}
arch/x86/kernel/smpboot.c +2 -0
@@ -77,6 +77,7 @@#include <asm/i8259.h> #include <asm/realmode.h> #include <asm/misc.h> +#include <asm/qspinlock.h> /* Number of siblings per CPU package */ int smp_num_siblings =1 ;
@@ -1381,6 +1382,7 @@ void __init native_smp_prepare_boot_cpu(void)/* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu (me, cpu_callout_mask);cpu_set_state_online (me); +native_pv_lock_init (); }void __init native_smp_cpus_done (unsigned int max_cpus)
kernel/locking/qspinlock.c +4 -0
@@ -76,6 +76,10 @@#define MAX_NODES 4#endif +#ifdef CONFIG_PARAVIRT +DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key); +#endif +/* * Per-CPU queue node structures; we can never have more than 4 nested * contexts: task, softirq, hardirq, nmi.
Signature · 7 lines
2.12.3 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Juergen Gross
maintainerPATCH v2 2/2 paravirt, xen: correct xen_nopvspin case
In reply to Juergen GrossWith the boot parameter "xen_nopvspin" specified a Xen guest should not make use of paravirt spinlocks, but behave as if running on bare metal. This is not true, however, as the qspinlock code will fall back to a test-and-set scheme when it is detecting a hypervisor.
In order to avoid this disable the virt_spin_lock_key.
--- arch/x86/xen/spinlock.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/xen/spinlock.c +2 -0
@@ -10,6 +10,7 @@#include <linux/slab.h> #include <asm/paravirt.h> +#include <asm/qspinlock.h> #include <xen/interface/xen.h> #include <xen/events.h>
@@ -129,6 +130,7 @@ void __init xen_init_spinlocks(void)if (!xen_pvspin) {printk (KERN_DEBUG "xen: PV spinlocks disabled\n" ); +static_branch_disable (&virt_spin_lock_key);return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" );
Signature · 7 lines
2.12.3 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Juergen Gross
maintainerv2 cover guard virt_spin_lock() with a static key
With virt_spin_lock() being guarded by a static key the bare metal case can be optimized by patching the call away completely. In case a kernel running as a guest it can decide whether to use paravitualized spinlocks, the current fallback to the unfair test-and-set scheme, or to mimic the bare metal behavior.
V2:
- use static key instead of making virt_spin_lock() a pvops function
Juergen Gross (2):
paravirt/locks: use new static key for controlling call of
virt_spin_lock()
paravirt,xen: correct xen_nopvspin case
arch/x86/include/asm/qspinlock.h | 11 +++++++++++ arch/x86/kernel/paravirt-spinlocks.c | 6 ++++++ arch/x86/kernel/smpboot.c | 2 ++ arch/x86/xen/spinlock.c | 2 ++ kernel/locking/qspinlock.c | 4 ++++ 5 files changed, 25 insertions(+)
Signature · 1 line
2.12.3
Juergen Gross
maintainerPATCH v2 2/2 paravirt,xen: correct xen_nopvspin case
With the boot parameter "xen_nopvspin" specified a Xen guest should not make use of paravirt spinlocks, but behave as if running on bare metal. This is not true, however, as the qspinlock code will fall back to a test-and-set scheme when it is detecting a hypervisor.
In order to avoid this disable the virt_spin_lock_key.
--- arch/x86/xen/spinlock.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/xen/spinlock.c +2 -0
@@ -10,6 +10,7 @@#include <linux/slab.h> #include <asm/paravirt.h> +#include <asm/qspinlock.h> #include <xen/interface/xen.h> #include <xen/events.h>
@@ -129,6 +130,7 @@ void __init xen_init_spinlocks(void)if (!xen_pvspin) {printk (KERN_DEBUG "xen: PV spinlocks disabled\n" ); +static_branch_disable (&virt_spin_lock_key);return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" );
Signature · 1 line
2.12.3
Juergen Gross
maintainerPATCH v2 1/2 paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Juergen GrossThere 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.
--- arch/x86/include/asm/qspinlock.h | 11 +++++++++++ arch/x86/kernel/paravirt-spinlocks.c | 6 ++++++ arch/x86/kernel/smpboot.c | 2 ++ kernel/locking/qspinlock.c | 4 ++++ 4 files changed, 23 insertions(+)
arch/x86/include/asm/qspinlock.h +11 -0
@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <linux/jump_label.h> #include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #include <asm/paravirt.h>
@@ -46,9 +47,15 @@ static inline void queued_spin_unlock(struct qspinlock *lock)#endif #ifdef CONFIG_PARAVIRT +DECLARE_STATIC_KEY_TRUE (virt_spin_lock_key); + +void native_pv_lock_init (void )__init ; +#define virt_spin_lock virt_spin_lockstatic inline bool virt_spin_lock (struct qspinlock *lock) { +if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;
@@ -65,6 +72,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock) return true; } +#else +static inline void native_pv_lock_init (void ) +{ +}#endif /* CONFIG_PARAVIRT */ #include <asm-generic/qspinlock.h>
arch/x86/kernel/paravirt-spinlocks.c +6 -0
@@ -42,3 +42,9 @@ struct pv_lock_ops pv_lock_ops = {#endif /* SMP */ };EXPORT_SYMBOL (pv_lock_ops); + +void __init native_pv_lock_init (void ) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +static_branch_disable (&virt_spin_lock_key); +}
arch/x86/kernel/smpboot.c +2 -0
@@ -77,6 +77,7 @@#include <asm/i8259.h> #include <asm/realmode.h> #include <asm/misc.h> +#include <asm/qspinlock.h> /* Number of siblings per CPU package */ int smp_num_siblings =1 ;
@@ -1381,6 +1382,7 @@ void __init native_smp_prepare_boot_cpu(void)/* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu (me, cpu_callout_mask);cpu_set_state_online (me); +native_pv_lock_init (); }void __init native_smp_cpus_done (unsigned int max_cpus)
kernel/locking/qspinlock.c +4 -0
@@ -76,6 +76,10 @@#define MAX_NODES 4#endif +#ifdef CONFIG_PARAVIRT +DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key); +#endif +/* * Per-CPU queue node structures; we can never have more than 4 nested * contexts: task, softirq, hardirq, nmi.
Signature · 1 line
2.12.3
Re: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
Quoted 95 lines · Juergen Gross
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 tovirt_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 Juergen Gross <[email protected]>--- arch/x86/include/asm/qspinlock.h | 11 +++++++++++ arch/x86/kernel/paravirt-spinlocks.c | 6 ++++++ arch/x86/kernel/smpboot.c | 2 ++ kernel/locking/qspinlock.c | 4 ++++ 4 files changed, 23 insertions(+)arch/x86/include/asm/qspinlock.h +11
-0@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <linux/jump_label.h> #include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #include <asm/paravirt.h> @@ -46,9 +47,15 @@ static inline void queued_spin_unlock(struct qspinlock *lock)#endif #ifdef CONFIG_PARAVIRT +DECLARE_STATIC_KEY_TRUE (virt_spin_lock_key); + +void native_pv_lock_init (void )__init ; +#define virt_spin_lock virt_spin_lockstatic inline bool virt_spin_lock (struct qspinlock *lock) { +if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;@@ -65,6 +72,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock) return true; } +#else +static inline void native_pv_lock_init (void ) +{ +}#endif /* CONFIG_PARAVIRT */ #include <asm-generic/qspinlock.h> arch/x86/kernel/paravirt-spinlocks.c +6
-0@@ -42,3 +42,9 @@ struct pv_lock_ops pv_lock_ops = {#endif /* SMP */ };EXPORT_SYMBOL (pv_lock_ops); + +void __init native_pv_lock_init (void ) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +static_branch_disable (&virt_spin_lock_key); +}arch/x86/kernel/smpboot.c +2
-0@@ -77,6 +77,7 @@#include <asm/i8259.h> #include <asm/realmode.h> #include <asm/misc.h> +#include <asm/qspinlock.h> /* Number of siblings per CPU package */ int smp_num_siblings =1 ;@@ -1381,6 +1382,7 @@ void __init native_smp_prepare_boot_cpu(void)/* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu (me, cpu_callout_mask);cpu_set_state_online (me); +native_pv_lock_init (); }void __init native_smp_cpus_done (unsigned int max_cpus)kernel/locking/qspinlock.c +0
-0
kernel/locking/qspinlock.c line 85
Quoted 10 lines
kernel/locking/qspinlock.c +4
-0@@ -76,6 +76,10 @@#define MAX_NODES 4#endif +#ifdef CONFIG_PARAVIRT +DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key); +#endif +/* * Per-CPU queue node structures; we can never have more than 4 nested * contexts: task, softirq, hardirq, nmi.
Re: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Juergen GrossQuoted 95 lines · Juergen Gross
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 tovirt_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 Juergen Gross <[email protected]>--- arch/x86/include/asm/qspinlock.h | 11 +++++++++++ arch/x86/kernel/paravirt-spinlocks.c | 6 ++++++ arch/x86/kernel/smpboot.c | 2 ++ kernel/locking/qspinlock.c | 4 ++++ 4 files changed, 23 insertions(+)arch/x86/include/asm/qspinlock.h +11
-0@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <linux/jump_label.h> #include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #include <asm/paravirt.h> @@ -46,9 +47,15 @@ static inline void queued_spin_unlock(struct qspinlock *lock)#endif #ifdef CONFIG_PARAVIRT +DECLARE_STATIC_KEY_TRUE (virt_spin_lock_key); + +void native_pv_lock_init (void )__init ; +#define virt_spin_lock virt_spin_lockstatic inline bool virt_spin_lock (struct qspinlock *lock) { +if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;@@ -65,6 +72,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock) return true; } +#else +static inline void native_pv_lock_init (void ) +{ +}#endif /* CONFIG_PARAVIRT */ #include <asm-generic/qspinlock.h> arch/x86/kernel/paravirt-spinlocks.c +6
-0@@ -42,3 +42,9 @@ struct pv_lock_ops pv_lock_ops = {#endif /* SMP */ };EXPORT_SYMBOL (pv_lock_ops); + +void __init native_pv_lock_init (void ) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +static_branch_disable (&virt_spin_lock_key); +}arch/x86/kernel/smpboot.c +2
-0@@ -77,6 +77,7 @@#include <asm/i8259.h> #include <asm/realmode.h> #include <asm/misc.h> +#include <asm/qspinlock.h> /* Number of siblings per CPU package */ int smp_num_siblings =1 ;@@ -1381,6 +1382,7 @@ void __init native_smp_prepare_boot_cpu(void)/* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu (me, cpu_callout_mask);cpu_set_state_online (me); +native_pv_lock_init (); }void __init native_smp_cpus_done (unsigned int max_cpus)kernel/locking/qspinlock.c +0
-0
kernel/locking/qspinlock.c line 85
Quoted 10 lines
kernel/locking/qspinlock.c +4
-0@@ -76,6 +76,10 @@#define MAX_NODES 4#endif +#ifdef CONFIG_PARAVIRT +DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key); +#endif +/* * Per-CPU queue node structures; we can never have more than 4 nested * contexts: task, softirq, hardirq, nmi.
Re: [PATCH v2 2/2] paravirt,xen: correct xen_nopvspin case
In reply to Juergen GrossQuoted 25 lines · Juergen Gross
With the boot parameter "
xen_nopvspin" specified a Xen guest should not make use of paravirt spinlocks, but behave as if running on bare metal. This is not true, however, as the qspinlock code will fall back to a test-and-set scheme when it is detecting a hypervisor.In order to avoid this disable the
virt_spin_lock_key.Signed-off-by Juergen Gross <[email protected]>--- arch/x86/xen/spinlock.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/xen/spinlock.c +1
-0@@ -10,6 +10,7 @@#include <linux/slab.h> #include <asm/paravirt.h> +#include <asm/qspinlock.h> #include <xen/interface/xen.h> #include <xen/events.h>
arch/x86/xen/spinlock.c void __init xen_init_spinlocks(void) · line 136
Quoted 7 lines
arch/x86/xen/spinlock.c +1
-0@@ -129,6 +130,7 @@ void __init xen_init_spinlocks(void)if (!xen_pvspin) {printk (KERN_DEBUG "xen: PV spinlocks disabled\n" ); +static_branch_disable (&virt_spin_lock_key);return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" );
Re: [PATCH v2 2/2] paravirt, xen: correct xen_nopvspin case
In reply to Juergen GrossQuoted 25 lines · Juergen Gross
With the boot parameter "
xen_nopvspin" specified a Xen guest should not make use of paravirt spinlocks, but behave as if running on bare metal. This is not true, however, as the qspinlock code will fall back to a test-and-set scheme when it is detecting a hypervisor.In order to avoid this disable the
virt_spin_lock_key.Signed-off-by Juergen Gross <[email protected]>--- arch/x86/xen/spinlock.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/xen/spinlock.c +1
-0@@ -10,6 +10,7 @@#include <linux/slab.h> #include <asm/paravirt.h> +#include <asm/qspinlock.h> #include <xen/interface/xen.h> #include <xen/events.h>
arch/x86/xen/spinlock.c void __init xen_init_spinlocks(void) · line 136
Quoted 7 lines
arch/x86/xen/spinlock.c +1
-0@@ -129,6 +130,7 @@ void __init xen_init_spinlocks(void)if (!xen_pvspin) {printk (KERN_DEBUG "xen: PV spinlocks disabled\n" ); +static_branch_disable (&virt_spin_lock_key);return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" );
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/2] paravirt,xen: correct xen_nopvspin case
In reply to Juergen GrossQuoted 25 lines · Juergen Gross
With the boot parameter "
xen_nopvspin" specified a Xen guest should not make use of paravirt spinlocks, but behave as if running on bare metal. This is not true, however, as the qspinlock code will fall back to a test-and-set scheme when it is detecting a hypervisor.In order to avoid this disable the
virt_spin_lock_key.Signed-off-by Juergen Gross <[email protected]>--- arch/x86/xen/spinlock.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/xen/spinlock.c +1
-0@@ -10,6 +10,7 @@#include <linux/slab.h> #include <asm/paravirt.h> +#include <asm/qspinlock.h> #include <xen/interface/xen.h> #include <xen/events.h>
arch/x86/xen/spinlock.c void __init xen_init_spinlocks(void) · line 136
Quoted 7 lines
arch/x86/xen/spinlock.c +1
-0@@ -129,6 +130,7 @@ void __init xen_init_spinlocks(void)if (!xen_pvspin) {printk (KERN_DEBUG "xen: PV spinlocks disabled\n" ); +static_branch_disable (&virt_spin_lock_key);return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" );
Re: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Juergen GrossQuoted 95 lines · Juergen Gross
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 tovirt_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 Juergen Gross <[email protected]>--- arch/x86/include/asm/qspinlock.h | 11 +++++++++++ arch/x86/kernel/paravirt-spinlocks.c | 6 ++++++ arch/x86/kernel/smpboot.c | 2 ++ kernel/locking/qspinlock.c | 4 ++++ 4 files changed, 23 insertions(+)arch/x86/include/asm/qspinlock.h +11
-0@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <linux/jump_label.h> #include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #include <asm/paravirt.h> @@ -46,9 +47,15 @@ static inline void queued_spin_unlock(struct qspinlock *lock)#endif #ifdef CONFIG_PARAVIRT +DECLARE_STATIC_KEY_TRUE (virt_spin_lock_key); + +void native_pv_lock_init (void )__init ; +#define virt_spin_lock virt_spin_lockstatic inline bool virt_spin_lock (struct qspinlock *lock) { +if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;@@ -65,6 +72,10 @@ static inline bool virt_spin_lock(struct qspinlock *lock) return true; } +#else +static inline void native_pv_lock_init (void ) +{ +}#endif /* CONFIG_PARAVIRT */ #include <asm-generic/qspinlock.h> arch/x86/kernel/paravirt-spinlocks.c +6
-0@@ -42,3 +42,9 @@ struct pv_lock_ops pv_lock_ops = {#endif /* SMP */ };EXPORT_SYMBOL (pv_lock_ops); + +void __init native_pv_lock_init (void ) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +static_branch_disable (&virt_spin_lock_key); +}arch/x86/kernel/smpboot.c +2
-0@@ -77,6 +77,7 @@#include <asm/i8259.h> #include <asm/realmode.h> #include <asm/misc.h> +#include <asm/qspinlock.h> /* Number of siblings per CPU package */ int smp_num_siblings =1 ;@@ -1381,6 +1382,7 @@ void __init native_smp_prepare_boot_cpu(void)/* already set me in cpu_online_mask in boot_cpu_init() */ cpumask_set_cpu (me, cpu_callout_mask);cpu_set_state_online (me); +native_pv_lock_init (); }void __init native_smp_cpus_done (unsigned int max_cpus)kernel/locking/qspinlock.c +0
-0
kernel/locking/qspinlock.c line 85
Quoted 10 lines
kernel/locking/qspinlock.c +4
-0@@ -76,6 +76,10 @@#define MAX_NODES 4#endif +#ifdef CONFIG_PARAVIRT +DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key); +#endif +/* * Per-CPU queue node structures; we can never have more than 4 nested * contexts: task, softirq, hardirq, nmi.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Peter Zijlstra
maintainerRe: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Waiman LongQuoted 8 lines · Waiman Long
arch/x86/include/asm/qspinlock.h static inline void queued_spin_unlock(struct qspinlock *lock) · line 60
Quoted 8 lines
#define
virt_spin_lockvirt_spin_lock
static inline boolvirt_spin_lock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0+if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;
Now native has two NOPs instead of one. Can't we merge these two static branches?
Peter Zijlstra
maintainerRe: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Waiman LongQuoted 8 lines · Waiman Long
arch/x86/include/asm/qspinlock.h static inline void queued_spin_unlock(struct qspinlock *lock) · line 60
Quoted 8 lines
#define
virt_spin_lockvirt_spin_lock
static inline boolvirt_spin_lock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0+if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;
Now native has two NOPs instead of one. Can't we merge these two static branches?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Waiman Long
reviewerRe: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Peter ZijlstraQuoted 11 lines · Peter Zijlstra
Quoted 8 lines · Waiman Long
arch/x86/include/asm/qspinlock.h static inline void queued_spin_unlock(struct qspinlock *lock) · line 60
Quoted 8 lines
#define
virt_spin_lockvirt_spin_lock
static inline boolvirt_spin_lock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0+if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;Now native has two NOPs instead of one. Can't we merge these two static branches?
I guess we can remove the static_cpu_has() call. Just that any spin_lock calls before native_pv_lock_init() will use the virt_spin_lock(). That is still OK as the init call is done before SMP starts.
Cheers,
Longman
Waiman Long
reviewerRe: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Peter ZijlstraQuoted 11 lines · Peter Zijlstra
Quoted 8 lines · Waiman Long
arch/x86/include/asm/qspinlock.h static inline void queued_spin_unlock(struct qspinlock *lock) · line 60
Quoted 8 lines
#define
virt_spin_lockvirt_spin_lock
static inline boolvirt_spin_lock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0+if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;Now native has two NOPs instead of one. Can't we merge these two static branches?
I guess we can remove the static_cpu_has() call. Just that any spin_lock calls before native_pv_lock_init() will use the virt_spin_lock(). That is still OK as the init call is done before SMP starts.
Cheers,
Longman
Waiman Long
reviewerRe: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Peter ZijlstraQuoted 11 lines · Peter Zijlstra
Quoted 8 lines · Waiman Long
arch/x86/include/asm/qspinlock.h static inline void queued_spin_unlock(struct qspinlock *lock) · line 60
Quoted 8 lines
#define
virt_spin_lockvirt_spin_lock
static inline boolvirt_spin_lock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0+if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;Now native has two NOPs instead of one. Can't we merge these two static branches?
I guess we can remove the static_cpu_has() call. Just that any spin_lock calls before native_pv_lock_init() will use the virt_spin_lock(). That is still OK as the init call is done before SMP starts.
Cheers,
Longman
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Juergen Gross
maintainerRe: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Waiman LongQuoted 14 lines · Waiman Long
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Waiman Long
arch/x86/include/asm/qspinlock.h static inline void queued_spin_unlock(struct qspinlock *lock) · line 60
Quoted 8 lines
#define
virt_spin_lockvirt_spin_lock
static inline boolvirt_spin_lock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0+if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;Now native has two NOPs instead of one. Can't we merge these two static branches?
Quoted 3 lines
I guess we can remove the
static_cpu_has()call. Just that anyspin_lockcalls beforenative_pv_lock_init()will use thevirt_spin_lock(). That is still OK as the init call is done before SMP starts.
Hmm, right. I'll send V3 in some minutes.
Juergen
Juergen Gross
maintainerRe: [PATCH v2 1/2] paravirt/locks: use new static key for controlling call of virt_spin_lock()
In reply to Waiman LongQuoted 14 lines · Waiman Long
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · Waiman Long
arch/x86/include/asm/qspinlock.h static inline void queued_spin_unlock(struct qspinlock *lock) · line 60
Quoted 8 lines
#define
virt_spin_lockvirt_spin_lock
static inline boolvirt_spin_lock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0+if (!static_branch_likely (&virt_spin_lock_key)) +return false;if (!static_cpu_has (X86_FEATURE_HYPERVISOR ))return false;Now native has two NOPs instead of one. Can't we merge these two static branches?
Quoted 3 lines
I guess we can remove the
static_cpu_has()call. Just that anyspin_lockcalls beforenative_pv_lock_init()will use thevirt_spin_lock(). That is still OK as the init call is done before SMP starts.
Hmm, right. I'll send V3 in some minutes.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel