diff options
author | Chunming Zhou <david1.zhou@amd.com> | 2015-07-23 22:49:47 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2015-08-17 16:50:38 -0400 |
commit | 176e1ab1b534368d0cd338a010aaea99067c3c6e (patch) | |
tree | 4a30358b9d603cf62eded5032665816ec3d2de97 | |
parent | e0d8f3c34e54b7f7563360131e89be0d9405d436 (diff) |
drm/amdgpu: protect fence_process from multiple context
fence_process may be called from kthread, user thread and interrupt context.
it is possible to called concurrently, then will wake up fence queue multiple times.
Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 2 |
3 files changed, 7 insertions, 2 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 1b8d05ff88e7..0703fbfd5130 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h | |||
@@ -869,6 +869,7 @@ struct amdgpu_ring { | |||
869 | struct amdgpu_fence_driver fence_drv; | 869 | struct amdgpu_fence_driver fence_drv; |
870 | struct amd_gpu_scheduler *scheduler; | 870 | struct amd_gpu_scheduler *scheduler; |
871 | 871 | ||
872 | spinlock_t fence_lock; | ||
872 | struct mutex *ring_lock; | 873 | struct mutex *ring_lock; |
873 | struct amdgpu_bo *ring_obj; | 874 | struct amdgpu_bo *ring_obj; |
874 | volatile uint32_t *ring; | 875 | volatile uint32_t *ring; |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c index 1580d8d7a3bf..b0e15b574606 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | |||
@@ -295,6 +295,7 @@ void amdgpu_fence_process(struct amdgpu_ring *ring) | |||
295 | uint64_t seq, last_seq, last_emitted; | 295 | uint64_t seq, last_seq, last_emitted; |
296 | unsigned count_loop = 0; | 296 | unsigned count_loop = 0; |
297 | bool wake = false; | 297 | bool wake = false; |
298 | unsigned long irqflags; | ||
298 | 299 | ||
299 | /* Note there is a scenario here for an infinite loop but it's | 300 | /* Note there is a scenario here for an infinite loop but it's |
300 | * very unlikely to happen. For it to happen, the current polling | 301 | * very unlikely to happen. For it to happen, the current polling |
@@ -317,6 +318,7 @@ void amdgpu_fence_process(struct amdgpu_ring *ring) | |||
317 | * have temporarly set the last_seq not to the true real last | 318 | * have temporarly set the last_seq not to the true real last |
318 | * seq but to an older one. | 319 | * seq but to an older one. |
319 | */ | 320 | */ |
321 | spin_lock_irqsave(&ring->fence_lock, irqflags); | ||
320 | last_seq = atomic64_read(&ring->fence_drv.last_seq); | 322 | last_seq = atomic64_read(&ring->fence_drv.last_seq); |
321 | do { | 323 | do { |
322 | last_emitted = ring->fence_drv.sync_seq[ring->idx]; | 324 | last_emitted = ring->fence_drv.sync_seq[ring->idx]; |
@@ -355,7 +357,7 @@ void amdgpu_fence_process(struct amdgpu_ring *ring) | |||
355 | if (handled_seq == latest_seq) { | 357 | if (handled_seq == latest_seq) { |
356 | DRM_ERROR("ring %d, EOP without seq update (lastest_seq=%llu)\n", | 358 | DRM_ERROR("ring %d, EOP without seq update (lastest_seq=%llu)\n", |
357 | ring->idx, latest_seq); | 359 | ring->idx, latest_seq); |
358 | return; | 360 | goto exit; |
359 | } | 361 | } |
360 | do { | 362 | do { |
361 | amd_sched_isr(ring->scheduler); | 363 | amd_sched_isr(ring->scheduler); |
@@ -364,6 +366,8 @@ void amdgpu_fence_process(struct amdgpu_ring *ring) | |||
364 | 366 | ||
365 | wake_up_all(&ring->adev->fence_queue); | 367 | wake_up_all(&ring->adev->fence_queue); |
366 | } | 368 | } |
369 | exit: | ||
370 | spin_unlock_irqrestore(&ring->fence_lock, irqflags); | ||
367 | } | 371 | } |
368 | 372 | ||
369 | /** | 373 | /** |
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c index 855e2196657a..1e68a561bbfe 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | |||
@@ -367,7 +367,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, | |||
367 | } | 367 | } |
368 | ring->next_rptr_gpu_addr = adev->wb.gpu_addr + (ring->next_rptr_offs * 4); | 368 | ring->next_rptr_gpu_addr = adev->wb.gpu_addr + (ring->next_rptr_offs * 4); |
369 | ring->next_rptr_cpu_addr = &adev->wb.wb[ring->next_rptr_offs]; | 369 | ring->next_rptr_cpu_addr = &adev->wb.wb[ring->next_rptr_offs]; |
370 | 370 | spin_lock_init(&ring->fence_lock); | |
371 | r = amdgpu_fence_driver_start_ring(ring, irq_src, irq_type); | 371 | r = amdgpu_fence_driver_start_ring(ring, irq_src, irq_type); |
372 | if (r) { | 372 | if (r) { |
373 | dev_err(adev->dev, "failed initializing fences (%d).\n", r); | 373 | dev_err(adev->dev, "failed initializing fences (%d).\n", r); |