Commit graph

4624 commits

Author SHA1 Message Date
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
Gerwin Klein
8f88c958fc utils: safer str_to_long
Make str_to_long more defensive against malformed content, since this
function runs on user (cmd line) input on x86. The input is from boot
time, i.e. trusted, but the function should still be memory safe.

This change does not fix overflow issues which may still lead to
undefined behaviour.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-10-15 14:28:59 +11:00
Gerwin Klein
ff3e7ff93e aarch32: remove unused functions
getKernelStack() is never called, and readHTPIDRO() was only called in
getKernelStack(). readTPIDRPRW() is only used in hyp configurations.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2024-10-14 17:45:42 +11:00
Alwin Joshy
9080b6844b invocations_all.json: define remove_prefix()
We relied on str.removeprefix(), which is only available in
python >= 3.9. To make this script more portable, we add our
own implementation.

Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2024-10-07 16:55:54 +11:00
Alwin Joshy
ca0edeaeab invocations_all.json: make paths explicit
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2024-10-07 16:55:54 +11:00
Alwin Joshy
bd1c392409 Export invocation numbers to JSON file
Co-authored-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>

tmp
2024-10-04 09:06:02 +01:00
Ivan Velickovic
85aa104eb4 Fix TCB size on RISC-V 32-bit when FPU is enabled
This configuration is not in CI (hence why it lead to
a build error in the first place) so I just tested
it locally via sel4test with:

```
../init-build.sh -DPLATFORM=qemu-riscv-virt \
                 -DMCS=1 -DKernelRiscvExtD=1 \
                 -DKernelRiscvExtF=1 -DRISCV32=1
```

and it passed.

Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
2024-09-16 12:31:52 +01:00
Wanja Zaeske
05858be490 feat: add riscv-none-elf- as valid RISCV prefix
Fixes #1309

Signed-off-by: Wanja Zaeske <wanja.zaeske@dlr.de>
2024-08-14 15:33:19 +02:00
Ivan Velickovic
534ea259d3
Print virtual address already mapped in user error (#1304)
Print virtual address already mapped in user error

Co-authored-by: Axel Heider <axel-h@users.noreply.github.com>
Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
2024-08-13 20:29:39 +02:00
Michael McInerney
c679fe77d6 mcs: use local variable in postpone
This eases verification by using a local variable
which remains unchanged during execution of the
function.

This preserves semantics since tcbSchedDequeue
will not modify the scTcb field of the given sc.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2024-07-19 19:13:48 +10:00
Alwin Joshy
1253115999 hw debug api: aarch64 port
Adding support for the hardware debug API to
aarch64.

Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2024-07-18 16:09:52 +10:00
Alwin Joshy
b3974732b9 hw debug api: modify single stepping checks
On aarch32, single stepping is configured by setting an instruction
breakpoint to mismatch mode. The way that it is checked whether a
given breakpoint is being used as a normal breakpoint or for
single-stepping is by checking if it has been configured to mismatch.
This works because the HW debug API does not currently provide a way
to otherwise configure mismatch breakpoints, but seems like an
unsatisfactory solution. Whether single-stepping is enabled, and
the breakpoint that is being used for it is already stored in the
TCB of a thread, and this commit changes checks related to
single-stepping to use this information instead.

Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2024-07-18 16:09:52 +10:00
Alwin Joshy
28ffc62f74 aarch32: change dbg register fields
Changing the debug register fields to what they are referred to
as in the ARMv7 and ARMv8 manuals. Mostly a cosmetic change,
but improves clarity.

Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2024-07-18 16:09:52 +10:00
Alwin Joshy
c35930f565 change files to allow compilation
Signed-off-by: Alwin Joshy <joshyalwin@gmail.com>
2024-07-18 16:09:52 +10:00