debuggers.hg

changeset 19991:fe4c6845a9d7

vmx: Fix handling of FS/GS base MSRs.

Firstly, these MSRs are always accessible if the CPU supports them --
we should not check for EFER.LMA.

Secondly, we should not use teh cached value of shadow_gs while the
VCPU is running. It can be stale if the guest has executed SWAPGS
(which we cannot trap). Hence always access the underlying host MSR
when emulating guest accesses.

The latter bug was found and a patch proposed by <leonid@3tera.com>

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jul 16 10:26:55 2009 +0100 (2009-07-16)
parents 1033c6cdec62
children 8ce42378828b
files xen/arch/x86/hvm/vmx/vmx.c
line diff
     1.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Thu Jul 16 08:30:23 2009 +0100
     1.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Jul 16 10:26:55 2009 +0100
     1.3 @@ -177,20 +177,14 @@ static enum handler_return long_mode_do_
     1.4  
     1.5      case MSR_FS_BASE:
     1.6          msr_content = __vmread(GUEST_FS_BASE);
     1.7 -        goto check_long_mode;
     1.8 +        break;
     1.9  
    1.10      case MSR_GS_BASE:
    1.11          msr_content = __vmread(GUEST_GS_BASE);
    1.12 -        goto check_long_mode;
    1.13 +        break;
    1.14  
    1.15      case MSR_SHADOW_GS_BASE:
    1.16 -        msr_content = v->arch.hvm_vmx.shadow_gs;
    1.17 -    check_long_mode:
    1.18 -        if ( !(hvm_long_mode_enabled(v)) )
    1.19 -        {
    1.20 -            vmx_inject_hw_exception(TRAP_gp_fault, 0);
    1.21 -            return HNDL_exception_raised;
    1.22 -        }
    1.23 +        rdmsrl(MSR_SHADOW_GS_BASE, msr_content);
    1.24          break;
    1.25  
    1.26      case MSR_STAR:
    1.27 @@ -241,9 +235,6 @@ static enum handler_return long_mode_do_
    1.28      case MSR_FS_BASE:
    1.29      case MSR_GS_BASE:
    1.30      case MSR_SHADOW_GS_BASE:
    1.31 -        if ( !hvm_long_mode_enabled(v) )
    1.32 -            goto gp_fault;
    1.33 -
    1.34          if ( !is_canonical_address(msr_content) )
    1.35              goto uncanonical_address;
    1.36  
    1.37 @@ -252,10 +243,7 @@ static enum handler_return long_mode_do_
    1.38          else if ( ecx == MSR_GS_BASE )
    1.39              __vmwrite(GUEST_GS_BASE, msr_content);
    1.40          else
    1.41 -        {
    1.42 -            v->arch.hvm_vmx.shadow_gs = msr_content;
    1.43              wrmsrl(MSR_SHADOW_GS_BASE, msr_content);
    1.44 -        }
    1.45  
    1.46          break;
    1.47  
    1.48 @@ -284,7 +272,6 @@ static enum handler_return long_mode_do_
    1.49  
    1.50   uncanonical_address:
    1.51      HVM_DBG_LOG(DBG_LEVEL_0, "Not cano address of msr write %x", ecx);
    1.52 - gp_fault:
    1.53      vmx_inject_hw_exception(TRAP_gp_fault, 0);
    1.54   exception_raised:
    1.55      return HNDL_exception_raised;
    1.56 @@ -311,7 +298,10 @@ static void vmx_restore_host_msrs(void)
    1.57  
    1.58  static void vmx_save_guest_msrs(struct vcpu *v)
    1.59  {
    1.60 -    /* MSR_SHADOW_GS_BASE may have been changed by swapgs instruction. */
    1.61 +    /*
    1.62 +     * We cannot cache SHADOW_GS_BASE while the VCPU runs, as it can
    1.63 +     * be updated at any time via SWAPGS, which we cannot trap.
    1.64 +     */
    1.65      rdmsrl(MSR_SHADOW_GS_BASE, v->arch.hvm_vmx.shadow_gs);
    1.66  }
    1.67