drm/amdgpu: fix the memory corruption on S3
Subsystems (2)
PATCH 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.
---
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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +6 -2
@@ -372,8 +372,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ; failed_mem:
@@ -384,6 +382,7 @@ static int psp_load_fw(struct amdgpu_device *adev) &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed:kfree (cmd); + cmd =NULL ;return ret; }
@@ -443,6 +442,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): 1498719798-8435-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Quoted 23 lines · Huang Rui
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]>---
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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 375
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-2@@ -372,8 +372,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ;
This looks like a good catch.
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 385
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-0@@ -384,6 +382,7 @@ static int psp_load_fw(struct amdgpu_device *adev) &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed:kfree (cmd); + cmd =NULL ;
This should probably be
psp->cmd = NULL;
instead?
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 448
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-0@@ -443,6 +442,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 ; + }
This should probably be
if (psp->cmd) {? If so, you could skip the if altogether, since kfree(NULL) is safe.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ 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): 86b9418d-450e-9101-517d-8d1ae7c8b358-otUistvHUpPR7s880joybQ@public.gmane.org
Quoted 44 lines · Michel Dänzer
Quoted 9 lines · Huang Rui
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]>---
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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0
amdgpu/amdgpu_psp.cdrivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 375
Quoted 10 lines
index 5041073..fcdd542 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-2@@ -372,8 +372,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ;This looks like a good catch.
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 385
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-0@@ -384,6 +382,7 @@ static int psp_load_fw(struct amdgpu_device *adev) &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed:kfree (cmd); + cmd =NULL ;This should probably be
Quoted 4 lines
psp->cmd = NULL;instead?
Actually, we set psp->cmd = cmd before.
But anyway, we needn't "cmd" member any more.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 443
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -443,6 +442,11 @@ static int psp_hw_fini(void *handle)amdgpu_bo_free_kernel (&psp->fence_buf_bo, &psp->fence_buf_mc_addr, &psp->
fence_buf);drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 448
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-0+if (!psp->cmd) { +kfree (psp->cmd); + psp->cmd =NULL ; + }
Quoted 5 lines
This should probably be
if (psp->cmd) {? If so, you could skip the if altogether, since kfree(NULL) is safe.
Nice catch. My typo. ;-)
You're right. Will update it in V2.
Thanks,
Rui
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Indeed a nice catch.
Just skimming over the PSP code, wouldn't it be simpler to temporary allocate the cmd buffer in psp_np_fw_load()?
Doesn't looks like that is used outside that function. Might even be possible to just allocate the buffer on the stack.
Regards,
Christian.
Am 29.06.2017 um 09:59 schrieb Huang Rui:
Quoted 63 lines · Michel Dänzer
Quoted 42 lines · Huang Rui
Quoted 9 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]>---
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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0
amdgpu/amdgpu_psp.cdrivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 375
Quoted 10 lines
index 5041073..fcdd542 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-2@@ -372,8 +372,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ;This looks like a good catch.
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 385
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-0@@ -384,6 +382,7 @@ static int psp_load_fw(struct amdgpu_device *adev) &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed:kfree (cmd); + cmd =NULL ;This should probably be
Quoted 4 lines
psp->cmd = NULL;instead?
Actually, we set
psp->cmd= cmd before.But anyway, we needn't "cmd" member any more.
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 443
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0@@ -443,6 +442,11 @@ static int psp_hw_fini(void *handle)amdgpu_bo_free_kernel (&psp->fence_buf_bo, &psp->fence_buf_mc_addr, &psp->
fence_buf);drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_hw_fini(void *handle) · line 448
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-0+if (!psp->cmd) { +kfree (psp->cmd); + psp->cmd =NULL ; + }This should probably be
if (psp->cmd) {
Quoted 7 lines
Quoted 1 line
? If so, you could skip the if altogether, since kfree(NULL) is safe.
Nice catch. My typo. ;-)
You're right. Will update it in V2.
Thanks,
Rui
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 45 lines · Huang Rui
Quoted 44 lines · Michel Dänzer
Quoted 9 lines · Huang Rui
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]>---
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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0
amdgpu/amdgpu_psp.cdrivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 375
Quoted 10 lines
index 5041073..fcdd542 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-2@@ -372,8 +372,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ;This looks like a good catch.
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 385
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-0@@ -384,6 +382,7 @@ static int psp_load_fw(struct amdgpu_device *adev) &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed:kfree (cmd); + cmd =NULL ;This should probably be
Quoted 8 lines
Quoted 4 lines
psp->cmd = NULL;instead?
Actually, we set
psp->cmd= cmd before.But anyway, we needn't "cmd" member any more.
You should probably still set psp->cmd = NULL here, otherwise psp->cmd still contains the pointer to the memory that is freed here, which could result in use-after-free somewhere else.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ 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): d86cec19-7927-c29e-d2fb-fdaf589e3369-otUistvHUpPR7s880joybQ@public.gmane.org
Quoted 51 lines · Michel Dänzer
Quoted 50 lines · Huang Rui
Quoted 48 lines · Michel Dänzer
Quoted 9 lines · Huang Rui
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]>---
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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/ renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-0
amdgpu/amdgpu_psp.cdrivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 375
Quoted 10 lines
index 5041073..fcdd542 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0
-2@@ -372,8 +372,6 @@ static int psp_load_fw(struct amdgpu_device *adev)if (ret) goto failed_mem; -kfree (cmd); -return 0 ;This looks like a good catch.
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static int psp_load_fw(struct amdgpu_device *adev) · line 385
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1
-0@@ -384,6 +382,7 @@ static int psp_load_fw(struct amdgpu_device *adev) &psp->fw_pri_mc_addr, &psp->fw_pri_buf); failed:kfree (cmd); + cmd =NULL ;This should probably be
psp->cmd = NULL;instead?
Quoted 8 lines
Quoted 3 lines
Actually, we set
psp->cmd= cmd before.But anyway, we needn't "cmd" member any more.
You should probably still set
psp->cmd= NULL here, otherwisepsp->cmdstill contains the pointer to the memory that is freed here, which could result in use-after-free somewhere else.
Right, I already found it and update it in V2, please take a look.
Thanks,
Ray
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx