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

riscv_syscall.S: Fix a massive bug in syscall dispatch logic #314

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

pussuw
Copy link

@pussuw pussuw commented Nov 12, 2024

There is an enormous error in the system call dispatch logic; if a task is inside a critical section (local interrupts disabled) there is a chance that during a context switch when the task resumes, local interrupts are erroneously ENABLED. This obviously leads to unexpected crashes and such.

This happens when the CPU status has Previous Interrupt Enable (PIE) set to 1, even though Interrupt Enable (IE) is set to 0.

When the system call returns via ERET, the CPU sets PIE->IE and if PIE=1 interrupts get enabled.

This is fixed easily by explicitly CLEARING PIE from the register save area, if IE=0 when the system call was started.

Backport from upstream

There is an enormous error in the system call dispatch logic; if a task
is inside a critical section (local interrupts disabled) there is a chance
that during a context switch when the task resumes, local interrupts are
erroneously ENABLED. This obviously leads to unexpected crashes and such.

This happens when the CPU status has Previous Interrupt Enable (PIE) set
to 1, even though Interrupt Enable (IE) is set to 0.

When the system call returns via ERET, the CPU sets PIE->IE and if PIE=1
interrupts get enabled.

This is fixed easily by explicitly CLEARING PIE from the register save
area, if IE=0 when the system call was started.
@pussuw pussuw requested review from jlaitine and eenurkka November 12, 2024 08:17
Copy link

@eenurkka eenurkka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@pussuw pussuw merged commit 7a149ae into master Nov 12, 2024
11 checks passed
@pussuw pussuw deleted the rv_syscall_fix branch November 12, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants