Commit graph

1737 commits

Author SHA1 Message Date
Damon Lee
123a0d844b armv8,CMake: Split generic timer, counter access
Instead of exporting the generic timer and counter access to userland in
one go, this commit splits it up into two different operations which
require two different build flags to be turned on. This is because the
timers expose a storage channel and allow threads to corrupt the
registers for each other.

Also move the config options to a better location and have them
depend on a more suitable config flag.
2019-09-18 14:51:07 +10:00
Anna Lyons
f02e59c59b armv8: expand generic timer user-level access
- allow the compare register to be set by user level (for both
  virtual and physical timer.
- allow the generic timer to be exported to EL1 as well when running
  seL4 as a hypervisor
2019-09-17 14:31:44 +10:00
Kent McLeod
d6bef3c533 cmake: Only include cmake files for selected arch
This prevents accidental declaration of properties or configurations
that are for the incorrect architecture selected. This was previously
required as the variables KernelWordSize and KernelArch were defined in
each arch specific cmake.config file. Now that they are defined in
advance it is possible to exclude the other imports.
2019-09-13 18:42:42 +10:00
Anna Lyons
7798b4767d aarch64: allow access to memory below physBase
On aarch64 physBase is the constant that points to the bottom of
physical memory (RAM).

Prior to this change the kernel window was mapped directly to physBase,
which is usually not a 0 paddr. As a consequence the kernel could not
access any memory below physBase.

This change fixes this issue by mapping the start of the kernel window
to 0 in the physical address space.

- add new constant PADDR_LOAD, the location of the kernel image in the
physical address space.
- add new constant PADDR_BASE, the start of the physical address space
(0).
- add new constant KERNEL_ELF_BASE, the location of the kernel image in
kernel virtual memory.

A consequence of this change is that on aarch64, the kernelBase constant
now points to the start of the kernel window in virtual memory, but
*not* to the start of the kernel image as these are now different.
2019-09-13 08:35:19 +10:00
Anna Lyons
3e685da663 aarch64: update fpsimd_HWCapTest for ARMv8.2
Prior to this commit this check would fail on ARMv8.2 and greater, as
having a bit set after this version does not imply that FPU/SIMD is not
supported.

For ARMv8.2 and above the values of the AdvSIMD/FP bits in
ID_AA64PFR0_EL1 are as follows:

- 0b1111 means FPU/SIMD is not supported.
- 0b0000 means FPU/SIMD is supported except for half-precision floating
point arithmetic.
- 0b0001 means FPU/SIMD is supported including half-precision floating
point arithmetic.
2019-09-11 13:46:46 +10:00
Curtis Millar
9cd7958dbe hifive: Real time clock operates at 1MHz
The SiFive FU540-C000 runs mtime on the rtcclk which operates at 1MHz
from an external oscillator.
2019-08-27 10:46:13 +10:00
Curtis Millar
ccfd672039 mcs: Boot RISC-V with scheduling control & context
Make sure that when the kernel boots a scheduling control cap is created
and that the initial thread and idle thread are scheduled using correct
systemt time.
2019-08-27 10:46:13 +10:00
Curtis Millar
7adf81f6d7 mcs: fastpath_reply_recv reply argument for RISC-V
Add the reply argument to the fastpath_reply_recv call for RISC-V.
2019-08-27 10:46:13 +10:00
Curtis Millar
449dcd5038 mcs: Select additional registers for RISC-V
mcs requires an additional 2 registers for performing system calls to
pass information regarding the reply capability and the destination of a
nbsend/recv.
2019-08-27 10:46:13 +10:00
Curtis Millar
e19fddbb56 mcs: Remove timer init and reset from RISC-V
The timer init and reset are not needed to initialise the clock for MCS
in RISC-V.
2019-08-27 10:46:13 +10:00
Curtis Millar
557f8d4fb8 riscv: Relocate read time to header
Move the RISCV function to read the current time to the header file so
that it can be inlined for MCS.
2019-08-27 10:46:12 +10:00
Anna Lyons
acdf0be5e5 mcs: Fix potential crash on preemption
Preemption can be triggered due to a revoke operation, which may have
deleted one or both of the current thread and current scheduling
context. Don't manipulate the current thread if it is no longer valid
and just charge the SC iff it is valid and the thread is not.

This was discovered during verification.
2019-08-22 11:22:41 +10:00
Anna Lyons
b33d4680f2 mcs: Avoid charging invalid scheduling contexts
ChargeBudget can be called after a preemption, but the preemption may
have deleted the scheduling context. Do not charge scheduling contexts
that have been deleted (check scRefillMax).
2019-08-22 11:22:41 +10:00
Anna Lyons
86e50d0703 mcs: Avoid missing a timer tick
Preemption can be via the timer interrupt. In this case we need to
update the timestamp so we can reprogram the timer for the next timeout
and guarantee it is in the future, otherwise we will end up setting a
timeout in the past.
2019-08-22 11:22:41 +10:00
Anna Lyons
b358a1c59c trivial: move isSchedulable to header 2019-08-22 11:22:41 +10:00
Anna Lyons
bf56d30d47 trivial: remove redundant condition
Remove redundant condition in schedcontext_resume, discovered by
verification.
2019-08-22 11:22:41 +10:00
Anna Lyons
9dffbd0167 Avoid adding thread without budget to scheduler
Prior to this change calling yieldTo on an sc with a thread that was not
in the scheduler and had an insufficient/unready head replenishment
would be added incorrectly to the scheduler.

If the thread isn't in the scheduler, use schedcontext_resume to ensure
that it is in the release queue if it has an insufficient/unready head
replenishment, and thus prevent that thread from being added to the
scheduler.
2019-08-22 11:22:41 +10:00
Anna Lyons
3a1218b347 Fix: Move refill_unblock_check into isSchedulable
Don't modify sc parameters unless we know that sc is not in the release
queue.
2019-08-22 11:22:41 +10:00
Anna Lyons
257a62c73f mcs: explicitly use ksCurSC
- in refill_[budget|split]_check.
- This simplifies the code and the proofs.
2019-08-22 11:22:41 +10:00
Anna Lyons
52dd8f092a mcs: Avoid removing the SC of the current thread
If the scheduling context is changed on the currently running thread
this causes issues if the operation triggers a preemption. This change
makes the proofs easier, and also makes sense for the api, as users
wishing to suspend the current thread should just use Suspend.
2019-08-22 11:22:41 +10:00
Anna Lyons
12be249514 mcs: in cancelIPC, clear the tcbFault
A fault message is an IPC. Threads which have faulted can be inactive,
blocked on send, or blocked on reply. Always clear tcbFault when
cancelling IPC to make sure restarted threads are not in a fault state.
2019-08-22 11:22:41 +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
225d74f6ae mcs: Set threads to inactive in cancelBadgedSends
This is the same reasoning as for cancelAllIPC
2019-08-22 11:22:41 +10:00
Anna Lyons
5d1db7c94c mcs: Set thread to inactive if no reply is present
If we're in a scenario where do_call or fault is set, but there is no
reply, the calling/faulting thread needs to be set to inactive to
prevent it reentering the scheduler in a bad state. If the reply is set,
then the calling/faulting thread is set to blocked on reply correctly.
2019-08-22 11:22:40 +10:00
Anna Lyons
395df93969 mcs: Set threads to inactive in cancelAllIPC
If a thread's fault endpoint has been deleted, such that cancelAllIPC is
called on that endpoint, set the thread state to inactive. This prevents
threads with faults from entering the run queue and makes the
behaviour consistent with threads faulting without a fault handler set.

This came up as verification now need the invariant that threads in the
runqueue have no faulted, an invariant not required before MCS.
Previously the behaviour was not broken, as threads would just refault
and be made inactive at that point.
2019-08-22 11:22:40 +10:00
Anna Lyons
9ccdc857e7 mcs: Use rescheduleRequired in schedcontext_bind
Schedcontext_bind is currently called in ThreadControl, which
manipulates capabilities which in turn can result in KsSchedulerAction
being deleted. This means that we cannot use possibleSwitchTo in this
function.

This is a stop-gap fix for verification, the long term fix is to split
setting scheduling parameters from ThreadControl, then we can return to
a direct switch, and also do a direct switch for other thread/scheduler
settings like priorities.
2019-08-22 11:22:40 +10:00
Anna Lyons
f1113460b4 mcs: Fix setPriority
When setting a thread priority, we need to check if it is in the
scheduler before putting it back in the scheduler, otherwise we do not
know enough about the scheduling context to know that the thread is
active.
2019-08-22 11:22:40 +10:00
Anna Lyons
61b886664d mcs: fix notification donation semantics
- update thread state before donate
- schedcontext_resume after donate

This ensures our scheduling invariants (on the run queue) are held.
2019-08-22 11:22:40 +10:00
Anna Lyons
82601b883b mcs: only donate on fault if the faulter has an SC
Fix bug found by Corey during verification
2019-08-22 11:22:40 +10:00
Anna Lyons
6195ea6651 mcs: break call chain in reply_remove_tcb
Rather than preserving the chain break it completely. This changes the
semantics such that if a reply is removed in the middle of a call
chain, a donated scheduling context cannot return to the original
caller.
2019-08-22 11:22:40 +10:00
Anna Lyons
6611cff6c0 mcs: fix behaviour on seL4_SchedContext_YieldTo
When yieldingTo a same prio thread, the same prio thread should run
first, not the current thread. Due to changes to possibleSwitchTo in
master scheduler this code became outdated and the current thread would
be rescheduled immediately.

The desired behaviour is that the thread being yieldedTo should be at
the head of the scheduler queue for its priority, and the current thread
should be just after it.
2019-08-22 11:22:40 +10:00
Anna Lyons
58725c4920 mcs: Preserve the value of scConsumed on Yield
We use the chargeBudget logic in the kernel on seL4_Yield to free up
the budget available in the head refill, however this
updates scConsumed. Given this is a simulated charge (the thread is
yielding the budget, not actually using it), this is incorrect.
2019-08-22 11:22:40 +10:00
Gerwin Klein
ba78e3b298 mcs: allow only unbound SC/TCB in SetSchedParams
This removes some special-casing from the proof.
2019-08-22 11:22:40 +10:00
Gerwin Klein
9412c98e33 trivial: sync comment with code 2019-08-22 11:22:40 +10:00
Gerwin Klein
754baa8fad mcs: Swap TCB cap install order in ThreadControl
Installing the endpoint caps before the CSpace/VSpace roots is easier
for verification, because deleting endpoint caps is always well-behaved,
but CNode cap deletion can be complex.
2019-08-22 11:22:40 +10:00
Anna Lyons
cfd8924a9f smp: always migrateTCB on schedcontrol_configure
we have no guarantees as to where the FPU context is
2019-08-22 11:22:40 +10:00
Anna Lyons
3d56973743 smp: remove excess code in schedContext_donate
- always migrate the TCB (the FPU context could be anywhere)
- don't need to call migrateTCB or rescheduleRequired, this is handled
by calling paths.
2019-08-22 11:22:40 +10:00
Anna Lyons
8cb01f32ec smp: remove excess remote call stall in unbindTCB
This isn't required as all code paths into this function have already
stalled the tcb
2019-08-22 11:22:39 +10:00
Anna Lyons
26205f61e1 smp: remove excess code in bindTCB
- we know the tcb does not have an SC at this point
- it may need to migrate if the FPU context is still on the other core.
2019-08-22 11:22:39 +10:00
Anna Lyons
f4c41f3936 x86-smp: remove check on Arch_migrateTCB
This check is not required and aligns the code back with master.
2019-08-22 11:22:39 +10:00
Anna Lyons
483f0ae22f mcs: SchedControlConfigure: charge correct core
Previously this code would incorrectly call chargeBudget twice, where it
was intended to be charging a specific core.
2019-08-22 11:22:39 +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
52beb5f3f1 reply_pop: do not call donate if SC is not NULL
This handles the specific case where a thread has donated its SC
over a Call but then is bound to another SC before the reply is
executed. In this edge-case, the donated SC remains with the callee.
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
7c3b80d3ed mcs: check budget is sufficient in preemptionPoint
When we enter the kernel we know we have at least getKernelWcetUs
budget. Preemption points need to maintain this invariant and check
again.
2019-08-22 11:22:39 +10:00
Anna Lyons
d4f9a705c7 tk1: increase WCET us for tk1
The TK1 is running at 700Mhz so this needs to be slower
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
efdf293984 mcs: make sure blocked threads have spare refills
otherwise they wake up and go back to sleep immediately
2019-08-22 11:22:38 +10:00