diff mbox series

[kvm-unit-tests,04/14] x86: msr: Restore original MSR value after writing arbitrary test value

Message ID 20210422030504.3488253-5-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series x86: MSR_GS_BASE and friends | expand

Commit Message

Sean Christopherson April 22, 2021, 3:04 a.m. UTC
Restore the original MSR value after the WRMSR/RDMSR test.  MSR_GS_BASE
in particular needs to be restored as it points at per-cpu data.

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

Patch

diff --git a/x86/msr.c b/x86/msr.c
index 757156d..5a3f1c3 100644
--- a/x86/msr.c
+++ b/x86/msr.c
@@ -77,7 +77,7 @@  static int find_msr_info(int msr_index)
 
 static void test_msr_rw(int msr_index, unsigned long long input, unsigned long long expected)
 {
-    unsigned long long r = 0;
+    unsigned long long r, orig;
     int index;
     const char *sptr;
     if ((index = find_msr_info(msr_index)) != -1) {
@@ -86,8 +86,11 @@  static void test_msr_rw(int msr_index, unsigned long long input, unsigned long l
         printf("couldn't find name for msr # %#x, skipping\n", msr_index);
         return;
     }
+
+    orig = rdmsr(msr_index);
     wrmsr(msr_index, input);
     r = rdmsr(msr_index);
+    wrmsr(msr_index, orig);
     if (expected != r) {
         printf("testing %s: output = %#" PRIx32 ":%#" PRIx32
 	       " expected = %#" PRIx32 ":%#" PRIx32 "\n", sptr,