physics-mv
FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.
Brought by drakestapleton
physics-mv / m16 / m16_requalify.c
| 1 | /* |
| 2 | * m16_requalify.c -- M16 libcuda-free causality qualification test. |
| 3 | * |
| 4 | * Sequence: |
| 5 | * 1. Initialize raw RM client (zero libcuda). |
| 6 | * 2. Create independent channel, USERD, and obtain work-submit token. |
| 7 | * 3. Allocate a GPU-uncached marker page (marker and marker2 = 0), so the |
| 8 | * chip's store reaches memory instead of sitting in its L2. |
| 9 | * 4. Construct M16 semaphore-release method stream (expected payload: 0x16c0ffee). |
| 10 | * 5. Enqueue work to GPFIFO ring WITHOUT ringing doorbell. |
| 11 | * 6. Negative control: wait 100ms, assert marker remains strictly 0. |
| 12 | * 7. Positive stimulus: ring doorbell with session work-submit token. |
| 13 | * 8. Assert marker changes to 0x16c0ffee. |
| 14 | * 9. Inspect /proc/self/maps to prove libcuda.so was never loaded. |
| 15 | * 10. Output machine-parsable receipts. |
| 16 | */ |
| 17 | #include "m16_native.h" |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <unistd.h> |
| 22 | |
| 23 | static int check_proc_maps(void) { |
| 24 | FILE *f = fopen("/proc/self/maps", "r"); |
| 25 | if (!f) return -1; |
| 26 | char line[512]; |
| 27 | int hit = 0; |
| 28 | while (fgets(line, sizeof(line), f)) { |
| 29 | if (strstr(line, "libcuda.so") || strstr(line, "libcudart.so")) { |
| 30 | hit = 1; |
| 31 | break; |
| 32 | } |
| 33 | } |
| 34 | fclose(f); |
| 35 | return hit; |
| 36 | } |
| 37 | |
| 38 | int main(int argc, char **argv) { |
| 39 | (void)argc; |
| 40 | (void)argv; |
| 41 | |
| 42 | printf("=== M16 CORRECTIVE REQUALIFICATION: CONTROLLED CAUSALITY TRANSACTION ===\n"); |
| 43 | |
| 44 | M16NativeContext ctx; |
| 45 | if (m16_native_open(&ctx) != 0) { |
| 46 | fprintf(stderr, "FATAL: m16_native_open failed: %s\n", ctx.rm.err); |
| 47 | return 1; |
| 48 | } |
| 49 | printf("[OBSERVED] RM client opened: GPU minor=%u compute_class=0x%x sm_version=0x%x\n", |
| 50 | ctx.rm.minor, ctx.rm.compute_class, ctx.rm.sm_version); |
| 51 | |
| 52 | if (m16_native_create_channel(&ctx) != 0) { |
| 53 | fprintf(stderr, "FATAL: m16_native_create_channel failed: %s\n", ctx.rm.err); |
| 54 | m16_native_close(&ctx); |
| 55 | return 1; |
| 56 | } |
| 57 | printf("[OBSERVED] Channel initialized: token=0x%08x gpfifo=0x%08x fifo_va=0x%lx doorbell=%p\n", |
| 58 | ctx.rm.token, ctx.rm.gpfifo, (unsigned long)ctx.rm.fifo.va, (void *)ctx.rm.doorbell); |
| 59 | |
| 60 | void *marker_cpu = NULL; |
| 61 | uint64_t marker_va = 0; |
| 62 | if (m16_native_alloc_memory_uncached(&ctx, 0x1000, &marker_cpu, &marker_va) != 0) { |
| 63 | fprintf(stderr, "FATAL: alloc marker failed: %s\n", ctx.rm.err); |
| 64 | m16_native_close(&ctx); |
| 65 | return 1; |
| 66 | } |
| 67 | volatile uint32_t *marker = (volatile uint32_t *)marker_cpu; |
| 68 | volatile uint32_t *marker2 = (volatile uint32_t *)((volatile uint8_t *)marker_cpu + M16_MARKER2_OFF); |
| 69 | *marker = 0; |
| 70 | *marker2 = 0; |
| 71 | printf("[OBSERVED] Uncached marker page at VA=0x%lx CPU=%p (marker=0x%08x marker2=0x%08x)\n", |
| 72 | (unsigned long)marker_va, marker_cpu, *marker, *marker2); |
| 73 | |
| 74 | uint32_t methods[64]; |
| 75 | int nwords = m16_native_build_release_flushed(methods, marker_va, 0x16c0ffee, ctx.rm.compute_class); |
| 76 | if (nwords <= 0) { |
| 77 | fprintf(stderr, "FATAL: build release failed\n"); |
| 78 | m16_native_close(&ctx); |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | /* Step 1: Enqueue to GPFIFO without ringing doorbell */ |
| 83 | printf("\n--- STEP 1: NEGATIVE CONTROL (DOORBELL WITHHELD) ---\n"); |
| 84 | if (m16_native_enqueue_methods(&ctx, methods, (size_t)nwords) != 0) { |
| 85 | fprintf(stderr, "FATAL: enqueue failed: %s\n", ctx.rm.err); |
| 86 | m16_native_close(&ctx); |
| 87 | return 1; |
| 88 | } |
| 89 | printf("[OBSERVED] Enqueued %d words to GPFIFO index %u. Withholding doorbell notification...\n", |
| 90 | nwords, ctx.rm.put - 1); |
| 91 | |
| 92 | /* Wait 100ms and verify marker has NOT changed */ |
| 93 | usleep(100000); |
| 94 | printf("[OBSERVED] Markers after 100ms without doorbell: 0x%08x / 0x%08x (expected 0x00000000 / 0x00000000)\n", |
| 95 | *marker, *marker2); |
| 96 | if (*marker != 0 || *marker2 != 0) { |
| 97 | fprintf(stderr, "FATAL: Negative control failed: marker changed without doorbell!\n"); |
| 98 | m16_native_close(&ctx); |
| 99 | return 2; |
| 100 | } |
| 101 | printf("NEGATIVE_CONTROL_PASS: Marker strictly remained 0x00000000 while doorbell was withheld.\n"); |
| 102 | |
| 103 | /* Step 2: Positive stimulus (Ring doorbell) */ |
| 104 | printf("\n--- STEP 2: POSITIVE STIMULUS (DOORBELL RUNG) ---\n"); |
| 105 | printf("[OBSERVED] Storing work-submit token 0x%08x to doorbell MMIO at %p...\n", |
| 106 | ctx.rm.token, (void *)ctx.rm.doorbell); |
| 107 | m16_native_ring_doorbell(&ctx); |
| 108 | |
| 109 | if (m16_native_wait_marker(marker, 0x16c0ffee, 2000) != 0) { |
| 110 | fprintf(stderr, "FATAL: Positive control failed: timeout waiting for marker 0x16c0ffee! Actual=0x%08x\n", |
| 111 | *marker); |
| 112 | m16_native_close(&ctx); |
| 113 | return 3; |
| 114 | } |
| 115 | printf("[OBSERVED] Marker after doorbell rung: 0x%08x (expected 0x16c0ffee)\n", *marker); |
| 116 | printf("POSITIVE_CONTROL_PASS: Marker successfully updated to 0x16c0ffee upon doorbell store.\n"); |
| 117 | |
| 118 | if (m16_native_wait_marker(marker2, M16_MARKER2_PAYLOAD, 2000) != 0) { |
| 119 | fprintf(stderr, "FATAL: Positive control failed: timeout waiting for the post-flush marker! Actual=0x%08x\n", |
| 120 | *marker2); |
| 121 | m16_native_close(&ctx); |
| 122 | return 3; |
| 123 | } |
| 124 | printf("[OBSERVED] Second marker after the L2 flush: 0x%08x (expected 0x%08x)\n", *marker2, M16_MARKER2_PAYLOAD); |
| 125 | |
| 126 | /* Step 3: Process mappings audit */ |
| 127 | int cuda_mapped = check_proc_maps(); |
| 128 | printf("\n--- STEP 3: RUNTIME LIBCUDA AUDIT ---\n"); |
| 129 | printf("[OBSERVED] libcuda.so / libcudart.so present in /proc/self/maps: %s\n", |
| 130 | cuda_mapped ? "YES (FAIL)" : "NO (PASS)"); |
| 131 | if (cuda_mapped) { |
| 132 | fprintf(stderr, "FATAL: libcuda detected in process address space!\n"); |
| 133 | m16_native_close(&ctx); |
| 134 | return 4; |
| 135 | } |
| 136 | printf("NO_LIBCUDA_PASS: Zero libcuda / libcudart mappings present in live process.\n"); |
| 137 | |
| 138 | printf("\nCAUSALITY_VERIFICATION_PASS: Doorbell causality strictly confirmed.\n"); |
| 139 | printf("M16_REQUALIFICATION_PASS: Milestone 16 native execution verified.\n"); |
| 140 | |
| 141 | nvrm_retire(&ctx.rm, ctx.rm.put); |
| 142 | m16_native_close(&ctx); |
| 143 | return 0; |
| 144 | } |