Raul Rangel has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/59021 )
Change subject: arch/x86/smp/spinlock: Fix threading when !STAGE_HAS_SPINLOCKS ......................................................................
arch/x86/smp/spinlock: Fix threading when !STAGE_HAS_SPINLOCKS
Cooperative multitasking has previously only been used in ramstage. When running threads in romstage it was observed that two threads could be trying to write to the serial console. This doesn't happen in ramstage because when holding a spin lock, threading gets disabled. We need to do the same thing in romstage. We don't actually need spin locks in romstage, but we still need to disable multitasking.
One alternative is adding a thread_mutex everywhere a spinlock is defined, but that seems excessive.
BUG=b:179699789 TEST=Boot guybrush to OS and verify printk is not intermingled in romstage.
Signed-off-by: Raul E Rangel rrangel@chromium.org Change-Id: Iea621fcdad8f0367acce4f70be42a4e9a68da938 --- M src/arch/x86/include/arch/smp/spinlock.h 1 file changed, 10 insertions(+), 16 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/21/59021/1
diff --git a/src/arch/x86/include/arch/smp/spinlock.h b/src/arch/x86/include/arch/smp/spinlock.h index 19e9129..6ba92dd 100644 --- a/src/arch/x86/include/arch/smp/spinlock.h +++ b/src/arch/x86/include/arch/smp/spinlock.h @@ -17,8 +17,6 @@
#define STAGE_HAS_SPINLOCKS !ENV_ROMSTAGE_OR_BEFORE
-#if STAGE_HAS_SPINLOCKS - #define DECLARE_SPIN_LOCK(x) \ static spinlock_t x = SPIN_LOCK_UNLOCKED;
@@ -42,9 +40,11 @@
static __always_inline void spin_lock(spinlock_t *lock) { - __asm__ __volatile__( - spin_lock_string - : "=m" (lock->lock) : : "memory"); + if (STAGE_HAS_SPINLOCKS) { + __asm__ __volatile__( + spin_lock_string + : "=m" (lock->lock) : : "memory"); + }
/* Switching contexts while holding a spinlock will lead to deadlocks */ thread_coop_disable(); @@ -55,17 +55,11 @@ { thread_coop_enable();
- __asm__ __volatile__( - spin_unlock_string - : "=m" (lock->lock) : : "memory"); + if (STAGE_HAS_SPINLOCKS) { + __asm__ __volatile__( + spin_unlock_string + : "=m" (lock->lock) : : "memory"); + } }
-#else - -#define DECLARE_SPIN_LOCK(x) -#define spin_lock(lock) do {} while (0) -#define spin_unlock(lock) do {} while (0) - -#endif - #endif /* ARCH_SMP_SPINLOCK_H */