On Wed, 2026-11-11 at 15:05 +0000, Tvrtko Ursulin wrote: > jobs. It did not feel worth explicitly putting cc: stable on the patch.
OK. > > This is the *next* job's scheduled fence, so this sounds suspiciously > > racy. Testing the bit and overwriting the timestamp, can't that race? > > I have a feeling the code was assuming the default ordered workqueue > ensures either run_job or free_job runs at a time. So seeing timestamped > next fence guarantees free_job has exclusive right to the timestamp write. > > That is not true though for the three drivers which use own unordered > workqueues - pvr, nouveau and panthor. > > If we look at the drm_sched_run_job_work(): > ... > drm_sched_job_begin(sched_job); > -> puts on a pending_list for free job to find > ... > drm_sched_fence_scheduled(s_fence, fence); > -> signals the scheduled fence > ... > > If free_job interleaves in the middle, so it sees the next job but it > looks unscheduled it will skip the correction. I'm not even sure why this is done here. We just overwrite the fence's timestamp. Why? The fence gets marked (signaled) as scheduled in drm_sched_run_job_work(). Hence, that should be the relevant point in time. Why should free_job() have anything to do with that? Looks very suspicious. As if there are two redundant mechanisms here. > Yes I think you are right. As said I think there is no real bug due race > with unordered workqueues, but for formal correctness it would require a > memory barrier after test_bit, or full blown locking. Is it guaranteed that this fence is signaled and, thus, has a timestamp, or is it not? If it's guaranteed, the test_bit() is actually unnecessary. If it is not guaranteed, then there can be misordering between the two operations and it's UB and, thus, a bug. That said, I'm OK with your patch here being merged since you did not cause that chaos / problem, but a second patch with a FIXME about the issue that links this mail-thread would be good. P.
