From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH] x86: clear guest's EFLAGS.RF after emulating instructions Date: Tue, 19 Jun 2007 11:53:18 +0200 Message-ID: <4677C3AE.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Signed-off-by: Jan Beulich Index: 2007-06-18/xen/arch/x86/hvm/io.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-06-18.orig/xen/arch/x86/hvm/io.c 2007-06-18 11:26:06.0000000= 00 +0200 +++ 2007-06-18/xen/arch/x86/hvm/io.c 2007-06-18 11:12:47.000000000 = +0200 @@ -858,6 +858,7 @@ void hvm_io_assist(void) } =20 /* Copy register changes back into current guest state. */ + regs->eflags &=3D ~X86_EFLAGS_RF; hvm_load_cpu_guest_regs(v, regs); memcpy(guest_cpu_user_regs(), regs, HVM_CONTEXT_STACK_BYTES); =20 Index: 2007-06-18/xen/arch/x86/hvm/platform.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-06-18.orig/xen/arch/x86/hvm/platform.c 2007-06-18 11:26:06.0000000= 00 +0200 +++ 2007-06-18/xen/arch/x86/hvm/platform.c 2007-06-18 11:12:47.0000000= 00 +0200 @@ -1065,6 +1065,7 @@ void handle_mmio(unsigned long gpa) } =20 regs->eip +=3D inst_len; /* advance %eip */ + regs->eflags &=3D ~X86_EFLAGS_RF; =20 switch ( mmio_op->instr ) { case INSTR_MOV: @@ -1122,6 +1123,7 @@ void handle_mmio(unsigned long gpa) /* IO read --> memory write */ if ( dir =3D=3D IOREQ_READ ) errcode |=3D PFEC_write_access; regs->eip -=3D inst_len; /* do not advance %eip */ + regs->eflags |=3D X86_EFLAGS_RF; hvm_inject_exception(TRAP_page_fault, errcode, addr); return; } @@ -1150,6 +1152,7 @@ void handle_mmio(unsigned long gpa) /* Failed on the page-spanning copy. Inject PF = into * the guest for the address where we failed */ regs->eip -=3D inst_len; /* do not advance %eip = */ + regs->eflags |=3D X86_EFLAGS_RF; /* Must set CR2 at the failing address */=20 addr +=3D size - rv; gdprintk(XENLOG_DEBUG, "Pagefault on non-io side = of a " Index: 2007-06-18/xen/arch/x86/hvm/vmx/vmx.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-06-18.orig/xen/arch/x86/hvm/vmx/vmx.c 2007-06-18 11:26:06.0000000= 00 +0200 +++ 2007-06-18/xen/arch/x86/hvm/vmx/vmx.c 2007-06-18 11:14:48.0000000= 00 +0200 @@ -1300,16 +1300,20 @@ static int __get_instruction_length(void =20 static void inline __update_guest_eip(unsigned long inst_len) { - unsigned long current_eip, intr_shadow; + unsigned long curr; =20 - current_eip =3D __vmread(GUEST_RIP); - __vmwrite(GUEST_RIP, current_eip + inst_len); + curr =3D __vmread(GUEST_RIP); + __vmwrite(GUEST_RIP, curr + inst_len); =20 - intr_shadow =3D __vmread(GUEST_INTERRUPTIBILITY_INFO); - if ( intr_shadow & (VMX_INTR_SHADOW_STI | VMX_INTR_SHADOW_MOV_SS) ) + curr =3D __vmread(GUEST_RFLAGS); + if (curr & X86_EFLAGS_RF) + __vmwrite(GUEST_RFLAGS, curr & ~X86_EFLAGS_RF); + + curr =3D __vmread(GUEST_INTERRUPTIBILITY_INFO); + if ( curr & (VMX_INTR_SHADOW_STI | VMX_INTR_SHADOW_MOV_SS) ) { - intr_shadow &=3D ~(VMX_INTR_SHADOW_STI | VMX_INTR_SHADOW_MOV_SS); - __vmwrite(GUEST_INTERRUPTIBILITY_INFO, intr_shadow); + curr &=3D ~(VMX_INTR_SHADOW_STI | VMX_INTR_SHADOW_MOV_SS); + __vmwrite(GUEST_INTERRUPTIBILITY_INFO, curr); } } =20 @@ -1881,7 +1885,7 @@ static void vmx_world_save(struct vcpu * c->eip +=3D __get_instruction_length(); /* Safe: MOV Cn, LMSW, CLTS = */ =20 c->esp =3D __vmread(GUEST_RSP); - c->eflags =3D __vmread(GUEST_RFLAGS); + c->eflags =3D __vmread(GUEST_RFLAGS) & ~X86_EFLAGS_RF; =20 c->cr0 =3D v->arch.hvm_vmx.cpu_shadow_cr0; c->cr3 =3D v->arch.hvm_vmx.cpu_cr3; @@ -2257,7 +2261,6 @@ static int vmx_set_cr0(unsigned long val "Enabling CR0.PE at %%eip 0x%lx", eip); if ( vmx_assist(v, VMX_ASSIST_RESTORE) ) { - eip =3D __vmread(GUEST_RIP); HVM_DBG_LOG(DBG_LEVEL_1, "Restoring to %%eip 0x%lx", eip); return 0; /* do not update eip! */ Index: 2007-06-18/xen/arch/x86/traps.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-06-18.orig/xen/arch/x86/traps.c 2007-06-18 11:26:06.0000000= 00 +0200 +++ 2007-06-18/xen/arch/x86/traps.c 2007-06-18 11:12:47.000000000 = +0200 @@ -621,6 +621,7 @@ static int emulate_forced_invalid_op(str regs->ecx =3D c; regs->edx =3D d; regs->eip =3D eip; + regs->eflags &=3D ~X86_EFLAGS_RF; =20 return EXCRET_fault_fixed; } @@ -1777,6 +1778,7 @@ static int emulate_privileged_op(struct=20 =20 done: regs->eip =3D eip; + regs->eflags &=3D ~X86_EFLAGS_RF; return EXCRET_fault_fixed; =20 fail: Index: 2007-06-18/xen/arch/x86/x86_emulate.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-06-18.orig/xen/arch/x86/x86_emulate.c 2007-06-18 11:26:06.0000000= 00 +0200 +++ 2007-06-18/xen/arch/x86/x86_emulate.c 2007-06-18 11:26:45.0000000= 00 +0200 @@ -1630,6 +1630,7 @@ x86_emulate( } =20 /* Commit shadow register state. */ + _regs.eflags &=3D ~EF_RF; *ctxt->regs =3D _regs; =20 done: Index: 2007-06-18/xen/include/asm-x86/hvm/svm/emulate.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-06-18.orig/xen/include/asm-x86/hvm/svm/emulate.h 2007-06-18 = 11:26:06.000000000 +0200 +++ 2007-06-18/xen/include/asm-x86/hvm/svm/emulate.h 2007-06-18 = 11:12:47.000000000 +0200 @@ -138,6 +138,7 @@ static void inline __update_guest_eip( { ASSERT(inst_len > 0); vmcb->rip +=3D inst_len; + vmcb->rflags &=3D ~X86_EFLAGS_RF; } =20 #endif /* __ASM_X86_HVM_SVM_EMULATE_H__ */