Commit graph

154 commits

Author SHA1 Message Date
Gerwin Klein
93f73a49ad tcb: make validFaultHandler available
Make the function validFaultHandler available to the assert in
sendFaultIPC in faulthandler.c.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-06-02 10:20:59 +10:00
Michael McInerney
771c9e43ce mcs: handle endpoint and ntfn queues uniformly
- Introduce functions to append and dequeue to/from endpoint and
  notification queues, in order to make verification feasible. Handle
  linked list manipulations with the same functions that were
  previously used for the ready and release queues, together with a new
  function that allows for a new item to be inserted into the queue
  after another item that is already in the queue.

- Remove tcbEPNext and tcbEPPrev pointers from the MCS version, and
  instead use tcbSchedNext and tcbSchedPrev pointers, given that no
  thread can be simultaneously in any two of the endpoint,
  notification, ready, or release queues.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-05-22 11:42:19 +10:00
Indan Zupancic
27a52ddd4c Runtime Domain Schedules
Implementation of RFC-20.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-03-24 15:03:39 +11:00
Michael McInerney
d16c975677 mcs: refactor finaliseCap to ease verification
This in particular introduces the function
schedContext_unbindReply, which is used within
finaliseCap, as well as invokeSchedContext_Unbind.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-02-16 14:13:14 +11:00
Gerwin Klein
d648c5dd53 trivial: align for better readability
White space change only:

- left-align sizes within each block declaration
- min 2 spaces to separate field name from size

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-01-09 09:00:43 +11:00
Gerwin Klein
c9f3c64162 bf structs: eliminate BF_CANONICAL_RANGE #ifdefs
Eliminate #ifdefs for BF_CANONICAL_RANGE in bitfield specifications,
using the new field_ptr command. Use word_size expressions for some of
the padding fields to make clearer where the sizes come from.

The transformations in this commit are written to produce exactly
identical output for code and proofs. In some rare cases, padding
could in the future be rearranged to make more use of field_ptr, but
these edits would create code differences and are left for later.

It may now also be to share more blocks between generic 32 and 64
definitions if they only reference word_size. This is also left for
later to reduce noise.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-01-09 09:00:43 +11:00
Krishnan Winter
85e57f7480 thread_ctrl: Remove unused flags
Signed-off-by: Krishnan Winter <krishnanwinter1@gmail.com>
2025-08-01 12:38:52 +01:00
Indan Zupancic
1415cac443 Add seL4_TCB_SetFlags Syscall
Add flags to tcb_t and the seL4_TCBFlag_fpuDisabled flag.

Enums are signed, make TCB flags word_t to make it unsigned.

Signed-off-by: Indan Zupancic <indan@nul.nu>
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2025-07-24 16:44:08 +10:00
Indan Zupancic
8f8776a541 Domain: Split off invokeDomainSetSet
Retain the ridiculous name to make clear which invocation is being
handled.

Rename tptr to tcb for consistency within the file.

We have a dom_t type, use it as early as possible.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Gerwin Klein
90dafb2e71 yieldTo: respect kernel reply protocol
Before:

- invokeSchedContext_Consumed and invokeSchedContext_YieldTo clobber
  the message info field in the reply from kernel, which results in a
  length 0 message.

- invokeSchedContext_Consumed and invokeSchedContext_YieldTo may crash
  the kernel for read-only IPC buffers

- invokeSchedContext_Consumed and invokeSchedContext_YieldTo generate
  a reply from kernel for syscalls that should not generate replies

- completeYieldTo does not set the badge register, which will contain
  whatever that previous syscall returned and not correctly indicate
  success/failure.

- completeYieldTo sets registers of the current thread, combined with
  IPC buffer message registers of potentially another thread.

Instead:

- pass the thread to setConsumed instead of the IPC buffer, so we can
  write to the correct registers

- look up the IPC buffer again and check for write authority

- follow the kernel reply protocol, which includes only generating a
  message for `call`. This means, we need to pass the flag through from
  higher-level decode functions.

- set thread state to Running if a reply message from the kernel was
  created, leave on Restart for default empty success message.

- set the badge register

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-06-04 15:54:45 +02:00
julia
eca86cff19 treewide: typo fixes
Signed-off-by: julia <git.ts@trainwit.ch>
2025-04-14 12:05:16 +10:00
Gerwin Klein
4f4721706e reply: do not assume replyObject NULL invariant
We no longer guarantee the invariant that the replyObject reference is
NULL when the thread state is not BlockedOnReceive or BlockedOnReply.

It is likely that this invariant was true in the kernel so far, but
proving it would require a new proof that the reference is already NULL
for any setThreadState to a simple state like Running, Inactive,
Restart. This either means reasoning about the state the thread had
before setThreadSate, or explicitly setting the reference to NULL more
often.

There are many of these setThreadState instances, and the benefit of
maintaining the invariant is low. Not maintaining the invariant removes
some state updates from low-level functions (called often) at the cost
of adding some if-checks in higher-level functions (called less often).

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-02-10 15:53:08 +11:00
Michael McInerney
6b6bb12501 mcs: remove parameter from schedContext_unbindTCB
This removes the tcb parameter from schedContext_unbindTCB, which
is unnecessary, since it is always the scTcb of the given sc.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2024-07-17 09:11:51 +10:00
Michael McInerney
220ef4f94e mcs: refactor awaken
This refactors awaken, providing an inline function for the
while loop condition, and modifying tcbReleaseDequeue to now
perform the entire loop body.

Since tcbReleaseDequeue will perform tcbReleaseRemove on the
head of the release queue, the variable ksReprogram will be set
to true within tcbReleaseRemove, and therefore, we do not need
to set this variable separately within the loop body of awaken.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2024-07-16 18:01:44 +10:00
Michael McInerney
686bba4d2a mcs: more uniformly handle ready and release queue
This introduces library functions for updating the linked lists which
use the tcbSchedNext and tcbSchedPrev pointers of a TCB, and uses these
to perform the updates to the ready queues and the release queue.

In order to accommodate this, ksReleaseQueue is now of type tcb_queue_t.

Co-authored-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2024-05-23 18:04:06 +10:00
Axel Heider
3c180701ee remove Arch_migrateTCB()
It does the same on all architectures, so the contents can be moved
into the generic code.

Signed-off-by: Axel Heider <axelheider@gmx.de>
2023-06-21 08:58:28 +10:00
alwin-joshy
069c937272
Implemented signal fastpath on AARCH64 (#793)
The signal fastpath aims to optimize the
seL4_Signal operation. In this commit, it is
implemented for MCS AARCH64 (SMP and non-SMP).
The fastpath does not include the case where
signaling results in a higher priority thread
being unblocked and made available for
scheduling (on any core). It does not
fastpath the case where the signaled thread
is donated a scheduling context and has its
FPU state saved in the FPU of a core.

Co-authored-by: Shane Kadish <shane.kadish@csiro.au>
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2023-01-10 10:15:39 +11:00
Michael McInerney
b7f2a1fb6f mcs: remove unused tcbReply field from tcb struct
The pointer to a reply object, if any, can be accessed
via the replyObject in the thread state

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2022-09-13 13:21:20 +02:00
Gerwin Klein
1c28462ebf structures: fix MCS object sizes
The kernel expects object sizes to be powers of two for size and
alignment computations.

- add missing padding for MCS 64-bit configurations for notifications
  (other configs were already fine)
- add missing padding for reply object struct
- strengthen compile time assertion to catch discrepancies in the
  future.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2022-07-19 14:01:45 +10:00
Indan Zupancic
f3addaa0fb Trivial: Remove now incorrect comment
Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2021-09-10 20:48:04 +10:00
Curtis Millar
6a9e860e4e mcs: Only unbind extant donated ntfn sc
When determining whether a SC donated from the notification should be
returned, we must ensure not to try and return a NULL SC to a
notification with not bound SC.

This could occur when a passive server performs a NBSendWait/NBSendRecv
with a notification in the receive phase, where the SC for the receiver
was returned in the send phase and the notification has no bound SC.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-04-29 12:07:07 +10:00
Curtis Millar
afbea15710 mcs: Add sporadic flag to SchedControl_Configure
This adds a flags parameter to SchedControl_Configure to enable
configuration of a sporadic SC.

This also allows flags to be added in the future as needed without
breaking the API.

This allows the user to configure an SC either to be constrained as a
sporadic task where accumulated time is only delayed to when a task has
become runnable (implementing the sporadic server algorithm) or
whenever the task becomes the current executing task (implementing the
sliding-window constraint as in constant-bandwidth servers).

This can be used to prevent non-realtime tasks from exceeding bandwidth
under any circumstances, even in an over-committed configuration, whilst
also allowing work-conserving tasks to be configured in the same system.

To implement sporadic servers, we need to ensure that the suspension of
a task cannot be used as a mechanism to amplify budget of a task by
granting that task access to effectively multiple periods worth of
replenishments within a single period.

To align the implementation of SCs with the model of sporadic servers we
must delay available time until the release of a task. Within seL4, a
release would be any time where an SC changes from not being associated
with a Running, RunningVM, or Restart thread to one that is.

This can occur when an SC is bound to a new thread in such a state or
when a thread changes to such a state from any non-running states.

Critically, replenishments should not be delayed at the point when an SC
becomes the current SC (as was the case prior to this commit). This has
the effect of enforcing a continuous, constant bandwidth which is a
restriction that is incompatible with standard scheduling logic.

Accounting for this requires inserting a new refill_unblock_check
call whenever a sporadic SC is unblocked and removing the
refill_unblock_check call from when said SC is scheduled.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2021-04-14 15:24:40 +10:00
Matthew Brecknell
4520503c8a remove slot_range_t
The RISC-V calling convention specifies that when a C function takes an
argument by value, the binary function should take the argument by
reference, if the value is larger than 2 pointer words.

For binary verification, we avoid implementing this aspect of the RISC-V
calling convention, by eliminating all such function arguments for
functions which are not inlined.

In this commit, we remove the `slot_range_t` structure altogether. For
the small number of functions which previously used this type, we unpack
the structure into three separate arguments.

Even though we are primarily concerned with RISC-V, we remove
`slot_range_t` arguments across all architectures.

Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
2021-03-19 11:29:51 +11:00
Matthew Brecknell
b2ad98214d avoid passing extra_caps_t by value
The RISC-V calling convention specifies that when a C function takes an
argument by value, the binary function should take the argument by
reference, if the value is larger than 2 pointer words.

For binary verification, we avoid implementing this aspect of the RISC-V
calling convention, by eliminating all such function arguments for
functions which are not inlined.

In this commit, we remove `extra_caps_t` function arguments. This
primarily concerns invocation decode functions. Since `loookupExtraCaps`
already stores extra caps in a global `current_extra_caps`, this
essentially amounts to eliminating many redundant structure copy
operations.

On some execution paths involving IPC, the extra caps lookup may happen
twice: first in the invocation decode, and then for cap transfer in the
performance phase of the IPC operation. Because the two phases are
entirely distinct, there is no interference in the use of a common
global variable.

Even though we are primarily concerned with RISC-V, we remove
`extra_caps_t` arguments across all architectures.

Signed-off-by: Matthew Brecknell <Matthew.Brecknell@data61.csiro.au>
2021-03-19 11:29:51 +11:00
Stefan O'Rear
b94d70adfc Outline object physical functions
Most of the uses of these are in functions where the cap type is
statically known and the correct branch could be used directly, but the
compiler does not know this so having these as inlines causes a large
number of accesses to bitfields of unrelated cap types in functions that
manipulate caps.

Moving this out of line makes the results of changing cap bitfields less
noisy.

Signed-off-by: Stefan O'Rear <sorear@fastmail.com>
2020-12-07 10:48:31 +11:00
Miki Tanaka
4ee1f90a7d mcs: add tcb argument to reply_unlink
reply_unlink takes a reply and remove the link between that reply
and its tcb. This link always exists at the call site and the tcb
information is always avaialble, or can be made available.

This commit adds this tcb as an extra argument to aid varification.

Signed-off-by: Miki Tanaka <miki.tanaka@data61.csiro.au>
2020-10-02 12:38:39 +10:00
Sylvain Gauthier
0c32e252d4 fix TCB_PTR_DEBUG_PTR debug macro
The base pointer is wrong, and it creates some nasty corruption down the
line (only affects debug builds).

Signed-off-by: Sylvain Gauthier <sylvain.gauthier@data61.csiro.au>
2020-08-31 16:23:32 +10:00
Mitchell Buckley
cc4b86d098 Check for reschedule on sched context return
The current state of MCS seL4 verification makes use of an invariant
that whenever the scheduler action is set to "resume current thread"
the current thread and the current sc are bound together. Since
maybeReturnSchedContext may unbind a thread from a scheduling context,
it should perform a check on whether it is unbinding from the current
thread, and in that case call rescheduleRequired which will (among
other things) change the scheduler action.

Signed-off-by: Mitchell Buckley <mitchell.buckley@data61.csiro.au>
2020-08-12 10:10:31 +10:00
Kent McLeod
09d42ac0ed mcs: Return bound notification SC before ep recv
If a thread is running on the SchedContext of it's bound notification,
when it next does a blocking recv/wait operation on an ep the SC is
removed. This allows the thread to return to being a passive thread to
receive the next notification or ep message.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-07-24 16:48:48 +10:00
Kent McLeod
15e615ada5 tcb_t: Add ascii diagram of tcb object layout
Now that debug_tcb_t is also located in a tcb object, add a diagram for
clarity.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-07-22 00:32:27 +10:00
Kent McLeod
9d9bb994e5 debug: create debug_tcb_t struct
Special debug variables that were previously stored at the end of the
tcb_t struct often cause the struct to get too large for the power-of-2
sized untyped object definition. This change moves these variables into
a new structure named debug_tcb_t that is located between the TCB CNode
and the tcb_t struct within a tcb kernel object. Because tcb_t needs to
be stored on a power-of-2 aligned boundary and the TCB CNode only
contains < 5 slots, there is easily > 512 bytes of unused data in every
tcb object. The kernel verification needs to be sure that objects don't
overlap in memory and so this space can't be easily used in a release
build at the moment, but for debug configurations using it shouldn't be
an issue.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-07-22 00:31:18 +10:00
Curtis Millar
c428f320b7 reflect function split in thread_control_flag
The thread_control_flag enum which defines which arguments should be
used to reconfigure the TCB should also be split into two sets of flags
as they are now applied to two different functions.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-04-27 11:44:00 +10:00
Anna Lyons
60f9eaa654 Split ThreadControl into two functions
This ensures that verification are not required to prove problematic
combinations of updates to a TCB that aren't even permitted by the API.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-04-27 11:44:00 +10:00
Qian Ge
512a0200de replacing all ifndef with pargma once
All the kernel header files now use pargma once rather than the ifndef,
as the pre-processed C files do not change while header files
are protected with pargma once. This will also solve any naming issues
caused by ifndef.
2020-03-23 11:04:46 +11:00
Gerwin Klein
79da079239 Convert license tags to SPDX identifiers
This commit also converts our own copyright headers to directly use
SPDX, but leaves all other copyright header intact, only adding the
SPDX ident. As far as possible this commit also merges multiple
Data61 copyright statements/headers into one for consistency.
2020-03-09 13:21:49 +08:00
Kent McLeod
2d362cb7c8 arm,SMP: Refactor irq_t structure for smp
Explicitly create a struct definition for irq_t on SMP Arm
configurations. This makes it a lot harder to mistakenly use the wrong
irq encoding when moving an irq between a cnode index and hardware irq
number / core. A couple areas where this was being handled incorrectly
was fixed as part of the refactor. When performing an ipi for masking
PPI interrupts, the idx encoding is used as it fits into a single word.
2020-02-05 13:56:48 +11:00
Curtis Millar
18219bbedf mcs: RISC-V uses 39-bit addressing in stuctures.bf
RISC-V uses 39-bit virtual addressing rather than 48 bits so the
'high' bits of a pointer can be 39 or fewer bits on RISCV rather than
48.
2019-08-27 10:46:13 +10:00
Curtis Millar
af34037edb trivial: spelling of the word 'canonical' 2019-08-27 10:46:13 +10:00
Anna Lyons
ef4ba6b69a mcs: Introduce firstPhase flag to invocations
Some invocations contain two phases, and certain operations cannot be
allowed to run in the first phase as it could effect the currently
running thread and result in an invalid system state for the second
phase. This change filters those invocations, preventing them from being
used in the first phase of a two-phase, blocking system call.
2019-08-22 11:22:41 +10:00
Anna Lyons
4f00022f7d mcs: Use cancelIPC instead of reply_clear
- reply_clear only does half the job
- remove reply_clear no longer used
2019-08-22 11:22:39 +10:00
Anna Lyons
f103ac223d mcs: Refactor replies to solve revoke problems
Before this change, we set the replyObject in the thread state on recv
with no back pointer such that stray pointers would be left in the
thread state when a reply object was completed.

The new semantics are clearer and fix this problem by doing the
following:

- tcb->tcbReply is removed and the thread state field is always used,
  this was unneccessary duplication previously
- the thread state value is set to the reply object only when the thread
  is in BlockedOnReply or BlockedOnRecv
- the reply contains a back pointer, replyTCB, which points to that
  thread
- if a thread has its reply removed, it must be set to
  ThreadState_Inactive.
- deletion is easy in the blockedOnRecv case, we just unlink the reply
  and the tcb.
- deletion is complicated for blockedOnReply. If we are deleing a tcb,
  we remove the actual reply object and the call chain is broken. If we
  are deleting a reply, we maintain the call chain by moving the tcb to
  the next reply.
- we refactor the reply object interface to solve the above.
    * reply_clear: removes the reply from any connections (tcb, sc)
    * reply_unlink: just unlinks the tcb and reply, and sets the thread
      state to inactive
    * reply_remove: removes the reply from the call chain
    * reply_remove_tcb: removes the exact reply that a tcb is bound to,
      as we are removing that tcb. Breaks the call chain.
2019-08-22 11:22:39 +10:00
Anna Lyons
2329cd81dc mcs: add seL4_SchedContext_YieldTo
Implement seL4_SchedContext_YieldTo, which allows users to manipulate
the scheduling queues up to their MCP and can be used for user level
scheduling.
2019-08-22 11:22:38 +10:00
Anna Lyons
a38e62f2f9 mcs: timeout exceptions
- Add seL4_TCB_SetTimeoutEndpoint
- implement timeout exceptions
2019-08-22 11:22:38 +10:00
Anna Lyons
c405ef53d2 mcs: install fault endpoint into tcb cnode
- seL4_TCB_Configure no longer takes a fault endpoint.
- seL4_TCB_SetSpace takes a cap in the callers cspace for the
  fault endpoint, not the target tcbs.
- seL4_TCB_SetSchedParams now also takes a fault endpoint as above.

This change installs the fault endpoint cap into the tcb cnode
first validating it.

This means either of the functions that set it will now return an error
if the cap is not either a null cap or an endpoint with send and
grant rights.

Significantly, the cap passed to the function should be in the callers
cspace, not the target tcbs.
2019-08-22 11:22:38 +10:00
Anna Lyons
106b893ee0 mcs: configurable scheduling context size
This allows users to define custom amounts of refills without
increasing the scheduling context size system wide.

also add libsel4 functions for refill size
2019-08-22 11:22:38 +10:00
Anna Lyons
a22cb3d102 mcs: associate scheduling context + ntfn
This commit allows scheduling contexts to be bound
to notification objects. When a passive server
receives a notification it will receive the scheduling
context from the notification. When the server
blocks the scheduling context is returned.
2019-08-22 11:22:37 +10:00
Anna Lyons
554f812da3 mcs: scheduling context donation over ipc
After this commit, threads blocked on an endpoint can recieve a
scheduling context from the thread that wakes the blocked thread.
2019-08-22 11:22:37 +10:00
Anna Lyons
5fe1890a83 mcs: order EP and NTFN queues
Previously IPC signal queues were FIFO, as of this change they are
ordered by priority (FIFO for same prio threads).
2019-08-22 11:22:35 +10:00
Anna Lyons
34c1f920b1 mcs: add periodic scheduling
This commit adds periodic scheduling with sporadic servers.
2019-08-22 11:22:35 +10:00
Anna Lyons
952134d1b8 mcs: Add a scheduling context object
This is the first part of the seL4 MCS. This commit:

    * adds a scheduling context object. Threads without scheduling
      context objects cannot be scheduled.
    * replaces tcbTimeSlice with the scheduling context object
    * adds seL4_SchedControl caps for each core
    * adds seL4_SchedControl_Configure which allows users to configure
      amount of ticks a scheduling context has, and set a core for the
      scheduling context.
    * adds seL4_SchedContext_Bind, Unbind and UnbindObject, which allows
      a tcb to be bound to a scheduling context.
2019-08-22 11:22:34 +10:00