Merge branch 'kvm-5.16-fixes' into kvm-master
[linux-2.6-microblaze.git] / arch / x86 / kvm / xen.c
index 272be5c..565da9c 100644 (file)
@@ -190,6 +190,7 @@ void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, int state)
 
 int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
 {
+       int err;
        u8 rc = 0;
 
        /*
@@ -216,13 +217,29 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
        if (likely(slots->generation == ghc->generation &&
                   !kvm_is_error_hva(ghc->hva) && ghc->memslot)) {
                /* Fast path */
-               __get_user(rc, (u8 __user *)ghc->hva + offset);
-       } else {
-               /* Slow path */
-               kvm_read_guest_offset_cached(v->kvm, ghc, &rc, offset,
-                                            sizeof(rc));
+               pagefault_disable();
+               err = __get_user(rc, (u8 __user *)ghc->hva + offset);
+               pagefault_enable();
+               if (!err)
+                       return rc;
        }
 
+       /* Slow path */
+
+       /*
+        * This function gets called from kvm_vcpu_block() after setting the
+        * task to TASK_INTERRUPTIBLE, to see if it needs to wake immediately
+        * from a HLT. So we really mustn't sleep. If the page ended up absent
+        * at that point, just return 1 in order to trigger an immediate wake,
+        * and we'll end up getting called again from a context where we *can*
+        * fault in the page and wait for it.
+        */
+       if (in_atomic() || !task_is_running(current))
+               return 1;
+
+       kvm_read_guest_offset_cached(v->kvm, ghc, &rc, offset,
+                                    sizeof(rc));
+
        return rc;
 }