Skip to contentSkip to conversation

KVM: test: add the test case to check PFEC on prefetch pte path

PATCH Applied Xiao Guangrong 2 participants 5 messages Dec 23, 2010 – Jan 4, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 KVM: test: add the test case to check PFEC on prefetch pte path

Check page fault error code on prefetch pte path

---
 x86/access.c |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 66 insertions(+), 8 deletions(-)
x86/access.c +66 -8
index 067565b..f43f7f1 100644
@@ -408,7 +408,9 @@ fault:
         at->expected_error &= ~PFERR_FETCH_MASK;
 }
 
-void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool)
+void __ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, u64 pd_page,
+			       u64 pt_page)
+
 {
     unsigned long root = read_cr3();
 
@@ -423,13 +425,12 @@ void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool)
 	switch (i) {
 	case 4:
 	case 3:
-	    pte = vroot[index];
-	    pte = ac_test_alloc_pt(pool) | PT_PRESENT_MASK;
-	    pte |= PT_WRITABLE_MASK | PT_USER_MASK;
+	    pte = pd_page ? pd_page : ac_test_alloc_pt(pool);
+	    pte |= PT_PRESENT_MASK | PT_WRITABLE_MASK | PT_USER_MASK;
 	    break;
 	case 2:
 	    if (!at->flags[AC_PDE_PSE])
-		pte = ac_test_alloc_pt(pool);
+		pte = pt_page ? pt_page : ac_test_alloc_pt(pool);
 	    else {
 		pte = at->phys & PT_PSE_BASE_ADDR_MASK;
 		pte |= PT_PSE_MASK;
@@ -475,6 +476,17 @@ void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool)
     ac_set_expected_status(at);
 }
 
+static void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool)
+{
+	__ac_setup_specific_pages(at, pool, 0, 0);
+}
+
+static void ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool,
+				    u64 pd_page, u64 pt_page)
+{
+	return __ac_setup_specific_pages(at, pool, pd_page, pt_page);
+}
+
 static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond,
                           const char *fmt, ...)
 {
@@ -663,6 +675,43 @@ err:
     return 0;
 }
 
+/*
+ * This test case is used to triger the bug which is fixed by
+ * commit 3ddf6c06e13e in the kvm tree
+ */
+static int check_pfec_on_prefetch_pte(ac_pool_t *pool)
+{
+	ac_test_t at1, at2;
+
+	ac_test_init(&at1, (void *)(0x123406001000));
+	ac_test_init(&at2, (void *)(0x123406003000));
+
+	at1.flags[AC_PDE_PRESENT] = 1;
+	at1.flags[AC_PTE_PRESENT] = 1;
+	ac_setup_specific_pages(&at1, pool, 30 * 1024 * 1024, 30 * 1024 * 1024);
+
+	at2.flags[AC_PDE_PRESENT] = 1;
+	at2.flags[AC_PTE_NX] = 1;
+	at2.flags[AC_PTE_PRESENT] = 1;
+	ac_setup_specific_pages(&at2, pool, 30 * 1024 * 1024, 30 * 1024 * 1024);
+
+	if (!ac_test_do_access(&at1)) {
+		printf("%s: prepare fail\n", __FUNCTION__);
+		goto err;
+	}
+
+	if (!ac_test_do_access(&at2)) {
+		printf("%s: check PFEC on prefetch pte path fail\n",
+			__FUNCTION__);
+		goto err;
+	}
+
+	return 1;
+
+err:
+    return 0;
+}
+
 int ac_test_exec(ac_test_t *at, ac_pool_t *pool)
 {
     int r;
@@ -675,11 +724,18 @@ int ac_test_exec(ac_test_t *at, ac_pool_t *pool)
     return r;
 }
 
+typedef int (*ac_test_fn)(ac_pool_t *pool);
+const ac_test_fn ac_test_cases[] =
+{
+	corrupt_hugepage_triger,
+	check_pfec_on_prefetch_pte,
+};
+
 int ac_test_run(void)
 {
     ac_test_t at;
     ac_pool_t pool;
-    int tests, successes;
+    int i, tests, successes;
 
     printf("run\n");
     tests = successes = 0;
@@ -690,8 +746,10 @@ int ac_test_run(void)
 	successes += ac_test_exec(&at, &pool);
     } while (ac_test_bump(&at));
 
-    ++tests;
-    successes += corrupt_hugepage_triger(&pool);
+    for (i = 0; i < ARRAY_SIZE(ac_test_cases); i++) {
+	++tests;
+	successes += ac_test_cases[i](&pool);
+    }
 
     printf("\n%d tests, %d failures\n", tests, tests - successes);
 
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/2 KVM: test: dump page mapping if test fail

It can help us to fix the bug

---
 x86/access.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
x86/access.c +21 -1
index f43f7f1..709d1a6 100644
@@ -35,6 +35,9 @@ typedef unsigned long pt_element_t;
 #define MSR_EFER 0xc0000080
 #define EFER_NX_MASK		(1ull << 11)
 
+#define PT_INDEX(address, level)       \
+       ((address) >> (12 + ((level)-1) * 9)) & 511
+
 /*
  * page table access check tests
  */
@@ -420,7 +423,7 @@ void __ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, u64 pd_page,
     at->ptep = 0;
     for (int i = 4; i >= 1 && (i >= 2 || !at->flags[AC_PDE_PSE]); --i) {
 	pt_element_t *vroot = va(root & PT_BASE_ADDR_MASK);
-	unsigned index = ((unsigned long)at->virt >> (12 + (i-1) * 9)) & 511;
+	unsigned index = PT_INDEX((unsigned long)at->virt, i);
 	pt_element_t pte = 0;
 	switch (i) {
 	case 4:
@@ -487,6 +490,22 @@ static void ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool,
 	return __ac_setup_specific_pages(at, pool, pd_page, pt_page);
 }
 
+static void dump_mapping(ac_test_t *at)
+{
+	unsigned long root = read_cr3();
+	int i;
+
+	printf("Dump mapping: address: %llx\n", at->virt);
+	for (i = 4; i >= 1 && (i >= 2 || !at->flags[AC_PDE_PSE]); --i) {
+		pt_element_t *vroot = va(root & PT_BASE_ADDR_MASK);
+		unsigned index = PT_INDEX((unsigned long)at->virt, i);
+		pt_element_t pte = vroot[index];
+
+		printf("------L%d: %llx\n", i, pte);
+		root = vroot[index];
+	}
+}
+
 static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond,
                           const char *fmt, ...)
 {
@@ -511,6 +530,7 @@ static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond,
     vsnprintf(buf, sizeof(buf), fmt, ap);
     va_end(ap);
     printf("FAIL: %s\n", buf);
+    dump_mapping(at);
 }
 
 static int pt_match(pt_element_t pte1, pt_element_t pte2, pt_element_t ignore)
Signature · 1 line
1.7.0.4
Applied
#2 lore raw
In reply to Xiao Guangrong
Quoted 1 line · Xiao Guangrong

Check page fault error code on prefetch pte path

Applied both, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw
In reply to Xiao Guangrong
Quoted 2 lines · Xiao Guangrong

Check page fault error code on prefetch pte path

Can you point out the commit which fixed this failure? I'd like to backport it if it's simple enough.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 6 lines · Avi Kivity
Quoted 2 lines · Xiao Guangrong

Check page fault error code on prefetch pte path

Can you point out the commit which fixed this failure? I'd like to backport it if it's simple enough.

The commit is 3ddf6c06e13e:

commit 3ddf6c06e13ef7842e58815d28ec88faae19c8db

Author: Xiao Guangrong <[email protected]>
Date:   Wed Nov 17 12:11:41 2010 +0800

KVM: MMU: don't mark spte notrap if reserved bit set

If reserved bit is set, we need inject the #PF with PFEC.RSVD=1, but shadow_notrap_nonpresent_pte injects #PF with PFEC.RSVD=0 only