diff mbox series

[v2] drm/mediatek: Add spinlock for setting vblank event in atomic_begin

Message ID 20230920090658.31181-1-jason-jh.lin@mediatek.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm/mediatek: Add spinlock for setting vblank event in atomic_begin | expand

Commit Message

Jason-JH.Lin Sept. 20, 2023, 9:06 a.m. UTC
Add spinlock protection to avoid race condition on vblank event
between mtk_drm_crtc_atomic_begin() and mtk_drm_finish_page_flip().

Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
Suggested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
Reviewed-by: Fei Shao <fshao@chromium.org>
Tested-by: Fei Shao <fshao@chromium.org>
---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

AngeloGioacchino Del Regno Sept. 20, 2023, 9:15 a.m. UTC | #1
Il 20/09/23 11:06, Jason-JH.Lin ha scritto:
> Add spinlock protection to avoid race condition on vblank event
> between mtk_drm_crtc_atomic_begin() and mtk_drm_finish_page_flip().
> 
> Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
> Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> Suggested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
> Reviewed-by: Fei Shao <fshao@chromium.org>
> Tested-by: Fei Shao <fshao@chromium.org>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

Cheers!
CK Hu (胡俊光) Nov. 8, 2023, 7:27 a.m. UTC | #2
Hi, Jason:

On Wed, 2023-09-20 at 17:06 +0800, Jason-JH.Lin wrote:
> Add spinlock protection to avoid race condition on vblank event
> between mtk_drm_crtc_atomic_begin() and mtk_drm_finish_page_flip().

Reviewed-by: CK Hu <ck.hu@mediatek.com>

> 
> Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC
> MT8173.")
> Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> Suggested-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>
> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
> Reviewed-by: Fei Shao <fshao@chromium.org>
> Tested-by: Fei Shao <fshao@chromium.org>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index b6fa4ad2f94d..cab4fe092f13 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -744,6 +744,7 @@ static void mtk_drm_crtc_atomic_begin(struct
> drm_crtc *crtc,
>  									
>   crtc);
>  	struct mtk_crtc_state *mtk_crtc_state =
> to_mtk_crtc_state(crtc_state);
>  	struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
> +	unsigned long flags;
>  
>  	if (mtk_crtc->event && mtk_crtc_state->base.event)
>  		DRM_ERROR("new event while there is still a pending
> event\n");
> @@ -751,7 +752,11 @@ static void mtk_drm_crtc_atomic_begin(struct
> drm_crtc *crtc,
>  	if (mtk_crtc_state->base.event) {
>  		mtk_crtc_state->base.event->pipe =
> drm_crtc_index(crtc);
>  		WARN_ON(drm_crtc_vblank_get(crtc) != 0);
> +
> +		spin_lock_irqsave(&crtc->dev->event_lock, flags);
>  		mtk_crtc->event = mtk_crtc_state->base.event;
> +		spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
> +
>  		mtk_crtc_state->base.event = NULL;
>  	}
>  }
Chen-Yu Tsai Nov. 24, 2023, 4:40 a.m. UTC | #3
On Wed, Nov 8, 2023 at 3:27 PM CK Hu (胡俊光) <ck.hu@mediatek.com> wrote:
>
> Hi, Jason:
>
> On Wed, 2023-09-20 at 17:06 +0800, Jason-JH.Lin wrote:
> > Add spinlock protection to avoid race condition on vblank event
> > between mtk_drm_crtc_atomic_begin() and mtk_drm_finish_page_flip().
>
> Reviewed-by: CK Hu <ck.hu@mediatek.com>

Please also merge this for fixes so it lands sooner.

> >
> > Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC
> > MT8173.")
> > Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> > Suggested-by: AngeloGioacchino Del Regno <
> > angelogioacchino.delregno@collabora.com>
> > Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
> > Reviewed-by: Fei Shao <fshao@chromium.org>
> > Tested-by: Fei Shao <fshao@chromium.org>
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > index b6fa4ad2f94d..cab4fe092f13 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > @@ -744,6 +744,7 @@ static void mtk_drm_crtc_atomic_begin(struct
> > drm_crtc *crtc,
> >
> >   crtc);
> >       struct mtk_crtc_state *mtk_crtc_state =
> > to_mtk_crtc_state(crtc_state);
> >       struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
> > +     unsigned long flags;
> >
> >       if (mtk_crtc->event && mtk_crtc_state->base.event)
> >               DRM_ERROR("new event while there is still a pending
> > event\n");
> > @@ -751,7 +752,11 @@ static void mtk_drm_crtc_atomic_begin(struct
> > drm_crtc *crtc,
> >       if (mtk_crtc_state->base.event) {
> >               mtk_crtc_state->base.event->pipe =
> > drm_crtc_index(crtc);
> >               WARN_ON(drm_crtc_vblank_get(crtc) != 0);
> > +
> > +             spin_lock_irqsave(&crtc->dev->event_lock, flags);
> >               mtk_crtc->event = mtk_crtc_state->base.event;
> > +             spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
> > +
> >               mtk_crtc_state->base.event = NULL;
> >       }
> >  }
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index b6fa4ad2f94d..cab4fe092f13 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -744,6 +744,7 @@  static void mtk_drm_crtc_atomic_begin(struct drm_crtc *crtc,
 									  crtc);
 	struct mtk_crtc_state *mtk_crtc_state = to_mtk_crtc_state(crtc_state);
 	struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
+	unsigned long flags;
 
 	if (mtk_crtc->event && mtk_crtc_state->base.event)
 		DRM_ERROR("new event while there is still a pending event\n");
@@ -751,7 +752,11 @@  static void mtk_drm_crtc_atomic_begin(struct drm_crtc *crtc,
 	if (mtk_crtc_state->base.event) {
 		mtk_crtc_state->base.event->pipe = drm_crtc_index(crtc);
 		WARN_ON(drm_crtc_vblank_get(crtc) != 0);
+
+		spin_lock_irqsave(&crtc->dev->event_lock, flags);
 		mtk_crtc->event = mtk_crtc_state->base.event;
+		spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+
 		mtk_crtc_state->base.event = NULL;
 	}
 }