Skip to content

Commit 0985dba

Browse files
dwmw2bonzini
authored andcommitted
KVM: x86/xen: Fix kvm_xen_has_interrupt() sleeping in kvm_vcpu_block()
In kvm_vcpu_block, the current task is set to TASK_INTERRUPTIBLE before making a final check whether the vCPU should be woken from HLT by any incoming interrupt. This is a problem for the get_user() in __kvm_xen_has_interrupt(), which really shouldn't be sleeping when the task state has already been set. I think it's actually harmless as it would just manifest itself as a spurious wakeup, but it's causing a debug warning: [ 230.963649] do not call blocking ops when !TASK_RUNNING; state=1 set at [<00000000b6bcdbc9>] prepare_to_swait_exclusive+0x30/0x80 Fix the warning by turning it into an *explicit* spurious wakeup. When invoked with !task_is_running(current) (and we might as well add in_atomic() there while we're at it), just return 1 to indicate that an IRQ is pending, which will cause a wakeup and then something will call it again in a context that *can* sleep so it can fault the page back in. Cc: [email protected] Fixes: 40da8cc ("KVM: x86/xen: Add event channel interrupt vector upcall") Signed-off-by: David Woodhouse <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 4b2caef commit 0985dba

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

arch/x86/kvm/xen.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, int state)
190190

191191
int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
192192
{
193+
int err;
193194
u8 rc = 0;
194195

195196
/*
@@ -216,13 +217,29 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v)
216217
if (likely(slots->generation == ghc->generation &&
217218
!kvm_is_error_hva(ghc->hva) && ghc->memslot)) {
218219
/* Fast path */
219-
__get_user(rc, (u8 __user *)ghc->hva + offset);
220-
} else {
221-
/* Slow path */
222-
kvm_read_guest_offset_cached(v->kvm, ghc, &rc, offset,
223-
sizeof(rc));
220+
pagefault_disable();
221+
err = __get_user(rc, (u8 __user *)ghc->hva + offset);
222+
pagefault_enable();
223+
if (!err)
224+
return rc;
224225
}
225226

227+
/* Slow path */
228+
229+
/*
230+
* This function gets called from kvm_vcpu_block() after setting the
231+
* task to TASK_INTERRUPTIBLE, to see if it needs to wake immediately
232+
* from a HLT. So we really mustn't sleep. If the page ended up absent
233+
* at that point, just return 1 in order to trigger an immediate wake,
234+
* and we'll end up getting called again from a context where we *can*
235+
* fault in the page and wait for it.
236+
*/
237+
if (in_atomic() || !task_is_running(current))
238+
return 1;
239+
240+
kvm_read_guest_offset_cached(v->kvm, ghc, &rc, offset,
241+
sizeof(rc));
242+
226243
return rc;
227244
}
228245

0 commit comments

Comments
 (0)