Skip to content

Conversation

adamperlin
Copy link
Contributor

@adamperlin adamperlin commented Aug 22, 2025

This PR fixes #735. The approach used here is to write the formatted panic message in chunks to the host via outb to avoid buffering on the host.

@adamperlin adamperlin force-pushed the adamperlin/panic-remove-allocations branch from c83158f to 93e8563 Compare August 22, 2025 21:18
@jprendes jprendes added the kind/bugfix For PRs that fix bugs label Aug 22, 2025
@danbugs danbugs requested a review from Copilot August 22, 2025 21:39
Copilot

This comment was marked as outdated.

@adamperlin adamperlin force-pushed the adamperlin/panic-remove-allocations branch 3 times, most recently from 1b0113c to 576df92 Compare August 26, 2025 05:45
@adamperlin adamperlin force-pushed the adamperlin/panic-remove-allocations branch from 2f25176 to d786619 Compare August 27, 2025 20:23
@adamperlin
Copy link
Contributor Author

adamperlin commented Aug 28, 2025

Just a note here, this is currently blocked on fuzzing failures due to the memory leak described in #826; currently attempting to use snapshotting in the host call fuzzer to restore back to a clean memory state on each fuzzing iteration, which I will open a separate PR for.

adamperlin and others added 9 commits August 28, 2025 15:07
Signed-off-by: adamperlin <adamp@nanosoft.com>
using a new FixedStringBuf type backed by a static mut array.
Adds a test to verify that StackOverflow no longer occurs on OOM panic

Signed-off-by: adamperlin <adamp@nanosoft.com>
Add some docstrings

Signed-off-by: adamperlin <adamp@nanosoft.com>
Signed-off-by: adamperlin <adamp@nanosoft.com>
Signed-off-by: adamperlin <adamp@nanosoft.com>
Signed-off-by: adamperlin <adamp@nanosoft.com>
…n panic handler to avoid any possible recursive panic

Signed-off-by: adamperlin <adamp@nanosoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adam Perlin <adamp@nanosoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adam Perlin <adamp@nanosoft.com>
@adamperlin adamperlin force-pushed the adamperlin/panic-remove-allocations branch 2 times, most recently from 60a13c2 to 43e5480 Compare September 2, 2025 19:28
…emove-allocations

Signed-off-by: adamperlin <adamp@nanosoft.com>
Signed-off-by: adamperlin <adamp@nanosoft.com>
@adamperlin adamperlin force-pushed the adamperlin/panic-remove-allocations branch from 9b59310 to cf5efdb Compare September 2, 2025 19:45
ludfjig
ludfjig previously approved these changes Sep 2, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

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

Looks good to me. Let's see what others think!

dblnz
dblnz previously approved these changes Sep 3, 2025
Copy link
Contributor

@dblnz dblnz left a comment

Choose a reason for hiding this comment

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

LGTM!

…ort-based io directly to stream

error messages to the host and avoid needing a fixed-size buffer in the
panic handler.

Signed-off-by: adamperlin <adamp@nanosoft.com>
@adamperlin adamperlin dismissed stale reviews from dblnz and ludfjig via e9f5ace September 3, 2025 23:45
Signed-off-by: adamperlin <adamp@nanosoft.com>
…emove-allocations

Signed-off-by: adamperlin <adamp@nanosoft.com>
Signed-off-by: adamperlin <adamp@nanosoft.com>
Signed-off-by: adamperlin <adamp@nanosoft.com>
@andreiltd
Copy link
Member

andreiltd commented Sep 4, 2025

Sorry, I'm a bit late to the party but I think a similar problem exists in hyperlight_guest_bin exception handler, I'm not sure if this is something we want to address as part of this PR or follow up on this. Notably:

https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_guest_bin/src/exceptions/handler.rs#L82

The additional problem in hyperlight_guest_bin is that the code is unsound because the message string is NOT null terminated but it is treated as such later in the code:

https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_guest_bin/src/exceptions/handler.rs#L112

In result this I belive is UB:
https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_guest/src/exit.rs#L57

@syntactically
Copy link
Member

Sorry, I'm a bit late to the party but I think a similar problem exists in hyperlight_guest_bin exception handler, I'm not sure if this is something we want to address as part of this PR or follow up on this. Notably:

https://github.com/hyperlight-dev/hyperlight/blob/main/src/hyperlight_guest_bin/src/exceptions/handler.rs#L82

I'm aware of that one and am rewriting the whole exn handler at the moment anyway, so I was just going to roll it up in a slightly larger PR with the rest of the architecture stuff. Unless you are running into an urgent issue caused by this?

@andreiltd
Copy link
Member

Hey @syntactically, nothing urgent, no :) Great to hear you're working on this.

@adamperlin
Copy link
Contributor Author

I'm glad this is being worked on too! Thank you for bringing this up @andreiltd!

@ludfjig @dblnz Could I get one more review on this? I've changed the approach based on @syntactically's suggestion so now there is no fixed-size buffer on the guest side!

…emove-allocations

Signed-off-by: adamperlin <adamp@nanosoft.com>
@adamperlin adamperlin added this to the v0.10.0 milestone Sep 5, 2025
ludfjig
ludfjig previously approved these changes Sep 8, 2025
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

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

Looks good to me, but I am not too familiar with how OUT currently works in the host. Maybe @danbugs could review to make sure this looks correct?

danbugs
danbugs previously approved these changes Sep 9, 2025
Copy link
Contributor

@danbugs danbugs left a comment

Choose a reason for hiding this comment

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

LGTM!

jsturtevant and others added 2 commits September 9, 2025 16:56
Co-authored-by: Dan Chiarlone <danilochiarlone@gmail.com>
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
@jsturtevant jsturtevant dismissed stale reviews from ludfjig and danbugs via 4844ee3 September 9, 2025 23:57
@jsturtevant jsturtevant merged commit 6432590 into hyperlight-dev:main Sep 10, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bugfix For PRs that fix bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't alloc memory in panic handler
8 participants