Crosspage mmio unit test
cover Crosspage mmio unit test
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(-)
Signature · 1 line
1.7.10
PATCH 1/2 vm: add alloc_vpages()
Allows allocating contiguous virtual address space.
Signed-off-by Avi Kivity <[email protected]>
--- lib/x86/vm.c | 9 +++++++-- lib/x86/vm.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
lib/x86/vm.c +7 -2
@@ -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 ); +}
lib/x86/vm.h +1 -0
@@ -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,
Signature · 1 line
1.7.10
PATCH 2/2 emulator: test cross-page mmio
In reply to Avi KivitySigned-off-by Avi Kivity <[email protected]>
--- x86/emulator.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
x86/emulator.c +19 -1
@@ -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 ; + asmvolatile ("mov %1, %0" :"=r" (w) :"m" (*pw) :"memory" ); +report ("cross-page mmio read" , w ==0x7799 ); + asmvolatile ("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 ; }
Signature · 1 line
1.7.10