Skip to contentSkip to conversation

VMRUN should store the RIP after the instruction

PATCH In review Alexander Graf 2 participants 4 messages Jun 4, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VMRUN should store the RIP after the instruction

VMRUN stores the IP which is used to return to the instruction after the VMRUN in case of a VMEXIT. Due to recent changes, this does not happen anymore and a VMEXIT simply returns to the VMRUN instruction.

Alex

op_helper.c +1 -1
Index: target-i386/op_helper.c
===================================================================
@@ -4836,7 +4836,7 @@
     svm_save_seg(env->vm_hsave + offsetof(struct vmcb, save.ds), 
                  &env->segs[R_DS]);
 
-    stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rip), EIP);
+    stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rip), EIP + 3);
     stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rsp), ESP);
     stq_phys(env->vm_hsave + offsetof(struct vmcb, save.rax), EAX);
 
#1 lore raw
Quoted 3 lines · Alexander Graf

VMRUN stores the IP which is used to return to the instruction after the VMRUN in case of a VMEXIT. Due to recent changes, this does not happen anymore and a VMEXIT simply returns to the VMRUN instruction.

Alex

The open-coded + 3 bothers me. Are there any circumstances that a prefix could be used with vmrun that would change the instruction length? vmrun doesn't appear to be affected by prefixes but I don't see anything in the AMD manual specifically forbidding it.

Regards,

Anthony Liguori

#2 lore raw
Quoted 6 lines · Anthony Liguori
Quoted 3 lines · Alexander Graf

VMRUN stores the IP which is used to return to the instruction after the VMRUN in case of a VMEXIT. Due to recent changes, this does not happen anymore and a VMEXIT simply returns to the VMRUN instruction.

Alex

The open-coded + 3 bothers me. Are there any circumstances that a prefix could be used with vmrun that would change the instruction length? vmrun doesn't appear to be affected by prefixes but I don't see anything in the AMD manual specifically forbidding it.

This is true and it bothers me as well. I am open to suggestions how to receive the IP after the instruction that is about to be executed. Probably this could be done in translate.c?

Alex

#3 lore raw
Quoted 11 lines · Alexander Graf
Quoted 6 lines · Anthony Liguori
Quoted 3 lines · Alexander Graf

VMRUN stores the IP which is used to return to the instruction after the VMRUN in case of a VMEXIT. Due to recent changes, this does not happen anymore and a VMEXIT simply returns to the VMRUN instruction.

Alex

The open-coded + 3 bothers me. Are there any circumstances that a prefix could be used with vmrun that would change the instruction length? vmrun doesn't appear to be affected by prefixes but I don't see anything in the AMD manual specifically forbidding it.

This is true and it bothers me as well. I am open to suggestions how to receive the IP after the instruction that is about to be executed. Probably this could be done in translate.c?

Looks like Fabrice's commit handles it nicely.

Regards,

Anthony Liguori

Quoted 1 line

Alex