Skip to content

Commit

Permalink
x86/apic: Make x2apic_disable() work correctly
Browse files Browse the repository at this point in the history
x2apic_disable() clears x2apic_state and x2apic_mode unconditionally, even
when the state is X2APIC_ON_LOCKED, which prevents the kernel to disable
it thereby creating inconsistent state.

Due to the early state check for X2APIC_ON, the code path which warns about
a locked X2APIC cannot be reached.

Test for state < X2APIC_ON instead and move the clearing of the state and
mode variables to the place which actually disables X2APIC.

[ tglx: Massaged change log. Added Fixes tag. Moved clearing so it's at the
  	right place for back ports ]

Fixes: a57e456 ("x86/apic: Fix fallout from x2apic cleanup")
Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20240813014827.895381-1-yuntao.wang@linux.dev
  • Loading branch information
Yuntao Wang authored and Thomas Gleixner committed Aug 13, 2024
1 parent 7c626ce commit 0ecc5be
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions arch/x86/kernel/apic/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1775,12 +1775,9 @@ static __init void apic_set_fixmap(bool read_apic);

static __init void x2apic_disable(void)
{
u32 x2apic_id, state = x2apic_state;
u32 x2apic_id;

x2apic_mode = 0;
x2apic_state = X2APIC_DISABLED;

if (state != X2APIC_ON)
if (x2apic_state < X2APIC_ON)
return;

x2apic_id = read_apic_id();
Expand All @@ -1793,6 +1790,10 @@ static __init void x2apic_disable(void)
}

__x2apic_disable();

x2apic_mode = 0;
x2apic_state = X2APIC_DISABLED;

/*
* Don't reread the APIC ID as it was already done from
* check_x2apic() and the APIC driver still is a x2APIC variant,
Expand Down

0 comments on commit 0ecc5be

Please sign in to comment.