Commit graph

1832 commits

Author SHA1 Message Date
Michael McInerney
d16c975677 mcs: refactor finaliseCap to ease verification
This in particular introduces the function
schedContext_unbindReply, which is used within
finaliseCap, as well as invokeSchedContext_Unbind.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-02-16 14:13:14 +11:00
Ivan Velickovic
04db8cebcc x86: skip clock_sync_test on QEMU
Try detect if we are running as a guest based on the CPUID
and skip clock_sync_test if we are.

Similar as previous patches for skipping QEMU on ARM/RISC-V
but at run-time instead of build-time.

Tested with qemu-system-x86_64 using `-smp 4`, the test is now
skipped with regular QEMU as well as `-accel kvm`.

Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
2026-01-13 09:16:25 +10:00
Gerwin Klein
d648c5dd53 trivial: align for better readability
White space change only:

- left-align sizes within each block declaration
- min 2 spaces to separate field name from size

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-01-09 09:00:43 +11:00
Gerwin Klein
c9f3c64162 bf structs: eliminate BF_CANONICAL_RANGE #ifdefs
Eliminate #ifdefs for BF_CANONICAL_RANGE in bitfield specifications,
using the new field_ptr command. Use word_size expressions for some of
the padding fields to make clearer where the sizes come from.

The transformations in this commit are written to produce exactly
identical output for code and proofs. In some rare cases, padding
could in the future be rearranged to make more use of field_ptr, but
these edits would create code differences and are left for later.

It may now also be to share more blocks between generic 32 and 64
definitions if they only reference word_size. This is also left for
later to reduce noise.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-01-09 09:00:43 +11:00
Indan Zupancic
717cf90201 Aarch64: Drop ISBs in enableFpu/disableFpu
Doing an ISB is very expensive, about ~30 cycles on some CPUs,
so try to avoid them if possible.

For the writes to (most) system registers to be observed, a
'Context Synchronization event' needs to occur (see ARM DDI 0487
M.a §D24.1.2.2 / pD24-8367).

The kernel is not doing any FPU operations after disabling the FPU,
so there is never a need for an ISB there. Returning to user space
counts as a 'Context Synchronization event' and ensures the FPU enable
or disable has completed when user space starts executing.

An ISB after enabling the FPU is only needed in case the FPU was
disabled for the kernel and the kernel wants to do FPU operations
like saving or restoring the FPU state. The ISB ensures that the
FPU enable system register write is finished before FPU using
instructions are executed.

For Aarch64 non-HYP it is possible to disable the FPU for user space
(EL0), but keep it enabled for the kernel (EL1). This is done by
setting CPACR_EL1.FPEN to 1, which the code actually already did.

Aarch64 with virtualisation enabled is more complicated and needs
higher level changes to achieve the same, which aren't done here,
the change is limited to removing the ISB in disableFpu().

This partially fixes issue #1569.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-12-19 00:57:04 +00:00
Rihui Wu
b0567c4d1c benchmark: fix thread utils on riscv's fastpath
Signed-off-by: Rihui Wu <rihui.wu@unsw.edu.au>
2025-12-05 11:14:27 +00:00
Akif Ejaz
4f7d7b7376 Add support for the Banana Pi BPI-F3
Based on the SpacemiT K1 SoC

Signed-off-by: Akif Ejaz <akifejaz40@gmail.com>
2025-11-27 20:01:07 +01:00
Kent McLeod
9746e27615 aarch32: Allow compilation for cortex-a72
cortex-A72 can be run in aarch32 mode similar to cortex-a53.

Signed-off-by: Kent McLeod <kent@kry10.com>
2025-11-21 17:37:27 +11:00
Ivan Velickovic
0f497ab3a0 Disable clock sync test on QEMU RISC-V
This will sometimes fail when using QEMU RISC-V virt
with multiple cores, make the behaviour consistent as
QEMU ARM virt.

Given that QEMU is not intended to be a cycle accurate
simulator, I imagine that is why this does not reliably
succeed.

Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
2025-11-20 16:24:55 +11:00
Indan Zupancic
3cbd3b2e95 SGI, GICv3: Fix plat_SGITargetValid
Otherwise it is not possible to send SGIs to all cores on platforms
with non-contiguous Affinity values or more than 16 cores.

16 is the limit of the target list, which is only relevant when
sending an SGI to multiple targets at once.

Update the API documentation to reflect what's actually happening.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-11-18 16:00:12 +11:00
Corey Lewis
01c3487efd arm: flush vcpu when setting domain of a thread
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2025-11-16 19:52:27 +11:00
Corey Lewis
e558631c73 arm: flush vcpu when switching domain
This avoids information about vcpu state being leaked across domains.

Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2025-11-16 19:52:27 +11:00
Corey Lewis
2734df9217 arm: remove misleading comment
The compile error for exposing vcpu_t could be easily fixed, the real
issue is the functions not existing when HYP is disabled.

Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2025-11-16 19:52:27 +11:00
Julia Vassiliki
7099f9d543 aarch64: fixup address space layout docs for hyp
Fixes #957

I removed the notes about TK1 since it's not just TK1.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
2025-11-10 23:47:39 +00:00
Mathieu Mirmont
57a909f615 x86: fix VCPU object creation
VCPU objects are "physical" objects, as in they do use memory areas
allocated from Untyped.

Signed-off-by: Mathieu Mirmont <mat@neutrality.ch>
2025-11-07 10:07:39 +11:00
Julia Vassiliki
3db39fd7bc am335/ompa3/bcm2837: compare irq & maxIRQ with <=
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
2025-11-03 10:00:53 +11:00
Julia Vassiliki
3977e12b8b arm,gic-v3: fix GICD_CTLR_ARE_NS bit value
This reverts https://github.com/seL4/seL4/pull/1490 as the
change that was made in that PR was reading the wrong part
of the GIC specification, because ARM decided that the
register layouts are different in non-secure vs secure mode.

Fixes (again) https://github.com/seL4/seL4/issues/1489

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
2025-10-30 13:20:40 +00:00
Julia Vassiliki
70c75b956e aarch64: improve kernel address space layout docs
These diagrams were really unclear and confusing to me,
especially as I always needed to convert from "2^64 - 2^39"
form to "0x0000008000000000" form many times in my head.

They were also out of date and wrong, containing graphics of the
PDPT (from x86) as well as TLB bitmaps.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
2025-10-28 11:14:27 +00:00
Julia Vassiliki
0f058d05db aarch64: keep EL2 docs near hypervisor config
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
2025-10-28 11:14:27 +00:00
Gerwin Klein
73df5be82c machine: move setIRQTrigger into interrupt.h
Move setIRQTrigger from <arch>/hardware.h into interrupt.h together
with the rest of the IRQ interface, because it is now a visible
interface even for platforms and architectures that do not provide the
functionality.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-10-10 14:36:43 +11:00
Gerwin Klein
ec918cf123 arm,irq: use UNREACHBLE in unimplemented functions
UNREACHABLE instead of halt means the compiler can elide the function
from the binary.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-10-10 14:36:43 +11:00
Gerwin Klein
6c7a376200 arm: default setIRQTrigger for non-GIC platforms
Provide a default dummy implementation for setIRQTrigger even for
non-GIC platforms where this operation is not supported. Otherwise,
the function is declared in the header, but has no implementation.

Implementing it as UNREACHABLE() means verification will show that the
function is not called.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-10-10 14:36:43 +11:00
Gerwin Klein
eaed120175 util: provide FNSPEC for __unreachable
Adding a spec with precondition False means verification has to show
that the function is not called.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-10-10 14:36:43 +11:00
Gerwin Klein
40c4ad5112 arm: plat_SGITargetValid for non-GIC platforms
Provide an implementation of the header function plat_SGITargetValid
even for non-GIC platforms. This function will not be called, but
verification has a general lemma about it, and the default
implementation makes that lemma true without adding special cases.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-10-10 14:36:43 +11:00
Indan Zupancic
a117712c19 Make fastpath_restore match restore_user_context
Mostly call c_exit_hook() with global lock held.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-10-09 10:31:01 +01:00
julia
09e6c3f5e2 debug: invalidate ksKernelEntry on kernel exit
There's a few cases in the kernel where the ksKernelEntry tracking
is not perfect, such as in SError reporting, and (I believe) a few
other places which I haven't tracked down to a cause - but some of
e.g. the RISC-V trap code where the first entry faults and the 2nd
proceeds can report stale information.

In these cases, the kernel says that the entry was via a certain
syscall or interrupt (etc), even though that was clearly not the
case because we know the kernel exited. Now we will print out this:

    halting...
    Kernel entry via Unknown (0)

The changes:

- When exiting the kernel, via `c_exit_hook()`, reset
  `ksKernelEntry.path` to "Unknown".

  An alternative here would have been add a global "valid" boolean
  to the kernel state, but this requires modifying every site where
  we set the ksKernelEntry.path to also set valid = true, which is
  ugly.

- Remove Entry_UnimplementedDevice from entry_type_t as it is never
  used, to leave enough room to add Entry_Unknown.

- Switch out the CONFIG_DEBUG_BUILD || BENCHMARK TRACK ENTRIES #if
  in the x86 breakpoint code with the more concise
  `TRACK_KERNEL_ENTRIES` define used elsewhere.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-20 15:57:58 +01:00
julia
5de930983b arm,riscv: eliminate idle_thread function prologue
Similar to #510 but for all other platforms. The idle_thread runs
without a stack and so cannot handle the stack prologue. This should
hopefully make the kernel rely less on FORCE_INLINE for this as well.

We create idle.S assembly files for each platform, as GCC does not
support `__attribute__((naked))` on AArch64 (GCC 13.2.0) and bails out.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-19 09:06:24 +01:00
Gerwin Klein
dfaef4b712 arm: make irqInvalid static const
Helps the C compiler to recognise irqInvalid as a constant. This in
turn helps with binary verification, because irqInvalid is already
parsed as a constant in Isabelle since it is never written to.

See also the discussion in #1349 and #1324

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-08-15 12:16:46 +01:00
Gerwin Klein
db2b2be64c aarch32: make sure irqInvalid is irq_t
The GIC platforms use irq_t for irqInvalid -- bring remaining AArch32
platforms in line with that.

irq_t is an unsigned type (when it is an integer) and enum constants are
signed. For the proofs to treat these platforms uniformly, they need to
be the same kind. They can't all be enums, because irq_t can be a more
complex type for SMP platforms.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-08-15 12:16:46 +01:00
julia
41c9e79dd1 asidpools: consistently use ASID_LOW macro
Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-08 10:39:53 +01:00
julia
b8e81b077a asidpools: consistently use ASID_HIGH macro
Also, change the definition of ASID_HIGH from

    ((a >> asidLowBits) & MASK(asidHighBits))

to

    ((a) >> asidLowBits)

because the mask is an unnecessary operation (this is handled by the
proofs). It is unnecessary because these (SW) ASIDs are kernel-only
and are never exposed to users, so they will never set bits asid from
the asidLow and asidHigh bits.

Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-08 10:39:53 +01:00
julia
5aa9729ec3 asidpools: remove unused ASID_POOL_INDEX_BITS
I'm not even sure what the seL4_ASIDPoolIndexBits means

Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-08 10:39:53 +01:00
julia
e5c3aef827 asidpools: use nASIDPools for the ASID Tables
Signed-off-by: julia <git.ts@trainwit.ch>
2025-08-08 10:39:53 +01:00
Krishnan Winter
85e57f7480 thread_ctrl: Remove unused flags
Signed-off-by: Krishnan Winter <krishnanwinter1@gmail.com>
2025-08-01 12:38:52 +01:00
julia
66207ddc5c boot: fix argname in populate_bi_frame prototype
https://github.com/seL4/seL4/pull/1497#issuecomment-3134325333

Signed-off-by: julia <git.ts@trainwit.ch>
2025-07-31 14:20:15 +10:00
Indan Zupancic
180eb4db78 Aarch32, FPU: Remove FPEXC DEX and EX checks
According to Arm documentation, the exception-handling routine
needs to zero the following bits in FPEXC:

DEX, IDF, IXF, UFF, OFF, DZF and IOF

In seL4, the user space fault handler should do this, as the kernel
doesn't know when user space is done handling the FPU trap.

In case of virtualisation, the guest kernel should clear these bits.

Now that the seL4 kernel doesn't handle FPU traps itself any more,
user space can handle asynchronous traps if it wants to.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
77f5fab0a0 Aarch32, FPU: Init fpexc with FPU enabled
On 32-bit ARM the fpexc system register is set by loadFpuState,
which includes the FPU enable/disable bit FPEXC_EN_BIT. This
register is part of the usercontext and needs to be initialised
correctly, otherwise the FPU will be disabled by loadFpuState.

Before, this bug was hidden because the FPU was enabled lazily
after a trap. This bug just caused one extra FPU trap at first
FPU use for each task: The first handleFPUFault would fail to
enable the FPU, causing another FPU trap when user space gets
restarted.

On the second FPU fault, switchLocalFpuOwner calls enableFpu first
and then calls saveFpuState because ksActiveFPUState is set to the
current task's FPU state. Then it gets saved with FPEXC_EN_BIT set
and the task can continue with the FPU actually enabled.

This also means that with the old code, the initial FPEXC state
of each task was equal to the previous active FPU task's.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Corey Lewis
504f1ccf00 FPU: ease verification
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2025-07-24 16:44:08 +10:00
Indan Zupancic
4031b9db83 ARM64: Always declare disable FPU functions
disableFpu() is always called at boot and calls one of those.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
8502701926 FPU: Rename fpuThreadDelete to fpuRelease
It's not only used when deleting a thread any more.

Swapping fpuRelease and dissociateVCPUTCB makes no practical
difference as they are independent, but it simplifies
verification slightly.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
c4501d5ed4 FPU: Do lazyFPURestore in switchToThread
To ease verification.

Fairly trivial change, except for x86, of course.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
134ab60ae0 FPU: Remove Unused isFpuEnable
Unused on ARM, on RISC-V it is actually the final decision and not
a cache.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
a96982e576 x86, FPU: Fix XSAVES
Add config choice and change the default from XSAVEOPT to XSAVE.

The first config choice is used as the default option. Only XSAVE
is guaranteed to always work, the others require newer CPUs.

Get rid of dubious FPU state headers, we don't need them:
- XCOMP_BV_COMPACTED_FORMAT is set by xsavec or xsaves.
- We can init MXCSR with the ldmxcsr instruction.

Only system state should be configured in IA32_XSS_MSR,
setting FPU user state bits causes an exception.

All memory should be zeroed already, no need to do it again.

See also issue #179.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
1bd0e3b788 FPU: ksCurFPUOwner instead of ksActiveFPUState
Trivial change, except for x86 virtualisation and bootup.

Normally the seL4_TCBFlag_fpuDisabled flag is used to decide whether
to enable or disable the FPU. However, with x86 virtualisation there
is only one TCB. Use the task flag for the host and always enable FPU
for the guest.

When either the host or the guest's FPU is loaded, ksCurFPUOwner will
point to our TCB. saveFpuState and loadFpuState check fpu_active and
do the right thing depending on the current FPU user. To make this
work it was necessary to pass tcb_t to saveFpuState and loadFpuState.
Use the idle thread to store the initial FPU state. x86KSnullFpuState
is kept to simplify verification.

However, when Arch_initFpu is called, the idle thread hasn't been
created yet, so move the initialisation to after create_idle_thread,
but before create_initial_thread, as that leads to Arch_initFpuContext
using x86KSnullFpuState.

Also initialise VCPU FPU registers correctly for x86, otherwise the
initial state is wrong and can't be loaded when XSAVES is enabled.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
5035def0b9 FPU: Save and restore FPU state based on TCB flag
Remove fault-based FPU state saving and loading.

Signed-off-by: Indan Zupancic <indan@nul.nu>
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2025-07-24 16:44:08 +10:00
Indan Zupancic
1415cac443 Add seL4_TCB_SetFlags Syscall
Add flags to tcb_t and the seL4_TCBFlag_fpuDisabled flag.

Enums are signed, make TCB flags word_t to make it unsigned.

Signed-off-by: Indan Zupancic <indan@nul.nu>
Signed-off-by: Corey Lewis <corey.lewis@proofcraft.systems>
2025-07-24 16:44:08 +10:00
Indan Zupancic
8f8776a541 Domain: Split off invokeDomainSetSet
Retain the ridiculous name to make clear which invocation is being
handled.

Rename tptr to tcb for consistency within the file.

We have a dom_t type, use it as early as possible.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
35ec2554b9 Domain: Save FPU state when changing domain
Co-authored-by: Corey Lewis <corlewis@gmail.com>
Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
296638287a ARM: Move debug state to the end of user_context
Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00
Indan Zupancic
46adf99242 Aarch64: Remove incorrect comment
It was blindly copied from Aarch32 and has never been correct.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2025-07-24 16:44:08 +10:00