diff mbox series

[kvm-unit-tests,04/12] nSVM: Explicitly save/update/restore EFER.NX for NPT NX test

Message ID 20210622210047.3691840-5-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series nSVM: NPT improvements and cleanups | expand

Commit Message

Sean Christopherson June 22, 2021, 9 p.m. UTC
Explicitly set EFER.NX in the NPT NX test instead of assuming all tests
will run with EFER.NX=1, and use the test's scratch field to save/restore
EFER.  There is no need to force EFER.NX=1 for all tests, and a future
test will verify that a #NPT occurs when EFER.NX=0 and PTE.NX=1, i.e.
wants the exact opposite.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 x86/svm_tests.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index aa74cfe..506bd75 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -700,9 +700,11 @@  static bool sel_cr0_bug_check(struct svm_test *test)
 
 static void npt_nx_prepare(struct svm_test *test)
 {
-
     u64 *pte;
 
+    test->scratch = rdmsr(MSR_EFER);
+    wrmsr(MSR_EFER, test->scratch | EFER_NX);
+
     pte = npt_get_pte((u64)null_test);
 
     *pte |= PT64_NX_MASK;
@@ -712,6 +714,8 @@  static bool npt_nx_check(struct svm_test *test)
 {
     u64 *pte = npt_get_pte((u64)null_test);
 
+    wrmsr(MSR_EFER, test->scratch);
+
     *pte &= ~PT64_NX_MASK;
 
     vmcb->save.efer |= EFER_NX;