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

userlib: remove panics in kipc implementation #1937

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

cbiffle
Copy link
Collaborator

@cbiffle cbiffle commented Nov 25, 2024

The kipc stubs tend to assert on the rc value received from the kernel. This isn't ideal: we generally have to trust the kernel, and we can't do anything useful if it misbehaves. So the assert is merely costing a bunch of flash for a condition that can never happen. This removes these asserts.

The system_restart kipc needs to indicate a "noreturn" send, but of course we have no way of doing that right now. So, it panicked if the send returned. This created another can't-happen panic site in flash. I've replaced it with an infinite loop that compiles to a two-byte branch instruction, and in practice will never even be reached (but the compiler doesn't know that).

This further reduces text and stack size in El Jefe.

The kipc stubs tend to assert on the rc value received from the kernel.
This isn't ideal: we generally have to trust the kernel, and we can't do
anything useful if it misbehaves. So the assert is merely costing a
bunch of flash for a condition that can never happen. This removes these
asserts.

The system_restart kipc needs to indicate a "noreturn" send, but of
course we have no way of doing that right now. So, it panicked if the
send returned. This created _another_ can't-happen panic site in flash.
I've replaced it with an infinite loop that compiles to a two-byte
branch instruction, and in practice will never even be reached (but the
compiler doesn't know that).

This further reduces text and stack size in El Jefe.
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

The rationale for removing these assertions makes sense to me, thanks for documenting it!

Out of curiosity: can Jefe stack size allocations reasonably be disembiggened in any of our app.tomls now?

sys/userlib/src/kipc.rs Outdated Show resolved Hide resolved
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

whoops, forgot to click "approve"!

Co-authored-by: Eliza Weisman <eliza@elizas.website>
@cbiffle cbiffle enabled auto-merge (squash) November 26, 2024 19:10
@cbiffle
Copy link
Collaborator Author

cbiffle commented Nov 26, 2024

Out of curiosity: can Jefe stack size allocations reasonably be disembiggened in any of our app.tomls now?

@hawkw probably, but the process of finding them and right-sizing them is unpleasant and I'm currently not up for it.

@cbiffle cbiffle merged commit 740fd43 into master Nov 26, 2024
125 checks passed
@cbiffle cbiffle deleted the cbiffle/kipc-panic-reduction branch November 26, 2024 19:16
@hawkw
Copy link
Member

hawkw commented Nov 26, 2024

Out of curiosity: can Jefe stack size allocations reasonably be disembiggened in any of our app.tomls now?

@hawkw probably, but the process of finding them and right-sizing them is unpleasant and I'm currently not up for it.

That's entirely reasonable; I wasn't going to say you had to do it now, or anything. And, I think it can be justified by saying that, in the absence of better automated processes for estimating max stack depths, giving the supervisor a bigger stack margin is probably more useful unless we are actively trying to scrounge up a few more bytes of RAM for some specific purpose, which we're not at present!

cbiffle added a commit that referenced this pull request Nov 26, 2024
The supervisor task in Hubris is not permitted to panic, since it's
responsible for handling panics.

Jefe has historically contained a bunch of (static) panics, many of
which aren't actually possible at runtime. I've been gradually grinding
away at these in my other PRs.

As of #1937, it's now possible to build a _minimal_ Jefe (like we use on
the G0) that contains no panics. So I've enabled that on donglet, and
turned on the userlib/no-panic feature that will statically ensure it
remains true.

Turning on dump support in Jefe causes a bunch of panics to reappear,
because humpty is panic-heavy. That's a task for another day.
@cbiffle
Copy link
Collaborator Author

cbiffle commented Nov 26, 2024

@hawkw if you like getting stack back, you're going to love my next PR. ;-)

cbiffle added a commit that referenced this pull request Nov 26, 2024
The supervisor task in Hubris is not permitted to panic, since it's
responsible for handling panics.

Jefe has historically contained a bunch of (static) panics, many of
which aren't actually possible at runtime. I've been gradually grinding
away at these in my other PRs.

As of #1937, it's now possible to build a _minimal_ Jefe (like we use on
the G0) that contains no panics. So I've enabled that on donglet, and
turned on the userlib/no-panic feature that will statically ensure it
remains true.

Turning on dump support in Jefe causes a bunch of panics to reappear,
because humpty is panic-heavy. That's a task for another day.

In addition to eliminating all panic sites, this also eliminates the
last indirect function calls from the generated binaries -- meaning, the
static stack size estimate is very likely exact. So I have taken the
opportunity to shrink the stack by a bit, reclaiming 256 bytes of RAM on
this RAM-starved part.
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.

2 participants