From 116b0ba7607277250bf0c5d694f55fd12d213d04 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Mon, 16 Nov 2026 19:11:58 -0500 Subject: vgsp: eng89q - scan every trusted 3D flush before admission; header-only admission; admit a header-DRAW window --- kernel/gsp_sema_service.c | 190 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 180 insertions(+), 10 deletions(-) (limited to 'kernel/gsp_sema_service.c') diff --git a/kernel/gsp_sema_service.c b/kernel/gsp_sema_service.c index e5e1000..d1ecfb1 100644 --- a/kernel/gsp_sema_service.c +++ b/kernel/gsp_sema_service.c @@ -11921,6 +11921,9 @@ static u32 svc_gl_chunk_boundary(const u8 *buf, u32 len, u32 start, static u32 svc_gl_draw_scan_log; static u64 svc_gl_draw_scan_seen[16]; static u32 svc_gl_draw_scan_pos; +static u64 svc_gl_mismatch_seen[16]; +static u32 svc_gl_mismatch_pos; +static u32 svc_gl_flush_log; static bool svc_gl_draw_scan_new_push(u64 push_va) { @@ -11934,6 +11937,19 @@ static bool svc_gl_draw_scan_new_push(u64 push_va) return true; } +/* eng89q: one DRAW-MISMATCH receipt per push (legacy alias vs header). */ +static bool svc_gl_mismatch_new_push(u64 push_va) +{ + u32 i; + + for (i = 0; i < ARRAY_SIZE(svc_gl_mismatch_seen); i++) + if (svc_gl_mismatch_seen[i] == push_va) + return false; + svc_gl_mismatch_seen[svc_gl_mismatch_pos++ % + ARRAY_SIZE(svc_gl_mismatch_seen)] = push_va; + return true; +} + static u32 svc_gl_draw_walk(const u32 *win, u32 n, u32 base_word, u32 *at, u32 *span_out, u32 *runs_out, bool log_it, struct svc_channel *ch, u64 push_va) @@ -12024,6 +12040,64 @@ static void svc_gl_draw_scan(struct svc_channel *ch, const u8 *buf, u32 len, } } +/* + * eng89q: pre-admission DRAW census. eng89p only walked the window inside + * svc_gl_stream_chunks(), i.e. after admission, so a draw-bearing window + * that admission refused was never scanned - the blind spot this receipt + * removes. Walk the window (then the whole push as the found_outside + * fallback) with the corrected header-only grammar, one receipt per push, + * and return whether the header is inside [start_off, at_off). Reuses the + * shared push ring, so the later svc_gl_draw_scan() does not duplicate the + * receipt while still computing the draw slice. + */ +static bool svc_gl_draw_scan_pre(struct svc_channel *ch, const u8 *buf, + u32 len, u32 start_off, u32 at_off, + bool *outside, u32 *at_out) +{ + u32 win_words, push_words, at = 0, span = 0, runs = 0; + u32 at2 = 0, span2 = 0, runs2 = 0; + u64 push_va = svc_gr_cand.push_va; + bool log_it, out = false, found_in_win = false; + u32 found; + + if (outside) + *outside = false; + if (at_out) + *at_out = 0; + log_it = svc_gl_draw_scan_new_push(push_va); + win_words = at_off > start_off ? (at_off - start_off) / 4u : 0u; + push_words = len / 4u; + found = 0; + if (win_words) + found = svc_gl_draw_walk((const u32 *)(buf + start_off), + win_words, start_off / 4u, &at, &span, + &runs, log_it, ch, push_va); + if (found) + found_in_win = true; + else if (push_words) { + found = svc_gl_draw_walk((const u32 *)buf, push_words, 0, + &at2, &span2, &runs2, log_it, ch, + push_va); + if (found) { + out = true; + at = at2; + runs = runs2; + } + } + if (log_it && svc_gl_draw_scan_log < 64u) { + svc_gl_draw_scan_log++; + pr_info("sema-gl: DRAW-SCAN-PRE h=0x%x push=0x%llx win_off=%u win_words=%u found=%u at=%u runs=%u%s\n", + ch->h_object, push_va, start_off / 4u, win_words, + found, at, runs, + out ? " found_outside=1" : ""); + } + if (outside) + *outside = out; + if (at_out) + *at_out = at; + return found_in_win; +} + static void svc_gl_stream_chunks(struct svc_channel *ch, const u8 *buf, u32 len, u32 at_off) { @@ -12591,12 +12665,12 @@ static bool svc_gl_rtp_valid(void) } /* - * Cheap draw marker for the persisted-admission path: the real beef draw - * windows carry BEGIN (0x1618), DRAW_VERTEX_ARRAY (0xd78) or a CALL(34) - * (0x3910). A data blob that happens to inherit a persisted bind is then - * not admitted as a 3D section. + * eng89q: the legacy byte-coverage marker. Kept only as the A/B reference + * for the DRAW-MISMATCH receipt; it accepts an interior word of a wide + * op=1/3 state run whose m0 lands on the draw method (the c997-c1001 + * false positive: 0x3910 inside a span=4353 run, never a CALL header). */ -static bool svc_gl_win_has_draw(const u8 *buf, u32 len) +static bool svc_gl_win_has_draw_legacy(const u8 *buf, u32 len) { u32 i; @@ -12635,6 +12709,38 @@ static bool svc_gl_win_has_draw(const u8 *buf, u32 len) return false; } +/* + * eng89q: header-only admission marker. Only a run header may carry the + * draw CALL: op=5 header 0xa00a0e44 (m0=0x3910, DRAW_IAB/CALL_MME_MACRO + * 34) or its CALL_MME_DATA sibling 0x3914, exactly the rule DRAW-SCAN and + * svc_gl_chunk_has_draw_ia() use (eng89p). Interior data words are + * skipped with the run's own 1+cnt span, so a wide state run can no longer + * admit a 14k-word non-draw window on an interior alias. + */ +static bool svc_gl_win_has_draw(const u8 *buf, u32 len) +{ + const u32 *win = (const u32 *)buf; + u32 n, r; + + if (!buf) + return false; + n = len / 4u; + for (r = 0; r < n;) { + u32 h = win[r]; + u32 op = (h >> 29) & 7u; + u32 cnt = (h >> 16) & 0x1fffu; + u32 span = 1u; + u32 m0 = (h & 0xfffu) << 2; + + if ((op <= 3u || op == 5u) && cnt && r + 1u + cnt <= n) + span = 1u + cnt; + if (m0 == 0x3910u || m0 == 0x3914u) + return true; + r += span; + } + return false; +} + static void svc_gl_rt_note(const u8 *buf, u32 len, u64 h, u64 push) { u32 A[4] = { 0 }, B[4] = { 0 }, W[4] = { 0 }, H[4] = { 0 }; @@ -12812,6 +12918,9 @@ static void svc_gl_flush(struct nv_vgpu_device *vgpu, const char *blob_src = "none"; const char *op_src = "stream"; u64 kick_va; + bool gl_win3d = false, gl_pre_found = false, gl_pre_outside = false; + bool gl_marker = false, gl_admitted = false, gl_draw_admit = true; + u32 gl_pre_at = 0; /* * SESSION 153 CONT.6 (task 1): record every section arrival (any @@ -13870,11 +13979,74 @@ static void svc_gl_flush(struct nv_vgpu_device *vgpu, * the 'd' operands are synthetic but the window bytes are real). Gate * to the beef family so no other client's capture changes lane. */ + /* + * eng89q: observe EVERY trusted 3D window before admission. eng89p + * only scanned inside svc_gl_stream_chunks(), so a draw-bearing + * window that admission refused was never scanned. marker is the + * legacy byte-coverage result, admitted the new header-only result; + * the pre-scan distinguishes found=0 (absent) from found_outside=1 + * (present elsewhere in the same push), and its in-window result + * powers the header-DRAW override below. + */ + gl_win3d = trusted && + (op_src[0] == 's' || op_src[0] == 'h' || + op_src[0] == 'd') && + at_off > svc_gl.start_off && svc_gr_cand.valid; + if (gl_win3d) { + gl_marker = svc_gl_win_has_draw_legacy(buf, len); + gl_admitted = svc_gl_win_has_draw(buf, len); + if (gl_marker && !gl_admitted && + svc_gl_mismatch_new_push(push_va)) + pr_info("sema-gl: DRAW-MISMATCH h=0x%x push=0x%llx interior=1 header=0 words=%u\n", + ch->h_object, push_va, + (at_off - svc_gl.start_off) / 4u); + gl_pre_found = svc_gl_draw_scan_pre(ch, buf, len, + svc_gl.start_off, at_off, + &gl_pre_outside, &gl_pre_at); + if (svc_gl_flush_log < 256u) { + svc_gl_flush_log++; + pr_info("sema-gl: GL-FLUSH h=0x%x push=0x%llx va=0x%llx words=%u marker=%u admitted=%u\n", + ch->h_object, push_va, + (unsigned long long)(push_va + + svc_gl.start_off), + (at_off - svc_gl.start_off) / 4u, + gl_marker ? 1u : 0u, + gl_admitted ? 1u : 0u); + } + } + /* + * eng89q: header-only admission. Refuse an interior-alias marker, + * but admit a window the header-only marker still rejects when the + * pre-admission census found the CALL header INSIDE this window and + * the persisted colour-target bind is live. Beef/stream3d lane + * only, behind the existing sema_gl_win_rt_persist and + * sema_gl_draw_synth knobs; the raw push/window geometry must still + * hold or the override would admit a window nothing can launch. + */ + if (op_src[0] == 'd' && + (ch->h_object & 0xfffff000u) == 0xbeef0000u) { + gl_draw_admit = svc_gl_window_drawwin_ok(buf, len, + svc_gl.start_off, + at_off, ch->h_object); + if (!gl_draw_admit && gl_win3d && gl_pre_found && + !gl_pre_outside && + READ_ONCE(svc_gl_rtp) && svc_gl_rtp_valid() && + READ_ONCE(gsp_sema_gl_draw_synth) && + gl_pre_at < (at_off - svc_gl.start_off) / 4u && + len == svc_gr_cand.push_n * 4 && + svc_gl.start_off + 8u <= at_off) { + gl_draw_admit = true; + pr_info("sema-gl: 3D mark admitted (header DRAW-SCAN override) h=0x%x push=0x%llx start=0x%x at=0x%x win=%u words at=%u\n", + ch->h_object, push_va, svc_gl.start_off, + at_off, + (at_off - svc_gl.start_off) / 4u, + gl_pre_at); + } + } if ((op_src[0] == 's' || op_src[0] == 'h' || (op_src[0] == 'd' && (ch->h_object & 0xfffff000u) == 0xbeef0000u && - svc_gl_window_drawwin_ok(buf, len, svc_gl.start_off, - at_off, ch->h_object))) && + gl_draw_admit)) && svc_gr_cand.valid && len == svc_gr_cand.push_n * 4 && svc_gl.start_off + 8u <= at_off && @@ -13900,9 +14072,7 @@ static void svc_gl_flush(struct nv_vgpu_device *vgpu, * diagnostic below names the failing condition (the next * bound to size). */ - if (op_src[0] == 'd' && - !svc_gl_window_drawwin_ok(buf, len, svc_gl.start_off, - at_off, ch->h_object)) { + if (op_src[0] == 'd' && !gl_draw_admit) { /* eng25: bounded witness when a beef draw-synth * window is refused - its last colour-target bind * is not a usable C597 RT (see the clause above). */ -- cgit v1.2.3