Commit 3dbef3e3bf13d74582fe43548f5c570a0cec9b20

Authored by Raghavendra K T
Committed by Gleb Natapov
1 parent 9d05746e7b

KVM: Enable pvspinlock after jump_label_init() to avoid VM hang

We use jump label to enable pv-spinlock. With the changes in (442e0973e927
Merge branch 'x86/jumplabel'), the jump label behaviour has changed
that would result in eventual hang of the VM since we would end up in a
situation where slow path locks would halt the vcpus but we will not be
able to wakeup the vcpu by lock releaser using unlock kick.

Similar problem in Xen and more detailed description is available in
a945928ea270 (xen: Do not enable spinlocks before jump_label_init()
has executed)

This patch splits kvm_spinlock_init to separate jump label changes with
pvops patching and also make jump label enabling after jump_label_init().

Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Gleb Natapov <gleb@redhat.com>

Showing 1 changed file with 14 additions and 3 deletions Side-by-side Diff

arch/x86/kernel/kvm.c
... ... @@ -775,12 +775,23 @@
775 775 if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT))
776 776 return;
777 777  
778   - printk(KERN_INFO "KVM setup paravirtual spinlock\n");
  778 + pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(kvm_lock_spinning);
  779 + pv_lock_ops.unlock_kick = kvm_unlock_kick;
  780 +}
779 781  
  782 +static __init int kvm_spinlock_init_jump(void)
  783 +{
  784 + if (!kvm_para_available())
  785 + return 0;
  786 + if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT))
  787 + return 0;
  788 +
780 789 static_key_slow_inc(&paravirt_ticketlocks_enabled);
  790 + printk(KERN_INFO "KVM setup paravirtual spinlock\n");
781 791  
782   - pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(kvm_lock_spinning);
783   - pv_lock_ops.unlock_kick = kvm_unlock_kick;
  792 + return 0;
784 793 }
  794 +early_initcall(kvm_spinlock_init_jump);
  795 +
785 796 #endif /* CONFIG_PARAVIRT_SPINLOCKS */