Skip to content

Allow the guest to manage its own stack#1205

Merged
syntactically merged 7 commits intomainfrom
lm/stack-scratch
Feb 4, 2026
Merged

Allow the guest to manage its own stack#1205
syntactically merged 7 commits intomainfrom
lm/stack-scratch

Conversation

@syntactically
Copy link
Member

This is a combination of several commits related to refactoring the guest stack from the original PR. It also addresses the longstanding issue #665.

@syntactically syntactically added kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. Guest-COW PRs that form part of the Guest-COW change labels Feb 2, 2026
ludfjig
ludfjig previously approved these changes Feb 3, 2026
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.

LGTM! Can we remove pub struct GuestStack, and there seems to be some enums variants that may no longer constructed like StackOverflow, CheckStackGuard, ConvertRspPointer. We could potentially remove these (or in future PRs if preferable)

simongdavies
simongdavies previously approved these changes Feb 3, 2026
Copy link
Contributor

@simongdavies simongdavies 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 great! A few minor comments and nits but otherwise LGTM.

@syntactically
Copy link
Member Author

Rebased and added fixups addressing the review comments (thanks!)

@ludfjig
Copy link
Contributor

ludfjig commented Feb 3, 2026

LGTM! Can we remove pub struct GuestStack, and there seems to be some enums variants that may no longer constructed like StackOverflow, CheckStackGuard, ConvertRspPointer. We could potentially remove these (or in future PRs if preferable)

@syntactically any opinions on this?

@syntactically
Copy link
Member Author

syntactically commented Feb 3, 2026

LGTM! Can we remove pub struct GuestStack, and there seems to be some enums variants that may no longer constructed like StackOverflow, CheckStackGuard, ConvertRspPointer. We could potentially remove these (or in future PRs if preferable)

@syntactically any opinions on this?

@ludfjig Sorry, I missed this the first time around. I think I just added ef752ce addressing this?

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.

Great work! I've left a couple of comments and questions.

This commit changes the code that sets up all these processor control
structures to allocate pages from the scratch region, map them to an
arbitrary VA, and then point the processor at that VA (in order to
ensure that they survive snapshotting at the same VA).  It also
refactors the architecture-specific initialisation code somewhat, in
order to make it a bit easier to have one memory allocation shared by
all the relevant tables & in preparation for future multi-architecture
support.

Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
A separate exception stack is needed in preparation for moving
management of the main guest stack into the guest.

Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
They may not be terribly useful as we move towards a stack that the
guest is allowed to grow on its own.

Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Previously, this code path was not tested, and would fail because
`UninitializedSandbox::evolve()` unconditionally tried to run the
guest initialisation function, which has already been run in this
case.  This simply ignores the initialisation stage if the snapshot
has no `preinitialise` entrypoint.

All that `UninitializedSandbox` is really good for at this point is
registering host functions, so it might make sense to further revisit
the API.

Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
This moves management of the guest stack into the guest, allowing the
guest to flexibly allocate pages from the scratch region to the stack.
This also makes the stack dynamically growable and essentially
unbounded, as is common on other architectures.

Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
Signed-off-by: Lucy Menon <168595099+syntactically@users.noreply.github.com>
@syntactically syntactically merged commit 78b07d7 into main Feb 4, 2026
110 of 112 checks passed
@syntactically syntactically deleted the lm/stack-scratch branch February 4, 2026 15:15
@jsturtevant jsturtevant mentioned this pull request Feb 4, 2026
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Guest-COW PRs that form part of the Guest-COW change kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants