Skip to contentSkip to conversation

memleak on xe load & unload on PTL

RFC In review Michał Grzelak 3 participants 4 messages Nov 18, 2025 – Nov 20, 2025

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

RFC 1/1 memleak on xe load & unload on PTL

Hi,

just hit memory leak on xe module load & unload:

unreferenced object 0xffff88811b047d10 (size 16):
comm "modprobe", pid 1058, jiffies 4297578480
hex dump (first 16 bytes):

    00 6b 4b 2d 81 88 ff ff 80 7e 4b 2d 81 88 ff ff  .kK-.....~K-....
  backtrace (crc 4f169eaf):
    kmemleak_alloc+0x4a/0x90
    __kmalloc_cache_noprof+0x488/0x800
    drm_buddy_init+0xc2/0x330 [drm_buddy]
    __xe_ttm_vram_mgr_init+0xc3/0x190 [xe]
    xe_ttm_stolen_mgr_init+0xf5/0x9d0 [xe]
    xe_device_probe+0x326/0x9e0 [xe]
    xe_pci_probe+0x39a/0x610 [xe]
    local_pci_probe+0x47/0xb0
    pci_device_probe+0xf3/0x260
    really_probe+0xf1/0x3c0
    __driver_probe_device+0x8c/0x180
    driver_probe_device+0x24/0xd0
    __driver_attach+0x10f/0x220
    bus_for_each_dev+0x7f/0xe0
    driver_attach+0x1e/0x30
    bus_add_driver+0x151/0x290

Issue was reproduced on PTL & BMG, booted with latest kernel from drm-tip. Looks like fault was introduced in commit d4cd665c9 ("drm/buddy: Separate clear and dirty free block trees"), since reverting it makes the leak disappear. Also attached RFC patch, which at first glance could fix the issue.

Added xe maintainers and the author to Cc.

BR,
Michał

From 914aa53c18a88834310b8560323b63bae98fb29d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Grzelak?= <[email protected]>
Date: Tue, 18 Nov 2025 11:34:11 +0100
Subject: [PATCH] drm/buddy: release free_trees array on buddy mm teardown
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316

During initialization of DRM buddy memory manager at drm_buddy_init, mm->free_trees array is allocated for both clear and dirty RB trees. During cleanup happening at drm_buddy_fini it is never freed, leading to memory leaks observed on xe module load & unload cycles.

Deallocate array for free trees when cleaning up buddy memory manager.

Fixes d4cd665c ("drm/buddy: Separate clear and dirty free block trees")
---
 drivers/gpu/drm/drm_buddy.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_buddy.c +1 -0
index 2f279b46bd2c..8308116058cc 100644
@@ -420,6 +420,7 @@ void drm_buddy_fini(struct drm_buddy *mm)
 
 	for_each_free_tree(i)
 		kfree(mm->free_trees[i]);
+	kfree(mm->free_trees);
 	kfree(mm->roots);
 }
 EXPORT_SYMBOL(drm_buddy_fini);
Signature · 1 line
2.45.2
#1 lore raw

Hi Michal,

Please send the patch for the review.

Regards,
Arun.

Quoted 36 lines · Michał Grzelak

Hi,

just hit memory leak on xe module load & unload:

unreferenced object 0xffff88811b047d10 (size 16):
  comm "modprobe", pid 1058, jiffies 4297578480
  hex dump (first 16 bytes):
    00 6b 4b 2d 81 88 ff ff 80 7e 4b 2d 81 88 ff ff .kK-.....~K-.... backtrace (crc 4f169eaf):

    kmemleak_alloc+0x4a/0x90
    __kmalloc_cache_noprof+0x488/0x800
    drm_buddy_init+0xc2/0x330 [drm_buddy]
    __xe_ttm_vram_mgr_init+0xc3/0x190 [xe]
    xe_ttm_stolen_mgr_init+0xf5/0x9d0 [xe]
    xe_device_probe+0x326/0x9e0 [xe]
    xe_pci_probe+0x39a/0x610 [xe]
    local_pci_probe+0x47/0xb0
    pci_device_probe+0xf3/0x260
    really_probe+0xf1/0x3c0
    __driver_probe_device+0x8c/0x180
    driver_probe_device+0x24/0xd0
    __driver_attach+0x10f/0x220
    bus_for_each_dev+0x7f/0xe0
    driver_attach+0x1e/0x30
    bus_add_driver+0x151/0x290

Issue was reproduced on PTL & BMG, booted with latest kernel from drm-tip. Looks like fault was introduced in commit d4cd665c9 ("drm/buddy: Separate clear and dirty free block trees"), since reverting it makes the leak disappear. Also attached RFC patch, which at first glance could fix the issue.

Added xe maintainers and the author to Cc.

BR,
Michał

Reviewed-by on v1 1/1
#2 lore raw
In reply to Michał Grzelak
Quoted 26 lines · Michał Grzelak

Hi,

just hit memory leak on xe module load & unload:

unreferenced object 0xffff88811b047d10 (size 16):
comm "modprobe", pid 1058, jiffies 4297578480
hex dump (first 16 bytes):

   00 6b 4b 2d 81 88 ff ff 80 7e 4b 2d 81 88 ff ff  .kK-.....~K-....
 backtrace (crc 4f169eaf):
   kmemleak_alloc+0x4a/0x90
   __kmalloc_cache_noprof+0x488/0x800
   drm_buddy_init+0xc2/0x330 [drm_buddy]
   __xe_ttm_vram_mgr_init+0xc3/0x190 [xe]
   xe_ttm_stolen_mgr_init+0xf5/0x9d0 [xe]
   xe_device_probe+0x326/0x9e0 [xe]
   xe_pci_probe+0x39a/0x610 [xe]
   local_pci_probe+0x47/0xb0
   pci_device_probe+0xf3/0x260
   really_probe+0xf1/0x3c0
   __driver_probe_device+0x8c/0x180
   driver_probe_device+0x24/0xd0
   __driver_attach+0x10f/0x220
   bus_for_each_dev+0x7f/0xe0
   driver_attach+0x1e/0x30
   bus_add_driver+0x151/0x290
Quoted 7 lines

Issue was reproduced on PTL & BMG, booted with latest kernel from drm-tip. Looks like fault was introduced in commit d4cd665c9 ("drm/buddy: Separate clear and dirty free block trees"), since reverting it makes the leak disappear. Also attached RFC patch, which at first glance could fix the issue.

Added xe maintainers and the author to Cc.

the backtrace above and the commit message below could be merged together

Quoted 31 lines

BR,
Michał

From 914aa53c18a88834310b8560323b63bae98fb29d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Grzelak?= <[email protected]>
Date: Tue, 18 Nov 2025 11:34:11 +0100
Subject: [PATCH] drm/buddy: release free_trees array on buddy mm teardown
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316

During initialization of DRM buddy memory manager at drm_buddy_init, mm->free_trees array is allocated for both clear and dirty RB trees. During cleanup happening at drm_buddy_fini it is never freed, leading to memory leaks observed on xe module load & unload cycles.

Deallocate array for free trees when cleaning up buddy memory manager.

Fixes d4cd665c ("drm/buddy: Separate clear and dirty free block trees")

---
drivers/gpu/drm/drm_buddy.c | 1 +

1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_buddy.c +0 -0
index 2f279b46bd2c..8308116058cc 100644

drivers/gpu/drm/drm_buddy.c void drm_buddy_fini(struct drm_buddy *mm) · line 423

Quoted 4 lines
drivers/gpu/drm/drm_buddy.c +1 -0
@@ -420,6 +420,7 @@ void drm_buddy_fini(struct drm_buddy *mm)
 
 	for_each_free_tree(i)
 		kfree(mm->free_trees[i]);
+	kfree(mm->free_trees);

looks correct to me and also matches the out_free_tree label in drm_buddy_init()

thanks,
Lucas De Marchi

Quoted 6 lines
drivers/gpu/drm/drm_buddy.c +0 -0
 	kfree(mm->roots);
 }
 EXPORT_SYMBOL(drm_buddy_fini);
Signature · 1 line
2.45.2
#3 lore raw
Quoted 66 lines · Lucas De Marchi
Quoted 26 lines · Michał Grzelak

Hi,

just hit memory leak on xe module load & unload:

unreferenced object 0xffff88811b047d10 (size 16):
comm "modprobe", pid 1058, jiffies 4297578480
hex dump (first 16 bytes):

   00 6b 4b 2d 81 88 ff ff 80 7e 4b 2d 81 88 ff ff  .kK-.....~K-....
 backtrace (crc 4f169eaf):
   kmemleak_alloc+0x4a/0x90
   __kmalloc_cache_noprof+0x488/0x800
   drm_buddy_init+0xc2/0x330 [drm_buddy]
   __xe_ttm_vram_mgr_init+0xc3/0x190 [xe]
   xe_ttm_stolen_mgr_init+0xf5/0x9d0 [xe]
   xe_device_probe+0x326/0x9e0 [xe]
   xe_pci_probe+0x39a/0x610 [xe]
   local_pci_probe+0x47/0xb0
   pci_device_probe+0xf3/0x260
   really_probe+0xf1/0x3c0
   __driver_probe_device+0x8c/0x180
   driver_probe_device+0x24/0xd0
   __driver_attach+0x10f/0x220
   bus_for_each_dev+0x7f/0xe0
   driver_attach+0x1e/0x30
   bus_add_driver+0x151/0x290
Quoted 7 lines

Issue was reproduced on PTL & BMG, booted with latest kernel from drm-tip. Looks like fault was introduced in commit d4cd665c9 ("drm/buddy: Separate clear and dirty free block trees"), since reverting it makes the leak disappear. Also attached RFC patch, which at first glance could fix the issue.

Added xe maintainers and the author to Cc.

the backtrace above and the commit message below could be merged together

Quoted 28 lines

From 914aa53c18a88834310b8560323b63bae98fb29d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Grzelak?= <[email protected]>
Date: Tue, 18 Nov 2025 11:34:11 +0100
Subject: [PATCH] drm/buddy: release free_trees array on buddy mm teardown
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316

During initialization of DRM buddy memory manager at drm_buddy_init, mm->free_trees array is allocated for both clear and dirty RB trees. During cleanup happening at drm_buddy_fini it is never freed, leading to memory leaks observed on xe module load & unload cycles.

Deallocate array for free trees when cleaning up buddy memory manager.

Fixes d4cd665c ("drm/buddy: Separate clear and dirty free block trees")

---
drivers/gpu/drm/drm_buddy.c | 1 +

1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_buddy.c +0 -0
index 2f279b46bd2c..8308116058cc 100644
@@ -420,6 +420,7 @@ void drm_buddy_fini(struct drm_buddy *mm)
 
Quoted 8 lines

drivers/gpu/drm/drm_buddy.c void drm_buddy_fini(struct drm_buddy *mm) · line 423

Quoted 3 lines
drivers/gpu/drm/drm_buddy.c +1 -0
 	for_each_free_tree(i)
 		kfree(mm->free_trees[i]);
+	kfree(mm->free_trees);

looks correct to me and also matches the out_free_tree label in drm_buddy_init()

Thank you Lucas for your review. I will update the commit message with your R-B applied when resending the patch.

BR,
Michał