drm/amd: Fix more cases of NULL pointer deref at fini
Subsystems (2)
PATCH 1/2 drm/amd: Fix more cases of NULL pointer deref at fini
I found more case that a NULL version causes problems. Add NULL checks as applicable.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
@@ -3463,6 +3463,9 @@ static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int r; +if (!ip_block->version) +return ; +if (!ip_block->version->funcs->hw_fini) {dev_err (adev->dev,"hw_fini of IP block <%s> not defined\n" , ip_block->version->funcs->name);
@@ -3496,6 +3499,8 @@ static void amdgpu_device_smu_fini_early(struct amdgpu_device *adev)for (i =0 ; i < adev->num_ip_blocks; i++) {if (!adev->ip_blocks[i].status.hw)continue ; +if (!adev->ip_blocks[i].version) +continue ;if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_SMC ) {amdgpu_ip_block_hw_fini (&adev->ip_blocks[i]);break ;
Signature · 1 line
2.53.0
PATCH 2/2 drm/amd: Make sure asic_funcs is set in amdgpu_device_ip_fini_early()
If asic_funcs isn't set then the GPU doesn't cleanly clean up when an IP block is missing.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -1
@@ -3554,7 +3554,8 @@ static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev)* in the APU is to trigger a GPU reset, but this should be done during * the unload phase to avoid adding boot latency and screen flicker. */ -if ((adev->flags &AMD_IS_APU ) && !adev->gmc.is_app_apu) { +if ((adev->flags &AMD_IS_APU ) && !adev->gmc.is_app_apu && + adev->asic_funcs) { r =amdgpu_asic_reset (adev);if (r)dev_err (adev->dev,"asic reset on %s failed\n" , __func__);
Signature · 1 line
2.53.0
Quoted 14 lines · Mario Limonciello
I found more case that a NULL version causes problems. Add NULL checks as applicable.
Fixes 39fc2bc4da00 ("drm/amdgpu: Protect GPU register accesses in powergated state in some paths")Signed-off-by Mario Limonciello <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block) · line 3468
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3463,6 +3463,9 @@ static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int r; +if (!ip_block->version) +return ; +
ip block versions are set during discovery phase itself. This is a very early init failure and ideally the fix should be not to call any fini for such an early failure.
Thanks,
Lijo
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0if (!ip_block->version->funcs->hw_fini) {dev_err (adev->dev,"hw_fini of IP block <%s> not defined\n" , ip_block->version->funcs->name);@@ -3496,6 +3499,8 @@ static void amdgpu_device_smu_fini_early(struct amdgpu_device *adev)for (i =0 ; i < adev->num_ip_blocks; i++) {if (!adev->ip_blocks[i].status.hw)continue ; +if (!adev->ip_blocks[i].version) +continue ;if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_SMC ) {amdgpu_ip_block_hw_fini (&adev->ip_blocks[i]);break ;
Quoted 12 lines · Lijo
Quoted 9 lines · Mario Limonciello
I found more case that a NULL version causes problems. Add NULL checks as applicable.
Fixes 39fc2bc4da00 ("drm/amdgpu: Protect GPU register accesses in powergated state in some paths")Signed-off-by Mario Limonciello <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 5 +++++1 file changed, 5 insertions(+)
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_ip_block_hw_fini(struct · line 3468
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3463,6 +3463,9 @@ static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int r; + if (!ip_block->version) + return; +ip block versions are set during discovery phase itself. This is a very early init failure
Yes; this case is NPI system that not all blocks are in discovery yet. System panics at bootup with NULL ptr deref in multiple places instead of a clean recovery and keep fbdev. This patch series sorts it out.
Quoted 1 line
and ideally the fix should be not to call any fini for such an early failure.
As an alternative to this series?
Quoted 18 lines
Thanks,
LijoQuoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0if (!ip_block->version->funcs->hw_fini) { dev_err(adev->dev, "hw_fini of IP block <%s> not defined\n", ip_block->version->funcs->name);@@ -3496,6 +3499,8 @@ static void amdgpu_device_smu_fini_early(struct amdgpu_device *adev) for (i = 0; i < adev->num_ip_blocks; i++) { if (!adev->ip_blocks[i].status.hw) continue; + if (!adev->ip_blocks[i].version) + continue; if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) { amdgpu_ip_block_hw_fini(&adev->ip_blocks[i]);break;
Quoted 29 lines · Mario Limonciello
Quoted 12 lines · Lijo
Quoted 9 lines · Mario Limonciello
I found more case that a NULL version causes problems. Add NULL checks as applicable.
Fixes 39fc2bc4da00 ("drm/amdgpu: Protect GPU register accesses in powergated state in some paths")Signed-off-by Mario Limonciello <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 5 +++++1 file changed, 5 insertions(+)Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_ip_block_hw_fini(struct · line 3468
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3463,6 +3463,9 @@ static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int r; + if (!ip_block->version) + return; +ip block versions are set during discovery phase itself. This is a very early init failure
Quoted 2 lines
Yes; this case is NPI system that not all blocks are in discovery yet. System panics at bootup with NULL ptr deref in multiple places instead of a clean recovery and keep fbdev. This patch series sorts it out.
Blocks not in discovery shouldn't be added to ip list or should be added differently.
Quoted 4 lines
Quoted 1 line
and ideally the fix should be not to call any fini for such an early failure.
As an alternative to this series?
Yes, if it's a failure as early as in discovery stage, probably we should skip amdgpu_device_fini_hw altogether.
Thanks,
Lijo
Quoted 19 lines
Quoted 18 lines
Thanks,
LijoQuoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0if (!ip_block->version->funcs->hw_fini) { dev_err(adev->dev, "hw_fini of IP block <%s> not defined\n", ip_block->version->funcs->name);@@ -3496,6 +3499,8 @@ static void amdgpu_device_smu_fini_early(struct amdgpu_device *adev) for (i = 0; i < adev->num_ip_blocks; i++) { if (!adev->ip_blocks[i].status.hw) continue; + if (!adev->ip_blocks[i].version) + continue; if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) { amdgpu_ip_block_hw_fini(&adev->ip_blocks[i]);break;
Quoted 35 lines · Lijo
Quoted 29 lines · Mario Limonciello
Quoted 12 lines · Lijo
Quoted 9 lines · Mario Limonciello
I found more case that a NULL version causes problems. Add NULL checks as applicable.
Fixes 39fc2bc4da00 ("drm/amdgpu: Protect GPU register accesses in powergated state in some paths")Signed-off-by Mario Limonciello <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 5 +++++1 file changed, 5 insertions(+)Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_ip_block_hw_fini(struct · line 3468
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3463,6 +3463,9 @@ static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int r; + if (!ip_block->version) + return; +ip block versions are set during discovery phase itself. This is a very early init failure
Quoted 2 lines
Yes; this case is NPI system that not all blocks are in discovery yet. System panics at bootup with NULL ptr deref in multiple places instead of a clean recovery and keep fbdev. This patch series sorts it out.
Quoted 8 lines
Blocks not in discovery shouldn't be added to ip list or should be added differently.
Quoted 4 lines
Quoted 1 line
and ideally the fix should be not to call any fini for such an early failure.
As an alternative to this series?
Yes, if it's a failure as early as in discovery stage, probably we should skip
amdgpu_device_fini_hwaltogether.
I experimented some more and feel that the solution I came up with is correct. There are valid versions of everything at this time (the failed IP block isn't there at that time).
So how would you know to skip fini? I guess check asic_funcs not to be NULL?
But then it's the same as the second commit is doing already.
Quoted 24 lines
Thanks,
LijoQuoted 19 lines
Quoted 18 lines
Thanks,
LijoQuoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0if (!ip_block->version->funcs->hw_fini) { dev_err(adev->dev, "hw_fini of IP block <%s> not defined\n", ip_block->version->funcs->name);@@ -3496,6 +3499,8 @@ static void amdgpu_device_smu_fini_early(struct amdgpu_device *adev) for (i = 0; i < adev->num_ip_blocks; i++) { if (!adev->ip_blocks[i].status.hw) continue; + if (!adev->ip_blocks[i].version) + continue; if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) { amdgpu_ip_block_hw_fini(&adev->ip_blocks[i]);break;
Quoted 40 lines · Mario Limonciello
Quoted 37 lines · Lijo
Quoted 29 lines · Mario Limonciello
Quoted 12 lines · Lijo
Quoted 9 lines · Mario Limonciello
I found more case that a NULL version causes problems. Add NULL checks as applicable.
Fixes 39fc2bc4da00 ("drm/amdgpu: Protect GPU register accesses in powergated state in some paths")Signed-off-by Mario Limonciello <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 5 +++++1 file changed, 5 insertions(+)Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_ip_block_hw_fini(struct · line 3468
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0@@ -3463,6 +3463,9 @@ static void amdgpu_ip_block_hw_fini(struct amdgpu_ip_block *ip_block) struct amdgpu_device *adev = ip_block->adev; int r; + if (!ip_block->version) + return; +ip block versions are set during discovery phase itself. This is a very early init failure
Quoted 2 lines
Yes; this case is NPI system that not all blocks are in discovery yet. System panics at bootup with NULL ptr deref in multiple places instead of a clean recovery and keep fbdev. This patch series sorts it out.
Blocks not in discovery shouldn't be added to ip list or should be added differently.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
and ideally the fix should be not to call any fini for such an early failure.
As an alternative to this series?
Yes, if it's a failure as early as in discovery stage, probably we should skip
amdgpu_device_fini_hwaltogether.I experimented some more and feel that the solution I came up with is correct. There are valid versions of everything at this time (the failed IP block isn't there at that time).
My understanding of the situation is this is any early exit since driver doesn't recognize one IP block and hence cannot assign corresponding version functions. Without discovery mechanism, the equivalent case is driver not detecting the device id. In both cases, there shouldn't be any need to run through sw/hw fini sequences of ip block.
Quoted 2 lines
So how would you know to skip fini? I guess check
asic_funcsnot to be NULL?
One way is to undo the effect of set_ip_block within discovery itself. For ex: if there is discovery error, call amdgpu_ip_block_clear() or similar and remove any added ip blocks. num_ip_blocks will then be 0 and in such cases don't run through any unwind sequence (that shouldn't really be needed then). That is the same case if driver is not able detect a valid discovery binary blob also.
Thanks,
Lijo
Quoted 27 lines
But then it's the same as the second commit is doing already.
Quoted 24 lines
Thanks,
LijoQuoted 19 lines
Quoted 18 lines
Thanks,
LijoQuoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0if (!ip_block->version->funcs->hw_fini) { dev_err(adev->dev, "hw_fini of IP block <%s> not defined\n", ip_block->version->funcs->name);@@ -3496,6 +3499,8 @@ static void amdgpu_device_smu_fini_early(struct amdgpu_device *adev) for (i = 0; i < adev->num_ip_blocks; i++) { if (!adev->ip_blocks[i].status.hw) continue; + if (!adev->ip_blocks[i].version) + continue; if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) { amdgpu_ip_block_hw_fini(&adev->ip_blocks[i]);break;