amdgpu: fixes memleak issue when init failed
Subsystems (2)
PATCH 1/1 amdgpu: fixes memleak issue when init failed
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19 -5
@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total); +VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }/**
Signature · 1 line
2.26.2
Am 21.04.20 um 13:17 schrieb Bernard Zhao:
Quoted 3 lines
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.
NAK, failure to create sysfs nodes are not critical.
Christian.
Quoted 50 lines
Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +12
-5@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total);
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, · line 218
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7
-0+VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
From: "Christian König" <[email protected]>
Date: 2020-04-21 19:22:49
To: Bernard Zhao <[email protected]>,Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
Quoted 8 lines
Quoted 3 lines
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.NAK, failure to create sysfs nodes are not critical.
Christian.
OK, get it.
By the way, should i modify this patch to just handle <kfree(mgr)> in error branch, or that it is also unnecessary?
Regards,
Bernard
Quoted 61 lines
Quoted 60 lines
Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19
-5@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total); +VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }/**
Christian König
maintainerAm 21.04.20 um 14:09 schrieb 赵军奎:
Quoted 8 lines
From: "Christian König" <[email protected]>
Date: 2020-04-21 19:22:49
To: Bernard Zhao <[email protected]>,Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:Quoted 3 lines
Quoted 3 lines
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.
Quoted 6 lines
Quoted 4 lines
NAK, failure to create sysfs nodes are not critical.
Christian.
OK, get it.
By the way, should i modify this patch to just handle <kfree(mgr)> in error branch, or that it is also unnecessary?
What you can do is to drop the "return ret" if anything with the sysfs nodes goes wrong and instead print the error code.
It's really annoying that loading, unloading and loading the driver again sometimes fails because we have a bug in the sysfs files cleanup.
We certainly should fix those bugs as well, but they are just not critical for correct driver functionality.
Regards,
Christian.
Quoted 62 lines
Regards,
BernardQuoted 58 lines
Quoted 58 lines
Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19
-5@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total); +VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }
Quoted 2 lines
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, · line 218
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0
-0/**
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
发件人:"Christian König" <[email protected]>
发送日期:2020-04-21 21:02:27
收件人:"赵军奎" <[email protected]>
抄送人:Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected],[email protected] 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
Quoted 10 lines
Quoted 10 lines
From: "Christian König" <[email protected]>
Date: 2020-04-21 19:22:49
To: Bernard Zhao <[email protected]>,Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:Quoted 5 lines
Quoted 3 lines
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.NAK, failure to create sysfs nodes are not critical.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Christian.
OK, get it.
By the way, should i modify this patch to just handle <kfree(mgr)> in error branch, or that it is also unnecessary?What you can do is to drop the "return ret" if anything with the sysfs nodes goes wrong and instead print the error code.
Emmm, for this part, i am not sure, my modify first print the error, secone release not free memory, and last return error, make everything clear to the system.
I think it`s the same with what you mentioned, is there something that I misunderstood?
Quoted 76 lines
It's really annoying that loading, unloading and loading the driver again sometimes fails because we have a bug in the sysfs files cleanup.
We certainly should fix those bugs as well, but they are just not critical for correct driver functionality.
Regards,
Christian.Quoted 64 lines
Regards,
BernardQuoted 59 lines
Quoted 59 lines
Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19
-5@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total); +VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }/**
Christian König
maintainerAm 21.04.20 um 15:39 schrieb 赵军奎:
Quoted 17 lines
发件人:"Christian König" <[email protected]>
发送日期:2020-04-21 21:02:27
收件人:"赵军奎" <[email protected]>
抄送人:Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected],[email protected] 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:Quoted 12 lines
Quoted 12 lines
From: "Christian König" <[email protected]>
Date: 2020-04-21 19:22:49
To: Bernard Zhao <[email protected]>,Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:Quoted 7 lines
Quoted 3 lines
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.NAK, failure to create sysfs nodes are not critical.
Christian.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
OK, get it.
By the way, should i modify this patch to just handle <kfree(mgr)> in error branch, or that it is also unnecessary?What you can do is to drop the "return ret" if anything with the sysfs nodes goes wrong and instead print the error code.
Emmm, for this part, i am not sure, my modify first print the error, secone release not free memory, and last return error, make everything clear to the system.
I think it`s the same with what you mentioned, is there something that I misunderstood?
Yes, maybe an example makes it more clear what to do here. Currently we print and error and return when something with the sysfs files goes wrong:
if (ret) {
DRM_ERROR("Failed to create device file mem_info_vram_total\n"); return ret;
}
But what we should do instead is just to print an error and continue and in the end return success status:
if (ret)
DRM_ERROR("Failed to create device file mem_info_vram_total (%d)\n", r);
...
return 0;
Regards,
Christian.
Quoted 71 lines
Quoted 71 lines
It's really annoying that loading, unloading and loading the driver again sometimes fails because we have a bug in the sysfs files cleanup.
We certainly should fix those bugs as well, but they are just not critical for correct driver functionality.
Regards,
Christian.Quoted 61 lines
Regards,
BernardQuoted 58 lines
Quoted 58 lines
Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19
-5@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total); +VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, · line 218
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0
-0/**
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
发件人:"Christian König" <[email protected]>
发送日期:2020-04-21 22:53:47
收件人:"赵军奎" <[email protected]>
抄送人:Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected],[email protected] 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:
Quoted 40 lines
Quoted 17 lines
发件人:"Christian König" <[email protected]>
发送日期:2020-04-21 21:02:27
收件人:"赵军奎" <[email protected]>
抄送人:Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected],[email protected] 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:Quoted 12 lines
Quoted 12 lines
From: "Christian König" <[email protected]>
Date: 2020-04-21 19:22:49
To: Bernard Zhao <[email protected]>,Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:Quoted 7 lines
Quoted 3 lines
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.NAK, failure to create sysfs nodes are not critical.
Christian.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
OK, get it.
By the way, should i modify this patch to just handle <kfree(mgr)> in error branch, or that it is also unnecessary?What you can do is to drop the "return ret" if anything with the sysfs nodes goes wrong and instead print the error code.
Emmm, for this part, i am not sure, my modify first print the error, secone release not free memory, and last return error, make everything clear to the system.
I think it`s the same with what you mentioned, is there something that I misunderstood?Yes, maybe an example makes it more clear what to do here. Currently we print and error and return when something with the sysfs files goes wrong:
if (ret) {
DRM_ERROR("Failed to create device file mem_info_vram_total\n"); return ret;
}But what we should do instead is just to print an error and continue and in the end return success status:
if (ret)
DRM_ERROR("Failed to create device file mem_info_vram_total (%d)\n", r);
Quoted 6 lines
...
return 0;Regards,
Christian.
Emmm, i am still confused about two points:
1 Does that mean there is no failed case in this function?
2 There is no need to free the kzmalloc space(no possibility of memory leak )?
Regards,
Bernard
Quoted 74 lines
Quoted 73 lines
Quoted 72 lines
It's really annoying that loading, unloading and loading the driver again sometimes fails because we have a bug in the sysfs files cleanup.
We certainly should fix those bugs as well, but they are just not critical for correct driver functionality.
Regards,
Christian.Quoted 62 lines
Regards,
BernardQuoted 59 lines
Quoted 59 lines
Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19
-5@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total); +VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }/**
Christian König
maintainerAm 22.04.20 um 02:56 schrieb 赵军奎:
Quoted 44 lines
发件人:"Christian König" <[email protected]>
发送日期:2020-04-21 22:53:47
收件人:"赵军奎" <[email protected]>
抄送人:Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected],[email protected] 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:Quoted 39 lines
Quoted 17 lines
发件人:"Christian König" <[email protected]>
发送日期:2020-04-21 21:02:27
收件人:"赵军奎" <[email protected]>
抄送人:Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected],[email protected] 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:Quoted 12 lines
Quoted 12 lines
From: "Christian König" <[email protected]>
Date: 2020-04-21 19:22:49
To: Bernard Zhao <[email protected]>,Alex Deucher <[email protected]>,"David (ChunMing) Zhou" <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,Tom St Denis <[email protected]>,Ori Messinger <[email protected]>,Sam Ravnborg <[email protected]>,[email protected],[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:Quoted 7 lines
Quoted 3 lines
VRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.NAK, failure to create sysfs nodes are not critical.
Christian.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
OK, get it.
By the way, should i modify this patch to just handle <kfree(mgr)> in error branch, or that it is also unnecessary?What you can do is to drop the "return ret" if anything with the sysfs nodes goes wrong and instead print the error code.
Emmm, for this part, i am not sure, my modify first print the error, secone release not free memory, and last return error, make everything clear to the system.
I think it`s the same with what you mentioned, is there something that I misunderstood?Yes, maybe an example makes it more clear what to do here. Currently we print and error and return when something with the sysfs files goes wrong:
if (ret) {
DRM_ERROR("Failed to create device file mem_info_vram_total\n"); return ret;
}But what we should do instead is just to print an error and continue and in the end return success status:
if (ret)
DRM_ERROR("Failed to create device filemem_info_vram_total
(%d)\n", r);
Quoted 8 lines
Quoted 6 lines
...
return 0;Regards,
Christian.Emmm, i am still confused about two points:
1 Does that mean there is no failed case in this function?
Well the kzalloc can still fail.
Quoted 1 line
2 There is no need to free the kzmalloc space(no possibility of memory leak )?
Correct, yes.
Regards,
Christian.
Quoted 73 lines
Regards,
BernardQuoted 69 lines
Quoted 69 lines
Quoted 69 lines
It's really annoying that loading, unloading and loading the driver again sometimes fails because we have a bug in the sysfs files cleanup.
We certainly should fix those bugs as well, but they are just not critical for correct driver functionality.
Regards,
Christian.Quoted 61 lines
Regards,
BernardQuoted 58 lines
Quoted 58 lines
Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +19
-5@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n" ); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n" ); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n" ); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n" ); -return ret; + goto VIS_VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_vendor);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_vendor\n" ); -return ret; + goto VRAM_VERDOR_FAIL; }return 0 ; + +VRAM_VERDOR_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_used); +VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vis_vram_total); +VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret; }
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man, · line 218
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0
-0/**
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 31 lines
-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Bernard Zhao
Sent: Tuesday, April 21, 2020 7:17 AM
To: Alex Deucher <[email protected]>; Christian König <[email protected]>; David (ChunMing) Zhou <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Tom St Denis <[email protected]>; Ori Messinger <[email protected]>; Sam Ravnborg <[email protected]>; Bernard Zhao <[email protected]>; [email protected]; dri- [email protected]; [email protected]
Cc: [email protected]
Subject: [PATCH] amdgpu: fixes memleak issue when init failedVRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.Signed-off-by Bernard Zhao <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c| 24
++++++++++++++++----1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0
-0@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man,
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_init(struct · line 184
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_total\n"); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);
Have you looked at the DEVICE_ATTR mechanism?
It is set up to add device files. You won't get the granularity of each file, but it has a lot more automatic-ness to setting this stuff up.
Mike
Quoted 58 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3
-3if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n"); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n"); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n"); -return ret; + goto VIS_VRAM_USED_FAIL; } ret = device_create_file(adev->dev,&dev_attr_mem_info_vram_vendor); if (ret) { DRM_ERROR("Failed to create device filemem_info_vram_vendor\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1-return ret; + goto VRAM_VERDOR_FAIL;} return 0;drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3
-0+ +VRAM_VERDOR_FAIL: + device_remove_file(adev->dev,
&dev_attr_mem_info_vis_vram_used);drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4
-0+VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: + device_remove_file(adev->dev,
&dev_attr_mem_info_vis_vram_total);drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7
-0+VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret;}
/**
--
2.26.2_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 22.04.20 um 17:51 schrieb Ruhl, Michael J:
Quoted 34 lines
Quoted 34 lines
-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Bernard Zhao
Sent: Tuesday, April 21, 2020 7:17 AM
To: Alex Deucher <[email protected]>; Christian König <[email protected]>; David (ChunMing) Zhou <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Tom St Denis <[email protected]>; Ori Messinger <[email protected]>; Sam Ravnborg <[email protected]>; Bernard Zhao <[email protected]>; [email protected]; dri- [email protected]; [email protected]
Cc: [email protected]
Subject: [PATCH] amdgpu: fixes memleak issue when init failedVRAM manager and DRM MM when init failed, there is no operaction to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.Signed-off-by Bernard Zhao <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c| 24
++++++++++++++++----1 file changed, 19 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0
-0@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(structttm_mem_type_manager *man, ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_total);if (ret) {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_init(struct · line 184
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1DRM_ERROR ("Failed to create device file mem_info_vram_total\n"); -return ret; + goto VRAM_TOTAL_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_total);Have you looked at the
DEVICE_ATTRmechanism?
Yeah, I've thought about that as well. But didn't had time to look into detail if that could be applied here or not.
Regards,
Christian.
Quoted 60 lines
It is set up to add device files. You won't get the granularity of each file, but it has a lot more automatic-ness to setting this stuff up.
Mike
Quoted 54 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3
-3if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_total\n"); -return ret; + goto VIS_VRAM_TOTA_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vram_used\n"); -return ret; + goto VRAM_USED_FAIL; } ret =device_create_file (adev->dev, &dev_attr_mem_info_vis_vram_used);if (ret) {DRM_ERROR ("Failed to create device file mem_info_vis_vram_used\n"); -return ret; + goto VIS_VRAM_USED_FAIL; } ret = device_create_file(adev->dev,&dev_attr_mem_info_vram_vendor); if (ret) { DRM_ERROR("Failed to create device filemem_info_vram_vendor\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +1
-1-return ret; + goto VRAM_VERDOR_FAIL;} return 0;drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3
-0+ +VRAM_VERDOR_FAIL: + device_remove_file(adev->dev,
&dev_attr_mem_info_vis_vram_used);drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4
-0+VIS_VRAM_USED_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_used); +RVAM_USED_FAIL: + device_remove_file(adev->dev,
&dev_attr_mem_info_vis_vram_total);drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7
-0+VIS_VRAM_TOTA_FAIL: +device_remove_file (adev->dev, &dev_attr_mem_info_vram_total); +VRAM_TOTAL_FAIL: +kfree (mgr); + man->priv =NULL ; + +return ret;}
/**
--
2.26.2
Quoted 8 lines
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx