Skip to content

Commit

Permalink
Supposed fix for some SandyBridge mobile CPUs hang on AP startup when
Browse files Browse the repository at this point in the history
x2APIC mode is detected and enabled.  Current theory is that switching
the APIC mode while an IPI is in flight might be the issue.

Postpone switching to x2APIC mode until we are guaranteed that all
starting IPIs are already send and aknowledged.  Use aps_ready signal
as an indication that the BSP is done with us.

Tested by:	adrian
Sponsored by:	The FreeBSD Foundation
MFC after:	2 months
  • Loading branch information
kostikbel committed Feb 28, 2015
1 parent 359d7df commit 5918450
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions sys/amd64/amd64/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,19 +705,21 @@ init_secondary(void)
wrmsr(MSR_STAR, msr);
wrmsr(MSR_SF_MASK, PSL_NT|PSL_T|PSL_I|PSL_C|PSL_D);

/*
* On real hardware, switch to x2apic mode if possible.
* Disable local APIC until BSP directed APs to run.
*/
lapic_xapic_mode();

/* signal our startup to the BSP. */
mp_naps++;

/* Spin until the BSP releases the AP's. */
while (!aps_ready)
ia32_pause();

/*
* On real hardware, switch to x2apic mode if possible. Do it
* after aps_ready was signalled, to avoid manipulating the
* mode while BSP might still want to send some IPI to us
* (second startup IPI is ignored on modern hardware etc).
*/
lapic_xapic_mode();

/* Initialize the PAT MSR. */
pmap_init_pat();

Expand Down
14 changes: 8 additions & 6 deletions sys/i386/i386/mp_machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,6 @@ init_secondary(void)
load_cr0(cr0);
CHECK_WRITE(0x38, 5);

/*
* On real hardware, switch to x2apic mode if possible.
* Disable local APIC until BSP directed APs to run.
*/
lapic_xapic_mode();

/* signal our startup to the BSP. */
mp_naps++;
CHECK_WRITE(0x39, 6);
Expand All @@ -742,6 +736,14 @@ init_secondary(void)
lidt(&r_idt);
#endif

/*
* On real hardware, switch to x2apic mode if possible. Do it
* after aps_ready was signalled, to avoid manipulating the
* mode while BSP might still want to send some IPI to us
* (second startup IPI is ignored on modern hardware etc).
*/
lapic_xapic_mode();

/* Initialize the PAT MSR if present. */
pmap_init_pat();

Expand Down

0 comments on commit 5918450

Please sign in to comment.