drm/radeon: Track the status of a page flip more explicitly

This prevents a panic: radeon_crtc_handle_page_flip() could run before
radeon_flip_work_func(), triggering the BUG_ON() in drm_vblank_put().

Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Michel Dänzer 2014-06-30 18:12:34 +09:00 committed by Alex Deucher
parent b0880e87c1
commit a2b6d3b33b
2 changed files with 21 additions and 5 deletions

View file

@ -285,7 +285,6 @@ static void radeon_unpin_work_func(struct work_struct *__work)
void radeon_crtc_handle_vblank(struct radeon_device *rdev, int crtc_id) void radeon_crtc_handle_vblank(struct radeon_device *rdev, int crtc_id)
{ {
struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id]; struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
struct radeon_flip_work *work;
unsigned long flags; unsigned long flags;
u32 update_pending; u32 update_pending;
int vpos, hpos; int vpos, hpos;
@ -295,8 +294,11 @@ void radeon_crtc_handle_vblank(struct radeon_device *rdev, int crtc_id)
return; return;
spin_lock_irqsave(&rdev->ddev->event_lock, flags); spin_lock_irqsave(&rdev->ddev->event_lock, flags);
work = radeon_crtc->flip_work; if (radeon_crtc->flip_status != RADEON_FLIP_SUBMITTED) {
if (work == NULL) { DRM_DEBUG_DRIVER("radeon_crtc->flip_status = %d != "
"RADEON_FLIP_SUBMITTED(%d)\n",
radeon_crtc->flip_status,
RADEON_FLIP_SUBMITTED);
spin_unlock_irqrestore(&rdev->ddev->event_lock, flags); spin_unlock_irqrestore(&rdev->ddev->event_lock, flags);
return; return;
} }
@ -344,12 +346,17 @@ void radeon_crtc_handle_flip(struct radeon_device *rdev, int crtc_id)
spin_lock_irqsave(&rdev->ddev->event_lock, flags); spin_lock_irqsave(&rdev->ddev->event_lock, flags);
work = radeon_crtc->flip_work; work = radeon_crtc->flip_work;
if (work == NULL) { if (radeon_crtc->flip_status != RADEON_FLIP_SUBMITTED) {
DRM_DEBUG_DRIVER("radeon_crtc->flip_status = %d != "
"RADEON_FLIP_SUBMITTED(%d)\n",
radeon_crtc->flip_status,
RADEON_FLIP_SUBMITTED);
spin_unlock_irqrestore(&rdev->ddev->event_lock, flags); spin_unlock_irqrestore(&rdev->ddev->event_lock, flags);
return; return;
} }
/* Pageflip completed. Clean up. */ /* Pageflip completed. Clean up. */
radeon_crtc->flip_status = RADEON_FLIP_NONE;
radeon_crtc->flip_work = NULL; radeon_crtc->flip_work = NULL;
/* wakeup userspace */ /* wakeup userspace */
@ -476,6 +483,7 @@ static void radeon_flip_work_func(struct work_struct *__work)
/* do the flip (mmio) */ /* do the flip (mmio) */
radeon_page_flip(rdev, radeon_crtc->crtc_id, base); radeon_page_flip(rdev, radeon_crtc->crtc_id, base);
radeon_crtc->flip_status = RADEON_FLIP_SUBMITTED;
spin_unlock_irqrestore(&crtc->dev->event_lock, flags); spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
up_read(&rdev->exclusive_lock); up_read(&rdev->exclusive_lock);
@ -544,7 +552,7 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,
/* We borrow the event spin lock for protecting flip_work */ /* We borrow the event spin lock for protecting flip_work */
spin_lock_irqsave(&crtc->dev->event_lock, flags); spin_lock_irqsave(&crtc->dev->event_lock, flags);
if (radeon_crtc->flip_work) { if (radeon_crtc->flip_status != RADEON_FLIP_NONE) {
DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
spin_unlock_irqrestore(&crtc->dev->event_lock, flags); spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
drm_gem_object_unreference_unlocked(&work->old_rbo->gem_base); drm_gem_object_unreference_unlocked(&work->old_rbo->gem_base);
@ -552,6 +560,7 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,
kfree(work); kfree(work);
return -EBUSY; return -EBUSY;
} }
radeon_crtc->flip_status = RADEON_FLIP_PENDING;
radeon_crtc->flip_work = work; radeon_crtc->flip_work = work;
/* update crtc fb */ /* update crtc fb */

View file

@ -306,6 +306,12 @@ struct radeon_atom_ss {
uint16_t amount; uint16_t amount;
}; };
enum radeon_flip_status {
RADEON_FLIP_NONE,
RADEON_FLIP_PENDING,
RADEON_FLIP_SUBMITTED
};
struct radeon_crtc { struct radeon_crtc {
struct drm_crtc base; struct drm_crtc base;
int crtc_id; int crtc_id;
@ -331,6 +337,7 @@ struct radeon_crtc {
/* page flipping */ /* page flipping */
struct workqueue_struct *flip_queue; struct workqueue_struct *flip_queue;
struct radeon_flip_work *flip_work; struct radeon_flip_work *flip_work;
enum radeon_flip_status flip_status;
/* pll sharing */ /* pll sharing */
struct radeon_atom_ss ss; struct radeon_atom_ss ss;
bool ss_enabled; bool ss_enabled;