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 / IMAC_GPU_BENCH.md

208 lines · 10544 bytes Raw Blame History Rendered
1# IMAC GPU Bench: interfaces for feat/imac-gpu-bench
2
3## Status (read this first)
4
5- **Live kernel swap over UDP is NOT BUILT.** `native/kernel/x86/swap_x86.c`
6 `recv_swap_udp` is gone; the receiver on port 47034 does not exist yet. The
7 verify, quiesce and jump path works, but only with the slot object staged on a
8 disk (QEMU test). A running iMac cannot receive a kernel over the network.
9- **GPU bench over UDP is built but NOT TESTED on hardware.** The lab image has the
10 tg3 receive and transmit path for port 47035 (`tg3_x86.c`). QEMU has no BCM57766,
11 so nothing here exercises it. The QEMU test drives the same protocol code over a
12 COM1 socket instead.
13- The BARs in the QEMU bench test are **RAM stand-ins**, not PCI emulation.
14- Nothing in this document has been run on an iMac.
15
16## Install instructions (corrected)
17
181. **The first lab kernel is installed by one normal netboot** (`NETLDR.EFI`, signed
19 with the owner key). The kernel that runs on the iMac today has no swap receiver,
20 so a live swap cannot deliver the first lab kernel.
212. **Later lab kernels are meant to arrive by live swap, with no firmware boot.**
22 That path is not working yet (see Status). Until the UDP receiver is built and
23 tested, each kernel is installed by netboot.
243. Only a lab build (`CK_X86_REPORT=1`) contains the swap receiver and the bench
25 console. A default image contains neither; the Makefile link step refuses a
26 default image that has the swap verifier or trampoline symbols.
27
28## Interfaces
29
30### Ports
31
32| Port | Purpose | Direction | Auth | Status |
33|-------|---------------|--------------|-----------------------|--------|
34| 47034 | Live swap | Spark to iMac | Ed25519 via ck_slot_verify | Not built (receiver stub removed) |
35| 47035 | GPU bench | Spark to iMac | HMAC-SHA256 | Lab build; tg3 path untested |
36
37### Live swap: slot object and verification
38
39The swap input is a signed slot object: one 4096-byte manifest unit
40(`native/boot/slot_format.h`) followed by the raw kernel PE image. It is verified by
41`ck_slot_verify` (`native/boot/slot_select.c`), the same function NETLDR.EFI calls
42(`native/boot/net_loader.c`, the `ck_slot_verify(m, obj + CK_SLOT_UNIT, ...)` call).
43It checks the manifest structure, that `signer_id` names a trusted key, the Ed25519
44signature over the 448 signed bytes, and the image SHA-512. The trusted keys are the
45same table NETLDR uses, generated with `ck_slot_tool keys-c`.
46
47Make a slot object (the `ck_imac_swap` tool does not sign):
48
49```
50ck_slot_tool make-manifest --image IMACKERN-LAB.EFI --generation N --out M.bin
51ck_slot_tool sign-test M.bin --out MS.bin # RFC 8032 TEST key: QEMU only
52ck_slot_tool verify MS.bin --image IMACKERN-LAB.EFI --test-key
53cat MS.bin IMACKERN-LAB.EFI > SLOT_OBJECT
54```
55
56For hardware, sign with the owner key (`ck_slot_tool tbs`, an offline signer, then
57`attach-sig`). The TEST key is refused for hardware by the tool.
58
59### GPU bench protocol (port 47035)
60
61Authentication key: 32-byte HMAC-SHA256 key, `bench_proto.h` `BENCH_TEST_KEY_INIT`
62by default (16 zero bytes followed by 0x01..0x10). A production build sets it with
63`CK_X86_BENCH_KEY=<32 bytes as C initialiser values>`. The Spark tool uses the built-in
64test key unless `--key <file>` gives a 32-byte binary key file.
65`make imac-kernel CK_X86_BENCH_KEY_FILE=<that file>` binds the same file into the
66image without the key ever appearing in a command line or build log (the generated
67header is mode 600 inside the build directory); the ready line then says `this
68image's own key` instead of `the TEST key`. The lab image of bundle 1 uses
69`~/.config/aienos/imac-bench.key` on the Spark.
70
71Replay protection: a 64-bit counter. The kernel refuses any request whose counter is
72not above the last one it accepted (the kernel keeps this until it reboots).
73
74```
75Request (Spark to iMac, 64 bytes):
76 magic[4] = "ABCH"
77 version u8 = 1
78 cmd u8 = BENCH_CMD_*
79 pad[2] = 0
80 counter u64 be (must be above the kernel's last accepted counter)
81 arg0..3 u32 be each (meaning per command, below)
82 hmac[32] = HMAC-SHA256(key, bytes 0..31)
83
84Response (iMac to Spark, 64 bytes):
85 magic[4] = "ABCR"
86 version u8 = 1
87 status u8 = BENCH_OK | BENCH_ERR_*
88 pad[2] = 0
89 counter u64 be (echoed; 0 on a bad-HMAC refusal)
90 tsc u64 be
91 result u32 be
92 before u32 be
93 hmac[32] = HMAC-SHA256(key, bytes 0..31) every response, errors included
94```
95
96Commands (arg0..arg3):
97
98| Code | Name | arg0 | arg1 | arg2 | arg3 |
99|------|---------------------|------------|-------------|----------|------------|
100| 0x00 | BENCH_CMD_PING | 0 | 0 | 0 | 0 |
101| 0x01 | BENCH_CMD_PCI_CFG | offset (dword aligned, 0..252) | 0 | 0 | 0 |
102| 0x02 | BENCH_CMD_BAR5_READ | reg_index | 0 | 0 | 0 |
103| 0x03 | BENCH_CMD_BAR5_WRITE| reg_index | value | 0 | 0 |
104| 0x04 | BENCH_CMD_BAR0_READ | word_off | 0 | 0 | 0 |
105| 0x05 | BENCH_CMD_BAR0_WRITE| word_off | value | 0 | 0 |
106| 0x06 | BENCH_CMD_BAR5_POLL | reg_index | mask | expected | timeout_ms |
107| 0x07 | BENCH_CMD_BAR5_RMW | reg_index | clear_mask | set_bits | 0 |
108
109`reg_index` is a DWORD index (byte offset = index x 4). `word_off` is a DWORD
110offset into BAR0.
111
112Status codes: `0x00` OK; `0x01` ERR_AUTH (bad HMAC, or counter not above the last);
113`0x02` ERR_RANGE (not on the allowlist, or offset out of range); `0x03` ERR_ALLONES
114(the read returned 0xFFFFFFFF: device gone); `0x04` ERR_TIMEOUT (TSC-bounded poll
115expired); `0x05` ERR_NODEV; `0x06` ERR_BUSY; `0x07` ERR_CMD.
116
117The kernel answers an ALLONES read and carries on. The Spark tool is what stops the
118batch: `ck_gpu_bench` sends nothing after an ERR_ALLONES reply.
119
120BAR5 write allowlist (DWORD indexes, inclusive). Every number is from AMD's MIT register
121headers in Linux, `drivers/gpu/drm/amd/include/asic_reg/dce/dce_11_2_d.h` and
122`smu/smu_7_1_3_d.h`:
123
124| Range | What sits there |
125|---|---|
126| `0x4800`-`0x4900` | UNIPHY link control, LVTMA panel power sequencer (`mmLVTMA_PWRSEQ_CNTL` 0x481b), backlight PWM (`mmBL_PWM_CNTL` 0x4820) |
127| `0x4A00`-`0x4C00` | DIG 0 and DIG 1 front ends: the HDMI and DisplayPort encoder blocks (`mmDIG_FE_CNTL` 0x4a00, `mmDIG1_DIG_FE_CNTL` 0x4b00, `mmDIG2_DIG_FE_CNTL` 0x4c00). Not the CRTC (`mmCRTC_STATUS` is 0x1ba3, not writable here). |
128| `0x1A04`-`0x1A12` | DCP0 graphics surface: `mmGRPH_PRIMARY_SURFACE_ADDRESS` 0x1a04, `mmGRPH_PITCH` 0x1a06, `mmGRPH_PRIMARY_SURFACE_ADDRESS_HIGH` 0x1a07, `mmGRPH_UPDATE` 0x1a11, `mmGRPH_FLIP_CONTROL` 0x1a12 (controller 0 only) |
129| `0x0094`-`0x0095` | SMC mailbox 0: `mmSMC_MESSAGE_0` 0x94, `mmSMC_RESP_0` 0x95 (the pair Linux `smu7_send_msg_to_smc` uses) |
130| `0x00A4` | `mmSMC_MSG_ARG_0` 0xa4 (the message argument) |
131
132BAR5 reads: any index 0..65535. BAR0 (VRAM): words 0..65535 (the first 256 KiB only).
133
134## Build
135
136```
137make -C native/kernel imac-kernel CK_X86_REPORT=1 CK_TEST_SLOT_KEY=1 CK_X86_BENCH=1
138make -C native/kernel imac-kernel CK_X86_REPORT=1 CK_SLOT_KEYS=<owner public keys file> CK_X86_BENCH=1
139make -C native/kernel ck-gpu-bench ck-imac-swap # host tools -> $(OUT)/host/
140```
141
142| Variable | Meaning |
143|----------|---------|
144| `CK_X86_REPORT=1` | Lab build: swap receiver, bench console, tg3 transmit, network report. Required for the two below. |
145| `CK_X86_BENCH=1` | Compile the bench console (lab only). |
146| `CK_X86_BENCH_KEY=` | Bench HMAC key bound into the image (default: test key). |
147| `CK_SLOT_KEYS=<file>` | Owner public keys for the swap verifier (same format as the NETLDR keys). Required in a lab build unless the next line is set. |
148| `CK_TEST_SLOT_KEY=1` | RFC 8032 TEST key for the swap verifier. QEMU tests only. |
149| `CK_X86_SWAP_TEST_DISK=1` | QEMU test: swap slot object read raw from SATA disk 2, LBA 2048. Lab only. |
150| `CK_X86_BENCH_TEST=1` | QEMU test: RAM stand-in BARs, bench packets as COM1 text lines. Lab only. |
151
152The default `make imac-kernel` produces `IMACKERN.EFI` with none of the lab code.
153
154## Host tools
155
156### ck_gpu_bench
157
158```
159ck_gpu_bench [--key FILE] [--target IP | --serial PATH] [--transcript FILE] <script.bench>
160ck_gpu_bench ping [same options]
161```
162
163Script lines: `ping`, `pci_cfg OFF`, `bar5_read REG`, `bar5_write REG VAL`,
164`bar0_read W`, `bar0_write W VAL`, `bar5_poll REG MASK EXPECTED MS`,
165`bar5_rmw REG CLEAR SET`. Prefixes for negative tests: `badauth CMD` (one HMAC byte
166flipped), `stale CMD` (counter 1), `replay` (previous request again). Numbers accept
167decimal or `0x`.
168
169Output: one line per transaction, `<label> <STATUS>: result=0x.. before=0x..`.
170Exit 0 all OK; 1 an error status or an ALLONES stop; 2 transport failure.
171
172The counter starts from the clock, so a second run is not refused by a kernel that
173has seen a previous run. `--transcript` writes every byte received on the serial
174link and every request sent.
175
176### ck_imac_swap (not usable against an iMac yet)
177
178```
179ck_imac_swap push <SLOT_OBJECT> [--target IP]
180```
181
182Sends a signed slot object (see above) to port 47034. The kernel side is not built,
183so the tool times out against a real iMac. It does not sign anything.
184
185## QEMU tests
186
187- `scripts/qemu_ck_imac_swap_test.sh`: boots kernel A, which teaches Allen one fact
188 and saves Allen's memory; A verifies slot B with `ck_slot_verify`, quiesces and
189 jumps into B in the same QEMU process; B must load the memory A saved. A second run
190 refuses a bad signature.
191- `scripts/qemu_ck_gpu_bench_test.sh`: boots the lab kernel with the test transport
192 and runs a script through the real `ck_gpu_bench --serial`. Covers ping, config and
193 BAR reads and writes, allowlist refusal, poll and read-modify-write, replay, bad
194 HMAC, stale counter, and the all-ones stop.
195
196Both tests run QEMU's emulated CPU and devices only. A PASS says the code does what
197it says in QEMU. It says nothing about the GPU, the BCM57766 or the iMac firmware.
198
199## Honest limits
200
201- The swap trampoline uses the AP trampoline page (`tramp_pa`, below 1 MiB). If the
202 frame allocator did not give a page there, the swap is refused.
203- The swap does not apply PE base relocations: both kernels must be linked at the
204 same addresses.
205- A wrong GPU write can wedge the PCIe link; only a power hold (firmware boot)
206 recovers. The allowlist and the before/after logging make this rare.
207- No multi-kernel in flight: a second swap request during a swap is refused.
208- The bench key in the QEMU test build is the public test key.