x86: allow pre-enabled x2apic mode to be disabled
cover x86: allow pre-enabled x2apic mode to be disabled
Previous version of this patch and discussion can be found at
https://lkml.org/lkml/2011/12/16/488
Splitup the patch from Yinghai into multiple patches with minor changes and other review comments (https://lkml.org/lkml/2011/12/20/27)
thanks,
suresh
PATCH 1/5 x86, apic: add probe() for apic_flat
From: Yinghai Lu <[email protected]>
Currently we start with the default apic_flat mode and switch to some other apic model depending on the apic drivers acpi_madt_oem_check() routines and later followed by the apic drivers probe() routines.
Once we selected non flat mode there was no case where we fall back to flat mode again.
Upcoming changes allow bios-enabled x2apic mode to be disabled by the OS if interrupt-remapping etc is not setup properly by the bios.
We now has a case for the apic to fall back to legacy flat mode during apic driver probe() seqeuence. Add a simple flat_probe() which allows the apic_flat mode to be the last fallback option.
---
arch/x86/kernel/apic/apic_flat_64.c +6 -1
@@ -171,9 +171,14 @@ static int flat_phys_pkg_id(int initial_apic_id, int index_msb)return initial_apic_id >> index_msb; } +static int flat_probe (void ) +{ +return 1 ; +} +static struct apic apic_flat = { .name ="flat" , - .probe =NULL , + .probe = flat_probe, .acpi_madt_oem_check = flat_acpi_madt_oem_check, .apic_id_registered = flat_apic_id_registered,
[tip:x86/apic] x86, apic: Add probe() for apic_flat
Commit-ID: e8524b2f43ab6747518aef81c709d104c478b1cd Gitweb: http://git.kernel.org/tip/e8524b2f43ab6747518aef81c709d104c478b1cd Author: Yinghai Lu <[email protected]> AuthorDate: Wed, 21 Dec 2011 17:45:15 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Fri, 23 Dec 2011 11:00:45 -0800
x86, apic: Add probe() for apic_flat
Currently we start with the default apic_flat mode and switch to some other apic model depending on the apic drivers acpi_madt_oem_check() routines and later followed by the apic drivers probe() routines.
Once we selected non flat mode there was no case where we fall back to flat mode again.
Upcoming changes allow bios-enabled x2apic mode to be disabled by the OS if interrupt-remapping etc is not setup properly by the bios.
We now has a case for the apic to fall back to legacy flat mode during apic driver probe() seqeuence. Add a simple flat_probe() which allows the apic_flat mode to be the last fallback option.
--- arch/x86/kernel/apic/apic_flat_64.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/kernel/apic/apic_flat_64.c +6 -1
@@ -171,9 +171,14 @@ static int flat_phys_pkg_id(int initial_apic_id, int index_msb)return initial_apic_id >> index_msb; } +static int flat_probe (void ) +{ +return 1 ; +} +static struct apic apic_flat = { .name ="flat" , - .probe =NULL , + .probe = flat_probe, .acpi_madt_oem_check = flat_acpi_madt_oem_check, .apic_id_registered = flat_apic_id_registered,
PATCH 2/5 x86, acpi: skip acpi x2apic entries if the x2apic feature is not present
In reply to Suresh SiddhaFrom: Yinghai Lu <[email protected]>
If the x2apic feature is not present (either the cpu is not capable of it or the user has disabled the feature using boot-parameter etc), ignore the x2apic MADT and SRAT entries provided by the ACPI tables.
---
arch/x86/kernel/acpi/boot.c +8 -2
@@ -219,6 +219,8 @@ static int __init acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end) {struct acpi_madt_local_x2apic *processor =NULL ; +int apic_id; +u8 enabled; processor = (struct acpi_madt_local_x2apic *)header;
@@ -227,6 +229,8 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)acpi_table_print_madt_entry (header); + apic_id = processor->local_apic_id; + enabled = processor->lapic_flags &ACPI_MADT_ENABLED ;#ifdef CONFIG_X86_X2APIC /* * We need to register disabled CPU as well to permit
@@ -235,8 +239,10 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)* to not preallocating memory for all NR_CPUS * when we use CPU hotplug. */ -acpi_register_lapic (processor->local_apic_id,/* APIC ID */ - processor->lapic_flags &ACPI_MADT_ENABLED ); +if (!cpu_has_x2apic && (apic_id >=0xff ) && enabled) + printk(KERN_WARNING PREFIX "x2apic entry ignored\n"); +else +acpi_register_lapic (apic_id, enabled);#else printk(KERN_WARNING PREFIX "x2apic entry ignored\n");#endif
arch/x86/mm/srat.c +6 -1
@@ -69,6 +69,12 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)if ((pa->flags &ACPI_SRAT_CPU_ENABLED ) ==0 )return ; pxm = pa->proximity_domain; + apic_id = pa->apic_id; +if (!cpu_has_x2apic && (apic_id >=0xff )) { +printk (KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n" , + pxm, apic_id); +return ; + } node =setup_node (pxm);if (node <0 ) {printk (KERN_ERR "SRAT: Too many proximity domains %x\n" , pxm);
@@ -76,7 +82,6 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)return ; } - apic_id = pa->apic_id;if (apic_id >=MAX_LOCAL_APIC ) {printk (KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n" , pxm, apic_id, node);return ;
[tip:x86/apic] x86, acpi: Skip acpi x2apic entries if the x2apic feature is not present
Commit-ID: a35fd28256e7736cc84af8931a16224f0bfaaf6c Gitweb: http://git.kernel.org/tip/a35fd28256e7736cc84af8931a16224f0bfaaf6c Author: Yinghai Lu <[email protected]> AuthorDate: Wed, 21 Dec 2011 17:45:16 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Fri, 23 Dec 2011 11:00:50 -0800
x86, acpi: Skip acpi x2apic entries if the x2apic feature is not present
If the x2apic feature is not present (either the cpu is not capable of it or the user has disabled the feature using boot-parameter etc), ignore the x2apic MADT and SRAT entries provided by the ACPI tables.
--- arch/x86/kernel/acpi/boot.c | 10 ++++++++-- arch/x86/mm/srat.c | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-)
arch/x86/kernel/acpi/boot.c +8 -2
@@ -219,6 +219,8 @@ static int __init acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end) {struct acpi_madt_local_x2apic *processor =NULL ; +int apic_id; +u8 enabled; processor = (struct acpi_madt_local_x2apic *)header;
@@ -227,6 +229,8 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)acpi_table_print_madt_entry (header); + apic_id = processor->local_apic_id; + enabled = processor->lapic_flags &ACPI_MADT_ENABLED ;#ifdef CONFIG_X86_X2APIC /* * We need to register disabled CPU as well to permit
@@ -235,8 +239,10 @@ acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)* to not preallocating memory for all NR_CPUS * when we use CPU hotplug. */ -acpi_register_lapic (processor->local_apic_id,/* APIC ID */ - processor->lapic_flags &ACPI_MADT_ENABLED ); +if (!cpu_has_x2apic && (apic_id >=0xff ) && enabled) + printk(KERN_WARNING PREFIX "x2apic entry ignored\n"); +else +acpi_register_lapic (apic_id, enabled);#else printk(KERN_WARNING PREFIX "x2apic entry ignored\n");#endif
arch/x86/mm/srat.c +6 -1
@@ -69,6 +69,12 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)if ((pa->flags &ACPI_SRAT_CPU_ENABLED ) ==0 )return ; pxm = pa->proximity_domain; + apic_id = pa->apic_id; +if (!cpu_has_x2apic && (apic_id >=0xff )) { +printk (KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n" , + pxm, apic_id); +return ; + } node =setup_node (pxm);if (node <0 ) {printk (KERN_ERR "SRAT: Too many proximity domains %x\n" , pxm);
@@ -76,7 +82,6 @@ acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)return ; } - apic_id = pa->apic_id;if (apic_id >=MAX_LOCAL_APIC ) {printk (KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n" , pxm, apic_id, node);return ;
PATCH 3/5 x86, x2apic: fallback to xapic when bios doesnt setup interrupt-remapping
In reply to Suresh SiddhaFrom: Yinghai Lu <[email protected]>
On some of the recent Intel SNB platforms, by default bios is pre-enabling x2apic mode in the cpu with out setting up interrupt-remapping. This case was resulting in the kernel to panic as the cpu is already in x2apic mode but the OS was not able to enable interrupt-remapping (which is a pre-req for using x2apic capability).
On these platforms all the apic-ids are < 255 and the kernel can fallback to xapic mode if the bios has not enabled interrupt-remapping (which is mostly the case if the bios has not exported interrupt-remapping tables to the OS).
--- arch/x86/include/asm/apic.h | 4 ++ arch/x86/include/asm/apicdef.h | 1 arch/x86/kernel/apic/apic.c | 73 ++++++++++++++++++++++++++++++----------- arch/x86/kernel/apic/io_apic.c | 4 ++ 4 files changed, 64 insertions(+), 18 deletions(-)
arch/x86/include/asm/apic.h +4 -0
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read }extern int x2apic_phys; +extern int x2apic_preenabled;extern void check_x2apic (void );extern void enable_x2apic (void );extern void x2apic_icr_write (u32 low,u32 id);
@@ -198,6 +199,9 @@ static inline void x2apic_force_phys(voi x2apic_phys = 1; }#else +static inline void disable_x2apic (void ) +{ +}static inline void check_x2apic (void ) { }
arch/x86/include/asm/apicdef.h +1 -0
@@ -144,6 +144,7 @@#define APIC_BASE (fix_to_virt(FIX_APIC_BASE))#define APIC_BASE_MSR 0x800 +#define XAPIC_ENABLE (1UL << 11)#define X2APIC_ENABLE (1UL << 10)#ifdef CONFIG_X86_32
arch/x86/kernel/apic/apic.c +55 -18
128 lines not on this page · raw message
arch/x86/kernel/apic/io_apic.c +4 -0
@@ -2948,6 +2948,10 @@ static inline void __init check_timer(vo }local_irq_disable ();apic_printk (APIC_QUIET ,KERN_INFO "..... failed :(.\n" ); +if (x2apic_preenabled) +apic_printk (APIC_QUIET ,KERN_INFO +"Perhaps problem with the pre-enabled x2apic mode\n" +"Try booting with x2apic and interrupt-remapping disabled in the bios.\n" );panic ("IO-APIC + timer doesn't work! Boot with apic=debug and send a " "report. Then try booting with the 'noapic' option.\n" ); out:
[tip:x86/apic] x86, x2apic: Fallback to xapic when BIOS doesn' t setup interrupt-remapping
Commit-ID: fb209bd891645bb87b9618b724f0b4928e0df3de Gitweb: http://git.kernel.org/tip/fb209bd891645bb87b9618b724f0b4928e0df3de Author: Yinghai Lu <[email protected]> AuthorDate: Wed, 21 Dec 2011 17:45:17 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Fri, 23 Dec 2011 11:01:01 -0800
x86, x2apic: Fallback to xapic when BIOS doesn't setup interrupt-remapping
On some of the recent Intel SNB platforms, by default bios is pre-enabling x2apic mode in the cpu with out setting up interrupt-remapping. This case was resulting in the kernel to panic as the cpu is already in x2apic mode but the OS was not able to enable interrupt-remapping (which is a pre-req for using x2apic capability).
On these platforms all the apic-ids are < 255 and the kernel can fallback to xapic mode if the bios has not enabled interrupt-remapping (which is mostly the case if the bios has not exported interrupt-remapping tables to the OS).
--- arch/x86/include/asm/apic.h | 4 ++ arch/x86/include/asm/apicdef.h | 1 + arch/x86/kernel/apic/apic.c | 73 ++++++++++++++++++++++++++++++---------- arch/x86/kernel/apic/io_apic.c | 4 ++ 4 files changed, 64 insertions(+), 18 deletions(-)
arch/x86/include/asm/apic.h +4 -0
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read(void) }extern int x2apic_phys; +extern int x2apic_preenabled;extern void check_x2apic (void );extern void enable_x2apic (void );extern void x2apic_icr_write (u32 low,u32 id);
@@ -198,6 +199,9 @@ static inline void x2apic_force_phys(void) x2apic_phys = 1; }#else +static inline void disable_x2apic (void ) +{ +}static inline void check_x2apic (void ) { }
arch/x86/include/asm/apicdef.h +1 -0
@@ -144,6 +144,7 @@#define APIC_BASE (fix_to_virt(FIX_APIC_BASE))#define APIC_BASE_MSR 0x800 +#define XAPIC_ENABLE (1UL << 11)#define X2APIC_ENABLE (1UL << 10)#ifdef CONFIG_X86_32
arch/x86/kernel/apic/apic.c +55 -18
128 lines not on this page · raw message
arch/x86/kernel/apic/io_apic.c +4 -0
@@ -2948,6 +2948,10 @@ static inline void __init check_timer(void) }local_irq_disable ();apic_printk (APIC_QUIET ,KERN_INFO "..... failed :(.\n" ); +if (x2apic_preenabled) +apic_printk (APIC_QUIET ,KERN_INFO +"Perhaps problem with the pre-enabled x2apic mode\n" +"Try booting with x2apic and interrupt-remapping disabled in the bios.\n" );panic ("IO-APIC + timer doesn't work! Boot with apic=debug and send a " "report. Then try booting with the 'noapic' option.\n" ); out:
PATCH 4/5 x86, x2apic: allow "nox2apic" to disable x2apic mode setup by bios
In reply to Suresh SiddhaFrom: Yinghai Lu <[email protected]>
Currently "nox2apic" boot parameter was not enabling x2apic mode if the cpu, kernel are all capable of enabling x2apic mode and the OS handover happened in xapic mode.
However If the bios enabled x2apic prior to OS handover, using "nox2apic" boot parameter had no effect.
If the boot cpu's apicid is < 255, enable "nox2apic" boot parameter to disable the x2apic mode setup by the bios. This will enable the kernel to fallback to xapic mode and bringup only the cpu's which has apic-id < 255.
--- arch/x86/include/asm/apic.h | 1 + arch/x86/kernel/apic/apic.c | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-)
arch/x86/kernel/apic/apic.c +28 -11
@@ -148,15 +148,24 @@ int x2apic_mode;/* x2apic enabled before OS handover */ int x2apic_preenabled;static int x2apic_disabled; +static int nox2apic;static __init int setup_nox2apic (char *str) {if (x2apic_enabled ()) { -pr_warning ("Bios already enabled x2apic, " -"can't enforce nox2apic" ); -return 0 ; - } +int apicid =native_apic_msr_read (APIC_ID ); + +if (apicid >=255 ) { +pr_warning ("Apicid: %08x, cannot enforce nox2apic\n" , + apicid); +return ; + } + +pr_warning ("x2apic already enabled. will disable it\n" ); + }else +setup_clear_cpu_cap (X86_FEATURE_X2APIC ); + + nox2apic =1 ; -setup_clear_cpu_cap (X86_FEATURE_X2APIC );return 0 ; }early_param ("nox2apic" , setup_nox2apic);
@@ -1453,12 +1462,17 @@ static void disable_x2apic(void)if (msr &X2APIC_ENABLE ) {u32 x2apic_id =read_apic_id (); -if (x2apic_id >255 ) -panic ("Can not disable x2apic, id: %08x\n" , x2apic_id); +if (x2apic_id >=255 ) +panic ("Cannot disable x2apic, id: %08x\n" , x2apic_id);pr_info ("Disabling x2apic\n" );__disable_x2apic (msr); +if (nox2apic) { +clear_cpu_cap (&cpu_data (0 ),X86_FEATURE_X2APIC ); +setup_clear_cpu_cap (X86_FEATURE_X2APIC ); + } + x2apic_disabled =1 ; x2apic_mode =0 ;
@@ -1533,13 +1547,16 @@ void __init enable_IR_x2apic(void) legacy_pic->mask_all ();mask_ioapic_entries (); +if (x2apic_preenabled && nox2apic) +disable_x2apic (); +if (dmar_table_init_ret) ret =-1 ;else ret =enable_IR ();if (!x2apic_supported ()) - goto nox2apic; + goto skip_x2apic;if (ret <0 ) {/* IR is required if there is APIC ID > 255 even when running
@@ -1549,7 +1566,7 @@ void __init enable_IR_x2apic(void) !hypervisor_x2apic_available()) {if (x2apic_preenabled)disable_x2apic (); - goto nox2apic; + goto skip_x2apic; }/* * without IR all CPUs can be addressed by IOAPIC/MSI
@@ -1560,7 +1577,7 @@ void __init enable_IR_x2apic(void)if (ret ==IRQ_REMAP_XAPIC_MODE ) {pr_info ("x2apic not enabled, IRQ remapping is in xapic mode\n" ); - goto nox2apic; + goto skip_x2apic; } x2apic_enabled =1 ;
@@ -1571,7 +1588,7 @@ void __init enable_IR_x2apic(void)pr_info ("Enabled x2apic\n" ); } -nox2apic: +skip_x2apic:if (ret <0 )/* IR enabling failed */ restore_ioapic_entries (); legacy_pic->restore_mask ();
arch/x86/include/asm/apic.h +1 -0
@@ -216,6 +216,7 @@ static inline void x2apic_force_phys(voi { } +#define nox2apic 0#define x2apic_preenabled 0#define x2apic_supported () 0#endif
Re: [patch 4/5] x86, x2apic: allow "nox2apic" to disable x2apic mode setup by bios
Review static void disable_x2apic(void) · line 1466
Quoted 8 lines · Suresh Siddha
(quoted diff) +2
-2@@ -1453,12 +1462,17 @@ static void disable_x2apic(void) if (msr & X2APIC_ENABLE) { u32 x2apic_id = read_apic_id(); - if (x2apic_id > 255) - panic("Can not disable x2apic, id: %08x\n", x2apic_id); + if (x2apic_id >= 255) + panic("Cannot disable x2apic, id: %08x\n", x2apic_id);
can not be applied cleanly.
update it a little bit.
need to use attached one to replace 4/5.
Thanks
Yinghai
Subject: [patch 4/5] x86, x2apic: allow "nox2apic" to disable x2apic mode setup by bios
From: Yinghai Lu <[email protected]>
Currently "nox2apic" boot parameter was not enabling x2apic mode if the cpu, kernel are all capable of enabling x2apic mode and the OS handover happened in xapic mode.
However If the bios enabled x2apic prior to OS handover, using "nox2apic" boot parameter had no effect.
If the boot cpu's apicid is < 255, enable "nox2apic" boot parameter to disable the x2apic mode setup by the bios. This will enable the kernel to fallback to xapic mode and bringup only the cpu's which has apic-id < 255.
-v2: fix patch error and two compiling warning
make disable_x2apic to be __init
--- arch/x86/include/asm/apic.h | 1 + arch/x86/kernel/apic/apic.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-)
arch/x86/kernel/apic/apic.c +27 -10
@@ -148,15 +148,24 @@ int x2apic_mode;/* x2apic enabled before OS handover */ int x2apic_preenabled;static int x2apic_disabled; +static int nox2apic;static __init int setup_nox2apic (char *str) {if (x2apic_enabled ()) { -pr_warning ("Bios already enabled x2apic, " -"can't enforce nox2apic" ); -return 0 ; - } +int apicid =native_apic_msr_read (APIC_ID ); + +if (apicid >=255 ) { +pr_warning ("Apicid: %08x, cannot enforce nox2apic\n" , + apicid); +return 0 ; + } + +pr_warning ("x2apic already enabled. will disable it\n" ); + }else +setup_clear_cpu_cap (X86_FEATURE_X2APIC ); + + nox2apic =1 ; -setup_clear_cpu_cap (X86_FEATURE_X2APIC );return 0 ; }early_param ("nox2apic" , setup_nox2apic);
@@ -1443,7 +1452,7 @@ static inline void __disable_x2apic(u64wrmsrl (MSR_IA32_APICBASE , msr & ~X2APIC_ENABLE ); } -static void disable_x2apic (void ) +static __init void disable_x2apic (void ) {u64 msr;
@@ -1460,6 +1469,11 @@ static void disable_x2apic(void)pr_info ("Disabling x2apic\n" );__disable_x2apic (msr); +if (nox2apic) { +clear_cpu_cap (&cpu_data (0 ),X86_FEATURE_X2APIC ); +setup_clear_cpu_cap (X86_FEATURE_X2APIC ); + } + x2apic_disabled =1 ; x2apic_mode =0 ;
@@ -1534,13 +1548,16 @@ void __init enable_IR_x2apic(void) legacy_pic->mask_all ();mask_ioapic_entries (); +if (x2apic_preenabled && nox2apic) +disable_x2apic (); +if (dmar_table_init_ret) ret =-1 ;else ret =enable_IR ();if (!x2apic_supported ()) - goto nox2apic; + goto skip_x2apic;if (ret <0 ) {/* IR is required if there is APIC ID > 255 even when running
@@ -1550,7 +1567,7 @@ void __init enable_IR_x2apic(void) !hypervisor_x2apic_available()) {if (x2apic_preenabled)disable_x2apic (); - goto nox2apic; + goto skip_x2apic; }/* * without IR all CPUs can be addressed by IOAPIC/MSI
@@ -1561,7 +1578,7 @@ void __init enable_IR_x2apic(void)if (ret ==IRQ_REMAP_XAPIC_MODE ) {pr_info ("x2apic not enabled, IRQ remapping is in xapic mode\n" ); - goto nox2apic; + goto skip_x2apic; } x2apic_enabled =1 ;
@@ -1572,7 +1589,7 @@ void __init enable_IR_x2apic(void)pr_info ("Enabled x2apic\n" ); } -nox2apic: +skip_x2apic:if (ret <0 )/* IR enabling failed */ restore_ioapic_entries (); legacy_pic->restore_mask ();
arch/x86/include/asm/apic.h +1 -0
@@ -216,6 +216,7 @@ static inline void x2apic_force_phys(voi { } +#define nox2apic 0#define x2apic_preenabled 0#define x2apic_supported () 0#endif
Re: [patch 4/5] x86, x2apic: allow "nox2apic" to disable x2apic mode setup by bios
Quoted 14 lines · Yinghai Lu
Review static void disable_x2apic(void) · line 1466
Quoted 8 lines · Suresh Siddha
(quoted diff) +2
-2@@ -1453,12 +1462,17 @@ static void disable_x2apic(void) if (msr & X2APIC_ENABLE) { u32 x2apic_id = read_apic_id(); - if (x2apic_id > 255) - panic("Can not disable x2apic, id: %08x\n", x2apic_id); + if (x2apic_id >= 255) + panic("Cannot disable x2apic, id: %08x\n", x2apic_id);can not be applied cleanly.
Quoted 4 lines
update it a little bit.
need to use attached one to replace 4/5.
Thanks Yinghai. updated patch look good.
Ingo, can you please queue this series to -tip?
thanks,
suresh
[tip:x86/apic] x86, x2apic: Allow "nox2apic" to disable x2apic mode setup by BIOS
In reply to Yinghai LuCommit-ID: a31bc32760992a2c68f3d6bf7da9f760c0fd7c41 Gitweb: http://git.kernel.org/tip/a31bc32760992a2c68f3d6bf7da9f760c0fd7c41 Author: Yinghai Lu <[email protected]> AuthorDate: Fri, 23 Dec 2011 11:01:43 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Fri, 23 Dec 2011 11:01:43 -0800
x86, x2apic: Allow "nox2apic" to disable x2apic mode setup by BIOS
Currently "nox2apic" boot parameter was not enabling x2apic mode if the cpu, kernel are all capable of enabling x2apic mode and the OS handover happened in xapic mode.
However If the bios enabled x2apic prior to OS handover, using "nox2apic" boot parameter had no effect.
If the boot cpu's apicid is < 255, enable "nox2apic" boot parameter to disable the x2apic mode setup by the bios. This will enable the kernel to fallback to xapic mode and bringup only the cpu's which has apic-id < 255.
-v2: fix patch error and two compiling warning
make disable_x2apic to be __init
--- arch/x86/include/asm/apic.h | 1 + arch/x86/kernel/apic/apic.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-)
arch/x86/include/asm/apic.h +1 -0
@@ -216,6 +216,7 @@ static inline void x2apic_force_phys(void) { } +#define nox2apic 0#define x2apic_preenabled 0#define x2apic_supported () 0#endif
arch/x86/kernel/apic/apic.c +27 -10
@@ -148,15 +148,24 @@ int x2apic_mode;/* x2apic enabled before OS handover */ int x2apic_preenabled;static int x2apic_disabled; +static int nox2apic;static __init int setup_nox2apic (char *str) {if (x2apic_enabled ()) { -pr_warning ("Bios already enabled x2apic, " -"can't enforce nox2apic" ); -return 0 ; - } +int apicid =native_apic_msr_read (APIC_ID ); + +if (apicid >=255 ) { +pr_warning ("Apicid: %08x, cannot enforce nox2apic\n" , + apicid); +return 0 ; + } + +pr_warning ("x2apic already enabled. will disable it\n" ); + }else +setup_clear_cpu_cap (X86_FEATURE_X2APIC ); + + nox2apic =1 ; -setup_clear_cpu_cap (X86_FEATURE_X2APIC );return 0 ; }early_param ("nox2apic" , setup_nox2apic);
@@ -1443,7 +1452,7 @@ static inline void __disable_x2apic(u64 msr)wrmsrl (MSR_IA32_APICBASE , msr & ~X2APIC_ENABLE ); } -static void disable_x2apic (void ) +static __init void disable_x2apic (void ) {u64 msr;
@@ -1460,6 +1469,11 @@ static void disable_x2apic(void)pr_info ("Disabling x2apic\n" );__disable_x2apic (msr); +if (nox2apic) { +clear_cpu_cap (&cpu_data (0 ),X86_FEATURE_X2APIC ); +setup_clear_cpu_cap (X86_FEATURE_X2APIC ); + } + x2apic_disabled =1 ; x2apic_mode =0 ;
@@ -1534,13 +1548,16 @@ void __init enable_IR_x2apic(void) legacy_pic->mask_all ();mask_ioapic_entries (); +if (x2apic_preenabled && nox2apic) +disable_x2apic (); +if (dmar_table_init_ret) ret =-1 ;else ret =enable_IR ();if (!x2apic_supported ()) - goto nox2apic; + goto skip_x2apic;if (ret <0 ) {/* IR is required if there is APIC ID > 255 even when running
@@ -1550,7 +1567,7 @@ void __init enable_IR_x2apic(void) !hypervisor_x2apic_available()) {if (x2apic_preenabled)disable_x2apic (); - goto nox2apic; + goto skip_x2apic; }/* * without IR all CPUs can be addressed by IOAPIC/MSI
@@ -1561,7 +1578,7 @@ void __init enable_IR_x2apic(void)if (ret ==IRQ_REMAP_XAPIC_MODE ) {pr_info ("x2apic not enabled, IRQ remapping is in xapic mode\n" ); - goto nox2apic; + goto skip_x2apic; } x2apic_enabled =1 ;
@@ -1572,7 +1589,7 @@ void __init enable_IR_x2apic(void)pr_info ("Enabled x2apic\n" ); } -nox2apic: +skip_x2apic:if (ret <0 )/* IR enabling failed */ restore_ioapic_entries (); legacy_pic->restore_mask ();
PATCH 5/5 x86: skip cpus with apic-ids >= 255 in !x2apic_mode
In reply to Suresh SiddhaFrom: Suresh Siddha <[email protected]>
If the x2apic mode is disabled for reasons like interrupt-remapping not available etc, then we need to skip the logical cpu bringup of apic-id's >= 255. Otherwise as the platform is in xapic mode, init/startup IPI's will consider only the low 8-bits and there is a possibility of re-sending init/startup IPI's to the logical cpu that is already online.
This will avoid potential reboots/unpredictable behavior etc.
--- arch/x86/kernel/smpboot.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/smpboot.c +2 -1
@@ -840,7 +840,8 @@ int __cpuinit native_cpu_up(unsigned intpr_debug ("++++++++++++++++++++=_---CPU UP %u\n" , cpu);if (apicid ==BAD_APICID || apicid == boot_cpu_physical_apicid || - !physid_isset (apicid, phys_cpu_present_map)) { + !physid_isset (apicid, phys_cpu_present_map) || + (!x2apic_mode && apicid >=255 )) {printk (KERN_ERR "%s: bad cpu %d\n" , __func__, cpu);return -EINVAL ; }
[tip:x86/apic] x86: Skip cpus with apic-ids >= 255 in !x2apic_mode
Commit-ID: c284b42abadbb22083bfde24d308899c08d44ffa Gitweb: http://git.kernel.org/tip/c284b42abadbb22083bfde24d308899c08d44ffa Author: Suresh Siddha <[email protected]> AuthorDate: Wed, 21 Dec 2011 17:45:19 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Fri, 23 Dec 2011 11:01:49 -0800
x86: Skip cpus with apic-ids >= 255 in !x2apic_mode
If the x2apic mode is disabled for reasons like interrupt-remapping not available etc, then we need to skip the logical cpu bringup of apic-id's >= 255. Otherwise as the platform is in xapic mode, init/startup IPI's will consider only the low 8-bits and there is a possibility of re-sending init/startup IPI's to the logical cpu that is already online.
This will avoid potential reboots/unpredictable behavior etc.
--- arch/x86/kernel/smpboot.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kernel/smpboot.c +2 -1
@@ -840,7 +840,8 @@ int __cpuinit native_cpu_up(unsigned int cpu)pr_debug ("++++++++++++++++++++=_---CPU UP %u\n" , cpu);if (apicid ==BAD_APICID || apicid == boot_cpu_physical_apicid || - !physid_isset (apicid, phys_cpu_present_map)) { + !physid_isset (apicid, phys_cpu_present_map) || + (!x2apic_mode && apicid >=255 )) {printk (KERN_ERR "%s: bad cpu %d\n" , __func__, cpu);return -EINVAL ; }