Skip to contentSkip to conversation

drm/xe: fix pvc unload issue

PATCH In review Chang, Bruce 3 participants 5 messages Mar 30, 2023 – Mar 31, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/xe: fix pvc unload issue

Currently, unload pvc driver will generate a null dereference and the call stack is as below.

[ 4850.618000] Call Trace:
[ 4850.620740]  <TASK>
[ 4850.623134]  ttm_bo_cleanup_memtype_use+0x3f/0x50 [ttm]
[ 4850.628661]  ttm_bo_release+0x154/0x2c0 [ttm]
[ 4850.633317]  ? drm_buddy_fini+0x62/0x80 [drm_buddy]
[ 4850.638487]  ? __kmem_cache_free+0x27d/0x2c0
[ 4850.643054]  ttm_bo_put+0x38/0x60 [ttm]
[ 4850.647190]  xe_gem_object_free+0x1f/0x30 [xe]
[ 4850.651945]  drm_gem_object_free+0x1e/0x30 [drm]
[ 4850.656904]  ggtt_fini_noalloc+0x9d/0xe0 [xe]
[ 4850.661574]  drm_managed_release+0xb5/0x150 [drm]
[ 4850.666617]  drm_dev_release+0x30/0x50 [drm]
[ 4850.671209]  devm_drm_dev_init_release+0x3c/0x60 [drm]

There are a couple issues, but the main one is due to TTM has only one TTM_PL_TT region, but since pvc has 2 tiles and tries to setup 1 TTM_PL_TT each tile. The second will overwrite the first one.

During unload time, the first tile will reset the TTM_PL_TT manger and when the second tile is trying to free Bo and it will generate the null reference since the TTM manage is already got reset to 0.

The fix is to share the TTM_PL_TT manager and use a count to only allow the last instance to release.

Cc Stuart Summers <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/xe/xe_device_types.h |  3 +++
 drivers/gpu/drm/xe/xe_gt.c           |  9 +++++++--
 drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c  | 25 +++++++++++++++----------
 3 files changed, 25 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_device_types.h +3 -0
index 88f863edc41c..ea771f120c0f 100644
@@ -195,6 +195,9 @@ struct xe_device {
 			/** @mapping: pointer to VRAM mappable space */
 			void *__iomem mapping;
 		} vram;
+		/** @gtt_mr: GTT TTM manager */
+		struct xe_ttm_gtt_mgr *gtt_mgr;
+		int instance;
 	} mem;
 
 	/** @usm: unified memory state */
drivers/gpu/drm/xe/xe_gt.c +7 -2
index fd7a5b43ba3e..e7ca141478ef 100644
@@ -77,8 +77,13 @@ int xe_gt_alloc(struct xe_device *xe, struct xe_gt *gt)
 		if (!gt->mem.vram_mgr)
 			return -ENOMEM;
 
-		gt->mem.gtt_mgr = drmm_kzalloc(drm, sizeof(*gt->mem.gtt_mgr),
-					       GFP_KERNEL);
+		if (!xe->mem.gtt_mgr) {
+			xe->mem.gtt_mgr =
+				drmm_kzalloc(drm, sizeof(*gt->mem.gtt_mgr),
+					     GFP_KERNEL);
+			xe->mem.instance = 0;
+		}
+		gt->mem.gtt_mgr = xe->mem.gtt_mgr;
 		if (!gt->mem.gtt_mgr)
 			return -ENOMEM;
 	} else {
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +15 -10
index 8075781070f2..05300c71928e 100644
@@ -94,6 +94,9 @@ static void ttm_gtt_mgr_fini(struct drm_device *drm, void *arg)
 	struct ttm_resource_manager *man = &mgr->manager;
 	int err;
 
+	if (--xe->mem.instance)
+		return;
+
 	ttm_resource_manager_set_used(man, false);
 
 	err = ttm_resource_manager_evict_all(&xe->ttm, man);
@@ -113,18 +116,20 @@ int xe_ttm_gtt_mgr_init(struct xe_gt *gt, struct xe_ttm_gtt_mgr *mgr,
 
 	XE_BUG_ON(xe_gt_is_media_type(gt));
 
-	mgr->gt = gt;
-	man->use_tt = true;
-	man->func = &xe_ttm_gtt_mgr_func;
-
-	ttm_resource_manager_init(man, &xe->ttm, gtt_size >> PAGE_SHIFT);
+	if (!xe->mem.instance) {
+		mgr->gt = gt;
+		man->use_tt = true;
+		man->func = &xe_ttm_gtt_mgr_func;
 
-	ttm_set_driver_manager(&xe->ttm, XE_PL_TT, &mgr->manager);
-	ttm_resource_manager_set_used(man, true);
+		ttm_resource_manager_init(man, &xe->ttm, gtt_size >> PAGE_SHIFT);
 
-	err = drmm_add_action_or_reset(&xe->drm, ttm_gtt_mgr_fini, mgr);
-	if (err)
-		return err;
+		ttm_set_driver_manager(&xe->ttm, XE_PL_TT, &mgr->manager);
+		ttm_resource_manager_set_used(man, true);
+		err = drmm_add_action_or_reset(&xe->drm, ttm_gtt_mgr_fini, mgr);
+		if (err)
+			return err;
+	}
+	xe->mem.instance ++;
 
 	return 0;
 }
Signature · 1 line
2.25.1
#1 lore raw

[Intel-xe] ✓ CI.Patch_applied: success for drm/xe: fix pvc unload issue

== Series Details ==

== Series Details ==

Series: drm/xe: fix pvc unload issue
URL : https://patchwork.freedesktop.org/series/115881/
State : success

== Summary ==

=== Applying kernel patches on branch 'drm-xe-next' with base: === commit 5de0375b04455c7c8e516f53715eedde50f5ae45

Author:     Maarten Lankhorst <[email protected]>
AuthorDate: Thu Mar 23 15:05:18 2023 +0100
Commit:     Maarten Lankhorst <[email protected]>
CommitDate: Wed Mar 29 11:24:42 2023 +0200

drm/xe: Display api changes update

=== git am output follows ===
Applying: drm/xe: fix pvc unload issue

#2 lore raw

[Intel-xe] ✗ CI.KUnit: failure for drm/xe: fix pvc unload issue

In reply to Chang, Bruce
== Series Details ==

== Series Details ==

Series: drm/xe: fix pvc unload issue
URL : https://patchwork.freedesktop.org/series/115881/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:In file included from /usr/include/stdlib.h:1013,

                 from ../arch/um/drivers/chan_user.c:6:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/os-Linux/helper.c:6:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/os-Linux/irq.c:8:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/os-Linux/skas/process.c:7:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/drivers/fd.c:7:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/os-Linux/execvp.c:24:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/x86/um/os-Linux/registers.c:8:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/os-Linux/main.c:8:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/os-Linux/file.c:8:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^

make[3]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/irq.o] Error 1 make[3]: *** Waiting for unfinished jobs....
make[4]: *** [../scripts/Makefile.build:252: arch/x86/um/os-Linux/registers.o] Error 1 make[3]: *** [../scripts/Makefile.build:494: arch/x86/um/os-Linux] Error 2 make[3]: *** Waiting for unfinished jobs....
make[3]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/execvp.o] Error 1 make[3]: *** [../scripts/Makefile.build:252: arch/um/drivers/chan_user.o] Error 1 make[3]: *** Waiting for unfinished jobs....
make[3]: *** [../scripts/Makefile.build:252: arch/um/drivers/fd.o] Error 1 In file included from /usr/include/stdlib.h:1013,

                 from ../arch/um/os-Linux/mem.c:8:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^
In file included from /usr/include/stdlib.h:1013,
                 from ../arch/um/os-Linux/process.c:8:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^

make[3]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/helper.o] Error 1 make[4]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/skas/process.o] Error 1 make[4]: *** Waiting for unfinished jobs....
make[3]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/main.o] Error 1 make[3]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/file.o] Error 1 make[3]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/mem.o] Error 1 make[3]: *** [../scripts/Makefile.build:252: arch/um/os-Linux/process.o] Error 1 make[3]: *** [../scripts/Makefile.build:494: arch/um/os-Linux/skas] Error 2
make[2]: *** [../scripts/Makefile.build:494: arch/um/os-Linux] Error 2
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [../scripts/Makefile.build:494: arch/x86/um] Error 2
make[2]: *** [../scripts/Makefile.build:494: arch/um/drivers] Error 2
In file included from /usr/include/stdlib.h:1013,
from arch/um/kernel/config.c:7:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function ‘atof’:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled

   26 | {
      | ^

make[3]: *** [../scripts/Makefile.build:252: arch/um/kernel/config.o] Error 1 make[3]: *** Waiting for unfinished jobs....
make[2]: *** [../scripts/Makefile.build:494: arch/um/kernel] Error 2 make[1]: *** [/kernel/Makefile:2025: .] Error 2
make: *** [Makefile:226: __sub-make] Error 2

[15:42:34] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[15:42:38] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make ARCH=um O=.kunit --jobs=48
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel
#3 lore raw
In reply to Chang, Bruce
Quoted 22 lines · Bruce

Currently, unload pvc driver will generate a null dereference and the call stack is as below.

[ 4850.618000] Call Trace:
[ 4850.620740]  <TASK>
[ 4850.623134]  ttm_bo_cleanup_memtype_use+0x3f/0x50 [ttm]
[ 4850.628661]  ttm_bo_release+0x154/0x2c0 [ttm]
[ 4850.633317]  ? drm_buddy_fini+0x62/0x80 [drm_buddy]
[ 4850.638487]  ? __kmem_cache_free+0x27d/0x2c0
[ 4850.643054]  ttm_bo_put+0x38/0x60 [ttm]
[ 4850.647190]  xe_gem_object_free+0x1f/0x30 [xe]
[ 4850.651945]  drm_gem_object_free+0x1e/0x30 [drm]
[ 4850.656904]  ggtt_fini_noalloc+0x9d/0xe0 [xe]
[ 4850.661574]  drm_managed_release+0xb5/0x150 [drm]
[ 4850.666617]  drm_dev_release+0x30/0x50 [drm]
[ 4850.671209]  devm_drm_dev_init_release+0x3c/0x60 [drm]

There are a couple issues, but the main one is due to TTM has only one TTM_PL_TT region, but since pvc has 2 tiles and tries to setup 1 TTM_PL_TT each tile. The second will overwrite the first one.

Quoted 6 lines

During unload time, the first tile will reset the TTM_PL_TT manger and when the second tile is trying to free Bo and it will generate the null reference since the TTM manage is already got reset to 0.

The fix is to share the TTM_PL_TT manager and use a count to only allow the last instance to release.

Would it make sense to rather move it out of GT init, and just have one instance in the xe_device? And with that to rather consider xe->mem.vram_size, instead of gt->mem.vram_size when considering the potential "GTT" size? I think PL_TT is just system memory that can be touched by the GPU device (likely has a gtt mapping), so not sure why that needs to be GT centric.

Quoted 92 lines
Cc Stuart Summers <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/xe/xe_device_types.h |  3 +++
 drivers/gpu/drm/xe/xe_gt.c           |  9 +++++++--
 drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c  | 25 +++++++++++++++----------
 3 files changed, 25 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_device_types.h +3 -0
index 88f863edc41c..ea771f120c0f 100644
@@ -195,6 +195,9 @@ struct xe_device {
                        /** @mapping: pointer to VRAM mappable space */
                        void *__iomem mapping;
                } vram;
+               /** @gtt_mr: GTT TTM manager */
+               struct xe_ttm_gtt_mgr *gtt_mgr;
+               int instance;
        } mem;
 
        /** @usm: unified memory state */
drivers/gpu/drm/xe/xe_gt.c +7 -2
index fd7a5b43ba3e..e7ca141478ef 100644
@@ -77,8 +77,13 @@ int xe_gt_alloc(struct xe_device *xe, struct xe_gt *gt)
                if (!gt->mem.vram_mgr)
                        return -ENOMEM;
 
-               gt->mem.gtt_mgr = drmm_kzalloc(drm, sizeof(*gt->mem.gtt_mgr),
-                                              GFP_KERNEL);
+               if (!xe->mem.gtt_mgr) {
+                       xe->mem.gtt_mgr =
+                               drmm_kzalloc(drm, sizeof(*gt->mem.gtt_mgr),
+                                            GFP_KERNEL);
+                       xe->mem.instance = 0;
+               }
+               gt->mem.gtt_mgr = xe->mem.gtt_mgr;
                if (!gt->mem.gtt_mgr)
                        return -ENOMEM;
        } else {
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +15 -11
index 8075781070f2..05300c71928e 100644
@@ -94,6 +94,9 @@ static void ttm_gtt_mgr_fini(struct drm_device *drm, void *arg)
        struct ttm_resource_manager *man = &mgr->manager;
        int err;
 
+       if (--xe->mem.instance)
+               return;
+
        ttm_resource_manager_set_used(man, false);
 
        err = ttm_resource_manager_evict_all(&xe->ttm, man);
@@ -113,18 +116,20 @@ int xe_ttm_gtt_mgr_init(struct xe_gt *gt, struct xe_ttm_gtt_mgr *mgr,
 
        XE_BUG_ON(xe_gt_is_media_type(gt));
 
-       mgr->gt = gt;
-       man->use_tt = true;
-       man->func = &xe_ttm_gtt_mgr_func;
-
-       ttm_resource_manager_init(man, &xe->ttm, gtt_size >> PAGE_SHIFT);
+       if (!xe->mem.instance) {
+               mgr->gt = gt;
+               man->use_tt = true;
+               man->func = &xe_ttm_gtt_mgr_func;
 
-       ttm_set_driver_manager(&xe->ttm, XE_PL_TT, &mgr->manager);
-       ttm_resource_manager_set_used(man, true);
+               ttm_resource_manager_init(man, &xe->ttm, gtt_size >> PAGE_SHIFT);
 
-       err = drmm_add_action_or_reset(&xe->drm, ttm_gtt_mgr_fini, mgr);
-       if (err)
-               return err;
+               ttm_set_driver_manager(&xe->ttm, XE_PL_TT, &mgr->manager);
+               ttm_resource_manager_set_used(man, true);
+               err = drmm_add_action_or_reset(&xe->drm, ttm_gtt_mgr_fini, mgr);
+               if (err)
+                       return err;
+       }
+       xe->mem.instance ++;
 
        return 0;
 }
--

2.25.1

#4 lore raw
Quoted 40 lines

-----Original Message-----
From: Matthew Auld <[email protected]>
Sent: Thursday, March 30, 2023 10:40 PM
To: Chang, Yu bruce <[email protected]>
Cc: [email protected]; Thomas Hellström <[email protected]>
Subject: Re: [Intel-xe] [PATCH] drm/xe: fix pvc unload issue

Quoted 21 lines · Bruce

Currently, unload pvc driver will generate a null dereference and the call stack is as below.

[ 4850.618000] Call Trace:
[ 4850.620740]  <TASK>
[ 4850.623134]  ttm_bo_cleanup_memtype_use+0x3f/0x50 [ttm] [
4850.628661]  ttm_bo_release+0x154/0x2c0 [ttm] [ 4850.633317]  ?
drm_buddy_fini+0x62/0x80 [drm_buddy] [ 4850.638487]  ?
__kmem_cache_free+0x27d/0x2c0 [ 4850.643054]  ttm_bo_put+0x38/0x60
[ttm] [ 4850.647190]  xe_gem_object_free+0x1f/0x30 [xe] [ 4850.651945]
drm_gem_object_free+0x1e/0x30 [drm] [ 4850.656904]
ggtt_fini_noalloc+0x9d/0xe0 [xe] [ 4850.661574]
drm_managed_release+0xb5/0x150 [drm] [ 4850.666617]
drm_dev_release+0x30/0x50 [drm] [ 4850.671209]
devm_drm_dev_init_release+0x3c/0x60 [drm]

There are a couple issues, but the main one is due to TTM has only one TTM_PL_TT region, but since pvc has 2 tiles and tries to setup 1 TTM_PL_TT each tile. The second will overwrite the first one.

Quoted 6 lines

During unload time, the first tile will reset the TTM_PL_TT manger and when the second tile is trying to free Bo and it will generate the null reference since the TTM manage is already got reset to 0.

The fix is to share the TTM_PL_TT manager and use a count to only allow the last instance to release.

Quoted 7 lines

Would it make sense to rather move it out of GT init, and just have one instance in the xe_device? And with that to rather consider xe->mem.vram_size, instead of gt->mem.vram_size when considering the potential "GTT" size? I think PL_TT is just system memory that can be touched by the GPU device (likely has a gtt mapping), so not sure why that needs to be GT centric.

[BC] Also got comment from Matt as below
"
Matthew Auld is correct, that the gtt_mgr is the system memory manager for TTM and this is a per device resource - that is where it should live, be initialized, and fini. Likely change any args in public functions to a device rather than GT too.
...
let’s adjust the name too. s/gtt_mgr/sys_mgr

Matt
"

[BC] actually I thought about it, but I didn't want to make too much change and just want to fix the unloading issue.

Totally agree that the gtt should be global and not per gt. Will try to make the change.

Thanks,
Bruce

Quoted 101 lines

drivers/gpu/drm/xe/xe_gt.c int xe_gt_alloc(struct xe_device *xe, struct xe_gt

Quoted 30 lines
Cc Stuart Summers <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/xe/xe_device_types.h |  3 +++
 drivers/gpu/drm/xe/xe_gt.c           |  9 +++++++--
 drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c  | 25 +++++++++++++++----------
 3 files changed, 25 insertions(+), 12 deletions(-)
drivers/gpu/drm/xe/xe_device_types.h +3 -0
index 88f863edc41c..ea771f120c0f 100644
@@ -195,6 +195,9 @@ struct xe_device {
                        /** @mapping: pointer to VRAM mappable space */
                        void *__iomem mapping;
                } vram;
+               /** @gtt_mr: GTT TTM manager */
+               struct xe_ttm_gtt_mgr *gtt_mgr;
+               int instance;
        } mem;
 
        /** @usm: unified memory state */ diff --git

a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c index fd7a5b43ba3e..e7ca141478ef 100644

drivers/gpu/drm/xe/xe_gt.c +0 -0
@@ -77,8 +77,13 @@ int xe_gt_alloc(struct xe_device *xe, struct xe_gt

*gt)

drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c static void ttm_gtt_mgr_fini(struct drm_device *drm,

Quoted 22 lines
drivers/gpu/drm/xe/xe_gt.c +7 -2
                if (!gt->mem.vram_mgr)
                        return -ENOMEM;
 
-               gt->mem.gtt_mgr = drmm_kzalloc(drm, sizeof(*gt-
 mem.gtt_mgr),
-                                              GFP_KERNEL);
+               if (!xe->mem.gtt_mgr) {
+                       xe->mem.gtt_mgr =
+                               drmm_kzalloc(drm, sizeof(*gt->mem.gtt_mgr),
+                                            GFP_KERNEL);
+                       xe->mem.instance = 0;
+               }
+               gt->mem.gtt_mgr = xe->mem.gtt_mgr;
                if (!gt->mem.gtt_mgr)
                        return -ENOMEM;
        } else {
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +0 -0
index 8075781070f2..05300c71928e 100644
@@ -94,6 +94,9 @@ static void ttm_gtt_mgr_fini(struct drm_device *drm,

void *arg)

Quoted 14 lines
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +3 -1
        struct ttm_resource_manager *man = &mgr->manager;
        int err;
 
+       if (--xe->mem.instance)
+               return;
+
        ttm_resource_manager_set_used(man, false);
 
        err = ttm_resource_manager_evict_all(&xe->ttm, man); @@
-113,18 +116,20 @@ int xe_ttm_gtt_mgr_init(struct xe_gt *gt, struct

xe_ttm_gtt_mgr *mgr,

        XE_BUG_ON(xe_gt_is_media_type(gt));

drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c int xe_ttm_gtt_mgr_init(struct xe_gt *gt, struct xe_ttm_gtt_mgr *mgr,

Quoted 5 lines
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +0 -5
-       mgr->gt = gt;
-       man->use_tt = true;
-       man->func = &xe_ttm_gtt_mgr_func;
-
-       ttm_resource_manager_init(man, &xe->ttm, gtt_size >>

PAGE_SHIFT);

Quoted 6 lines
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +4 -1
+       if (!xe->mem.instance) {
+               mgr->gt = gt;
+               man->use_tt = true;
+               man->func = &xe_ttm_gtt_mgr_func;
 
-       ttm_set_driver_manager(&xe->ttm, XE_PL_TT, &mgr->manager);

drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c int xe_ttm_gtt_mgr_init(struct xe_gt *gt, struct xe_ttm_gtt_mgr *mgr,

Quoted 10 lines
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +5 -4
-       ttm_resource_manager_set_used(man, true);
+               ttm_resource_manager_init(man, &xe->ttm, gtt_size >>
+ PAGE_SHIFT);
 
-       err = drmm_add_action_or_reset(&xe->drm, ttm_gtt_mgr_fini, mgr);
-       if (err)
-               return err;
+               ttm_set_driver_manager(&xe->ttm, XE_PL_TT, &mgr->manager);
+               ttm_resource_manager_set_used(man, true);
+               err = drmm_add_action_or_reset(&xe->drm, ttm_gtt_mgr_fini,

mgr);

Quoted 10 lines
drivers/gpu/drm/xe/xe_ttm_gtt_mgr.c +4 -1
+               if (err)
+                       return err;
+       }
+       xe->mem.instance ++;
 
        return 0;
 }
--

2.25.1