[patch 10/23] x86/x2apic: Disable x2apic from nox2apic setup
From: Thomas Gleixner
Date: Thu Jan 15 2015 - 16:26:58 EST
There is no point in postponing the hardware disablement of x2apic. It
can be disabled right away in the nox2apic setup function.
Disable it right away and set the state to DISABLED . This allows to
remove all the nox2apic conditionals all over the place.
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
arch/x86/include/asm/apic.h | 1
arch/x86/kernel/apic/apic.c | 59 +++++++++++++++++---------------------------
2 files changed, 24 insertions(+), 36 deletions(-)
Index: tip/arch/x86/include/asm/apic.h
===================================================================
--- tip.orig/arch/x86/include/asm/apic.h
+++ tip/arch/x86/include/asm/apic.h
@@ -185,7 +185,6 @@ static inline int x2apic_enabled(void)
#define x2apic_supported() (cpu_has_x2apic)
#else
-static inline void disable_x2apic(void) { }
static inline void enable_x2apic(void) { }
static inline int x2apic_enabled(void) { return 0; }
Index: tip/arch/x86/kernel/apic/apic.c
===================================================================
--- tip.orig/arch/x86/kernel/apic/apic.c
+++ tip/arch/x86/kernel/apic/apic.c
@@ -1474,12 +1474,8 @@ void __init bsp_end_local_APIC_setup(voi
}
-/* Control whether x2APIC mode is enabled or not */
-static bool nox2apic __initdata;
-
#ifdef CONFIG_X86_X2APIC
int x2apic_mode;
-static int x2apic_disabled;
enum {
X2APIC_OFF,
@@ -1488,6 +1484,19 @@ enum {
};
static int x2apic_state;
+static inline void disable_x2apic(void)
+{
+ u64 msr;
+
+ rdmsrl(MSR_IA32_APICBASE, msr);
+ if (!(msr & X2APIC_ENABLE))
+ return;
+ /* Disable xapic and x2apic first and then reenable xapic mode */
+ wrmsrl(MSR_IA32_APICBASE, msr & ~(X2APIC_ENABLE | XAPIC_ENABLE));
+ wrmsrl(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE);
+ printk_once(KERN_INFO "x2apic disabled\n");
+}
+
static int __init setup_nox2apic(char *str)
{
if (x2apic_enabled()) {
@@ -1498,28 +1507,17 @@ static int __init setup_nox2apic(char *s
apicid);
return 0;
}
-
- pr_warning("x2apic already enabled. will disable it\n");
- } else
- setup_clear_cpu_cap(X86_FEATURE_X2APIC);
-
- nox2apic = true;
+ pr_warning("x2apic already enabled.\n");
+ disable_x2apic();
+ }
+ setup_clear_cpu_cap(X86_FEATURE_X2APIC);
x2apic_state = X2APIC_DISABLED;
+ x2apic_mode = 0;
return 0;
}
early_param("nox2apic", setup_nox2apic);
-/*
- * Need to disable xapic and x2apic at the same time and then enable xapic mode
- */
-static inline void __disable_x2apic(u64 msr)
-{
- wrmsrl(MSR_IA32_APICBASE,
- msr & ~(X2APIC_ENABLE | XAPIC_ENABLE));
- wrmsrl(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE);
-}
-
-static __init void disable_x2apic(void)
+static __init void x2apic_disable(void)
{
u64 msr;
@@ -1533,20 +1531,13 @@ static __init void disable_x2apic(void)
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);
- }
+ disable_x2apic();
x2apic_mode = 0;
register_lapic_address(mp_lapic_addr);
}
- x2apic_disabled = 1;
x2apic_state = X2APIC_DISABLED;
}
@@ -1554,9 +1545,8 @@ void enable_x2apic(void)
{
u64 msr;
- rdmsrl(MSR_IA32_APICBASE, msr);
- if (x2apic_disabled) {
- __disable_x2apic(msr);
+ if (x2apic_state == X2APIC_DISABLED) {
+ disable_x2apic();
x2apic_mode = 0;
return;
}
@@ -1564,6 +1554,7 @@ void enable_x2apic(void)
if (!x2apic_mode)
return;
+ rdmsrl(MSR_IA32_APICBASE, msr);
if (!(msr & X2APIC_ENABLE)) {
printk_once(KERN_INFO "Enabling x2apic\n");
wrmsrl(MSR_IA32_APICBASE, msr | X2APIC_ENABLE);
@@ -1584,7 +1575,7 @@ static __init void try_to_enable_x2apic(
(IS_ENABLED(CONFIG_HYPERVISOR_GUEST) &&
!hypervisor_x2apic_available())) {
pr_info("x2apic: IRQ remapping doesn't support X2APIC mode\n");
- disable_x2apic();
+ x2apic_disable();
return;
}
@@ -1656,8 +1647,6 @@ void __init enable_IR_x2apic(void)
legacy_pic->mask_all();
mask_ioapic_entries();
- if (nox2apic)
- disable_x2apic();
/* If irq_remapping_prepare() succeded, try to enable it */
if (ir_stat >= 0)
ir_stat = try_to_enable_IR();
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/