Repository navigation
Fix the G17 late-completion Oops in drm_sched_job_done() - #381
Merged
Merged
Conversation
drm_sched_init() resets every other piece of scheduler state but leaves free_guilty to whatever the caller's allocation held. The timeout worker frees the job it just handled whenever free_guilty is set, so a stale value makes the first timeout of a new scheduler free a job that is still running, with its callback still on the hardware fence. C drivers embed the scheduler in zeroed memory and never see this. Set it explicitly so recycled or reinitialised storage cannot carry it over. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
drm_sched_init() expects zeroed storage. It takes a non-NULL sched_rq to mean the scheduler is already set up, and it never writes free_guilty. Scheduler::new() allocated SchedulerInner with UniqueArc::new_uninit() and cleared only sched_rq, so free_guilty kept whatever the recycled kmalloc object held there. clang tests that bool against 1, and a stale 1 byte is common in freed kernel objects. drm_sched_job_timedout() checks free_guilty right after the timedout_job callback. When it is set, the first timeout of the scheduler frees the job it just timed out, even though the backend returned DRM_GPU_SCHED_STAT_NO_HANG and the job is still on the GPU. The job's callback stays on its hardware fence, and the late completion then runs drm_sched_job_done() on the freed job and faults on its cleared s_fence. That is the Neo Oops seen with stock Mesa running dEQP-VK.ray_query.stress.tess_control_shader.triangles, a NULL dereference at drm_sched_job_done+0x24 called from the G17 completion::Output::publish in the events_highpri worker, after which GPU completions stopped. Those jobs outlive the two second watchdog, and the bounded execution allowance runs the timeout worker on every poll, so every new queue gets a chance to hit a stale byte. Jobs that finish inside one poll never reach the timeout worker, so only workloads that really time out can trip it. Zero the whole drm_gpu_scheduler before drm_sched_init(), which also retires the old TODO. Split the initialisation from the allocation so KUnit can hand it dirty storage, and add rust_drm_sched tests for a late completion after repeated NO_HANG timeouts and for eight jobs completing out of order under repeated timeouts, with the last two cancelled by teardown before their late results arrive. All three fail without this change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
This was referenced Oct 23, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes the Oops the Neo hit on 73h during the CTS rerun, a NULL dereference in
drm_sched_job_done()called from the G17 completion path (completion::Output::publish) in the events_highpri worker. After it the worker died holding a fence lock and GPU completions stopped until a reboot.It wasn't the new timeout code itself. The Rust scheduler binding allocated its
drm_gpu_schedulerwithUniqueArc::new_uninit()and only clearedsched_rqbefore callingdrm_sched_init().drm_sched_init()never writesfree_guilty, so that byte kept whatever the recycled kmalloc object had in it. clang tests it against 1 and a stale 1 is pretty common. When it hit, the first timeout on that scheduler freed the job it had just timed out, even though G17 returned NO_HANG and the job was still running. Its callback was still on the hardware fence, so when the job really finisheddrm_sched_job_done()ran on the freed job and hit the cleareds_fence. That matches the dump exactly, fault ats_fence->schedwith the job's credits still readable.Only jobs that outlive the 2 s watchdog ever reach that code. The
ray_query.stressandposition_fetchcases on stock Mesa 0.6 do, and with the bounded allowance the timeout worker runs on every poll, so every new queue got plenty of chances to land on a bad byte.The fix zeroes the whole scheduler struct before
drm_sched_init(), which also clears out the old TODO there.drm_sched_init()now setsfree_guiltyitself as well, so C users with recycled storage can't trip over the same thing. No G17 driver changes were needed, its completion paths were already idempotent. The scheduler just shouldn't have been freeing a running job.Tests
rust_drm_schedKUnit suite that builds schedulers in deliberately dirty storage. It covers a late completion after repeated NO_HANG timeouts, and eight jobs completing out of order under repeated timeouts with the last two cancelled by teardown before their late results land. All three fail on the old init and pass with this.drm_schedC KUnit with panic_on_warn, 42/42.🤖 Generated with Claude Code