Merge branch 'fix/freertos_delete_with_caps_smp_race_v5.3' into 'release/v5.3'

fix(freertos): close vTaskDeleteWithCaps cross-core delete race on SMP preview kernel (v5.3)

See merge request espressif/esp-idf!48603
This commit is contained in:
Jiang Jiang Jian
2026-06-29 15:16:11 +08:00
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -94,13 +94,35 @@ err:
* So we suspend the task before deleting it. */ * So we suspend the task before deleting it. */
vTaskSuspend( xTaskToDelete ); vTaskSuspend( xTaskToDelete );
/* Wait for the task to be suspended */ /* Wait until the task is no longer the current task on any core.
while( eRunning == eTaskGetState( xTaskToDelete ) ) *
* Polling on pxCurrentTCBs[] (via xTaskGetCurrentTaskHandleForCore())
* matches the predicate vTaskDelete() uses to choose between immediate
* and IDLE-deferred TCB cleanup. By waiting on it here, we guarantee
* that the vTaskDelete() call below takes the immediate path and that
* prvDeleteTCB() runs synchronously before vTaskDelete() returns, so
* the heap_caps_free() / vPortFree() that follow cannot race with the
* IDLE task. */
for( ;; )
{ {
taskYIELD(); BaseType_t xStillOnCore = pdFALSE;
for( BaseType_t xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ )
{
if( xTaskGetCurrentTaskHandleForCore( xCoreID ) == xTaskToDelete )
{
xStillOnCore = pdTRUE;
break;
}
} }
configASSERT( eRunning != eTaskGetState( xTaskToDelete ) ); if( xStillOnCore == pdFALSE )
{
break;
}
taskYIELD();
}
/* We can delete the task and free the memory buffers. /* We can delete the task and free the memory buffers.
* First, we must call `vTaskDelete` so that the port task delete callback is called. * First, we must call `vTaskDelete` so that the port task delete callback is called.