Skip to contentSkip to conversation

drm/amdgpu: Fix the iounmap error of rmmio

PATCH In review Ma Jun 4 participants 5 messages Mar 15, 2024 – Mar 18, 2024

Subsystems (2)
lore
Share & tools
lore

Ma Jun

author
#0 lore raw

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

Fixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")
---
 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
index 39dd76e57154..d65a6aabefbb 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Ma Jun

Setting the rmmio pointer to NULL to fix the following iounmap error and calltrace.
iounmap: bad address 00000000d0b3631f

Fixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")
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
index 39dd76e57154..d65a6aabefbb 100644
@@ -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);
  	}
maintainer
#2 lore raw
In reply to Ma Jun

Am 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 address 00000000d0b3631f

Fixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")
---
  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
index 39dd76e57154..d65a6aabefbb 100644

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 -0
  	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)) {

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);
  	}
#3 lore raw

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 address 00000000d0b3631f

Fixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")
---
  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
index 39dd76e57154..d65a6aabefbb 100644
@@ -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 -0
  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.

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 -0
  	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)) {

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);
  	}
maintainer
#4 lore raw

Am 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 address 00000000d0b3631f

Fixes 923f7a82d2e1 ("drm/amd/amdgpu: Fix potential ioremap() memory leaks in amdgpu_device_init()")
---
   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
index 39dd76e57154..d65a6aabefbb 100644
@@ -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 -0
   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.

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 Jun

Quoted 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 -0
   	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)) {

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);
   	}