|
@@ -498,6 +498,34 @@ static void __init kvm_apf_trap_init(void)
|
|
|
update_intr_gate(X86_TRAP_PF, async_page_fault);
|
|
|
}
|
|
|
|
|
|
+static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask);
|
|
|
+
|
|
|
+static void kvm_flush_tlb_others(const struct cpumask *cpumask,
|
|
|
+ const struct flush_tlb_info *info)
|
|
|
+{
|
|
|
+ u8 state;
|
|
|
+ int cpu;
|
|
|
+ struct kvm_steal_time *src;
|
|
|
+ struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
|
|
|
+
|
|
|
+ cpumask_copy(flushmask, cpumask);
|
|
|
+ /*
|
|
|
+ * We have to call flush only on online vCPUs. And
|
|
|
+ * queue flush_on_enter for pre-empted vCPUs
|
|
|
+ */
|
|
|
+ for_each_cpu(cpu, flushmask) {
|
|
|
+ src = &per_cpu(steal_time, cpu);
|
|
|
+ state = READ_ONCE(src->preempted);
|
|
|
+ if ((state & KVM_VCPU_PREEMPTED)) {
|
|
|
+ if (try_cmpxchg(&src->preempted, &state,
|
|
|
+ state | KVM_VCPU_FLUSH_TLB))
|
|
|
+ __cpumask_clear_cpu(cpu, flushmask);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ native_flush_tlb_others(flushmask, info);
|
|
|
+}
|
|
|
+
|
|
|
static void __init kvm_guest_init(void)
|
|
|
{
|
|
|
int i;
|
|
@@ -517,6 +545,9 @@ static void __init kvm_guest_init(void)
|
|
|
pv_time_ops.steal_clock = kvm_steal_clock;
|
|
|
}
|
|
|
|
|
|
+ if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH))
|
|
|
+ pv_mmu_ops.flush_tlb_others = kvm_flush_tlb_others;
|
|
|
+
|
|
|
if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
|
|
|
apic_set_eoi_write(kvm_guest_apic_eoi_write);
|
|
|
|
|
@@ -598,6 +629,22 @@ static __init int activate_jump_labels(void)
|
|
|
}
|
|
|
arch_initcall(activate_jump_labels);
|
|
|
|
|
|
+static __init int kvm_setup_pv_tlb_flush(void)
|
|
|
+{
|
|
|
+ int cpu;
|
|
|
+
|
|
|
+ if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH)) {
|
|
|
+ for_each_possible_cpu(cpu) {
|
|
|
+ zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
|
|
|
+ GFP_KERNEL, cpu_to_node(cpu));
|
|
|
+ }
|
|
|
+ pr_info("KVM setup pv remote TLB flush\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+arch_initcall(kvm_setup_pv_tlb_flush);
|
|
|
+
|
|
|
#ifdef CONFIG_PARAVIRT_SPINLOCKS
|
|
|
|
|
|
/* Kick a cpu by its apicid. Used to wake up a halted vcpu */
|