lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 18 Sep 2023 18:47:28 +0800
From:   Fei Shao <fshao@...omium.org>
To:     AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>
Cc:     "Jason-JH.Lin" <jason-jh.lin@...iatek.com>,
        Chun-Kuang Hu <chunkuang.hu@...nel.org>,
        Alexandre Mergnat <amergnat@...libre.com>,
        Eugen Hristev <eugen.hristev@...labora.com>,
        Jason-ch Chen <jason-ch.chen@...iatek.com>,
        Johnson Wang <johnson.wang@...iatek.com>,
        Singo Chang <singo.chang@...iatek.com>,
        Nancy Lin <nancy.lin@...iatek.com>,
        Shawn Sung <shawn.sung@...iatek.com>,
        dri-devel@...ts.freedesktop.org,
        linux-mediatek@...ts.infradead.org,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        Project_Global_Chrome_Upstream_Group@...iatek.com
Subject: Re: [PATCH] drm/mediatek: Add spinlock for setting vblank event in atomic_begin

Hi Angelo,

On Wed, Sep 13, 2023 at 4:35 PM AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com> wrote:
>
> Il 22/08/23 15:26, 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().
> >
>
> Hello Jason,
>
> Can you please provide more information about this race condition?
> (check below)
>
> > Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
> > Signed-off-by: Jason-JH.Lin <jason-jh.lin@...iatek.com>
> > ---
> >   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 d40142842f85..128a672fe3c9 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > @@ -746,6 +746,9 @@ 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;
> > +
> > +     spin_lock_irqsave(&crtc->dev->event_lock, flags);
> >
> >       if (mtk_crtc->event && mtk_crtc_state->base.event)
> >               DRM_ERROR("new event while there is still a pending event\n");
> > @@ -756,6 +759,8 @@ static void mtk_drm_crtc_atomic_begin(struct drm_crtc *crtc,
>
> ...because my suspect is that what creates the race condition in this function is
> the unlocked *assignment* to mtk_crtc->event, not the rest.
>
> If I'm right, you don't need to unconditionally spinlock at the beginning of this
> function hence ever-so-slightly improving performance compared to this version.
>
> Can you please try this one and check if this *also* solves the issue?
>
>         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_lock_irqrestore(&crtc->dev->event_lock, flags);
>
>                 mtk_crtc_state->base.event = NULL;
>         }
>
> P.S.: I'd try that myself, but I can't seem to reproduce the issue.

I'm still able to reproduce it so I gave it a try, and this approach
also seems to fix the issue.  :)
FWIW, the way I reproduce that is to toggle the night light mode on
and off repeatedly through the UI panel while playing YouTube videos
on my device.

Jason, can you post a new version with Angelo's suggestion?

Regards,
Fei

>
> Regards,
> Angelo
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ