Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
	Francois Dugast <francois.dugast@intel.com>
Subject: Re: [PATCH] drm/xe/hw_engine_group: Fix potential leak
Date: Fri, 27 Jun 2025 14:15:31 -0700	[thread overview]
Message-ID: <aF8J88KDr6nheMXG@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <20250627184143.1480-1-michal.wajdeczko@intel.com>

On Fri, Jun 27, 2025 at 08:41:43PM +0200, Michal Wajdeczko wrote:
> If we fail to allocate a workqueue we will leak kzalloc'ed group
> object since it was designed to be kfree'ed in the drmm cleanup
> action, but we didn't have a chance to register this action yet.
> 
> To avoid this leak allocate a group object using drmm_kzalloc()
> and start using predefined drmm action to release the workqueue.
> 
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> Cc: Francois Dugast <francois.dugast@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_hw_engine_group.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_hw_engine_group.c b/drivers/gpu/drm/xe/xe_hw_engine_group.c
> index 2d68c5b5262a..87a6dcb1b4b5 100644
> --- a/drivers/gpu/drm/xe/xe_hw_engine_group.c
> +++ b/drivers/gpu/drm/xe/xe_hw_engine_group.c
> @@ -12,15 +12,6 @@
>  #include "xe_hw_engine_group.h"
>  #include "xe_vm.h"
>  
> -static void
> -hw_engine_group_free(struct drm_device *drm, void *arg)
> -{
> -	struct xe_hw_engine_group *group = arg;
> -
> -	destroy_workqueue(group->resume_wq);
> -	kfree(group);
> -}
> -
>  static void
>  hw_engine_group_resume_lr_jobs_func(struct work_struct *w)
>  {
> @@ -53,7 +44,7 @@ hw_engine_group_alloc(struct xe_device *xe)
>  	struct xe_hw_engine_group *group;
>  	int err;
>  
> -	group = kzalloc(sizeof(*group), GFP_KERNEL);
> +	group = drmm_kzalloc(&xe->drm, sizeof(*group), GFP_KERNEL);
>  	if (!group)
>  		return ERR_PTR(-ENOMEM);
>  
> @@ -61,14 +52,14 @@ hw_engine_group_alloc(struct xe_device *xe)
>  	if (!group->resume_wq)
>  		return ERR_PTR(-ENOMEM);
>  
> +	err = drmm_add_action_or_reset(&xe->drm, __drmm_workqueue_release, group->resume_wq);

I was hoping something like this would get added. I suggested a similar
idea to the Xe maintainers a while back, but they didn’t like it. It
seems someone else has now added this at the DRM level. We can probably
update Xe in several places to use drmm_alloc_ordered_workqueue, but in
this case, resume_wq is not an ordered workqueue—although maybe it
should be.

Anyway, all of the above is follow-up work. This patch itself looks good
to me.

Reviewed-by: Matthew Brost <matthew.brost@intel.com>

> +	if (err)
> +		return ERR_PTR(err);
> +
>  	init_rwsem(&group->mode_sem);
>  	INIT_WORK(&group->resume_work, hw_engine_group_resume_lr_jobs_func);
>  	INIT_LIST_HEAD(&group->exec_queue_list);
>  
> -	err = drmm_add_action_or_reset(&xe->drm, hw_engine_group_free, group);
> -	if (err)
> -		return ERR_PTR(err);
> -
>  	return group;
>  }
>  
> -- 
> 2.47.1
> 

  reply	other threads:[~2025-06-27 21:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 18:41 [PATCH] drm/xe/hw_engine_group: Fix potential leak Michal Wajdeczko
2025-06-27 21:15 ` Matthew Brost [this message]
2025-06-30 18:51 ` ✓ CI.KUnit: success for " Patchwork
2025-06-30 19:32 ` ✓ Xe.CI.BAT: " Patchwork
2025-07-01 23:04 ` ✗ Xe.CI.Full: failure " Patchwork
2025-07-02 11:12   ` Michal Wajdeczko

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=aF8J88KDr6nheMXG@lstrano-desk.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=francois.dugast@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=michal.wajdeczko@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