drm/exynos: fix pending update handling
authorAndrzej Hajda <a.hajda@samsung.com>
Mon, 26 Sep 2016 07:50:21 +0000 (16:50 +0900)
committerInki Dae <daeinki@gmail.com>
Fri, 30 Sep 2016 15:39:35 +0000 (00:39 +0900)
Exynos DRM devices update their registers at vblank time. Exynos-DRM uses
custom mechanism to wait for vblank. This mechanism is error prone -
variables are not updated atomically. As a result in certain circumstances
user space can try to free buffers which are still in use by hardware,
in such cases IOMMU can throw OOPS.
The patch instead of fixing the mechanism replaces it with drm core helper.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Inki Dae <inki.dae@samsung.com>
drivers/gpu/drm/exynos/exynos_drm_crtc.c
drivers/gpu/drm/exynos/exynos_drm_drv.c
drivers/gpu/drm/exynos/exynos_drm_drv.h

index 785ffa6cc30976694e6a31c6843038700b3e00cf..5b6845bc18fc7fc7f65528879e751e974fc57c61 100644 (file)
@@ -134,8 +134,6 @@ struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
        exynos_crtc->ops = ops;
        exynos_crtc->ctx = ctx;
 
-       init_waitqueue_head(&exynos_crtc->wait_update);
-
        crtc = &exynos_crtc->base;
 
        private->crtc[pipe] = crtc;
@@ -175,13 +173,6 @@ void exynos_drm_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe)
                exynos_crtc->ops->disable_vblank(exynos_crtc);
 }
 
-void exynos_drm_crtc_wait_pending_update(struct exynos_drm_crtc *exynos_crtc)
-{
-       wait_event_timeout(exynos_crtc->wait_update,
-                          (atomic_read(&exynos_crtc->pending_update) == 0),
-                          msecs_to_jiffies(50));
-}
-
 void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc,
                                struct exynos_drm_plane *exynos_plane)
 {
@@ -190,9 +181,6 @@ void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc,
 
        exynos_plane->pending_fb = NULL;
 
-       if (atomic_dec_and_test(&exynos_crtc->pending_update))
-               wake_up(&exynos_crtc->wait_update);
-
        spin_lock_irqsave(&crtc->dev->event_lock, flags);
        if (exynos_crtc->event)
                drm_crtc_send_vblank_event(crtc, exynos_crtc->event);
@@ -235,10 +223,8 @@ void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc,
        spin_lock_irqsave(&crtc->dev->event_lock, flags);
 
        e = exynos_crtc->event;
-       if (e && e->base.file_priv == file) {
+       if (e && e->base.file_priv == file)
                exynos_crtc->event = NULL;
-               atomic_dec(&exynos_crtc->pending_update);
-       }
 
        spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
 
index 486943e70f70bc7137a8e64a156cf8d12b8e9bc3..def78c8c1780a90ef8a8354770a3618276a506da 100644 (file)
@@ -45,37 +45,11 @@ struct exynos_atomic_commit {
        u32                     crtcs;
 };
 
-static void exynos_atomic_wait_for_commit(struct drm_atomic_state *state)
-{
-       struct drm_crtc_state *crtc_state;
-       struct drm_crtc *crtc;
-       int i, ret;
-
-       for_each_crtc_in_state(state, crtc, crtc_state, i) {
-               struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
-
-               if (!crtc->state->enable)
-                       continue;
-
-               ret = drm_crtc_vblank_get(crtc);
-               if (ret)
-                       continue;
-
-               exynos_drm_crtc_wait_pending_update(exynos_crtc);
-               drm_crtc_vblank_put(crtc);
-       }
-}
-
 static void exynos_atomic_commit_complete(struct exynos_atomic_commit *commit)
 {
        struct drm_device *dev = commit->dev;
        struct exynos_drm_private *priv = dev->dev_private;
        struct drm_atomic_state *state = commit->state;
-       struct drm_plane *plane;
-       struct drm_crtc *crtc;
-       struct drm_plane_state *plane_state;
-       struct drm_crtc_state *crtc_state;
-       int i;
 
        drm_atomic_helper_commit_modeset_disables(dev, state);
 
@@ -89,25 +63,9 @@ static void exynos_atomic_commit_complete(struct exynos_atomic_commit *commit)
         * have the relevant clocks enabled to perform the update.
         */
 
-       for_each_crtc_in_state(state, crtc, crtc_state, i) {
-               struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
-
-               atomic_set(&exynos_crtc->pending_update, 0);
-       }
-
-       for_each_plane_in_state(state, plane, plane_state, i) {
-               struct exynos_drm_crtc *exynos_crtc =
-                                               to_exynos_crtc(plane->crtc);
-
-               if (!plane->crtc)
-                       continue;
-
-               atomic_inc(&exynos_crtc->pending_update);
-       }
-
        drm_atomic_helper_commit_planes(dev, state, 0);
 
-       exynos_atomic_wait_for_commit(state);
+       drm_atomic_helper_wait_for_vblanks(dev, state);
 
        drm_atomic_helper_cleanup_planes(dev, state);
 
index 7f1a49d5bdbe876f5cd8dc81f659892743144e75..cee3a4c761060e4a9e2447b8006c45259fc5daf6 100644 (file)
@@ -173,8 +173,6 @@ struct exynos_drm_crtc {
        enum exynos_drm_output_type     type;
        unsigned int                    pipe;
        struct drm_pending_vblank_event *event;
-       wait_queue_head_t               wait_update;
-       atomic_t                        pending_update;
        const struct exynos_drm_crtc_ops        *ops;
        void                            *ctx;
        struct exynos_drm_clk           *pipe_clk;