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

ia32/exceptions: fix FPU exceptions #624

Merged
merged 7 commits into from
Nov 29, 2024
Merged

ia32/exceptions: fix FPU exceptions #624

merged 7 commits into from
Nov 29, 2024

Conversation

badochov
Copy link
Contributor

@badochov badochov commented Nov 18, 2024

Description

This PR aims to resolve situation with exceptions caused by FPU on Intel.

First commit resolves issue where recently instead of a triple fault on FPU error exception 16 got presented on the screen, due to wrong instruction setting flag.

Second, commit fixes saving context in exceptions.

Third commit changes fsave in context saving procedure to fnsave to prevent infinite recursion on FPU exception causing a triple fault. Due to this change exception 16 is reported correctly as exception 16 not as tripple fault. Thus, exception 16 is excepted to appear not Triple fault.

Fourth, commit fixes the root cause of the intermittent error. The cr0Bits were overwritten by eax during context restoration. We may restore twice from the same context in case of a signal pushed during _threads_schedule. Then we restore once from the context to go to the signal handler, after the signal is handled the context is modified to have original eip and esp and we longjump to it resulting in second restoration from the context with overwritten cr0Bits. This resulted in TS flag being removed without proper FPU initialization on next restore.

The following commits are optimizations.

Fixes: phoenix-rtos/phoenix-rtos-project#1012

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: ia32-generic-qemu

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@badochov badochov marked this pull request as ready for review November 18, 2024 14:37
@badochov badochov requested a review from agkaminski November 18, 2024 14:37
Copy link

github-actions bot commented Nov 18, 2024

Unit Test Results

7 958 tests   7 416 ✅  40m 32s ⏱️
  470 suites    542 💤
    1 files        0 ❌

Results for commit 887e356.

♻️ This comment has been updated with latest results.

@badochov badochov removed the request for review from agkaminski November 18, 2024 15:03
@badochov badochov marked this pull request as draft November 18, 2024 15:03
@badochov badochov changed the title ia32/exceptions: fix FPU exceptions ia32/exceptions: improve FPU exceptions Nov 18, 2024
@badochov badochov requested a review from agkaminski November 18, 2024 16:23
@badochov badochov marked this pull request as ready for review November 18, 2024 16:25
@badochov badochov force-pushed the badochov/exc-int branch 2 times, most recently from 709b931 to 1967f0f Compare November 18, 2024 17:29
jnz .exception_pushRegisters should have flags from andl not subl
instruction.

JIRA: RTOS-954
savesp saved in exception_pushContext pointed to savesp instead of edi.

JIRA: RTOS-954
Checking for FPU exception in preambule of exception handling causes
infinite recursion of FPU exceptions if one is found.

JIRA: RTOS-954
@badochov badochov changed the title ia32/exceptions: improve FPU exceptions ia32/exceptions: fix FPU exceptions Nov 27, 2024
cr0Bits were overwriteen by eax in the context during restoration. This resulted in a crash on second context restoration.

JIRA: RTOS-954
As we use interirupt gate for exceptions the interrupts are already
disabled.

JIRA: RTOS-954
Apply same optimizations as to exceptions_pushContext

JIRA: RTOS-954
Copy link
Member

@mateusz-bloch mateusz-bloch left a comment

Choose a reason for hiding this comment

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

Tested the changes with the latest master of the project, and everything seems to be ok.

@badochov badochov merged commit 07519a2 into master Nov 29, 2024
36 checks passed
@badochov badochov deleted the badochov/exc-int branch November 29, 2024 11:03
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.

ia32-generic-qemu: intermittent system reboots during fork() and exit
3 participants