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

arch/arm/arm64: Fix stxr's used in spinlocks register size #907

Closed

Conversation

mogasergiu
Copy link
Member

@mogasergiu mogasergiu commented May 25, 2023

Our spinlocks have a size of 4-bytes and an alignment of 8, which, in our semaphore implementation, causes a padding of 4 bytes. This is fine, but it is an inconsistency.

With QEMU direct kernel boot, all of our free memory is zeroed out. However, when using a previous boot phase such as UEFI, this inconsistency shows itself through an always locked spinlock. UEFI firmware "poisons" all of its free memory with 0xaf bytes which leads to our stxr, whose second register argument is 64-bit instead of 32-bit, also atomically storing the poisoned padding.

Thus, make sure that our stxr uses 32-bit register for the to be transferred register.

GitHub-Fixes: #289

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.pl on your commit series before opening this PR;
  • Updated relevant documentation.

Base target

  • Architecture(s): arm64
  • Platform(s): kvm
  • Application(s): N/A

Additional configuration

Description of changes

Our `spinlock`s have a size of 4-bytes and an alignment of 8, which,
in our `semaphore` implementation, causes a padding of 4 bytes. This
is fine, but it is an inconsistency.

With `QEMU` direct kernel boot, all of our free memory is zeroed out.
However, when using a previous boot phase such as `UEFI`, this
inconsistency shows itself through an always locked `spinlock`.
`UEFI` firmware "poisons" all of its free memory with `0xaf` bytes
which leads to our `stxr`, whose second register argument is 64-bit
instead of 32-bit, also atomically storing the `poisoned` padding.

Thus, make sure that our `stxr` uses 32-bit register for the to be
transferred register.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
GitHub-Fixes: unikraft#289
@mogasergiu mogasergiu requested a review from a team as a code owner May 25, 2023 12:05
@razvand razvand requested review from eduardvintila and mariasfiraiala and removed request for a team May 31, 2023 04:46
@razvand razvand added area/arch Unikraft Architecture lang/c Issues or PRs to do with C/C++ arch/arm64 kind/quick-fix Issue is a quick fix labels May 31, 2023
@razvand razvand added this to the v0.14.0 (Prometheus) milestone May 31, 2023
mogasergiu added a commit to mogasergiu/unikraft that referenced this pull request Jun 22, 2023
Copy link
Contributor

@mariasfiraiala mariasfiraiala left a comment

Choose a reason for hiding this comment

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

This looks good, thanks @mogasergiu!

Reviewed-by: Maria Sfiraiala maria.sfiraiala@gmail.com

@michpappas
Copy link
Member

@eduardvintila please let me know if you're planning to have a look at this PR, otherwise I'm ready to merge.

Copy link
Member

@eduardvintila eduardvintila left a comment

Choose a reason for hiding this comment

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

All good. Nice catch, @mogasergiu!
Reviewed-by: Eduard Vintilă eduard.vintila47@gmail.com

@michpappas
Copy link
Member

Approved-by: Michalis Pappas michalis@unikraft.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch/arm64 area/arch Unikraft Architecture ci/merged Merged by CI kind/quick-fix Issue is a quick fix lang/c Issues or PRs to do with C/C++
Projects
Status: Done!
Development

Successfully merging this pull request may close these issues.

None yet

6 participants