diff options
author | Gleb Natapov <gleb@redhat.com> | 2011-04-01 10:26:29 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-05-11 07:56:57 -0400 |
commit | 1499e54af03ae51a937c59035bc86002deae0572 (patch) | |
tree | 89f75af765784f573f818737e7aa3392eaabac52 /arch/x86/kvm/x86.c | |
parent | c761e5868e6737abe0464636ebd7fcbb6814c626 (diff) |
KVM: x86: better fix for race between nmi injection and enabling nmi window
Fix race between nmi injection and enabling nmi window in a simpler way.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b9402d5fa0e9..692c70d6fd02 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -5171,6 +5171,7 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu) | |||
5171 | static int vcpu_enter_guest(struct kvm_vcpu *vcpu) | 5171 | static int vcpu_enter_guest(struct kvm_vcpu *vcpu) |
5172 | { | 5172 | { |
5173 | int r; | 5173 | int r; |
5174 | bool nmi_pending; | ||
5174 | bool req_int_win = !irqchip_in_kernel(vcpu->kvm) && | 5175 | bool req_int_win = !irqchip_in_kernel(vcpu->kvm) && |
5175 | vcpu->run->request_interrupt_window; | 5176 | vcpu->run->request_interrupt_window; |
5176 | 5177 | ||
@@ -5214,11 +5215,19 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) | |||
5214 | if (unlikely(r)) | 5215 | if (unlikely(r)) |
5215 | goto out; | 5216 | goto out; |
5216 | 5217 | ||
5218 | /* | ||
5219 | * An NMI can be injected between local nmi_pending read and | ||
5220 | * vcpu->arch.nmi_pending read inside inject_pending_event(). | ||
5221 | * But in that case, KVM_REQ_EVENT will be set, which makes | ||
5222 | * the race described above benign. | ||
5223 | */ | ||
5224 | nmi_pending = ACCESS_ONCE(vcpu->arch.nmi_pending); | ||
5225 | |||
5217 | if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) { | 5226 | if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) { |
5218 | inject_pending_event(vcpu); | 5227 | inject_pending_event(vcpu); |
5219 | 5228 | ||
5220 | /* enable NMI/IRQ window open exits if needed */ | 5229 | /* enable NMI/IRQ window open exits if needed */ |
5221 | if (vcpu->arch.nmi_pending) | 5230 | if (nmi_pending) |
5222 | kvm_x86_ops->enable_nmi_window(vcpu); | 5231 | kvm_x86_ops->enable_nmi_window(vcpu); |
5223 | else if (kvm_cpu_has_interrupt(vcpu) || req_int_win) | 5232 | else if (kvm_cpu_has_interrupt(vcpu) || req_int_win) |
5224 | kvm_x86_ops->enable_irq_window(vcpu); | 5233 | kvm_x86_ops->enable_irq_window(vcpu); |