Skip to contentSkip to conversation

drm/amdgpu: Call amdgpu_device_unmap_mmio() if device is unplugged to prevent crash in GPU initialization failure

PATCH In review Leslie Shi 4 participants 5 messages Dec 17, 2021 – Dec 23, 2021 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Leslie Shi

author
#0 lore raw

PATCH v3 1/1 drm/amdgpu: Call amdgpu_device_unmap_mmio() if device is unplugged to prevent crash in GPU initialization failure

[Why]
In amdgpu_driver_load_kms, when amdgpu_device_init returns error during driver modprobe, it will start the error handle path immediately and call into amdgpu_device_unmap_mmio as well to release mapped VRAM. However, in the following release callback, driver stills visits the unmapped memory like vcn.inst[i].fw_shared_cpu_addr in vcn_v3_0_sw_fini. So a kernel crash occurs.

[How]
call amdgpu_device_unmap_mmio() if device is unplugged to prevent invalid memory address in vcn_v3_0_sw_fini() when GPU initialization failure.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
index f31caec669e7..f6a47b927cfd 100644
@@ -3899,7 +3899,9 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
 
 	amdgpu_gart_dummy_page_fini(adev);
 
-	amdgpu_device_unmap_mmio(adev);
+	if (drm_dev_is_unplugged(adev_to_drm(adev)))
+		amdgpu_device_unmap_mmio(adev);
+
 }
 
 void amdgpu_device_fini_sw(struct amdgpu_device *adev)
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw

[Public]

Regards,
Guchun

-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Friday, December 17, 2021 10:26 AM
To: Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Cc: Chen, Guchun <[email protected]>; Shi, Leslie <[email protected]>
Subject: [PATCH v3] drm/amdgpu: Call amdgpu_device_unmap_mmio() if device is unplugged to prevent crash in GPU initialization failure

[Why]
In amdgpu_driver_load_kms, when amdgpu_device_init returns error during driver modprobe, it will start the error handle path immediately and call into amdgpu_device_unmap_mmio as well to release mapped VRAM. However, in the following release callback, driver stills visits the unmapped memory like vcn.inst[i].fw_shared_cpu_addr in vcn_v3_0_sw_fini. So a kernel crash occurs.

[How]
call amdgpu_device_unmap_mmio() if device is unplugged to prevent invalid memory address in vcn_v3_0_sw_fini() when GPU initialization failure.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
index f31caec669e7..f6a47b927cfd 100644
@@ -3899,7 +3899,9 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
 
 	amdgpu_gart_dummy_page_fini(adev);
 
-	amdgpu_device_unmap_mmio(adev);
+	if (drm_dev_is_unplugged(adev_to_drm(adev)))
+		amdgpu_device_unmap_mmio(adev);
+
 }
 
 void amdgpu_device_fini_sw(struct amdgpu_device *adev)

--
2.25.1

maintainer Acked-by on v3 1/1
#2 lore raw
In reply to Leslie Shi

Am 17.12.21 um 03:26 schrieb Leslie Shi:

Quoted 11 lines

[Why]
In amdgpu_driver_load_kms, when amdgpu_device_init returns error during driver modprobe, it will start the error handle path immediately and call into amdgpu_device_unmap_mmio as well to release mapped VRAM. However, in the following release callback, driver stills visits the unmapped memory like vcn.inst[i].fw_shared_cpu_addr in vcn_v3_0_sw_fini. So a kernel crash occurs.

[How]
call amdgpu_device_unmap_mmio() if device is unplugged to prevent invalid memory address in vcn_v3_0_sw_fini() when GPU initialization failure.

Looks sane to me, but Andrey should probably nood as well.

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
index f31caec669e7..f6a47b927cfd 100644
@@ -3899,7 +3899,9 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)
 
  	amdgpu_gart_dummy_page_fini(adev);
 
-	amdgpu_device_unmap_mmio(adev);
+	if (drm_dev_is_unplugged(adev_to_drm(adev)))
+		amdgpu_device_unmap_mmio(adev);
+
  }
 
  void amdgpu_device_fini_sw(struct amdgpu_device *adev)
Reviewed-by
#3 lore raw

Andrey

Quoted 35 lines · Christian König

Am 17.12.21 um 03:26 schrieb Leslie Shi:

Quoted 11 lines

[Why]
In amdgpu_driver_load_kms, when amdgpu_device_init returns error during driver modprobe, it will start the error handle path immediately and call into amdgpu_device_unmap_mmio as well to release mapped VRAM. However, in the following release callback, driver stills visits the unmapped memory like vcn.inst[i].fw_shared_cpu_addr in vcn_v3_0_sw_fini. So a kernel crash occurs.

[How]
call amdgpu_device_unmap_mmio() if device is unplugged to prevent invalid memory address in vcn_v3_0_sw_fini() when GPU initialization failure.

Looks sane to me, but Andrey should probably nood as well.

Quoted 17 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
index f31caec669e7..f6a47b927cfd 100644
@@ -3899,7 +3899,9 @@ void amdgpu_device_fini_hw(struct amdgpu_device 
 *adev)
         amdgpu_gart_dummy_page_fini(adev);
   -    amdgpu_device_unmap_mmio(adev);
+    if (drm_dev_is_unplugged(adev_to_drm(adev)))
+        amdgpu_device_unmap_mmio(adev);
+
   }
     void amdgpu_device_fini_sw(struct amdgpu_device *adev)

A message that is not in the archive (sent off-list or not yet received): DM6PR12MB39302C239EB5DBBF5EF30F7B97789@DM6PR12MB3930.namprd12.prod.outlook.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): DM6PR12MB39306C1F1EF550E0AB0872D6977E9@DM6PR12MB3930.namprd12.prod.outlook.com

#7 lore raw

Adding back public list and Leslie specifically.

Lijo is right and it's not MTTR release only, also all the unmaps in amdgpu_device_unmap_mmio since this patch makes call to amdgpu_device_unmap_mmio conditioned on device unplugged we need then to still take care of unmapping even when device is NOT unplugged - for this i suggest to look at 'drm/amdgpu: Unmap all MMIO mappings' and just conditionally call all the deleted unmaps in the patch where the condition is 'if (drm_dev_enter(dev))'.

Andrey

Quoted 85 lines · Lijo

[AMD Official Use Only]

Actually, I was asking specifically about this -

gmc_v9_0_sw_init -> amdgpu_bo_init-> adev->gmc.vram_mtrr = arch_phys_wc_add(adev->gmc.aper_base,

                                 adev->gmc.aper_size);

As per this patch, if the driver load failed due to some error which happens during hw_init(), this action is not undone. I was thinking why it's not considered important to skip this on driver failure to load. For ex: when some MTRR register is reserved for this mapping.

Thanks,
Lijo

-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Friday, December 17, 2021 9:05 PM
To: Lazar, Lijo <[email protected]>
Subject: Re: [PATCH v3] drm/amdgpu: Call amdgpu_device_unmap_mmio() if device is unplugged to prevent crash in GPU initialization failure

We do unmap on unload, this function is a collection of all MMIO unmapps we already do on unload, it's just does them early on in case of device hot removal. Before pci_driver.remove callback (amdgpu_pci_remove) finish execution.

Andrey

Quoted 61 lines · Lijo

[AMD Official Use Only]

As a side note, even if it's a failed driver load, why it is not important to undo the mappings created during driver load? I'm wondering what is the impact on a system like MI200 A+A.

Thanks,
Lijo

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrey Grodzovsky
Sent: Friday, December 17, 2021 8:32 PM
To: Koenig, Christian <[email protected]>; Shi, Leslie <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Cc: Chen, Guchun <[email protected]>
Subject: Re: [PATCH v3] drm/amdgpu: Call amdgpu_device_unmap_mmio() if device is unplugged to prevent crash in GPU initialization failure

Andrey

Quoted 38 lines · Christian König

Am 17.12.21 um 03:26 schrieb Leslie Shi:

Quoted 8 lines

[Why]
In amdgpu_driver_load_kms, when amdgpu_device_init returns error during driver modprobe, it will start the error handle path immediately and call into amdgpu_device_unmap_mmio as well to release mapped VRAM. However, in the following release callback, driver stills visits the unmapped memory like vcn.inst[i].fw_shared_cpu_addr in vcn_v3_0_sw_fini. So a kernel crash occurs.

Quoted 6 lines

[How]
call amdgpu_device_unmap_mmio() if device is unplugged to prevent invalid memory address in
vcn_v3_0_sw_fini() when GPU initialization failure.

Looks sane to me, but Andrey should probably nood as well.

Quoted 19 lines
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index f31caec669e7..f6a47b927cfd 100644
@@ -3899,7 +3899,9 @@ void amdgpu_device_fini_hw(struct

amdgpu_device
*adev)
        amdgpu_gart_dummy_page_fini(adev);
  -    amdgpu_device_unmap_mmio(adev);
+    if (drm_dev_is_unplugged(adev_to_drm(adev))) +        amdgpu_device_unmap_mmio(adev);
+
  }
    void amdgpu_device_fini_sw(struct amdgpu_device *adev)