hw: fix regression of smp kernel initialization

In commit "hw: improve cross-cpu synchronization" the implicit safe
initialization of the global kernel lock gets unsafe.
It is a static object, which is protected by the cxx library regarding
its initialization. But our cxx library uses a Genode::semaphore in
the contention case of object construction, which implicitly leads
to kernel syscalls for blocking the corresponding thread. This behaviour
is unacceptable for the kernel code.
Therefore, this fix guards the initialization of the kernel code with
a simple static boolean value explicitely.

Ref #3042
Ref #3043
This commit is contained in:
Stefan Kalkowski 2019-02-19 15:18:02 +01:00 committed by Christian Helmuth
parent 1ff36965f4
commit 2cf4e5a6de

View File

@ -43,12 +43,24 @@ extern "C" void kernel_init();
*/
extern "C" void kernel_init()
{
static volatile bool lock_ready = false;
static volatile bool pool_ready = false;
static volatile bool kernel_ready = false;
/**
* It is essential to guard the initialization of the data_lock object
* in the SMP case, because otherwise the __cxa_guard_aquire of the cxx
* library contention path might get called, which ends up in
* calling a Semaphore, which will call Kernel::stop_thread() or
* Kernel::yield() system-calls in this code
*/
while (Cpu::executing_id() != Cpu::primary_id() && !lock_ready) { ; }
{
Lock::Guard guard(data_lock());
lock_ready = true;
/* initialize current cpu */
pool_ready = cpu_pool().initialize(pic());
};