lib: sbi: Simplify wait_for_coldboot() implementation
authorAnup Patel <apatel@ventanamicro.com>
Fri, 15 Mar 2024 14:25:23 +0000 (19:55 +0530)
committerAnup Patel <anup@brainfault.org>
Fri, 5 Apr 2024 12:18:23 +0000 (17:48 +0530)
commitbeb0cd177f10a6bdafd73aac19059fecf6a07a91
treeb54f4bd17bd293cb3e27c62ffdf3338571758937
parentf5375bc15e9f3e577dfc24f9095a3e37246a3fa3
lib: sbi: Simplify wait_for_coldboot() implementation

On QEMU virt machine with large number of HARTs, some of the HARTs
randomly fail to come out of wait_for_coldboot() due to one of the
following race-conditions:

1) Failing HARTs are not able to acquire the coldboot_lock and
   update the coldboot_hartmask in wait_for_coldboot() before
   the coldboot HART acquires the coldboot_lock and sends IPI
   in wake_coldboot_harts() hence the failing HARTs never
   receive IPI from the coldboot HART.

2) Failing HARTs acquire the coldbood_lock and update the
   coldboot_hartmask before coldboot HART does sbi_scratch_init()
   so the sbi_hartmask_set_hartid() does not update the
   coldboot_hartmask on the failing HARTs hence they never
   receive IPI from the coldboot HART.

To address this, use a simple busy-loop in wait_for_coldboot() for
polling on coldboot_done flag.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
include/sbi/riscv_barrier.h
lib/sbi/sbi_init.c