From 7aea15aa6b59c96a6d4c0c847352dd1c45145c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Fri, 15 Oct 2021 17:14:20 +0300 Subject: [PATCH] cpu/x86/lapic: Fix choice X2APIC_ONLY MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When sending self an IPI, some instructions may be processed before IPI is serviced. Spend some time doing nothing, to avoid entering a printk() and acquiring console_lock and dead-locking. Change-Id: I78070ae91e78c11c3e3aa225e5673d4667d6f7bb Signed-off-by: Kyösti Mälkki Reviewed-on: https://review.coreboot.org/c/coreboot/+/60213 Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons Reviewed-by: Arthur Heymans --- src/include/cpu/x86/lapic.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/include/cpu/x86/lapic.h b/src/include/cpu/x86/lapic.h index c1603f21f0..e131d2ec46 100644 --- a/src/include/cpu/x86/lapic.h +++ b/src/include/cpu/x86/lapic.h @@ -145,8 +145,16 @@ static __always_inline unsigned int lapicid(void) static __always_inline void lapic_send_ipi_self(uint32_t icrlow) { + int i = 1000; + /* LAPIC_DEST_SELF does not support all delivery mode -fields. */ lapic_send_ipi(icrlow, lapicid()); + + /* In case of X2APIC force a short delay, to prevent deadlock in a case + * the immediately following code acquires some lock, like with printk(). + */ + while (CONFIG(X2APIC_ONLY) && i--) + cpu_relax(); } static __always_inline void lapic_send_ipi_others(uint32_t icrlow)