Skip to content

C6/H2: flip-link feature #1008

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

Merged
merged 4 commits into from
Dec 11, 2023
Merged

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented Dec 8, 2023

Since on C6/H2 the caches are not residing in the start of RAM we can move the stack to start of RAM to get zero-cost stack overflow protection (inspired by flip-link)

I will probably add some code in esp-backtrace to give a hint when there is an access fault slightly below _stack_end to make things a bit more obvious.

Currently a stack overflow with the flip-link feature looks like this

Exception 'Store/AMO access fault' mepc=0x4080c0ca, mtval=0x407ffee0

An access fault trying to access memory near the start of RAM indicates a stack overflow

This needs a lot of testing before it's fine to merge.

Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

This is awesome! Really cool that we can achieve this without double linking too, neat!

I have a few comments, mostly around docs just because linker scripts are insanely hard to reason about, so the more docs and info on what they're doing and why the better.

"ld/riscv/hal-defaults.x",
out.join("hal-defaults.x"),
)?;
preprocess_file(&config_symbols, "ld/riscv/asserts.x", out.join("asserts.x"))?;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think these two files need preprocessing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I just thought applying it everywhere is easier than having some files pre-processed and some not 🤔 but not sure what is better

@MabezDev
Copy link
Member

MabezDev commented Dec 8, 2023

I also wonder if we can improve the error message, if we are in the trap handler and we know SP is out of bounds, we can reason that a stack overflow was detected 🤔.

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Dec 8, 2023

I also wonder if we can improve the error message, if we are in the trap handler and we know SP is out of bounds, we can reason that a stack overflow was detected 🤔.

We might re-use e.g. exception code 14 to signal that - probably worth a try. Then esp-backtrace could give a definitive hint that it was a stack overflow. Need to try if that would work

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Dec 8, 2023

That works! Now we get Exception 'Reserved' mepc=0x420138c0, mtval=0x407ffffc but we can give a better hint now in esp-backtrace

Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

LGTM, I've only tested a few examples so far, I will test some more soon.

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Dec 8, 2023

In the meantime, I tested with esp-wifi .... looks good so far

@bjoernQ bjoernQ force-pushed the esp32c6-esp32h2-flip-link-alike branch from 0d97101 to 71a9f9a Compare December 11, 2023 11:39
Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

Thanks for exploring this, it's a really cool feature to have!

LGTM

@bjoernQ bjoernQ added this pull request to the merge queue Dec 11, 2023
Merged via the queue into esp-rs:main with commit c1912fc Dec 11, 2023
@bjoernQ bjoernQ deleted the esp32c6-esp32h2-flip-link-alike branch December 11, 2023 12:45
@jessebraham
Copy link
Member

Can we please try to remember to update the CI workflow when new features are added, especially when linker scripts are involved.

@bjoernQ
Copy link
Contributor Author

bjoernQ commented Dec 11, 2023

Can we please try to remember to update the CI workflow when new features are added, especially when linker scripts are involved.

Ah true ...

Studiedlist pushed a commit to Studiedlist/esp-hal that referenced this pull request Dec 11, 2023
* C6/H2: flip-link feature

* CHANGELOG.md entry

* Include .wifiextrairam in .rwtext.wifi

* Set exception code 14 if SP was out of bounds
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