ia64/xen-unstable

changeset 16418:93d129d27f69

hvm: Clean up CPUID 0x80000001 emulation. Filter out RDTSCP feature
and emulate with #UD on AMD.
Signed-off-by: Keir Fraser <keir.fraser@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Nov 22 10:33:10 2007 +0000 (2007-11-22)
parents 05cbf512b82b
children 7186e9611d55
files xen/arch/x86/hvm/svm/emulate.c xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/vmx/vmx.c xen/include/asm-x86/hvm/svm/emulate.h
line diff
     1.1 --- a/xen/arch/x86/hvm/svm/emulate.c	Wed Nov 21 14:36:07 2007 +0000
     1.2 +++ b/xen/arch/x86/hvm/svm/emulate.c	Thu Nov 22 10:33:10 2007 +0000
     1.3 @@ -348,8 +348,6 @@ MAKE_INSTR(WBINVD, 2, 0x0f, 0x09);
     1.4  MAKE_INSTR(CPUID,  2, 0x0f, 0xa2);
     1.5  MAKE_INSTR(RDMSR,  2, 0x0f, 0x32);
     1.6  MAKE_INSTR(WRMSR,  2, 0x0f, 0x30);
     1.7 -MAKE_INSTR(RDTSC,  2, 0x0f, 0x31);
     1.8 -MAKE_INSTR(RDTSCP, 3, 0x0f, 0x01, 0xf9);
     1.9  MAKE_INSTR(CLI,    1, 0xfa);
    1.10  MAKE_INSTR(STI,    1, 0xfb);
    1.11  MAKE_INSTR(RDPMC,  2, 0x0f, 0x33);
    1.12 @@ -383,8 +381,6 @@ static const u8 *opc_bytes[INSTR_MAX_COU
    1.13      [INSTR_CPUID]  = OPCODE_CPUID,
    1.14      [INSTR_RDMSR]  = OPCODE_RDMSR,
    1.15      [INSTR_WRMSR]  = OPCODE_WRMSR,
    1.16 -    [INSTR_RDTSC]  = OPCODE_RDTSC,
    1.17 -    [INSTR_RDTSCP] = OPCODE_RDTSCP,
    1.18      [INSTR_CLI]    = OPCODE_CLI,
    1.19      [INSTR_STI]    = OPCODE_STI,
    1.20      [INSTR_RDPMC]  = OPCODE_RDPMC,
     2.1 --- a/xen/arch/x86/hvm/svm/svm.c	Wed Nov 21 14:36:07 2007 +0000
     2.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Thu Nov 22 10:33:10 2007 +0000
     2.3 @@ -996,6 +996,7 @@ static void svm_do_no_device_fault(struc
     2.4  /* Reserved bits EDX: [31:29], [27], [22:20], [18], [10] */
     2.5  #define SVM_VCPU_CPUID_L1_EDX_RESERVED 0xe8740400
     2.6  
     2.7 +#define bitmaskof(idx)  (1U << ((idx) & 31))
     2.8  static void svm_vmexit_do_cpuid(struct vmcb_struct *vmcb,
     2.9                                  struct cpu_user_regs *regs)
    2.10  {
    2.11 @@ -1022,32 +1023,23 @@ static void svm_vmexit_do_cpuid(struct v
    2.12          break;
    2.13  
    2.14      case 0x80000001:
    2.15 +        /* Filter features which are shared with 0x00000001:EDX. */
    2.16          if ( vlapic_hw_disabled(vcpu_vlapic(v)) )
    2.17              __clear_bit(X86_FEATURE_APIC & 31, &edx);
    2.18 -
    2.19  #if CONFIG_PAGING_LEVELS >= 3
    2.20          if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_PAE_ENABLED] )
    2.21  #endif
    2.22              __clear_bit(X86_FEATURE_PAE & 31, &edx);
    2.23 -
    2.24          __clear_bit(X86_FEATURE_PSE36 & 31, &edx);
    2.25  
    2.26 -        /* Clear the Cmp_Legacy bit
    2.27 -         * This bit is supposed to be zero when HTT = 0.
    2.28 -         * See details on page 23 of AMD CPUID Specification.
    2.29 -         */
    2.30 -        __clear_bit(X86_FEATURE_CMP_LEGACY & 31, &ecx);
    2.31 -
    2.32 -        /* Make SVM feature invisible to the guest. */
    2.33 -        __clear_bit(X86_FEATURE_SVME & 31, &ecx);
    2.34 -        __clear_bit(X86_FEATURE_SKINIT & 31, &ecx);
    2.35 -
    2.36 -        __clear_bit(X86_FEATURE_OSVW & 31, &ecx);
    2.37 -        __clear_bit(X86_FEATURE_WDT & 31, &ecx);
    2.38 -
    2.39 -        /* So far, we do not support 3DNow for the guest. */
    2.40 -        __clear_bit(X86_FEATURE_3DNOW & 31, &edx);
    2.41 -        __clear_bit(X86_FEATURE_3DNOWEXT & 31, &edx);
    2.42 +        /* Filter all other features according to a whitelist. */
    2.43 +        edx &= (0x0183f3ff | /* features shared with 0x00000001:EDX */
    2.44 +                bitmaskof(X86_FEATURE_NX) |
    2.45 +                bitmaskof(X86_FEATURE_LM) |
    2.46 +                bitmaskof(X86_FEATURE_SYSCALL) |
    2.47 +                bitmaskof(X86_FEATURE_MP) |
    2.48 +                bitmaskof(X86_FEATURE_MMXEXT) |
    2.49 +                bitmaskof(X86_FEATURE_FFXSR));
    2.50          break;
    2.51  
    2.52      case 0x80000007:
    2.53 @@ -2293,6 +2285,7 @@ asmlinkage void svm_vmexit_handler(struc
    2.54          hvm_triple_fault();
    2.55          break;
    2.56  
    2.57 +    case VMEXIT_RDTSCP:
    2.58      case VMEXIT_MONITOR:
    2.59      case VMEXIT_MWAIT:
    2.60      case VMEXIT_VMRUN:
     3.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Wed Nov 21 14:36:07 2007 +0000
     3.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Nov 22 10:33:10 2007 +0000
     3.3 @@ -1298,6 +1298,14 @@ static void vmx_do_cpuid(struct cpu_user
     3.4      case 0x0000000A:
     3.5          eax = ebx = ecx = edx = 0;
     3.6          break;
     3.7 +
     3.8 +    case 0x80000001:
     3.9 +        /* Only a few features are advertised in Intel's 0x80000001. */
    3.10 +        ecx &= (bitmaskof(X86_FEATURE_LAHF_LM));
    3.11 +        edx &= (bitmaskof(X86_FEATURE_NX) |
    3.12 +                bitmaskof(X86_FEATURE_LM) |
    3.13 +                bitmaskof(X86_FEATURE_SYSCALL));
    3.14 +        break;
    3.15      }
    3.16  
    3.17      regs->eax = eax;
     4.1 --- a/xen/include/asm-x86/hvm/svm/emulate.h	Wed Nov 21 14:36:07 2007 +0000
     4.2 +++ b/xen/include/asm-x86/hvm/svm/emulate.h	Thu Nov 22 10:33:10 2007 +0000
     4.3 @@ -47,8 +47,6 @@ enum instruction_index {
     4.4      INSTR_CPUID,
     4.5      INSTR_RDMSR,
     4.6      INSTR_WRMSR,
     4.7 -    INSTR_RDTSC,
     4.8 -    INSTR_RDTSCP,
     4.9      INSTR_CLI,
    4.10      INSTR_STI,
    4.11      INSTR_RDPMC,