KVM: x86 emulator: fix hypercall return value on AMD

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Wednesday, June 11, 2008 - 6:05 pm

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=33e388...
Commit:     33e3885de25148e00595c4dd808d6eb15db2edcf
Parent:     f20d2752980c144c82649eb18746ef0c29f508dd
Author:     Avi Kivity <avi@qumranet.com>
AuthorDate: Wed May 21 15:34:25 2008 +0300
Committer:  Avi Kivity <avi@qumranet.com>
CommitDate: Fri Jun 6 21:08:25 2008 +0300

    KVM: x86 emulator: fix hypercall return value on AMD
    
    The hypercall instructions on Intel and AMD are different.  KVM allows the
    guest to choose one or the other (the default is Intel), and if the guest
    chooses incorrectly, KVM will patch it at runtime to select the correct
    instruction.  This allows live migration between Intel and AMD machines.
    
    This patching occurs in the x86 emulator.  The current code also executes
    the hypercall.  Unfortunately, the tail end of the x86 emulator code also
    executes, overwriting the return value of the hypercall with the original
    contents of rax (which happens to be the hypercall number).
    
    Fix not by executing the hypercall in the emulator context; instead let the
    guest reissue the patched instruction and execute the hypercall via the
    normal path.
    
    Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 arch/x86/kvm/x86_emulate.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index 8a96320..932f216 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -1727,7 +1727,8 @@ twobyte_insn:
 			if (rc)
 				goto done;
 
-			kvm_emulate_hypercall(ctxt->vcpu);
+			/* Let the processor re-execute the fixed hypercall */
+			c->eip = ctxt->vcpu->arch.rip;
 			/* Disable writeback. */
 			c->dst.type = OP_NONE;
 			break;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
KVM: x86 emulator: fix hypercall return value on AMD, Linux Kernel Mailing ..., (Wed Jun 11, 6:05 pm)