interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / docs / osc-launch.md

126 lines · 10658 bytes Raw Blame History Source

OSC unit task launch (C3-3a)

Label for everything below: QEMU (aarch64 virt), TEST signer, not physical. Nothing here has run on a Spark or any real machine. Contract: OSC_UNIT_ARTIFACT.md section 9 (aien-protocols PR #17). Gate: scripts/qemu_ck_osc_launch_test.sh (OSC_LAUNCH row in scripts/ck_gates.sh, notes in native/kernel/GATES.md).

What runs

An admitted unit (struct osc_accept from osc_unit_admit) is run as one function call in an EL0 task with its own address space, by ck_osc_launch (core/osc_task.c): verify the unit's realization receipt (aienos#383, docs/osc-receipts.md; no valid receipt, no launch), look up the function by exact name, check the arguments, copy and re-hash the code, map, enter EL0, wait, classify, tear down. One call at a time, one slot.

The call signature (what an entry gets)

The ticks budget

The unit is timer ticks: one tick is one EL1 physical-timer interrupt, CNTFRQ/100 counter counts = 10 ms (the C kernel's scheduler tick, arch/timer.c). The budget is the unit's declared cpu_ticks, lowered (never raised) by max_ticks in the request. The timer is armed only for the duration of the task; the Nth tick that arrives while EL0 is running ends the task. A task shorter than one tick is never charged (ticks=0); the limit is accurate to one tick.

OUTCOME_UNKNOWN reaches the caller as struct osc_result: cls == OSC_RES_UNKNOWN (4) and unknown_reason: 1 FAULT, 2 TICK_OVERRUN, 3 LAUNCH_LOST, 4 TRAP_CODE_UNKNOWN, 255 OTHER (the spec's values). The other classes: RETURNED (1) with value, TRAPPED (2) with trap_code 1..14, REFUSED (3) with refused_code (40, 41, 30, 16 or 14). The reason is diagnostic and never changes the class.

Re-entry: yes, with a caller-owned workspace

A unit can be called again and see state left in a caller-owned cells workspace: pass the same struct ck_osc_ws ({ mem, pages }, page aligned, pages chosen by the caller, 0 to 32) in ck_osc_launch_req.ws. The kernel maps the caller's pages read-write (never executable) and does not clear them at teardown; the unit's own stack and registers are not kept, nothing else persists. The gate calls counter(ws, 1) three times on one workspace (1, 2, 3), once on a fresh one (1 again), and twice on a 23-page workspace (the OSH resumable size, 91,648 bytes) touching its very last cell: 1, then 2, state preserved. Section 9 allows this: borrows last for one call and the runtime keeps no reference. An OSH step that returns NEED_MORE_INPUT and is called again therefore works if all its state lives in that workspace. Not provided: alloc, arenas and pools (the runtime services behind vtable offsets 0 and 24..96), so a step that allocates through OscRt ends OUTCOME_UNKNOWN(OTHER).

What is enforced

Decisions (simplest honest option, with reasons)

  1. A bare brk is a fault, not TRAPPED. The brief said "TRAPPED with the BRK immediate for BRK 1..14". Spec 8.4 says a unit that reaches a brk has faulted and the platform reports OUTCOME_UNKNOWN(FAULT), "never TRAPPED"; 9.3 says a launcher never maps a fault to TRAPPED. The spec wins. TRAPPED comes from the real compiler sequence: the unit calls the runtime trap service with the code (ldr x16,[rt,#16]; blr x16, code in x1), served by the trap stub. The gate shows TRAPPED 3 and 14 that way, and brk reached directly as FAULT.
  2. The ticks budget uses the existing 10 ms timer interrupt, armed only while a task runs, with no preemption between tasks. This keeps the C kernel's scheduler untouched. Cost: 10 ms granularity.
  3. A caller cap on the budget (max_ticks), because the declared maximum of a signer is up to 1e9 ticks (a loop would run 115 days). The cap only lowers.
  4. Launcher hard maxima are stricter than the container's. Spec 8.2 step 16: a signer-declared budget above a hard maximum is refused LIMIT_EXCEEDED (14) before any reservation, nothing runs. The only declared budget the launcher bounds is max_stack_bytes, at 64 KiB: a stack of 65552 (65536 + 16, the smallest legal value above the maximum: the container needs a multiple of 16) gives 14 (gate line, unit l02_stack_over), and so does a06_valid_limits_at_max (1 MiB). cpu_ticks is never refused here; the caller cap max_ticks only lowers it (decision 3). pool_slots is not bounded: no pool service exists, a call to one ends OUTCOME_UNKNOWN(OTHER) (decision 6). Real reservation failures keep 30 (RESOURCE_UNAVAILABLE): code larger than 64 KiB, input over 4 KiB, task slot busy, no free address-space slot. The container has no workspace field (spec section 7), so there is no declared workspace to refuse. cpu_ticks and pool_slots have no launcher hard maximum, so they never get 14 from the launcher: the container already bounds them at admission (cpu_ticks up to 1e9, pool_slots up to 64), a lower tick limit is the caller's max_ticks (decision 3), and pool_slots reserves nothing because no pool service exists. 4a. The workspace is caller-sized, capped at 32 pages (128 KiB, OSC_WS_MAX_PAGES). The only workspace bound is the caller's. OSH needs 23 pages. 0 pages means no workspace. The cap bounds the user pages, page-table slots and kernel bss; it is the kernel's choice, never read from the container. A request over the cap, with a null or non-page-aligned mem, or overlapping the launcher's own state or the input buffer, is refused before anything is mapped with 30 (RESOURCE_UNAVAILABLE), the code spec 8.3 gives to a failed reservation of pages. The workspace is mapped read-write into EL0, so it MUST be memory the caller owns. The kernel has no region it limits workspaces to; beyond those checks it trusts the caller (also stated in osc_task.h). The mapping is never executable, is not cleared at teardown, and cells pointer checks use the actual size.
  5. Ownership failures use code 41. The spec gives no separate code for 9.1.1 item 4.
  6. Unprovided runtime services end the task as OUTCOME_UNKNOWN(OTHER) instead of being faked.
  7. Hand-assembled test unit. The extra gate units (trap, spin, faults, counter) are written in assembly (tests/fixtures/osc_unit/launch/l01.S) and signed with the spec's own generator helpers; oscc emits only digests, and OSC has no way to loop forever or fault. The IR section is min.ir, so the IR does not describe that code (attested, never checked: spec section 10).

Not done (later cuts)