Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/docs/IMAC_GPU_BENCH.md # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 18 1. **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. 21 2. **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. 24 3. 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 39 The 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). 43 It checks the manifest structure, that `signer_id` names a trusted key, the Ed25519 44 signature over the 448 signed bytes, and the image SHA-512. The trusted keys are the 45 same table NETLDR uses, generated with `ck_slot_tool keys-c`. 46 47 Make a slot object (the `ck_imac_swap` tool does not sign): 48 49 ``` 50 ck_slot_tool make-manifest --image IMACKERN-LAB.EFI --generation N --out M.bin 51 ck_slot_tool sign-test M.bin --out MS.bin # RFC 8032 TEST key: QEMU only 52 ck_slot_tool verify MS.bin --image IMACKERN-LAB.EFI --test-key 53 cat MS.bin IMACKERN-LAB.EFI > SLOT_OBJECT 54 ``` 55 56 For 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 61 Authentication key: 32-byte HMAC-SHA256 key, `bench_proto.h` `BENCH_TEST_KEY_INIT` 62 by 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 64 test key unless `--key ` gives a 32-byte binary key file. 65 `make imac-kernel CK_X86_BENCH_KEY_FILE=` binds the same file into the 66 image without the key ever appearing in a command line or build log (the generated 67 header is mode 600 inside the build directory); the ready line then says `this 68 image'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 71 Replay protection: a 64-bit counter. The kernel refuses any request whose counter is 72 not above the last one it accepted (the kernel keeps this until it reboots). 73 74 ``` 75 Request (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 84 Response (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 96 Commands (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 110 offset into BAR0. 111 112 Status 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 115 expired); `0x05` ERR_NODEV; `0x06` ERR_BUSY; `0x07` ERR_CMD. 116 117 The kernel answers an ALLONES read and carries on. The Spark tool is what stops the 118 batch: `ck_gpu_bench` sends nothing after an ERR_ALLONES reply. 119 120 BAR5 write allowlist (DWORD indexes, inclusive). Every number is from AMD's MIT register 121 headers 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 132 BAR5 reads: any index 0..65535. BAR0 (VRAM): words 0..65535 (the first 256 KiB only). 133 134 ## Build 135 136 ``` 137 make -C native/kernel imac-kernel CK_X86_REPORT=1 CK_TEST_SLOT_KEY=1 CK_X86_BENCH=1 138 make -C native/kernel imac-kernel CK_X86_REPORT=1 CK_SLOT_KEYS= CK_X86_BENCH=1 139 make -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=` | 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 152 The default `make imac-kernel` produces `IMACKERN.EFI` with none of the lab code. 153 154 ## Host tools 155 156 ### ck_gpu_bench 157 158 ``` 159 ck_gpu_bench [--key FILE] [--target IP | --serial PATH] [--transcript FILE] 160 ck_gpu_bench ping [same options] 161 ``` 162 163 Script 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 166 flipped), `stale CMD` (counter 1), `replay` (previous request again). Numbers accept 167 decimal or `0x`. 168 169 Output: one line per transaction, `