From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH 1/2] kvm-unit-tests: Add a func to run instruction in emulator Date: Sun, 9 Jun 2013 19:00:49 +0300 Message-ID: <20130609160049.GB29022@redhat.com> References: <1370572299-2706-1-git-send-email-yzt356@gmail.com> <20130609110738.GO4725@redhat.com> <20130609124953.GU4725@redhat.com> <20130609140953.GG15299@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm , Paolo Bonzini To: =?utf-8?B?5p2O5pil5aWHIDxBcnRodXIgQ2h1bnFpIExpPg==?= Return-path: Received: from mx1.redhat.com ([209.132.183.28]:8004 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753182Ab3FIQAw convert rfc822-to-8bit (ORCPT ); Sun, 9 Jun 2013 12:00:52 -0400 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Sun, Jun 09, 2013 at 11:23:26PM +0800, =E6=9D=8E=E6=98=A5=E5=A5=87 <= Arthur Chunqi Li> wrote: > On Sun, Jun 9, 2013 at 10:09 PM, Gleb Natapov wrote= : > > On Sun, Jun 09, 2013 at 09:22:27PM +0800, =E6=9D=8E=E6=98=A5=E5=A5=87= wrote: > >> On Sun, Jun 9, 2013 at 8:49 PM, Gleb Natapov wro= te: > >> > On Sun, Jun 09, 2013 at 08:44:32PM +0800, =E6=9D=8E=E6=98=A5=E5=A5= =87 wrote: > >> >> On Sun, Jun 9, 2013 at 7:07 PM, Gleb Natapov = wrote: > >> >> > On Fri, Jun 07, 2013 at 10:31:38AM +0800, Arthur Chunqi Li wr= ote: > >> >> >> Add a function trap_emulator to run an instruction in emulat= or. > >> >> >> Set inregs first (%rax, %rsp, %rbp, %rflags have special usa= ge and > >> >> >> cannot set in inregs), put instruction codec in alt_insn and= call > >> >> >> func with alt_insn_length. Get results in outregs. > >> >> >> > >> >> > Why %rax, %rsp, %rbp, %rflags cannot be set in inregs? > >> >> > > >> >> > %rax because trapping instruction uses it? Use one that does = not use > >> >> > register at all: MOV r/m32, imm32 > >> >> I don't know why set %rax before call alt_insn_page can cause e= rror. I > >> >> use "xchg %%rax, 0+%[save]" before "call *%1" and the %rcx is n= ot set > >> >> correctly. > >> > We better find this out :) > >> I found that before calling alt_insn_page, address of "mem" is sav= ed > >> to %rax, why? > > Because instruction that we use to trigger vmexit is mov %eax, (%ra= x) so > > MMOI address mem is loaded into %rax before jumping into it. > I think this is why changing %rax will cause error. If we use mov > %eax, (%rax) to trigger vmexit, and %rax is changed before calling > alt_insn_page, codes in alt_insn_page will not be executed and return > directly. > I changed the codes which trigger vmexit to "mov %eax, (%r8)" and set > "mem" to %r8 before calling alt_insn_page, it runs OK. >=20 Just use an instruction that does not use registers at all. mov $1, add= r where addr is immediate and encoded from mem parameter. > Besides, I also don't know if changed %rflags may cause some > unpredictable actions, so now we just treat it with no error :) If test sets rflags to a value that causes crashes this is a test bug, no need to prevent this from happening. -- Gleb.