Fixes for mmu access unit test
cover Fixes for mmu access unit test
The mmu access unit test fails when testing real processor (e.g. with npt or ept). In one case this was because the test was too restrictive (more than one result is allowed) and in another both the test and kvm shadow mmu are faulty.
This patchset fixes the test. Another patch will follow fixing kvm (but only after nnpt is merged).
Avi Kivity (5):
test: access: split off test case formatting from execution
test: access: consolidate test failure reporting into a function
test: access: report successful tests optionally
test: access: allow the processor not to set pde.a if a fault occurs
test: access: don't expect fetch fault indication if !efer.nx
kvm/user/test/x86/access.c | 106 ++++++++++++++++++++++++++++++++------------ 1 files changed, 77 insertions(+), 29 deletions(-)
PATCH 1/5 test: access: split off test case formatting from execution
--- kvm/user/test/x86/access.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
kvm/user/test/x86/access.c +8 -2
@@ -557,9 +557,8 @@ int ac_test_do_access(ac_test_t *at)return 1 ; } -int ac_test_exec (ac_test_t *at) +static void ac_test_show (ac_test_t *at) { -int r;char line[5000 ]; *line =0 ;
@@ -571,6 +570,13 @@ int ac_test_exec(ac_test_t *at) }strcat (line,": " );printf ("%s" , line); +} + +int ac_test_exec (ac_test_t *at) +{ +int r; + +ac_test_show (at);ac_test_setup_pte (at); r =ac_test_do_access (at);return r;
Signature · 1 line
1.7.0.4
PATCH 2/5 test: access: consolidate test failure reporting into a function
In reply to Avi Kivity--- kvm/user/test/x86/access.c | 60 +++++++++++++++++++++++++++----------------- 1 files changed, 37 insertions(+), 23 deletions(-)
kvm/user/test/x86/access.c +37 -23
@@ -453,6 +453,28 @@ fault: ; } +static void ac_test_check (ac_test_t *at,_Bool *success_ret,_Bool cond, +const char *fmt, ...) +{ +va_list ap; +char buf[500 ]; + +if (!*success_ret) { +return ; + } + +if (!cond) { +return ; + } + + *success_ret = false; + +va_start (ap, fmt); +vsnprintf (buf,sizeof (buf), fmt, ap); +va_end (ap); +printf ("FAIL: %s\n" , buf); +} +int ac_test_do_access (ac_test_t *at) {static unsigned unique =42 ;
@@ -460,6 +482,7 @@ int ac_test_do_access(ac_test_t *at)unsigned e;static unsigned char user_stack[4096 ];unsigned long rsp; +_Bool success = true; ++unique;
@@ -531,30 +554,21 @@ int ac_test_do_access(ac_test_t *at)"jmp back_to_kernel \n\t" ".section .text"); -if (fault && !at->expected_fault) { -printf ("FAIL: unexpected fault\n" ); -return 0 ; - } -if (!fault && at->expected_fault) { -printf ("FAIL: unexpected access\n" ); -return 0 ; - } -if (fault && e != at->expected_error) { -printf ("FAIL: error code %x expected %x\n" , e, at->expected_error); -return 0 ; - } -if (at->ptep && *at->ptep != at->expected_pte) { -printf ("FAIL: pte %x expected %x\n" , *at->ptep, at->expected_pte); -return 0 ; +ac_test_check (at, &success, fault && !at->expected_fault, +"unexpected fault" ); +ac_test_check (at, &success, !fault && at->expected_fault, +"unexpected access" ); +ac_test_check (at, &success, fault && e != at->expected_error, +"error code %x expected %x" , e, at->expected_error); +ac_test_check (at, &success, at->ptep && *at->ptep != at->expected_pte, +"pte %x expected %x" , *at->ptep, at->expected_pte); +ac_test_check (at, &success, *at->pdep != at->expected_pde, +"pde %x expected %x" , *at->pdep, at->expected_pde); + +if (success) { +printf ("PASS\n" ); } - -if (*at->pdep != at->expected_pde) { -printf ("FAIL: pde %x expected %x\n" , *at->pdep, at->expected_pde); -return 0 ; - } - -printf ("PASS\n" ); -return 1 ; +return success; }static void ac_test_show (ac_test_t *at)
Signature · 1 line
1.7.0.4
PATCH 3/5 test: access: report successful tests optionally
In reply to Avi KivityThere are so many tests, no point in reporting successful ones. Leave the capability optional in case a failure triggers a kvm or testsuite crash before the report is complete and we need to see which test failed.
--- kvm/user/test/x86/access.c | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-)
kvm/user/test/x86/access.c +13 -2
@@ -6,6 +6,8 @@#define true 1#define false 0 +static _Bool verbose = false; +typedef unsigned long pt_element_t ;#define PAGE_SIZE ((pt_element_t)4096)
@@ -145,6 +147,9 @@ typedef struct {unsigned long linear_addr; } __attribute__((packed)) descriptor_table_t; + +static void ac_test_show (ac_test_t *at); +void lidt (idt_entry_t *idt,int nentries) {descriptor_table_t dt;
@@ -469,6 +474,10 @@ static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond, *success_ret = false; +if (!verbose) { +ac_test_show (at); + } +va_start (ap, fmt);vsnprintf (buf,sizeof (buf), fmt, ap);va_end (ap);
@@ -565,7 +574,7 @@ int ac_test_do_access(ac_test_t *at)ac_test_check (at, &success, *at->pdep != at->expected_pde,"pde %x expected %x" , *at->pdep, at->expected_pde); -if (success) { +if (success && verbose) {printf ("PASS\n" ); }return success;
@@ -590,7 +599,9 @@ int ac_test_exec(ac_test_t *at) {int r; -ac_test_show (at); +if (verbose) { +ac_test_show (at); + }ac_test_setup_pte (at); r =ac_test_do_access (at);return r;
Signature · 1 line
1.7.0.4
PATCH 4/5 test: access: allow the processor not to set pde.a if a fault occurs
In reply to Avi KivitySome processors only set accessed bits if the translation is valid; allow this behaviour. This squelchs errors running with EPT.
--- kvm/user/test/x86/access.c | 25 ++++++++++++++++++++----- 1 files changed, 20 insertions(+), 5 deletions(-)
kvm/user/test/x86/access.c +20 -5
@@ -137,6 +137,7 @@ typedef struct {pt_element_t expected_pte;pt_element_t *pdep;pt_element_t expected_pde; +pt_element_t ignore_pde;int expected_fault;unsigned expected_error;idt_entry_t idt[256 ];
@@ -370,6 +371,7 @@ void ac_test_setup_pte(ac_test_t *at)if (at->ptep) at->expected_pte = *at->ptep; at->expected_pde = *at->pdep; + at->ignore_pde =0 ; at->expected_fault =0 ; at->expected_error =PFERR_PRESENT_MASK ;
@@ -416,13 +418,17 @@ void ac_test_setup_pte(ac_test_t *at)if (at->flags[AC_ACCESS_FETCH ] && at->flags[AC_PDE_NX ]) at->expected_fault =1 ; -if (at->expected_fault) +if (!at->flags[AC_PDE_ACCESSED ]) + at->ignore_pde =PT_ACCESSED_MASK ; + +if (!pde_valid) goto fault; - at->expected_pde |=PT_ACCESSED_MASK ; +if (!at->expected_fault) + at->expected_pde |=PT_ACCESSED_MASK ;if (at->flags[AC_PDE_PSE ]) { -if (at->flags[AC_ACCESS_WRITE ]) +if (at->flags[AC_ACCESS_WRITE ] && !at->expected_fault) at->expected_pde |=PT_DIRTY_MASK ; goto no_pte; }
@@ -455,7 +461,8 @@ void ac_test_setup_pte(ac_test_t *at) no_pte: fault: - ; +if (!at->expected_fault) + at->ignore_pde =0 ; } static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond,
@@ -484,6 +491,13 @@ static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond,printf ("FAIL: %s\n" , buf); } +static int pt_match (pt_element_t pte1,pt_element_t pte2,pt_element_t ignore) +{ + pte1 &= ~ignore; + pte2 &= ~ignore; +return pte1 == pte2; +} +int ac_test_do_access (ac_test_t *at) {static unsigned unique =42 ;
@@ -571,7 +585,8 @@ int ac_test_do_access(ac_test_t *at) "error code %x expected %x", e, at->expected_error);ac_test_check (at, &success, at->ptep && *at->ptep != at->expected_pte,"pte %x expected %x" , *at->ptep, at->expected_pte); -ac_test_check (at, &success, *at->pdep != at->expected_pde, +ac_test_check (at, &success, + !pt_match (*at->pdep, at->expected_pde, at->ignore_pde),"pde %x expected %x" , *at->pdep, at->expected_pde);if (success && verbose) {
Signature · 1 line
1.7.0.4
PATCH 5/5 test: access: don't expect fetch fault indication if !efer.nx
In reply to Avi KivityBit 4 of the page-fault error code can only be set if efer.nx=1.
--- kvm/user/test/x86/access.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
kvm/user/test/x86/access.c +2 -0
@@ -463,6 +463,8 @@ no_pte: fault:if (!at->expected_fault) at->ignore_pde =0 ; +if (!at->flags[AC_CPU_EFER_NX ]) + at->expected_error &= ~PFERR_FETCH_MASK ; } static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond,
Signature · 1 line
1.7.0.4
Marcelo Tosatti
AppliedQuoted 8 lines · Avi Kivity
The mmu access unit test fails when testing real processor (e.g. with npt or ept). In one case this was because the test was too restrictive (more than one result is allowed) and in another both the test and kvm shadow mmu are faulty.
This patchset fixes the test. Another patch will follow fixing kvm (but only after nnpt is merged).
Quoted 8 lines
Avi Kivity (5):
test: access: split off test case formatting from execution
test: access: consolidate test failure reporting into a function
test: access: report successful tests optionally
test: access: allow the processor not to set pde.a if a fault occurs
test: access: don't expect fetch fault indication if !efer.nxkvm/user/test/x86/access.c | 106 ++++++++++++++++++++++++++++++++------------
Applied, thanks.