From: Shuicheng Lin <shuicheng.lin@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: stuart.summers@intel.com, Shuicheng Lin <shuicheng.lin@intel.com>,
Lucas De Marchi <lucas.demarchi@intel.com>,
Matthew Brost <matthew.brost@intel.com>
Subject: [PATCH v3] drm/xe/guc: Fix resource leak in xe_guc_ct_init_noalloc()
Date: Mon, 10 Nov 2025 18:45:23 +0000 [thread overview]
Message-ID: <20251110184522.1581001-2-shuicheng.lin@intel.com> (raw)
In-Reply-To: <20251104221613.795865-2-shuicheng.lin@intel.com>
xe_guc_ct_init_noalloc() allocates the CT workqueue and other helpers
before it tries to initialize ct->lock. If drmm_mutex_init() fails
we currently bail out without releasing those resources because the
guc_ct_fini() hasn’t been registered yet.
Since destroy_workqueue() in guc_ct_fini() may flush the workqueue, which
in turn can take the ct lock, the initialization sequence is restructured
to first initialize the ct->lock, then set up all CT state, and finally
register guc_ct_fini().
v2: guc_ct_fini() does take ct lock. (Matt)
v3: move primelockdep() together with drmm_mutex_init(). (Lucas)
Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
---
drivers/gpu/drm/xe/xe_guc_ct.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_guc_ct.c b/drivers/gpu/drm/xe/xe_guc_ct.c
index 671d69958ce7..c29807ace363 100644
--- a/drivers/gpu/drm/xe/xe_guc_ct.c
+++ b/drivers/gpu/drm/xe/xe_guc_ct.c
@@ -225,6 +225,12 @@ int xe_guc_ct_init_noalloc(struct xe_guc_ct *ct)
xe_gt_assert(gt, !(guc_ct_size() % PAGE_SIZE));
+ err = drmm_mutex_init(&xe->drm, &ct->lock);
+ if (err)
+ return err;
+
+ primelockdep(ct);
+
ct->g2h_wq = alloc_ordered_workqueue("xe-g2h-wq", WQ_MEM_RECLAIM);
if (!ct->g2h_wq)
return -ENOMEM;
@@ -240,12 +246,6 @@ int xe_guc_ct_init_noalloc(struct xe_guc_ct *ct)
init_waitqueue_head(&ct->wq);
init_waitqueue_head(&ct->g2h_fence_wq);
- err = drmm_mutex_init(&xe->drm, &ct->lock);
- if (err)
- return err;
-
- primelockdep(ct);
-
err = drmm_add_action_or_reset(&xe->drm, guc_ct_fini, ct);
if (err)
return err;
--
2.49.0
next prev parent reply other threads:[~2025-11-10 18:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 22:16 [PATCH] drm/xe/guc: Register CT fini action before mutex init Shuicheng Lin
2025-11-04 22:29 ` Matthew Brost
2025-11-05 20:14 ` Lucas De Marchi
2025-11-04 23:37 ` [PATCH v2] drm/xe/guc: Fix resource leak in xe_guc_ct_init_noalloc() Shuicheng Lin
2025-11-05 5:02 ` ✓ CI.KUnit: success for drm/xe/guc: Register CT fini action before mutex init (rev2) Patchwork
2025-11-05 6:24 ` ✓ Xe.CI.BAT: " Patchwork
2025-11-05 12:12 ` ✓ Xe.CI.Full: " Patchwork
2025-11-10 18:45 ` Shuicheng Lin [this message]
2025-11-10 19:45 ` [PATCH v3] drm/xe/guc: Fix resource leak in xe_guc_ct_init_noalloc() Lucas De Marchi
2025-11-20 17:03 ` Lin, Shuicheng
2025-11-21 16:47 ` Lucas De Marchi
2025-11-10 19:01 ` ✓ CI.KUnit: success for drm/xe/guc: Register CT fini action before mutex init (rev3) Patchwork
2025-11-10 19:56 ` ✓ Xe.CI.BAT: " Patchwork
2025-11-11 1:29 ` ✗ Xe.CI.Full: 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=20251110184522.1581001-2-shuicheng.lin@intel.com \
--to=shuicheng.lin@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=lucas.demarchi@intel.com \
--cc=matthew.brost@intel.com \
--cc=stuart.summers@intel.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