Skip to contentSkip to conversation

amdgpu: Fix crash when MEC2 firmware fails to load

PATCH Superseded David McFarland 2 participants 7 messages Jan 29, 2024 – Jan 30, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover amdgpu: Fix crash when MEC2 firmware fails to load

I only noticed this because my distro broke the mec2.bin symbolic link, so the firmware failed to load. This resulted in:

amdgpu 0000:0b:00.0: Direct firmware load for amdgpu/navi10_mec2.bin failed with error -2

BUG: kernel NULL pointer dereference, address: 0000000000000008
[...]
Call Trace:
 <TASK>
 ? __die+0x23/0x70
 ? page_fault_oops+0x17d/0x4b0
 ? srso_alias_return_thunk+0x5/0xfbef5
 ? exc_page_fault+0x72/0x160
 ? asm_exc_page_fault+0x26/0x30
 ? request_firmware+0x48/0x60 [firmware_class]
 ? amdgpu_gfx_cp_init_microcode+0x22e/0x260 [amdgpu]
 gfx_v10_0_early_init+0x722/0x8d0 [amdgpu]

The attached patch removes some code that looks like it was added by mistake, or by a bad merge. With it I get still get the load failed error as expected, but no crash. After fixing the firmware, no error is printed.

David McFarland (1):
drm/amd: Don't init MEC2 firmware when it fails to load

 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 --
 1 file changed, 2 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/1 drm/amd: Don't init MEC2 firmware when it fails to load

The same calls are made directly above, but conditional on the firmware loading and validating successfully.

Fixes 9931b67690cf ("drm/amd: Load GFX10 microcode during early_init")
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -2
index d63cab294883..b0ba68016a02 100644
@@ -4022,18 +4022,16 @@ static int gfx_v10_0_init_microcode(struct amdgpu_device *adev)
 	err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw, fw_name);
 	if (!err) {
 		amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
 		amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
 	} else {
 		err = 0;
 		adev->gfx.mec2_fw = NULL;
 	}
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
 
 	gfx_v10_0_check_fw_write_wait(adev);
 out:
 	if (err) {
 		amdgpu_ucode_release(&adev->gfx.pfp_fw);
 		amdgpu_ucode_release(&adev->gfx.me_fw);
 		amdgpu_ucode_release(&adev->gfx.ce_fw);
 		amdgpu_ucode_release(&adev->gfx.rlc_fw);
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH 1/1] drm/amd: Don't init MEC2 firmware when it fails to load

Quoted 4 lines · David McFarland

The same calls are made directly above, but conditional on the firmware loading and validating successfully.

Fixes 9931b67690cf ("drm/amd: Load GFX10 microcode during early_init")

This is a great find, thank you for the fix. I'll apply it to our tree and Alex should send it in a future fixes PR.

Quoted 27 lines
---
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 --
  1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -2
index d63cab294883..b0ba68016a02 100644
@@ -4022,18 +4022,16 @@ static int gfx_v10_0_init_microcode(struct amdgpu_device *adev)
  	err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw, fw_name);
  	if (!err) {
  		amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
  		amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
  	} else {
  		err = 0;
  		adev->gfx.mec2_fw = NULL;
  	}
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
 
  	gfx_v10_0_check_fw_write_wait(adev);
  out:
  	if (err) {
  		amdgpu_ucode_release(&adev->gfx.pfp_fw);
  		amdgpu_ucode_release(&adev->gfx.me_fw);
  		amdgpu_ucode_release(&adev->gfx.ce_fw);
  		amdgpu_ucode_release(&adev->gfx.rlc_fw);
#3 lore raw

Re: [PATCH 1/1] drm/amd: Don't init MEC2 firmware when it fails to load

Quoted 9 lines · Mario Limonciello
Quoted 4 lines · David McFarland

The same calls are made directly above, but conditional on the firmware loading and validating successfully.

Fixes 9931b67690cf ("drm/amd: Load GFX10 microcode during early_init")

This is a great find, thank you for the fix.  I'll apply it to our tree and Alex should send it in a future fixes PR.

Sorry to be pedantic; but I realized after I tried to apply this is missing a S-o-b. Can you please add one?

Quoted 29 lines
Quoted 28 lines

---
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 --

  1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -2
index d63cab294883..b0ba68016a02 100644
@@ -4022,18 +4022,16 @@ static int gfx_v10_0_init_microcode(struct 
 amdgpu_device *adev)
       err = amdgpu_ucode_request(adev, &adev->gfx.mec2_fw, fw_name);
       if (!err) {
           amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
           amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
       } else {
           err = 0;
           adev->gfx.mec2_fw = NULL;
       }
-    amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
-    amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
       gfx_v10_0_check_fw_write_wait(adev);

  out:
      if (err) { amdgpu_ucode_release(&adev->gfx.pfp_fw); amdgpu_ucode_release(&adev->gfx.me_fw); amdgpu_ucode_release(&adev->gfx.ce_fw); amdgpu_ucode_release(&adev->gfx.rlc_fw);

Reviewed-by on v2 1/1
#5 lore raw

Re: [PATCH v2 1/1] drm/amd: Don't init MEC2 firmware when it fails to load

In reply to David McFarland
Quoted 7 lines · David McFarland

The same calls are made directly above, but conditional on the firmware loading and validating successfully.

Fixes 9931b67690cf ("drm/amd: Load GFX10 microcode during early_init")

---
v2: signed off

Thanks.

And I'll apply this now.

Quoted 17 lines
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 --
  1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -2
index d63cab294883..b0ba68016a02 100644
@@ -4027,8 +4027,6 @@ static int gfx_v10_0_init_microcode(struct amdgpu_device *adev)
  		err = 0;
  		adev->gfx.mec2_fw = NULL;
  	}
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
 
  	gfx_v10_0_check_fw_write_wait(adev);
  out:
#4 lore raw

PATCH v2 1/1 drm/amd: Don't init MEC2 firmware when it fails to load

In reply to Mario Limonciello

The same calls are made directly above, but conditional on the firmware loading and validating successfully.

Fixes 9931b67690cf ("drm/amd: Load GFX10 microcode during early_init")

---
v2: signed off

 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0 -2
index d63cab294883..b0ba68016a02 100644
@@ -4027,8 +4027,6 @@ static int gfx_v10_0_init_microcode(struct amdgpu_device *adev)
 		err = 0;
 		adev->gfx.mec2_fw = NULL;
 	}
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2);
-	amdgpu_gfx_cp_init_microcode(adev, AMDGPU_UCODE_ID_CP_MEC2_JT);
 
 	gfx_v10_0_check_fw_write_wait(adev);
 out:
Signature · 1 line
2.40.1
#6 lore raw

v2 cover drm/amd: Don't init MEC2 firmware when it fails to load

In reply to Mario Limonciello
Quoted 2 lines

Sorry to be pedantic; but I realized after I tried to apply this is missing a S-o-b. Can you please add one?

Of course, here you go. I left it off because I wasn't 100% sure about the intention of your previous change.

David McFarland (1):
drm/amd: Don't init MEC2 firmware when it fails to load

 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 --
 1 file changed, 2 deletions(-)
Signature · 1 line
2.40.1