All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <dev@lankhorst.se>
To: intel-xe@lists.freedesktop.org
Cc: Maarten Lankhorst <dev@lankhorst.se>
Subject: [PATCH 3/4] drm/xe: Fix small leak in migration error path.
Date: Fri,  2 May 2025 11:35:12 +0200	[thread overview]
Message-ID: <20250502093514.510621-4-dev@lankhorst.se> (raw)
In-Reply-To: <20250502093514.510621-1-dev@lankhorst.se>

When logical_mask or hwe are zero, we should call xe_vm_close_and_put,
and on error, m->pt_bo is also not cleared.

Also call xe_bo_unpin_map_no_vm even though it is a vm bo,
to ensure the BO is freed.

Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
 drivers/gpu/drm/xe/xe_migrate.c | 60 +++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index 673a5d165482e..7ee27c9f77bac 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -386,6 +386,38 @@ static bool xe_migrate_needs_ccs_emit(struct xe_device *xe)
 	return xe_device_has_flat_ccs(xe) && !(GRAPHICS_VER(xe) >= 20 && IS_DGFX(xe));
 }
 
+static struct xe_exec_queue *xe_migrate_create_queue(struct xe_tile *tile,
+						     struct xe_vm *vm)
+{
+	struct xe_device *xe = tile_to_xe(tile);
+	struct xe_gt *primary_gt = tile->primary_gt;
+
+	if (xe->info.has_usm) {
+		struct xe_hw_engine *hwe = xe_gt_hw_engine(primary_gt,
+							   XE_ENGINE_CLASS_COPY,
+							   primary_gt->usm.reserved_bcs_instance,
+							   false);
+		u32 logical_mask = xe_migrate_usm_logical_mask(primary_gt);
+
+		if (!hwe || !logical_mask)
+			return ERR_PTR(-EINVAL);
+
+		/*
+		 * XXX: Currently only reserving 1 (likely slow) BCS instance on
+		 * PVC, may want to revisit if performance is needed.
+		 */
+		return xe_exec_queue_create(xe, vm, logical_mask, 1, hwe,
+					    EXEC_QUEUE_FLAG_KERNEL |
+					    EXEC_QUEUE_FLAG_PERMANENT |
+					    EXEC_QUEUE_FLAG_HIGH_PRIORITY, 0);
+	} else {
+		return xe_exec_queue_create_class(xe, primary_gt, vm,
+						  XE_ENGINE_CLASS_COPY,
+						  EXEC_QUEUE_FLAG_KERNEL |
+						  EXEC_QUEUE_FLAG_PERMANENT, 0);
+	}
+}
+
 /**
  * xe_migrate_init() - Initialize a migrate context
  * @tile: Back-pointer to the tile we're initializing for.
@@ -395,7 +427,6 @@ static bool xe_migrate_needs_ccs_emit(struct xe_device *xe)
 struct xe_migrate *xe_migrate_init(struct xe_tile *tile)
 {
 	struct xe_device *xe = tile_to_xe(tile);
-	struct xe_gt *primary_gt = tile->primary_gt;
 	struct xe_migrate *m;
 	struct xe_vm *vm;
 	int err;
@@ -420,32 +451,11 @@ struct xe_migrate *xe_migrate_init(struct xe_tile *tile)
 		return ERR_PTR(err);
 	}
 
-	if (xe->info.has_usm) {
-		struct xe_hw_engine *hwe = xe_gt_hw_engine(primary_gt,
-							   XE_ENGINE_CLASS_COPY,
-							   primary_gt->usm.reserved_bcs_instance,
-							   false);
-		u32 logical_mask = xe_migrate_usm_logical_mask(primary_gt);
-
-		if (!hwe || !logical_mask)
-			return ERR_PTR(-EINVAL);
-
-		/*
-		 * XXX: Currently only reserving 1 (likely slow) BCS instance on
-		 * PVC, may want to revisit if performance is needed.
-		 */
-		m->q = xe_exec_queue_create(xe, vm, logical_mask, 1, hwe,
-					    EXEC_QUEUE_FLAG_KERNEL |
-					    EXEC_QUEUE_FLAG_PERMANENT |
-					    EXEC_QUEUE_FLAG_HIGH_PRIORITY, 0);
-	} else {
-		m->q = xe_exec_queue_create_class(xe, primary_gt, vm,
-						  XE_ENGINE_CLASS_COPY,
-						  EXEC_QUEUE_FLAG_KERNEL |
-						  EXEC_QUEUE_FLAG_PERMANENT, 0);
-	}
+	m->q = xe_migrate_create_queue(tile, vm);
 	if (IS_ERR(m->q)) {
+		xe_bo_unpin_map_no_vm(m->pt_bo);
 		xe_vm_close_and_put(vm);
+		drm_suballoc_manager_fini(&m->vm_update_sa);
 		return ERR_CAST(m->q);
 	}
 
-- 
2.45.2


  parent reply	other threads:[~2025-05-02  9:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02  9:35 [PATCH 0/4] drm/xe: Update migration tests Maarten Lankhorst
2025-05-02  9:35 ` [PATCH 1/4] drm/xe: Simplify migration kunit tests Maarten Lankhorst
2025-05-02 16:54   ` Matthew Brost
2025-05-02  9:35 ` [PATCH 2/4] drm/xe: Silence migrate debug message Maarten Lankhorst
2025-05-02 16:55   ` Matthew Brost
2025-05-02  9:35 ` Maarten Lankhorst [this message]
2025-05-02 16:59   ` [PATCH 3/4] drm/xe: Fix small leak in migration error path Matthew Brost
2025-05-02  9:35 ` [PATCH 4/4] drm/xe: Add migrate performance kunit test Maarten Lankhorst
2025-05-08  6:49   ` Matthew Brost
2025-05-02 11:02 ` ✓ CI.Patch_applied: success for drm/xe: Update migration tests Patchwork
2025-05-02 11:02 ` ✗ CI.checkpatch: warning " Patchwork
2025-05-02 11:03 ` ✓ CI.KUnit: success " Patchwork
2025-05-02 11:12 ` ✓ CI.Build: " Patchwork
2025-05-02 11:14 ` ✓ CI.Hooks: " Patchwork
2025-05-02 11:15 ` ✓ CI.checksparse: " Patchwork
2025-05-02 15:21 ` ✗ Xe.CI.Full: failure " Patchwork
2025-05-06  7:59 ` ✗ Xe.CI.BAT: " 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=20250502093514.510621-4-dev@lankhorst.se \
    --to=dev@lankhorst.se \
    --cc=intel-xe@lists.freedesktop.org \
    /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.