vmm: refactor userspace's emsr_fakewrite() master origin/master current
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 22 Aug 2019 18:46:45 +0000 (14:46 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 22 Aug 2019 18:46:45 +0000 (14:46 -0400)
The old fakewrite would attempt to do a readmsr, which will fail.
However, we only need to do a readmsr if we read before writing.  Most
uses of this will do a write first.

Note that rdmsr and wrmsr will fail from userspace.  The MSR emulation
code is mostly just an unused copy of the kernel's, but it's useful to
prototype changes in userspace without requiring a kernel reboot.  i.e.
this is for debugging.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/vmm/vmxmsr.c

index 67f7032..03b8a13 100644 (file)
@@ -128,18 +128,17 @@ static int emsr_fakewrite(struct guest_thread *vm_thread, struct emmsr *msr,
        uint64_t msr_val;
        struct vm_trapframe *vm_tf = &(vm_thread->uthread.u_ctx.tf.vm_tf);
 
-       if (!msr->written) {
-               msr_val = read_msr(msr->reg);
-               eax = low32(msr_val);
-               edx = high32(msr_val);
-       } else {
-               eax = msr->eax;
-               edx = msr->edx;
-       }
        if (opcode == EXIT_REASON_MSR_READ) {
+               if (!msr->written) {
+                       msr_val = read_msr(msr->reg);
+                       eax = low32(msr_val);
+                       edx = high32(msr_val);
+               } else {
+                       eax = msr->eax;
+                       edx = msr->edx;
+               }
                vm_tf->tf_rax = eax;
                vm_tf->tf_rdx = edx;
-               return 0;
        } else {
                msr->edx = vm_tf->tf_rdx;
                msr->eax = vm_tf->tf_rax;