Commit graph

1673 commits

Author SHA1 Message Date
Kent McLeod
cb8ee83f0c aarch64,vspace: Remove pud cap type
Now the vspace_cap is used for all vspace roots and all other page
tables are referred to by page table caps.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-08-10 08:20:22 +10:00
Kent McLeod
dc808b3d76 aarch64,vspace: Rename pgd cap to vspace cap
This is already what's presented at userlevel. Now the underlying kernel
cap reflects the same name.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-08-10 08:20:22 +10:00
Kent McLeod
b3cc852425 aarch64,vspace: Remove page_directory captype
The page_table cap is used in it's place.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-08-10 08:20:22 +10:00
Kent McLeod
5b00dff656 aarch64,vspace: Merge pgde_t type into pte_t type
Finish combining different page table types into a single type.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-08-10 08:20:22 +10:00
Kent McLeod
fc4ee3f931 aarch64,vspace: Merge pude_t type into pte_t
Next step is to merge pude_t type.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-08-10 08:20:22 +10:00
Kent McLeod
dad370959f aarch64,vspace: Merge pde_t into pte_t
Remove the pde_t type and replace all usages with pte_t.
This doesn't remove the page directory cap type yet. Now the page
directory cap refers to a table of pte_t entries and is treated the same
as the object that a page table cap refers to.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-08-10 08:20:22 +10:00
Kent McLeod
629c60d0a0 aarch64,vspace: Setup single pte_t type
This first commit only handles 4k pages.
4k pages are mapped using level 3 descriptor formats which annoyingly
have an opposite type definition (bit[1]) from all other levels. At all
other levels, a bit value of 0 is page and 1 is table. At level 3, a bit
value of 1 is page (and there is no bit value for a table).

This prevents us from using a single tagged-union type definition for
all page table descriptor definitions. For now we treat 4k pages as
special and try and push on ahead with the single type definition
anyway.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-08-10 08:20:22 +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
Axel Heider
5091e5313d doc: fix typos
Co-authored-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
Signed-off-by: Axel Heider <axelheider@gmx.de>
2023-06-08 12:47:14 +10:00
Kent McLeod
7fec9bc9e9 Add CONFIG_X86_64_VTX_64BIT_GUESTS guards
Guard the new implementation of 64-bit x86 guests behind a config
option. This is done so that existing projects that use x86_64 hosts
with ia32-bit guests can continue to be supported until either the old
feature is preferred to be deprecated, or support can be added to
support both simmultaneously.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-06-06 13:29:34 +10:00
Chris Guikema
2dbd1b818a 64-bit-vms: Add kernel support for 64-bit VMs
This commit combines a number of smaller commits which do the following:

    * Enter IA-32e mode when running a 64-bit host
    * Handle additional general purpose registers in 64-bit mode
    * Handle 64-bit specific MSR events
    * Properly save and restore FS, GS, and Shadow GS registers

CCDC-GVSC DISTRIBUTION A.  Approved for public release; distribution
unlimited. OPSEC#4481.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-06-06 13:29:34 +10:00
Gerwin Klein
35c41a822f macros: avoid breaking C subset
__builtin_offsetof is not part of the verification C subset -- avoid
accidental use by not declaring a macro for it and filter out the
single use by explicitly marking it as invisible to verification.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-05-31 14:55:57 +10:00
Gerwin Klein
94d393418e gic_v3: _Static_assert is not supported
Prefer compile_assert over _Static_assert. The latter is only available
in C11, and the verification demands C99.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-05-31 13:30:07 +10:00
JorgeMVP
b544529615 generc_timer: enable only once for mcs/non-mcs
Enable the timer only at initialization and since it is always
enabled. It is not needed to be re-enabled.

Signed-off-by: JorgeMVP <jorgepereira89@gmail.com>
2023-05-25 20:42:02 +10:00
JorgeMVP
62c8148268 generic_timer: force timer to de-assert irq
Generic Timer IRQs are level-sensitive, when the CNT_TVAL
is updated the trigger condition is de-asserted and the
change is propagated to the GIC in a finite time to clear
the pending state.

However, we have to make sure the timer deasserts before
EOIR/DIR, otherwise the interrupt happens again. Therefore,
we need an isb() to cause the timer to de-assert before EOIR/DIR.

There is also a chance of spurious IRQ. A spurious IRQ can be
generated, in the case we have a level-sensitive IRQ, and its
pending state is cleared at device-level but not yet propagated
to the GIC. In between the IRQ deactivation and IRQ ack of the
new interrupt if the requested change from the timer gets propagated
then it causes a spurious IRQ.

Signed-off-by: JorgeMVP <jorgepereira89@gmail.com>
2023-05-25 20:42:02 +10:00
Ivan-Velickovic
8c9cf6c7db Remove VMKernelReadOnly from AArch64 VM rights
In the interest of stability and not breaking
things, the value of VMReadOnly remains the same.

Signed-off-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
2023-05-25 14:48:37 +10:00
JorgeMVP
a681fb9755 gic_v3: AP1R for group 1 IRQs
- In non-secure world, group 1 IRQs are used instead of group 0.
Signed-off-by: JorgeMVP <jorgepereira89@gmail.com>
2023-05-08 20:46:22 +10:00
Kent McLeod
8402de52db aarch64: Add option for user cache maintenance
Add a config option, KernelAArch64UserCacheEnable, that enables user
level access to DC CVAU, DC CIVAC, DC CVAC, and IC IVAU which are cache
maintenance operations for the data caches and instruction caches
underlying Normal memory and also access to the read-only cache-type
register CTR_EL0 that provides cache type information. The ArmV8-A
architecture allows access from EL0 as fast cache maintenance operations
improves DMA performance in user-level device drivers.

These instructions are a subset of the available cache maintenance
instructions as they can only address lines by virtual address (VA).
They also require that the VA provided referrs to a valid mapping
with at least read permissions. This corresponds to lines that the
EL0 could already affect via regular operation and so it's not expected
to break any cache-partitioning scheme.

The config option allows this policy to be selected for a particular
kernel configuration, but it is default enabled as this has been the
existing behavior for current aarch64,hyp configurations and have not
been explicitly disabled in non-hyp configurations.

Signed-off-by: Kent McLeod <kent@kry10.com>
2023-04-25 15:49:28 +10:00
Kent McLeod
57ca89d68e trivial: Fix typo of UCT bit in SCTLR_EL1
Signed-off-by: Kent McLeod <kent@kry10.com>
2023-04-25 15:49:28 +10:00
Axel Heider
55dc30b4a6 boot/risc-v: avoid uncommon fence usage
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2023-04-23 22:26:19 +10:00
JorgeMVP
b8f1753d64 ipi: add missing barrier and enforce completion
- dmb() no longer works for GICv3, and consequently
a stronger barrier like dsb() has to be used. A weaker
variant of dsb is used to ensure the observability of
complete stores in the same inner-shareable domain.

Signed-off-by: JorgeMVP <jorgepereira89@gmail.com>
2023-04-23 15:00:48 +10:00
JorgeMVP
a4b591727a arm64: add required isb() between AT and PAR inst
- "When an address translation instruction is executed,
explicit synchronization is required to guarantee the
result is visible to subsequent direct reads of PAR_EL1."

Signed-off-by: JorgeMVP <jorgepereira89@gmail.com>
2023-04-23 14:59:35 +10:00
JorgeMVP
a7845d297d gic_v3: fix offset for gicd iroutern mem-map reg
GICD_IROUTERn is at the offset 0x6100 for SPI 32.
SGIs and PPIs do not have a target since they are private to CPUs.
Signed-off-by: JorgeMVP <jorgepereira89@gmail.com>
2023-04-14 18:18:50 +10:00
Gerwin Klein
ca1d5f9226 machine: compile time checks for multikernel
Add compile time checks for conditions on physBase that are necessary
for verification of multikernel builds to succeed -- if these fail, the
proofs will fail.

If these succeed, and nothing else has changed compared to a verified
kernel other than physBase, then the proofs will succeed. This does not
mean that all platform requirements are validated, it just means that
all requirements for the proofs to be consistent are met.

The conditions correspond to those in

    spec/machine/*/Arch_Kernel_Config_Lemmas.thy

in the verification repository.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-12 15:56:26 +10:00
Gerwin Klein
51966d4508 boot: document region types
Mention that it can be Ok for regions to overflow. State explicitly
that the end is exclusive.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2023-04-12 15:07:02 +10:00
Alwin Joshy
f8b2440b38 Implemented the vm fault fastpath on aarch64
This fastpath optimizes the performance of VM faults in
seL4. It is heavily based on the existing seL4_Call
fastpath and includes the addition of fastpathing replies
to faulted threads in the seL4_ReplyRecv fastpath.
Currently only supported only implemented for aarch64.

Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2023-03-08 17:58:14 +11:00
Rafal Kolanski
65a1b457a4 make physBase a static inline function
For verification flexible w.r.t kernel placement in physical memory, we
need to relate physBase as a named constant to its abstract equivalent.
Unfortunately, apart from enums, the C programming language does not
have real constants. The C parser follows the C standard and requires
enums constants to be storable as int, meaning without major overhaul
enums are not sufficient for storing word_t-sized memory addresses.

Since the linker scripts can't deal with static inline functions
in the constants they need (KERNEL_ELF_BASE and KERNEL_ELF_PADDR_BASE),
we provide the following preprocessor definitions for the linker
specifically:
* PHYS_BASE_RAW (the numerical value returned by physBase())
* KERNEL_ELF_BASE_RAW
* KERNEL_ELF_PADDR_BASE_RAW

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2023-03-07 14:29:14 +11:00
Chris Guikema
b99e1ba325 rocketchip-zcu102: use plic0
On the ZCU102 Rocketchip instantiation, the PLIC is available required
to use hardware peripherals like a UART

Signed-off-by: Chris Guikema <chris.guikema@dornerworks.com>
2023-02-22 09:35:14 +11:00
Axel Heider
d14c53974c user proper field from thread context structure
The thread context structure layout is explicitly designed to have the
register context first, as this simplifies saving the user context on
entry in assembly code. On the exit path there is no need to hard-code
this assumption, stick to the semantics and leave details to the
compiler.

Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2023-01-13 10:22:28 +11: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
Axel Heider
838b9a4331 risc-v/plic: support rv32 targets
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2022-12-03 08:21:29 +11:00
Axel Heider
548a81a057 riscv: support qemu-riscv-virt platform
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2022-11-13 11:53:54 +11:00
Axel Heider
1e38178832 aarch32: fix define check
Fix wrong name used in refactoring of commit 4b491dcf

Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2022-11-11 13:52:25 +11:00
Axel Heider
72aeea983a boot/arm: remove activate_global_pd usage
activate_global_pd is just an alias for activate_kernel_vspace nowadays

Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2022-11-11 09:03:57 +11:00
Axel Heider
b07d653bdb boot: remove unused return values
Remove the return value from configure_sched_context(), because it never
fails. As a consequence, create_idle_thread() also never fails and does
not need a return value.

Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2022-10-30 19:54:02 +11:00
Indan Zupancic
2a8c9683f3 MCS, SMP: Add clock synchronisation test
Because ksCurTime is compared cross-node now, time across
nodes must be the same. Check this once during boot.

Replace __atomic_signal_fence with the more correct
__atomic_thread_fence, as ksNumCPUs will be changed
cross-node.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2022-10-28 10:39:30 +11:00
Indan Zupancic
04c096128b Cleanup refill_new
Remove the now unused core argument from refill_new and replace all
REFILL_NEW calls with direct calls.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2022-10-28 10:39:30 +11:00
Indan Zupancic
ba262f6d75 Do not use cross-node ksCurTime
The code using ksCurTime assumes that ksCurTime is up-to-date,
but this assumption is wrong for ksCurTime of other CPU cores.
Those can be quite some time in the past.

The implications of using NODE_STATE(ksCurTime) is that clocks
on all cores must be synchronous:

- Riscv is okay: The specification states: "The real-time clocks
  of all hardware threads in a single user application should be
  synchronized to within one tick of the real-time clock."
- x86 okay if not ancient when Invariant TSC is supported.
- aarch64 is okay.
- arm32: arm_global.h is okay. Exynos timer seems okay. am335x and
  omap3430 are single-core.

See also #854.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2022-10-28 10:39:30 +11:00
Axel Heider
0c8c386394 fastpatch: use thread passed as parameter
Use the thread passed as parameter instead of making assumption that
this is in sync with the global state.

Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2022-10-28 09:20:47 +11:00
Axel Heider
9c083b84ef make macro less obscure
- explicitly mention the parameter to make macro less obscure.
- add brackets to make the expression an atom.

Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
2022-10-01 10:16:32 +02:00
Yanyan Shen
e4c5bf242c aarch64: Use isb after changing FPU ctrl registers
Signed-off-by: Yanyan Shen <yshen@hybridkernel.com>
2022-09-22 10:13:13 -07:00
Axel Heider
6dd3a18065 re-use existing functions to avoid redundancy
Signed-off-by: Axel Heider <axelheider@gmx.de>
2022-09-15 11:25:04 +02: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
Peter Chubb
d84f3fcb4a Add newer Skylake model ID
At least some server-class Skylake processors use 0x55 as
their model ID.
These are Skylake X processors.

Signed-off-by: Peter Chubb <peter.chubb@unsw.edu.au>
2022-07-29 17:01:32 +10: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
FinnZhang
dd2a435722 fix arm64 address space graphic in comment
Signed-off-by: FinnZhang <finnzhang@outlook.com>
2022-06-29 16:12:05 +10:00
Ryan Barry
4ce6cbe9ea Don't clobber msgInfo register
The messageinfo register is set to 0 after processing a kernel object
invocation if the invocation set the thread state to restart. This is a
problem if the kernel object invocation had also set the message info
register.

The existing convention in this case is for the kernel invocation to
set the thread state to running right before it returns to avoid the
problematic code path. However, there are some invocations that do not
follow this convention and their message info register gets clobbered.
There are also some invocations that set message registers without
setting the message info register at all, or that do not guard their
message register updates with a call parameter.

This commit fixes these issues modulo setConsumed, which we defer to a
later point.

Co-authored-by: Jimmy Brush <code@jimmah.com>
Signed-off-by: Ryan Barry <ryan.barry@proofcraft.systems>
2022-06-17 15:31:10 +10:00
Rafal Kolanski
b8ef00e09a arm: don't do S1 translation in Arch_setMRs_fault
For a VM fault in a hypervisor context, 32-bit Arm translated the IP
address into an IPA, while 64-bit Arm did not. The previous commit
made these consistent by performing the translation on both.

After investigation and discussion, the 32-bit Arm behaviour was
declared a bug: reporting an IPA (instead of a VA) to the VMM is not
very useful and can cause issues when the fault message is not sent
immediately (SELFOUR-1602). This commit, therefore, removes all stage 1
translation from Arch_setMRs_fault on Arm platforms.

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-06-06 10:10:49 +10:00
Rafal Kolanski
fce5cece4d arm: consolidate stage 1 translation function use
This commit introduces `addressTranslateS1` to be used on Arm platforms
with hypervisor enabled for stage 1 (vaddr to IPA) translation. On
AArch32 this is a rename from `addressTranslateS1CPR`, and on AArch64 it
wraps `ats1e1r`. This changes the ABI on AArch64 to report faulting
address as IPA.

Reasoning:

With hypervisor enabled, AArch64 defined `addressTranslateS1CPR` to do
nothing, while AArch32 defined it to do stage 1 translation. This
delivered VM faults to the user with the faulting address being either
an IPA or a vaddr depending on mode. This inconsistency is undesireable.

This commit proposes adjusting the inconsistency to match AArch32
behaviour, as it is one of the verified platforms.

Signed-off-by: Rafal Kolanski <rafal.kolanski@proofcraft.systems>
2022-06-06 10:10:49 +10:00
Indan Zupancic
4a7d08def0 MCS, ARM: Introduce TIMER_OVERHEAD_TICKS
For ARM currently TIMER_PRECISION exists, but that is in microseconds
and not fine-grained enough.

This is needed to make periodic tasks synchronous with the system clock.
If this value is zero every period will be extended with the overhead of
taking an interrupt and reading the system clock. To avoid this drift,
the configured value should be set to at least the average overhead.

See also issue #844.

Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
2022-05-23 16:31:45 +10:00