drm/i915/execlists: Mark up the racy access to switch_priority_hint
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 9 Mar 2020 14:42:49 +0000 (14:42 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 9 Mar 2020 17:08:58 +0000 (17:08 +0000)
[ 7534.150687] BUG: KCSAN: data-race in __execlists_submission_tasklet [i915] / process_csb [i915]
[ 7534.150706]
[ 7534.150717] write to 0xffff8881f1bc24b4 of 4 bytes by task 24404 on cpu 3:
[ 7534.150925]  __execlists_submission_tasklet+0x1158/0x2780 [i915]
[ 7534.151133]  execlists_submit_request+0x2e8/0x2f0 [i915]
[ 7534.151348]  submit_notify+0x8f/0xc0 [i915]
[ 7534.151549]  __i915_sw_fence_complete+0x5d/0x3e0 [i915]
[ 7534.151753]  i915_sw_fence_complete+0x58/0x80 [i915]
[ 7534.151963]  i915_sw_fence_commit+0x16/0x20 [i915]
[ 7534.152179]  __i915_request_queue+0x60/0x70 [i915]
[ 7534.152388]  i915_gem_do_execbuffer+0x3997/0x4c20 [i915]
[ 7534.152598]  i915_gem_execbuffer2_ioctl+0x2c3/0x580 [i915]
[ 7534.152615]  drm_ioctl_kernel+0xe4/0x120
[ 7534.152629]  drm_ioctl+0x297/0x4c7
[ 7534.152642]  ksys_ioctl+0x89/0xb0
[ 7534.152654]  __x64_sys_ioctl+0x42/0x60
[ 7534.152667]  do_syscall_64+0x6e/0x2c0
[ 7534.152681]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 7534.152693]
[ 7534.152703] read to 0xffff8881f1bc24b4 of 4 bytes by interrupt on cpu 2:
[ 7534.152914]  process_csb+0xe7c/0x10a0 [i915]
[ 7534.153120]  execlists_submission_tasklet+0x30/0x170 [i915]
[ 7534.153138]  tasklet_action_common.isra.0+0x42/0xa0
[ 7534.153153]  __do_softirq+0xd7/0x2cd
[ 7534.153166]  run_ksoftirqd+0x15/0x20
[ 7534.153180]  smpboot_thread_fn+0x1ab/0x300
[ 7534.153194]  kthread+0x19a/0x1e0
[ 7534.153207]  ret_from_fork+0x1f/0x30

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200309144249.10309-1-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/gt/intel_lrc.c

index a1d2688..b5149e4 100644 (file)
@@ -1782,12 +1782,13 @@ timeslice(const struct intel_engine_cs *engine)
 static unsigned long
 active_timeslice(const struct intel_engine_cs *engine)
 {
-       const struct i915_request *rq = *engine->execlists.active;
+       const struct intel_engine_execlists *execlists = &engine->execlists;
+       const struct i915_request *rq = *execlists->active;
 
        if (!rq || i915_request_completed(rq))
                return 0;
 
-       if (engine->execlists.switch_priority_hint < effective_prio(rq))
+       if (READ_ONCE(execlists->switch_priority_hint) < effective_prio(rq))
                return 0;
 
        return timeslice(engine);
@@ -1804,8 +1805,11 @@ static void set_timeslice(struct intel_engine_cs *engine)
 static void start_timeslice(struct intel_engine_cs *engine)
 {
        struct intel_engine_execlists *execlists = &engine->execlists;
+       int prio = queue_prio(execlists);
 
-       execlists->switch_priority_hint = execlists->queue_priority_hint;
+       WRITE_ONCE(execlists->switch_priority_hint, prio);
+       if (prio == INT_MIN)
+               return;
 
        if (timer_pending(&execlists->timer))
                return;
@@ -5330,10 +5334,10 @@ void intel_execlists_show_requests(struct intel_engine_cs *engine,
 
        if (execlists->switch_priority_hint != INT_MIN)
                drm_printf(m, "\t\tSwitch priority hint: %d\n",
-                          execlists->switch_priority_hint);
+                          READ_ONCE(execlists->switch_priority_hint));
        if (execlists->queue_priority_hint != INT_MIN)
                drm_printf(m, "\t\tQueue priority hint: %d\n",
-                          execlists->queue_priority_hint);
+                          READ_ONCE(execlists->queue_priority_hint));
 
        last = NULL;
        count = 0;