Skip to content
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

lib: os: mpsc_pbuf: do not use sem when spinlock is held #83355

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

Conversation

ycsin
Copy link
Member

@ycsin ycsin commented Dec 24, 2024

Logging in spinlock context when the log buffer is full can lead to taking the branch that attempts to wait for a sem, this causes a context switch which isn't allowed when a spinlock is held. Which may trigger an 'ASSERTION FAILED' message
(when CONFIG_SPIN_VALIDATE=y) which is again, routed through the logging subsystem (when CONFIG_LOG=y), and since the log buffer was already full, this just goes on and on and on forever.

To prevent that, check if the current spinlock key can be used to unlock IRQ, if it doesn't, it means that a lock is already held outside the function.

  • should add a test to validate

Logging in spinlock context when the log buffer is full can lead
to taking the branch that attempts to wait for a sem, this causes
a context switch which isn't allowed when a spinlock is held. Which
may trigger an 'ASSERTION FAILED' message
(when `CONFIG_SPIN_VALIDATE=y`) which is again, routed through the
logging subsystem (when `CONFIG_LOG=y`), and since the log buffer
was already full, this just goes on and on and on forever.

To prevent that, check if the current spinlock key can be used to
unlock IRQ, if it doesn't, it means that a lock is already held outside
the function.

Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Maxim Adelman <[email protected]>
@ycsin ycsin requested a review from luchnikov December 24, 2024 09:42
@ycsin ycsin added bug The issue is a bug, or the PR is fixing a bug backport v3.7-branch Request backport to the v3.7-branch backport v4.0-branch Backport to the v4.0-branch area: Logging labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Logging backport v3.7-branch Request backport to the v3.7-branch backport v4.0-branch Backport to the v4.0-branch bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

log/mpsc_pbuf: logging in spinlock held context can cause recurring exception
1 participant