Merge tag 'kvm-3.9-1' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[firefly-linux-kernel-4.4.55.git] / arch / powerpc / kvm / book3s_pr.c
index 73ed11c41bacfe691f60607c5519b179ae13f3cf..5e93438afb068c89b27062cec2bb772d4e77ce4c 100644 (file)
@@ -34,6 +34,8 @@
 #include <asm/kvm_book3s.h>
 #include <asm/mmu_context.h>
 #include <asm/switch_to.h>
+#include <asm/firmware.h>
+#include <asm/hvcall.h>
 #include <linux/gfp.h>
 #include <linux/sched.h>
 #include <linux/vmalloc.h>
@@ -1289,12 +1291,21 @@ void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
 {
 }
 
+static unsigned int kvm_global_user_count = 0;
+static DEFINE_SPINLOCK(kvm_global_user_count_lock);
+
 int kvmppc_core_init_vm(struct kvm *kvm)
 {
 #ifdef CONFIG_PPC64
        INIT_LIST_HEAD(&kvm->arch.spapr_tce_tables);
 #endif
 
+       if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
+               spin_lock(&kvm_global_user_count_lock);
+               if (++kvm_global_user_count == 1)
+                       pSeries_disable_reloc_on_exc();
+               spin_unlock(&kvm_global_user_count_lock);
+       }
        return 0;
 }
 
@@ -1303,6 +1314,14 @@ void kvmppc_core_destroy_vm(struct kvm *kvm)
 #ifdef CONFIG_PPC64
        WARN_ON(!list_empty(&kvm->arch.spapr_tce_tables));
 #endif
+
+       if (firmware_has_feature(FW_FEATURE_SET_MODE)) {
+               spin_lock(&kvm_global_user_count_lock);
+               BUG_ON(kvm_global_user_count == 0);
+               if (--kvm_global_user_count == 0)
+                       pSeries_enable_reloc_on_exc();
+               spin_unlock(&kvm_global_user_count_lock);
+       }
 }
 
 static int kvmppc_book3s_init(void)