#!/usr/bin/env python3 """Stateful sequence fuzz: carry each invoke's OUTPUT into the next invoke's INPUT. Every fuzz so far issued independent invokes with a freshly built buffer, which cannot reach defects that need a sequence -- create, use, destroy, use again. That is exactly the shape of the GCP lifetime defects, and pass 94 recorded that the generic handle test was too coarse. This keeps the buffer live: the output of invoke N becomes the input of invoke N+1 (sometimes mutated), over long randomised command sequences, so handles the TA emits are fed straight back to it -- including after whatever command might free them. Detection: non-benign status, stall, write past the declared window, or drift in a fixed re-probe (cmd 0 on a pristine buffer) sampled periodically -- drift being the signature of corrupted internal state. """ import glob, random, struct, sys, time sys.path.insert(0,'/root/psp/hw') from tinygrad import Device import tinygrad.runtime.autogen.am.am as am from ring_wrap import install adev=Device["AMD"].iface.dev_impl; psp=adev.psp submit=install(psp,adev) PAT=0x22222222; WIN=0x4000; TOTAL=0x8000 BENIGN={0x0,0xffff0000} TAS={'GCP':'ta_22-0-0-77_7c426e7f','MERIT':'ta_24-0-0-70_5cd4afda','OPM':'ta_25-0-0-81_dc596ba6', 'CSU':'ta_42-0-0-6_1c874c3c','OC':'ta_50-0-0-1_cbd47c59','XGMI':'ta_32-0-0-20_20a3d1a4', 'AUC':'ta_16-0-0-9_9e9044cf'} name=sys.argv[1]; N=int(sys.argv[2]) if len(sys.argv)>2 else 1500 SKIP={'AUC':{6}}.get(name,set()) base=open(glob.glob('/root/psp/contall/'+TAS[name]+'*')[0],'rb').read() def alloc(n): pa=adev.mm.palloc(n,align=0x1000,zero=True,boot=False); return pa,adev.paddr2mc(pa) ap_,amc=alloc(0x80000); cp,cmc=alloc(TOTAL) n=(len(base)+3)&~3 adev.vram.view(ap_,n)[:]=base+b'\x00'*(n-len(base)); adev.gmc.flush_hdp() c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_LOAD_TA); t=c.cmd.cmd_load_ta t.app_phy_addr_lo,t.app_phy_addr_hi=amc&0xFFFFFFFF,amc>>32; t.app_len=len(base) t.cmd_buf_phy_addr_lo,t.cmd_buf_phy_addr_hi=cmc&0xFFFFFFFF,cmc>>32; t.cmd_buf_len=WIN r=submit(c); sid=r.resp.session_id print('%s load %#x sid=%s'%(name,r.resp.status&0xFFFFFFFF,sid), flush=True) def raw_invoke(cid): c=am.struct_psp_gfx_cmd_resp(cmd_id=am.GFX_CMD_ID_INVOKE_CMD) iv=c.cmd.cmd_invoke_cmd; iv.session_id,iv.ta_cmd_id=sid,cid t0=time.time() try: st=submit(c).resp.status&0xFFFFFFFF except Exception as e: try: st=int(str(e).strip().split()[-1])&0xFFFFFFFF except Exception: st=-1 return st, time.time()-t0 def probe(): b=bytearray(WIN); struct.pack_into('5: hits.append(('STALL',i,cid)); break adev.gmc.flush_hdp() o=bytes(adev.vram.view(cp,TOTAL)[:]) if any(struct.unpack_from('>16)!=0xffff: hits.append(('STATUS',i,cid,hex(st))) if i%300==0 and i: if probe()!=ref: hits.append(('DRIFT',i)); break adev.vram.view(cp+WIN,TOTAL-WIN)[:]=bytes(struct.pack('