ia64/xen-unstable

changeset 17255:4b157affc08f

x86: fix feature availability for PV guests

PV guests should not be allowed to believe features not currently
virtualized (in many cases, requiring special MSRs) are available. Of
course it is bad enough that to work on older hypervisors guests will
still need to special case this, but better fix it now than never.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 18 16:05:24 2008 +0000 (2008-03-18)
parents 2c2b442902e2
children 6ac99b961bff
files xen/arch/x86/traps.c xen/include/asm-x86/cpufeature.h xen/include/asm-x86/msr-index.h
line diff
     1.1 --- a/xen/arch/x86/traps.c	Tue Mar 18 16:02:36 2008 +0000
     1.2 +++ b/xen/arch/x86/traps.c	Tue Mar 18 16:05:24 2008 +0000
     1.3 @@ -677,32 +677,75 @@ static int emulate_forced_invalid_op(str
     1.4          : "=a" (a), "=b" (b), "=c" (c), "=d" (d)
     1.5          : "0" (a), "1" (b), "2" (c), "3" (d) );
     1.6  
     1.7 -    if ( regs->eax == 1 )
     1.8 +    if ( (regs->eax & 0x7fffffff) == 1 )
     1.9      {
    1.10          /* Modify Feature Information. */
    1.11          __clear_bit(X86_FEATURE_VME, &d);
    1.12          __clear_bit(X86_FEATURE_PSE, &d);
    1.13          __clear_bit(X86_FEATURE_PGE, &d);
    1.14 +        __clear_bit(X86_FEATURE_MCE, &d);
    1.15 +        __clear_bit(X86_FEATURE_MCA, &d);
    1.16 +        if ( !IS_PRIV(current->domain) )
    1.17 +            __clear_bit(X86_FEATURE_MTRR, &d);
    1.18 +        __clear_bit(X86_FEATURE_PSE36, &d);
    1.19 +    }
    1.20 +    switch ( (uint32_t)regs->eax )
    1.21 +    {
    1.22 +    case 1:
    1.23 +        /* Modify Feature Information. */
    1.24          if ( !cpu_has_sep )
    1.25              __clear_bit(X86_FEATURE_SEP, &d);
    1.26  #ifdef __i386__
    1.27          if ( !supervisor_mode_kernel )
    1.28              __clear_bit(X86_FEATURE_SEP, &d);
    1.29  #endif
    1.30 -        if ( !IS_PRIV(current->domain) )
    1.31 -            __clear_bit(X86_FEATURE_MTRR, &d);
    1.32 -    }
    1.33 -    else if ( regs->eax == 0x80000001 )
    1.34 -    {
    1.35 +        __clear_bit(X86_FEATURE_DS, &d);
    1.36 +        __clear_bit(X86_FEATURE_ACC, &d);
    1.37 +        __clear_bit(X86_FEATURE_PBE, &d);
    1.38 +
    1.39 +        __clear_bit(X86_FEATURE_DTES64 % 32, &c);
    1.40 +        __clear_bit(X86_FEATURE_MWAIT % 32, &c);
    1.41 +        __clear_bit(X86_FEATURE_DSCPL % 32, &c);
    1.42 +        __clear_bit(X86_FEATURE_VMXE % 32, &c);
    1.43 +        __clear_bit(X86_FEATURE_SMXE % 32, &c);
    1.44 +        __clear_bit(X86_FEATURE_EST % 32, &c);
    1.45 +        __clear_bit(X86_FEATURE_TM2 % 32, &c);
    1.46 +        if ( is_pv_32bit_vcpu(current) )
    1.47 +            __clear_bit(X86_FEATURE_CX16 % 32, &c);
    1.48 +        __clear_bit(X86_FEATURE_XTPR % 32, &c);
    1.49 +        __clear_bit(X86_FEATURE_PDCM % 32, &c);
    1.50 +        __clear_bit(X86_FEATURE_DCA % 32, &c);
    1.51 +        break;
    1.52 +    case 0x80000001:
    1.53          /* Modify Feature Information. */
    1.54 -#ifdef __i386__
    1.55 -        __clear_bit(X86_FEATURE_SYSCALL % 32, &d);
    1.56 +        if ( is_pv_32bit_vcpu(current) )
    1.57 +        {
    1.58 +            __clear_bit(X86_FEATURE_LM % 32, &d);
    1.59 +            __clear_bit(X86_FEATURE_LAHF_LM % 32, &c);
    1.60 +        }
    1.61 +#ifndef __i386__
    1.62 +        if ( is_pv_32on64_vcpu(current) &&
    1.63 +             boot_cpu_data.x86_vendor != X86_VENDOR_AMD )
    1.64  #endif
    1.65 +            __clear_bit(X86_FEATURE_SYSCALL % 32, &d);
    1.66 +        __clear_bit(X86_FEATURE_PAGE1GB % 32, &d);
    1.67          __clear_bit(X86_FEATURE_RDTSCP % 32, &d);
    1.68 -    }
    1.69 -    else
    1.70 -    {
    1.71 +
    1.72 +        __clear_bit(X86_FEATURE_SVME % 32, &c);
    1.73 +        __clear_bit(X86_FEATURE_OSVW % 32, &c);
    1.74 +        __clear_bit(X86_FEATURE_IBS % 32, &c);
    1.75 +        __clear_bit(X86_FEATURE_SKINIT % 32, &c);
    1.76 +        __clear_bit(X86_FEATURE_WDT % 32, &c);
    1.77 +        break;
    1.78 +    case 5: /* MONITOR/MWAIT */
    1.79 +    case 0xa: /* Architectural Performance Monitor Features */
    1.80 +    case 0x8000000a: /* SVM revision and features */
    1.81 +    case 0x8000001b: /* Instruction Based Sampling */
    1.82 +        a = b = c = d = 0;
    1.83 +        break;
    1.84 +    default:
    1.85          (void)cpuid_hypervisor_leaves(regs->eax, &a, &b, &c, &d);
    1.86 +        break;
    1.87      }
    1.88  
    1.89      regs->eax = a;
    1.90 @@ -2035,6 +2078,15 @@ static int emulate_privileged_op(struct 
    1.91              if ( rdmsr_safe(regs->ecx, regs->eax, regs->edx) )
    1.92                  goto fail;
    1.93              break;
    1.94 +        case MSR_IA32_MISC_ENABLE:
    1.95 +            if ( rdmsr_safe(regs->ecx, regs->eax, regs->edx) )
    1.96 +                goto fail;
    1.97 +            regs->eax &= ~(MSR_IA32_MISC_ENABLE_PERF_AVAIL |
    1.98 +                           MSR_IA32_MISC_ENABLE_MONITOR_ENABLE);
    1.99 +            regs->eax |= MSR_IA32_MISC_ENABLE_BTS_UNAVAIL |
   1.100 +                         MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL |
   1.101 +                         MSR_IA32_MISC_ENABLE_XTPR_DISABLE;
   1.102 +            break;
   1.103          default:
   1.104              if ( rdmsr_hypervisor_regs(regs->ecx, &l, &h) )
   1.105              {
     2.1 --- a/xen/include/asm-x86/cpufeature.h	Tue Mar 18 16:02:36 2008 +0000
     2.2 +++ b/xen/include/asm-x86/cpufeature.h	Tue Mar 18 16:05:24 2008 +0000
     2.3 @@ -42,6 +42,7 @@
     2.4  #define X86_FEATURE_HT		(0*32+28) /* Hyper-Threading */
     2.5  #define X86_FEATURE_ACC		(0*32+29) /* Automatic clock control */
     2.6  #define X86_FEATURE_IA64	(0*32+30) /* IA-64 processor */
     2.7 +#define X86_FEATURE_PBE		(0*32+31) /* Pending Break Enable */
     2.8  
     2.9  /* AMD-defined CPU features, CPUID level 0x80000001, word 1 */
    2.10  /* Don't duplicate feature flags which are redundant with Intel! */
    2.11 @@ -76,6 +77,7 @@
    2.12  
    2.13  /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */
    2.14  #define X86_FEATURE_XMM3	(4*32+ 0) /* Streaming SIMD Extensions-3 */
    2.15 +#define X86_FEATURE_DTES64	(4*32+ 2) /* 64-bit Debug Store */
    2.16  #define X86_FEATURE_MWAIT	(4*32+ 3) /* Monitor/Mwait support */
    2.17  #define X86_FEATURE_DSCPL	(4*32+ 4) /* CPL Qualified Debug Store */
    2.18  #define X86_FEATURE_VMXE	(4*32+ 5) /* Virtual Machine Extensions */
    2.19 @@ -115,6 +117,8 @@
    2.20  #define X86_FEATURE_MISALIGNSSE	(6*32+ 7) /* Misaligned SSE Access */
    2.21  #define X86_FEATURE_3DNOWPF	(6*32+ 8) /* 3DNow! Prefetch */
    2.22  #define X86_FEATURE_OSVW	(6*32+ 9) /* OS Visible Workaround */
    2.23 +#define X86_FEATURE_IBS		(6*32+ 10) /* Instruction Based Sampling */
    2.24 +#define X86_FEATURE_SSE5	(6*32+ 11) /* AMD Streaming SIMD Extensions-5 */
    2.25  #define X86_FEATURE_SKINIT	(6*32+ 12) /* SKINIT, STGI/CLGI, DEV */
    2.26  #define X86_FEATURE_WDT		(6*32+ 13) /* Watchdog Timer */
    2.27  
     3.1 --- a/xen/include/asm-x86/msr-index.h	Tue Mar 18 16:02:36 2008 +0000
     3.2 +++ b/xen/include/asm-x86/msr-index.h	Tue Mar 18 16:05:24 2008 +0000
     3.3 @@ -255,6 +255,8 @@
     3.4  #define MSR_IA32_MISC_ENABLE_PERF_AVAIL   (1<<7)
     3.5  #define MSR_IA32_MISC_ENABLE_BTS_UNAVAIL  (1<<11)
     3.6  #define MSR_IA32_MISC_ENABLE_PEBS_UNAVAIL (1<<12)
     3.7 +#define MSR_IA32_MISC_ENABLE_MONITOR_ENABLE (1<<18)
     3.8 +#define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1<<23)
     3.9  
    3.10  /* Intel Model 6 */
    3.11  #define MSR_P6_EVNTSEL0			0x00000186