From patchwork Thu Jun 6 05:03:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Chunqi Li X-Patchwork-Id: 2677091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 66C3540077 for ; Thu, 6 Jun 2013 05:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752895Ab3FFFEF (ORCPT ); Thu, 6 Jun 2013 01:04:05 -0400 Received: from mail-pb0-f47.google.com ([209.85.160.47]:54916 "EHLO mail-pb0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752430Ab3FFFED (ORCPT ); Thu, 6 Jun 2013 01:04:03 -0400 Received: by mail-pb0-f47.google.com with SMTP id rr13so92438pbb.20 for ; Wed, 05 Jun 2013 22:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=j8Qi2az2cHARxRA9XqhdRD2Y6sIZy/F12dE7wX7lbuQ=; b=y6iAmRVluaBh7mX8qqFgZFHwXJ+XCQHghG28iT9kAgRFLqvCxrVKuTCbqelMsAiUgB UITwmM5WTrjB/YeGTLd2PacRMYJACmQV2raze3f6Qpu/BYHPieDjUI8vBsIuWv/sEsQX shzz5ZU5zJ7pCL6kfiaLlP87UmZ1GwKfeUmecNhcR0oderjQnfrCY2DIBozdNWV1/nju 5dWkAaR8i3pAeDnN1YBR8w6aWUPtooAfGUCfL8w0AttTH6WSSIqxdGDTidRUhANe09o6 To3sCASIW5DIe8odpbeLWb3cjOFXUdt2JA0rn1mgyLLvrcb3iE/EWKT2YcrPhY/VU9J7 W9mg== X-Received: by 10.68.232.42 with SMTP id tl10mr36635126pbc.72.1370495043162; Wed, 05 Jun 2013 22:04:03 -0700 (PDT) Received: from Blade1-02.Blade1-02 ([162.105.146.101]) by mx.google.com with ESMTPSA id qh4sm75887119pac.8.2013.06.05.22.03.55 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Jun 2013 22:04:02 -0700 (PDT) From: Arthur Chunqi Li To: kvm@vger.kernel.org Cc: gleb@redhat.com, pbonzini@redhat.com, Arthur Chunqi Li Subject: [PATCH] kvm-unit-tests: Add test case for accessing bpl via modr/m Date: Thu, 6 Jun 2013 13:03:44 +0800 Message-Id: <1370495024-3712-1-git-send-email-yzt356@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Test access to %bpl via modr/m addressing mode. This case can test another bug in the boot of RHEL5.9 64-bit. Signed-off-by: Arthur Chunqi Li --- x86/emulator.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/x86/emulator.c b/x86/emulator.c index 96576e5..3563971 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -901,6 +901,45 @@ static void test_simplealu(u32 *mem) report("test", *mem == 0x8400); } +static void test_bpl_modrm(uint64_t *mem, uint8_t *insn_page, + uint8_t *alt_insn_page, void *insn_ram) +{ + ulong *cr3 = (ulong *)read_cr3(); + uint16_t cx = 0; + + // 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 VMEXIT + insn_page[0] = 0x66; // mov $0x4321, %cx + insn_page[1] = 0xb9; + insn_page[2] = 0x21; + insn_page[3] = 0x43; + insn_page[4] = 0x89; // mov %eax, (%rax) + insn_page[5] = 0x00; + insn_page[6] = 0x90; // nop + // Place mov %cl, %bpl in alt_insn_page for emulator to execuate + // If emulator mistaken addressing %bpl, %cl may be moved to %ch + // %cx will be broken to 0x2121, not 0x4321 + alt_insn_page[4] = 0x40; + alt_insn_page[5] = 0x88; + alt_insn_page[6] = 0xcd; + + // Load the code TLB with insn_page, but point the page tables at + // alt_insn_page (and keep the data TLB clear, for AMD decode 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)); + asm volatile("":"=c"(cx)); + report("access bpl in modr/m", cx == 0x4321); +} + int main() { void *mem; @@ -964,6 +1003,8 @@ int main() test_string_io_mmio(mem); + test_bpl_modrm(mem, insn_page, alt_insn_page, insn_ram); + printf("\nSUMMARY: %d tests, %d failures\n", tests, fails); return fails ? 1 : 0; }