Re: [PATCH] static_call: Handle module init failure correctly in static_call_del_module()

From: Jinjie Ruan
Date: Wed Sep 04 2024 - 23:35:23 EST




On 2024/9/4 16:51, Thomas Gleixner wrote:
> On Wed, Sep 04 2024 at 16:03, Jinjie Ruan wrote:
>> On 2024/9/4 15:08, Thomas Gleixner wrote:
>>> So the check must be:
>>>
>>> if (!static_call_key_has_mods(key))
>>> break;
>>
>> Hi, Thomas,
>>
>> with this patch, the issue not occurs again,
>>
>> but there are some memory leak here same to the following problem:
>
> That has absolutely nothing to do with static calls and the memory
> allocation failure case there.
>
> The module passed all preparatory steps, otherwise it would not be able
> to create a kmem_cache from the module init() function:
>
> kmem_cache_create+0x11/0x20
> do_one_initcall+0xdc/0x550
> do_init_module+0x241/0x630
>
> amdgpu_init()
>
> r = amdgpu_sync_init();
> if (r)
> goto error_sync;
>
> r = amdgpu_fence_slab_init();
> if (r)
> goto error_fence;
>
> <SNIP>
>
> return pci_register_driver(&amdgpu_kms_pci_driver);
>
> error_fence:
> amdgpu_sync_fini();
> error_sync:
> return r;
>
> Can you spot the problem?

Hi, Thomas,

It seems that it is not the memory leak source,

I test with the following patch, the memory leak also occurs,

but with the Link patch, the problem solved and the memory leak missed.

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 094498a0964b..3589e4768bd6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -3032,11 +3032,11 @@ static int __init amdgpu_init(void)

r = amdgpu_sync_init();
if (r)
- goto error_sync;
+ return r;

r = amdgpu_fence_slab_init();
if (r)
- goto error_fence;
+ goto error_sync;

DRM_INFO("amdgpu kernel modesetting enabled.\n");
amdgpu_register_atpx_handler();
@@ -3046,12 +3046,18 @@ static int __init amdgpu_init(void)
amdgpu_amdkfd_init();

/* let modprobe override vga console setting */
- return pci_register_driver(&amdgpu_kms_pci_driver);
+ r = pci_register_driver(&amdgpu_kms_pci_driver);
+ if (r)
+ goto error_fence;
+
+ return 0;

error_fence:
- amdgpu_sync_fini();
+ amdgpu_fence_slab_fini();

error_sync:
+ amdgpu_sync_fini();
+
return r;
}


>
> Thanks,
>
> tglx