From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K8plL-0004i6-Kj for qemu-devel@nongnu.org; Wed, 18 Jun 2008 00:59:15 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K8plJ-0004hi-VU for qemu-devel@nongnu.org; Wed, 18 Jun 2008 00:59:15 -0400 Received: from [199.232.76.173] (port=55898 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K8plJ-0004hf-RW for qemu-devel@nongnu.org; Wed, 18 Jun 2008 00:59:13 -0400 Received: from ns.suse.de ([195.135.220.2]:44738 helo=mx1.suse.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K8plI-0000M1-Pr for qemu-devel@nongnu.org; Wed, 18 Jun 2008 00:59:13 -0400 Message-ID: <4858961A.2010805@suse.de> Date: Wed, 18 Jun 2008 06:59:06 +0200 From: Alexander Graf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] SVM: Trap on correct IP References: <48585805.9070706@suse.de> In-Reply-To: <48585805.9070706@suse.de> Content-Type: multipart/mixed; boundary="------------050007090508040908070208" Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------050007090508040908070208 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Alexander Graf wrote: > Hi, > > Currently HLT always traps at the IP after the hlt instruction. SVM > requires its trap on the instruction's IP though, which breaks the > current implementation as soon as an HLT intercept occurs. > > This patch does the SVM intercept with an IP value before the HLT > instruction. > > Alex > > Signed-off-by: Alexander Graf > > This version should also fix MWAIT. Signed-off-by: Alexander Graf --------------050007090508040908070208 Content-Type: text/x-patch; name="qemu-svm-hlt.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-svm-hlt.patch" Index: target-i386/helper.h =================================================================== --- target-i386/helper.h (revision 4744) +++ target-i386/helper.h (working copy) @@ -60,9 +60,9 @@ DEF_HELPER(void, helper_syscall, (int next_eip_addend)) DEF_HELPER(void, helper_sysret, (int dflag)) #endif -DEF_HELPER(void, helper_hlt, (void)) +DEF_HELPER(void, helper_hlt, (int next_eip_addend)) DEF_HELPER(void, helper_monitor, (target_ulong ptr)) -DEF_HELPER(void, helper_mwait, (void)) +DEF_HELPER(void, helper_mwait, (int next_eip_addend)) DEF_HELPER(void, helper_debug, (void)) DEF_HELPER(void, helper_raise_interrupt, (int intno, int next_eip_addend)) DEF_HELPER(void, helper_raise_exception, (int exception_index)) Index: target-i386/op_helper.c =================================================================== --- target-i386/op_helper.c (revision 4744) +++ target-i386/op_helper.c (working copy) @@ -4547,9 +4547,10 @@ } #endif -void helper_hlt(void) +void helper_hlt(int next_eip_addend) { helper_svm_check_intercept_param(SVM_EXIT_HLT, 0); + EIP+=next_eip_addend; env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */ env->halted = 1; @@ -4565,7 +4566,7 @@ helper_svm_check_intercept_param(SVM_EXIT_MONITOR, 0); } -void helper_mwait(void) +void helper_mwait(int next_eip_addend) { if ((uint32_t)ECX != 0) raise_exception(EXCP0D_GPF); @@ -4575,7 +4576,8 @@ /* more than one CPU: do not sleep because another CPU may wake this one */ } else { - helper_hlt(); + /* XXX: is it ok to intercept HLT when MWAIT is not intercepted? */ + helper_hlt(next_eip_addend); } } Index: target-i386/translate.c =================================================================== --- target-i386/translate.c (revision 4744) +++ target-i386/translate.c (working copy) @@ -6420,8 +6420,8 @@ } else { if (s->cc_op != CC_OP_DYNAMIC) gen_op_set_cc_op(s->cc_op); - gen_jmp_im(s->pc - s->cs_base); - tcg_gen_helper_0_0(helper_hlt); + gen_jmp_im(pc_start - s->cs_base); + tcg_gen_helper_0_1(helper_hlt, tcg_const_i32(s->pc - pc_start)); s->is_jmp = 3; } break; @@ -6541,8 +6541,8 @@ gen_op_set_cc_op(s->cc_op); s->cc_op = CC_OP_DYNAMIC; } - gen_jmp_im(s->pc - s->cs_base); - tcg_gen_helper_0_0(helper_mwait); + gen_jmp_im(pc_start - s->cs_base); + tcg_gen_helper_0_1(helper_mwait, tcg_const_i32(s->pc - pc_start)); gen_eob(s); break; default: --------------050007090508040908070208--