All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 0/3] svm: fix expected values and add extra NPT tests
@ 2014-09-02 15:05 Paolo Bonzini
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 1/3] x86: svm: fix exitinfo values for " Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-09-02 15:05 UTC (permalink / raw)
  To: kvm; +Cc: jroedel, agraf, valentine.sinitsyn, jan.kiszka

The NPT implementation of SVM does not set bits 32 and 33 of EXITINFO1.
We want to fix that, so check those fields and also add two extra tests:

- reserved bits during page access (the existing test is for reserved bits
  during page table walks)

- test for writes to a read-only page mapped to an MMIO device from L1

Paolo Bonzini (3):
  x86: svm: fix exitinfo values for NPT tests
  x86: svm: add page access reserved bit test
  x86: svm: add L1 MMIO read-only permission test

 x86/svm.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 77 insertions(+), 11 deletions(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH kvm-unit-tests 1/3] x86: svm: fix exitinfo values for NPT tests
  2014-09-02 15:05 [PATCH kvm-unit-tests 0/3] svm: fix expected values and add extra NPT tests Paolo Bonzini
@ 2014-09-02 15:05 ` Paolo Bonzini
  2014-09-02 16:14   ` Joerg Roedel
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 2/3] x86: svm: add page access reserved bit test Paolo Bonzini
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 3/3] x86: svm: add L1 MMIO read-only permission test Paolo Bonzini
  2 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2014-09-02 15:05 UTC (permalink / raw)
  To: kvm; +Cc: jroedel, agraf, valentine.sinitsyn, jan.kiszka

The exitinfo values were plain wrong for the page-walk tests
(including npt_rsvd), or else they were missing bits 32:33.
Expect the right values.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/svm.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/x86/svm.c b/x86/svm.c
index 00b3191..c4d6d94 100644
--- a/x86/svm.c
+++ b/x86/svm.c
@@ -703,7 +703,7 @@ static bool npt_nx_check(struct test *test)
     test->vmcb->save.efer |= (1 << 11);
 
     return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
-           && (test->vmcb->control.exit_info_1 == 0x15);
+           && (test->vmcb->control.exit_info_1 == 0x100000015ULL);
 }
 
 static void npt_us_prepare(struct test *test)
@@ -728,7 +728,7 @@ static bool npt_us_check(struct test *test)
     *pte |= (1ULL << 2);
 
     return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
-           && (test->vmcb->control.exit_info_1 == 0x05);
+           && (test->vmcb->control.exit_info_1 == 0x100000005ULL);
 }
 
 static void npt_rsvd_prepare(struct test *test)
@@ -744,7 +744,7 @@ static bool npt_rsvd_check(struct test *test)
     pdpe[0] &= ~(1ULL << 8);
 
     return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
-            && (test->vmcb->control.exit_info_1 == 0x0f);
+            && (test->vmcb->control.exit_info_1 == 0x200000006ULL);
 }
 
 static void npt_rw_prepare(struct test *test)
@@ -772,7 +772,7 @@ static bool npt_rw_check(struct test *test)
     *pte |= (1ULL << 1);
 
     return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
-           && (test->vmcb->control.exit_info_1 == 0x07);
+           && (test->vmcb->control.exit_info_1 == 0x100000007ULL);
 }
 
 static void npt_pfwalk_prepare(struct test *test)
@@ -793,7 +793,7 @@ static bool npt_pfwalk_check(struct test *test)
     *pte |= (1ULL << 1);
 
     return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
-           && (test->vmcb->control.exit_info_1 == 0x7)
+           && (test->vmcb->control.exit_info_1 == 0x200000006ULL)
 	   && (test->vmcb->control.exit_info_2 == read_cr3());
 }
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH kvm-unit-tests 2/3] x86: svm: add page access reserved bit test
  2014-09-02 15:05 [PATCH kvm-unit-tests 0/3] svm: fix expected values and add extra NPT tests Paolo Bonzini
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 1/3] x86: svm: fix exitinfo values for " Paolo Bonzini
@ 2014-09-02 15:05 ` Paolo Bonzini
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 3/3] x86: svm: add L1 MMIO read-only permission test Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-09-02 15:05 UTC (permalink / raw)
  To: kvm; +Cc: jroedel, agraf, valentine.sinitsyn, jan.kiszka

The reserved bit test was testing faults during page walk, rather than
during page access.  Add another test that uses large pages to test
reserved bits during page access, and rename the old test to indicate
what it really covers.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/svm.c | 50 +++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 43 insertions(+), 7 deletions(-)

diff --git a/x86/svm.c b/x86/svm.c
index c4d6d94..df316b5 100644
--- a/x86/svm.c
+++ b/x86/svm.c
@@ -102,6 +102,17 @@ static void setup_svm(void)
     pml4e[0] = ((u64)pdpe) | 0x27;
 }
 
+static u64 *npt_get_pde(u64 address)
+{
+    int i1, i2;
+
+    address >>= 21;
+    i1 = (address >> 9) & 0x3;
+    i2 = address & 0x1ff;
+
+    return &pde[i1][i2];
+}
+
 static u64 *npt_get_pte(u64 address)
 {
     int i1, i2;
@@ -731,20 +742,27 @@ static bool npt_us_check(struct test *test)
            && (test->vmcb->control.exit_info_1 == 0x100000005ULL);
 }
 
+u64 save_pde;
+
 static void npt_rsvd_prepare(struct test *test)
 {
+    u64 *pde;
 
     vmcb_ident(test->vmcb);
+    pde = npt_get_pde((u64) null_test);
 
-    pdpe[0] |= (1ULL << 8);
+    save_pde = *pde;
+    *pde = (1ULL << 19) | (1ULL << 7) | 0x27;
 }
 
 static bool npt_rsvd_check(struct test *test)
 {
-    pdpe[0] &= ~(1ULL << 8);
+    u64 *pde = npt_get_pde((u64) null_test);
+
+    *pde = save_pde;
 
     return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
-            && (test->vmcb->control.exit_info_1 == 0x200000006ULL);
+            && (test->vmcb->control.exit_info_1 == 0x10000001dULL);
 }
 
 static void npt_rw_prepare(struct test *test)
@@ -775,7 +793,7 @@ static bool npt_rw_check(struct test *test)
            && (test->vmcb->control.exit_info_1 == 0x100000007ULL);
 }
 
-static void npt_pfwalk_prepare(struct test *test)
+static void npt_rw_pfwalk_prepare(struct test *test)
 {
 
     u64 *pte;
@@ -786,7 +804,7 @@ static void npt_pfwalk_prepare(struct test *test)
     *pte &= ~(1ULL << 1);
 }
 
-static bool npt_pfwalk_check(struct test *test)
+static bool npt_rw_pfwalk_check(struct test *test)
 {
     u64 *pte = npt_get_pte(read_cr3());
 
@@ -797,6 +815,22 @@ static bool npt_pfwalk_check(struct test *test)
 	   && (test->vmcb->control.exit_info_2 == read_cr3());
 }
 
+static void npt_rsvd_pfwalk_prepare(struct test *test)
+{
+
+    vmcb_ident(test->vmcb);
+
+    pdpe[0] |= (1ULL << 8);
+}
+
+static bool npt_rsvd_pfwalk_check(struct test *test)
+{
+    pdpe[0] &= ~(1ULL << 8);
+
+    return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
+            && (test->vmcb->control.exit_info_1 == 0x200000006ULL);
+}
+
 static void npt_l1mmio_prepare(struct test *test)
 {
     vmcb_ident(test->vmcb);
@@ -984,8 +1018,10 @@ static struct test tests[] = {
 	    default_finished, npt_rsvd_check },
     { "npt_rw", npt_supported, npt_rw_prepare, npt_rw_test,
 	    default_finished, npt_rw_check },
-    { "npt_pfwalk", npt_supported, npt_pfwalk_prepare, null_test,
-	    default_finished, npt_pfwalk_check },
+    { "npt_rsvd_pfwalk", npt_supported, npt_rsvd_pfwalk_prepare, null_test,
+	    default_finished, npt_rsvd_pfwalk_check },
+    { "npt_rw_pfwalk", npt_supported, npt_rw_pfwalk_prepare, null_test,
+	    default_finished, npt_rw_pfwalk_check },
     { "npt_l1mmio", npt_supported, npt_l1mmio_prepare, npt_l1mmio_test,
 	    default_finished, npt_l1mmio_check },
     { "latency_run_exit", default_supported, latency_prepare, latency_test,
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH kvm-unit-tests 3/3] x86: svm: add L1 MMIO read-only permission test
  2014-09-02 15:05 [PATCH kvm-unit-tests 0/3] svm: fix expected values and add extra NPT tests Paolo Bonzini
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 1/3] x86: svm: fix exitinfo values for " Paolo Bonzini
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 2/3] x86: svm: add page access reserved bit test Paolo Bonzini
@ 2014-09-02 15:05 ` Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2014-09-02 15:05 UTC (permalink / raw)
  To: kvm; +Cc: jroedel, agraf, valentine.sinitsyn, jan.kiszka

Test that the emulator correctly injects a nested page fault VMEXIT.

Reported-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/svm.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/x86/svm.c b/x86/svm.c
index df316b5..85bb1fa 100644
--- a/x86/svm.c
+++ b/x86/svm.c
@@ -855,6 +855,34 @@ static bool npt_l1mmio_check(struct test *test)
     return nested_apic_version1 == lvr && nested_apic_version2 == lvr;
 }
 
+static void npt_rw_l1mmio_prepare(struct test *test)
+{
+
+    u64 *pte;
+
+    vmcb_ident(test->vmcb);
+    pte = npt_get_pte(0xfee00080);
+
+    *pte &= ~(1ULL << 1);
+}
+
+static void npt_rw_l1mmio_test(struct test *test)
+{
+    volatile u32 *data = (volatile void*)(0xfee00080);
+
+    *data = *data;
+}
+
+static bool npt_rw_l1mmio_check(struct test *test)
+{
+    u64 *pte = npt_get_pte(0xfee00080);
+
+    *pte |= (1ULL << 1);
+
+    return (test->vmcb->control.exit_code == SVM_EXIT_NPF)
+           && (test->vmcb->control.exit_info_1 == 0x100000007ULL);
+}
+
 static void latency_prepare(struct test *test)
 {
     default_prepare(test);
@@ -1024,6 +1052,8 @@ static struct test tests[] = {
 	    default_finished, npt_rw_pfwalk_check },
     { "npt_l1mmio", npt_supported, npt_l1mmio_prepare, npt_l1mmio_test,
 	    default_finished, npt_l1mmio_check },
+    { "npt_rw_l1mmio", npt_supported, npt_rw_l1mmio_prepare, npt_rw_l1mmio_test,
+	    default_finished, npt_rw_l1mmio_check },
     { "latency_run_exit", default_supported, latency_prepare, latency_test,
       latency_finished, latency_check },
     { "latency_svm_insn", default_supported, lat_svm_insn_prepare, null_test,
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH kvm-unit-tests 1/3] x86: svm: fix exitinfo values for NPT tests
  2014-09-02 15:05 ` [PATCH kvm-unit-tests 1/3] x86: svm: fix exitinfo values for " Paolo Bonzini
@ 2014-09-02 16:14   ` Joerg Roedel
  0 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2014-09-02 16:14 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, agraf, valentine.sinitsyn, jan.kiszka

On Tue, Sep 02, 2014 at 05:05:26PM +0200, Paolo Bonzini wrote:
> The exitinfo values were plain wrong for the page-walk tests
> (including npt_rsvd), or else they were missing bits 32:33.
> Expect the right values.

Are bits 32:33 really emulated? IIRC they were not emulated in the
inital implementation, and they are missing in some hardware NPT
implementations as well.


	Joerg


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-09-02 16:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-02 15:05 [PATCH kvm-unit-tests 0/3] svm: fix expected values and add extra NPT tests Paolo Bonzini
2014-09-02 15:05 ` [PATCH kvm-unit-tests 1/3] x86: svm: fix exitinfo values for " Paolo Bonzini
2014-09-02 16:14   ` Joerg Roedel
2014-09-02 15:05 ` [PATCH kvm-unit-tests 2/3] x86: svm: add page access reserved bit test Paolo Bonzini
2014-09-02 15:05 ` [PATCH kvm-unit-tests 3/3] x86: svm: add L1 MMIO read-only permission test Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.