From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH] Test case of multibyte NOP in emulation mode Date: Wed, 5 Jun 2013 11:27:57 +0300 Message-ID: <20130605082757.GP4725@redhat.com> References: <20130605064247.GD15299@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]:22277 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751405Ab3FEI2A convert rfc822-to-8bit (ORCPT ); Wed, 5 Jun 2013 04:28:00 -0400 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Jun 05, 2013 at 03:00:33PM +0800, =E6=9D=8E=E6=98=A5=E5=A5=87 <= Arthur Chunqi Li> wrote: > Yes, that should be the point. x86/realmode.c is always running in > emulation mode. I added the testing here there but no error occurred.= I > cannot find the reason. >=20 > The code is as follows added to x86/realmode.c > static void test_nopl(void) > { > MK_INSN(nopl, ".byte 0x0f, 0x1f, 0x00\n\r"); > exec_in_big_real_mode(&insn_nopl); > report("nopl", 0, 1); > } >=20 > and I objdump from realmode.flat is as follows: > 00006458 : > 6458: 0f 1f 00 nopl (%eax) >=20 > But there cause no error when executing this insn. Why? >=20 Because you probably use cpu that supports unrestricted mode or use AMD processor. Can you try loading kvm-intel with unrestricted_guest=3D0 option? >=20 > On Wed, Jun 5, 2013 at 2:42 PM, Gleb Natapov wrote: >=20 > > On Wed, Jun 05, 2013 at 10:16:46AM +0800, =E6=9D=8E=E6=98=A5=E5=A5=87= wrote: > > > Add multibyte NOP test case to kvm-unit-tests. This case can test= one > > > of bugs when booting RHEL5.9 64-bit. > > > > > Adding the test to x86/realmode.c will be much easier. > > > > > Signed-off-by: Arthur Chunqi Li > > > --- > > > x86/emulator.c | 33 +++++++++++++++++++++++++++++++++ > > > 1 file changed, 33 insertions(+) > > > > > > diff --git a/x86/emulator.c b/x86/emulator.c > > > index 96576e5..f26c70f 100644 > > > --- a/x86/emulator.c > > > +++ b/x86/emulator.c > > > @@ -901,6 +901,37 @@ static void test_simplealu(u32 *mem) > > > report("test", *mem =3D=3D 0x8400); > > > } > > > > > > +static void test_nopl(uint64_t *mem, uint8_t *insn_page, > > > + uint8_t *alt_insn_page, void *insn_ram) > > > +{ > > > + ulong *cr3 =3D (ulong *)read_cr3(); > > > + > > > + // Pad with RET instructions > > > + memset(insn_page, 0xc3, 4096); > > > + memset(alt_insn_page, 0xc3, 4096); > > > + // Place a trapping instruction in the page to trigger a VME= XIT > > > + insn_page[0] =3D 0x89; // mov %eax, (%rax) > > > + insn_page[1] =3D 0x00; > > > + insn_page[2] =3D 0x90; // nop > > > + // Place nopl 0x0(%eax) in alt_insn_page for emulator to exe= cuate > > > + alt_insn_page[0] =3D 0x0f; // nop DWORD ptr[EAX] > > > + alt_insn_page[1] =3D 0x1f; > > > + alt_insn_page[2] =3D 0x00; > > > + > > > + // Load the code TLB with insn_page, but point the page tabl= es at > > > + // alt_insn_page (and keep the data TLB clear, for AMD decod= e > > assist). > > > + // This will make the CPU trap on the insn_page instruction = but the > > > + // hypervisor will see alt_insn_page. > > > + install_page(cr3, virt_to_phys(insn_page), insn_ram); > > > + // Load code TLB > > > + invlpg(insn_ram); > > > + asm volatile("call *%0" : : "r"(insn_ram + 3)); > > > + // Trap, let hypervisor emulate at alt_insn_page > > > + install_page(cr3, virt_to_phys(alt_insn_page), insn_ram); > > > + asm volatile("call *%0" : : "r"(insn_ram), "a"(mem)); > > > + report("nopl", 1); > > > +} > > > + > > > int main() > > > { > > > void *mem; > > > @@ -964,6 +995,8 @@ int main() > > > > > > test_string_io_mmio(mem); > > > > > > + test_nopl(mem, insn_page, alt_insn_page, insn_ram); > > > + > > > printf("\nSUMMARY: %d tests, %d failures\n", tests, fails); > > > return fails ? 1 : 0; > > > } > > > -- > > > 1.7.9.5 > > > > -- > > Gleb. > > >=20 >=20 >=20 > --=20 > Arthur Chunqi Li > Department of Computer Science > School of EECS > Peking University > Beijing, China -- Gleb.