All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 04/11] drm/msm: let the kms drivers clean up a failed kms_init()
Date: Sat, 03 Oct 2026 01:34:30 +0000	[thread overview]
Message-ID: <20261003013430.936601F00893@smtp.kernel.org> (raw)
In-Reply-To: <20261003-msm-kms-destroy-fixes-v1-4-e062b7dae77f@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/msm: NULL pointer dereference in snapshot worker due to inverted teardown order
--

commit 5b99326f79a79593a3cb18892305a7e107cff364
Author: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>

drm/msm: let the kms drivers clean up a failed kms_init()

A failed priv->kms_init() or ->hw_init() is cleaned up by the ->destroy()
callback, which makes ->destroy() responsible for tearing down a KMS in
any state between "not initialised at all" and "fully initialised". The
kernel convention is the opposite: a function which fails undoes its own
steps, and the teardown only ever sees a fully set up object.

> diff --git a/drivers/gpu/drm/msm/msm_kms.c b/drivers/gpu/drm/msm/msm_kms.c
> index f3e39c3907a93..f65774b04c6fa 100644
> --- a/drivers/gpu/drm/msm/msm_kms.c
> +++ b/drivers/gpu/drm/msm/msm_kms.c
[ ... ]
> @@ -344,9 +348,10 @@ int msm_drm_kms_init(struct device *dev, const struct drm_driver *drv)
>  err_destroy_event_threads:
>  	msm_drm_kms_destroy_event_threads(kms);
>  err_destroy_kms:
> -	msm_disp_snapshot_destroy(ddev);
>  	if (kms->funcs)
>  		kms->funcs->destroy(kms);
> +err_destroy_snapshot:
> +	msm_disp_snapshot_destroy(ddev);
>  
>  	return ret;
>  }

[Severity: High]
Does this inverted teardown order cause a NULL pointer dereference in the
snapshot worker?

If an error occurs after kms_init() succeeds in msm_drm_kms_init() (for
example, if drm_vblank_init() fails), the error path jumps to
err_destroy_event_threads. If a concurrent IOMMU fault or underrun triggers
msm_disp_snapshot_state() at this time, it queues the snapshot work.

With this patch, the teardown order is swapped so that
kms->funcs->destroy(kms) is called before msm_disp_snapshot_destroy(ddev).
The destroy() callback (such as dpu_kms_destroy() calling
_dpu_kms_hw_destroy()) tears down the hardware and sets pointers like
dpu_kms->catalog = NULL.

When msm_disp_snapshot_destroy() is subsequently called, it invokes
kthread_destroy_worker(), which flushes the worker and executes the pending
snapshot work. The snapshot work calls kms->funcs->snapshot(), which then
dereferences the nulled hardware state, resulting in a kernel oops in
dpu_kms_mdp_snapshot() when reading cat->ctl_count.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261003-msm-kms-destroy-fixes-v1-0-e062b7dae77f@oss.qualcomm.com?part=4

  reply	other threads:[~2026-10-03  1:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03  0:27 [PATCH 00/11] drm/msm: fix the error handling of the KMS init Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 01/11] drm/msm: fail the snapshot init when its worker cannot be created Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 02/11] drm/msm: unwind msm_drm_kms_init() on failure Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 03/11] drm/msm: clean up after a failed msm_kms_init() Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 04/11] drm/msm: let the kms drivers clean up a failed kms_init() Dmitry Baryshkov
2026-10-03  1:34   ` sashiko-bot [this message]
2026-10-03  0:27 ` [PATCH 05/11] drm/msm/mdp5: unwind a failed mdp5_kms_init() Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 06/11] drm/msm/mdp4: unwind a failed mdp4_kms_init() Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 07/11] drm/msm/dpu: don't tear down a failed hw_init twice Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 08/11] drm/msm: tear down only a successfully initialised KMS Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 09/11] drm/msm/dpu: unwind a failed dpu_kms_hw_init() step by step Dmitry Baryshkov
2026-10-03  1:34   ` sashiko-bot
2026-10-03  0:27 ` [PATCH 10/11] drm/msm/mdp4: disable the vdd regulator on teardown Dmitry Baryshkov
2026-10-03  0:27 ` [PATCH 11/11] drm/msm: drop the runtime PM flags from the KMS teardown 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=20261003013430.936601F00893@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.