Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
target/
# Nothing enters the CI image unless it is listed here. Build output, editor and tool state,
# local notes and logs stay out, whatever they are called. `.git` is kept: the threat model asks
# reporters to quote `git -C /src rev-parse HEAD` from inside the container.
# A new top-level entry that the build or the tests need must be added below.
*
!.cargo
!.git
!.gitattributes
!.gitignore
!.github
!Cargo.lock
!Cargo.toml
!LICENSE
!rust-toolchain.toml
!assets
!ci
!crates
!design
!kernel
!loader
!tools
!userspace
!vendor
!*.md
# Local files that .gitignore also keeps out, at any depth inside the listed directories
**/NO-COMMIT*
**/target
**/.DS_Store
**/*.log
**/*.rs.bk
15 changes: 12 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ $ cargo build -p k0-kernel --features console --offline
$ tools/qemu-boot-test.sh # boot under QEMU and check the self-tests
```

`tools/host-test.sh` runs the tests of `k0-abi`, `k0-cap`, `k0-boot` and `k0-efi` on any host (221 tests on an AArch64 host, 161 elsewhere). The tests of `k0-mm` contain AArch64 inline assembly, so they only run on an AArch64 host (Apple Silicon or Linux arm64). The script runs them for both the 4 KiB and the 16 KiB granule.
`tools/host-test.sh` runs the tests of `k0-abi`, `k0-cap`, `k0-boot` and `k0-efi` on any host (250 tests on an AArch64 host, 164 elsewhere). The tests of `k0-mm` contain AArch64 inline assembly, so they only run on an AArch64 host (Apple Silicon or Linux arm64). The script runs them for both the 4 KiB and the 16 KiB granule.

`tools/qemu-boot-test.sh` boots the debug kernel, checks the boot log line by line in a fixed order, fails on any error marker, and stops QEMU as soon as the root task reports `root: sched tests pass`. Set `K0_BOOT_TIMEOUT` (seconds) on slow machines. It reads the serial port, so it needs an image with a console driver. To test an image without console, use `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty` and `K0_BOOT_CONSOLE_PAGE`, which are described in "Testing an image without console" in [USAGE.md](USAGE.md#testing-an-image-without-console).
`tools/qemu-boot-test.sh` boots the debug kernel, checks the boot log line by line in a fixed order, fails on any error marker, and stops QEMU as soon as the root task reports `root: sched tests pass`. Besides the pass lines, it expects `k0: kernel reserve ` before the `k0: untyped ` lines, `k0: idle (waiting for a timeout)` and `root: timeout tests pass` after `root: teardown tests pass`, and `root: kernel reserve tests pass` after `root: revocation tests pass`. Any line that starts with `k0: all tasks` is a failure. It also counts the timer tick lines between `root: teardown tests pass` and `root: timeout tests pass` and wants at least 4, because EL0 has no clock and this is how the lower bound of a timeout is checked. The timeout tests wait for real ticks, so a boot takes about 4 seconds longer than it did before. Set `K0_BOOT_TIMEOUT` (seconds) on slow machines. It reads the serial port, so it needs an image with a console driver. To test an image without console, use `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty` and `K0_BOOT_CONSOLE_PAGE`, which are described in "Testing an image without console" in [USAGE.md](USAGE.md#testing-an-image-without-console).

The default QEMU CPU model (`cortex-a72`) has no PAC, PAN or RNDR. To exercise those paths as well, boot on QEMU's `max` model and require the matching log lines. Any arguments after the kernel path are passed to QEMU. You can enter it as follows:

Expand Down Expand Up @@ -159,7 +159,16 @@ $ docker run --rm --network none k0-ci tools/host-test.sh
$ docker run --rm --network none k0-ci tools/boot-matrix.sh
```

Run this from **a clean checkout**, because the build context includes everything in the working directory.
Run this from **a clean checkout**, because the build context is the working directory. The following list describes how the image is made.

- **Base image**: it is pinned by the digest of its multi-architecture index (`debian:bookworm@sha256:...`).
- **Rust toolchain**: the image does not use rustup. `ci/install-toolchain.py` pins the SHA-256 of the Rust 1.89.0 channel manifest and checks every package it installs (rustc, cargo, rust-std for the host and for `aarch64-unknown-none-softfloat` and `aarch64-unknown-uefi`, rust-src and llvm-tools) against the hashes in that manifest. A mismatch fails the image build.
- **Build context**: `.dockerignore` is an allowlist, so nothing enters the image unless it is listed there. **A new top-level file or directory** that the build or the tests need must be added to it. `.git` is kept in the image.

> [!NOTE]
> Not everything is pinned. The versions of the Debian packages float (apt checks them with the archive keys inside the pinned base image), and so do the GitHub runner images. The GitHub Actions used by the workflows are pinned by commit hash.

Developers still use rustup on their own machines. Only the CI image changed.

## Rules for kernel changes

Expand Down
15 changes: 12 additions & 3 deletions CONTRIBUTING_KR.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ $ cargo build -p k0-kernel --features console --offline
$ tools/qemu-boot-test.sh # QEMU 부팅과 자가 테스트 확인
```

`tools/host-test.sh`는 `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`의 테스트를 어느 호스트에서나 실행합니다(AArch64 호스트에서 221개, 그 밖에서 161개). `k0-mm` 테스트는 AArch64 인라인 어셈블리를 포함하기 때문에 AArch64 호스트(Apple Silicon 또는 Linux arm64)에서만 실행되며, 스크립트가 4 KiB와 16 KiB 그래뉼 두 구성으로 모두 돌립니다.
`tools/host-test.sh`는 `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`의 테스트를 어느 호스트에서나 실행합니다(AArch64 호스트에서 250개, 그 밖에서 164개). `k0-mm` 테스트는 AArch64 인라인 어셈블리를 포함하기 때문에 AArch64 호스트(Apple Silicon 또는 Linux arm64)에서만 실행되며, 스크립트가 4 KiB와 16 KiB 그래뉼 두 구성으로 모두 돌립니다.

`tools/qemu-boot-test.sh`는 디버그 커널을 부팅하고 부팅 로그를 정해진 순서대로 한 줄씩 확인합니다. 에러 표식이 하나라도 나오면 실패하고, 루트 태스크가 `root: sched tests pass`를 출력하면 곧바로 QEMU를 종료합니다. 느린 환경에서는 `K0_BOOT_TIMEOUT`(초)을 늘려 주세요. 직렬 포트를 읽기 때문에 콘솔 드라이버가 있는 이미지가 필요합니다. 콘솔 없는 이미지를 시험하려면 [USAGE_KR.md](USAGE_KR.md#콘솔-없는-이미지-시험)의 "콘솔 없는 이미지 시험"에 설명된 `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty`, `K0_BOOT_CONSOLE_PAGE`를 사용하세요.
`tools/qemu-boot-test.sh`는 디버그 커널을 부팅하고 부팅 로그를 정해진 순서대로 한 줄씩 확인합니다. 에러 표식이 하나라도 나오면 실패하고, 루트 태스크가 `root: sched tests pass`를 출력하면 곧바로 QEMU를 종료합니다. 통과 줄 외에도 `k0: untyped ` 줄보다 앞의 `k0: kernel reserve `, `root: teardown tests pass` 뒤의 `k0: idle (waiting for a timeout)`와 `root: timeout tests pass`, `root: revocation tests pass` 뒤의 `root: kernel reserve tests pass`를 기대합니다. `k0: all tasks`로 시작하는 줄은 모두 실패입니다. `root: teardown tests pass`와 `root: timeout tests pass` 사이의 타이머 틱 줄도 세어 4개 이상을 요구하는데, EL0에는 시계가 없어서 이것이 타임아웃의 하한을 확인하는 방법이기 때문입니다. 타임아웃 테스트는 실제 틱을 기다리므로 부팅 한 번이 이전보다 약 4초 더 걸립니다. 느린 환경에서는 `K0_BOOT_TIMEOUT`(초)을 늘려 주세요. 직렬 포트를 읽기 때문에 콘솔 드라이버가 있는 이미지가 필요합니다. 콘솔 없는 이미지를 시험하려면 [USAGE_KR.md](USAGE_KR.md#콘솔-없는-이미지-시험)의 "콘솔 없는 이미지 시험"에 설명된 `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty`, `K0_BOOT_CONSOLE_PAGE`를 사용하세요.

기본 QEMU CPU 모델(`cortex-a72`)에는 PAC, PAN, RNDR이 없습니다. 이 경로까지 검증하려면 QEMU의 `max` 모델로 부팅하고 해당 로그 줄을 필수로 지정하세요. 커널 경로 뒤의 인자는 그대로 QEMU에 전달됩니다. 다음과 같이 입력할 수 있습니다.

Expand Down Expand Up @@ -163,7 +163,16 @@ $ docker run --rm --network none k0-ci tools/host-test.sh
$ docker run --rm --network none k0-ci tools/boot-matrix.sh
```

빌드 컨텍스트에 작업 디렉터리의 모든 파일이 들어가므로 **깨끗한 체크아웃에서 실행**해 주세요.
빌드 컨텍스트는 작업 디렉터리이므로 **깨끗한 체크아웃에서 실행**해 주세요. 이미지는 다음과 같이 만들어집니다.

- **베이스 이미지**: 멀티 아키텍처 인덱스의 다이제스트(`debian:bookworm@sha256:...`)로 고정되어 있습니다.
- **Rust 툴체인**: 이미지에서는 rustup을 사용하지 않습니다. `ci/install-toolchain.py`가 Rust 1.89.0 채널 매니페스트의 SHA-256을 고정해 두고, 설치하는 모든 패키지(rustc, cargo, 호스트용과 `aarch64-unknown-none-softfloat`·`aarch64-unknown-uefi`용 rust-std, rust-src, llvm-tools)를 그 매니페스트의 해시와 대조합니다. 하나라도 다르면 이미지 빌드가 실패합니다.
- **빌드 컨텍스트**: `.dockerignore`는 허용 목록이므로, 목록에 없는 것은 이미지에 들어가지 않습니다. 빌드나 테스트에 필요한 **새 최상위 파일 또는 디렉터리**는 이 목록에 추가해야 합니다. `.git`은 이미지에 포함됩니다.

> [!NOTE]
> 모든 것이 고정되어 있지는 않습니다. Debian 패키지의 버전은 고정되지 않았고(apt는 고정된 베이스 이미지 안의 아카이브 키로 검증합니다), GitHub 러너 이미지도 마찬가지입니다. 워크플로가 사용하는 GitHub Actions는 커밋 해시로 고정되어 있습니다.

개발자는 여전히 자기 컴퓨터에서 rustup을 사용합니다. 바뀐 것은 CI 이미지뿐입니다.

## 커널 변경 규칙

Expand Down
28 changes: 20 additions & 8 deletions INTRODUCTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This document explains in plain words what K0 is, what it can do today and what

## What K0 is

An operating system kernel is the program that controls the hardware and decides what every other program may do. Most kernels are large and do many jobs themselves. K0 is a **microkernel**: it does only the few jobs that must be done inside the kernel and leaves everything else to ordinary programs. The kernel side is about 7,400 lines of Rust and assembly (comments included, tests excluded). It is small enough to read from start to end.
An operating system kernel is the program that controls the hardware and decides what every other program may do. Most kernels are large and do many jobs themselves. K0 is a **microkernel**: it does only the few jobs that must be done inside the kernel and leaves everything else to ordinary programs. The kernel side is about 11,800 lines of Rust and assembly (comments included, tests excluded). It is small enough to read from start to end.

The most important of those jobs is keeping programs apart. Think of a dormitory. Each room is a block of memory, each key opens one thing, and the kernel is the caretaker. A resident can open only the doors they hold a key for. A copy cannot be turned into a stronger key, and when a key is taken back, every copy made from it stops working too. In K0 these keys are called **capabilities**. The idea comes from the seL4 kernel.

Expand Down Expand Up @@ -131,6 +131,9 @@ These features only add and are not in `default`, so **every build command must
Memory is placed on an address space's map only by showing that address space's key (MAP, UNMAP). Keys carry rights (read, write, execute). A mailbox key can carry a tag that tells the receiver who sent a message (badge). Keys can be copied with the same or fewer rights, or moved between slots (CAP_COPY, CAP_MOVE).
- **Running tasks**: a task is tied to one key ring and one address space when it is set up (TCB_CONFIGURE) and then started (TCB_RESUME). Tasks take turns, and a timer interrupts a task that runs too long (round-robin scheduling with timer preemption). A task can give up its turn (YIELD) or finish (EXIT).
- **Messages**: tasks exchange short messages that travel in processor registers. The sender waits until the receiver takes the message (synchronous IPC: SEND, RECV, CALL, REPLY_RECV). Sending needs the write right on the mailbox key and receiving needs the read right. The receiver learns the tag of the sender's key, and the right to reply can be used only once.
- **Timeouts**: every one of these calls can carry a time limit, counted in timer ticks (one tick is one second). If no partner arrives in time, the call returns an error (`TIMEOUT`, or `REPLY_TIMEOUT` when a `CALL` was delivered but no reply came). Without a limit a task waits as long as it takes. The wait lasts at least the given number of ticks and may be a little longer. The limit says when the task becomes ready again, not when it runs.
- **Idle**: when no task can run, the kernel no longer stops. It waits for the next interrupt, wakes tasks whose time limit has passed and carries on. If nothing can ever wake a task, the machine stays idle and the boot log says `k0: all tasks stopped (none ready, no timeout pending)`.
- **Kernel tables sized at boot**: the kernel sets aside the memory for its own page tables and address space entries at boot, in proportion to the memory it hands out (about 0.4 % of RAM). So a task cannot use these tables up, and the number of address spaces is limited only by memory.
- **Crash containment**: when a task crashes, makes a system call the kernel does not know, or exits, only that task is stopped (fault isolation).
- **Task isolation and taking keys back**: tasks tied to different key rings and address spaces cannot reach each other's memory or keys. Every key remembers which key it was copied from (derivation list). Taking a key back (CAP_REVOKE) or deleting it (CAP_DELETE) has the following effects.
- Every key copied from it is removed as well.
Expand Down Expand Up @@ -226,13 +229,22 @@ What it stops:
- **Access to resources and memory**: a task cannot use a resource it holds no key for, and it cannot see memory that is not on its own map.

> [!WARNING]
> Availability is not protected. A task can still bring everything to a halt.
> Availability is not protected in general. A task can still slow down or block the other tasks, as the list below shows.

What it does not stop:

- **Availability**: there are two cases.
- If every task ends up waiting for a message, the kernel stops the processor core. A confined task can cause this by being the last one to wait.
- A task given a lot of free memory can use up the kernel's fixed tables (40 page tables for the kernel's own use, 256 address space entries), and then nobody can create new objects.
- **Availability**: three things improved, but a lot is still open.
- The kernel no longer stops when every task is waiting. It idles and keeps handling timer ticks.
- A task can limit its own waits with a timeout.
- The kernel's two tables for page tables and address spaces can no longer be used up by a task.

Still open:

- A task that waits without a timeout can wait forever if its partner never acts. Timeouts are used per call, so a server that must stay responsive has to give one on every wait.
- There is no priority and no CPU budget. Tasks take turns in equal slices, and a task that holds a lot of free memory can create many tasks and shrink everyone else's share.
- The kernel cannot be interrupted while it handles a system call. A long call, such as taking back a key to a large block of memory, delays every other task and every timeout.
- A fatal error inside the kernel, or an error from the hardware that the kernel cannot attribute to one task, still stops the whole machine.
- The kernel part of the boot log can be filled up by crash and exit lines.
- **Tasks that share a key ring and an address space**: such tasks are not isolated from each other. They behave like threads, parts of one program that share everything.
- **Control of a task**: whoever holds the key to a task, to its key ring or to its address space controls that task.

Expand All @@ -247,7 +259,7 @@ Missing features:
- **Capability transfer**: a key cannot be handed to another task inside a message (capability transfer over IPC).
- **Hardware interrupt notification**: a program cannot be told about hardware interrupts (Notification objects).
- **Crash reports**: a crashed task is only stopped. It is not reported to a handler task.
- **Timeouts and multicore**: there are no timeouts, and only one processor core is used.
- **Multicore**: only one processor core is used.
- **Device access**: programs cannot access hardware devices (device memory and interrupts).
- **Loading new executable code after boot**: this is the flip side of the write-or-run rule. Executable memory exists only for the root task image, so a confined task runs code from that image.
- **Multi-level key lookup and ASIDs**: multi-level key lookup and hardware address space tags (ASIDs) do not exist. Today every switch to another address space empties the processor's cache of memory map lookups (the TLB).
Expand All @@ -269,9 +281,9 @@ Missing features:

Missing protection and assurance:

- **Availability guarantees**: see the previous section.
- **Availability guarantees**: see the previous section. Several ways to block other tasks remain.
- **DMA isolation**: some devices read and write memory directly, without the processor (DMA). Once devices are handed to programs, a memory map for devices (an IOMMU, such as the SMMU on ARM) has to stop such a device from reading all memory. Nothing for this exists yet.
- **Side channels**: secrets can leak through timing or through caches the processor shares, rather than by direct access. A few such leaks are closed (programs cannot read the hardware counters, and the TLB is emptied whenever the address space changes). There is no general defence against cache or timing side channels, and they have not been analysed.
- **Side channels**: secrets can leak through timing or through caches the processor shares, rather than by direct access. A few such leaks are closed (programs cannot read the hardware counters, and the TLB is emptied whenever the address space changes). Timeouts give programs a clock, but it is as coarse as one timer tick. Whether that can help an attack has not been analysed. There is no general defence against cache or timing side channels, and they have not been analysed.
- **Waiting senders**: taking a key back does not cancel a sender already waiting at the mailbox. Its message is still delivered once.
- **Basis of assurance**: assurance comes from testing only.
- Unit tests and fuzzing (feeding random, broken input to find crashes) on the build machine
Expand Down
Loading