Add async page fault test
PATCH v2 1/1 Add async page fault test
The test checks that when hypervisor prefaults swapped in page it does not generates spurious #PFs in case page was unmapped while it was swapped out.
config-x86-common.mak +3 -1
@@ -34,7 +34,7 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \ $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \ $(TEST_DIR)/kvmclock_test.flat $(TEST_DIR)/eventinj.flat \ - $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat + $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat $(TEST_DIR)/asyncpf.flat ifdef API tests-common += api/api-sample
@@ -90,6 +90,8 @@ $(TEST_DIR)/s3.elf: $(cstart.o) $(TEST_DIR)/s3.o $(TEST_DIR)/pmu.elf: $(cstart.o) $(TEST_DIR)/pmu.o +$(TEST_DIR)/asyncpf.elf: $(cstart.o) $(TEST_DIR)/asyncpf.o + arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
lib/x86/processor.h +5 -0
@@ -302,4 +302,9 @@ static inline void invlpg(void *va) { asmvolatile ("invlpg (%0)" ::"r" (va) :"memory" ); } + +static inline void safe_halt (void ) +{ + asmvolatile ("sti; hlt" ); +}#endif
lib/x86/vm.c +5 -0
@@ -219,6 +219,11 @@ void *vmalloc(unsigned long size)return mem; } +uint64_t virt_to_phys_cr3 (void *mem) +{ +return (get_pte (phys_to_virt (read_cr3 ()), mem) &PTE_ADDR ) + ((ulong )mem & (PAGE_SIZE -1 )); +} +void vfree (void *mem) {unsigned long size = ((unsigned long *)mem)[-1 ];
lib/x86/vm.h +1 -0
@@ -22,6 +22,7 @@ void vfree(void *mem);void *vmap (unsigned long long phys,unsigned long size);void *alloc_vpage (void );void *alloc_vpages (ulong nr); +uint64_t virt_to_phys_cr3 (void *mem); void install_pte(unsigned long *cr3, int pte_level,
x86/asyncpf.c new file +113 -0
113 lines not on this page · raw message
--
Gleb.
Quoted 74 lines · Gleb Natapov
The test checks that when hypervisor prefaults swapped in page it does not generates spurious #PFs in case page was unmapped while it was swapped out.
config-x86-common.mak +3
-1@@ -34,7 +34,7 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \ $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \ $(TEST_DIR)/kvmclock_test.flat $(TEST_DIR)/eventinj.flat \ - $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat + $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat $(TEST_DIR)/asyncpf.flat ifdef API tests-common += api/api-sample@@ -90,6 +90,8 @@ $(TEST_DIR)/s3.elf: $(cstart.o) $(TEST_DIR)/s3.o $(TEST_DIR)/pmu.elf: $(cstart.o) $(TEST_DIR)/pmu.o +$(TEST_DIR)/asyncpf.elf: $(cstart.o) $(TEST_DIR)/asyncpf.o + arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.olib/x86/processor.h +5
-0@@ -302,4 +302,9 @@ static inline void invlpg(void *va) { asmvolatile ("invlpg (%0)" ::"r" (va) :"memory" ); } + +static inline void safe_halt (void ) +{ + asmvolatile ("sti; hlt" ); +}#endif lib/x86/vm.c +5
-0@@ -219,6 +219,11 @@ void *vmalloc(unsigned long size)return mem; } +uint64_t virt_to_phys_cr3 (void *mem) +{ +return (get_pte (phys_to_virt (read_cr3 ()), mem)&PTE_ADDR ) + ((ulong )mem& (PAGE_SIZE -1 )); +} +void vfree (void *mem) {unsigned long size = ((unsigned long *)mem)[-1 ];lib/x86/vm.h +1
-0@@ -22,6 +22,7 @@ void vfree(void *mem);void *vmap (unsigned long long phys,unsigned long size);void *alloc_vpage (void );void *alloc_vpages (ulong nr); +uint64_t virt_to_phys_cr3 (void *mem); void install_pte(unsigned long *cr3, int pte_level,x86/asyncpf.c new file +0
-0
x86/asyncpf.c line 2
Quoted 2 lines
x86/asyncpf.c new file +2
-0@@ -0,0 +1,113 @@ +/* +* Async PF test. For the test to actually do anywathing it ineeds to be started
^^^^^^^^^^^^^^^^^^^^ typo?
Signature · 2 lines
----- Igor
Quoted 67 lines · Igor Mammedov
Quoted 66 lines · Gleb Natapov
The test checks that when hypervisor prefaults swapped in page it does not generates spurious #PFs in case page was unmapped while it was swapped out.
config-x86-common.mak +3
-1@@ -34,7 +34,7 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \ $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \ $(TEST_DIR)/kvmclock_test.flat $(TEST_DIR)/eventinj.flat \ - $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat + $(TEST_DIR)/s3.flat $(TEST_DIR)/pmu.flat $(TEST_DIR)/asyncpf.flat ifdef API tests-common += api/api-sample@@ -90,6 +90,8 @@ $(TEST_DIR)/s3.elf: $(cstart.o) $(TEST_DIR)/s3.o $(TEST_DIR)/pmu.elf: $(cstart.o) $(TEST_DIR)/pmu.o +$(TEST_DIR)/asyncpf.elf: $(cstart.o) $(TEST_DIR)/asyncpf.o + arch_clean: $(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \ $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.olib/x86/processor.h +5
-0@@ -302,4 +302,9 @@ static inline void invlpg(void *va) { asmvolatile ("invlpg (%0)" ::"r" (va) :"memory" ); } + +static inline void safe_halt (void ) +{ + asmvolatile ("sti; hlt" ); +}#endif lib/x86/vm.c +5
-0@@ -219,6 +219,11 @@ void *vmalloc(unsigned long size)return mem; } +uint64_t virt_to_phys_cr3 (void *mem) +{ +return (get_pte (phys_to_virt (read_cr3 ()), mem)&PTE_ADDR ) + ((ulong )mem& (PAGE_SIZE -1 )); +} +void vfree (void *mem) {unsigned long size = ((unsigned long *)mem)[-1 ];lib/x86/vm.h +1
-0@@ -22,6 +22,7 @@ void vfree(void *mem);void *vmap (unsigned long long phys,unsigned long size);void *alloc_vpage (void );void *alloc_vpages (ulong nr); +uint64_t virt_to_phys_cr3 (void *mem);
Quoted 12 lines
x86/asyncpf.c line 2
Quoted 10 lines
lib/x86/vm.h +0
-0void install_pte(unsigned long *cr3, int pte_level,x86/asyncpf.c new file +2
-0@@ -0,0 +1,113 @@ +/* +* Async PF test. For the test to actually do anywathing it ineeds to be started ^^^^^^^^^^^^^^^^^^^^ typo?
Either that, or a new word!
--
Gleb.
Marcelo Tosatti
AppliedQuoted 3 lines · Gleb Natapov
The test checks that when hypervisor prefaults swapped in page it does not generates spurious #PFs in case page was unmapped while it was swapped out.
Applied, thanks.