All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 11:17 ` Bernard Zhao
  0 siblings, 0 replies; 30+ messages in thread
From: Bernard Zhao @ 2020-04-21 11:17 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David (ChunMing) Zhou,
	David Airlie, Daniel Vetter, Tom St Denis, Ori Messinger,
	Sam Ravnborg, Bernard Zhao, amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

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.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 82a3299e53c0..4c5fb153e6b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -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;
 }
 
 /**
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 11:17 ` Bernard Zhao
  0 siblings, 0 replies; 30+ messages in thread
From: Bernard Zhao @ 2020-04-21 11:17 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David (ChunMing) Zhou,
	David Airlie, Daniel Vetter, Tom St Denis, Ori Messinger,
	Sam Ravnborg, Bernard Zhao, amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

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.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 82a3299e53c0..4c5fb153e6b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -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;
 }
 
 /**
-- 
2.26.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 11:17 ` Bernard Zhao
  0 siblings, 0 replies; 30+ messages in thread
From: Bernard Zhao @ 2020-04-21 11:17 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David (ChunMing) Zhou,
	David Airlie, Daniel Vetter, Tom St Denis, Ori Messinger,
	Sam Ravnborg, Bernard Zhao, amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

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.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 82a3299e53c0..4c5fb153e6b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -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;
 }
 
 /**
-- 
2.26.2

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-21 11:17 ` Bernard Zhao
  (?)
@ 2020-04-21 11:22   ` Christian König
  -1 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 11:22 UTC (permalink / raw)
  To: Bernard Zhao, Alex Deucher, David (ChunMing) Zhou, David Airlie,
	Daniel Vetter, Tom St Denis, Ori Messinger, Sam Ravnborg,
	amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

Am 21.04.20 um 13:17 schrieb Bernard Zhao:
> 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.

>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>   1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 82a3299e53c0..4c5fb153e6b4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -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;
>   }
>   
>   /**


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 11:22   ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 11:22 UTC (permalink / raw)
  To: Bernard Zhao, Alex Deucher, David (ChunMing) Zhou, David Airlie,
	Daniel Vetter, Tom St Denis, Ori Messinger, Sam Ravnborg,
	amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

Am 21.04.20 um 13:17 schrieb Bernard Zhao:
> 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.

>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>   1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 82a3299e53c0..4c5fb153e6b4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -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;
>   }
>   
>   /**

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 11:22   ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 11:22 UTC (permalink / raw)
  To: Bernard Zhao, Alex Deucher, David (ChunMing) Zhou, David Airlie,
	Daniel Vetter, Tom St Denis, Ori Messinger, Sam Ravnborg,
	amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

Am 21.04.20 um 13:17 schrieb Bernard Zhao:
> 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.

>
> Signed-off-by: Bernard Zhao <bernard@vivo.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>   1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 82a3299e53c0..4c5fb153e6b4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -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;
>   }
>   
>   /**

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-21 11:22   ` Christian König
  (?)
@ 2020-04-21 12:09     ` 赵军奎
  -1 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-21 12:09 UTC (permalink / raw)
  To: Christian König
  Cc: Alex Deucher, David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Tom St Denis, Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel,
	linux-kernel, opensource.kernel


From: "Christian König" <christian.koenig@amd.com>
Date: 2020-04-21 19:22:49
To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
Cc:  opensource.kernel@vivo.com
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>> 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

>>
>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>   1 file changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> index 82a3299e53c0..4c5fb153e6b4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> @@ -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;
>>   }
>>   
>>   /**
>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 12:09     ` 赵军奎
  0 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-21 12:09 UTC (permalink / raw)
  To: Christian König
  Cc: Tom St Denis, Ori Messinger, opensource.kernel, David Airlie,
	linux-kernel, amd-gfx, dri-devel, Alex Deucher, Sam Ravnborg


From: "Christian König" <christian.koenig@amd.com>
Date: 2020-04-21 19:22:49
To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
Cc:  opensource.kernel@vivo.com
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>> 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

>>
>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>   1 file changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> index 82a3299e53c0..4c5fb153e6b4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> @@ -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;
>>   }
>>   
>>   /**
>


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 12:09     ` 赵军奎
  0 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-21 12:09 UTC (permalink / raw)
  To: Christian König
  Cc: Tom St Denis, David (ChunMing) Zhou, Ori Messinger,
	opensource.kernel, David Airlie, linux-kernel, amd-gfx,
	dri-devel, Daniel Vetter, Alex Deucher, Sam Ravnborg


From: "Christian König" <christian.koenig@amd.com>
Date: 2020-04-21 19:22:49
To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
Cc:  opensource.kernel@vivo.com
Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>> 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

>>
>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>   1 file changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> index 82a3299e53c0..4c5fb153e6b4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> @@ -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;
>>   }
>>   
>>   /**
>


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-21 12:09     ` 赵军奎
  (?)
@ 2020-04-21 13:02       ` Christian König
  -1 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 13:02 UTC (permalink / raw)
  To: 赵军奎
  Cc: Alex Deucher, David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Tom St Denis, Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel,
	linux-kernel, opensource.kernel

Am 21.04.20 um 14:09 schrieb 赵军奎:
> From: "Christian König" <christian.koenig@amd.com>
> Date: 2020-04-21 19:22:49
> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
> Cc:  opensource.kernel@vivo.com
> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>> 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?

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.

>
> Regards,
> Bernard
>
>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>> ---
>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>    1 file changed, 19 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> @@ -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;
>>>    }
>>>    
>>>    /**
>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 13:02       ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 13:02 UTC (permalink / raw)
  To: 赵军奎
  Cc: Tom St Denis, Ori Messinger, opensource.kernel, David Airlie,
	linux-kernel, amd-gfx, dri-devel, Alex Deucher, Sam Ravnborg

Am 21.04.20 um 14:09 schrieb 赵军奎:
> From: "Christian König" <christian.koenig@amd.com>
> Date: 2020-04-21 19:22:49
> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
> Cc:  opensource.kernel@vivo.com
> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>> 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?

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.

>
> Regards,
> Bernard
>
>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>> ---
>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>    1 file changed, 19 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> @@ -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;
>>>    }
>>>    
>>>    /**
>

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 13:02       ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 13:02 UTC (permalink / raw)
  To: 赵军奎
  Cc: Tom St Denis, David (ChunMing) Zhou, Ori Messinger,
	opensource.kernel, David Airlie, linux-kernel, amd-gfx,
	dri-devel, Daniel Vetter, Alex Deucher, Sam Ravnborg

Am 21.04.20 um 14:09 schrieb 赵军奎:
> From: "Christian König" <christian.koenig@amd.com>
> Date: 2020-04-21 19:22:49
> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
> Cc:  opensource.kernel@vivo.com
> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>> 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?

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.

>
> Regards,
> Bernard
>
>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>> ---
>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>    1 file changed, 19 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>> @@ -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;
>>>    }
>>>    
>>>    /**
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-21 13:02       ` Christian König
  (?)
@ 2020-04-21 13:39         ` 赵军奎
  -1 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-21 13:39 UTC (permalink / raw)
  To: Christian König
  Cc: Alex Deucher, David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Tom St Denis, Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel,
	linux-kernel, opensource.kernel


发件人:"Christian König" <christian.koenig@amd.com>
发送日期:2020-04-21 21:02:27
收件人:"赵军奎" <bernard@vivo.com>
抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>> From: "Christian König" <christian.koenig@amd.com>
>> Date: 2020-04-21 19:22:49
>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>> Cc:  opensource.kernel@vivo.com
>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>> 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?
>
>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?

>
>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.


>>
>> Regards,
>> Bernard
>>
>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>> ---
>>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>    1 file changed, 19 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> @@ -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;
>>>>    }
>>>>    
>>>>    /**
>>
>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 13:39         ` 赵军奎
  0 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-21 13:39 UTC (permalink / raw)
  To: Christian König
  Cc: Tom St Denis, Ori Messinger, opensource.kernel, David Airlie,
	linux-kernel, amd-gfx, dri-devel, Alex Deucher, Sam Ravnborg


发件人:"Christian König" <christian.koenig@amd.com>
发送日期:2020-04-21 21:02:27
收件人:"赵军奎" <bernard@vivo.com>
抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>> From: "Christian König" <christian.koenig@amd.com>
>> Date: 2020-04-21 19:22:49
>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>> Cc:  opensource.kernel@vivo.com
>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>> 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?
>
>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?

>
>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.


>>
>> Regards,
>> Bernard
>>
>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>> ---
>>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>    1 file changed, 19 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> @@ -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;
>>>>    }
>>>>    
>>>>    /**
>>
>


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 13:39         ` 赵军奎
  0 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-21 13:39 UTC (permalink / raw)
  To: Christian König
  Cc: Tom St Denis, David (ChunMing) Zhou, Ori Messinger,
	opensource.kernel, David Airlie, linux-kernel, amd-gfx,
	dri-devel, Daniel Vetter, Alex Deucher, Sam Ravnborg


发件人:"Christian König" <christian.koenig@amd.com>
发送日期:2020-04-21 21:02:27
收件人:"赵军奎" <bernard@vivo.com>
抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>> From: "Christian König" <christian.koenig@amd.com>
>> Date: 2020-04-21 19:22:49
>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>> Cc:  opensource.kernel@vivo.com
>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>> 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?
>
>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?

>
>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.


>>
>> Regards,
>> Bernard
>>
>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>> ---
>>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>    1 file changed, 19 insertions(+), 5 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>> @@ -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;
>>>>    }
>>>>    
>>>>    /**
>>
>


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-21 13:39         ` 赵军奎
  (?)
@ 2020-04-21 14:53           ` Christian König
  -1 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 14:53 UTC (permalink / raw)
  To: 赵军奎
  Cc: Alex Deucher, David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Tom St Denis, Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel,
	linux-kernel, opensource.kernel

Am 21.04.20 um 15:39 schrieb 赵军奎:
> 发件人:"Christian König" <christian.koenig@amd.com>
> 发送日期:2020-04-21 21:02:27
> 收件人:"赵军奎" <bernard@vivo.com>
> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>> From: "Christian König" <christian.koenig@amd.com>
>>> Date: 2020-04-21 19:22:49
>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>> Cc:  opensource.kernel@vivo.com
>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>> 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?
>> 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.


>
>> 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.
>
>>> Regards,
>>> Bernard
>>>
>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>> ---
>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>     1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> @@ -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;
>>>>>     }
>>>>>     
>>>>>     /**
>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 14:53           ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 14:53 UTC (permalink / raw)
  To: 赵军奎
  Cc: Tom St Denis, Ori Messinger, opensource.kernel, David Airlie,
	linux-kernel, amd-gfx, dri-devel, Alex Deucher, Sam Ravnborg

Am 21.04.20 um 15:39 schrieb 赵军奎:
> 发件人:"Christian König" <christian.koenig@amd.com>
> 发送日期:2020-04-21 21:02:27
> 收件人:"赵军奎" <bernard@vivo.com>
> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>> From: "Christian König" <christian.koenig@amd.com>
>>> Date: 2020-04-21 19:22:49
>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>> Cc:  opensource.kernel@vivo.com
>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>> 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?
>> 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.


>
>> 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.
>
>>> Regards,
>>> Bernard
>>>
>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>> ---
>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>     1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> @@ -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;
>>>>>     }
>>>>>     
>>>>>     /**
>

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 14:53           ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-21 14:53 UTC (permalink / raw)
  To: 赵军奎
  Cc: Tom St Denis, David (ChunMing) Zhou, Ori Messinger,
	opensource.kernel, David Airlie, linux-kernel, amd-gfx,
	dri-devel, Daniel Vetter, Alex Deucher, Sam Ravnborg

Am 21.04.20 um 15:39 schrieb 赵军奎:
> 发件人:"Christian König" <christian.koenig@amd.com>
> 发送日期:2020-04-21 21:02:27
> 收件人:"赵军奎" <bernard@vivo.com>
> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>> From: "Christian König" <christian.koenig@amd.com>
>>> Date: 2020-04-21 19:22:49
>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>> Cc:  opensource.kernel@vivo.com
>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>> 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?
>> 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.


>
>> 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.
>
>>> Regards,
>>> Bernard
>>>
>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>> ---
>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>     1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>> @@ -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;
>>>>>     }
>>>>>     
>>>>>     /**
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-21 14:53           ` Christian König
  (?)
@ 2020-04-22  0:56             ` 赵军奎
  -1 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-22  0:56 UTC (permalink / raw)
  To: Christian König
  Cc: Alex Deucher, David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Tom St Denis, Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel,
	linux-kernel, opensource.kernel


发件人:"Christian König" <christian.koenig@amd.com>
发送日期:2020-04-21 22:53:47
收件人:"赵军奎" <bernard@vivo.com>
抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:
>> 发件人:"Christian König" <christian.koenig@amd.com>
>> 发送日期:2020-04-21 21:02:27
>> 收件人:"赵军奎" <bernard@vivo.com>
>> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
>> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>>> From: "Christian König" <christian.koenig@amd.com>
>>>> Date: 2020-04-21 19:22:49
>>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>>> Cc:  opensource.kernel@vivo.com
>>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>>> 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?
>>> 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.
>

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

>>
>>> 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.
>>
>>>> Regards,
>>>> Bernard
>>>>
>>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>>> ---
>>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>>     1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> @@ -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;
>>>>>>     }
>>>>>>     
>>>>>>     /**
>>
>



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22  0:56             ` 赵军奎
  0 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-22  0:56 UTC (permalink / raw)
  To: Christian König
  Cc: Tom St Denis, Ori Messinger, opensource.kernel, David Airlie,
	linux-kernel, amd-gfx, dri-devel, Alex Deucher, Sam Ravnborg


发件人:"Christian König" <christian.koenig@amd.com>
发送日期:2020-04-21 22:53:47
收件人:"赵军奎" <bernard@vivo.com>
抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:
>> 发件人:"Christian König" <christian.koenig@amd.com>
>> 发送日期:2020-04-21 21:02:27
>> 收件人:"赵军奎" <bernard@vivo.com>
>> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
>> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>>> From: "Christian König" <christian.koenig@amd.com>
>>>> Date: 2020-04-21 19:22:49
>>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>>> Cc:  opensource.kernel@vivo.com
>>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>>> 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?
>>> 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.
>

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

>>
>>> 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.
>>
>>>> Regards,
>>>> Bernard
>>>>
>>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>>> ---
>>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>>     1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> @@ -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;
>>>>>>     }
>>>>>>     
>>>>>>     /**
>>
>


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re:Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22  0:56             ` 赵军奎
  0 siblings, 0 replies; 30+ messages in thread
From: 赵军奎 @ 2020-04-22  0:56 UTC (permalink / raw)
  To: Christian König
  Cc: Tom St Denis, David (ChunMing) Zhou, Ori Messinger,
	opensource.kernel, David Airlie, linux-kernel, amd-gfx,
	dri-devel, Daniel Vetter, Alex Deucher, Sam Ravnborg


发件人:"Christian König" <christian.koenig@amd.com>
发送日期:2020-04-21 22:53:47
收件人:"赵军奎" <bernard@vivo.com>
抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:
>> 发件人:"Christian König" <christian.koenig@amd.com>
>> 发送日期:2020-04-21 21:02:27
>> 收件人:"赵军奎" <bernard@vivo.com>
>> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
>> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>>> From: "Christian König" <christian.koenig@amd.com>
>>>> Date: 2020-04-21 19:22:49
>>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>>> Cc:  opensource.kernel@vivo.com
>>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>>> 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?
>>> 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.
>

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

>>
>>> 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.
>>
>>>> Regards,
>>>> Bernard
>>>>
>>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>>> ---
>>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>>     1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>> @@ -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;
>>>>>>     }
>>>>>>     
>>>>>>     /**
>>
>


_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-22  0:56             ` 赵军奎
  (?)
@ 2020-04-22  7:27               ` Christian König
  -1 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-22  7:27 UTC (permalink / raw)
  To: 赵军奎
  Cc: Alex Deucher, David (ChunMing) Zhou, David Airlie, Daniel Vetter,
	Tom St Denis, Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel,
	linux-kernel, opensource.kernel

Am 22.04.20 um 02:56 schrieb 赵军奎:
> 发件人:"Christian König" <christian.koenig@amd.com>
> 发送日期:2020-04-21 22:53:47
> 收件人:"赵军奎" <bernard@vivo.com>
> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:
>>> 发件人:"Christian König" <christian.koenig@amd.com>
>>> 发送日期:2020-04-21 21:02:27
>>> 收件人:"赵军奎" <bernard@vivo.com>
>>> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
>>> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>>>> From: "Christian König" <christian.koenig@amd.com>
>>>>> Date: 2020-04-21 19:22:49
>>>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>>>> Cc:  opensource.kernel@vivo.com
>>>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>>>> 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?
>>>> 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.
>>
> 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.

> 2 There is no need to free the kzmalloc space(no possibility of memory leak )?

Correct, yes.

Regards,
Christian.

>
> Regards,
> Bernard
>
>>>> 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.
>>>>> Regards,
>>>>> Bernard
>>>>>
>>>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>>>> ---
>>>>>>>      drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>>>      1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> @@ -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;
>>>>>>>      }
>>>>>>>      
>>>>>>>      /**
>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22  7:27               ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-22  7:27 UTC (permalink / raw)
  To: 赵军奎
  Cc: Tom St Denis, Ori Messinger, opensource.kernel, David Airlie,
	linux-kernel, amd-gfx, dri-devel, Alex Deucher, Sam Ravnborg

Am 22.04.20 um 02:56 schrieb 赵军奎:
> 发件人:"Christian König" <christian.koenig@amd.com>
> 发送日期:2020-04-21 22:53:47
> 收件人:"赵军奎" <bernard@vivo.com>
> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:
>>> 发件人:"Christian König" <christian.koenig@amd.com>
>>> 发送日期:2020-04-21 21:02:27
>>> 收件人:"赵军奎" <bernard@vivo.com>
>>> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
>>> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>>>> From: "Christian König" <christian.koenig@amd.com>
>>>>> Date: 2020-04-21 19:22:49
>>>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>>>> Cc:  opensource.kernel@vivo.com
>>>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>>>> 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?
>>>> 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.
>>
> 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.

> 2 There is no need to free the kzmalloc space(no possibility of memory leak )?

Correct, yes.

Regards,
Christian.

>
> Regards,
> Bernard
>
>>>> 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.
>>>>> Regards,
>>>>> Bernard
>>>>>
>>>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>>>> ---
>>>>>>>      drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>>>      1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> @@ -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;
>>>>>>>      }
>>>>>>>      
>>>>>>>      /**
>

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22  7:27               ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-22  7:27 UTC (permalink / raw)
  To: 赵军奎
  Cc: Tom St Denis, David (ChunMing) Zhou, Ori Messinger,
	opensource.kernel, David Airlie, linux-kernel, amd-gfx,
	dri-devel, Daniel Vetter, Alex Deucher, Sam Ravnborg

Am 22.04.20 um 02:56 schrieb 赵军奎:
> 发件人:"Christian König" <christian.koenig@amd.com>
> 发送日期:2020-04-21 22:53:47
> 收件人:"赵军奎" <bernard@vivo.com>
> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 15:39 schrieb 赵军奎:
>>> 发件人:"Christian König" <christian.koenig@amd.com>
>>> 发送日期:2020-04-21 21:02:27
>>> 收件人:"赵军奎" <bernard@vivo.com>
>>> 抄送人:Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org,opensource.kernel@vivo.com
>>> 主题:Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 14:09 schrieb 赵军奎:
>>>>> From: "Christian König" <christian.koenig@amd.com>
>>>>> Date: 2020-04-21 19:22:49
>>>>> To:  Bernard Zhao <bernard@vivo.com>,Alex Deucher <alexander.deucher@amd.com>,"David (ChunMing) Zhou" <David1.Zhou@amd.com>,David Airlie <airlied@linux.ie>,Daniel Vetter <daniel@ffwll.ch>,Tom St Denis <tom.stdenis@amd.com>,Ori Messinger <Ori.Messinger@amd.com>,Sam Ravnborg <sam@ravnborg.org>,amd-gfx@lists.freedesktop.org,dri-devel@lists.freedesktop.org,linux-kernel@vger.kernel.org
>>>>> Cc:  opensource.kernel@vivo.com
>>>>> Subject: Re: [PATCH] amdgpu: fixes memleak issue when init failed>Am 21.04.20 um 13:17 schrieb Bernard Zhao:
>>>>>>> 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?
>>>> 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.
>>
> 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.

> 2 There is no need to free the kzmalloc space(no possibility of memory leak )?

Correct, yes.

Regards,
Christian.

>
> Regards,
> Bernard
>
>>>> 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.
>>>>> Regards,
>>>>> Bernard
>>>>>
>>>>>>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>>>>>>> ---
>>>>>>>      drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
>>>>>>>      1 file changed, 19 insertions(+), 5 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> index 82a3299e53c0..4c5fb153e6b4 100644
>>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>>>>>>> @@ -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;
>>>>>>>      }
>>>>>>>      
>>>>>>>      /**
>

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-21 11:17 ` Bernard Zhao
  (?)
@ 2020-04-22 15:51   ` Ruhl, Michael J
  -1 siblings, 0 replies; 30+ messages in thread
From: Ruhl, Michael J @ 2020-04-22 15:51 UTC (permalink / raw)
  To: Bernard Zhao, Alex Deucher, Christian König,
	David (ChunMing) Zhou, David Airlie, Daniel Vetter, Tom St Denis,
	Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

>-----Original Message-----
>From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of
>Bernard Zhao
>Sent: Tuesday, April 21, 2020 7:17 AM
>To: Alex Deucher <alexander.deucher@amd.com>; Christian König
><christian.koenig@amd.com>; David (ChunMing) Zhou
><David1.Zhou@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter
><daniel@ffwll.ch>; Tom St Denis <tom.stdenis@amd.com>; Ori Messinger
><Ori.Messinger@amd.com>; Sam Ravnborg <sam@ravnborg.org>; Bernard
>Zhao <bernard@vivo.com>; amd-gfx@lists.freedesktop.org; dri-
>devel@lists.freedesktop.org; linux-kernel@vger.kernel.org
>Cc: opensource.kernel@vivo.com
>Subject: [PATCH] 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.
>
>Signed-off-by: Bernard Zhao <bernard@vivo.com>
>---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24
>++++++++++++++++----
> 1 file changed, 19 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>index 82a3299e53c0..4c5fb153e6b4 100644
>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>@@ -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);

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

> 	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;
> }
>
> /**
>--
>2.26.2
>
>_______________________________________________
>dri-devel mailing list
>dri-devel@lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22 15:51   ` Ruhl, Michael J
  0 siblings, 0 replies; 30+ messages in thread
From: Ruhl, Michael J @ 2020-04-22 15:51 UTC (permalink / raw)
  To: Bernard Zhao, Alex Deucher, Christian König,
	David (ChunMing) Zhou, David Airlie, Daniel Vetter, Tom St Denis,
	Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

>-----Original Message-----
>From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of
>Bernard Zhao
>Sent: Tuesday, April 21, 2020 7:17 AM
>To: Alex Deucher <alexander.deucher@amd.com>; Christian König
><christian.koenig@amd.com>; David (ChunMing) Zhou
><David1.Zhou@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter
><daniel@ffwll.ch>; Tom St Denis <tom.stdenis@amd.com>; Ori Messinger
><Ori.Messinger@amd.com>; Sam Ravnborg <sam@ravnborg.org>; Bernard
>Zhao <bernard@vivo.com>; amd-gfx@lists.freedesktop.org; dri-
>devel@lists.freedesktop.org; linux-kernel@vger.kernel.org
>Cc: opensource.kernel@vivo.com
>Subject: [PATCH] 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.
>
>Signed-off-by: Bernard Zhao <bernard@vivo.com>
>---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24
>++++++++++++++++----
> 1 file changed, 19 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>index 82a3299e53c0..4c5fb153e6b4 100644
>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>@@ -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);

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

> 	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;
> }
>
> /**
>--
>2.26.2
>
>_______________________________________________
>dri-devel mailing list
>dri-devel@lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22 15:51   ` Ruhl, Michael J
  0 siblings, 0 replies; 30+ messages in thread
From: Ruhl, Michael J @ 2020-04-22 15:51 UTC (permalink / raw)
  To: Bernard Zhao, Alex Deucher, Christian König,
	David (ChunMing) Zhou, David Airlie, Daniel Vetter, Tom St Denis,
	Ori Messinger, Sam Ravnborg, amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

>-----Original Message-----
>From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of
>Bernard Zhao
>Sent: Tuesday, April 21, 2020 7:17 AM
>To: Alex Deucher <alexander.deucher@amd.com>; Christian König
><christian.koenig@amd.com>; David (ChunMing) Zhou
><David1.Zhou@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter
><daniel@ffwll.ch>; Tom St Denis <tom.stdenis@amd.com>; Ori Messinger
><Ori.Messinger@amd.com>; Sam Ravnborg <sam@ravnborg.org>; Bernard
>Zhao <bernard@vivo.com>; amd-gfx@lists.freedesktop.org; dri-
>devel@lists.freedesktop.org; linux-kernel@vger.kernel.org
>Cc: opensource.kernel@vivo.com
>Subject: [PATCH] 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.
>
>Signed-off-by: Bernard Zhao <bernard@vivo.com>
>---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24
>++++++++++++++++----
> 1 file changed, 19 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>index 82a3299e53c0..4c5fb153e6b4 100644
>--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>@@ -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);

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

> 	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;
> }
>
> /**
>--
>2.26.2
>
>_______________________________________________
>dri-devel mailing list
>dri-devel@lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
  2020-04-22 15:51   ` Ruhl, Michael J
  (?)
@ 2020-04-22 18:28     ` Christian König
  -1 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-22 18:28 UTC (permalink / raw)
  To: Ruhl, Michael J, Bernard Zhao, Alex Deucher,
	Christian König, David (ChunMing) Zhou, David Airlie,
	Daniel Vetter, Tom St Denis, Ori Messinger, Sam Ravnborg,
	amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

Am 22.04.20 um 17:51 schrieb Ruhl, Michael J:
>> -----Original Message-----
>> From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of
>> Bernard Zhao
>> Sent: Tuesday, April 21, 2020 7:17 AM
>> To: Alex Deucher <alexander.deucher@amd.com>; Christian König
>> <christian.koenig@amd.com>; David (ChunMing) Zhou
>> <David1.Zhou@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter
>> <daniel@ffwll.ch>; Tom St Denis <tom.stdenis@amd.com>; Ori Messinger
>> <Ori.Messinger@amd.com>; Sam Ravnborg <sam@ravnborg.org>; Bernard
>> Zhao <bernard@vivo.com>; amd-gfx@lists.freedesktop.org; dri-
>> devel@lists.freedesktop.org; linux-kernel@vger.kernel.org
>> Cc: opensource.kernel@vivo.com
>> Subject: [PATCH] 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.
>>
>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24
>> ++++++++++++++++----
>> 1 file changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> index 82a3299e53c0..4c5fb153e6b4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> @@ -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);
> Have you looked at the DEVICE_ATTR mechanism?

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.

>
> 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
>
>> 	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;
>> }
>>
>> /**
>> --
>> 2.26.2
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22 18:28     ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-22 18:28 UTC (permalink / raw)
  To: Ruhl, Michael J, Bernard Zhao, Alex Deucher,
	Christian König, David (ChunMing) Zhou, David Airlie,
	Daniel Vetter, Tom St Denis, Ori Messinger, Sam Ravnborg,
	amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

Am 22.04.20 um 17:51 schrieb Ruhl, Michael J:
>> -----Original Message-----
>> From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of
>> Bernard Zhao
>> Sent: Tuesday, April 21, 2020 7:17 AM
>> To: Alex Deucher <alexander.deucher@amd.com>; Christian König
>> <christian.koenig@amd.com>; David (ChunMing) Zhou
>> <David1.Zhou@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter
>> <daniel@ffwll.ch>; Tom St Denis <tom.stdenis@amd.com>; Ori Messinger
>> <Ori.Messinger@amd.com>; Sam Ravnborg <sam@ravnborg.org>; Bernard
>> Zhao <bernard@vivo.com>; amd-gfx@lists.freedesktop.org; dri-
>> devel@lists.freedesktop.org; linux-kernel@vger.kernel.org
>> Cc: opensource.kernel@vivo.com
>> Subject: [PATCH] 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.
>>
>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24
>> ++++++++++++++++----
>> 1 file changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> index 82a3299e53c0..4c5fb153e6b4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> @@ -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);
> Have you looked at the DEVICE_ATTR mechanism?

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.

>
> 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
>
>> 	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;
>> }
>>
>> /**
>> --
>> 2.26.2
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-22 18:28     ` Christian König
  0 siblings, 0 replies; 30+ messages in thread
From: Christian König @ 2020-04-22 18:28 UTC (permalink / raw)
  To: Ruhl, Michael J, Bernard Zhao, Alex Deucher,
	Christian König, David (ChunMing) Zhou, David Airlie,
	Daniel Vetter, Tom St Denis, Ori Messinger, Sam Ravnborg,
	amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

Am 22.04.20 um 17:51 schrieb Ruhl, Michael J:
>> -----Original Message-----
>> From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of
>> Bernard Zhao
>> Sent: Tuesday, April 21, 2020 7:17 AM
>> To: Alex Deucher <alexander.deucher@amd.com>; Christian König
>> <christian.koenig@amd.com>; David (ChunMing) Zhou
>> <David1.Zhou@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter
>> <daniel@ffwll.ch>; Tom St Denis <tom.stdenis@amd.com>; Ori Messinger
>> <Ori.Messinger@amd.com>; Sam Ravnborg <sam@ravnborg.org>; Bernard
>> Zhao <bernard@vivo.com>; amd-gfx@lists.freedesktop.org; dri-
>> devel@lists.freedesktop.org; linux-kernel@vger.kernel.org
>> Cc: opensource.kernel@vivo.com
>> Subject: [PATCH] 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.
>>
>> Signed-off-by: Bernard Zhao <bernard@vivo.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24
>> ++++++++++++++++----
>> 1 file changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> index 82a3299e53c0..4c5fb153e6b4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> @@ -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);
> Have you looked at the DEVICE_ATTR mechanism?

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.

>
> 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
>
>> 	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;
>> }
>>
>> /**
>> --
>> 2.26.2
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2020-04-22 18:28 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21 11:17 [PATCH] amdgpu: fixes memleak issue when init failed Bernard Zhao
2020-04-21 11:17 ` Bernard Zhao
2020-04-21 11:17 ` Bernard Zhao
2020-04-21 11:22 ` Christian König
2020-04-21 11:22   ` Christian König
2020-04-21 11:22   ` Christian König
2020-04-21 12:09   ` 赵军奎
2020-04-21 12:09     ` 赵军奎
2020-04-21 12:09     ` 赵军奎
2020-04-21 13:02     ` Christian König
2020-04-21 13:02       ` Christian König
2020-04-21 13:02       ` Christian König
2020-04-21 13:39       ` 赵军奎
2020-04-21 13:39         ` 赵军奎
2020-04-21 13:39         ` 赵军奎
2020-04-21 14:53         ` Christian König
2020-04-21 14:53           ` Christian König
2020-04-21 14:53           ` Christian König
2020-04-22  0:56           ` 赵军奎
2020-04-22  0:56             ` 赵军奎
2020-04-22  0:56             ` 赵军奎
2020-04-22  7:27             ` Christian König
2020-04-22  7:27               ` Christian König
2020-04-22  7:27               ` Christian König
2020-04-22 15:51 ` Ruhl, Michael J
2020-04-22 15:51   ` Ruhl, Michael J
2020-04-22 15:51   ` Ruhl, Michael J
2020-04-22 18:28   ` Christian König
2020-04-22 18:28     ` Christian König
2020-04-22 18:28     ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.