# HG changeset patch # User Keir Fraser # Date 1295625507 0 # Node ID 9bd5f65050f8014de7d0fcf9d89ed8c441f261fa # Parent 5852612cd4c461e5219db73cc52de0c643c414e8 x86:x2apic: Disable x2apic on x86-32 permanently x2apic initialization on x86_32 uses vcpu pointer before it is initialized. As x2apic is unlikely to be used on x86_32, this patch disables x2apic permanently on x86_32. It also asserts the sanity of vcpu pointer before dereference to prevent further misuse. Signed-off-by: Fengzhe Zhang jb: Moved logic into check_x2apic_preenabled(), disabled dead code on x86_32. Index: xen-4.0.2-testing/xen/arch/x86/apic.c =================================================================== --- xen-4.0.2-testing.orig/xen/arch/x86/apic.c +++ xen-4.0.2-testing/xen/arch/x86/apic.c @@ -959,6 +959,10 @@ void x2apic_setup(void) if ( !cpu_has_x2apic ) return; +#ifdef __i386__ + BUG(); +#else + if ( !opt_x2apic ) { if ( !x2apic_enabled ) @@ -1020,6 +1024,7 @@ restore_out: unmask_8259A(); out: +#endif /* !__i386__ */ if ( ioapic_entries ) free_ioapic_entries(ioapic_entries); } Index: xen-4.0.2-testing/xen/arch/x86/genapic/x2apic.c =================================================================== --- xen-4.0.2-testing.orig/xen/arch/x86/genapic/x2apic.c +++ xen-4.0.2-testing/xen/arch/x86/genapic/x2apic.c @@ -25,6 +25,8 @@ #include #include +#ifndef __i386__ + static int x2apic_phys; /* By default we use logical cluster mode. */ boolean_param("x2apic_phys", x2apic_phys); @@ -137,6 +139,8 @@ const struct genapic *apic_x2apic_probe( return x2apic_phys ? &apic_x2apic_phys : &apic_x2apic_cluster; } +#endif /* !__i386__ */ + void __init check_x2apic_preenabled(void) { u32 lo, hi; @@ -149,7 +153,19 @@ void __init check_x2apic_preenabled(void if ( lo & MSR_IA32_APICBASE_EXTD ) { printk("x2APIC mode is already enabled by BIOS.\n"); +#ifndef __i386__ x2apic_enabled = 1; genapic = apic_x2apic_probe(); +#else + lo &= ~(MSR_IA32_APICBASE_ENABLE | MSR_IA32_APICBASE_EXTD); + wrmsr(MSR_IA32_APICBASE, lo, hi); + lo |= MSR_IA32_APICBASE_ENABLE; + wrmsr(MSR_IA32_APICBASE, lo, hi); + printk("x2APIC disabled permanently on x86_32.\n"); +#endif } + +#ifdef __i386__ + clear_bit(X86_FEATURE_X2APIC, boot_cpu_data.x86_capability); +#endif }