Fix possible deadlock on SMP stop_this_cpu
Do not use printk on the running thread after it has been sent the INIT IPI, execution may halt with console spinlock held. Change-Id: I64608935ea740fb827fa0307442f3fb102de7a08 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: http://review.coreboot.org/776 Reviewed-by: Ronald G. Minnich <rminnich@gmail.com> Tested-by: build bot (Jenkins) Reviewed-by: Rudolf Marek <r.marek@assembler.cz>
This commit is contained in:
parent
8b28d50cdd
commit
a01ae624af
|
@ -277,6 +277,19 @@ int start_cpu(device_t cpu)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_AP_IN_SIPI_WAIT == 1
|
#if CONFIG_AP_IN_SIPI_WAIT == 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sending INIT IPI to self is equivalent of asserting #INIT with a bit of delay.
|
||||||
|
* An undefined number of instruction cycles will complete. All global locks
|
||||||
|
* must be released before INIT IPI and no printk is allowed after this.
|
||||||
|
* De-asserting INIT IPI is a no-op on later Intel CPUs.
|
||||||
|
*
|
||||||
|
* If you set DEBUG_HALT_SELF to 1, printk's after INIT IPI are enabled
|
||||||
|
* but running thread may halt without releasing the lock and effectively
|
||||||
|
* deadlock other CPUs.
|
||||||
|
*/
|
||||||
|
#define DEBUG_HALT_SELF 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normally this function is defined in lapic.h as an always inline function
|
* Normally this function is defined in lapic.h as an always inline function
|
||||||
* that just keeps the CPU in a hlt() loop. This does not work on all CPUs.
|
* that just keeps the CPU in a hlt() loop. This does not work on all CPUs.
|
||||||
|
@ -298,38 +311,46 @@ void stop_this_cpu(void)
|
||||||
lapic_write_around(LAPIC_ICR, LAPIC_INT_LEVELTRIG | LAPIC_INT_ASSERT | LAPIC_DM_INIT);
|
lapic_write_around(LAPIC_ICR, LAPIC_INT_LEVELTRIG | LAPIC_INT_ASSERT | LAPIC_DM_INIT);
|
||||||
|
|
||||||
/* wait for the ipi send to finish */
|
/* wait for the ipi send to finish */
|
||||||
#if 0
|
#if DEBUG_HALT_SELF
|
||||||
// When these two printk(BIOS_SPEW, ...) calls are not removed, the
|
|
||||||
// machine will hang when log level is SPEW. Why?
|
|
||||||
printk(BIOS_SPEW, "Waiting for send to finish...\n");
|
printk(BIOS_SPEW, "Waiting for send to finish...\n");
|
||||||
#endif
|
#endif
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
do {
|
do {
|
||||||
#if 0
|
#if DEBUG_HALT_SELF
|
||||||
printk(BIOS_SPEW, "+");
|
printk(BIOS_SPEW, "+");
|
||||||
#endif
|
#endif
|
||||||
udelay(100);
|
udelay(100);
|
||||||
send_status = lapic_read(LAPIC_ICR) & LAPIC_ICR_BUSY;
|
send_status = lapic_read(LAPIC_ICR) & LAPIC_ICR_BUSY;
|
||||||
} while (send_status && (timeout++ < 1000));
|
} while (send_status && (timeout++ < 1000));
|
||||||
if (timeout >= 1000) {
|
if (timeout >= 1000) {
|
||||||
|
#if DEBUG_HALT_SELF
|
||||||
printk(BIOS_ERR, "timed out\n");
|
printk(BIOS_ERR, "timed out\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
mdelay(10);
|
mdelay(10);
|
||||||
|
|
||||||
|
#if DEBUG_HALT_SELF
|
||||||
printk(BIOS_SPEW, "Deasserting INIT.\n");
|
printk(BIOS_SPEW, "Deasserting INIT.\n");
|
||||||
|
#endif
|
||||||
/* Deassert the LAPIC INIT */
|
/* Deassert the LAPIC INIT */
|
||||||
lapic_write_around(LAPIC_ICR2, SET_LAPIC_DEST_FIELD(id));
|
lapic_write_around(LAPIC_ICR2, SET_LAPIC_DEST_FIELD(id));
|
||||||
lapic_write_around(LAPIC_ICR, LAPIC_INT_LEVELTRIG | LAPIC_DM_INIT);
|
lapic_write_around(LAPIC_ICR, LAPIC_INT_LEVELTRIG | LAPIC_DM_INIT);
|
||||||
|
|
||||||
|
#if DEBUG_HALT_SELF
|
||||||
printk(BIOS_SPEW, "Waiting for send to finish...\n");
|
printk(BIOS_SPEW, "Waiting for send to finish...\n");
|
||||||
|
#endif
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
do {
|
do {
|
||||||
|
#if DEBUG_HALT_SELF
|
||||||
printk(BIOS_SPEW, "+");
|
printk(BIOS_SPEW, "+");
|
||||||
|
#endif
|
||||||
udelay(100);
|
udelay(100);
|
||||||
send_status = lapic_read(LAPIC_ICR) & LAPIC_ICR_BUSY;
|
send_status = lapic_read(LAPIC_ICR) & LAPIC_ICR_BUSY;
|
||||||
} while (send_status && (timeout++ < 1000));
|
} while (send_status && (timeout++ < 1000));
|
||||||
if (timeout >= 1000) {
|
if (timeout >= 1000) {
|
||||||
|
#if DEBUG_HALT_SELF
|
||||||
printk(BIOS_ERR, "timed out\n");
|
printk(BIOS_ERR, "timed out\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
Loading…
Reference in New Issue