ia64/xen-unstable

changeset 3861:f25349622916

bitkeeper revision 1.1223 (4215eee4gqIO-1mu8V6FHhIhoaqaiQ)

Change priv-op emulation behaviour to fail silently in some cases
rather than propagate the fault (still non-silent in debug builds!).
Also be careful in running user-specified RDMSR/WRMSR: an invalid
MSR index causes a GP(0) fault.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@scramble.cl.cam.ac.uk
date Fri Feb 18 13:34:28 2005 +0000 (2005-02-18)
parents 0a8144360a21
children cb47fd96099e
files xen/arch/x86/dom0_ops.c xen/arch/x86/traps.c xen/include/asm-x86/config.h xen/include/asm-x86/msr.h
line diff
     1.1 --- a/xen/arch/x86/dom0_ops.c	Fri Feb 18 07:23:24 2005 +0000
     1.2 +++ b/xen/arch/x86/dom0_ops.c	Fri Feb 18 13:34:28 2005 +0000
     1.3 @@ -36,13 +36,13 @@ static unsigned long msr_hi;
     1.4  static void write_msr_for(void *unused)
     1.5  {
     1.6      if (((1 << current->processor) & msr_cpu_mask))
     1.7 -        wrmsr(msr_addr, msr_lo, msr_hi);
     1.8 +        (void)wrmsr_user(msr_addr, msr_lo, msr_hi);
     1.9  }
    1.10  
    1.11  static void read_msr_for(void *unused)
    1.12  {
    1.13      if (((1 << current->processor) & msr_cpu_mask))
    1.14 -        rdmsr(msr_addr, msr_lo, msr_hi);
    1.15 +        (void)rdmsr_user(msr_addr, msr_lo, msr_hi);
    1.16  }
    1.17  
    1.18  long arch_do_dom0_op(dom0_op_t *op, dom0_op_t *u_dom0_op)
     2.1 --- a/xen/arch/x86/traps.c	Fri Feb 18 07:23:24 2005 +0000
     2.2 +++ b/xen/arch/x86/traps.c	Fri Feb 18 13:34:28 2005 +0000
     2.3 @@ -375,12 +375,11 @@ static int emulate_privileged_op(struct 
     2.4          break;
     2.5  
     2.6      case 0x09: /* WBINVD */
     2.7 +        /* Ignore the instruction if unprivileged. */
     2.8          if ( !IS_CAPABLE_PHYSDEV(ed->domain) )
     2.9 -        {
    2.10              DPRINTK("Non-physdev domain attempted WBINVD.\n");
    2.11 -            goto fail;
    2.12 -        }
    2.13 -        wbinvd();
    2.14 +        else
    2.15 +            wbinvd();
    2.16          break;
    2.17  
    2.18      case 0x20: /* MOV CR?,<reg> */
    2.19 @@ -441,21 +440,21 @@ static int emulate_privileged_op(struct 
    2.20          break;
    2.21  
    2.22      case 0x30: /* WRMSR */
    2.23 +        /* Ignore the instruction if unprivileged. */
    2.24          if ( !IS_PRIV(ed->domain) )
    2.25 -        {
    2.26 -            DPRINTK("Non-priv domain attempted WRMSR.\n");
    2.27 +            DPRINTK("Non-priv domain attempted WRMSR(%p,%08lx,%08lx).\n",
    2.28 +                    regs->ecx, (long)regs->eax, (long)regs->edx);
    2.29 +        else if ( wrmsr_user(regs->ecx, regs->eax, regs->edx) )
    2.30              goto fail;
    2.31 -        }
    2.32 -        wrmsr(regs->ecx, regs->eax, regs->edx);
    2.33          break;
    2.34  
    2.35      case 0x32: /* RDMSR */
    2.36          if ( !IS_PRIV(ed->domain) )
    2.37 -        {
    2.38 -            DPRINTK("Non-priv domain attempted RDMSR.\n");
    2.39 +            DPRINTK("Non-priv domain attempted RDMSR(%p,%08lx,%08lx).\n",
    2.40 +                    regs->ecx, (long)regs->eax, (long)regs->edx);
    2.41 +        /* Everyone can read the MSR space. */
    2.42 +        if ( rdmsr_user(regs->ecx, regs->eax, regs->edx) )
    2.43              goto fail;
    2.44 -        }
    2.45 -        rdmsr(regs->ecx, regs->eax, regs->edx);
    2.46          break;
    2.47  
    2.48      default:
     3.1 --- a/xen/include/asm-x86/config.h	Fri Feb 18 07:23:24 2005 +0000
     3.2 +++ b/xen/include/asm-x86/config.h	Fri Feb 18 13:34:28 2005 +0000
     3.3 @@ -206,8 +206,10 @@ extern void __out_of_line_bug(int line) 
     3.4  #define __GUEST_SS        0x082b
     3.5  
     3.6  /* For generic assembly code: use macros to define operation/operand sizes. */
     3.7 -#define __OS "q"  /* Operation Suffix */
     3.8 -#define __OP "r"  /* Operand Prefix */
     3.9 +#define __OS          "q"  /* Operation Suffix */
    3.10 +#define __OP          "r"  /* Operand Prefix */
    3.11 +#define __FIXUP_ALIGN ".align 8"
    3.12 +#define __FIXUP_WORD  ".quad"
    3.13  
    3.14  #elif defined(__i386__)
    3.15  
    3.16 @@ -264,8 +266,10 @@ extern void __out_of_line_bug(int line) 
    3.17  #define __HYPERVISOR_DS 0x0810
    3.18  
    3.19  /* For generic assembly code: use macros to define operation/operand sizes. */
    3.20 -#define __OS "l"  /* Operation Suffix */
    3.21 -#define __OP "e"  /* Operand Prefix */
    3.22 +#define __OS          "l"  /* Operation Suffix */
    3.23 +#define __OP          "e"  /* Operand Prefix */
    3.24 +#define __FIXUP_ALIGN ".align 4"
    3.25 +#define __FIXUP_WORD  ".long"
    3.26  
    3.27  #endif /* __i386__ */
    3.28  
     4.1 --- a/xen/include/asm-x86/msr.h	Fri Feb 18 07:23:24 2005 +0000
     4.2 +++ b/xen/include/asm-x86/msr.h	Fri Feb 18 13:34:28 2005 +0000
     4.3 @@ -1,29 +1,46 @@
     4.4  #ifndef __ASM_MSR_H
     4.5  #define __ASM_MSR_H
     4.6  
     4.7 -/*
     4.8 - * Access to machine-specific registers (available on 586 and better only)
     4.9 - * Note: the rd* operations modify the parameters directly (without using
    4.10 - * pointer indirection), this allows gcc to optimize better
    4.11 - */
    4.12 -
    4.13  #define rdmsr(msr,val1,val2) \
    4.14       __asm__ __volatile__("rdmsr" \
    4.15  			  : "=a" (val1), "=d" (val2) \
    4.16  			  : "c" (msr))
    4.17  
    4.18 -#define rdmsrl(msr,val) do { unsigned long a__,b__; \
    4.19 -       __asm__ __volatile__("rdmsr" \
    4.20 -			    : "=a" (a__), "=d" (b__) \
    4.21 -			    : "c" (msr)); \
    4.22 -       val = a__ | (b__<<32); \
    4.23 -} while(0); 
    4.24 -
    4.25  #define wrmsr(msr,val1,val2) \
    4.26       __asm__ __volatile__("wrmsr" \
    4.27  			  : /* no outputs */ \
    4.28  			  : "c" (msr), "a" (val1), "d" (val2))
    4.29  
    4.30 +#define rdmsr_user(msr,val1,val2) ({\
    4.31 +    int _rc = 0; \
    4.32 +    __asm__ __volatile__( \
    4.33 +        "1: rdmsr\n2:\n" \
    4.34 +        ".section .fixup,\"ax\"\n" \
    4.35 +        "3: movl $1,%2\n; jmp 2b\n" \
    4.36 +        ".previous\n" \
    4.37 +        ".section __ex_table,\"a\"\n" \
    4.38 +        "   "__FIXUP_ALIGN"\n" \
    4.39 +        "   "__FIXUP_WORD" 1b,3b\n" \
    4.40 +        ".previous\n" \
    4.41 +        : "=a" (val1), "=d" (val2), "=r" (_rc) \
    4.42 +        : "c" (msr)); \
    4.43 +    _rc; })
    4.44 +
    4.45 +#define wrmsr_user(msr,val1,val2) ({\
    4.46 +    int _rc = 0; \
    4.47 +    __asm__ __volatile__( \
    4.48 +        "1: wrmsr\n2:\n" \
    4.49 +        ".section .fixup,\"ax\"\n" \
    4.50 +        "3: movl $1,%0\n; jmp 2b\n" \
    4.51 +        ".previous\n" \
    4.52 +        ".section __ex_table,\"a\"\n" \
    4.53 +        "   "__FIXUP_ALIGN"\n" \
    4.54 +        "   "__FIXUP_WORD" 1b,3b\n" \
    4.55 +        ".previous\n" \
    4.56 +        : "=r" (_rc) \
    4.57 +        : "c" (msr), "a" (val1), "d" (val2)); \
    4.58 +    _rc; })
    4.59 +
    4.60  #define rdtsc(low,high) \
    4.61       __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
    4.62