Skip to content

sel4-capdl-initializer: lazy SC rebind for passive#352

Open
dreamliner787-9 wants to merge 2 commits into
seL4:mainfrom
au-ts:passive_task_in_initialiser
Open

sel4-capdl-initializer: lazy SC rebind for passive#352
dreamliner787-9 wants to merge 2 commits into
seL4:mainfrom
au-ts:passive_task_in_initialiser

Conversation

@dreamliner787-9

Copy link
Copy Markdown
Contributor

Implements lazy Scheduling Context rebind for passive tasks inside the capDL initialiser.

Solves problems such as seL4/microkit#91

@dreamliner787-9 dreamliner787-9 requested a review from nspin as a code owner June 22, 2026 05:15
Add `fn bind_ntfn` for `SchedContext`.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
@dreamliner787-9 dreamliner787-9 force-pushed the passive_task_in_initialiser branch from 7dbba7a to 561c46e Compare June 22, 2026 05:18
Comment on lines +841 to +845
if obj.bound_notification().is_none() {
panic!("A passive task must have its own Notification.");
}
let bound_notification_cap =
self.orig_cap::<cap_type::Notification>(obj.bound_notification().unwrap().object);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use the let/Some destrucuturing (or match) here rather than is_none() and unwrap.

Also, if we do sc.bind_ntfn(), where is that SC from, if not obj.sc() and does that not imply that it is not none?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sc in this context could be the initialiser's SC or the TCB's SC as created from the spec. Binding the Notification to the initialiser's SC wouldn't make sense so that's why I had the if obj.bound_notification().is_none() check.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But I'm confused, you then do sc.bind_ntfn(bound_notification_cap)?; next?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wait my bad, in the original comment, sc would be either a Null cap or the TCB's SC as created from the spec.

Regardless, the if obj.sc().is_none() { check will make sure that sc is the TCB's SC.

Then bound_notification_cap is the TCB's Notification cap.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Then I think we should be explicit and use let/Some for that as well instead of using the previous sc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok sounds good

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I meant bound_sc here on the next line, not still sc. No point unwrapping to an unused var.

Also, I'd suggest using this variant:

let Some(bound_sc) = obj.sc() else {
   panic!("blah blah");
}

This removes the nested as you add more checks.

(Also, is panic!() the normal way that you do errors in rust-sel4?)

Implements lazy Scheduling Context rebind for passive tasks inside
the capDL initialiser.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
#[sel4_cfg(KERNEL_MCS)]
impl<C: InvocationContext> SchedContext<C> {
/// Corresponds to `seL4_SchedContext_Bind`.
pub fn bind_ntfn(self, notification: Notification) -> Result<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you rename this to sched_context_bind() to match the convention of the file?

Also, while you're at it, could you also rename unbind below to sched_context_unbind()?


pub master_fault_ep: Option<Word>,

pub passive: bool,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this flag necessary? Could we just bind the nfn to the sc whenever a tcb has both a nfn and a sc?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That seems wrong; an active server would both have a TCB, SC, and a notification but shouldn't have the SC bound to the notification for lazy rebind. Unless you mean something else?

(But yes this would also need changing in the C capDL spec)

@midnightveil midnightveil Jul 6, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I could've sworn I left another comment but I feel like there should be a way to ask for "SC bound to NTFN" in the spec more generally; which is what this is wanting.

(paasive w/lazy rebind = SC bound to TCB and SC bound to NTFN, and the TCB has ability to block on that notification; no need for an extra passive attribute...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How about we give a pub slots: Vec<CapTableEntry> to the NTFN object in the spec, if there is a SC cap in that Vec then do the passive with lazy rebind?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Surely binding ntfn to SC exists in the capDL spec?

(If not this should also be discussed on the C/Haskell repo as there are other stakeholders here)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've made an issue in the C/Haskell repo here: seL4/capdl#96

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.

3 participants