From: sashiko-bot@kernel.org
To: "Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 3/6] drm/msm: release scanout framebuffers only after a vblank
Date: Tue, 08 Sep 2026 15:42:25 +0000 [thread overview]
Message-ID: <20260908154252.A2FB01F00ADE@smtp.kernel.org> (raw)
In-Reply-To: <20260908-fd-kms-fix-smmu-v2-3-9391815742a8@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Fatal NULL pointer dereference in msm_kms_fini_fb_unpin() when handling initialization errors if msm_kms_init_fb_unpin() was not completed.
- [High] Deferred framebuffer unpin logic creates a TOCTOU race for shared framebuffers, leading to premature synchronous unpin and IOMMU faults.
--
commit ce24ef75bb4418725e7dde4f8dcb994be7c35638
Author: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
drm/msm: release scanout framebuffers only after a vblank
This commit defers the release of scanout framebuffers until after a vblank
has occurred by queuing the unpin work via a vblank worker. It prevents
hardware from fetching unmapped memory by ensuring the new configuration is
fully latched before detaching the VMA.
> diff --git a/drivers/gpu/drm/msm/msm_fb.c b/drivers/gpu/drm/msm/msm_fb.c
> index dfe040d5260bc..2e317bec9fbbb 100644
> --- a/drivers/gpu/drm/msm/msm_fb.c
> +++ b/drivers/gpu/drm/msm/msm_fb.c
[ ... ]
> @@ -144,6 +145,9 @@ void msm_framebuffer_cleanup(struct drm_framebuffer *fb, bool needed_dirtyfb)
>
> memset(msm_fb->iova, 0, sizeof(msm_fb->iova));
>
> + if (crtc && msm_crtc_queue_fb_unpin(crtc, fb))
> + goto out;
> +
> for (i = 0; i < n; i++) {
> msm_gem_unpin_iova(fb->obj[i], vm);
> msm_gem_vma_put(fb->obj[i]);
[Severity: High]
Does this deferred unpin logic handle shared framebuffers safely?
If a framebuffer is shared across multiple CRTCs and an atomic commit removes
it from all of them simultaneously, msm_framebuffer_cleanup() is called
sequentially for each plane. The last plane processed drops prepare_count to
zero and funnels the unpin to a single CRTC.
If that final CRTC happens to be disabled (where crtc->state->active is false
in msm_crtc_queue_fb_unpin()), it returns false, causing an immediate
synchronous unpin here. This could fault any other active CRTCs that haven't
reached their vblank and are still actively scanning out the old frame.
Even if active, could the last processed CRTC reach its vblank and unpin the
buffer before slower CRTCs finish their frames?
[ ... ]
> diff --git a/drivers/gpu/drm/msm/msm_kms.c b/drivers/gpu/drm/msm/msm_kms.c
> index e5d0ea6294484..6a857ad3464c4 100644
> --- a/drivers/gpu/drm/msm/msm_kms.c
> +++ b/drivers/gpu/drm/msm/msm_kms.c
[ ... ]
> +void msm_kms_fini_fb_unpin(struct drm_device *dev)
> +{
> + struct msm_drm_private *priv = dev->dev_private;
> + struct msm_kms *kms = priv->kms;
> + struct drm_crtc *crtc;
> +
> + drm_for_each_crtc(crtc, dev) {
> + unsigned int idx = drm_crtc_index(crtc);
> +
> + if (idx >= ARRAY_SIZE(kms->fb_unpin))
> + continue;
> +
> + drm_vblank_work_cancel_sync(&kms->fb_unpin[idx].vblank_work);
[Severity: High]
Can this cause a NULL pointer dereference on initialization error paths?
If msm_drm_kms_init() fails after CRTCs are created but before
msm_kms_init_fb_unpin() succeeds (for example, if drm_vblank_init() fails),
the error path calls msm_drm_kms_uninit(), which unconditionally calls
msm_kms_fini_fb_unpin().
Because the vblank_work structs were zero-allocated and never initialized,
drm_vblank_work_cancel_sync() will dereference a NULL work->vblank:
drivers/gpu/drm/drm_vblank_work.c:drm_vblank_work_cancel_sync() {
struct drm_vblank_crtc *vblank = work->vblank;
struct drm_device *dev = vblank->dev;
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260908-fd-kms-fix-smmu-v2-0-9391815742a8@oss.qualcomm.com?part=3
next prev parent reply other threads:[~2026-09-08 15:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 15:24 [PATCH v2 0/6] drm/msm: fix SMMU fault dumps Dmitry Baryshkov
2026-09-08 15:24 ` [PATCH v2 1/6] drm/msm: serialise framebuffer pin state Dmitry Baryshkov
2026-09-08 15:38 ` sashiko-bot
2026-09-08 15:24 ` [PATCH v2 2/6] drm/msm: fix framebuffer pin refcount leak on prepare failure Dmitry Baryshkov
2026-09-08 15:24 ` [PATCH v2 3/6] drm/msm: release scanout framebuffers only after a vblank Dmitry Baryshkov
2026-09-08 15:42 ` sashiko-bot [this message]
2026-09-08 15:24 ` [PATCH v2 4/6] drm/msm/dpu: clear the DSPP pointer when no DSPP is assigned Dmitry Baryshkov
2026-09-08 15:42 ` sashiko-bot
2026-09-08 15:24 ` [PATCH v2 5/6] drm/msm/dpu: only reassign resources when the encoder is reprogrammed Dmitry Baryshkov
2026-09-08 15:24 ` [PATCH v2 6/6] 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=20260908154252.A2FB01F00ADE@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;
as well as URLs for NNTP newsgroup(s).