drm/amdgpu: fix the memory corruption on S3
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: fix the memory corruption on S3
psp->cmd will be used on resume phase, so we can not free it on hw_init. Otherwise, a memory corruption will be triggered.
---
V1 -> V2:
- remove "cmd" variable.
- fix typo of check.
Alex, Christian,
This is the final fix for vega10 S3. The random memory corruption issue is root caused.
Thanks,
Ray
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +9 -8
@@ -330,14 +330,11 @@ static int psp_load_fw(struct amdgpu_device *adev) {int ret;struct psp_context *psp = &adev->psp; -struct psp_gfx_cmd_resp *cmd; - cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); -if (!cmd) + psp->cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); +if (!psp->cmd)return -ENOMEM ; - psp->cmd = cmd; - ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG, AMDGPU_GEM_DOMAIN_GTT, &psp->fw_pri_bo,
@@ -376,8 +373,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ; failed_mem:
@@ -387,7 +382,8 @@ static int psp_load_fw(struct amdgpu_device *adev)amdgpu_bo_free_kernel (&psp->fw_pri_bo, &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed: -kfree (cmd); +kfree (psp->cmd); + psp->cmd =NULL ;return ret; }
@@ -447,6 +443,11 @@ static int psp_hw_fini(void *handle)amdgpu_bo_free_kernel (&psp->fence_buf_bo, &psp->fence_buf_mc_addr, &psp->fence_buf); +if (psp->cmd) { +kfree (psp->cmd); + psp->cmd =NULL ; + } +return 0 ; }
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1498723761-6723-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Am 29.06.2017 um 10:09 schrieb Huang Rui:
Quoted 63 lines
psp->cmdwill be used on resume phase, so we can not free it onhw_init. Otherwise, a memory corruption will be triggered.Signed-off-by Huang Rui <[email protected]>---
V1 -> V2:
- remove "cmd" variable.
- fix typo of check.Alex, Christian,
This is the final fix for vega10 S3. The random memory corruption issue is root caused.
Thanks,
Ray--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-8@@ -330,14 +330,11 @@ static int psp_load_fw(struct amdgpu_device *adev) {int ret;struct psp_context *psp = &adev->psp; -struct psp_gfx_cmd_resp *cmd; - cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); -if (!cmd) + psp->cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); +if (!psp->cmd)return -ENOMEM ; - psp->cmd = cmd; - ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG, AMDGPU_GEM_DOMAIN_GTT, &psp->fw_pri_bo,@@ -376,8 +373,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ; failed_mem:@@ -387,7 +382,8 @@ static int psp_load_fw(struct amdgpu_device *adev)amdgpu_bo_free_kernel (&psp->fw_pri_bo, &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed: -kfree (cmd); +kfree (psp->cmd); + psp->cmd =NULL ;return ret; }
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 446
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-0@@ -447,6 +443,11 @@ static int psp_hw_fini(void *handle)amdgpu_bo_free_kernel (&psp->fence_buf_bo, &psp->fence_buf_mc_addr, &psp->fence_buf); +if (psp->cmd) {
As Michel noted as well please drop this extra check, kfree(NULL) is perfectly save.
With that fixed the patch is Reviewed-by: Christian König <[email protected]> for now, but I still think we could do better by only allocating the temporary command buffer when it is needed.
Regards,
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 453
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-0+kfree (psp->cmd); + psp->cmd =NULL ; + } +return 0 ; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 84d11f06-9c82-01a3-04f3-b3a4428b043b-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 70 lines · Christian König
Am 29.06.2017 um 10:09 schrieb Huang Rui:
Quoted 6 lines
psp->cmdwill be used on resume phase, so we can not free it onhw_init. Otherwise, a memory corruption will be triggered.Signed-off-by Huang Rui <[email protected]>---
Quoted 7 lines
V1 -> V2:
- remove "cmd" variable.
- fix typo of check.Alex, Christian,
This is the final fix for vega10 S3. The random memory corruption issue is
root
drivers/gpu/drm/amd/
Quoted 10 lines
caused.
Thanks,
Ray--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0
amdgpu/amdgpu_psp.cQuoted 40 lines
index 5bed483..711476792 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-8@@ -330,14 +330,11 @@ static int psp_load_fw(struct amdgpu_device *adev) {int ret;struct psp_context *psp = &adev->psp; -struct psp_gfx_cmd_resp *cmd; - cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); -if (!cmd) + psp->cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); +if (!psp->cmd)return -ENOMEM ; - psp->cmd = cmd; - ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG, AMDGPU_GEM_DOMAIN_GTT, &psp->fw_pri_bo,@@ -376,8 +373,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ; failed_mem:@@ -387,7 +382,8 @@ static int psp_load_fw(struct amdgpu_device *adev)amdgpu_bo_free_kernel (&psp->fw_pri_bo, &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed: -kfree (cmd); +kfree (psp->cmd); + psp->cmd =NULL ;return ret; }drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 444
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -447,6 +443,11 @@ static int psp_hw_fini(void *handle)amdgpu_bo_free_kernel (&psp->fence_buf_bo, &psp->fence_buf_mc_addr, &psp->
fence_buf);Quoted 1 line
Quoted 9 lines
Quoted 1 line
+ if (
psp->cmd) {As Michel noted as well please drop this extra check, kfree(NULL) is perfectly save.
With that fixed the patch is Reviewed-by: Christian König <[email protected]> for now, but I still think we could do better by only allocating the temporary command buffer when it is needed.
Thanks. This is the quick fix for release. You know, it was a tragedy till I found the root cause for S3 suspend/resume and make it stable, now it's able to enter S3 more than 30+ cycles and never crash.
I am planning to refine the psp codes, any suggestions are warm for me. I will refer the comments such as fence and "temporary command buffter" to modify it in following days. :-)
Thanks,
Ray
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Deucher, Alexander
Reviewed-by Alex DeucherQuoted 81 lines
-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, June 29, 2017 4:17 AM
To: Huang, Ray; [email protected]; Deucher, Alexander; Koenig, Christian
Cc: Huan, Alvin; Qiao, Joe(Markham); Jiang, Sonny; Wang, Ken; Yuan, Xiaojie
Subject: Re: [PATCH v2] drm/amdgpu: fix the memory corruption on S3Am 29.06.2017 um 10:09 schrieb Huang Rui:
Quoted 6 lines
psp->cmdwill be used on resume phase, so we can not free it onhw_init. Otherwise, a memory corruption will be triggered.Signed-off-by Huang Rui <[email protected]>---
Quoted 7 lines
V1 -> V2:
- remove "cmd" variable.
- fix typo of check.Alex, Christian,
This is the final fix for vega10 S3. The random memory corruption issue is
root
Review
Quoted 10 lines
caused.
Thanks,
Ray--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.cdrivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device
Quoted 4 lines
index 5bed483..711476792 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -330,14 +330,11 @@ static int psp_load_fw(struct amdgpu_device*adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2
-5{int ret;struct psp_context *psp = &adev->psp; -struct psp_gfx_cmd_resp *cmd; - cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); -if (!cmd) + psp->cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); +if (!psp->cmd)return -ENOMEM ; - psp->cmd = cmd; - ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG, AMDGPU_GEM_DOMAIN_GTT, &psp->fw_pri_bo,@@ -376,8 +373,6 @@ static int psp_load_fw(struct amdgpu_device*adev)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-2if (ret) goto failed_mem; -kfree (cmd); -return 0 ; failed_mem:@@ -387,7 +382,8 @@ static int psp_load_fw(struct amdgpu_device*adev)
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2
-1amdgpu_bo_free_kernel (&psp->fw_pri_bo, &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed: -kfree (cmd); +kfree (psp->cmd); + psp->cmd =NULL ;return ret; }@@ -447,6 +443,11 @@ static int psp_hw_fini(void *handle)amdgpu_bo_free_kernel (&psp->fence_buf_bo, &psp->fence_buf_mc_addr, &psp- fence_buf);
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 446
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-0+if (psp->cmd) {As Michel noted as well please drop this extra check, kfree(NULL) is perfectly save.
With that fixed the patch is Reviewed-by: Christian König <[email protected]> for now, but I still think we could do better by only allocating the temporary command buffer when it is needed.
Yes, nice find Ray! Glad to finally have this one solved! With the extra check fixed:
Quoted 4 lines
Regards,
Christian.
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 452
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-0+kfree (psp->cmd); + psp->cmd =NULL ; + } +return 0 ; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Yuan, Xiaojie
Tested-byRegards,
Xiaojie
________________________________
From: Huang Rui <[email protected]>
Sent: Thursday, June 29, 2017 4:09:21 PM
To: [email protected]; Deucher, Alexander; Koenig, Christian
Cc: Wang, Ken; Qiao, Joe(Markham); Jiang, Sonny; Huan, Alvin; Yuan, Xiaojie; Huang, Ray
Subject: [PATCH v2] drm/amdgpu: fix the memory corruption on S3
psp->cmd will be used on resume phase, so we can not free it on hw_init. Otherwise, a memory corruption will be triggered.
---
V1 -> V2:
- remove "cmd" variable.
- fix typo of check.
Alex, Christian,
This is the final fix for vega10 S3. The random memory corruption issue is root caused.
Thanks,
Ray
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +9 -8
@@ -330,14 +330,11 @@ static int psp_load_fw(struct amdgpu_device *adev) {int ret;struct psp_context *psp = &adev->psp; -struct psp_gfx_cmd_resp *cmd; - cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); -if (!cmd) + psp->cmd =kzalloc (sizeof (struct psp_gfx_cmd_resp ),GFP_KERNEL ); +if (!psp->cmd)return -ENOMEM ; - psp->cmd = cmd; - ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG, AMDGPU_GEM_DOMAIN_GTT, &psp->fw_pri_bo,
@@ -376,8 +373,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ; failed_mem:
@@ -387,7 +382,8 @@ static int psp_load_fw(struct amdgpu_device *adev)amdgpu_bo_free_kernel (&psp->fw_pri_bo, &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed: -kfree (cmd); +kfree (psp->cmd); + psp->cmd =NULL ;return ret; }
@@ -447,6 +443,11 @@ static int psp_hw_fini(void *handle)amdgpu_bo_free_kernel (&psp->fence_buf_bo, &psp->fence_buf_mc_addr, &psp->fence_buf); +if (psp->cmd) { +kfree (psp->cmd); + psp->cmd =NULL ; + } +return 0 ; }
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx