[PATCH v10 3/8] gpu: Fix uninitialized buddy for built-in drivers

Joel Fernandes posted 8 patches 1 month, 1 week ago
[PATCH v10 3/8] gpu: Fix uninitialized buddy for built-in drivers
Posted by Joel Fernandes 1 month, 1 week ago
From: Koen Koning <koen.koning@linux.intel.com>

Use subsys_initcall instead of module_init for the GPU buddy allocator,
so its initialization code runs before any gpu drivers.
Otherwise, a built-in driver that tries to use the buddy allocator will
run into a kernel NULL pointer dereference because slab_blocks is
uninitialized.

Specifically, this fixes drm/xe (as built-in) running into a kernel
panic during boot, because it uses buddy during device probe.

Fixes: ba110db8e1bc ("gpu: Move DRM buddy allocator one level up (part two)")
Cc: Joel Fernandes <joelagnelf@nvidia.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: intel-xe@lists.freedesktop.org
Cc: Peter Senna Tschudin <peter.senna@linux.intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Koen Koning <koen.koning@linux.intel.com>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
---
 drivers/gpu/buddy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
index 603c59a2013a..81f57fdf913b 100644
--- a/drivers/gpu/buddy.c
+++ b/drivers/gpu/buddy.c
@@ -1315,7 +1315,7 @@ static int __init gpu_buddy_module_init(void)
 	return 0;
 }
 
-module_init(gpu_buddy_module_init);
+subsys_initcall(gpu_buddy_module_init);
 module_exit(gpu_buddy_module_exit);
 
 MODULE_DESCRIPTION("GPU Buddy Allocator");
-- 
2.34.1
Re: [PATCH v10 3/8] gpu: Fix uninitialized buddy for built-in drivers
Posted by Danilo Krummrich 1 month, 1 week ago
On Wed Feb 18, 2026 at 9:55 PM CET, Joel Fernandes wrote:
> From: Koen Koning <koen.koning@linux.intel.com>
>
> Use subsys_initcall instead of module_init for the GPU buddy allocator,
> so its initialization code runs before any gpu drivers.
> Otherwise, a built-in driver that tries to use the buddy allocator will
> run into a kernel NULL pointer dereference because slab_blocks is
> uninitialized.
>
> Specifically, this fixes drm/xe (as built-in) running into a kernel
> panic during boot, because it uses buddy during device probe.
>
> Fixes: ba110db8e1bc ("gpu: Move DRM buddy allocator one level up (part two)")

This Fixes: tag seems wrong. How is this code move related to this problem?

This should rather be:

Fixes: 6387a3c4b0c4 ("drm: move the buddy allocator from i915 into common drm")

Also, please add:

Cc: stable@vger.kernel.org

> Cc: Joel Fernandes <joelagnelf@nvidia.com>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: intel-xe@lists.freedesktop.org
> Cc: Peter Senna Tschudin <peter.senna@linux.intel.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Signed-off-by: Koen Koning <koen.koning@linux.intel.com>
> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
> Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>

I also think this patch should be sent separately and go through drm-misc-fixes.
Re: [PATCH v10 3/8] gpu: Fix uninitialized buddy for built-in drivers
Posted by Joel Fernandes 1 month, 1 week ago
On Thu, Feb 19, 2026 at 11:09:42AM +0100, Danilo Krummrich wrote:
> > Fixes: ba110db8e1bc ("gpu: Move DRM buddy allocator one level up (part two)")
>
> This Fixes: tag seems wrong. How is this code move related to this problem?
>
> This should rather be:
>
> Fixes: 6387a3c4b0c4 ("drm: move the buddy allocator from i915 into common drm")

You're right, the bug existed since the original move to common drm.
Will update the Fixes tag.

> Also, please add:
>
> Cc: stable@vger.kernel.org

Will add.

> I also think this patch should be sent separately and go through drm-misc-fixes.

Agreed. I'll pull this patch out of the series and send it separately
targeting drm-misc-fixes.

Thanks,
Joel
Re: [PATCH v10 3/8] gpu: Fix uninitialized buddy for built-in drivers
Posted by Joel Fernandes 1 month, 1 week ago

On 2/19/2026 10:31 AM, Joel Fernandes wrote:
> On Thu, Feb 19, 2026 at 11:09:42AM +0100, Danilo Krummrich wrote:
>>> Fixes: ba110db8e1bc ("gpu: Move DRM buddy allocator one level up (part two)")
>>
>> This Fixes: tag seems wrong. How is this code move related to this problem?
>>
>> This should rather be:
>>
>> Fixes: 6387a3c4b0c4 ("drm: move the buddy allocator from i915 into common drm")
> 
> You're right, the bug existed since the original move to common drm.
> Will update the Fixes tag.
> 
>> Also, please add:
>>
>> Cc: stable@vger.kernel.org
> 
> Will add.
> 
>> I also think this patch should be sent separately and go through drm-misc-fixes.
> 
> Agreed. I'll pull this patch out of the series and send it separately
> targeting drm-misc-fixes.
> 
I just saw that Koen will send it separately so I'll let him handle it. In
future postings, I will put both this fix and earlier 2 patches (part one and
two of the move) with prefix [cherry-pick], since the only reason I am carrying
them is because it is a dependency that is not yet in torvalds/master branch.

I should have made that clear. Thanks,

--
Joel Fernandes