xcp-1.6-updates/xen-4.1.hg

changeset 23240:0bea45ab39f7

x86/emulator: workaround for AMD erratum 573

The only cases where we might end up emulating fsincos (as any other
x87 operations without memory operands) are
- when a HVM guest is in real mode (not applicable on AMD)
- between two half page table updates in PAE mode (unlikely, and not
doing the emulation here does affect only performance, not
correctness)
- when a guest maliciously (or erroneously) modifies an (MMIO or page
table update) instruction under emulation (unspecified behavior)

Hence, in order to avoid the erratum to cause harm to the entire host,
don't emulate fsincos on the affected AMD CPU families.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 24417:1452fb248cd5
xen-unstable date: Fri Dec 16 15:45:40 2011 +0100
author Jan Beulich <jbeulich@suse.com>
date Wed Mar 07 08:17:44 2012 +0000 (2012-03-07)
parents 04e5091cc08f
children d21100f1d00e
files tools/tests/x86_emulator/x86_emulate.c xen/arch/x86/x86_emulate.c xen/arch/x86/x86_emulate/x86_emulate.c xen/include/asm-x86/amd.h
line diff
     1.1 --- a/tools/tests/x86_emulator/x86_emulate.c	Wed Mar 07 08:16:53 2012 +0000
     1.2 +++ b/tools/tests/x86_emulator/x86_emulate.c	Wed Mar 07 08:17:44 2012 +0000
     1.3 @@ -3,5 +3,7 @@
     1.4  #include <string.h>
     1.5  #include <public/xen.h>
     1.6  
     1.7 +#define cpu_has_amd_erratum(nr) 0
     1.8 +
     1.9  #include "x86_emulate/x86_emulate.h"
    1.10  #include "x86_emulate/x86_emulate.c"
     2.1 --- a/xen/arch/x86/x86_emulate.c	Wed Mar 07 08:16:53 2012 +0000
     2.2 +++ b/xen/arch/x86/x86_emulate.c	Wed Mar 07 08:17:44 2012 +0000
     2.3 @@ -10,8 +10,14 @@
     2.4   */
     2.5  
     2.6  #include <asm/x86_emulate.h>
     2.7 +#include <asm/processor.h> /* current_cpu_info */
     2.8 +#include <asm/amd.h> /* cpu_has_amd_erratum() */
     2.9  
    2.10  /* Avoid namespace pollution. */
    2.11  #undef cmpxchg
    2.12 +#undef cpuid
    2.13 +
    2.14 +#define cpu_has_amd_erratum(nr) \
    2.15 +        cpu_has_amd_erratum(&current_cpu_data, AMD_ERRATUM_##nr)
    2.16  
    2.17  #include "x86_emulate/x86_emulate.c"
     3.1 --- a/xen/arch/x86/x86_emulate/x86_emulate.c	Wed Mar 07 08:16:53 2012 +0000
     3.2 +++ b/xen/arch/x86/x86_emulate/x86_emulate.c	Wed Mar 07 08:17:44 2012 +0000
     3.3 @@ -2578,6 +2578,9 @@ x86_emulate(
     3.4      case 0xd9: /* FPU 0xd9 */
     3.5          switch ( modrm )
     3.6          {
     3.7 +        case 0xfb: /* fsincos */
     3.8 +            fail_if(cpu_has_amd_erratum(573));
     3.9 +            /* fall through */
    3.10          case 0xc0 ... 0xc7: /* fld %stN */
    3.11          case 0xc8 ... 0xcf: /* fxch %stN */
    3.12          case 0xd0: /* fnop */
    3.13 @@ -2603,7 +2606,6 @@ x86_emulate(
    3.14          case 0xf8: /* fprem */
    3.15          case 0xf9: /* fyl2xp1 */
    3.16          case 0xfa: /* fsqrt */
    3.17 -        case 0xfb: /* fsincos */
    3.18          case 0xfc: /* frndint */
    3.19          case 0xfd: /* fscale */
    3.20          case 0xfe: /* fsin */
     4.1 --- a/xen/include/asm-x86/amd.h	Wed Mar 07 08:16:53 2012 +0000
     4.2 +++ b/xen/include/asm-x86/amd.h	Wed Mar 07 08:17:44 2012 +0000
     4.3 @@ -138,6 +138,12 @@
     4.4      AMD_OSVW_ERRATUM(1, AMD_MODEL_RANGE(0xf, 0x41, 0x2, 0xff, 0xf),     \
     4.5                          AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf))
     4.6  
     4.7 +#define AMD_ERRATUM_573							\
     4.8 +    AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x0f, 0x0, 0x0, 0xff, 0xf),	\
     4.9 +                       AMD_MODEL_RANGE(0x10, 0x0, 0x0, 0xff, 0xf),	\
    4.10 +                       AMD_MODEL_RANGE(0x11, 0x0, 0x0, 0xff, 0xf),	\
    4.11 +                       AMD_MODEL_RANGE(0x12, 0x0, 0x0, 0xff, 0xf))
    4.12 +
    4.13  struct cpuinfo_x86;
    4.14  int cpu_has_amd_erratum(const struct cpuinfo_x86 *, int, ...);
    4.15