Skip to content

drivers: NXP ENET: fix for issue mutex called from ISR #89443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

duerrfk
Copy link

@duerrfk duerrfk commented May 4, 2025

Fixes #89442

The NXP ENET driver uses a mutex inside an ISR.

Function ts_register_tx_event() (source file zephyr/drivers/ethernet/eth_nxp_enet.c) is invoked from the ISR when a TX packet timestamp is available. Before the timestamp is copied to the packet, a mutex is locked, most likely to protect the timestamp from concurrent read/write operations. Since mutexes are not allowed in ISR, the following assertion is triggered (when compiled with assertions):

ASSERTION FAIL [!arch_is_in_isr()] @ WEST_TOPDIR/zephyr/kernel/mutex.c:111

        mutexes cannot be used inside ISRs

The problem can be fixed by simply removing the calls to the mutex in ts_register_tx_event() since the timestamp is also protected from concurrent read operations using a semaphore (ptp_ts_sem), which is only released after copying the timestamp to the packet. This semaphore ptp_ts_sem ensures sequential execution of writing the timestamp in ts_register_tx_event() (inside the ISR) and subsequently reading the timestamp after waiting for the semaphore ptp_ts_sem in eth_wait_for_ptp_ts().

Copy link

github-actions bot commented May 4, 2025

Hello @duerrfk, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@decsny
Copy link
Member

decsny commented May 5, 2025

please fix compliance failures

The NXP ENET driver used a mutex inside an ISR.
Since mutexes are not allowed in ISR, an assertion had been triggered.
The mutex is not required since a semaphore ensures sequential writing
(in ISR) and subsequent reading (after eth_wait_for_ptp_ts()).
Fixed by removing calls to mutex.

Signed-off-by: Frank Duerr <frank.duerr@ipvs.uni-stuttgart.de>
@duerrfk duerrfk force-pushed the issue_mutex_in_isr branch from 0251d87 to 8b3b77e Compare May 6, 2025 06:39
@duerrfk
Copy link
Author

duerrfk commented May 6, 2025

Sorry for not checking for compliance! Compliance check passes now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Ethernet platform: NXP Drivers NXP Semiconductors, drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NXP ENET driver: mutex used in ISR
5 participants