drm/amdgpu: Fix the iounmap error of rmmio
Subsystems (2)
PATCH 1/1 drm/amdgpu: Fix the iounmap error of rmmio
Setting the rmmio pointer to NULL to fix the following iounmap error and calltrace.
iounmap: bad address 00000000d0b3631f
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -2
@@ -4383,6 +4383,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, unmap_memory:iounmap (adev->rmmio); + adev->rmmio =NULL ;return r; }
@@ -4514,9 +4515,11 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)#endif if (drm_dev_enter (adev_to_drm (adev), &idx)) { +if (adev->rmmio) { +iounmap (adev->rmmio); + adev->rmmio =NULL ; + } -iounmap (adev->rmmio); - adev->rmmio =NULL ;amdgpu_doorbell_fini (adev);drm_dev_exit (idx); }
Signature · 1 line
2.34.1
Quoted 6 lines · Ma Jun
Setting the rmmio pointer to NULL to fix the following iounmap error and calltrace.
iounmap: bad address00000000d0b3631fFixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")Signed-off-by Ma Jun <[email protected]>
Quoted 30 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-2@@ -4383,6 +4383,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, unmap_memory:iounmap (adev->rmmio); + adev->rmmio =NULL ;return r; }@@ -4514,9 +4515,11 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)#endif if (drm_dev_enter (adev_to_drm (adev), &idx)) { +if (adev->rmmio) { +iounmap (adev->rmmio); + adev->rmmio =NULL ; + } -iounmap (adev->rmmio); - adev->rmmio =NULL ;amdgpu_doorbell_fini (adev);drm_dev_exit (idx); }
Christian König
maintainerAm 15.03.24 um 06:17 schrieb Ma Jun:
Quoted 15 lines
Setting the rmmio pointer to NULL to fix the following iounmap error and calltrace.
iounmap: bad address00000000d0b3631fFixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_init(struct amdgpu_device *adev, · line 4386
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -4383,6 +4383,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, unmap_memory:iounmap (adev->rmmio); + adev->rmmio =NULL ;
Well that doesn't looks correct to me. You seem to be working around broken initialisation code here.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini_sw(struct amdgpu_device *adev) · line 4517
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0return r; }@@ -4514,9 +4515,11 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)#endif if (drm_dev_enter (adev_to_drm (adev), &idx)) {
Ok, well that alone doesn't look correct to me. The MMIO regions needs to be unmapped independent if the driver is disconnected or not.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini_sw(struct amdgpu_device *adev) · line 4518
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0+if (adev->rmmio) {
That looks just like a hack to me.
Regards,
Christian.
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-2+iounmap (adev->rmmio); + adev->rmmio =NULL ; + } -iounmap (adev->rmmio); - adev->rmmio =NULL ;amdgpu_doorbell_fini (adev);drm_dev_exit (idx); }
Hi Christian,
Quoted 17 lines · Christian König
Am 15.03.24 um 06:17 schrieb Ma Jun:
Quoted 16 lines
Setting the rmmio pointer to NULL to fix the following iounmap error and calltrace.
iounmap: bad address00000000d0b3631fFixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4383,6 +4383,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_init(struct amdgpu_device *adev, · line 4386
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0unmap_memory:iounmap (adev->rmmio); + adev->rmmio =NULL ;Well that doesn't looks correct to me. You seem to be working around broken initialisation code here.
I got this error when I tried to rescan the gpu device after removing it.
Regards,
Ma Jun
Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini_sw(struct amdgpu_device *adev) · line 4517
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0return r; }@@ -4514,9 +4515,11 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)#endif if (drm_dev_enter (adev_to_drm (adev), &idx)) {Ok, well that alone doesn't look correct to me. The MMIO regions needs to be unmapped independent if the driver is disconnected or not.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini_sw(struct amdgpu_device *adev) · line 4518
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0+if (adev->rmmio) {That looks just like a hack to me.
Regards,
Christian.Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-2+iounmap (adev->rmmio); + adev->rmmio =NULL ; + } -iounmap (adev->rmmio); - adev->rmmio =NULL ;amdgpu_doorbell_fini (adev);drm_dev_exit (idx); }
Christian König
maintainerAm 18.03.24 um 02:43 schrieb Ma, Jun:
Quoted 20 lines
Hi Christian,
Quoted 17 lines · Christian König
Am 15.03.24 um 06:17 schrieb Ma Jun:
Quoted 16 lines
Setting the rmmio pointer to NULL to fix the following iounmap error and calltrace.
iounmap: bad address00000000d0b3631fFixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4383,6 +4383,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
Quoted 6 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_init(struct amdgpu_device *adev, · line 4386
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0unmap_memory:iounmap (adev->rmmio); + adev->rmmio =NULL ;Well that doesn't looks correct to me. You seem to be working around broken initialisation code here.
I got this error when I tried to rescan the gpu device after removing it.
Yeah, exactly that's the point. The whole smatch warning was just bogous since amdgpu_device_fini_sw() will always cleanup the mapping.
So the whole patch 923f7a82d2e1 should be reverted instead.
Regards,
Christian.
Quoted 28 lines
Regards,
Ma JunQuoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini_sw(struct amdgpu_device *adev) · line 4517
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0return r; }@@ -4514,9 +4515,11 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)#endif if (drm_dev_enter (adev_to_drm (adev), &idx)) {Ok, well that alone doesn't look correct to me. The MMIO regions needs to be unmapped independent if the driver is disconnected or not.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c void amdgpu_device_fini_sw(struct amdgpu_device *adev) · line 4518
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0+if (adev->rmmio) {That looks just like a hack to me.
Regards,
Christian.Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-2+iounmap (adev->rmmio); + adev->rmmio =NULL ; + } -iounmap (adev->rmmio); - adev->rmmio =NULL ;amdgpu_doorbell_fini (adev);drm_dev_exit (idx); }