x86, lib: Add a wbinvd helper for an arbitrary cpu set
PATCH 1/2 x86, lib: Add a wbinvd helper for an arbitrary cpu set
From: Borislav Petkov <[email protected]>
Add a wbinvd helper for an arbitrary set of CPUs.
--- arch/x86/include/asm/smp.h | 4 +++- arch/x86/lib/cache-smp.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletions(-)
arch/x86/include/asm/smp.h +3 -1
@@ -141,6 +141,7 @@ void native_cpu_die(unsigned int cpu);void native_play_dead (void );void play_dead_common (void );void wbinvd_on_cpu (int cpu); +void wbinvd_on_cpus (const struct cpumask *);int wbinvd_on_all_cpus (void );void native_send_call_func_ipi (const struct cpumask *mask);
@@ -155,7 +156,8 @@ static inline int num_booting_cpus(void) return cpumask_weight(cpu_callout_mask); }#else /* !CONFIG_SMP */ -#define wbinvd_on_cpu (cpu) wbinvd() +#define wbinvd_on_cpu (cpu) wbinvd() +#define wbinvd_on_cpus (mask) wbinvd()static inline int wbinvd_on_all_cpus (void ) {wbinvd ();
arch/x86/lib/cache-smp.c +12 -0
@@ -12,6 +12,18 @@ void wbinvd_on_cpu(int cpu) }EXPORT_SYMBOL (wbinvd_on_cpu); +void wbinvd_on_cpus (const struct cpumask *mask) +{ +int this_cpu =get_cpu (); + +if (cpumask_test_cpu (this_cpu, mask)) +wbinvd (); + +smp_call_function_many (mask, __wbinvd,NULL ,1 ); +put_cpu (); +} +EXPORT_SYMBOL (wbinvd_on_cpus); +int wbinvd_on_all_cpus (void ) {return on_each_cpu (__wbinvd,NULL ,1 );
Signature · 1 line
1.7.3.1.50.g1e633
PATCH 2/2 kvm: Use wbinvd library functions
From: Borislav Petkov <[email protected]>
Replace local wbinvd helpers with equivalent x86 library functions.
--- arch/x86/kvm/x86.c | 14 +++----------- 1 files changed, 3 insertions(+), 11 deletions(-)
arch/x86/kvm/x86.c +3 -11
@@ -50,6 +50,7 @@#include <asm/debugreg.h> #include <asm/msr.h> +#include <asm/smp.h> #include <asm/desc.h> #include <asm/mtrr.h> #include <asm/mce.h>
@@ -2029,11 +2030,6 @@ out:return r; } -static void wbinvd_ipi (void *garbage) -{ -wbinvd (); -} -static bool need_emulate_wbinvd (struct kvm_vcpu *vcpu) { return vcpu->kvm->arch.iommu_domain &&
@@ -2047,8 +2043,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)if (kvm_x86_ops->has_wbinvd_exit ())cpumask_set_cpu (cpu, vcpu->arch.wbinvd_dirty_mask);else if (vcpu->cpu !=-1 && vcpu->cpu != cpu) -smp_call_function_single (vcpu->cpu, - wbinvd_ipi,NULL ,1 ); +wbinvd_on_cpu (vcpu->cpu); } kvm_x86_ops->vcpu_load (vcpu, cpu);
@@ -3978,10 +3973,7 @@ int kvm_emulate_wbinvd(struct kvm_vcpu *vcpu)return X86EMUL_CONTINUE ;if (kvm_x86_ops->has_wbinvd_exit ()) { -preempt_disable (); -smp_call_function_many (vcpu->arch.wbinvd_dirty_mask, - wbinvd_ipi,NULL ,1 ); -preempt_enable (); +wbinvd_on_cpus (vcpu->arch.wbinvd_dirty_mask);cpumask_clear (vcpu->arch.wbinvd_dirty_mask); }wbinvd ();
Signature · 1 line
1.7.3.1.50.g1e633
H. Peter Anvin
reviewerQuoted 4 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Add a wbinvd helper for an arbitrary set of CPUs.
Are there any expected users of this other than KVM?
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Quoted 7 lines · H. Peter Anvin
Quoted 4 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Add a wbinvd helper for an arbitrary set of CPUs.
Are there any expected users of this other than KVM?
Not that I know of. I had an earlier version for kvm which did
for_each_cpu(cpu, mask)
wbinvd_on_cpu(cpu)
but decided to add wbinvd_on_cpus() for completeness. Let me know what your preference is.
Thanks.
Signature · 8 lines
Regards/Gruss, Boris. Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632