Skip to contentSkip to conversation

KVM: x86: Fix immediate_exit handling for uninitialized AP

PATCH In review Jan H. Schönherr 2 participants 2 messages Sep 6, 2017 – Sep 13, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: Fix immediate_exit handling for uninitialized AP

When user space sets kvm_run->immediate_exit, KVM is supposed to return quickly. However, when a vCPU is in KVM_MP_STATE_UNINITIALIZED, the value is not considered and the vCPU blocks.

Fix that oversight.

Fixes 460df4c1fc7c008 ("KVM: race-free exit from KVM_RUN without POSIX signals")

---
compile-time tested only

---
 arch/x86/kvm/x86.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kvm/x86.c +4 -0
index 40039cd..a69a948 100644
@@ -7199,6 +7199,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
 
 	if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_UNINITIALIZED)) {
+		if (kvm_run->immediate_exit) {
+			r = -EINTR;
+			goto out;
+		}
 		kvm_vcpu_block(vcpu);
 		kvm_apic_accept_events(vcpu);
 		kvm_clear_request(KVM_REQ_UNHALT, vcpu);
Signature · 1 line
2.3.1.dirty
#1 lore raw

2017-09-06 18:34+0200, Jan H. Schönherr:

Quoted 19 lines

When user space sets kvm_run->immediate_exit, KVM is supposed to return quickly. However, when a vCPU is in KVM_MP_STATE_UNINITIALIZED, the value is not considered and the vCPU blocks.

Fix that oversight.

Fixes 460df4c1fc7c008 ("KVM: race-free exit from KVM_RUN without POSIX signals")

---
compile-time tested only

---
 arch/x86/kvm/x86.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kvm/x86.c +0 -0
index 40039cd..a69a948 100644

arch/x86/kvm/x86.c int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) · line 7206

Quoted 8 lines
arch/x86/kvm/x86.c +4 -0
@@ -7199,6 +7199,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
 
 	if (unlikely(vcpu->arch.mp_state == KVM_MP_STATE_UNINITIALIZED)) {
+		if (kvm_run->immediate_exit) {
+			r = -EINTR;
+			goto out;
+		}
 		kvm_vcpu_block(vcpu);

Without immediate_exit, we would also execute the following code, but I think it's ok not to ... queued, thanks.

Quoted 5 lines
arch/x86/kvm/x86.c +0 -0
 		kvm_apic_accept_events(vcpu);
 		kvm_clear_request(KVM_REQ_UNHALT, vcpu);
Signature · 1 line
2.3.1.dirty