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 v3 04/14] drm/msm: order the display snapshot sources around its worker
Date: Fri, 23 Oct 2026 23:41:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-183424@kernel.org> (raw)
In-Reply-To: <20261024-msm-kms-destroy-fixes-v3-4-66a30120a5ea@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/msm: unsynchronized fault handler clear in msm_drm_kms_uninit()
--

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

drm/msm: order the display snapshot sources around its worker

This commit reorders the registration and teardown of the display IOMMU fault
handler and the display snapshot worker in msm_drm_kms_init() and
msm_drm_kms_uninit() so that snapshot sources are started after KMS setup and
stopped before the snapshot worker is destroyed.

> diff --git a/drivers/gpu/drm/msm/msm_kms.c b/drivers/gpu/drm/msm/msm_kms.c
> index f3e39c3907a93..a94d2888a21e5 100644
> --- a/drivers/gpu/drm/msm/msm_kms.c
> +++ b/drivers/gpu/drm/msm/msm_kms.c

[ ... ]

> @@ -245,6 +241,8 @@ void msm_drm_kms_uninit(struct device *dev)
>  
>  	BUG_ON(!kms);
>  
> +	msm_mmu_set_fault_handler(to_msm_vm(kms->vm)->mmu, kms, NULL);
> +
>  	/* We must cancel and cleanup any pending vblank enable/disable
>  	 * work before msm_irq_uninstall() to avoid work re-enabling an
>  	 * irq after uninstall has disabled it.
> @@ -256,12 +254,12 @@ void msm_drm_kms_uninit(struct device *dev)
>  
>  	drm_kms_helper_poll_fini(ddev);
>  
> -	msm_disp_snapshot_destroy(ddev);
> -
>  	pm_runtime_get_sync(dev);
>  	msm_irq_uninstall(ddev);
>  	pm_runtime_put_sync(dev);
>  
> +	msm_disp_snapshot_destroy(ddev);

[Severity: High]
Can clearing the fault handler in msm_drm_kms_uninit() still race with an
in-flight display IOMMU fault and cause a NULL function pointer call or a
use-after-free on kms->dump_worker?

In drivers/gpu/drm/msm/msm_mmu.h, msm_mmu_set_fault_handler() performs plain
unlocked stores:

static inline void msm_mmu_set_fault_handler(struct msm_mmu *mmu, void *arg,
		int (*handler)(void *arg, unsigned long iova, int flags, void *data))
{
	mmu->arg = arg;
	mmu->handler = handler;
}

And in drivers/gpu/drm/msm/msm_iommu.c, msm_disp_fault_handler() checks and
calls iommu->base.handler without locking or READ_ONCE():

static int msm_disp_fault_handler(struct iommu_domain *domain, struct device *dev,
				  unsigned long iova, int flags, void *arg)
{
	struct msm_iommu *iommu = arg;

	if (iommu->base.handler)
		return iommu->base.handler(iommu->base.arg, iova, flags, NULL);

	return -ENOSYS;
}

First, without READ_ONCE() / WRITE_ONCE() or a lock, can the compiler reload
iommu->base.handler after the NULL check in msm_disp_fault_handler() while
msm_drm_kms_uninit() clears it, calling NULL?

Second, if a display SMMU context fault (for example, via the threaded IRQ
handler qcom_smmu_context_fault() -> report_iommu_fault() ->
msm_disp_fault_handler() -> msm_kms_fault_handler()) is already running when
msm_drm_kms_uninit() sets mmu->handler to NULL, nothing between
msm_mmu_set_fault_handler() and msm_disp_snapshot_destroy() waits for that
in-flight fault handler to complete (msm_irq_uninstall() only frees kms->irq,
while the SMMU domain and its fault IRQ are only torn down later in
kms->funcs->destroy(kms)).

If msm_kms_fault_handler() is preempted or running on another CPU, couldn't it
call msm_disp_snapshot_state() -> kthread_queue_work(kms->dump_worker,
&kms->dump_work) concurrently with or after msm_disp_snapshot_destroy() calls
kthread_destroy_worker(kms->dump_worker)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261024-msm-kms-destroy-fixes-v3-0-66a30120a5ea@oss.qualcomm.com?part=4

  reply	other threads:[~2026-10-23 23:41 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 23:19 [PATCH v3 00/14] drm/msm: fix the error handling of the KMS init Dmitry Baryshkov
2026-10-23 23:19 ` [PATCH v3 01/14] drm/msm: fail the snapshot init when its worker cannot be created Dmitry Baryshkov
2026-10-26  9:21   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 02/14] drm/msm/mdp5: forget the hardware blocks of a previous bind Dmitry Baryshkov
2026-10-26  9:22   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 03/14] drm/msm: unwind msm_drm_kms_init() on failure Dmitry Baryshkov
2026-10-26  9:26   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 04/14] drm/msm: order the display snapshot sources around its worker Dmitry Baryshkov
2026-10-23 23:41   ` sashiko-bot [this message]
2026-10-23 23:19 ` [PATCH v3 05/14] drm/msm: clean up after a failed msm_kms_init() Dmitry Baryshkov
2026-10-26  9:30   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 06/14] drm/msm: let the kms drivers clean up a failed kms_init() Dmitry Baryshkov
2026-10-26  9:33   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 07/14] drm/msm/mdp5: unwind a failed mdp5_kms_init() Dmitry Baryshkov
2026-10-26  9:39   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 08/14] drm/msm/mdp4: unwind a failed mdp4_kms_init() Dmitry Baryshkov
2026-10-26  9:40   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 09/14] drm/msm/dpu: don't tear down a failed hw_init twice Dmitry Baryshkov
2026-10-26  9:41   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 10/14] drm/msm: tear down only a successfully initialised KMS Dmitry Baryshkov
2026-10-26  9:42   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 11/14] drm/msm/dpu: clean up the self-refresh helpers on teardown Dmitry Baryshkov
2026-10-26  9:42   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 12/14] drm/msm/dpu: unwind a failed dpu_kms_hw_init() step by step Dmitry Baryshkov
2026-10-26  9:44   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 13/14] drm/msm/mdp4: disable the vdd regulator on teardown Dmitry Baryshkov
2026-10-26  9:44   ` Konrad Dybcio
2026-10-23 23:19 ` [PATCH v3 14/14] drm/msm: drop the runtime PM flags from the KMS teardown Dmitry Baryshkov
2026-10-26  9:45   ` Konrad Dybcio

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=sashiko-outbox-183424@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.