]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/atomic-helper: reset vblank on crtc reset
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 12 Jun 2020 16:00:49 +0000 (18:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:29:50 +0000 (11:29 +0200)
[ Upstream commit 51f644b40b4b794b28b982fdd5d0dd8ee63f9272 ]

Only when vblanks are supported ofc.

Some drivers do this already, but most unfortunately missed it. This
opens up bugs after driver load, before the crtc is enabled for the
first time. syzbot spotted this when loading vkms as a secondary
output. Given how many drivers are buggy it's best to solve this once
and for all in shared helper code.

Aside from moving the few existing calls to drm_crtc_vblank_reset into
helpers (i915 doesn't use helpers, so keeps its own) I think the
regression risk is minimal: atomic helpers already rely on drivers
calling drm_crtc_vblank_on/off correctly in their hooks when they
support vblanks. And driver that's failing to handle vblanks after
this is missing those calls already, and vblanks could only work by
accident when enabling a CRTC for the first time right after boot.

Big thanks to Tetsuo for helping track down what's going wrong here.

There's only a few drivers which already had the necessary call and
needed some updating:
- komeda, atmel and tidss also needed to be changed to call
  __drm_atomic_helper_crtc_reset() intead of open coding it
- tegra and msm even had it in the same place already, just code
  motion, and malidp already uses __drm_atomic_helper_crtc_reset().
- Laurent noticed that rcar-du and omap open-code their crtc reset and
  hence would actually be broken by this patch now. So fix them up by
  reusing the helpers, which brings the drm_crtc_vblank_reset() back.

Only call left is in i915, which doesn't use drm_mode_config_reset,
but has its own fastboot infrastructure. So that's the only case where
we actually want this in the driver still.

I've also reviewed all other drivers which set up vblank support with
drm_vblank_init. After the previous patch fixing mxsfb all atomic
drivers do call drm_crtc_vblank_on/off as they should, the remaining
drivers are either legacy kms or legacy dri1 drivers, so not affected
by this change to atomic helpers.

v2: Use the drm_dev_has_vblank() helper.

v3: Laurent pointed out that omap and rcar-du used drm_crtc_vblank_off
instead of drm_crtc_vblank_reset. Adjust them too.

v4: Laurent noticed that rcar-du and omap open-code their crtc reset
and hence would actually be broken by this patch now. So fix them up
by reusing the helpers, which brings the drm_crtc_vblank_reset() back.

v5: also mention rcar-du and ompadrm in the proper commit message
above (Laurent).

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Maxime Ripard <mripard@kernel.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Liviu Dudau <liviu.dudau@arm.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Link: https://syzkaller.appspot.com/bug?id=0ba17d70d062b2595e1f061231474800f076c7cb
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: syzbot+0871b14ca2e2fb64f6e3@syzkaller.appspotmail.com
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: "James (Qian) Wang" <james.qian.wang@arm.com>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Mihail Atanassov <mihail.atanassov@arm.com>
Cc: Brian Starkey <brian.starkey@arm.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Jyri Sarha <jsarha@ti.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Sean Paul <seanpaul@chromium.org>
Cc: Brian Masney <masneyb@onstation.org>
Cc: Emil Velikov <emil.velikov@collabora.com>
Cc: zhengbin <zhengbin13@huawei.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-tegra@vger.kernel.org
Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200612160056.2082681-1-daniel.vetter@ffwll.ch
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
drivers/gpu/drm/arm/malidp_drv.c
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c
drivers/gpu/drm/drm_atomic_state_helper.c
drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c
drivers/gpu/drm/omapdrm/omap_crtc.c
drivers/gpu/drm/omapdrm/omap_drv.c
drivers/gpu/drm/rcar-du/rcar_du_crtc.c
drivers/gpu/drm/tegra/dc.c
drivers/gpu/drm/tidss/tidss_crtc.c
drivers/gpu/drm/tidss/tidss_kms.c

index 56bd938961eeea29a1895616a4a3f3da716aad5d..f33418d6e1a0820f9050531a5f38d28e408c4c63 100644 (file)
@@ -492,10 +492,8 @@ static void komeda_crtc_reset(struct drm_crtc *crtc)
        crtc->state = NULL;
 
        state = kzalloc(sizeof(*state), GFP_KERNEL);
-       if (state) {
-               crtc->state = &state->base;
-               crtc->state->crtc = crtc;
-       }
+       if (state)
+               __drm_atomic_helper_crtc_reset(crtc, &state->base);
 }
 
 static struct drm_crtc_state *
@@ -616,7 +614,6 @@ static int komeda_crtc_add(struct komeda_kms_dev *kms,
                return err;
 
        drm_crtc_helper_add(crtc, &komeda_crtc_helper_funcs);
-       drm_crtc_vblank_reset(crtc);
 
        crtc->port = kcrtc->master->of_output_port;
 
index def8c9ffafcaf5ad4f95438af5178ba0b96e712c..a2a10bfbccac4ce2082ce9d2cb0437ef73fb68a2 100644 (file)
@@ -870,7 +870,6 @@ static int malidp_bind(struct device *dev)
        drm->irq_enabled = true;
 
        ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
-       drm_crtc_vblank_reset(&malidp->crtc);
        if (ret < 0) {
                DRM_ERROR("failed to initialise vblank\n");
                goto vblank_fail;
index 10985134ce0badd32b75ac2f5a6a41b08a3a9406..ce246b96330b772ab7f7388b0ee1ce66737f8d49 100644 (file)
@@ -411,10 +411,8 @@ static void atmel_hlcdc_crtc_reset(struct drm_crtc *crtc)
        }
 
        state = kzalloc(sizeof(*state), GFP_KERNEL);
-       if (state) {
-               crtc->state = &state->base;
-               crtc->state->crtc = crtc;
-       }
+       if (state)
+               __drm_atomic_helper_crtc_reset(crtc, &state->base);
 }
 
 static struct drm_crtc_state *
@@ -528,7 +526,6 @@ int atmel_hlcdc_crtc_create(struct drm_device *dev)
        }
 
        drm_crtc_helper_add(&crtc->base, &lcdc_crtc_helper_funcs);
-       drm_crtc_vblank_reset(&crtc->base);
 
        drm_mode_crtc_set_gamma_size(&crtc->base, ATMEL_HLCDC_CLUT_SIZE);
        drm_crtc_enable_color_mgmt(&crtc->base, 0, false,
index 8fce6a115dfe37e7e5c5e9f3cd4591664d0b8fd3..9ad74045158ece02ed775fa09e9ec113f5d454cb 100644 (file)
@@ -32,6 +32,7 @@
 #include <drm/drm_device.h>
 #include <drm/drm_plane.h>
 #include <drm/drm_print.h>
+#include <drm/drm_vblank.h>
 #include <drm/drm_writeback.h>
 
 #include <linux/slab.h>
@@ -93,6 +94,9 @@ __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
        if (crtc_state)
                __drm_atomic_helper_crtc_state_reset(crtc_state, crtc);
 
+       if (drm_dev_has_vblank(crtc->dev))
+               drm_crtc_vblank_reset(crtc);
+
        crtc->state = crtc_state;
 }
 EXPORT_SYMBOL(__drm_atomic_helper_crtc_reset);
index b5fed67c4651f4d9953ae3eb3149816e5a5b360e..0c54b7bc190106fb037e40c2f7ae30120e7e2d30 100644 (file)
@@ -1117,8 +1117,6 @@ static void mdp5_crtc_reset(struct drm_crtc *crtc)
                mdp5_crtc_destroy_state(crtc, crtc->state);
 
        __drm_atomic_helper_crtc_reset(crtc, &mdp5_cstate->base);
-
-       drm_crtc_vblank_reset(crtc);
 }
 
 static const struct drm_crtc_funcs mdp5_crtc_funcs = {
index fce7e944a280b0d110efc7fdc2e5182d31b96eb3..6d40914675dade9dddfee9f634907cc79e84fb41 100644 (file)
@@ -697,14 +697,16 @@ static int omap_crtc_atomic_get_property(struct drm_crtc *crtc,
 
 static void omap_crtc_reset(struct drm_crtc *crtc)
 {
+       struct omap_crtc_state *state;
+
        if (crtc->state)
                __drm_atomic_helper_crtc_destroy_state(crtc->state);
 
        kfree(crtc->state);
-       crtc->state = kzalloc(sizeof(struct omap_crtc_state), GFP_KERNEL);
 
-       if (crtc->state)
-               crtc->state->crtc = crtc;
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
+       if (state)
+               __drm_atomic_helper_crtc_reset(crtc, &state->base);
 }
 
 static struct drm_crtc_state *
index cdafd7ef1c3206eb7e22e3df3102450471c5728b..cc4d754ff8c027acfc2efba9ce2f26575bc39338 100644 (file)
@@ -595,7 +595,6 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 {
        const struct soc_device_attribute *soc;
        struct drm_device *ddev;
-       unsigned int i;
        int ret;
 
        DBG("%s", dev_name(dev));
@@ -642,9 +641,6 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
                goto err_cleanup_modeset;
        }
 
-       for (i = 0; i < priv->num_pipes; i++)
-               drm_crtc_vblank_off(priv->pipes[i].crtc);
-
        omap_fbdev_init(ddev);
 
        drm_kms_helper_poll_init(ddev);
index d73e88ddecd0f676f3ddbfee142cd5800d0df2e1..fe86a3e67757124bd39f9a15d2737ad284216bdf 100644 (file)
@@ -975,8 +975,7 @@ static void rcar_du_crtc_reset(struct drm_crtc *crtc)
        state->crc.source = VSP1_DU_CRC_NONE;
        state->crc.index = 0;
 
-       crtc->state = &state->state;
-       crtc->state->crtc = crtc;
+       __drm_atomic_helper_crtc_reset(crtc, &state->state);
 }
 
 static int rcar_du_crtc_enable_vblank(struct drm_crtc *crtc)
@@ -1271,9 +1270,6 @@ int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int swindex,
 
        drm_crtc_helper_add(crtc, &crtc_helper_funcs);
 
-       /* Start with vertical blanking interrupt reporting disabled. */
-       drm_crtc_vblank_off(crtc);
-
        /* Register the interrupt handler. */
        if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) {
                /* The IRQ's are associated with the CRTC (sw)index. */
index 04d6848d19fcf98251f024fab4dfbe53a50570ba..da8b9983b7de08c76b27608cf28a8868646bb417 100644 (file)
@@ -1169,7 +1169,6 @@ static void tegra_crtc_reset(struct drm_crtc *crtc)
                tegra_crtc_atomic_destroy_state(crtc, crtc->state);
 
        __drm_atomic_helper_crtc_reset(crtc, &state->base);
-       drm_crtc_vblank_reset(crtc);
 }
 
 static struct drm_crtc_state *
index 89a226912de85f425404ec90d713e839fbd575e5..4d01c4af61cd058f7eab10b5f9b976396b5eba95 100644 (file)
@@ -352,8 +352,7 @@ static void tidss_crtc_reset(struct drm_crtc *crtc)
                return;
        }
 
-       crtc->state = &tcrtc->base;
-       crtc->state->crtc = crtc;
+       __drm_atomic_helper_crtc_reset(crtc, &tcrtc->base);
 }
 
 static struct drm_crtc_state *tidss_crtc_duplicate_state(struct drm_crtc *crtc)
index c0240f7e0b1980a9314d5a672d59567c06518cb8..eec359f61a06db06c5f36068786cebcdbbc22294 100644 (file)
@@ -253,7 +253,6 @@ static int tidss_dispc_modeset_init(struct tidss_device *tidss)
 int tidss_modeset_init(struct tidss_device *tidss)
 {
        struct drm_device *ddev = &tidss->ddev;
-       unsigned int i;
        int ret;
 
        dev_dbg(tidss->dev, "%s\n", __func__);
@@ -278,10 +277,6 @@ int tidss_modeset_init(struct tidss_device *tidss)
        if (ret)
                return ret;
 
-       /* Start with vertical blanking interrupt reporting disabled. */
-       for (i = 0; i < tidss->num_crtcs; ++i)
-               drm_crtc_vblank_reset(tidss->crtcs[i]);
-
        drm_mode_config_reset(ddev);
 
        dev_dbg(tidss->dev, "%s done\n", __func__);