Commit graph

1409 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Rafal Kolanski
1fba3d9e68 riscv: DONT_TRANSLATE modifies_sip
To prevent a contradiction, the C parser does not allow a function to
claim both what it modifies and possess a body that may modify something
else. Instruct the C parser to not translate it in order for the
MODIFIES clause to take precedence.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-17 23:47:34 +10:00
Rafal Kolanski
b903cb7372 riscv: provide MODIFIES for read_sip
read_sip does not modify any state

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-17 22:33:22 +10:00
Rafal Kolanski
1f93e0508d riscv: tweak Arch_isFrameType argument name
It was 'type' on all other arches, but 't' on riscv. Being consistent
here means we can have the same proof for all arches.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-17 22:33:20 +10:00
Kent McLeod
c47b49a009 hifive: Expose seL4_IRQControl_GetTrigger API
This method is a no-op for the hifive platform as all of its interrupts
are positive-level triggered. But we expose the API so that the verified
configuration can include this API method to make it easier to support
different RISC-V platforms under verified configurations in the future.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-04-17 17:55:55 +10:00
Kent McLeod
9f5733e159 riscv: Fixup EXCEPTION_MESSAGE definition
The seL4_UserException_Number field of the seL4_UserException_Msg is set
explicitly in setMRs_fault with the saved value of scause from when the
exceptioin was taken.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-04-16 15:19:54 +10:00
Gerwin Klein
06928c1a03 riscv: cap_get_archCapIsPhysical unreachable case
The spec expects cap_get_archCapIsPhysical to return false for the
unreachable case. While we could prove that the case is unreachable in
all contexts the function is called, it needs fewer (=no) preconditions
when it provides a safe default instead.

Signed-off-by: Gerwin Klein <gerwin.klein@data61.csiro.au>
2020-04-12 21:15:54 +10:00
Rafal Kolanski
f42632ec46 riscv: change vm_fault_type_t to word_t
This makes riscv consistent with other platforms.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-11 01:12:56 +10:00
Kent McLeod
7cc1142c7a aarch64,vcpu: Add CNTKCTL_EL1 register to vcpu_t
This register is accessible from EL1 and affects whether Generic Timer
registers are accessible from EL0. When switching out of guests, the
kernel needs to restore the correct access for native threads.

Signed-off-by: Kent McLeod <Kent.Mcleod@data61.csiro.au>
2020-04-09 15:52:31 +10:00
Rafal Kolanski
451535a8b1 riscv: use same vm_rights as x86 for caps
Rights on frame caps differ somewhat between architectures, not entirely
in consistent ways. An example is handling write-only frame rights,
where riscv departs from x86. The vm_rights enumeration is not dictated
by hardware, hence we should strive towards consistency.

This change removes VMWriteOnly and makes riscv vm_rights and rights
masking match x86, to facilitate verification of riscv with reduced
proof changes. It does for the time being remove the ability for
write-only frames on riscv.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-09 13:03:37 +10:00
Rafal Kolanski
78bf170b21 riscv: use 2 bits for capFVMRights
vm_rights is an enumeration with 4 entries, which like on other
platforms requires 2 bits to store. Make riscv consistent with other
platforms.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-07 11:04:22 +10:00
Saer Debel
a221ee1ca8 Enabled IPC debug features under new config
Introduced a new config flag to enable
userError format strings to be written to the IPC buffer.
Another config bool has been introduced to toggle
printing the error out and this can also be set at runtime.

Signed-off-by: Saer Debel <saer.debel@data61.csiro.au>
2020-04-06 14:21:46 +10:00
Saer Debel
9dad7382e1 userError string written to IPC buffer
The format string in userError is now written to
the IPC buffer for debugging purposes.
This requires an snprintf which reuses vprintf with
a new structure for handling how output is done.

Signed-off-by: Saer Debel <saer.debel@data61.csiro.au>
2020-04-06 12:57:04 +10:00
Rafal Kolanski
0548f8d7e9 riscv: use word_t rather than "unsigned int"
For other platforms, word_t is used for passing length and size
parameters and adapts to 32 and 64-bit platforms appropriately.
The riscv platforms stands out by using "unsigned int" unlike the
others.

Reduce usage of "unsigned int" to match the other 64-bit verification
target platform, x86 64-bit.

Signed-off-by: Rafal Kolanski <rafal.kolanski@data61.csiro.au>
2020-04-04 22:14:53 +11:00
Siwei Zhuang
dda85f2cec riscv: Add cache function prototype
The function arch_clean_invalidate_caches() is required by kernel
benchmarking feature. Add the function prototype as a placeholder, not
yet implemented.

Signed-off-by: Siwei Zhuang <siwei.zhuang@data61.csiro.au>
2020-03-27 17:25:13 +11:00
Siwei Zhuang
f438fa0f31 riscv: Remove encoding.h
encoding.h was for ISA simulators originally. It's copied from
riscv-tools which is deprecated. It becomes difficult to maintain the
file. Besides, we merely need 6 lines of code out of this large file. So
redefine what we need in hardware.h and remove encoding.h
2020-03-24 13:46:36 +11:00
Siwei Zhuang
ee30ba6faf riscv: Rename sptbr to satp
The sptbr register is renamed to satp in RISCV privilege spec v1.10. We
kept using sptbr for old compiler versions. All compilers we use support
the new name now. There's no reason to keep the old name.
2020-03-24 13:42:48 +11: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
Kent McLeod
ae2b9bf89f hifive.h: Switch inline asm to c for mmio ops
The verification tooling is able to parse the semantics out of C data
accesses, but not if it is inline assembly.
2020-03-20 10:13:12 +11:00
Gerwin Klein
82b79f5117 remove unused prototypes
Removed two unused declarations that referred to the
removed recycle operation.
2020-03-11 20:20:09 +08:00
Luca(Wei) Chen
0769d05f1e trivial: fastpath: add config for declaration
c_handle_fastpath should only be declared for fastpath config.
And also fix the style and docs.
This change will not affect the result of compilation.
2020-03-11 09:29:11 +11:00
Luca(Wei) Chen
2b63cd9afe fastpath: fix for ARMv6 with gcc8
Couldn't pass seL4test on ARMv6 due to using FORCE_INLINE.
Replace to static inline will fix it and still got inlined.
Keep FORCE_INLINE for other platforms since inline is broken
on gcc and we have to make sure those functions got inlined.
2020-03-11 09:29:10 +11:00
Gerwin Klein
996e1624f3 Manually tag missing 3rd-party licenses
Two files were previously ignored in the license check.
2020-03-09 17:59:07 +08: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
Luca(Wei) Chen
99c7ff898e fastpath: reorganize the code layout on ARM
fastpath_call and fastpath_reply_recv got inlined into a single
function. This could cause loading unused code in cache and
additional jump instructions required in c_handle_syscall.
2020-03-02 13:32:35 +11:00
Anna Lyons
c4fe536984 arm: remote IPI call support for VIRQS
Added support for injecting remote IPI calls towards given VCPU's
on SMP configured systems. This introudcing a new type of
IpiRemoteCall and handlers for updating the vgic state on
incoming/outgoing IPI's.

Co-authored-by: Yanyan Shen <yanyan.shen@data61.csiro.au>
2020-02-20 12:53:04 +11:00
Alison Felizzi
bddd405417 arm: Added define for VMPIDR and VMPIDR_EL2
Added constant definitions for the VMPIDR (arm32) and VMPIDR_EL2
(arm64) registers. These being vcpu registers that can be
written, read, saved and restored. The 'Virtualization Multiprocessor
ID Register' (VMPIDR) is needed to program a vcpu's affinity during
initialisation. This is currently only exposed on SMP configurations.

Co-authored-by: Anna Lyons <anna@gh.st>
2020-02-20 12:52:59 +11:00
Rafal Kolanski
d5294a32b3 arm-hyp: change VPPIEvent irq bitfield to 10bit
Truncation to 10 bits is therefore handled by bitfield generator, making
correspondence with more abstract verified specs easier, as they use a
10-bit word to represent IRQs on 32-bit ARM platforms.
2020-02-20 11:41:00 +11:00
Rafal Kolanski
ebbd5ce97c arm-hyp: rename irq field of VPPIEvent to irq_w
Interferes with C parser variable order, want irq_t irq to be short
name.
2020-02-20 11:41:00 +11:00
Rafal Kolanski
01514662b7 arm-hyp: provide MODIFIES info for DONT_TRANSLATE
C parser cascades up DONT_TRANSLATE blocking modifies proofs, unless
some kind of spec is provided. This makes the claim that the timer
register getters don't modify any global state, and the setters modify
only state verification does not care about.
2020-02-20 11:41:00 +11:00
Kent McLeod
232b0e86b5 arm_hyp: Move PGD definitions out of libsel4
The PGD constants refer to the top level mapping object used by the
kernel for its own private mappings. Userlevel cannot create any PGD
objects and so these constants don't belong in libsel4.
2020-02-20 11:41:00 +11:00
Alison Felizzi
0e05f416ae arm: Configure traps on vcpu WFE/WFI calls
Configure the ability to trap on vcpu WFE/WFI calls. If enabled,
user-level would need to schedule a future interrupt when a given
vcpu invokes a WFE/WFI instruction. This otherwise leaving the
vcpu in a disabled state. An application can choose to
disable the trap if it doesn't want to handle the instruction and
schedule a future interrupt.
2020-02-20 11:40:59 +11:00
Alison Felizzi
71d636f8b3 arm_hyp: Save and restore vtimer state on switches
Added support for reading and writing additional virtual timer
registers for vcpu hw read and write accesses. These include the
compare value register (CNTV_CVAL) and offset register (CNTV_OFF),
each represented as two 32 bit (high and low) registers on aarch32 and
as single 64 bit registers on aarch64.

Added support for explicitly saving and restoring the virtual
timer registers when the vcpu is enabled and disabled. This
ensures when the vcpu is switched in and out, the virtual timer
registers are restored to a state that is consistent to when
it was last run.

By default the CNTVOFF register will be updated by the kernel to
accumulate the time the VCPU is not running. From the guest this will
result in the VCNT register not increasing when the VCPU is suspended.
This behavior can be turned off by disabling the
KernelArmVtimerUpdateVOffset config option.
2020-02-20 11:40:59 +11:00