From: Avi Kivity Subject: [PATCH kvm-unit-tests 2/2] emulator: test cross-page mmio Date: Wed, 18 Apr 2012 19:27:00 +0300 Message-ID: <1334766420-26137-3-git-send-email-avi@redhat.com> References: <1334766420-26137-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:11713 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083Ab2DRQ1H (ORCPT ); Wed, 18 Apr 2012 12:27:07 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3IGR7aq014753 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 18 Apr 2012 12:27:07 -0400 In-Reply-To: <1334766420-26137-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Avi Kivity --- x86/emulator.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/x86/emulator.c b/x86/emulator.c index 33820f4..969944a 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -694,6 +694,19 @@ static void test_mmx_movq_mf(uint64_t *mem, uint8_t *insn_page, handle_exception(MF_VECTOR, 0); } +static void test_crosspage_mmio(volatile uint8_t *mem) +{ + volatile uint16_t w, *pw; + + pw = (volatile uint16_t *)&mem[4095]; + mem[4095] = 0x99; + mem[4096] = 0x77; + asm volatile("mov %1, %0" : "=r"(w) : "m"(*pw) : "memory"); + report("cross-page mmio read", w == 0x7799); + asm volatile("mov %1, %0" : "=m"(*pw) : "r"((uint16_t)0x88aa)); + report("cross-page mmio write", mem[4095] == 0xaa && mem[4096] == 0x88); +} + int main() { void *mem; @@ -703,7 +716,10 @@ int main() setup_vm(); setup_idt(); - mem = vmap(IORAM_BASE_PHYS, IORAM_LEN); + mem = alloc_vpages(2); + install_page((void *)read_cr3(), IORAM_BASE_PHYS, mem); + // install the page twice to test cross-page mmio + install_page((void *)read_cr3(), IORAM_BASE_PHYS, mem + 4096); insn_page = alloc_page(); alt_insn_page = alloc_page(); insn_ram = vmap(virt_to_phys(insn_page), 4096); @@ -744,6 +760,8 @@ int main() test_mmx_movq_mf(mem, insn_page, alt_insn_page, insn_ram); + test_crosspage_mmio(mem); + printf("\nSUMMARY: %d tests, %d failures\n", tests, fails); return fails ? 1 : 0; } -- 1.7.10