Commit graph

4905 commits

Author SHA1 Message Date
Gerwin Klein
868454e1d6 trivial: cmake style update for helpers.cmake
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-06-12 14:14:59 +10:00
Gerwin Klein
c377a3233a cmake: set policy CMP0174 when it exists
Avoid warning about empty string arguments to functions config_option()
and config_string() in newer cmake versions.

Both behaviour versions (with and without policy) are safe for how we
are using those arguments. Setting the policy when it exists removes the
warning.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-06-12 14:14:59 +10:00
Michael McInerney
d82b2049a7 mcs: add cmake file for verified AARCH64 MCS
To build the verified configuration of AARCH64 MCS.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-06-12 08:46:13 +10:00
Michael McInerney
a15e9a32a2 mcs: add check for preemption to SysReplyRecv
To ease verification, in the SysReplyRecv case of handleSyscall, add
the explicit check for preemption, even though the call to
handleInvocation should not be preemptible.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-06-02 18:07:45 +10:00
Gerwin Klein
93f73a49ad tcb: make validFaultHandler available
Make the function validFaultHandler available to the assert in
sendFaultIPC in faulthandler.c.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-06-02 10:20:59 +10:00
Gerwin Klein
5d371316ff mcs: fix missing cap fault info in lookupReply
Set missing cap fault info (lookup_fault_missing_capability_new(0)) in
lookupReply and move handleFault to caller, so that lookupReply is an
actual lookup function without random side effects.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-06-02 08:06:01 +10:00
Michael McInerney
c119df0357 mcs: fix missing cap fault info in sendFaultIPC
Update the tcbLookupFailure field to be the current lookup fault, if
there is a current cap fault.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-06-02 07:52:18 +10:00
Michael McInerney
2d4c0e1a51 mcs: refactor validFaultHandler for readability
Simplify definition and avoiding double negation in validFaultHandler.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-06-02 07:52:18 +10:00
Bill Nguyen
7eac2ceab8 x86/c_traps.c: add clobbers in 32-bit VMX restore
The inline assembly blocks for vmlaunch and vmresume in the 32-bit
restore_vmx() function manually pop guest state into all general-purpose
registers.

Previously, these registers were not included in the inline assembly
clobber list. If a VM entry fails, execution falls through to the
vmlaunch_failed() C function. Because the compiler is unaware that the
registers were overwritten, it may generate code for the failure handler
that relies on destroyed state.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-06-01 10:02:02 +01:00
Bill Nguyen
84d60b58a1 x86_64/c_traps.c: fix registers clobbering in VMX
Previously, the assembly block in restore_vmx() passed a few C
variables as generic register inputs ("r"):
```
        : [reg]"r"(&vcpu->gp_registers[VCPU_EAX]),
        [launched]"r"(&vcpu->launched),
...
        [guest_msr]"r"(&vcpu->guest_msr_registers[VCPU_GS]),
        [host_msr]"r"(&vcpu->host_msr_registers[n_vcpu_msr_register])
```

This allowed the compiler to place them in any general-purpose register.
GCC happened to allocate them in a non-conflicting order with respect to
how CPU registers used in the assembly block. But on LLVM 22.1.5, it
assigned them to the exact registers the assembly block was manually
writing to via movq.

This caused the pointers to be overwritten before use, leading to a
guest hang when the registers were restored with garbage values by
a kernel built with LLVM.

I've updated the code to refer to the variables by name rather than by
registers to fix the problem.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-06-01 10:02:02 +01:00
Indan Zupancic
76389088b2 x86, 32bit, HYP: Fix style
Otherwise the style checker or Gitlint complains.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-05-29 00:02:40 +01:00
Indan Zupancic
87421cf7b2 x85, SMP: Fix compile error
GCC 10.2.1 doesn't like declarations inside a case statement without
a new context.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-05-29 00:02:40 +01:00
Indan Zupancic
c6c84d7aef x86, 32bit, SMP, HYP: Remove unused vcpu.kernelSP
User context already has a kernelSP, which is used.

Also, the 64-bit also doesn't has this, so probably a leftover.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-05-29 00:02:40 +01:00
Gerwin Klein
9d84967424 github: bump GH action versions
Node 20 is deprecated. Bump GitHub action dependencies to versions that
run on more recent node.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-05-28 18:13:04 +10:00
Ivan Velickovic
e912dff734 x86,SMP: fix VMCheckBoundNotification call
Missed from https://github.com/seL4/seL4/pull/1641.

I think the issue is that x86-64 is not built with VT-X
in any of the CI runs, so we should fix that.

Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
2026-05-23 11:14:40 +01:00
Gerwin Klein
c962e51e3b constants: decrease TCB_SIZE_BITS for some configs
The IPC queue changes for MCS in commit 771c9e43ce has decreased the
TCB size slightly, which brings TCB_SIZE_BITS down for config
combinations that have MCS + SMP + HYP + benchmarking enabled.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-05-22 13:31:04 +01:00
Gerwin Klein
7c11116b65 fastpath: apply MCS queue changes to signal FP
Apply the changes from commit 771c9e43ce to the signal fast path,
which was missed there.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-05-22 13:31:04 +01:00
Bill Nguyen
2f1b0708b3 x86_64/c_traps.c: fix compile error
Fix compile error from #1667.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-05-22 14:28:25 +10:00
Michael McInerney
771c9e43ce mcs: handle endpoint and ntfn queues uniformly
- Introduce functions to append and dequeue to/from endpoint and
  notification queues, in order to make verification feasible. Handle
  linked list manipulations with the same functions that were
  previously used for the ready and release queues, together with a new
  function that allows for a new item to be inserted into the queue
  after another item that is already in the queue.

- Remove tcbEPNext and tcbEPPrev pointers from the MCS version, and
  instead use tcbSchedNext and tcbSchedPrev pointers, given that no
  thread can be simultaneously in any two of the endpoint,
  notification, ready, or release queues.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-05-22 11:42:19 +10:00
Bill Nguyen
1ff6c16e6f x86_64/c_traps.c: patch Virtual Machine escape
The original `restore_vmx()` inline assembly passes the vmlaunch_failed
function pointer as a standard register constraint ("r"). Consequently,
the compiler allocates this pointer to a general-purpose register before
the assembly block begins.

However, immediately prior to executing vmlaunch or vmresume, the kernel
restores the guest's state via a sequence of popq instructions that
overwrite every general-purpose register. If the VM entry fails (e.g.,
due to an invalid VMCS state), execution falls through to the failure
path, which then attempts to jump to the register originally holding the
function pointer.

Because this register was just overwritten with guest-controlled data,
the kernel will jump to an arbitrary memory address dictated by the
guest. A malicious guest OS can exploit this by placing a payload
address in the targeted register and intentionally corrupting its VMCS
state (e.g. by compromising the userspace VMM) to force an entry
failure, achieving full VM escape and arbitrary code execution in the
kernel.

This patch fixes the vulnerability by using a RIP-relative `lea`
instruction to calculate the handler's address dynamically at the exact
moment of failure, entirely bypassing the clobbered registers.

I've managed to trigger this bug by compiling the kernel with LLVM. On
a VM Entry fail, the kernel would just crash because it jumped to a
random location. But after the fix, it no longer crashes and was able to
print out the error message in `vmlaunch_failed()`.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-05-22 00:35:02 +01:00
Indan Zupancic
e7121974af x86,SMP: Fix compile errors
Introduced by the previous commit of PR #1641:

x86,SMP: Fix VMCheckBoundNotification IPI handling

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-05-21 13:31:19 +01:00
Indan Zupancic
c8ae3010bc x86,SMP: Fix VMCheckBoundNotification IPI handling
When a notification is bound to an IRQ that arrives on a different
core than where the VCPU is running, x86 uses a special IPI to
notify the other core about this. (For performance reasons you
would try to avoid this setup. Nevertheless, it should work.)

When an IpiRemoteCall_VMCheckBoundNotification arrives during a
VM exit, the notification reply set by VMCheckBoundNotification()
gets overwritten by the handleVmexit() reply, leading to lost
notification events. This happens when VMCheckBoundNotification()
gets called by the IPI handling code within NODE_LOCK_SYS.

As there is no way to postpone the VM exit handling and the IPI
code doesn't know whether it races with a VM exit, doing nothing
if the current task is the target is the safest choice:

Either the IPI itself caused a VM exit, or there was a VM exit
happening already.

To handle the first case, explicitly call VMCheckBoundNotification()
in handleVmexit(). This must be done while holding the kernel lock,
as the other core can release the lock any moment after it received
our IPI reply.

In the latter case, pending notifications will be detected and
returned to user space by the next seL4_VMEnter() call.

Fix tested by Alessandro Legnani.

Resolves issue #1148.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-05-21 11:50:29 +01:00
Bill Nguyen
f0535f9e18 x86_64/traps.S: fix UBSAN crash when kernel except
The System V AMD64 ABI requires the stack pointer (%rsp) to be 16-byte
aligned immediately before a `call` instruction. In `kernel_exception`,
pushing three 8-byte control registers (%cr2, %cr3, %cr4) after
`INT_SAVE_STATE` misaligned the stack prior to calling
`handleKernelException`.

This commit adds an 8-byte padding before pushing the control registers
to maintain 16-byte alignment.

Previously, compiling the kernel with LLVM and UBSAN enabled resulted in
a recursive exception loop if a UB was encountered elsewhere in kernel
code. The misaligned stack would trigger UBSAN during exception
printing, causing an exception within the exception handler that
looped infinitely.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-05-20 14:47:47 +01:00
Bill Nguyen
b050e4b78d x86_64/vspace: made init_syscall_msrs not bootcode
`init_syscall_msrs()` is also called by `vcpu_restore_host_msrs()`
so should not be BOOT_CODE.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-05-20 14:32:35 +01:00
Julia Vassiliki
3527859e72 workflows: use ${{ variable }} not invalid $${{
I'm not entirely sure how this worked... but I guess GitHub
ignores the extra $ sign.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
2026-05-20 11:54:06 +10:00
Gerwin Klein
4220e60371 CHANGES: log stm32mp2 support
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-05-19 13:28:22 +01:00
Christian Bruel
c75cf0e2da Add support for stm32mp2 SoC family
Add support for STM32MP2 SoC A35 core and stm32mp25-ev1 board.

Supports HYP and SMP configurations
-DPLATFORM=stm32mp2 -DKernelARMlatform=stm32mp257f-ev1 (default)

Supports MCS configuration (for Microkit build)

Signed-off-by: Christian Bruel <christian.bruel@foss.st.com>
2026-05-19 13:28:22 +01:00
Yanfeng Liu
a0b4f2d25d manual: Reorg riscv32/64 hardware objects
This drops subsection for riscv so that subsections for rv32/64
belong to same level as those of x86 and arm32/64.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2026-05-09 20:24:50 +02:00
Bill Nguyen
744104654d x86/vcpu: expose VMX-preemption timer scale MSR
Currently, the kernel permits userspace VMMs to enable and use the
VMX-preemption timer by allowing writes to the following VMCS fields:
- VMX_GUEST_PREEMPTION_TIMER_VALUE (count)
- VMX_CONTROL_PIN_EXECUTION_CONTROLS (timer enable bit)
- VMX_CONTROL_EXIT_CONTROLS (save current count on context switch bit)

It also forwards the timer expiry event as a VM exit.

But it does not tell userspace how fast the timer will count down,
making it impossible to use. This commit exposes the timer's scale
via `seL4_X86_VCPU_ReadMSR`.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-05-09 10:54:59 +02:00
Michael McInerney
3fc42873f3 mcs: refactor some functions to ease verification
- separate the update of the release queue in tcbReleaseEnqueue from
  the setting of ksReprogramTimer, so that verification may reason
  uniformly abbout the update of the queue.

- use local variables in sendIPC and receiveIPC to avoid repeated
  accesses of the heap.

- move the update of the replyTCB field in receiveIPC so that the
  updates related to the thread state are grouped together, to more
  closely align with the Haskell specification.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-05-08 15:15:05 +02:00
Gerwin Klein
b62417a292 libsel4/riscv: avoid gcc 14.2 miscompilation
a7 is not changed by seL4_Yield, so the original declaration is correct.

However, in some loops GCC 14.2 may drop the load to a7 if a7 or
memory are not declared as clobbered in the assembly block. This is a
problem if *other* code does write to a7. For some reason GCC 14.2 does
not recognise those other loads. GCC 14.3 and GCC 15 both work as
expected.

The problem manifests in SCHED0011 in sel4test.

This change works around the GCC 14.2 problem because GCC 14.2 is the
standard Debian trixie compiler and it is likely that people will hit
the problem even if we say that GCC 14.2 should not be used.

The workaround uses the same implementation of seL4_Yield as the Arm and
x86/x64 versions do: inline call to sys_null with an empty asm volatile
declaring memory as clobbered. The memory clobber declaration eliminates
the miscompilation, and overall the implementations are now consistent.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-05-08 08:45:52 +02:00
Gerwin Klein
506f20d696 CHANGES.md: add missing copyright
When we renamed CHANGES to CHANGES.md, the copyright info from
reuse/dep5 for CHANGES was not transferred.

Remove CHANGES from .reuse/dep5 and add info to CHANGES.md directly.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-05-06 14:19:38 +02:00
Kent McLeod
0e7ddd3d75 trivial,cmake: Update cmake for style
Reorder the args to help the style formatter out.

Signed-off-by: Kent McLeod <kent@kry10.com>
2026-05-03 15:35:54 +01:00
Bill Nguyen
daa0dfb147 manual: updated EPT invocations to make it clearer
...that these syscalls are only used to manage VCPU page tables.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-04-28 08:22:34 +02:00
Bill Nguyen
79b104a3a1 manual: fix incorrect args desc for X86PageMapEPT
Fixed incorrect arguments descriptions for X86PageMapEPT, to make it
consistent with other invocations that take an EPT and guest physical
address such as X86EPTPTMap.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-04-28 08:22:34 +02:00
Michael McInerney
82a1a8f48f suspend: move call to setThreadState
The call to setThreadState within suspend is
moved to the end of the function, in order to
preserve invariants about the queues.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
2026-04-13 17:00:29 +10:00
yifei@zhan.science
19a520a22b Respect count in TCB_Write/ReadRegisters via loop
Previously TCB_WriteRegisters/ReadRegisters ignored the count parameter
and unconditionally copied the entire seL4_UserContext, this leads to
unnecessary overhead for VMM operations.

This addresses issue #1085

Signed-off-by: Yifei Zhan <yifei@zhan.science>
2026-04-11 13:58:22 +01:00
Gerwin Klein
061017b242 github: provide base ref for preprocess check
For preprocess checks on pull requests, check against the base_ref of
the pull request (e.g. master) instead of against the seL4 revision in
the verification manifest.

If base_ref has advanced over the verification manifest revision, we do
not want to see that difference again on pull requests, but only the
difference the pull request causes itself.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-04-10 21:16:18 +10:00
Michael McInerney
727ccd140f scheduleTCB: simplify scheduler action logic
The call to rescheduleRequired within scheduleTCB is performed only when
the scheduler action is ResumeCurrentThread, and therefore will only set
the scheduler action to ChooseNewThread. This removes the call to
rescheduleRequired and replaces it with the direct update to the
scheduler action.

Signed-off-by: Michael McInerney <michael.mcinerney@proofcraft.systems>
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-04-09 20:39:06 +10:00
Gerwin Klein
d3a0f5f7b9 github: update artifact path
The upstream action in the ci-actions repository has changed slightly
and leaves the PDF in a different location.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-04-07 11:56:17 +01:00
Gerwin Klein
f4a7417f66 arm,cmake: make verification and release equal
Make verification and release builds equal by setting the default for
KernelArmHypEnableVCPUCP14SaveAndRestore to OFF. The option is still
available to set in non-verification builds, only the default changes.

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-04-07 12:18:30 +10:00
seL4 CI
3f590a6027 Update VERSION file to 15.0.0-dev
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-03-31 10:58:57 +11:00
seL4 CI
881de507fe Release 15.0.0
Update VERSION
Update CHANGES.md

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-03-31 10:58:57 +11:00
Gerwin Klein
06063ec309 CHANGES: updates for upcoming release
Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
2026-03-31 10:19:45 +11:00
Kent McLeod
55c1ea653c style: Style cmake for qemu-arm-virt platform
Signed-off-by: Kent McLeod <kent@kry10.com>
2026-03-28 22:56:38 +00:00
Kent McLeod
d500b97512 qemu-arm-virt: add GICv3 support and GIC_VERSION
Add GIC_VERSION cmake option (default 2) to select between GICv2 and
GICv3 for the qemu-arm-virt platform. GICv3 support requires waking
the redistributor on QEMU and configuring interrupt security grouping
for the hypervisor.

Resolves: seL4/seL4#1170

Signed-off-by: Kent McLeod <kent@kry10.com>
2026-03-28 22:56:38 +00:00
Indan Zupancic
27a52ddd4c Runtime Domain Schedules
Implementation of RFC-20.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-03-24 15:03:39 +11:00
Indan Zupancic
f32f2a53d2 Export timer frequency to user space
Useful for configuring domains.

Signed-off-by: Indan Zupancic <indan@nul.nu>
2026-03-24 15:03:39 +11:00
Bill Nguyen
235f90f60e x86/vcpu: Expose VMX 2nd proc control to userspace
Allow userspace reads to `VMX_CONTROL_SECONDARY_PROCESSOR_CONTROLS`
field of VMCS. seL4 already allow writes to the field so no reason to
not allow reads.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-03-24 14:08:55 +11:00
Bill Nguyen
0d2c70c7f0 x86/vcpu: Do not force 64-bit VCPU mode
Previously, X86_64_VTX_64BIT_GUESTS forced the VCPU into 64-bit mode by
hardcoding the IA-32e bit in VM-Entry Controls. This prevented userspace
from starting a VCPU in real mode, which break cases where you want the
guest to be able to manage its own mode transitions. Such as booting
an UEFI firmware.

This change allows the guest to manage its own mode transitions
(real -> protected -> long mode). The X86_64_VTX_64BIT_GUESTS config is
now scoped strictly to enabling 64-bit features like MSR access.

Signed-off-by: Bill Nguyen <bill.nguyen@unsw.edu.au>
2026-03-24 14:08:55 +11:00