Commit Graph

4637 Commits

Author SHA1 Message Date
Gerwin Klein
478372b62d riscv: disable clock sync test on boot
Timer reads go via mmode on RISC-V, and the hifive board regularly fails
the clock sync test at boot because of that.

We could add a larger allowed delta, but the observed values so far are
up to 5us, so it is questionable what we then know after the test if we
do that. Disable for RISC-V instead.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-02-26 15:09:34 +11:00
Gerwin Klein
475f0911fc arm,gic_v3: consolidate types for verification
Verification requires inline assembly blocks to have consistent types.
In gic_v3 files, the `msr` and `mrs` instructions are used both with
uint32_t and uint64_t types, which causes the Isabelle C parser to fail.

According to the Arm GICv3 specification, the registers we are accessing
are all 64 bit registers. Some of them have the top 32 bits reserved as
res0. These are the ones that currently are used with uint32_t,
presumably for consistency with the corresponding gic_v2 functions.

To make the C parser succeed:

- for the SYSTEM_READ_WORD and SYSTEM_WRITE_WORD macros, use word_t or
  uint64_t
- for functions that are declared with uint32_t, leave the declaration
  intact, but use uint64_t internally for MSR with an explicit cast
  to/from uint32_t. This is the behaviour we are assuming the C compiler
  to have added implicitly before.

This commit does not change the fact that the gic_v3 virtualisation
functions assume a 64-bit architecture. For AArch32, word_t and uint64_t
may be incorrect.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-02-25 14:16:08 +11:00
julia
07be80478a riscv: rename incorrect level2_pt -> level1_pt
Since cdbae0b3b2, seL4 has used a
0-indexed naming for the levels of the page tables, starting
from the root (0) and down to the lowest level (2), for
CONFIG_PT_LEVELS=3.

However, the naming of the stored page table was never updated,
leading to a variety of confusing code such as:

    kernel_image_level2_dev_pt[RISCV_GET_PT_INDEX(vaddr, 1)] = \
        pte_next(paddr, true);

When CONFIG_PT_LEVELS=4, the entries of the level 1 page table
instead point to gigapages (1GiB) instead of megapages (2MiB).
This is the same as the previous behaviour.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-02-24 12:14:15 +00:00
Kent McLeod
5586c1193c gcc.cmake: Auto-detect riscv64-linux-gnu- tools
riscv64-linux-gnu- is supposed to be semantically equivalent to
riscv64-unknown-linux-gnu- but the names don't indicate whether the
toolchains have multilib support. At time of this commit,
riscv64-unknown-linux-gnu- is the default name given to the
multilib-capable riscv-toolchian installed via
https://github.com/riscv/riscv-gnu-toolchain.git so leaving it as a
higher priority.

Signed-off-by: Kent McLeod <kent@kry10.com>
2025-02-21 18:39:00 +11:00
Kent McLeod
bf3fbef460 riscv: Change default FPU extensions to ON
This changes the default configuration values of the build options:
KernelRiscvExtF and KernelRiscvExtD from OFF to ON.

The options control whether the kernel will support user applications
that use either of the floating point extensions. When these options are
off, FPU instructions will cause an exception.

Arm and x86 default FPU architecture support to ON and so this change is
making the default option consistent across architectures.

Signed-off-by: Kent McLeod <kent@kry10.com>
2025-02-21 18:39:00 +11:00
Ivan-Velickovic
ddad13cafd Improve print in handleSpuriousIRQ
Spend a couple minutes trying to decipher a weird
sip encoding until I realised it was in hex.

Signed-off-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
2025-02-18 10:58:37 +11:00
Gerwin Klein
c674b62a00 github: rename hardware test workflow file
The HW test workflow file is now responsible for multiple kinds of
hardware test.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-02-18 09:22:15 +11:00
Gerwin Klein
3c7c4d1182 github: add manual trigger where possible
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-02-18 09:22:15 +11:00
Gerwin Klein
c4e4b37fdf github: update name of deployment workflow
Disambiguate from seL4Test runs on pull requests.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-02-18 09:22:15 +11:00
Gerwin Klein
bbb2b6b6b7 github: factor out common workflows
The new reusable workflow feature of GitHub allows us to avoid
repeating the workflow definitions and collect them in the ci-actions
repo instead.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-02-18 09:22:15 +11:00
julia
7f91e0c5f6 libsel4: fix riscv ASIDcontrol param descriptions
Nowhere else in the documentation uses the phrase

    "Must be a depth of 32"

which seems incorrect for 64-bit riscv.

Also, the index parameter had the same description as root, which
is incorrect.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-02-12 11:00:03 +00:00
Nick Spinale
771130964f trivial: mcs: simplify implementation of cancelIPC
For the sake of making verification slightly easier.

Signed-off-by: Nick Spinale <nick@nickspinale.com>
2025-02-11 09:07:40 +11: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
Ivan-Velickovic
1cbaeb97f0 platform_gen: only generate regions that are used
Right now the `platform_gen.json` and `platform_gen.yaml` files contain
regions that are not actually used by the kernel. This is fine for
`platform_gen.h` because they are guarded by #ifdefs with kernel config
defines but the same approach does not work for YAML and JSON.

So, this patch changes the Python scripts that generate this files so
that they only generate the regions that actually end up being used.

Signed-off-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
2025-02-10 12:48:13 +11:00
julia
7f6d5c72aa riscv: remove breakpoint_stack from linker script
Presumably, this was copied from the common_arm.lds linker script,
but it was a particular implementation detail of the arm32 code,
and is unneeded on RISC-V.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-02-10 11:17:43 +11:00
julia
a13a358806 document & rename breakpoint_stack to abort_stack
Essentially, the `sp' register is banked between different PMODEs.

https://developer.arm.com/documentation/den0013/d/ARM-Processor-Modes-and-Registers/Registers

We initialise a stack that we will begin on when handling an exception.

Also, only include in the ARM linker script on AArch32 + non-hyp.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-02-10 11:17:43 +11:00
julia
697dfb8b9e riscv: catch s-mode traps and halt
These are never supposed to happen.
Note, that this will still use the kernel stack to save the registers
and so if page tables are corrupted, it will continually fault near the
trap_entry. But this is reasonably easy to tell from a debugger.

Not all traps will be handled via the s-mode trap handler; it depends on
the value of the `medeleg` register. This appears to default to 0xf0b509
(in QEMU) and so we can catch page faults.

Without this, traps in the kernel will be attributed to a trap of the
current running thread.

Previously, some kernel modifications that corrupted memory caused:

```
Caught cap fault in send phase at address 0
while trying to handle:
vm fault on data at address 0 with status ��7
in thread ��ffffffff8401bc00 "idle_thread" at address 0
With stack:
Invalid vspace
```

Now, the kernel prints out:

```
KERNEL ABORT (exception within s-mode)!
scause: 0xf, stval: 0x0
halting...
Kernel entry via Syscall, number: 1, Call
Cap type: 2, Invocation tag: 1
```

Signed-off-by: julia <git.ts@trainwit.ch>
2025-02-07 15:43:59 +00:00
Ivan-Velickovic
433c8144d8 config.cmake: fix depends line
Signed-off-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
2025-02-06 17:17:35 +11:00
Dr. Chang Liu, PhD.
edde814ceb aarch64: fix building with clang-18
On aarch64, clang interprets the compile option -mgeneral-regs-only
as disabling all FPU-related registers and instructions, which not
only include those generated by the compiler (which is how gcc would
interpret this option), but also those in (inline) assemblies written
explicitly by the programmer, which gcc does not forbid with this
option. This commit enables FPU-related registers and instruction
explicitly in the FPU-context switching code, so the kernel will build
under clang-18 on aarch64. The commit that changed the behaviour
between clang-17 and clang-18 is eabffc7 of the LLVM project.

Signed-off-by: Liu, Chang <cl91tp@gmail.com>
2025-02-06 09:58:32 +11:00
julia
7db2fc384d platform_gen.h.in: remove platform_interrupt_t sym
Presumably intended to be something like

    typedef enum IRQConstants { ... } platform_interrupt_t;

this instead declares a symbol that is exported and kept in the
binary, but is never used. Remove it.

Spotted as my kernel.elf binary contained a strange symbol:

    ffffffff8401b7f0  g O .bss 0000000000000004 platform_interrupt_t

Signed-off-by: julia <git.ts@trainwit.ch>
2025-02-04 10:11:24 +11:00
Matt Rossouw
e8c070cd35 Added initial support for Cheshire platform
Signed-off-by: Matt Rossouw <matthew.rossouw@unsw.edu.au>
2025-02-03 16:10:58 +11:00
julia
d96b447826 cmake: add riscv-none-elf- as valid gcc prefix
The previous commit 05858be didn't actually add it to both instances
of the if/else statement, and so doesn't actually work in all cases
(e.g. with `../init-build.sh`).

Signed-off-by: julia <git.ts@trainwit.ch>
2025-02-02 10:06:21 +00:00
Gerwin Klein
974e9ffb2e README: fix GettingStarted link for docsite update
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-01-31 13:04:49 +11:00
julia
dfd0853c5d vspace: userError for no unallocated ASID pools
This existed for ARM32, but not for ARM64, RISCV-V, or X86.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-01-31 08:59:25 +11:00
Gerwin Klein
1732c05ef6 github: pin Ubuntu 22.04 for deployment step
Python 3.12 in Ubuntu 24.04 has incompatible packages.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-12-19 17:42:27 +11:00
Michael McInerney
84163bd855 mcs: refactor refill_budget_check
This refactors refill_budget_check and schedule_used to
ease verification by limiting heap access via refill_head
and refill_tail, and providing (inlined) named functions
for both the condition and bodies of the loops.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2024-12-19 16:35:54 +11:00
Gerwin Klein
ae077fd738 tqma: remove virtualisation project settings
The settings KernelArmVtimerUpdateVOffset and
KernelArmDisableWFIWFETraps should be project settings, not platform
settings, and the values set here are not required for the platform to
work -- they just provide a different default.

Setting these in platform configs could lead to inconsistent project
builds when switching between platforms.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-12-19 11:48:44 +11:00
Gerwin Klein
7d493561cb github: pin style check to ubuntu-22.04
The default python version changes on ubuntu-24, which breaks the
version of cmake-format we are currently using.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-12-19 11:05:25 +11:00
Indan Zupancic
b7ce213654 Add i.MX93 SoC support
Signed-off-by: Indan Zupancic <indan@nul.nu>
2024-12-18 16:41:44 +11:00
Indan Zupancic
635d74639e Add fsl,imx7ulp-lpuart alias
Signed-off-by: Indan Zupancic <indan@nul.nu>
2024-12-18 16:41:44 +11:00
Yanfeng Liu
80e60fe397 manual/objects: clean garbage
This drops unnecessary `iz` text at chapter end.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-12-11 13:25:50 +11:00
Yanfeng Liu
5632069576 riscv/vspace.c: revise comments
This revises comments for `map_kernel_window()` to be in line with
the code.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-12-05 09:12:40 +11:00
Yanfeng Liu
b67ff0bcdf riscv/hardware.h: simplify RISCV_GET_PT_INDEX
This simplifies RISCV_GET_PT_INDEX by reusing RISCV_GET_LVL_PGSIZE_BITS.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-12-05 09:12:40 +11:00
Yanfeng Liu
5041edaad5 model/statedata.c: align idle thread block
Current TCB_PTR_CTE_PTR assumes that thread blocks are aligned at
BIT(seL4_TCBBits). However the idle thread blocks are aligned
differently at BIT(TCB_SIZE_BITS), thus TCB_PTR_CTE_PTR cannot be
used for idle threads.

This changes idle thread alignment to be consistent with standard
TCBs. Even though macros like TCB_PTR_CTE_PTR should not be used
for idle thread, verification assumes consistent alignment for all
TCBs.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-12-04 16:11:44 +11:00
Nick Spinale
24156aafc3 remove UNREACHABLE() from resolveAddressBits
The binary verification tools do not support __builtin_unreachable.

Signed-off-by: Nick Spinale <nick@nickspinale.com>
2024-12-04 15:23:38 +11:00
Yanfeng Liu
7c3bc020fa machine/capdl.c: fix memory corruption
This fixes memory corruption in `add_to_seen()` when watermark
equals to array length.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-12-04 10:02:35 +11:00
Nick Spinale
8b298285dc x86: initialize variables
Multiple versions of GCC were unable to determine that these variables
in decodeX86PortInvocation are initialized in all cases.

Oddly, this compilation failure was only observed with -O1. Compilation
with -O2 was not failing.

Signed-off-by: Nick Spinale <nick@nickspinale.com>
2024-12-03 16:22:46 +11:00
Ivan-Velickovic
e45d229601 Fix printing when IRQ is out of range
Signed-off-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
2024-12-03 08:56:47 +11:00
Yanfeng Liu
58674cdaec arch/riscv64: revise address space comments
This revises comments of virtual space mapping.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-11-27 09:20:25 +11:00
Szymon Duchniewicz
4b233815fd docs: README: Fix url to kernel features
Signed-off-by: Szymon Duchniewicz <s.duchniewicz@unsw.edu.au>
2024-11-22 18:33:13 +00:00
FennelFoxxo
e995b64653 boot: remove unnecessary reserve increment
The increment and reserve here is not an issue, but to keep
consistency with the change made in 291af86 we should remove it.

See PR #1317 for more info

Signed-off-by: James Martin <fennelfoxxo@gmail.com>
2024-11-17 11:00:24 +00:00
FennelFoxxo
4018ad5942 boot: fix init_freemem skipping reserved regions
In cases where the kernel is passed a very fragmented map of
available memory (specifically when booting from GRUB on x86),
it is possible for multiple available regions to overlap with
a single reserved region.

Currently, if there is an overlap
(where avail_reg[a].start >= reserved[r].start), the available
region is trimmed and the region index is incremented. This causes
any other overlapping regions to be handled as if they are
non-overlapping, since it's now looking at the next reserved region.
This eventually leads to reserved memory being passed to the root
task and can cause corruption issues if it is used.

It is fine to skip this index increment, since the available region
is now either empty or non-overlapping, and both cases are already
trivially handled.

Signed-off-by: James Martin <fennelfoxxo@gmail.com>
2024-11-17 11:00:24 +00:00
julia
d6b4e774ca riscv: Fix MAX_IRQ for QEMU platform
A better solution would be to parse the DTS; however QEMU
hasn't changed this in 6 years.

Signed-off-by: julia <git.ts@trainwit.ch>
2024-11-11 12:25:13 +00:00
julia
640643954c riscv: fix off-by-1 write for PLIC IRQ priorities
This produced 'sifive_plic_write: Invalid register write 0x180' in QEMU.
https://github.com/seL4/seL4/issues/1350#issuecomment-2464273308

Signed-off-by: julia <git.ts@trainwit.ch>
2024-11-11 12:25:13 +00:00
Matt Rossouw
65825d4df8 Re-enabled PLIC for Ariane
Signed-off-by: Matt Rossouw <matthew.rossouw@unsw.edu.au>
2024-11-06 10:02:41 +00:00
Yanfeng Liu
9edd2704ea manual: add CapSMC to table 9.1
This adds `seL4_CapSMC` to table 9.1 and updates section 9.1 so
that to be in line with latest upstream code.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-11-03 15:09:59 +00:00
Gerwin Klein
c5b23791ea configs: additional verified platforms
With recent proof improvements the proofs now apply to further platforms
in the ARM and AARCH64 configurations.

Refactor the verified configs to build on one include file per major
architecture which is then used for each platform with potentially
modified settings. Add path argument to `cmake_script_build_kernel`
macro to accommodate inclusion from different locations in the file
system.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-10-25 16:23:44 +11:00
Gerwin Klein
03ad568c89 move cache flush from untyped reset to retype
Do not perform cache flushing in clearMemory. Instead flush the cache
only for those object types where it is necessary, and only when the
object is retyped, not when the untyped cap is reset.

This reduces overall need for flushing and delays it to the point of
use. This should speed up boot time significantly, but may impact WCET,
because the largest flush is now the largest page size (e.g. 24) instead
of CONFIG_RESET_CHUNK_BITS (8). The user could already request a flush
of the largest page size before, though, so it this may not actually
impact WCET. Remains to be investigated.

Why this is safe:

- Flushing is only necessary for objects that are seen by other parts of
  the system, not for kernel-internal object. These objects are
  non-device frames (including IOMMU pages) and page tables. All other
  objects are only read/written by the kernel. Frames need to be flushed
  to RAM (as clearMemory did), because they could be seen uncached by
  devices. Page tables only to PoU for the page table walker.

- Before createNewObject in retype, these objects do not exist and
  cannot be seen by any part of the system. createNewObject is the point
  where new objects can become visible to the user.

- Theoretically, we could defer flushing further to the point where
  frames or page tables are mapped, but it is more complex to track
  whether a flush has already happened when they are mapped multiple
  times, whereas at retype the object cannot have been flushed already.

- The original implementation, before clearing memory was moved into
  reset untyped, also flushed at the same points.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-10-24 15:33:44 +11:00
Michael McInerney
5dd34db629 mcs: refactor cancelAllIPC and cancelBadgedSends
This factors out code from cancelAllIPC and cancelBadgedSends
by introducing the inline function restart_thread_if_no_fault

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2024-10-21 10:35:59 +11:00
Michael McInerney
7aac8a3053 mcs: use sc_active in commitTime
Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2024-10-17 20:01:08 +11:00