[mm_supv]: Allocate the Ring 3 stack per demotion instead of using the pre-allocated array

Open
#1,996 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust

Research direction

Start with the TODO in patina_mm_supervisor/src/privilege_mgmt/syscall_setup.rs and trace how get_cpl3_stack supplies the Ring 3 stack during demotion and return. Then inspect validate_named_regions, verify_passdown_protections, and the page-table walk that enforce the current PassDown stack assumptions. Done means a per-demotion User stack is allocated, scrubbed and freed, with allocation failure handled and the HOB checks updated.

Written by the indexing model from the issue text.

Description

state:backlog state:needs-triage type:feature-request urgency:low
Feature Overview

Each CPU's Ring 3 stack is a fixed slice of one array MM Init allocates (PassDown cpl3_stack_base, cpl3_stack_size per core). SyscallInterface::get_cpl3_stack returns the slice for the core. The stacks stay mapped user-writable for the life of the supervisor and are reused across demotions, so whatever one user call leaves on the stack is still there for the next. Tracked from a TODO in patina_mm_supervisor/src/privilege_mgmt/syscall_setup.rs.

    /// TODO: Consider allocating a page before demotion and freeing it on return instead of
    /// using the pre-allocated stack array.
    pub fn get_cpl3_stack(&self, cpu_index: usize) -> Result<u64, SyscallSetupError> {

https://github.com/OpenDevicePartnership/patina/pull/1875#discussion_r4555674267

Solution Overview

Allocate a User stack from the supervisor page allocator before each demotion, and scrub and free it on return, the same way other user allocations are freed. This needs a decision on the per-MMI allocation cost and on what to do when allocation fails. The current HOB checks (validate_named_regions, verify_passdown_protections and the page-table walk) treat the PassDown stacks as the only user-writable memory in MMRAM outside modules, so they would need to change too.

Alternatives Considered

No response

Urgency

Low

Are you going to implement the feature request?

I will implement the feature

Do you need maintainer feedback?

No maintainer feedback needed

Anything else?

No response

Dominant language
Rust
Stars
568
Forks
63
Avg merge
1d 16h
Merged PRs (30d)
60

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenDevicePartnership/patina

All issues in OpenDevicePartnership/patina

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.