mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "CK Hu (胡俊光)" <ck.hu@mediatek.com>
To: AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	"chunkuang.hu@kernel.org" <chunkuang.hu@kernel.org>
Cc: "Alexandre Mergnat" <amergnat@baylibre.com>,
	"simona@ffwll.ch" <simona@ffwll.ch>,
	"dmitry.osipenko@collabora.com" <dmitry.osipenko@collabora.com>,
	"kernel@collabora.com" <kernel@collabora.com>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"djkurtz@chromium.org" <djkurtz@chromium.org>,
	"granquet@baylibre.com" <granquet@baylibre.com>,
	"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"Bibby Hsieh (謝濟遠)" <Bibby.Hsieh@mediatek.com>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"littlecvr@chromium.org" <littlecvr@chromium.org>,
	"Rex-BC Chen (陳柏辰)" <Rex-BC.Chen@mediatek.com>
Subject: Re: [PATCH 3/3] drm/mediatek: mtk_disp_rdma: Enable/disable interrupt on bind/unbind
Date: Tue, 28 Oct 2025 09:49:25 +0000	[thread overview]
Message-ID: <fb2c7169b3c3e2e376ee0b092699735dc38bcbb6.camel@mediatek.com> (raw)
In-Reply-To: <20250924103708.19071-4-angelogioacchino.delregno@collabora.com>

On Wed, 2025-09-24 at 12:37 +0200, AngeloGioacchino Del Regno wrote:
> External email : Please do not click links or open attachments until you have verified the sender or the content.
> 
> 
> The RDMA driver is installing an ISR in the probe function but, if
> the component is not bound yet, the interrupt handler may call the
> vblank_cb ahead of time (while probing other drivers) or too late
> (while removing other drivers), possibly accessing memory that it
> should not try to access by reusing stale pointers.
> 
> In order to fix this, like done in the OVL driver, add a new `irq`
> member to struct mtk_disp_ovl and then set the NOAUTOEN flag to
> the irq before installing the ISR to manually disable and clear
> the hwirqs with register writes, and enable_irq() and disable_irq()
> in the bind and unbind callbacks respectively.
> 
> Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
> Link: https://lore.kernel.org/r/20250402083628.20111-6-angelogioacchino.delregno@collabora.com
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 34 ++++++++++++++----------
>  1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> index c9d41d75e7f2..9fd9bb1ee544 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_rdma.c
> @@ -81,6 +81,7 @@ struct mtk_disp_rdma_data {
>  struct mtk_disp_rdma {
>         struct clk                      *clk;
>         void __iomem                    *regs;
> +       int                             irq;
>         struct cmdq_client_reg          cmdq_reg;
>         const struct mtk_disp_rdma_data *data;
>         void                            (*vblank_cb)(void *data);
> @@ -295,13 +296,23 @@ void mtk_rdma_layer_config(struct device *dev, unsigned int idx,
>  static int mtk_disp_rdma_bind(struct device *dev, struct device *master,
>                               void *data)
>  {
> -       return 0;
> +       struct mtk_disp_rdma *priv = dev_get_drvdata(dev);
> +
> +       /* Disable and clear pending interrupts */
> +       writel(0x0, priv->regs + DISP_REG_RDMA_INT_ENABLE);
> +       writel(0x0, priv->regs + DISP_REG_RDMA_INT_STATUS);
> +
> +       enable_irq(priv->irq);
> 
> +       return 0;
>  }
> 
>  static void mtk_disp_rdma_unbind(struct device *dev, struct device *master,
>                                  void *data)
>  {
> +       struct mtk_disp_rdma *priv = dev_get_drvdata(dev);
> +
> +       disable_irq(priv->irq);
>  }
> 
>  static const struct component_ops mtk_disp_rdma_component_ops = {
> @@ -313,16 +324,15 @@ static int mtk_disp_rdma_probe(struct platform_device *pdev)
>  {
>         struct device *dev = &pdev->dev;
>         struct mtk_disp_rdma *priv;
> -       int irq;
>         int ret;
> 
>         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>         if (!priv)
>                 return -ENOMEM;
> 
> -       irq = platform_get_irq(pdev, 0);
> -       if (irq < 0)
> -               return irq;
> +       priv->irq = platform_get_irq(pdev, 0);
> +       if (priv->irq < 0)
> +               return priv->irq;
> 
>         priv->clk = devm_clk_get(dev, NULL);
>         if (IS_ERR(priv->clk))
> @@ -345,21 +355,17 @@ static int mtk_disp_rdma_probe(struct platform_device *pdev)
>         if (ret && (ret != -EINVAL))
>                 return dev_err_probe(dev, ret, "Failed to get rdma fifo size\n");
> 
> -       /* Disable and clear pending interrupts */
> -       writel(0x0, priv->regs + DISP_REG_RDMA_INT_ENABLE);
> -       writel(0x0, priv->regs + DISP_REG_RDMA_INT_STATUS);

Pending interrupt is cleared here, and interrupt is disabled here.
So the problem you mention would not happen.

Regards,
CK

> -
> -       ret = devm_request_irq(dev, irq, mtk_disp_rdma_irq_handler,
> -                              IRQF_TRIGGER_NONE, dev_name(dev), priv);
> -       if (ret < 0)
> -               return dev_err_probe(dev, ret, "Failed to request irq %d\n", irq);
> -
>         priv->data = of_device_get_match_data(dev);
> 
>         platform_set_drvdata(pdev, priv);
> 
>         pm_runtime_enable(dev);
> 
> +       ret = devm_request_irq(dev, priv->irq, mtk_disp_rdma_irq_handler,
> +                              IRQF_NO_AUTOEN, dev_name(dev), priv);
> +       if (ret < 0)
> +               return dev_err_probe(dev, ret, "Failed to request irq %d\n", priv->irq);
> +
>         ret = component_add(dev, &mtk_disp_rdma_component_ops);
>         if (ret) {
>                 pm_runtime_disable(dev);
> --
> 2.51.0
> 
> 


  reply	other threads:[~2025-10-28  9:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-24 10:37 [PATCH 0/3] drm/mediatek: Fixes: Stale pointer usage and device leak AngeloGioacchino Del Regno
2025-09-24 10:37 ` [PATCH 1/3] drm/mediatek: mtk_dp: Fix hdmi codec and phy driver unregistration AngeloGioacchino Del Regno
2025-09-25  1:09   ` Dmitry Baryshkov
2025-09-25 13:57     ` AngeloGioacchino Del Regno
2025-09-24 10:37 ` [PATCH 2/3] drm/mediatek: mtk_disp_ovl: Enable/disable interrupt on bind/unbind AngeloGioacchino Del Regno
2025-10-28  9:55   ` CK Hu (胡俊光)
2025-10-28 15:51     ` AngeloGioacchino Del Regno
2025-09-24 10:37 ` [PATCH 3/3] drm/mediatek: mtk_disp_rdma: " AngeloGioacchino Del Regno
2025-10-28  9:49   ` CK Hu (胡俊光) [this message]
2025-10-28 15:49     ` AngeloGioacchino Del Regno
2025-12-30 15:05       ` Chun-Kuang Hu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb2c7169b3c3e2e376ee0b092699735dc38bcbb6.camel@mediatek.com \
    --to=ck.hu@mediatek.com \
    --cc=Bibby.Hsieh@mediatek.com \
    --cc=Rex-BC.Chen@mediatek.com \
    --cc=airlied@gmail.com \
    --cc=amergnat@baylibre.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=djkurtz@chromium.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=granquet@baylibre.com \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=littlecvr@chromium.org \
    --cc=matthias.bgg@gmail.com \
    --cc=p.zabel@pengutronix.de \
    --cc=simona@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®