Skip to content

Commit fb209bd

Browse files
Yinghai LuH. Peter Anvin
authored andcommitted
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). Reported-by: Berck E. Nash <flyboy@gmail.com> Signed-off-by: Yinghai Lu <yinghai@kernel.org> Link: http://lkml.kernel.org/r/20111222014632.600418637@sbsiddha-desk.sc.intel.com Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent a35fd28 commit fb209bd

4 files changed

Lines changed: 64 additions & 18 deletions

File tree

‎arch/x86/include/asm/apic.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static inline u64 native_x2apic_icr_read(void)
176176
}
177177

178178
extern int x2apic_phys;
179+
extern int x2apic_preenabled;
179180
extern void check_x2apic(void);
180181
extern void enable_x2apic(void);
181182
extern void x2apic_icr_write(u32 low, u32 id);
@@ -198,6 +199,9 @@ static inline void x2apic_force_phys(void)
198199
x2apic_phys = 1;
199200
}
200201
#else
202+
static inline void disable_x2apic(void)
203+
{
204+
}
201205
static inline void check_x2apic(void)
202206
{
203207
}

‎arch/x86/include/asm/apicdef.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144

145145
#define APIC_BASE (fix_to_virt(FIX_APIC_BASE))
146146
#define APIC_BASE_MSR 0x800
147+
#define XAPIC_ENABLE (1UL << 11)
147148
#define X2APIC_ENABLE (1UL << 10)
148149

149150
#ifdef CONFIG_X86_32

‎arch/x86/kernel/apic/apic.c‎

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ __setup("apicpmtimer", setup_apicpmtimer);
146146
int x2apic_mode;
147147
#ifdef CONFIG_X86_X2APIC
148148
/* x2apic enabled before OS handover */
149-
static int x2apic_preenabled;
149+
int x2apic_preenabled;
150+
static int x2apic_disabled;
150151
static __init int setup_nox2apic(char *str)
151152
{
152153
if (x2apic_enabled()) {
@@ -1432,6 +1433,40 @@ void __init bsp_end_local_APIC_setup(void)
14321433
}
14331434

14341435
#ifdef CONFIG_X86_X2APIC
1436+
/*
1437+
* Need to disable xapic and x2apic at the same time and then enable xapic mode
1438+
*/
1439+
static inline void __disable_x2apic(u64 msr)
1440+
{
1441+
wrmsrl(MSR_IA32_APICBASE,
1442+
msr & ~(X2APIC_ENABLE | XAPIC_ENABLE));
1443+
wrmsrl(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE);
1444+
}
1445+
1446+
static void disable_x2apic(void)
1447+
{
1448+
u64 msr;
1449+
1450+
if (!cpu_has_x2apic)
1451+
return;
1452+
1453+
rdmsrl(MSR_IA32_APICBASE, msr);
1454+
if (msr & X2APIC_ENABLE) {
1455+
u32 x2apic_id = read_apic_id();
1456+
1457+
if (x2apic_id >= 255)
1458+
panic("Cannot disable x2apic, id: %08x\n", x2apic_id);
1459+
1460+
pr_info("Disabling x2apic\n");
1461+
__disable_x2apic(msr);
1462+
1463+
x2apic_disabled = 1;
1464+
x2apic_mode = 0;
1465+
1466+
register_lapic_address(mp_lapic_addr);
1467+
}
1468+
}
1469+
14351470
void check_x2apic(void)
14361471
{
14371472
if (x2apic_enabled()) {
@@ -1442,15 +1477,20 @@ void check_x2apic(void)
14421477

14431478
void enable_x2apic(void)
14441479
{
1445-
int msr, msr2;
1480+
u64 msr;
1481+
1482+
rdmsrl(MSR_IA32_APICBASE, msr);
1483+
if (x2apic_disabled) {
1484+
__disable_x2apic(msr);
1485+
return;
1486+
}
14461487

14471488
if (!x2apic_mode)
14481489
return;
14491490

1450-
rdmsr(MSR_IA32_APICBASE, msr, msr2);
14511491
if (!(msr & X2APIC_ENABLE)) {
14521492
printk_once(KERN_INFO "Enabling x2apic\n");
1453-
wrmsr(MSR_IA32_APICBASE, msr | X2APIC_ENABLE, msr2);
1493+
wrmsrl(MSR_IA32_APICBASE, msr | X2APIC_ENABLE);
14541494
}
14551495
}
14561496
#endif /* CONFIG_X86_X2APIC */
@@ -1487,7 +1527,7 @@ void __init enable_IR_x2apic(void)
14871527
ret = save_ioapic_entries();
14881528
if (ret) {
14891529
pr_info("Saving IO-APIC state failed: %d\n", ret);
1490-
goto out;
1530+
return;
14911531
}
14921532

14931533
local_irq_save(flags);
@@ -1499,22 +1539,30 @@ void __init enable_IR_x2apic(void)
14991539
else
15001540
ret = enable_IR();
15011541

1542+
if (!x2apic_supported())
1543+
goto nox2apic;
1544+
15021545
if (ret < 0) {
15031546
/* IR is required if there is APIC ID > 255 even when running
15041547
* under KVM
15051548
*/
15061549
if (max_physical_apicid > 255 ||
1507-
!hypervisor_x2apic_available())
1550+
!hypervisor_x2apic_available()) {
1551+
if (x2apic_preenabled)
1552+
disable_x2apic();
15081553
goto nox2apic;
1554+
}
15091555
/*
15101556
* without IR all CPUs can be addressed by IOAPIC/MSI
15111557
* only in physical mode
15121558
*/
15131559
x2apic_force_phys();
15141560
}
15151561

1516-
if (ret == IRQ_REMAP_XAPIC_MODE)
1562+
if (ret == IRQ_REMAP_XAPIC_MODE) {
1563+
pr_info("x2apic not enabled, IRQ remapping is in xapic mode\n");
15171564
goto nox2apic;
1565+
}
15181566

15191567
x2apic_enabled = 1;
15201568

@@ -1529,17 +1577,6 @@ void __init enable_IR_x2apic(void)
15291577
restore_ioapic_entries();
15301578
legacy_pic->restore_mask();
15311579
local_irq_restore(flags);
1532-
1533-
out:
1534-
if (x2apic_enabled || !x2apic_supported())
1535-
return;
1536-
1537-
if (x2apic_preenabled)
1538-
panic("x2apic: enabled by BIOS but kernel init failed.");
1539-
else if (ret == IRQ_REMAP_XAPIC_MODE)
1540-
pr_info("x2apic not enabled, IRQ remapping is in xapic mode\n");
1541-
else if (ret < 0)
1542-
pr_info("x2apic not enabled, IRQ remapping init failed\n");
15431580
}
15441581

15451582
#ifdef CONFIG_X86_64

‎arch/x86/kernel/apic/io_apic.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,10 @@ static inline void __init check_timer(void)
29482948
}
29492949
local_irq_disable();
29502950
apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
2951+
if (x2apic_preenabled)
2952+
apic_printk(APIC_QUIET, KERN_INFO
2953+
"Perhaps problem with the pre-enabled x2apic mode\n"
2954+
"Try booting with x2apic and interrupt-remapping disabled in the bios.\n");
29512955
panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
29522956
"report. Then try booting with the 'noapic' option.\n");
29532957
out:

0 commit comments

Comments
 (0)