You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I described several locking and concurrency problems of HAL_ETH in issue #72#71#70 and #69. This is another one related to the improper or missing locking via gState and HAL_ETH_STATE_BUSY.
If HAL_ETH_ReleaseTxPacket() gets preempted and another call to itself in another threads get scheduled (the functions is racing with itself), then the PTP timestamps stored in heth->TxTimestamp may be overwritten with those of another packet before the application callback HAL_ETH_TxPtpCallback() or heth->txPtpCallback() in the original call to HAL_ETH_ReleaseTxPacket() gets executed.
This would cause the application code to read the overwritten PTP timestamp and not the timestamp of the packet it actually sent.
This problem could be solved by either locking properly and atomically via gState or by not storing the timestamp in heth->TxTimestamp but in a stack variable in HAL_ETH_ReleaseTxPacket() and handing that stack pointer to the application which would be unique per thread.
The text was updated successfully, but these errors were encountered:
ALABSTM
added
bug
Something isn't working
hal
HAL-LL driver-related issue or pull-request.
eth
Ethernet-related issue or pull-request
labels
Sep 9, 2024
Thank you for your report. The HAL library is often used in contexts where the end user manages the synchronization of calls to HAL functions. If your application operates in a multi-threaded environment, we recommend using external synchronization mechanisms, such as mutexes or semaphores, to protect calls to HAL_ETH_ReleaseTxPacket().
I described several locking and concurrency problems of HAL_ETH in issue #72 #71 #70 and #69. This is another one related to the improper or missing locking via
gState
andHAL_ETH_STATE_BUSY
.If
HAL_ETH_ReleaseTxPacket()
gets preempted and another call to itself in another threads get scheduled (the functions is racing with itself), then the PTP timestamps stored inheth->TxTimestamp
may be overwritten with those of another packet before the application callbackHAL_ETH_TxPtpCallback()
orheth->txPtpCallback()
in the original call toHAL_ETH_ReleaseTxPacket()
gets executed.https://github.com/STMicroelectronics/stm32h7xx_hal_driver/blob/ceda3ceeca2ee77a76d2de2ee6b560ad87c90a48/Src/stm32h7xx_hal_eth.c#L1437-L1467
This would cause the application code to read the overwritten PTP timestamp and not the timestamp of the packet it actually sent.
This problem could be solved by either locking properly and atomically via gState or by not storing the timestamp in
heth->TxTimestamp
but in a stack variable inHAL_ETH_ReleaseTxPacket()
and handing that stack pointer to the application which would be unique per thread.The text was updated successfully, but these errors were encountered: