@@ -37,6 +37,7 @@ struct pd_metadata {
3737 char name [MAX_NAME_LEN ];
3838 /* For reporting potential stack overflows, keep track of the stack regions for each PD. */
3939 seL4_Word stack_bottom ;
40+ seL4_Word passive ;
4041} __attribute__((packed ));
4142
4243/* Correspond to `struct VmMetadata` in tool/microkit/src/symbols.rs */
@@ -740,25 +741,6 @@ static void monitor(void)
740741 seL4_Word pd_id = badge - 1 ;
741742 seL4_Word tcb_cap = BASE_PD_TCB_CAP + pd_id ;
742743
743- if (label == seL4_Fault_NullFault && pd_id < MAX_PDS ) {
744- /* This is a request from our PD to become passive */
745- err = seL4_SchedContext_UnbindObject (BASE_SCHED_CONTEXT_CAP + pd_id , tcb_cap );
746- if (err != seL4_NoError ) {
747- puts ("MON|ERROR: could not unbind scheduling context from thread control block\n" );
748- } else {
749- err = seL4_SchedContext_Bind (BASE_SCHED_CONTEXT_CAP + pd_id , BASE_NOTIFICATION_CAP + pd_id );
750- if (err != seL4_NoError ) {
751- puts ("MON|ERROR: could not bind scheduling context to notification object\n" );
752- } else {
753- puts ("MON|INFO: PD '" );
754- puts (pd_metadata [pd_id ].name );
755- puts ("' is now passive!\n" );
756- }
757- }
758-
759- continue ;
760- }
761-
762744 puts ("MON|ERROR: received message " );
763745 puthex32 (label );
764746 puts (" badge: " );
@@ -898,6 +880,8 @@ static void monitor(void)
898880
899881void main (void )
900882{
883+ puts ("MON|INFO: Microkit Monitor started!\n" );
884+
901885#if CONFIG_DEBUG_BUILD
902886 /*
903887 * Assign PD/VM names to each TCB with seL4, this helps debugging when an error
@@ -911,7 +895,28 @@ void main(void)
911895 }
912896#endif
913897
914- puts ("MON|INFO: Microkit Monitor started!\n" );
898+ /* If there are passive PDs in the system, lazily rebind it's Scheduling Context to it's Notification.
899+ * To workaround https://github.com/seL4/seL4/issues/1617 by applying https://github.com/seL4/seL4/pull/523
900+ */
901+ for (unsigned idx = 0 ; idx < pd_metadata_len ; idx ++ ) {
902+ if (pd_metadata [idx ].passive ) {
903+ seL4_Error err = seL4_SchedContext_Bind (BASE_SCHED_CONTEXT_CAP + idx , BASE_NOTIFICATION_CAP + idx );
904+ if (err != seL4_NoError ) {
905+ puts ("MON|ERROR: could not bind scheduling context to notification object\n" );
906+ continue ;
907+ }
908+
909+ err = seL4_TCB_Resume (BASE_PD_TCB_CAP + idx );
910+ if (err != seL4_NoError ) {
911+ puts ("MON|ERROR: could not bind resume passive PD TCB\n" );
912+ continue ;
913+ }
914+
915+ puts ("MON|INFO: PD '" );
916+ puts (pd_metadata [idx ].name );
917+ puts ("' is now passive!\n" );
918+ }
919+ }
915920
916921 monitor ();
917922}
0 commit comments