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

Make sure stack frames are 16-byte-aligned #597

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

peterfang
Copy link
Contributor

The x86-64 ABI requires 16b-aligned stack frames. Stack misalignment can sometimes lead to hard-to-debug segfaults because x86-64 code that follows the calling convention can assume that stack frames are 16b-aligned. This patch series makes sure this requirement is respected at various transition points in SVSM.

The x86-64 ABI requires 16b-aligned stack frames. Make sure the initial
stack frame is 16b-aligned when entering stage2_main(). Make
stage2_main() a diverging function since one shall never attempt to
return from it.

Signed-off-by: Peter Fang <[email protected]>
startup_64 is now stripped-down enough that we no longer need %r8/%r9 as
intermediary registers between stage2 and svsm_start(). Use %rdi and
%rsi directly in stage2 and pass them straight to svsm_start().

Signed-off-by: Peter Fang <[email protected]>
The x86-64 ABI requires 16b-aligned stack frames. Make sure the initial
stack frame is 16b-aligned when entering svsm_start(). Make svsm_start()
a diverging function since one shall never attempt to return from it.

Signed-off-by: Peter Fang <[email protected]>
Add align_down() in addition to align_up() to the Address trait, and use
the generic align_{up,down}() and is_aligned() calls to reduce code
duplication.

Signed-off-by: Peter Fang <[email protected]>
The x86-64 ABI requires 16b-aligned stack frames. Make sure
VMKernelStack::top_of_stack() always returns a 16b-aligned address,
regardless of the base address.

Signed-off-by: Peter Fang <[email protected]>
The x86-64 ABI requires 16b-aligned stack frames. Make sure AP's initial
stack frame is 16b-aligned when transferring control to the Rust startup
function. Make start_ap() a diverging function since one shall never
attempt to return from it.

Signed-off-by: Peter Fang <[email protected]>
The x86-64 ABI requires 16b-aligned stack frames. Make sure every
kernel/user task has a 16b-aligned kernel stack frame when control is
transferred to its function entry point. Make sure user stack frames are
always 16b-aligned as well.

No functional change intended. The intent of this commit is to make
clear that stack alignment is enforced and actively checked in debug
builds.

Signed-off-by: Peter Fang <[email protected]>
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.

1 participant