drm/amdgpu: Call amdgpu_device_unmap_mmio() iff device is unplugged to prevent crash in GPU initialization failure
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: Call amdgpu_device_unmap_mmio() iff 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() iff 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -1
@@ -3845,6 +3845,8 @@ static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)*/ void amdgpu_device_fini_hw (struct amdgpu_device *adev) { +int idx; +dev_info (adev->dev,"amdgpu: finishing device.\n" );flush_delayed_work (&adev->delayed_init_work);if (adev->mman.initialized) {
@@ -3888,7 +3890,11 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)amdgpu_gart_dummy_page_fini (adev); -amdgpu_device_unmap_mmio (adev); +if (!drm_dev_enter (adev_to_drm (adev), &idx)) +amdgpu_device_unmap_mmio (adev); +else +drm_dev_exit (idx); + }void amdgpu_device_fini_sw (struct amdgpu_device *adev)
Signature · 1 line
2.25.1
[Public]
Hi Leslie,
I think we need to modify it like:
+if (drm_dev_enter(adev_to_drm(adev), &idx)) {
+ amdgpu_device_unmap_mmio(adev);
+ drm_dev_exit(idx);
+}
Also you need to credit Andrey a 'suggested-by' in your patch.
Regards,
Guchun
-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 2:14 PM
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 v2] drm/amdgpu: Call amdgpu_device_unmap_mmio() iff 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() iff 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -1
@@ -3845,6 +3845,8 @@ static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)*/ void amdgpu_device_fini_hw (struct amdgpu_device *adev) { +int idx; +dev_info (adev->dev,"amdgpu: finishing device.\n" );flush_delayed_work (&adev->delayed_init_work);if (adev->mman.initialized) {
@@ -3888,7 +3890,11 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)amdgpu_gart_dummy_page_fini (adev); -amdgpu_device_unmap_mmio (adev); +if (!drm_dev_enter (adev_to_drm (adev), &idx)) +amdgpu_device_unmap_mmio (adev); +else +drm_dev_exit (idx); + }void amdgpu_device_fini_sw (struct amdgpu_device *adev)
--
2.25.1
[Public]
Hi Guchun,
As Andrey says, "we should not call amdgpu_device_unmap_mmio unless device is unplugged", I think we should call amdgpu_device_unmap_mmio() only if device is unplugged (drm_dev_enter() return false) .
+if (!drm_dev_enter(adev_to_drm(adev), &idx))
+ amdgpu_device_unmap_mmio(adev);
+ else
# drm_dev_exit(idx);
Regards,
Leslie
-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Thursday, December 16, 2021 2:46 PM
To: Shi, Leslie <[email protected]>; Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Call amdgpu_device_unmap_mmio() iff device is unplugged to prevent crash in GPU initialization failure
[Public]
Hi Leslie,
I think we need to modify it like:
+if (drm_dev_enter(adev_to_drm(adev), &idx)) {
+ amdgpu_device_unmap_mmio(adev);
+ drm_dev_exit(idx);
+}
Also you need to credit Andrey a 'suggested-by' in your patch.
Regards,
Guchun
-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 2:14 PM
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 v2] drm/amdgpu: Call amdgpu_device_unmap_mmio() iff 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() iff 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -1
@@ -3845,6 +3845,8 @@ static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)*/ void amdgpu_device_fini_hw (struct amdgpu_device *adev) { +int idx; +dev_info (adev->dev,"amdgpu: finishing device.\n" );flush_delayed_work (&adev->delayed_init_work);if (adev->mman.initialized) {
@@ -3888,7 +3890,11 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)amdgpu_gart_dummy_page_fini (adev); -amdgpu_device_unmap_mmio (adev); +if (!drm_dev_enter (adev_to_drm (adev), &idx)) +amdgpu_device_unmap_mmio (adev); +else +drm_dev_exit (idx); + }void amdgpu_device_fini_sw (struct amdgpu_device *adev)
--
2.25.1
[Public]
My BAD to misunderstand this.
There are both spell typos in patch subject and body, s/iff/if.
The patch is: Reviewed-by: Guchun Chen <[email protected]>
Please wait for the ack from Andrey and Christian before pushing this.
Regards,
Guchun
-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 3:00 PM
To: Chen, Guchun <[email protected]>; Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Call amdgpu_device_unmap_mmio() iff device is unplugged to prevent crash in GPU initialization failure
[Public]
Hi Guchun,
As Andrey says, "we should not call amdgpu_device_unmap_mmio unless device is unplugged", I think we should call amdgpu_device_unmap_mmio() only if device is unplugged (drm_dev_enter() return false) .
+if (!drm_dev_enter(adev_to_drm(adev), &idx))
+ amdgpu_device_unmap_mmio(adev);
+ else
# drm_dev_exit(idx);
Regards,
Leslie
-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Thursday, December 16, 2021 2:46 PM
To: Shi, Leslie <[email protected]>; Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Call amdgpu_device_unmap_mmio() iff device is unplugged to prevent crash in GPU initialization failure
[Public]
Hi Leslie,
I think we need to modify it like:
+if (drm_dev_enter(adev_to_drm(adev), &idx)) {
+ amdgpu_device_unmap_mmio(adev);
+ drm_dev_exit(idx);
+}
Also you need to credit Andrey a 'suggested-by' in your patch.
Regards,
Guchun
-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 2:14 PM
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 v2] drm/amdgpu: Call amdgpu_device_unmap_mmio() iff 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() iff 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -1
@@ -3845,6 +3845,8 @@ static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)*/ void amdgpu_device_fini_hw (struct amdgpu_device *adev) { +int idx; +dev_info (adev->dev,"amdgpu: finishing device.\n" );flush_delayed_work (&adev->delayed_init_work);if (adev->mman.initialized) {
@@ -3888,7 +3890,11 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)amdgpu_gart_dummy_page_fini (adev); -amdgpu_device_unmap_mmio (adev); +if (!drm_dev_enter (adev_to_drm (adev), &idx)) +amdgpu_device_unmap_mmio (adev); +else +drm_dev_exit (idx); + }void amdgpu_device_fini_sw (struct amdgpu_device *adev)
--
2.25.1
The !drm_dev_enter() is quite unusual and deserves a comment explaining what's going on here.
Apart from that it looks good with the typos fixed I think.
Christian.
Am 16.12.21 um 08:27 schrieb Chen, Guchun:
Quoted 102 lines
[Public]
My BAD to misunderstand this.
There are both spell typos in patch subject and body, s/iff/if.
The patch is: Reviewed-by: Guchun Chen <[email protected]>
Please wait for the ack from Andrey and Christian before pushing this.
Regards,
Guchun-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 3:00 PM
To: Chen, Guchun <[email protected]>; Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Callamdgpu_device_unmap_mmio()iff device is unplugged to prevent crash in GPU initialization failure[Public]
Hi Guchun,
As Andrey says, "we should not call
amdgpu_device_unmap_mmiounless device is unplugged", I think we should callamdgpu_device_unmap_mmio()only if device is unplugged (drm_dev_enter()return false) .drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-0+if (!drm_dev_enter (adev_to_drm (adev), &idx)) +amdgpu_device_unmap_mmio (adev); +else #
drm_dev_exit(idx);Regards,
Leslie-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Thursday, December 16, 2021 2:46 PM
To: Shi, Leslie <[email protected]>; Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Callamdgpu_device_unmap_mmio()iff device is unplugged to prevent crash in GPU initialization failure[Public]
Hi Leslie,
I think we need to modify it like:
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0+if (drm_dev_enter (adev_to_drm (adev), &idx)) { +amdgpu_device_unmap_mmio (adev); +drm_dev_exit (idx); +}Also you need to credit Andrey a 'suggested-by' in your patch.
Regards,
Guchun-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 2:14 PM
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 v2] drm/amdgpu: Callamdgpu_device_unmap_mmio()iff device is unplugged to prevent crash in GPU initialization failure[Why]
Inamdgpu_driver_load_kms, whenamdgpu_device_initreturns error during driver modprobe, it will start the error handle path immediately and call intoamdgpu_device_unmap_mmioas 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 invcn_v3_0_sw_fini. So a kernel crash occurs.[How]
callamdgpu_device_unmap_mmio()iff device is unplugged to prevent invalid memory address invcn_v3_0_sw_fini()when GPU initialization failure.Signed-off-by Leslie Shi <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-2@@ -3845,6 +3845,8 @@ static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)*/ void amdgpu_device_fini_hw (struct amdgpu_device *adev) { +int idx; +dev_info (adev->dev,"amdgpu: finishing device.\n" );flush_delayed_work (&adev->delayed_init_work);if (adev->mman.initialized) {@@ -3888,7 +3890,11 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)amdgpu_gart_dummy_page_fini (adev); -amdgpu_device_unmap_mmio (adev); +if (!drm_dev_enter (adev_to_drm (adev), &idx)) +amdgpu_device_unmap_mmio (adev); +else +drm_dev_exit (idx); + }void amdgpu_device_fini_sw (struct amdgpu_device *adev) --2.25.1
Maybe we just should use drm_dev_is_unplugged() for this particular case because, there would be no race since when device is unplugged it's final. It's the other way around that requires strict drm_dev_enter/exit scope.
Andrey
Quoted 109 lines · Christian König
The !drm_dev_enter() is quite unusual and deserves a comment explaining what's going on here.
Apart from that it looks good with the typos fixed I think.
Christian.
Am 16.12.21 um 08:27 schrieb Chen, Guchun:
Quoted 101 lines
[Public]
My BAD to misunderstand this.
There are both spell typos in patch subject and body, s/iff/if.
The patch is: Reviewed-by: Guchun Chen <[email protected]>
Please wait for the ack from Andrey and Christian before pushing this.
Regards,
Guchun-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 3:00 PM
To: Chen, Guchun <[email protected]>; Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Callamdgpu_device_unmap_mmio()iff device is unplugged to prevent crash in GPU initialization failure[Public]
Hi Guchun,
As Andrey says, "we should not call
amdgpu_device_unmap_mmiounless device is unplugged", I think we should callamdgpu_device_unmap_mmio()only if device is unplugged (drm_dev_enter()return false) .+if (!drm_dev_enter(adev_to_drm(adev), &idx))
+amdgpu_device_unmap_mmio(adev);
+ else
#drm_dev_exit(idx);Regards,
Leslie-----Original Message-----
From: Chen, Guchun <[email protected]>
Sent: Thursday, December 16, 2021 2:46 PM
To: Shi, Leslie <[email protected]>; Grodzovsky, Andrey <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/amdgpu: Callamdgpu_device_unmap_mmio()iff device is unplugged to prevent crash in GPU initialization failure[Public]
Hi Leslie,
I think we need to modify it like:
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0+if (drm_dev_enter (adev_to_drm (adev), &idx)) { + amdgpu_device_unmap_mmio(adev); + drm_dev_exit(idx); +}Also you need to credit Andrey a 'suggested-by' in your patch.
Regards,
Guchun-----Original Message-----
From: Shi, Leslie <[email protected]>
Sent: Thursday, December 16, 2021 2:14 PM
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 v2] drm/amdgpu: Callamdgpu_device_unmap_mmio()iff device is unplugged to prevent crash in GPU initialization failure[Why]
Inamdgpu_driver_load_kms, whenamdgpu_device_initreturns error during driver modprobe, it will start the error handle path immediately and call intoamdgpu_device_unmap_mmioas 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 invcn_v3_0_sw_fini. So a kernel crash occurs.[How]
callamdgpu_device_unmap_mmio()iff device is unplugged to prevent invalid memory address invcn_v3_0_sw_fini()when GPU initialization failure.Signed-off-by Leslie Shi <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 8 +++++++-1 file changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0@@ -3845,6 +3845,8 @@ static void amdgpu_device_unmap_mmio(structamdgpu_device *adev) */ void amdgpu_device_fini_hw(struct amdgpu_device *adev) { + int idx; + dev_info(adev->dev, "amdgpu: finishing device.\n"); flush_delayed_work(&adev->delayed_init_work); if (adev->mman.initialized) {@@ -3888,7 +3890,11 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) amdgpu_gart_dummy_page_fini(adev); - amdgpu_device_unmap_mmio(adev); + if (!drm_dev_enter(adev_to_drm(adev), &idx)) + amdgpu_device_unmap_mmio(adev); + else + drm_dev_exit(idx); + } void amdgpu_device_fini_sw(struct amdgpu_device *adev)Signature · 1 line
2.25.1