interplane.Get Omega
Read in your language

physics-mv

FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.

Brought by drakestapleton

GitHub aien-dev/physics-mv#64 (code only)

closed derived bd6e82ea3b16a0d4 #64

Imported from GitHub aien-dev/physics-mv#64 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 31fd0ef2e88ff87d45c3ef8f910ea70c8006089d · Head b7b2bb3befd701944cd8907daedda6f3ea95b7ab

Apply it

git checkout -b patch-bd6e82ea3b16a0d4 31fd0ef2e88ff87d45c3ef8f910ea70c8006089d
curl -fsSL https://interplane.io/drakestapleton/physics-mv/patches/bd6e82ea3b16a0d4.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/physics-mv
64
b7b2bb3befd701944cd8907daedda6f3ea95b7ab
{"kind":"github-import","owner":"aien-dev","repo":"physics-mv","number":64,"url":"https://github.com/aien-dev/physics-mv/pull/64","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:28Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/.crumb b/.crumb
index ca626f5..d7af15d 100644
--- a/.crumb
+++ b/.crumb
@@ -67,8 +67,8 @@
           "purpose": "Directory m3. Purpose not yet described by a human."
         },
         {
-          "digest": "d0f12718c9a38b3aad75629ff3ba946363355fbb30a0598ab49f7cdb8b3c5745",
-          "last_commit": "a398deb",
+          "digest": "9b65ea2751e79aba09b3bfef56a5f9c87f36d8cf63e88cd97d7d97f170e97d12",
+          "last_commit": "21077bb",
           "name": "tests",
           "purpose": "Directory tests. Purpose not yet described by a human."
         },
@@ -85,15 +85,15 @@
           "purpose": "Directory tools. Purpose not yet described by a human."
         }
       ],
-      "children_root": "sha256:c4a43175d60d1449ab896a1a2875173ed408c49d377f192f57217e0d451ac3c6",
-      "compiled_at": "2026-10-18T21:39:40Z",
+      "children_root": "sha256:96eace2f6024440506c47b20aa7040b23acd20f55d3a97887417c6881a1a2fc2",
+      "compiled_at": "2026-10-18T23:06:33Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:74bf7c962359a303aa5f420d3bcc791166eb0b923bb42b159d306aad20823086",
+      "digest": "sha256:15d2907959fac8ab90d589e9a1099118bac1a48d77b972df2bf0a9b177b937a9",
       "evidence_files": 81,
       "evidence_root": "sha256:0a0459a4517679721bb2817540dd06995500a1c1ede079bc4665d9da5c39183d",
       "files": 285,
-      "generated_at_commit": "a398debca4591dc6c0dab2a2e0b631efddd0aa2f",
-      "source_tree": "sha256:1b9d06927034e729ded03678e8fe6a4d3929fcffb0510eff40607c8185ba8cd1"
+      "generated_at_commit": "21077bb0b8556b184d97ef6ac953936a7440092e",
+      "source_tree": "sha256:9e4622083507c05046a0c7c8539f2cab868b2a456f67327989d093073114ea79"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/nvrm/lifecycle_gates.c b/nvrm/lifecycle_gates.c
index 3106fea..d7c77c8 100644
--- a/nvrm/lifecycle_gates.c
+++ b/nvrm/lifecycle_gates.c
@@ -308,6 +308,43 @@ static int gate_gpu_submit_after_churn(Nvrm *rm) {
     return 0;
 }
 
+
+/* omega#523: the compute-object RM_ALLOC is refused with NV_ERR_NO_MEMORY when
+ * the host has no free 2 MiB block at that instant. nvrm_channel must retry that
+ * one allocation, bounded, instead of failing the channel on the first refusal. */
+static int gate_channel_no_memory_retried(void) {
+    Nvrm rm;
+    if (nvrm_open(&rm) != 0) return -1;
+    rm.inject_rm_alloc_no_memory = 3;
+    rm.channel_no_memory_retry_ms = 1;
+    int rc = nvrm_channel(&rm);
+    int ok = rc == 0 && rm.compute_obj != 0 && rm.channel_no_memory_retries == 3 &&
+             rm.inject_rm_alloc_no_memory == 0;
+    if (!ok) printf("  channel after 3 injected NV_ERR_NO_MEMORY: rc=%d retries=%u err=\"%s\"\n",
+                    rc, rm.channel_no_memory_retries, rm.err);
+    nvrm_close(&rm);
+    return ok ? 0 : -1;
+}
+
+/* The retry is bounded: one refusal more than the budget is final, the channel
+ * has no compute object, and the error names the attempts and the host's supply
+ * of 2 MiB blocks so the next reader does not have to guess. */
+static int gate_channel_no_memory_bounded(void) {
+    Nvrm rm;
+    if (nvrm_open(&rm) != 0) return -1;
+    rm.inject_rm_alloc_no_memory = (uint8_t)(NVRM_CHANNEL_NO_MEMORY_RETRIES + 1);
+    rm.channel_no_memory_retry_ms = 1;
+    int rc = nvrm_channel(&rm);
+    int ok = rc != 0 && rm.compute_obj == 0 &&
+             rm.channel_no_memory_retries == NVRM_CHANNEL_NO_MEMORY_RETRIES &&
+             strstr(rm.err, "NV_ERR_NO_MEMORY") != NULL && strstr(rm.err, "attempts") != NULL &&
+             strstr(rm.err, "2 MiB blocks") != NULL;
+    if (!ok) printf("  bounded retry: rc=%d retries=%u err=\"%s\"\n", rc, rm.channel_no_memory_retries, rm.err);
+    int closed = nvrm_close(&rm) == 0;
+    if (!closed) printf("  bounded retry: close after refused channel failed: %s\n", rm.err);
+    return ok && closed ? 0 : -1;
+}
+
 int main(void) {
     printf("=== M19R NVRM LIFECYCLE GATES ===\n");
 
@@ -345,6 +382,8 @@ int main(void) {
     gate_result("UVM_FREE_FAILURE_QUARANTINES", gate_injected_free_failure(1) == 0);
     gate_result("RM_FREE_FAILURE_QUARANTINES", gate_injected_free_failure(0) == 0);
     gate_result("CORRUPT_TABLE_REFUSED", gate_corrupt_table_refusal() == 0);
+    gate_result("CHANNEL_NO_MEMORY_RETRIED", gate_channel_no_memory_retried() == 0);
+    gate_result("CHANNEL_NO_MEMORY_BOUNDED", gate_channel_no_memory_bounded() == 0);
     printf("TOTAL: %d PASSED: %d FAILED: %d\n", g_total, g_passed, g_failed);
     return (g_failed == 0) ? 0 : 1;
 }
diff --git a/nvrm/nvrm.c b/nvrm/nvrm.c
index 3961b05..406a788 100644
--- a/nvrm/nvrm.c
+++ b/nvrm/nvrm.c
@@ -11,6 +11,7 @@
 #include <stddef.h>
 #include <stdatomic.h>
 #include <fcntl.h>
+#include <limits.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
@@ -86,6 +87,45 @@ static int fail_alloc_context(Nvrm *rm, uint64_t size) {
                 (unsigned long long)size, meminfo_kb("MemFree"), meminfo_kb("MemAvailable"));
 }
 
+/* Free physically contiguous blocks of at least `order` pages across all zones
+ * (/proc/buddyinfo), or ULLONG_MAX when the file cannot be read. Order 9 is the
+ * 2 MiB block the channel's main context buffer needs. */
+static unsigned long long buddy_free_blocks_ge(unsigned order) {
+    FILE *f = fopen("/proc/buddyinfo", "r");
+    if (!f) return ULLONG_MAX;
+    char line[512];
+    unsigned long long total = 0;
+    while (fgets(line, sizeof line, f)) {
+        const char *p = strstr(line, "zone");
+        if (!p) continue;
+        p += 4;
+        while (*p == ' ') p++;
+        while (*p && *p != ' ') p++;           /* zone name */
+        unsigned long long n;
+        for (unsigned o = 0; o < 32 && sscanf(p, " %llu", &n) == 1; o++) {
+            if (o >= order) total += n;
+            while (*p == ' ') p++;
+            while (*p && *p != ' ') p++;
+        }
+    }
+    fclose(f);
+    return total;
+}
+
+/* Rewrite rm->err after the compute-object RM_ALLOC stayed NV_ERR_NO_MEMORY
+ * through every retry, so the line names the attempts, the wait and the host's
+ * supply of 2 MiB blocks at that moment. */
+static int fail_channel_no_memory(Nvrm *rm, uint32_t attempts, uint32_t delay_ms) {
+    char prev[sizeof rm->err];
+    memcpy(prev, rm->err, sizeof prev);
+    unsigned long long blocks = buddy_free_blocks_ge(9);
+    char blocks_text[32];
+    if (blocks == ULLONG_MAX) snprintf(blocks_text, sizeof blocks_text, "UNKNOWN");
+    else snprintf(blocks_text, sizeof blocks_text, "%llu", blocks);
+    return fail(rm, "%s after %u attempts over %u ms; MemFree %llu kB, free 2 MiB blocks %s", prev, attempts,
+                (attempts > 1 ? attempts - 1 : 0) * delay_ms, meminfo_kb("MemFree"), blocks_text);
+}
+
 static int nv_ioctl(int fd, unsigned nr, void *arg, size_t sz) {
     return ioctl(fd, NV_IOWR(nr, sz), arg);
 }
@@ -93,6 +133,12 @@ static int nv_ioctl(int fd, unsigned nr, void *arg, size_t sz) {
 static int uvm(Nvrm *rm, int fd, unsigned long cmd, void *params, NV_STATUS *st);
 
 static int rm_alloc(Nvrm *rm, uint32_t parent, uint32_t cls, void *params, uint32_t psz, uint32_t *out) {
+    rm->last_rm_status = 0;
+    if (cls == rm->compute_class && rm->inject_rm_alloc_no_memory) {
+        rm->inject_rm_alloc_no_memory--;
+        rm->last_rm_status = NV_ERR_NO_MEMORY;
+        return fail(rm, "RM_ALLOC class 0x%x status 0x%x (NV_ERR_NO_MEMORY) [injected]", cls, NV_ERR_NO_MEMORY);
+    }
     if (rm->rm_alloc_accepted == UINT64_MAX ||
         (cls != NV01_ROOT_CLIENT && rm->next_handle == UINT32_MAX))
         return fail(rm, "RM handle or accounting space exhausted");
@@ -106,6 +152,7 @@ static int rm_alloc(Nvrm *rm, uint32_t parent, uint32_t cls, void *params, uint3
     p.paramsSize = psz;
     if (nv_ioctl(rm->fd_ctl, NV_ESC_RM_ALLOC, &p, sizeof p) != 0)
         return fail(rm, "RM_ALLOC class 0x%x ioctl errno %d", cls, errno);
+    rm->last_rm_status = p.status;
     if (p.status != 0)
         return fail(rm, "RM_ALLOC class 0x%x status 0x%x%s", cls, p.status,
                     p.status == NV_ERR_NO_MEMORY ? " (NV_ERR_NO_MEMORY)" : "");
@@ -676,7 +723,21 @@ int nvrm_channel(Nvrm *rm) {
     gp.engineType = 0;
     gp.hContextShare = rm->ctxshare;
     if (rm_alloc(rm, rm->chgroup, rm->gpfifo_class, &gp, sizeof gp, &rm->gpfifo)) return -1;
-    if (rm_alloc(rm, rm->gpfifo, rm->compute_class, NULL, 0, &rm->compute_obj)) return -1;
+    /* NV_ERR_NO_MEMORY here is the host lacking one free 2 MiB block for the
+     * channel's main context buffer at this instant (see nvrm.h, omega#523).
+     * Retry that one RM_ALLOC, bounded; any other status is final at once. */
+    uint32_t delay_ms = rm->channel_no_memory_retry_ms ? rm->channel_no_memory_retry_ms
+                                                       : NVRM_CHANNEL_NO_MEMORY_RETRY_MS;
+    const uint32_t budget = NVRM_CHANNEL_NO_MEMORY_RETRIES;
+    rm->channel_no_memory_retries = 0;
+    for (;;) {
+        if (rm_alloc(rm, rm->gpfifo, rm->compute_class, NULL, 0, &rm->compute_obj) == 0) break;
+        if (rm->last_rm_status != NV_ERR_NO_MEMORY) return -1;
+        if (rm->channel_no_memory_retries >= budget)
+            return fail_channel_no_memory(rm, rm->channel_no_memory_retries + 1, delay_ms);
+        rm->channel_no_memory_retries++;
+        usleep((useconds_t)delay_ms * 1000u);
+    }
 
     NVC36F_CTRL_CMD_GPFIFO_GET_WORK_SUBMIT_TOKEN_PARAMS tk = { .workSubmitToken = 0xffffffffu };
     if (rm_control(rm, rm->gpfifo, NVC36F_CTRL_CMD_GPFIFO_GET_WORK_SUBMIT_TOKEN, &tk, sizeof tk)) return -1;
diff --git a/nvrm/nvrm.h b/nvrm/nvrm.h
index 59fa931..7558f03 100644
--- a/nvrm/nvrm.h
+++ b/nvrm/nvrm.h
@@ -35,6 +35,21 @@ typedef struct {
     uint64_t size;
 } NvrmVaRange;
 
+/* The compute object makes the RM allocate the channel's main graphics context
+ * buffer as ONE physically contiguous 2 MiB system-memory block (order 9), asked
+ * for once with __GFP_RETRY_MAYFAIL and no scattered fallback (open driver
+ * kernel-open/nvidia/nv-vm.c:377-391, kernel_graphics_context.c:1129; kernel
+ * tracepoint record in omega#523). On a long-running host that block is often
+ * missing for a few hundred milliseconds, so nvrm_channel retries that one
+ * RM_ALLOC, bounded, before NV_ERR_NO_MEMORY is final. Measured 2026-10-17 on
+ * the Spark: every refusal cleared within 5 attempts at 100 ms (omega#523). */
+#ifndef NVRM_CHANNEL_NO_MEMORY_RETRIES
+#define NVRM_CHANNEL_NO_MEMORY_RETRIES 50
+#endif
+#ifndef NVRM_CHANNEL_NO_MEMORY_RETRY_MS
+#define NVRM_CHANNEL_NO_MEMORY_RETRY_MS 100
+#endif
+
 /* One outstanding allocation, tracked so nvrm_free() can tell a real,
  * still-live NvrmMem apart from a stale/duplicate copy. */
 typedef struct {
@@ -82,6 +97,12 @@ typedef struct {
     /* Fault injection applies once at the driver wrapper boundary. */
     uint8_t       inject_uvm_free_failure;
     uint8_t       inject_rm_free_failure;
+    /* Refuse the next N compute-object RM_ALLOCs with NV_ERR_NO_MEMORY before
+     * the ioctl, so the retry in nvrm_channel can be exercised deterministically. */
+    uint8_t       inject_rm_alloc_no_memory;
+    uint32_t      last_rm_status;             /* status of the last RM_ALLOC that reached the driver (or was injected) */
+    uint32_t      channel_no_memory_retries;  /* NV_ERR_NO_MEMORY refusals the last nvrm_channel retried */
+    uint32_t      channel_no_memory_retry_ms; /* delay between those retries; 0 selects NVRM_CHANNEL_NO_MEMORY_RETRY_MS */
     uint64_t      rm_alloc_accepted;
     uint64_t      rm_free_accepted;
     char     err[256];
diff --git a/tests/.crumb b/tests/.crumb
index 8ec8b60..03df409 100644
--- a/tests/.crumb
+++ b/tests/.crumb
@@ -20,14 +20,14 @@
         }
       ],
       "children_root": "sha256:be29e4df8a1e9e426d7723fccf6e09f23eb6fb07a6b21490cd019c75d6fed6cd",
-      "compiled_at": "2026-10-18T21:39:40Z",
+      "compiled_at": "2026-10-18T23:06:33Z",
       "compiler": "crumb-compile/1",
-      "digest": "sha256:d0f12718c9a38b3aad75629ff3ba946363355fbb30a0598ab49f7cdb8b3c5745",
+      "digest": "sha256:9b65ea2751e79aba09b3bfef56a5f9c87f36d8cf63e88cd97d7d97f170e97d12",
       "evidence_files": 0,
       "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
       "files": 36,
-      "generated_at_commit": "a398debca4591dc6c0dab2a2e0b631efddd0aa2f",
-      "source_tree": "sha256:faa32cc28f11c2966c9463322c40688966f8a61da2d6e0b3a30a6dd280f2d1c1"
+      "generated_at_commit": "21077bb0b8556b184d97ef6ac953936a7440092e",
+      "source_tree": "sha256:53c9e955d5ba8ff3de7a58d2bc8a13437f7e3068e0fbd18e742a6bb5648c8a7f"
     },
     "owner_lane": "",
     "provenance": {
diff --git a/tests/run_nvrm_lifecycle_gates.sh b/tests/run_nvrm_lifecycle_gates.sh
index 216f107..75ca2b5 100755
--- a/tests/run_nvrm_lifecycle_gates.sh
+++ b/tests/run_nvrm_lifecycle_gates.sh
@@ -12,6 +12,7 @@ echo "=== M19R NVRM Lifecycle Gates ==="
 echo "Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
 echo "Host: $(uname -n) ($(uname -m))"
 
+mkdir -p build
 echo -e "\n[*] Building lifecycle_gates..."
 gcc -O2 -Wall -Wextra -Werror \
   -I./nvrm -I./m16 \
@@ -19,13 +20,13 @@ gcc -O2 -Wall -Wextra -Werror \
   -I./third_party/nvidia-open-580.173.02/kernel-open/common/inc \
   -I./third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \
   -I./third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include \
-  nvrm/nvrm.c m16/m16_native.c nvrm/lifecycle_gates.c -o nvrm/lifecycle_gates
+  nvrm/nvrm.c m16/m16_native.c nvrm/lifecycle_gates.c -o build/lifecycle_gates
 
 echo "    lifecycle_gates built cleanly."
 
 echo -e "\n[*] Running lifecycle_gates under GPU lock ($GB10_LOCK)..."
 gb10_lock_acquire
-./nvrm/lifecycle_gates
+./build/lifecycle_gates
 gb10_lock_release
 
 echo -e "\n=== M19R NVRM Lifecycle Gates: done ==="
diff --git a/tests/run_submission_visibility_gates.sh b/tests/run_submission_visibility_gates.sh
index 74a4f9c..4b356d1 100755
--- a/tests/run_submission_visibility_gates.sh
+++ b/tests/run_submission_visibility_gates.sh
@@ -12,6 +12,7 @@ echo "=== GB10 Submission Visibility Gates ==="
 echo "Timestamp: $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
 echo "Host: $(uname -n) ($(uname -m))"
 
+mkdir -p build
 echo -e "\n[*] Building submission_visibility_gates..."
 gcc -O2 -Wall -Wextra -Werror \
   -I./nvrm -I./m16 \
@@ -19,7 +20,7 @@ gcc -O2 -Wall -Wextra -Werror \
   -I./third_party/nvidia-open-580.173.02/kernel-open/common/inc \
   -I./third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \
   -I./third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include \
-  nvrm/nvrm.c m16/m16_native.c nvrm/submission_visibility_gates.c -o nvrm/submission_visibility_gates
+  nvrm/nvrm.c m16/m16_native.c nvrm/submission_visibility_gates.c -o build/submission_visibility_gates
 
 echo "    submission_visibility_gates built cleanly."
 
@@ -30,7 +31,7 @@ fi
 
 echo -e "\n[*] Running submission_visibility_gates under GPU lock ($GB10_LOCK)..."
 gb10_lock_acquire
-./nvrm/submission_visibility_gates
+./build/submission_visibility_gates
 gb10_lock_release
 
 echo -e "\n=== GB10 Submission Visibility Gates: done ==="