All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 0/2] Crosspage mmio unit test
@ 2012-04-18 16:26 Avi Kivity
  2012-04-18 16:26 ` [PATCH kvm-unit-tests 1/2] vm: add alloc_vpages() Avi Kivity
  2012-04-18 16:27 ` [PATCH kvm-unit-tests 2/2] emulator: test cross-page mmio Avi Kivity
  0 siblings, 2 replies; 3+ messages in thread
From: Avi Kivity @ 2012-04-18 16:26 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

Test that MMIO that crosses a page boundary is handled correctly.

Avi Kivity (2):
  vm: add alloc_vpages()
  emulator: test cross-page mmio

 lib/x86/vm.c   |    9 +++++++--
 lib/x86/vm.h   |    1 +
 x86/emulator.c |   20 +++++++++++++++++++-
 3 files changed, 27 insertions(+), 3 deletions(-)

-- 
1.7.10


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH kvm-unit-tests 1/2] vm: add alloc_vpages()
  2012-04-18 16:26 [PATCH kvm-unit-tests 0/2] Crosspage mmio unit test Avi Kivity
@ 2012-04-18 16:26 ` Avi Kivity
  2012-04-18 16:27 ` [PATCH kvm-unit-tests 2/2] emulator: test cross-page mmio Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2012-04-18 16:26 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

Allows allocating contiguous virtual address space.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 lib/x86/vm.c |    9 +++++++--
 lib/x86/vm.h |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/x86/vm.c b/lib/x86/vm.c
index abbb0c9..550ec9b 100644
--- a/lib/x86/vm.c
+++ b/lib/x86/vm.c
@@ -249,8 +249,13 @@ void *vmap(unsigned long long phys, unsigned long size)
     return mem;
 }
 
-void *alloc_vpage(void)
+void *alloc_vpages(ulong nr)
 {
-	vfree_top -= PAGE_SIZE;
+	vfree_top -= PAGE_SIZE * nr;
 	return vfree_top;
 }
+
+void *alloc_vpage(void)
+{
+    return alloc_vpages(1);
+}
diff --git a/lib/x86/vm.h b/lib/x86/vm.h
index bf8fd52..71ab4a8 100644
--- a/lib/x86/vm.h
+++ b/lib/x86/vm.h
@@ -21,6 +21,7 @@ void *vmalloc(unsigned long size);
 void vfree(void *mem);
 void *vmap(unsigned long long phys, unsigned long size);
 void *alloc_vpage(void);
+void *alloc_vpages(ulong nr);
 
 void install_pte(unsigned long *cr3,
                         int pte_level,
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH kvm-unit-tests 2/2] emulator: test cross-page mmio
  2012-04-18 16:26 [PATCH kvm-unit-tests 0/2] Crosspage mmio unit test Avi Kivity
  2012-04-18 16:26 ` [PATCH kvm-unit-tests 1/2] vm: add alloc_vpages() Avi Kivity
@ 2012-04-18 16:27 ` Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2012-04-18 16:27 UTC (permalink / raw)
  To: Marcelo Tosatti, kvm

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-18 16:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-18 16:26 [PATCH kvm-unit-tests 0/2] Crosspage mmio unit test Avi Kivity
2012-04-18 16:26 ` [PATCH kvm-unit-tests 1/2] vm: add alloc_vpages() Avi Kivity
2012-04-18 16:27 ` [PATCH kvm-unit-tests 2/2] emulator: test cross-page mmio Avi Kivity

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.