Skip to content

Enable mapping extra TCB and SC caps into PD's#406

Merged
midnightveil merged 2 commits into
seL4:mainfrom
au-ts:cap_sharing
Jun 11, 2026
Merged

Enable mapping extra TCB and SC caps into PD's#406
midnightveil merged 2 commits into
seL4:mainfrom
au-ts:cap_sharing

Conversation

@Kswin01

@Kswin01 Kswin01 commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

Note

See the modifications to manual.md for the behaviour, or alternatively, the old version of the PR description which is roughly similar but differs in the details:


This PR adds functionality to map arbitrary TCB and SC caps of other PD's into another PD. This can allow a user to share a SC cap of one PD to another without having to explicitly make the destination PD the parent (and therefore have to also handle faults of the child).

Adding a cap to a PD requires adding a <cap/> node to a PD:

    <protection_domain name="parent" priority="55">
        <program_image path="parent.elf" />
        <cap type="tcb" pd="child" dest_cspace_slot="5" />
        <cap type="sc" pd="parent" dest_cspace_slot="6" />
    </protection_domain>

You must specify the type of cap (currently only implemented for TCBs and SCs but can be extended in the future). Additionally, the name of the pd that is the source of that cap. The destination cspace slot is an index into the BASE_USER_CAPS region of the cspace.

This PR is also reflected in: https://github.com/au-ts/microkit_sdf_gen/tree/cap_sharing

@Kswin01 Kswin01 force-pushed the cap_sharing branch 4 times, most recently from 8191952 to 6ec5219 Compare January 5, 2026 04:54
@Kswin01 Kswin01 force-pushed the cap_sharing branch 9 times, most recently from 34d549f to e2661e0 Compare January 21, 2026 04:40
Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/sdf.rs Outdated
Comment thread tool/microkit/src/sdf.rs Outdated
Comment thread tool/microkit/src/sdf.rs Outdated
Comment thread tool/microkit/src/sdf.rs Outdated
Comment thread tool/microkit/src/sdf.rs
@Kswin01 Kswin01 force-pushed the cap_sharing branch 3 times, most recently from 3938f82 to 36eed41 Compare January 27, 2026 01:17

@Indanz Indanz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As you can see from the comments, I don't know Rust, so take everything I say with a big grain of salt. But I'm pretty sure it doesn't need to be quite this ugly.

Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/capdl/builder.rs Outdated
Comment thread tool/microkit/src/sdf.rs
@Kswin01 Kswin01 force-pushed the cap_sharing branch 3 times, most recently from 49c8382 to c870e06 Compare January 28, 2026 03:36
@midnightveil midnightveil self-assigned this Jun 5, 2026
@midnightveil

midnightveil commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Remaining work on this to get this merged:

  • Test example
  • Documentation
  • Bikeshed the appearance (thought: instead of <cap>, doing a <extra_caps> element with child (<endpoint>) or (<sc>); this would allow more fine grain attribute on the different cap types, instead of smooshing everything onto one <cap> element. (edit: <cnode element?)

Desired additions in later PRs.

  • remove PD hierarchy. To do this we want to add a feature to automatically migrate one .system file to another; there should be no need for this to be manual user.
  • Make it a fully functional replacement for the PD hierarchy. i.e. allow the fault endpoints to be set up arbitrarily. (it might make sense for this not to be the <extra_caps>, IDK
  • Make the "user caps" its own cnode that is dynamically sized, there's no reason to limit this (see also: the untypeds PR).
  • Auto-allocation of slots? (edit: maybe not?)
  • perms

@midnightveil

midnightveil commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

We've bikeshed the appearance internally, and decided that it will look like:

<protection_domain name="alpha">
   <cspace> <!-- the root cnode (currently size 512) -->
       <!-- implicitly, not mentioned in the xml: the microkit caps -->
       
       <cap_tcb slot="1" pd="beta" />
       <cap_vspace slot="2" pd="beta" />
   </cspace>
</protection_domain>

The plan is soon to change the layout of this exactly; I'm going to make the layout of where the user caps be instead an implementation details and you should use a helper function.

Survey of cap types

We have:

  1. Null cap (irrelevant)
  2. Untyped cap. There are no static untypeds to refer to, so this cap type does not make sense. When we do the dynamic-remaining untypeds these are dynamic, and we give them a cnode to go into. So we can ignore this. badge is meaningless
  3. Endpoint: not allowed, use channels for that
  4. Notification: badge useful here, though can default to the original
  5. reply cap: not given
  6. cnode cap: this will probably want some kind of "name" field to address the cnode, or maybe "pd" to address the cspace. badge contains the 'guard' value which we do want to control.
  7. thread/tcb: 1-1 with the pd name. badge means nothing.
  8. irqcontrol: badge means nothing. there is only one of these, so pd is meaningless
  9. irqhandler: badge has no meaning.
  10. arm smc: badge convey the smc ids that are allowed to use
  11. x86 iospace: badge is like PCI id or something, IDK
  12. riscv opensbi: badge conveys sbi ids that are allowed to use
  13. schedcontext: only assocaited with pd, nothing
  14. frame caps: no badge, associated with ?? something not a pd
  15. page table: no badge, associated with ?? not a pd
  16. vspace: no badge, associated with a pd
  17. asidcontrol/asidpool: no badge, not associated with anything

@Indanz

Indanz commented Jun 10, 2026

Copy link
Copy Markdown

5. reply cap: not given

Actually, for timeout fault handlers it makes sense to reply on behalf of the task for recovery purposes, especially if the server is reset.

@midnightveil

Copy link
Copy Markdown
Collaborator

Actually, for timeout fault handlers it makes sense to reply on behalf of the task for recovery purposes, especially if the server is reset.

well, regardless, the badge means nothing. and this would be associated with a PD, at least.

Comment thread docs/manual.md
Comment thread example/cap_sharing/secondary.c
Comment thread docs/manual.md Outdated
Comment thread tool/microkit/tests/sdf/pd_cap_mappings_overlapping.system
Comment thread tool/microkit/src/capdl/builder.rs Outdated
@midnightveil

Copy link
Copy Markdown
Collaborator

Commit history before I clean it up: https://github.com/au-ts/microkit/tree/archive/cap_sharing_history.

midnightveil and others added 2 commits June 11, 2026 15:23
This is useful for the following cap_sharing commit.
We have these three mappings from PD index to CSpace/Notification/
Endpoint; if we wanting to track more we'd need even more hashmaps.
Instead, merge them into a 'PDShadowCSpace' struct which is easier
to add more elements into, and lookup.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
This adds the ability to map (some) 'extra' capabilities
into pre-defined slots in a PD's CSpace, such as the TCB
or SC of another PD, which can be useful for writing
userspace schedulers without needing to use the parent-child
hierarchy.

This does increase the size of the PD CNode to 1024 entries.

Co-authored-by: Krishnan Winter <krishnan.winter@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
@midnightveil

Copy link
Copy Markdown
Collaborator

The link-check is expected to be failing until after this PR is merged.

@midnightveil midnightveil mentioned this pull request Jun 11, 2026
5 tasks
@midnightveil midnightveil merged commit 079561b into seL4:main Jun 11, 2026
10 of 11 checks passed
@midnightveil midnightveil deleted the cap_sharing branch June 11, 2026 06:32
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.

5 participants