[PATCH] cpukit/smp: Prevent premature thread dispatch

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Sep 17 05:39:10 UTC 2021


On 16/09/2021 22:50, Kinsey Moore wrote:
> There is currently a narrow window between the CPU state being set to UP
> and the dispatch disable flag being set. It is possible to perform a
> cross-processor thread dispatch in this window which catches the CPU in
> a state which is not actually fully ready for that type of thread
> dispatch.
> 
> This moves the CPU state change to just before the CPU's first thread
> dispatch and later than the dispatch disable flag change which closes
> the window for the race condition.
> ---
>   cpukit/score/src/threadstartmultitasking.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/cpukit/score/src/threadstartmultitasking.c b/cpukit/score/src/threadstartmultitasking.c
> index 094a535394..0c0951a243 100644
> --- a/cpukit/score/src/threadstartmultitasking.c
> +++ b/cpukit/score/src/threadstartmultitasking.c
> @@ -29,8 +29,6 @@ void _Thread_Start_multitasking( void )
>     Thread_Control  *heir;
>   
>   #if defined(RTEMS_SMP)
> -  _Per_CPU_State_change( cpu_self, PER_CPU_STATE_UP );
> -
>     /*
>      * Threads begin execution in the _Thread_Handler() function.   This
>      * function will set the thread dispatch disable level to zero.
> @@ -44,6 +42,8 @@ void _Thread_Start_multitasking( void )
>   
>   #if defined(RTEMS_SMP)
>     _CPU_SMP_Prepare_start_multitasking();
> +
> +  _Per_CPU_State_change( cpu_self, PER_CPU_STATE_UP );
>   #endif
>   
>   #if defined(_CPU_Start_multitasking)
> 

For which branch is this patch? The code on the master is different.

Which scenario caused a problem here? I guess there is a second bug 
involved, since maskable interrupt should be disabled for this code 
path. How could there be a race condition?

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber at embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the devel mailing list