From: "Jan Beulich" Subject: [PATCH] x86: disable AMD's C1E mode Date: Thu, 11 Oct 2007 09:51:49 +0100 Message-ID: <470E0045.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org In C1E the APIC timer stops ticking, which Xen cannot tolerate. (As I don't have a system that's affected, the patch must be considered untested). Signed-off-by: Jan Beulich Index: 2007-10-10/xen/arch/x86/acpi/boot.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-10-10.orig/xen/arch/x86/acpi/boot.c 2007-09-27 10:42:44.0000000= 00 +0200 +++ 2007-10-10/xen/arch/x86/acpi/boot.c 2007-10-10 17:14:46.000000000 = +0200 @@ -70,6 +70,9 @@ int acpi_skip_timer_override __initdata; static u64 acpi_lapic_addr __initdata =3D APIC_DEFAULT_PHYS_BASE; #endif =20 +u32 acpi_smi_cmd; +u8 acpi_enable_value, acpi_disable_value; + #ifndef __HAVE_ARCH_CMPXCHG #warning ACPI uses CMPXCHG, i486 and later hardware #endif @@ -509,9 +512,14 @@ static int __init acpi_parse_fadt(unsign pmtmr_ioport); #endif =20 + acpi_smi_cmd =3D fadt->smi_cmd; + acpi_enable_value =3D fadt->acpi_enable; + acpi_disable_value =3D fadt->acpi_disable; + #ifdef CONFIG_ACPI_SLEEP acpi_fadt_parse_sleep_info(fadt); #endif + return 0; } =20 Index: 2007-10-10/xen/arch/x86/cpu/amd.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-10-10.orig/xen/arch/x86/cpu/amd.c 2007-10-10 17:12:29.0000000= 00 +0200 +++ 2007-10-10/xen/arch/x86/cpu/amd.c 2007-10-10 17:14:05.000000000 = +0200 @@ -100,6 +100,32 @@ static void disable_c1_ramping(void)=20 } } =20 +#ifdef CONFIG_SMP +/* + * Disable C1E mode, as the APIC timer stops in that mode. + */ +static void disable_c1e(void *unused) +{ + u32 lo, hi; + + if (rdmsr_safe(0xC0010055, lo, hi) =3D=3D 0 + && (lo & ((1 << 27) | (1 << 28))) + && wrmsr_safe(0xC0010055, + lo & ~((1 << 27) | (1 << 28)), + hi) !=3D 0) + printk(KERN_ERR "Failed to disable C1E on CPU#%u (%08x)\n",= + smp_processor_id(), lo); +} + +static void check_disable_c1e(unsigned int port, u8 value) +{ + if (port =3D=3D acpi_smi_cmd && value =3D=3D acpi_enable_value) + on_each_cpu(disable_c1e, NULL, 1, 1); +} +#else +#define check_disable_c1e NULL +#endif + static void __init init_amd(struct cpuinfo_x86 *c) { u32 l, h; @@ -280,6 +306,10 @@ static void __init init_amd(struct cpuin switch (c->x86) { case 15 ... 17: set_bit(X86_FEATURE_K8, c->x86_capability); + if (acpi_smi_cmd && (acpi_enable_value | acpi_disable_value= )) { + disable_c1e(NULL); + pv_post_outb_hook =3D check_disable_c1e; + } break; case 6: set_bit(X86_FEATURE_K7, c->x86_capability); Index: 2007-10-10/xen/arch/x86/traps.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-10-10.orig/xen/arch/x86/traps.c 2007-10-10 17:11:34.0000000= 00 +0200 +++ 2007-10-10/xen/arch/x86/traps.c 2007-10-10 17:14:05.000000000 = +0200 @@ -1191,6 +1191,8 @@ void host_to_guest_gpr_switch(struct cpu unsigned long guest_to_host_gpr_switch(unsigned long) __attribute__((__regparm__(1))); =20 +void (*pv_post_outb_hook)(unsigned int port, u8 value); + /* Instruction fetch with error handling. */ #define insn_fetch(type, base, eip, limit) = \ ({ unsigned long _rc, _ptr =3D (base) + (eip); = \ @@ -1419,7 +1421,11 @@ static int emulate_privileged_op(struct=20 { case 1: if ( guest_outb_okay(port, v, regs) ) + { outb((u8)data, port); + if ( pv_post_outb_hook ) + pv_post_outb_hook(port, data); + } else if ( port =3D=3D 0x42 || port =3D=3D 0x43 || port = =3D=3D 0x61 ) pv_pit_handler(port, data, 1); break; @@ -1537,7 +1543,11 @@ static int emulate_privileged_op(struct=20 { case 1: if ( guest_outb_okay(port, v, regs) ) + { io_emul(regs); + if ( pv_post_outb_hook ) + pv_post_outb_hook(port, regs->eax); + } else if ( port =3D=3D 0x42 || port =3D=3D 0x43 || port =3D=3D = 0x61 ) pv_pit_handler(port, regs->eax, 1); break; Index: 2007-10-10/xen/include/asm-x86/acpi.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-10-10.orig/xen/include/asm-x86/acpi.h 2007-09-27 10:42:44.0000000= 00 +0200 +++ 2007-10-10/xen/include/asm-x86/acpi.h 2007-10-10 17:14:05.0000000= 00 +0200 @@ -114,6 +114,8 @@ extern int acpi_strict; extern int acpi_disabled; extern int acpi_ht; extern int acpi_pci_disabled; +extern u32 acpi_smi_cmd; +extern u8 acpi_enable_value, acpi_disable_value; static inline void disable_acpi(void)=20 {=20 acpi_disabled =3D 1; Index: 2007-10-10/xen/include/asm-x86/io.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-10-10.orig/xen/include/asm-x86/io.h 2006-08-21 18:02:24.0000000= 00 +0200 +++ 2007-10-10/xen/include/asm-x86/io.h 2007-10-10 17:14:05.000000000 = +0200 @@ -50,4 +50,6 @@ __OUT(b,"b",char) __OUT(w,"w",short) __OUT(l,,int) =20 +extern void (*pv_post_outb_hook)(unsigned int port, u8 value); + #endif