Skip to content

Commit a31bc32

Browse files
Yinghai LuH. Peter Anvin
authored andcommitted
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 Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com> Link: http://lkml.kernel.org/r/CAE9FiQUeB-3uxJAMiHsz=uPWoFv5Hg1pVepz7aU6YtqOxMC-=Q@mail.gmail.com Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent fb209bd commit a31bc32

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ static inline void x2apic_force_phys(void)
216216
{
217217
}
218218

219+
#define nox2apic 0
219220
#define x2apic_preenabled 0
220221
#define x2apic_supported() 0
221222
#endif

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,24 @@ int x2apic_mode;
148148
/* x2apic enabled before OS handover */
149149
int x2apic_preenabled;
150150
static int x2apic_disabled;
151+
static int nox2apic;
151152
static __init int setup_nox2apic(char *str)
152153
{
153154
if (x2apic_enabled()) {
154-
pr_warning("Bios already enabled x2apic, "
155-
"can't enforce nox2apic");
156-
return 0;
157-
}
155+
int apicid = native_apic_msr_read(APIC_ID);
156+
157+
if (apicid >= 255) {
158+
pr_warning("Apicid: %08x, cannot enforce nox2apic\n",
159+
apicid);
160+
return 0;
161+
}
162+
163+
pr_warning("x2apic already enabled. will disable it\n");
164+
} else
165+
setup_clear_cpu_cap(X86_FEATURE_X2APIC);
166+
167+
nox2apic = 1;
158168

159-
setup_clear_cpu_cap(X86_FEATURE_X2APIC);
160169
return 0;
161170
}
162171
early_param("nox2apic", setup_nox2apic);
@@ -1443,7 +1452,7 @@ static inline void __disable_x2apic(u64 msr)
14431452
wrmsrl(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE);
14441453
}
14451454

1446-
static void disable_x2apic(void)
1455+
static __init void disable_x2apic(void)
14471456
{
14481457
u64 msr;
14491458

@@ -1460,6 +1469,11 @@ static void disable_x2apic(void)
14601469
pr_info("Disabling x2apic\n");
14611470
__disable_x2apic(msr);
14621471

1472+
if (nox2apic) {
1473+
clear_cpu_cap(&cpu_data(0), X86_FEATURE_X2APIC);
1474+
setup_clear_cpu_cap(X86_FEATURE_X2APIC);
1475+
}
1476+
14631477
x2apic_disabled = 1;
14641478
x2apic_mode = 0;
14651479

@@ -1534,13 +1548,16 @@ void __init enable_IR_x2apic(void)
15341548
legacy_pic->mask_all();
15351549
mask_ioapic_entries();
15361550

1551+
if (x2apic_preenabled && nox2apic)
1552+
disable_x2apic();
1553+
15371554
if (dmar_table_init_ret)
15381555
ret = -1;
15391556
else
15401557
ret = enable_IR();
15411558

15421559
if (!x2apic_supported())
1543-
goto nox2apic;
1560+
goto skip_x2apic;
15441561

15451562
if (ret < 0) {
15461563
/* IR is required if there is APIC ID > 255 even when running
@@ -1550,7 +1567,7 @@ void __init enable_IR_x2apic(void)
15501567
!hypervisor_x2apic_available()) {
15511568
if (x2apic_preenabled)
15521569
disable_x2apic();
1553-
goto nox2apic;
1570+
goto skip_x2apic;
15541571
}
15551572
/*
15561573
* without IR all CPUs can be addressed by IOAPIC/MSI
@@ -1561,7 +1578,7 @@ void __init enable_IR_x2apic(void)
15611578

15621579
if (ret == IRQ_REMAP_XAPIC_MODE) {
15631580
pr_info("x2apic not enabled, IRQ remapping is in xapic mode\n");
1564-
goto nox2apic;
1581+
goto skip_x2apic;
15651582
}
15661583

15671584
x2apic_enabled = 1;
@@ -1572,7 +1589,7 @@ void __init enable_IR_x2apic(void)
15721589
pr_info("Enabled x2apic\n");
15731590
}
15741591

1575-
nox2apic:
1592+
skip_x2apic:
15761593
if (ret < 0) /* IR enabling failed */
15771594
restore_ioapic_entries();
15781595
legacy_pic->restore_mask();

0 commit comments

Comments
 (0)