Commit graph

3469 commits

Author SHA1 Message Date
Nick Spinale
a631ee42d8 aarch64: add missing vcpu cases
Adds missing vcpu cases for some aarch64-specific functions on
capabilities.

Signed-off-by: Nick Spinale <nick@nickspinale.com>
2020-05-27 19:15:17 +00:00
Curtis Millar
6fbee8ba05 Invert address mapping diagrams
This makes all daigrams have their first address at the end of the
diagram and their last address at the start of the diagram.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-22 12:26:13 +10:00
Curtis Millar
301f36359c trivial: Use UL_CONST in assembler macros
Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-22 12:26:13 +10:00
Curtis Millar
96456c6ae7 trivial: fix header files
Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-22 12:26:13 +10:00
Curtis Millar
4466c7c9b0 Remove references to kernelBase
kernelBase was used inconsistently between different architectures to
refer to the either of the first kernel address or the first address of
the mappings of the kernel ELF region specifically.

These have been replaced with more consistent use of constants
explicitly describing which region is being referenced.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-22 12:26:13 +10:00
Curtis Millar
fba7c896b0 Consolidate kernel virtual memory regions
Each architecture now only needs to describe the bounds of the three
memory regions: the 1:1 mapped physical memory region, the kernel ELF
region (which may or may not overlap the physical memory region) and the
device / kernel page table region.

The physical base address of the 1:1 mapped physcial memory region and
the kernel ELF region must also be specified.

The top of user addressable memory (where in the same virtual address
space as the kernel) is defined by USER_TOP.

The physic memory virtual mapping is described by PPTR_BASE and
PPTR_TOP. The base physical memory address is PADDR_BASE and is the
physical address used to map PPTR_BASE.

Don't use kernelBase when referring to the base of the 1:1 mapped
physical memory window.

The kernel ELF virtual address region is described by KERNEL_ELF_BASE
and extends until the virtual address of the symbol `ki_end` which is
created by the linker. KERNEL_ELF_PADDR_BASE is the base address of
the physical memory region used to map the kernel and is the address to
which KERNEL_ELF_BASE maps.

KERNEL_ELF_BASE and KERNEL_ELF_PADDR_BASE do not need to be aligned to a
page size boundary as they are approriately truncated during boot by the
`map_kernel_window` function.

KDEV_BASE describes the base virtual address of the kernel device region
and the region is assumed to extend to the end of virtual memory.

Note: The offset between PPTR_BASE and PADDR_BASE is used to translate
the virtual address of all untyped objects to physical addresses. This
includes device untyped objects or frame objects where the virtual
address does not fall within the 1:1 mapped physical memory region.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-22 12:26:13 +10:00
Saer Debel
7dc4209f89 Revised kernel printf implementation
Adapted musl printf implementation using our output abstraction.
Floating point specifiers are not supported in this adaptation.
Modified the code to also match our style and make it
less unnecessarily complex.

Signed-off-by: Saer Debel <saer.debel@data61.csiro.au>
2020-05-19 13:16:20 +10:00
Rafal Kolanski
77a4a1d64c aarch32: tune vcpu struct padding for verification
Verification requires packed C structures for reasoning. The C parser
assumes uint64_t (unsigned long long) has 8-byte alignment, thus size of
struct vcpu should be a multiple of 8. As this was not the case, we add
an extra word_t (4 bytes) for padding.

This type of manual padding is naturally fragile and will break as soon
as any field of struct vcpu changes in size by < 8 bytes.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-05-15 12:04:47 +10:00
Kent McLeod
00a9ba9123 aarch32: Move tpidruro from vcpu to tcb context
This register is visible to software executing at PL0 but not writeable.
Storing it in the VCPU context required custom save/restore handling as
it had to be explicitly handled when switching from a VCPU thread to a
non-VCPU thread so that it didn't become a channel. It is possible to
now update this register via seL4_TCB_WriteRegisters for software
executing at PL0.

This also fixes a bug where if a vcpu-thread is switched for a
non-vcpu-thread and then switched to a different vcpu-thread the
original vcpu-thread's copy of this register will get set to 0.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-05-15 12:04:39 +10:00
Siwei Zhuang
8b595ec9de riscv: Fix preprocess failure
The verification doesn't like FPU. Making FPU code invisible to
verification.

Signed-off-by: Siwei Zhuang <siwei.zhuang@data61.csiro.au>
2020-05-13 14:14:14 +10:00
Gerwin Klein
62b37194a5 github: invoke git status correctly
The -u option takes its argument without space.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-05-12 11:09:01 +08:00
Gerwin Klein
8a5ee2b5f8 github: sync with test invocation on bamboo
This should not change behaviour, but makes sure we replicate the test
setup more precisely.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-05-12 11:08:22 +08:00
Gerwin Klein
a4b1e347f6 github: use gitlint config from sel4_tools
Previously, gitlint would use the configuration from the local
repository only.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-05-12 11:07:46 +08:00
Siwei Zhuang
13d1a9963b riscv: Update to use per-hart cached FPU state
Use per-hart cached FPU state on RISC-V, align with other architectures.

Signed-off-by: Siwei Zhuang <siwei.zhuang@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
67cf62e86a trivial: Init FPU cached state for riscv
Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
a233f71184 trivial: Remove unused header files
Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
f6507ae6c5 riscv: Disable FPU access by default
By default the FPU access is disabled so that any accesses cause
traps.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
35e05b813a riscv: Update rv64 FPU code
The FPU enable/disable state is cached for all architectures, so
the RV64 FPU code is updated accordingly.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
472cd300d7 trivial: Add license
Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
343761ca5c riscv: Improve IPI code
The removed while loop in ipi_send_target can cause a deadlock, if
the target of an IPI remote call enters handleIPI through the
clh_is_ipi_pending path in smp/lock.h.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
57ce0a9cba riscv: Switch the FPU owner when migrating a TCB
If a TCB is being migrated to another core and it is the current
FPU owner, we reset the FPU owner to NULL.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
04061e113e riscv: Reset FPU owner when deleting a thread
If a thread to be deleted is the current FPU owner, we switch
away from the thread.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
4748f924fe riscv: Handle illegal instructions if FPU is off
When FPU is off, we first assume an illegal instruction fault
is triggered by an FPU access and retry the instruction after
switching the FPU owner. Otherwise, we handle the illegal
instruction fault.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
b660c2e48c riscv: Add FPU lazy switching code to kernel exits
lazyFPURestore is call during kernel exits. Then, the FPU is
enabled or disabled accordingly by chaning the SSTATUS
of the current thread. The SSTATUS will be written to the
physical SSTATUS CSR, and thus the FPU accesses will be
enabled or disabled.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
50b12303d4 riscv: Init FPU on each core
Init FCSR to 0 and disable FPU accesses.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
ff7562b288 riscv: Add FPU functions for RISCV
These functions are called by the arch-independent functions
to save and restore FPU state lazily.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
4006310e68 riscv: Add FPU state in TCB
Add FPU state storage in TCB and increase TCB size bits when FPU
is enabled.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
b8aa983e31 riscv: Add functions to read/write fcsr
read_fcsr and write_fcsr are added to access FPU CSR.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
8c556d5899 riscv: Enable compiler flag for FPU for RV64
The F and D extensions are enabled for RV64 when KernelHaveFPU
is enabled. Note that we still use the lp64 abi: no floating-point
arguments will be passed in registers

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Yanyan Shen
6a723182d1 riscv: Add FPU config options for RISCV
Two options, KernelRiscvExtD and KernelRiscvExtF, are added to
represent the D and F floating-point extensions. KernelHaveFPU
is enabled when the floating-point extensions are enabled.

Signed-off-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-05-07 13:48:26 +10:00
Curtis Millar
d5d54a0d55 introduce isStopped and change isBlocked
This changes the semantics if `isBlocked` to not include the 'inactive'
state when it returns true. The old semantics for isBlocked are provided
by `isStopped`.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-06 15:49:33 +10:00
Gerwin Klein
3f9a4cd809 github: add workflow actions for style checks
This replicates some of the TS-internal CI checks directly on github
for faster feedback.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-05-05 11:22:09 +10:00
Curtis Millar
ba5540fa75 mcs: Configure idle SC based on target core
Every SC in the system must be configured based on the actual core on
which it will run and all time comparisons for that SC must be made
relative to that core.

When creating SCs for the system idle threads those SCs must be
configured for their target cores.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-04 11:58:42 +10:00
Curtis Millar
95ddb55629 mcs: Compare with time in assigned core
All time for an SC should be relative to its assigned core. Any
operations which may occur on an SC on a remote core must explicitly
refer to that core.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-04 11:58:42 +10:00
Curtis Millar
1d419f6904 mcs: SC time relative to assigned core
The starting and ready times for any SC should be relative to the core
on which the SC is running rather than the current core.

Signed-off-by: Curtis Millar <curtis.millar@data61.csiro.au>
2020-05-04 11:58:42 +10:00
Rafal Kolanski
d7c35bf6a3 riscv: tweak frame remap errors again
When attempting to remap a frame, and we find a page table in the slot
we are intending to use, return DeleteFirst to the user, to match
verification specs.

This check is redundant, as lookupPTSlot does not stop on page table
PTEs.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-28 15:00:42 +10:00
Rafal Kolanski
4a8b9edb8f riscv: add return in decodeRISCVFrameInvocation
Previous change to return values accidentally removed it.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-28 07:37:50 +10:00
Rafal Kolanski
bc5ef019f9 riscv: change vaddr mismatch for frame remap error
seL4_IllegalOperation is not the appropriate error for attempting to
supply a mismatching vaddr for a frame remap. Return
seL4_InvalidArgument with the corresponding argument number.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-27 23:19:01 +10:00
Rafal Kolanski
9a58a37d64 riscv: fix ASID check for remapping a frame
In decodeRISCVFrameInvocation, in the RISCVPageMap case doing a remap,
the ASID check should check the ASID of the frame cap against the ASID
of the vspace. Currently it checks the ASID of the vspace against the
ASID of the vspace, which always succeeds.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-27 23:19:01 +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
Curtis Millar
a5de16d04e mcs: bind SC last in ThreadControlSched
This changes the order in MCS of ThreadControlSched:

1. Bind the fault handler
2. Set priorities
3. Bind or unbind scheduling contexts

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
Gerwin Klein
2b50d66587 riscv: tweak unmapPageTable loop
Prefer unsigned word arithmetic over signed for nicer proofs.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-04-26 16:42:34 +08:00
Gerwin Klein
9100cadb51 riscv: reorder setMR to align to enum
Aligning the order of setMR writes to the enum order avoids having
to prove that the operations commute.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-04-24 14:50:58 +08:00
Gerwin Klein
c0fae570a9 riscv: refactor for easier verification
Sequences of memory writes that correspond to one atomic spec operation
are time consuming in the proof. This commit refactors two of these to
make verification smoother. It also sets the (unused) mapped address of
top-level PageTableCaps to 0 as expected in the proofs.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-04-24 10:04:57 +10:00
Rafal Kolanski
ff9f2da132 riscv: performASIDControlInvocation ghost updates
Verification requires ghost state updates for the typed heap. Pull these
in from x86.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-24 02:17:26 +10:00
Rafal Kolanski
7ad699e4fb riscv: check type of cap before checking if mapped
In decodeRISCVMMUInvocation, in the asid_pool_cap case, the first extra
cap is supplied by the user. Before asking whether the page table cap is
mapped, we should check it is a page table cap.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-22 04:35:21 +10:00
Rafal Kolanski
869dc4a4c0 riscv: change top-level page table unmap check
The basic model of seL4 system calls is decode+perform. To be a
refinement of higher-level models, we cannot in a decode decide that
everything is fine, but we will do nothing.

In this case, we need to ensure the page table being unmapped is not a
top-level page table, by looking up the ASID. A page table that isn't
mapped does not have a stored ASID. performPageTableInvocationUnmap is
capable of handling this and there is no need to early-exit from
decodeRISCVPageTableInvocation.

We proceed with performing an unmap on a non-mapped page table
regardless, and only check for being a top-level page table in the
mapped case.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-22 04:35:21 +10:00
Gerwin Klein
038d1fcd6d riscv: fix page mapping bug
Previously, it was possible in decodeRISCVFrameInvocation for the rwx
rights of the new PTE to become 000 after masking with cap rights. This
would turn the frame PTE into a page table PTE instead, and allow the
user to create almost arbitrary mappings, including to kernel data and
code. The defect was discovered in the C verification of the RISC-V
port.

This commit changes the PTE to an invalid PTE in that situation, which
has the same effect (faulting when accessed) as mapping a PTE without
rights has on the other supported architectures.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-04-21 18:46:20 +08:00
Gerwin Klein
9181beb963 riscv: avoid undefined access in lookupPTSlot
The function getPPtrFromHWPTE is not applicable to invalid PTEs, so
this commit refactors the loop such that the the access is guaranteed
to be guarded by the corresponding isPTEPageTable check.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-04-21 14:54:54 +08:00