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

jit: make sure RSP is 16 byte aligned when we call into rust code #515

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

alessandrod
Copy link

This aligns $rsp in emit_rust_call() so that if the rust code uses SIMD instructions that require alignment we don't crash

@codecov-commenter
Copy link

Codecov Report

Merging #515 (ccfd894) into main (e7aaea2) will increase coverage by 0.06%.
The diff coverage is 80.00%.

❗ Current head ccfd894 differs from pull request most recent head 147f5f1. Consider uploading reports for the commit 147f5f1 to get more accurate results

@@            Coverage Diff             @@
##             main     #515      +/-   ##
==========================================
+ Coverage   89.63%   89.70%   +0.06%     
==========================================
  Files          23       23              
  Lines       10301    10311      +10     
==========================================
+ Hits         9233     9249      +16     
+ Misses       1068     1062       -6     
Files Changed Coverage Δ
src/jit.rs 92.18% <80.00%> (-0.18%) ⬇️

... and 1 file with indirect coverage changes

The System V ABI requires $rsp to be 16 bytes aligned. Internally we
don't emit any instructions that require alignment but when we call out
to rustc generated code we must align.
@Lichtso
Copy link

Lichtso commented Sep 15, 2023

I would like to emit an assertion before each rust call to find the offending call sites first and then investigate further. Working on another PR for that.

@alessandrod
Copy link
Author

I would like to emit an assertion before each rust call to find the offending call sites first and then investigate further. Working on another PR for that.

I'm working on unit tests for this, so please leave it to me 😊 But the answer is "all the call sites".

We don't try to maintain alignment anywhere. Before doing this patch I actually started changing that, but it seemed like too big a change for a backport. Also since we don't have an explicit stack allocator but we manipulate the stack as we go, it seems like it would be fragile.

@Lichtso
Copy link

Lichtso commented Sep 16, 2023

We don't try to maintain alignment anywhere.

That is not true, while we do lack explicit tests, I have implemented stack padding in various places to reach 16 byte alignment. Some are marked as such in comments, e.g.

rbpf/src/jit.rs

Line 1407 in e7aaea2

self.emit_ins(X86Instruction::push_immediate(OperandSize::S64, -1)); // Used as PC value in error case, acts as stack padding otherwise

@Lichtso Lichtso changed the base branch from main to v0.6 September 19, 2023 14:37
@Lichtso Lichtso merged commit f5d87ad into solana-labs:v0.6 Sep 19, 2023
1 check passed
@ryleung-solana
Copy link

Does this fix need to be merged into main as well?

@Lichtso
Copy link

Lichtso commented Sep 22, 2023

Yes, but we are working on a more detailed analysis of the places which cause misalignment first.

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.

4 participants