From: sashiko-bot@kernel.org
To: "Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 4/8] drm/msm: release scanout framebuffers only after a vblank
Date: Sat, 12 Sep 2026 12:59:34 +0000 [thread overview]
Message-ID: <20260912125934.CC68D1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260912-fd-kms-fix-smmu-v3-4-a7ddc6fe2032@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Concurrent execution of msm_crtc_queue_fb_unpin() and msm_crtc_vblank_off() causes a use-after-free of the unpin work item.
--
commit d546c6b2b93655071c146a3c50f9a3cb4baa8f1b
Author: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Subject: drm/msm: release scanout framebuffers only after a vblank
This commit modifies the framebuffer cleanup process to defer unpinning
until after a vblank by scheduling a drm_vblank_work item. It also
provides a mechanism to release these works directly if the CRTC is
switched off and no further vblanks will arrive.
> diff --git a/drivers/gpu/drm/msm/msm_kms.c b/drivers/gpu/drm/msm/msm_kms.c
> index f3e39c3907a93..4582ba040f6ff 100644
> --- a/drivers/gpu/drm/msm/msm_kms.c
> +++ b/drivers/gpu/drm/msm/msm_kms.c
[ ... ]
> @@ -165,6 +167,119 @@ void msm_crtc_disable_vblank(struct drm_crtc *crtc)
> vblank_ctrl_queue_work(priv, crtc, false);
> }
>
> +struct msm_fb_unpin_work {
> + struct drm_vblank_work base;
> + struct list_head node;
> + struct msm_kms_fb_unpin *pending;
> + struct drm_framebuffer *fb;
> +};
> +
> +static void msm_kms_fb_unpin_release(struct msm_fb_unpin_work *unpin)
> +{
> + msm_framebuffer_unpin(unpin->fb);
> + drm_framebuffer_put(unpin->fb);
> + kfree(unpin);
> +}
[ ... ]
> +void msm_crtc_vblank_off(struct drm_crtc *crtc)
> +{
[ ... ]
> + for (;;) {
> + spin_lock(&pending->lock);
> + unpin = list_first_entry_or_null(&pending->fbs, typeof(*unpin),
> + node);
> + if (unpin)
> + list_del_init(&unpin->node);
> + spin_unlock(&pending->lock);
> +
> + if (!unpin)
> + break;
> +
> + drm_vblank_work_cancel_sync(&unpin->base);
> + msm_kms_fb_unpin_release(unpin);
[Severity: High]
Is it possible for a concurrent msm_crtc_queue_fb_unpin() call to still be
holding the unpin pointer when this releases it?
If an atomic commit calls msm_crtc_queue_fb_unpin(), and a concurrent CRTC
disable commit concurrently calls msm_crtc_vblank_off() here, could the newly
added unpin object be popped and freed before it has been scheduled?
> + }
> +
> +out:
> + drm_crtc_vblank_off(crtc);
> +}
> +
> +bool msm_crtc_queue_fb_unpin(struct drm_crtc *crtc, struct drm_framebuffer *fb)
> +{
[ ... ]
> + drm_vblank_work_init(&unpin->base, crtc, msm_kms_fb_unpin_work);
> +
> + spin_lock(&pending->lock);
> + list_add_tail(&unpin->node, &pending->fbs);
> + spin_unlock(&pending->lock);
> +
> + if (drm_vblank_work_schedule(&unpin->base,
> + drm_crtc_vblank_count(crtc) + 1, true) != 1) {
[Severity: High]
Can this sequence trigger a use-after-free or double-free?
Since the unpin object is published to pending->fbs before calling
drm_vblank_work_schedule(), and the lock is dropped, a concurrent
msm_crtc_vblank_off() could potentially grab the object from the list and
free it.
If that happens, does this code then attempt to access the freed unpin->base,
and potentially double-free it with the kfree(unpin) below if scheduling
fails?
> + spin_lock(&pending->lock);
> + list_del_init(&unpin->node);
> + spin_unlock(&pending->lock);
> +
> + drm_framebuffer_put(fb);
> + kfree(unpin);
> +
> + return false;
> + }
> +
> + return true;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260912-fd-kms-fix-smmu-v3-0-a7ddc6fe2032@oss.qualcomm.com?part=4
next prev parent reply other threads:[~2026-09-12 12:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-12 12:48 [PATCH v3 0/8] drm/msm: fix SMMU fault dumps Dmitry Baryshkov
2026-09-12 12:48 ` [PATCH v3 1/8] drm/msm: serialise framebuffer pin state Dmitry Baryshkov
2026-09-12 12:48 ` [PATCH v3 2/8] drm/msm: fix framebuffer pin refcount leak on prepare failure Dmitry Baryshkov
2026-09-12 12:48 ` [PATCH v3 3/8] drm/msm: unwind msm_drm_kms_init() on failure Dmitry Baryshkov
2026-09-12 13:33 ` sashiko-bot
2026-09-12 12:48 ` [PATCH v3 4/8] drm/msm: release scanout framebuffers only after a vblank Dmitry Baryshkov
2026-09-12 12:59 ` sashiko-bot [this message]
2026-09-12 12:48 ` [PATCH v3 5/8] drm/msm/dpu: clear the DSPP pointer when no DSPP is assigned Dmitry Baryshkov
2026-09-12 13:02 ` sashiko-bot
2026-09-12 12:48 ` [PATCH v3 6/8] drm/msm/dpu: clear the DSC blocks left by a previous reservation Dmitry Baryshkov
2026-09-12 12:59 ` sashiko-bot
2026-09-12 12:48 ` [PATCH v3 7/8] drm/msm/dpu: only reassign resources when the encoder is reprogrammed Dmitry Baryshkov
2026-09-12 12:48 ` [PATCH v3 8/8] drm/ci: mark pixel-format tests as passing on SC7180 Dmitry Baryshkov
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=20260912125934.CC68D1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/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