From: "Mohammed Gamal" Subject: Re: [PATCH][RESEND] x86_emulator: Emulate cld and std instruction Date: Thu, 31 Jul 2008 13:25:40 +0300 Message-ID: <52d4a3890807310325r208b7943h89df5490e2af0131@mail.gmail.com> References: <20080730212727.GA7708@mohd-laptop> <48918C6C.1000408@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, riel@surriel.com To: "Avi Kivity" Return-path: Received: from an-out-0708.google.com ([209.85.132.243]:28664 "EHLO an-out-0708.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbYGaKZl (ORCPT ); Thu, 31 Jul 2008 06:25:41 -0400 Received: by an-out-0708.google.com with SMTP id d40so75774and.103 for ; Thu, 31 Jul 2008 03:25:40 -0700 (PDT) In-Reply-To: <48918C6C.1000408@qumranet.com> Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: On Thu, Jul 31, 2008 at 12:57 PM, Avi Kivity wrote: > Mohammed Gamal wrote: >> >> This patch adds 'cld' and 'std' instructions to the emulator >> >> > > I presume for big real mode? Which guest wants it? Actually I was experimenting with checking guest state and emulating on mode switches. When I was doing so, it used to happen with all guests, so I guess it maybe something related to the BIOS not a specific guest. BTW, the other way we can do is still handle vmentry failures. I discovered that the problem that caused occasional exits with Guillaume's patches is very likely to be that not enough checks on the guest state. The only check was if CS RPL equals SS RPL, so what happens is that when a vmexit and then a vmentry occurs CS and SS RPL maybe equal, but other checks might cause a vmentry failure. I've written a function to check that guest state is VMX valid - although not all checks are implemented yet, and I no more get the occasional vmexits. > >> @@ -1755,6 +1755,14 @@ special_insn: >> ctxt->eflags |= X86_EFLAGS_IF; >> c->dst.type = OP_NONE; /* Disable writeback. */ >> break; >> + case 0xfc: /* cld */ >> + ctxt->eflags &= ~EFLG_DF; >> + c->dst.type = OP_NONE; /* Disable writeback. */ >> + break; >> + case 0xfd: /* std */ >> + ctxt->eflags |= EFLG_DF; >> + c->dst.type = OP_NONE; /* Disable writeback. */ >> + break; >> > > You need to add non-zero entries in opcode_table[] for this to work. Also, > why disable writeback? If there is not DstSomething in opcode_table[], > c->dst.type will be OP_NONE anyway. > Oh! completely forgot about that, sorry! > I would like to see test cases for emulator changes. See > users/test/x86/emulator.c. Of course, right now it is impossible to cause > cld and std to execute in the emulator. But with the proposed > invalid_guest_state() change, it should be easy to to cause this state and > force emulation. > > So how about adding optional invalid_guest_state() support (controlled by a > module parameter), then start adding instructions and test cases, then > removing the module parameter when everything works? > Sounds good