* [PATCH] KVM: Fix mmu_reload() clash with nested vmx event injection
@ 2012-05-14 15:07 Avi Kivity
2012-05-16 21:12 ` Marcelo Tosatti
0 siblings, 1 reply; 2+ messages in thread
From: Avi Kivity @ 2012-05-14 15:07 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm
Currently the inject_pending_event() call during guest entry happens after
kvm_mmu_reload(). This is for historical reasons - we used to
inject_pending_event() in atomic context, while kvm_mmu_reload() needs task
context.
A problem is that nested vmx can cause the mmu context to be reset, if event
injection is intercepted and causes a #VMEXIT instead (the #VMEXIT resets
CR0/CR3/CR4). If this happens, we end up with invalid root_hpa, and since
kvm_mmu_reload() has already run, no one will fix it and we end up entering
the guest this way.
Fix by reordering event injection to be before kvm_mmu_reload(). Use
->cancel_injection() to undo if kvm_mmu_reload() fails.
https://bugzilla.kernel.org/show_bug.cgi?id=42980
Reported-by: Luke-Jr <luke-jr+linuxbugs@utopios.org>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
arch/x86/kvm/x86.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 4de705c..b78f89d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5279,10 +5279,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
kvm_deliver_pmi(vcpu);
}
- r = kvm_mmu_reload(vcpu);
- if (unlikely(r))
- goto out;
-
if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) {
inject_pending_event(vcpu);
@@ -5298,6 +5294,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
}
}
+ r = kvm_mmu_reload(vcpu);
+ if (unlikely(r)) {
+ kvm_x86_ops->cancel_injection(vcpu);
+ goto out;
+ }
+
preempt_disable();
kvm_x86_ops->prepare_guest_switch(vcpu);
--
1.7.10.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] KVM: Fix mmu_reload() clash with nested vmx event injection
2012-05-14 15:07 [PATCH] KVM: Fix mmu_reload() clash with nested vmx event injection Avi Kivity
@ 2012-05-16 21:12 ` Marcelo Tosatti
0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2012-05-16 21:12 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm
On Mon, May 14, 2012 at 06:07:56PM +0300, Avi Kivity wrote:
> Currently the inject_pending_event() call during guest entry happens after
> kvm_mmu_reload(). This is for historical reasons - we used to
> inject_pending_event() in atomic context, while kvm_mmu_reload() needs task
> context.
>
> A problem is that nested vmx can cause the mmu context to be reset, if event
> injection is intercepted and causes a #VMEXIT instead (the #VMEXIT resets
> CR0/CR3/CR4). If this happens, we end up with invalid root_hpa, and since
> kvm_mmu_reload() has already run, no one will fix it and we end up entering
> the guest this way.
>
> Fix by reordering event injection to be before kvm_mmu_reload(). Use
> ->cancel_injection() to undo if kvm_mmu_reload() fails.
>
> https://bugzilla.kernel.org/show_bug.cgi?id=42980
>
> Reported-by: Luke-Jr <luke-jr+linuxbugs@utopios.org>
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
> arch/x86/kvm/x86.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-16 21:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-14 15:07 [PATCH] KVM: Fix mmu_reload() clash with nested vmx event injection Avi Kivity
2012-05-16 21:12 ` Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox