From 630f5a0df40f5262f1c4e071450af65391aaad0f Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Mon, 16 Nov 2026 09:59:24 -0500 Subject: vgsp: eng89b - persist the colour-target bind across pushes Most beef draw pushes carry no colour-target bind of their own (the client binds the target once per context/target switch in an earlier state push), so the per-window admission refused the real frame pushes on most boots ('beef draw-synth: no valid last colour-target bind', the shallow-boot lottery). Track the last complete, plausible bind seen on a trusted push (same surface-class validity as the first-bind check; an invalid later write never overwrites a valid state) and admit a beef draw window on it: RT-PERSIST + '3D mark admitted (persisted colour-target bind)' receipts. Knob sema_gl_win_rt_persist, default 1. --- kernel/gsp_sema_service.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) (limited to 'kernel/gsp_sema_service.c') diff --git a/kernel/gsp_sema_service.c b/kernel/gsp_sema_service.c index 69b7341..f0f6632 100644 --- a/kernel/gsp_sema_service.c +++ b/kernel/gsp_sema_service.c @@ -12190,6 +12190,108 @@ static bool svc_gl_window_rt_first_valid(const u8 *buf, u32 len, u32 start_off, return false; } +/* + * eng89: persisted colour-target bind. + * + * The client binds its colour target once per context/target switch (an INC + * run over methods 0x800/0x804/0x808/0x80c), in a state push that is often + * NOT the push that carries the frame's draw window. The per-window + * admission checks below therefore refuse the real draw pushes on most + * boots ("beef draw-synth: no valid last colour-target bind"), which is the + * shallow-boot lottery. Track the last complete, plausible bind seen on a + * trusted push of this channel and admit a beef draw window on that + * persisted state. Only a bind that passes the same surface-class validity + * as svc_gl_window_rt_first_valid is stored, so a data blob cannot poison + * it (an invalid later write leaves the previous valid state in place). + */ +static u32 svc_gl_rtp_a[4], svc_gl_rtp_b[4], svc_gl_rtp_w[4], svc_gl_rtp_h[4]; +static u32 svc_gl_rtp_mask; +static u64 svc_gl_rtp_push; +static bool svc_gl_rtp = true; +module_param_named(sema_gl_win_rt_persist, svc_gl_rtp, bool, 0644); +MODULE_PARM_DESC(sema_gl_win_rt_persist, + "Remember the last valid colour-target bind from any trusted push and admit beef draw windows on that persisted state (default 1)"); + +static bool svc_gl_rtp_valid(void) +{ + return READ_ONCE(svc_gl_rtp_mask) != 0u; +} + +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 }; + bool sa[4] = { false }, sb[4] = { false }; + bool sw[4] = { false }, sh[4] = { false }; + u32 o = 0, j, nval = 0; + + if (!buf || len < 4u) + return; + while (o + 4u <= len) { + u32 hh, op, cnt, m, span = 1u, k; + + memcpy(&hh, buf + o, 4); + op = (hh >> 29) & 7u; + cnt = (hh >> 16) & 0xfffu; + m = (hh & 0x1fffu) << 2; + if ((op == 1u || op == 3u || op == 5u) && cnt && + o + 4u + cnt * 4u <= len) + span = 1u + cnt; + for (k = 0; k < span; k++) { + u32 mm = m + 4u * k, v = 0; + + if (k && op != 1u && op != 3u) + break; + if (k) + memcpy(&v, buf + o + 4u + k * 4u, 4); + else if (op == 4u) + v = (hh >> 16) & 0x1fffu; + else + continue; + for (j = 0; j < 4u; j++) { + u32 base = 0x800u + j * 0x40u; + + if (mm == base) { A[j] = v; sa[j] = true; } + else if (mm == base + 4u) { B[j] = v; sb[j] = true; } + else if (mm == base + 8u) { W[j] = v; sw[j] = true; } + else if (mm == base + 0xcu) { H[j] = v; sh[j] = true; } + } + } + o += span * 4u; + } + for (j = 0; j < 4u; j++) { + if (sa[j] && sb[j] && sw[j] && sh[j] && + (A[j] & ~0xffu) == 0 && (A[j] & 0xffu) <= 1u && + B[j] >= 0x08000000u && B[j] < 0x40000000u && + (B[j] & 3u) == 0 && W[j] > 0 && W[j] <= 0x4000u && + H[j] > 0 && H[j] <= 0x4000u) { + svc_gl_rtp_a[j] = A[j]; + svc_gl_rtp_b[j] = B[j]; + svc_gl_rtp_w[j] = W[j]; + svc_gl_rtp_h[j] = H[j]; + nval++; + } + } + if (nval) { + WRITE_ONCE(svc_gl_rtp_push, push); + smp_wmb(); + WRITE_ONCE(svc_gl_rtp_mask, READ_ONCE(svc_gl_rtp_mask) | 1u); + if (gsp_sema_dbg) { + static u32 rtp_log; + + if (rtp_log < 16u) { + rtp_log++; + pr_info("sema-gl: RT-PERSIST h=0x%llx push=0x%llx groups=%u A=%08x,%08x,%08x,%08x B=%08x,%08x,%08x,%08x W=%08x,%08x,%08x,%08x H=%08x,%08x,%08x,%08x\n", + (unsigned long long)h, + (unsigned long long)push, nval, + A[0], A[1], A[2], A[3], + B[0], B[1], B[2], B[3], + W[0], W[1], W[2], W[3], + H[0], H[1], H[2], H[3]); + } + } + } +} + static bool svc_gl_window_drawwin_ok(const u8 *buf, u32 len, u32 start_off, u32 at_off) { @@ -12209,6 +12311,24 @@ static bool svc_gl_window_drawwin_ok(const u8 *buf, u32 len, u32 start_off, } return true; } + /* + * eng89: the draw window usually carries no bind of its own (the + * target was bound by an earlier state push). Admit on the + * persisted bind when one is known; the replay context's RT state + * comes from the channel shadow, not from this window. + */ + if (READ_ONCE(svc_gl_rtp) && svc_gl_rtp_valid()) { + static u32 rtp_adm_log; + + if (rtp_adm_log < 16u) { + rtp_adm_log++; + pr_info("sema-gl: 3D mark admitted (persisted colour-target bind) start=0x%x at=0x%x win=%u words\n", + start_off, at_off, + at_off > start_off ? + (at_off - start_off) / 4u : 0u); + } + return true; + } return false; } @@ -12251,6 +12371,8 @@ static void svc_gl_flush(struct nv_vgpu_device *vgpu, svc_gl_arrival_note(push_va, buf, len); /* CONT.411: state at every flush entry for the kick channel. */ svc_gl_watch_note(ch, "entry", push_va, len, at_off, trusted); + if (trusted && READ_ONCE(svc_gl_rtp)) + svc_gl_rt_note(buf, len, ch->h_object, push_va); svc_gl_prog_apply_param(); if (!svc_gl.seen || !trusted) { svc_gl_watch_note(ch, !svc_gl.seen ? "early-noseen" : -- cgit v1.2.3