Fixed exception level for new threads #232
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a tiny change, but it fixes a huge bug.
To understand it, please have a look at the ending of
kern_exc_leave
:If the assumption mentioned in comment is not met, that is: EXL bit of the status register stored in saved context is not set, then between the
mtc0
instruction anderet
an interrupt may arrive. This is unacceptable, because it would overwrite the just-restored context (in particular, it overwrites EPC address with the address of themove
instruction, resulting in a endless loop over the last three instructions). That seems unlikely to happen, so here's a proof:b3925e8, OVPsimp:
test=all seed=823261445 repeat=5
EDIT: You can also see the problem in this build for #234.
Now typically the stored SR has EXL set, because usually we store the SR value in
kern_exc_enter
. But when a new context is prepared inctx_init
, the contents of SR are based on current SR state - so naturally it is likely the EXL bit is 0.The reason we've not observed this issue until now is because this problem may only occur on the very first
ctx_switch -> kern_exc_leave
for a new thread, and it requires the interrupt to come at a very precise moment - which happens very rarely. So it only goes to show how much have our testing procedures improved that we are able to catch such an obscure problem.This fix ensures SR EXL bit is set for all fresh contexts.