Skip to contentSkip to conversation

drm/amdgpu: Fix the page fault issue in amdgpu_irq_fini

PATCH In review Emily Deng 3 participants 5 messages Mar 18, 2021 – Mar 19, 2021

Subsystems (2)
lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix the page fault issue in amdgpu_irq_fini

For some source, it will be shared by some client ID and source ID. To fix the page fault issue, set all those to null.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +13 -3
index af026109421a..623b1ac6231d 100644
@@ -359,7 +359,7 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
  */
 void amdgpu_irq_fini(struct amdgpu_device *adev)
 {
-	unsigned i, j;
+	unsigned i, j, m, n;
 
 	if (adev->irq.installed) {
 		drm_irq_uninstall(adev_to_drm(adev));
@@ -380,12 +380,22 @@ void amdgpu_irq_fini(struct amdgpu_device *adev)
 			if (!src)
 				continue;
 
-			kfree(src->enabled_types);
+			if (src->enabled_types)
+				kfree(src->enabled_types);
+
 			src->enabled_types = NULL;
+
 			if (src->data) {
 				kfree(src->data);
 				kfree(src);
-				adev->irq.client[i].sources[j] = NULL;
+			}
+
+			for (m = 0; m < AMDGPU_IRQ_CLIENTID_MAX; ++m) {
+				if (!adev->irq.client[m].sources)
+					continue;
+				for (n = 0; n < AMDGPU_MAX_IRQ_SRC_ID; ++n)
+					if (adev->irq.client[m].sources[n] == src)
+						adev->irq.client[m].sources[n] = NULL;
 			}
 		}
 		kfree(adev->irq.client[i].sources);
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

Am 18.03.21 um 12:48 schrieb Emily Deng:

Quoted 22 lines

For some source, it will be shared by some client ID and source ID. To fix the page fault issue, set all those to null.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
index af026109421a..623b1ac6231d 100644
@@ -359,7 +359,7 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
   */
  void amdgpu_irq_fini(struct amdgpu_device *adev)
  {
-	unsigned i, j;
+	unsigned i, j, m, n;
 
  	if (adev->irq.installed) {
  		drm_irq_uninstall(adev_to_drm(adev));

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 384

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -1
@@ -380,12 +380,22 @@ void amdgpu_irq_fini(struct amdgpu_device *adev)
  			if (!src)
  				continue;
 
-			kfree(src->enabled_types);
+			if (src->enabled_types)
+				kfree(src->enabled_types);

A NULL check before kfree() is unecessary and will be complained about by the static checkers.

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 387

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+
  			src->enabled_types = NULL;
+

Unrelated white space change.

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 398

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +8 -1
  			if (src->data) {
  				kfree(src->data);
  				kfree(src);
-				adev->irq.client[i].sources[j] = NULL;
+			}
+
+			for (m = 0; m < AMDGPU_IRQ_CLIENTID_MAX; ++m) {
+				if (!adev->irq.client[m].sources)
+					continue;
+				for (n = 0; n < AMDGPU_MAX_IRQ_SRC_ID; ++n)
+					if (adev->irq.client[m].sources[n] == src)
+						adev->irq.client[m].sources[n] = NULL;

Hui what? The memory you set to NULL here is freed on the line below.

Accessing it after that would be illegal, so why do you want to set it to NULL?

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 401

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
  			}
  		}
  		kfree(adev->irq.client[i].sources);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#2 lore raw

[AMD Official Use Only - Internal Distribution Only]

Quoted 34 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, March 18, 2021 7:52 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix the page fault issue in amdgpu_irq_fini

Am 18.03.21 um 12:48 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device

Quoted 23 lines

For some source, it will be shared by some client ID and source ID. To fix the page fault issue, set all those to null.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
index af026109421a..623b1ac6231d 100644
@@ -359,7 +359,7 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
   */
  void amdgpu_irq_fini(struct amdgpu_device *adev)
  {
-unsigned i, j;
+unsigned i, j, m, n;
 
  if (adev->irq.installed) {
  drm_irq_uninstall(adev_to_drm(adev));
@@ -380,12 +380,22 @@ void amdgpu_irq_fini(struct amdgpu_device

*adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
  if (!src)
  continue;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 384

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -1
-kfree(src->enabled_types);
+if (src->enabled_types)
+kfree(src->enabled_types);

A NULL check before kfree() is unecessary and will be complained about by the static checkers.

Sorry, will remove this.

Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 387

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+
  src->enabled_types = NULL;
+

Unrelated white space change.

Sorry, will remove this also.

Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev)

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +6 -1
  if (src->data) {
  kfree(src->data);
  kfree(src);
-adev->irq.client[i].sources[j] = NULL;
+}
+
+for (m = 0; m < AMDGPU_IRQ_CLIENTID_MAX; ++m) {
+if (!adev->irq.client[m].sources)
+continue;
+for (n = 0; n < AMDGPU_MAX_IRQ_SRC_ID;

++n)

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device · line 397

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+if (adev->irq.client[m].sources[n] ==

src)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device · line 398

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+adev->irq.client[m].sources[n]

= NULL;

Hui what? The memory you set to NULL here is freed on the line below.

Accessing it after that would be illegal, so why do you want to set it to NULL?

[Emily] It is in the loop "for (j = 0; j < AMDGPU_MAX_IRQ_SRC_ID; ++j) {", shouldn't have been freed in this loop. Only set " adev->irq.client[i].sources[j] = NULL;" is not enough, as it maybe have other client ID and src ID will share the same src. Also need to set those to NULL.

Quoted 6 lines

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
  }
  }
  kfree(adev->irq.client[i].sources);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw

[AMD Official Use Only - Internal Distribution Only]

Hi, Emily,
What about refine struct amdgpu_irq_src with refcount? Your change could fix this issue, but it is unreadable.

Best Regards
Dennis Li
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Deng, Emily
Sent: Friday, March 19, 2021 9:38 AM
To: Christian König <[email protected]>; [email protected]
Subject: RE: [PATCH] drm/amdgpu: Fix the page fault issue in amdgpu_irq_fini

[AMD Official Use Only - Internal Distribution Only]

[AMD Official Use Only - Internal Distribution Only]

Quoted 35 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, March 18, 2021 7:52 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix the page fault issue in amdgpu_irq_fini

Am 18.03.21 um 12:48 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device

Quoted 23 lines

For some source, it will be shared by some client ID and source ID. To fix the page fault issue, set all those to null.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
index af026109421a..623b1ac6231d 100644
@@ -359,7 +359,7 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
   */
  void amdgpu_irq_fini(struct amdgpu_device *adev)
  {
-unsigned i, j;
+unsigned i, j, m, n;
 
  if (adev->irq.installed) {
  drm_irq_uninstall(adev_to_drm(adev));
@@ -380,12 +380,22 @@ void amdgpu_irq_fini(struct amdgpu_device

*adev)

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
  if (!src)
  continue;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 384

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -1
-kfree(src->enabled_types);
+if (src->enabled_types)
+kfree(src->enabled_types);

A NULL check before kfree() is unecessary and will be complained about by the static checkers.

Sorry, will remove this.

Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 387

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+
  src->enabled_types = NULL;
+

Unrelated white space change.

Sorry, will remove this also.

Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +5 -1
  if (src->data) {
  kfree(src->data);
  kfree(src);
-adev->irq.client[i].sources[j] = NULL;
+}
+
+for (m = 0; m < AMDGPU_IRQ_CLIENTID_MAX; ++m) { if 
+(!adev->irq.client[m].sources) continue; for (n = 0; n < 
+AMDGPU_MAX_IRQ_SRC_ID;

++n)

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device · line 396

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+if (adev->irq.client[m].sources[n] ==

src)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device · line 397

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+adev->irq.client[m].sources[n]

= NULL;

Hui what? The memory you set to NULL here is freed on the line below.

Accessing it after that would be illegal, so why do you want to set it to NULL?

[Emily] It is in the loop "for (j = 0; j < AMDGPU_MAX_IRQ_SRC_ID; ++j) {", shouldn't have been freed in this loop. Only set " adev->irq.client[i].sources[j] = NULL;" is not enough, as it maybe have other client ID and src ID will share the same src. Also need to set those to NULL.

Quoted 6 lines

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
  }
  }
  kfree(adev->irq.client[i].sources);

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CDennis.Li%40amd.com%7C3e94ebf6f1d34e31898e08d8ea77b613%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637517147175478166%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=m2sQW4Ncv40K97wxOgC%2BSFiT8yhy6996E%2FR%2FMWLoh64%3D&amp;reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
In reply to Deng, Emily

Am 19.03.21 um 02:38 schrieb Deng, Emily:

Quoted 60 lines

[AMD Official Use Only - Internal Distribution Only]

Quoted 31 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, March 18, 2021 7:52 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix the page fault issue in amdgpu_irq_fini

Am 18.03.21 um 12:48 schrieb Emily Deng:

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device

Quoted 23 lines

For some source, it will be shared by some client ID and source ID. To fix the page fault issue, set all those to null.

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 16 +++++++++++++---
   1 file changed, 13 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -1
index af026109421a..623b1ac6231d 100644
@@ -359,7 +359,7 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
    */
   void amdgpu_irq_fini(struct amdgpu_device *adev)
   {
-unsigned i, j;
+unsigned i, j, m, n;
 
   if (adev->irq.installed) {
   drm_irq_uninstall(adev_to_drm(adev));
@@ -380,12 +380,22 @@ void amdgpu_irq_fini(struct amdgpu_device

*adev)

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 384

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -1
   if (!src)
   continue;
 
-kfree(src->enabled_types);
+if (src->enabled_types)
+kfree(src->enabled_types);

A NULL check before kfree() is unecessary and will be complained about by the static checkers.

Sorry, will remove this.

Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev) · line 387

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +2 -0
+
   src->enabled_types = NULL;
+

Unrelated white space change.

Sorry, will remove this also.

Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device *adev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +6 -1
   if (src->data) {
   kfree(src->data);
   kfree(src);
-adev->irq.client[i].sources[j] = NULL;
+}
+
+for (m = 0; m < AMDGPU_IRQ_CLIENTID_MAX; ++m) {
+if (!adev->irq.client[m].sources)
+continue;
+for (n = 0; n < AMDGPU_MAX_IRQ_SRC_ID;

++n)

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device · line 397

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+if (adev->irq.client[m].sources[n] ==

src)

Quoted 8 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c void amdgpu_irq_fini(struct amdgpu_device · line 398

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +1 -0
+adev->irq.client[m].sources[n]

= NULL;

Hui what? The memory you set to NULL here is freed on the line below.

Accessing it after that would be illegal, so why do you want to set it to NULL?

[Emily] It is in the loop "for (j = 0; j < AMDGPU_MAX_IRQ_SRC_ID; ++j) {", shouldn't have been freed in this loop. Only set " adev->irq.client[i].sources[j] = NULL;" is not enough, as it maybe have other client ID and src ID will share the same src. Also need to set those to NULL.

No, that can't happen.

It is illegal to use a dynamic allocated source with multiple client ID and src ID. Where do you see that?

We could also probably completely remove this feature since it is unused as far as I know.

Thanks,
Christian.

Quoted 5 lines
Quoted 5 lines

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -0
   }
   }
   kfree(adev->irq.client[i].sources);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx