From: "Mohammed Gamal" Subject: Re: [PATCH] x86 emulator: Update EIP even with instructions with no writeback Date: Sun, 6 Jul 2008 16:26:37 +0300 Message-ID: <52d4a3890807060626g4c231ccem3e40798e15d8a65a@mail.gmail.com> References: <20080705191421.GA28785@mohd-laptop> <48707989.1050003@qumranet.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_20487_2302379.1215350797964" Cc: kvm@vger.kernel.org, riel@surriel.com To: "Avi Kivity" Return-path: Received: from an-out-0708.google.com ([209.85.132.242]:30411 "EHLO an-out-0708.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753974AbYGFN0j (ORCPT ); Sun, 6 Jul 2008 09:26:39 -0400 Received: by an-out-0708.google.com with SMTP id d40so351928and.103 for ; Sun, 06 Jul 2008 06:26:38 -0700 (PDT) In-Reply-To: <48707989.1050003@qumranet.com> Sender: kvm-owner@vger.kernel.org List-ID: ------=_Part_20487_2302379.1215350797964 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sun, Jul 6, 2008 at 10:51 AM, Avi Kivity wrote: > Mohammed Gamal wrote: >> >> This patch resolves the problem encountered with HLT emulation with >> FreeDOS's HIMEM XMS Driver. >> HLT is the only instruction that goes to the done label unconditionally, >> causing the EIP value not to be updated which leads to the guest looping >> forever on the same instruction. >> >> Signed-off-by: Mohammed Gamal >> >> --- >> >> arch/x86/kvm/x86_emulate.c | 4 +++- >> 1 files changed, 3 insertions(+), 1 deletions(-) >> >> diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c >> index dd4efe1..04d7f02 100644 >> --- a/arch/x86/kvm/x86_emulate.c >> +++ b/arch/x86/kvm/x86_emulate.c >> @@ -1769,13 +1769,15 @@ writeback: >> /* Commit shadow register state. */ >> memcpy(ctxt->vcpu->arch.regs, c->regs, sizeof c->regs); >> - kvm_rip_write(ctxt->vcpu, c->eip); >> done: >> if (rc == X86EMUL_UNHANDLEABLE) { >> c->eip = saved_eip; >> return -1; >> } >> + else >> + kvm_rip_write(ctxt->vcpu, c->eip); >> + >> return 0; > > Why not change hlt to writeback like all other instructions? > IIRC hlt doesn't do writebacks. So, instead of changing hlt to go for a bogus writeback, I thought it'd be more logical that since we're going to the done label anyway we check first if the instruction is unhandleable, in which case we write the saved EIP, otherwise we update the EIP value. Anyway, here is a patch that changes hlt to writeback. ------=_Part_20487_2302379.1215350797964 Content-Type: text/x-diff; name=hlt_bugfix.patch Content-Transfer-Encoding: base64 X-Attachment-Id: f_fiboh66x0 Content-Disposition: attachment; filename=hlt_bugfix.patch IGFyY2gveDg2L2t2bS94ODZfZW11bGF0ZS5jIHwgICAgMiArLQogMSBmaWxlcyBjaGFuZ2VkLCAx IGluc2VydGlvbnMoKyksIDEgZGVsZXRpb25zKC0pCgpkaWZmIC0tZ2l0IGEvYXJjaC94ODYva3Zt L3g4Nl9lbXVsYXRlLmMgYi9hcmNoL3g4Ni9rdm0veDg2X2VtdWxhdGUuYwppbmRleCBkZDRlZmUx Li42MmU3MWI2IDEwMDY0NAotLS0gYS9hcmNoL3g4Ni9rdm0veDg2X2VtdWxhdGUuYworKysgYi9h cmNoL3g4Ni9rdm0veDg2X2VtdWxhdGUuYwpAQCAtMTczMiw3ICsxNzMyLDcgQEAgc3BlY2lhbF9p bnNuOgogCQlicmVhazsKIAljYXNlIDB4ZjQ6ICAgICAgICAgICAgICAvKiBobHQgKi8KIAkJY3R4 dC0+dmNwdS0+YXJjaC5oYWx0X3JlcXVlc3QgPSAxOwotCQlnb3RvIGRvbmU7CisJCWJyZWFrOwog CWNhc2UgMHhmNToJLyogY21jICovCiAJCS8qIGNvbXBsZW1lbnQgY2FycnkgZmxhZyBmcm9tIGVm bGFncyByZWcgKi8KIAkJY3R4dC0+ZWZsYWdzIF49IEVGTEdfQ0Y7Cg== ------=_Part_20487_2302379.1215350797964--