From: sashiko-bot@kernel.org
To: "Srinivasan Shanmugam" <srinivasan.shanmugam@amd.com>
Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org,
intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v3 1/2] drm: Add common drm_user_fence helper
Date: Thu, 27 Aug 2026 15:29:55 +0000 [thread overview]
Message-ID: <20260827152955.D2E6E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827151950.4080674-2-srinivasan.shanmugam@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Memory leak of `drm_user_fence`, `mm_struct`, and `dma_fence` when a pending work item is successfully cancelled.
--
commit 922879f241f70a69a977d292a4790f93e66ca3e2
Author: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
drm: Add common drm_user_fence helper
This commit introduces a common DRM user fence helper that provides a
kref-managed, MM-borrowing dma-fence-callback-to-workqueue pattern. This
allows drivers to access userspace memory from a kthread context when a
GPU fence signals.
> diff --git a/drivers/gpu/drm/drm_user_fence.c b/drivers/gpu/drm/drm_user_fence.c
> new file mode 100644
> index 0000000000000..5e6d4c1071306
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_user_fence.c
[ ... ]
> +void drm_user_fence_cancel_sync(struct drm_user_fence *ufence)
> +{
> + drm_user_fence_cancel(ufence);
> + cancel_work_sync(&ufence->work);
[Severity: High]
Can ignoring the return value of cancel_work_sync() cause a memory leak
of the drm_user_fence, mm_struct, and an extra dma_fence reference?
If a user arms a user fence and the hardware signals it, the signal
callback drm_user_fence_cb() queues the work item. If the user then tears
down the object before the work item executes, drm_user_fence_cancel_sync()
is called.
If cancel_work_sync() successfully dequeues the pending work, it returns
true, and drm_user_fence_work() will never run. This means the call to
drm_user_fence_put() at the end of drm_user_fence_work() is skipped:
static void drm_user_fence_work(struct work_struct *w)
{
...
drm_user_fence_put(ufence);
}
Leaking the mm_struct pins memory, and leaking the dma_fence can prevent GPU
resource cleanup.
Would it be safer to check the return value and drop the reference?
if (cancel_work_sync(&ufence->work))
drm_user_fence_put(ufence);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260827151950.4080674-1-srinivasan.shanmugam@amd.com?part=1
next prev parent reply other threads:[~2026-08-27 15:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 15:19 [PATCH v3 0/2] drm: Add Common drm_user_fence helper and Convert XE Srinivasan Shanmugam
2026-08-27 15:19 ` [PATCH v3 1/2] drm: Add common drm_user_fence helper Srinivasan Shanmugam
2026-08-27 15:29 ` sashiko-bot [this message]
2026-08-27 15:19 ` [PATCH v3 2/2] drm/xe: Convert xe_user_fence to drm_user_fence Srinivasan Shanmugam
2026-08-27 15:35 ` sashiko-bot
2026-08-27 15:50 ` ✗ CI.checkpatch: warning for drm: Add Common drm_user_fence helper and Convert XE (rev2) Patchwork
2026-08-27 15:50 ` ✗ CI.KUnit: failure " Patchwork
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=20260827152955.D2E6E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=media-ci@linuxtv.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=srinivasan.shanmugam@amd.com \
/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