Skip to contentSkip to conversation

Add async page fault test

PATCH Applied Gleb Natapov 3 participants 4 messages May 9, 2012 – May 14, 2012 KVM

lore
Share & tools
lore
#0 lore raw

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
index c8fbda7..6976f78 100644
@@ -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
index c7e1afb..e46d8d0 100644
@@ -302,4 +302,9 @@ static inline void invlpg(void *va)
 {
 	asm volatile("invlpg (%0)" ::"r" (va) : "memory");
 }
+
+static inline void safe_halt(void)
+{
+	asm volatile("sti; hlt");
+}
 #endif
lib/x86/vm.c +5 -0
index 550ec9b..71b70fd 100644
@@ -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
index 71ab4a8..3473f8d 100644
@@ -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.

#1 lore raw
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
index c8fbda7..6976f78 100644
@@ -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
index c7e1afb..e46d8d0 100644
@@ -302,4 +302,9 @@ static inline void invlpg(void *va)
  {
  	asm volatile("invlpg (%0)" ::"r" (va) : "memory");
  }
+
+static inline void safe_halt(void)
+{
+	asm volatile("sti; hlt");
+}
  #endif
lib/x86/vm.c +5 -0
index 550ec9b..71b70fd 100644
@@ -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
index 71ab4a8..3473f8d 100644
@@ -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
new file mode 100644
index 0000000..62c0455

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
#2 lore raw
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
index c8fbda7..6976f78 100644
@@ -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
index c7e1afb..e46d8d0 100644
@@ -302,4 +302,9 @@ static inline void invlpg(void *va)
 {
 	asm volatile("invlpg (%0)" ::"r" (va) : "memory");
 }
+
+static inline void safe_halt(void)
+{
+	asm volatile("sti; hlt");
+}
 #endif
lib/x86/vm.c +5 -0
index 550ec9b..71b70fd 100644
@@ -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
index 71ab4a8..3473f8d 100644
@@ -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 -0
 void install_pte(unsigned long *cr3,
                         int pte_level,
x86/asyncpf.c new file +2 -0
new file mode 100644
index 0000000..62c0455
@@ -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.

#3 lore raw
In reply to Gleb Natapov
Quoted 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.