Skip to contentSkip to conversation

drm/amdgpu: Fix null ptr when calling query_ras_error_count

PATCH In review Andrey Grodzovsky 2 participants 6 messages Aug 13, 2019 – Aug 14, 2019 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: Fix null ptr when calling query_ras_error_count

ras_err_data.err_addr was never allocated

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +17 -0
index 50c13b0..d9fb860 100644
@@ -1011,6 +1011,21 @@ static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
 	int ret;
 	struct ras_err_data err_data = {0, 0, 0, NULL};
 
+	/* Allocate enough to serve max  number of requests*/
+	int err_addr_size = data->ring_size / data->aligned_element_size *
+			   obj->adev->umc.umc_inst_num *
+			   obj->adev->umc.channel_inst_num;
+
+	err_data.err_addr = kcalloc(err_addr_size,
+				    sizeof(*err_data.err_addr),
+				    GFP_KERNEL);
+
+	if (!err_data.err_addr) {
+		DRM_ERROR("Not enough memory!");
+		return;
+	}
+
+
 	while (data->rptr != data->wptr) {
 		rmb();
 		memcpy(&entry, &data->ring[data->rptr],
@@ -1039,6 +1054,8 @@ static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
 			}
 		}
 	}
+
+	 kfree(err_data.err_addr);
 }
 
 static void amdgpu_ras_interrupt_process_handler(struct work_struct *work)
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1565718642-18107-1-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amdgpu: Start using amdgpu_ras_add_bad_pages.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +22 -1
index 296e2d9..46517c4 100644
@@ -243,15 +243,36 @@ static int gmc_v9_0_process_ras_data_cb(struct amdgpu_device *adev,
 		struct ras_err_data *err_data,
 		struct amdgpu_iv_entry *entry)
 {
+	unsigned long new_err_addr_cnt, old_err_addr_cnt = err_data->err_addr_cnt;
+
 	kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
 	if (adev->umc.funcs->query_ras_error_count)
 		adev->umc.funcs->query_ras_error_count(adev, err_data);
 	/* umc query_ras_error_address is also responsible for clearing
 	 * error status
 	 */
-	if (adev->umc.funcs->query_ras_error_address)
+	if (adev->umc.funcs->query_ras_error_address) {
+		unsigned long *bps;
+		int i;
+
 		adev->umc.funcs->query_ras_error_address(adev, err_data);
 
+		new_err_addr_cnt = err_data->err_addr_cnt - old_err_addr_cnt;
+
+		if (new_err_addr_cnt) {
+			bps = kcalloc(new_err_addr_cnt, sizeof(*bps), GFP_KERNEL);
+			if (!bps)
+				return -ENOMEM;
+
+			for (i = 0; i < new_err_addr_cnt; i++)
+				bps[i] = err_data->err_addr[old_err_addr_cnt + i]  >> PAGE_SHIFT;
+
+			amdgpu_ras_add_bad_pages(adev, bps, new_err_addr_cnt);
+
+			kfree(bps);
+		}
+	}
+
 	/* only uncorrectable error needs gpu reset */
 	if (err_data->ue_count)
 		amdgpu_ras_reset_gpu(adev, 0);
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1565718642-18107-2-git-send-email-andrey.grodzovsky-5C7GfCeVMHo@public.gmane.org

#4 lore raw

PATCH v2 1/1 drm/amdgpu: Start using amdgpu_ras_add_bad_pages

v2: Trigger GPU reset in case of new bad address errors.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +25 -2
index 296e2d9..f5f36ff 100644
@@ -243,17 +243,40 @@ static int gmc_v9_0_process_ras_data_cb(struct amdgpu_device *adev,
 		struct ras_err_data *err_data,
 		struct amdgpu_iv_entry *entry)
 {
+	unsigned long new_err_addr_cnt, old_err_addr_cnt;
+	new_err_addr_cnt = 0;
+	old_err_addr_cnt = err_data->err_addr_cnt;
+
 	kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
 	if (adev->umc.funcs->query_ras_error_count)
 		adev->umc.funcs->query_ras_error_count(adev, err_data);
 	/* umc query_ras_error_address is also responsible for clearing
 	 * error status
 	 */
-	if (adev->umc.funcs->query_ras_error_address)
+	if (adev->umc.funcs->query_ras_error_address) {
+		unsigned long *bps;
+		int i;
+
 		adev->umc.funcs->query_ras_error_address(adev, err_data);
 
+		new_err_addr_cnt = err_data->err_addr_cnt - old_err_addr_cnt;
+
+		if (new_err_addr_cnt) {
+			bps = kcalloc(new_err_addr_cnt, sizeof(*bps), GFP_KERNEL);
+			if (!bps)
+				return -ENOMEM;
+
+			for (i = 0; i < new_err_addr_cnt; i++)
+				bps[i] = err_data->err_addr[old_err_addr_cnt + i]  >> PAGE_SHIFT;
+
+			amdgpu_ras_add_bad_pages(adev, bps, new_err_addr_cnt);
+
+			kfree(bps);
+		}
+	}
+
 	/* only uncorrectable error needs gpu reset */
-	if (err_data->ue_count)
+	if (err_data->ue_count || new_err_addr_cnt)
 		amdgpu_ras_reset_gpu(adev, 0);
 
 	return AMDGPU_RAS_SUCCESS;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#5 lore raw
In reply to a message not in the archive

Hi Andrey:

I'm also working on ras error address saving based on your eeprom patches, and the implementation is different from you. I'll send out my patches this week and we can discuss it.

Regards,
Tao

Quoted 60 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrey Grodzovsky
Sent: 2019年8月14日 1:51
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Grodzovsky, Andrey <[email protected]>; Pan, Xinhui <[email protected]>; Zhang, Hawking <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: Fix null ptr when calling query_ras_error_count

ras_err_data.err_addr was never allocated

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +15 -0
index 50c13b0..d9fb860 100644
@@ -1011,6 +1011,21 @@ static void amdgpu_ras_interrupt_handler(struct
 ras_manager *obj)
 	int ret;
 	struct ras_err_data err_data = {0, 0, 0, NULL};
 
+	/* Allocate enough to serve max  number of requests*/
+	int err_addr_size = data->ring_size / data->aligned_element_size *
+			   obj->adev->umc.umc_inst_num *
+			   obj->adev->umc.channel_inst_num;
+
+	err_data.err_addr = kcalloc(err_addr_size,
+				    sizeof(*err_data.err_addr),
+				    GFP_KERNEL);
+
+	if (!err_data.err_addr) {
+		DRM_ERROR("Not enough memory!");
+		return;
+	}
+
+
 	while (data->rptr != data->wptr) {
 		rmb();

memcpy(&entry, &data->ring[data->rptr], @@ -1039,6
+1054,8 @@ static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
 			}
 		}
 	}
+
+	 kfree(err_data.err_addr);
 }
 
 static void amdgpu_ras_interrupt_process_handler(struct work_struct

*work)
--
2.7.4

Quoted 4 lines

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

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

A message that is not in the archive (sent off-list or not yet received): MN2PR12MB30542C37DA293DFADD11EE3EB0AD0-rweVpJHSKTqnT25eLM+iUQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#7 lore raw

Are you referring to this patch which fixes a crash or to the second patch in the serries ?

Andrey

________________________________________
From: Zhou1, Tao <[email protected]>
Sent: 13 August 2019 22:24:00
To: Grodzovsky, Andrey; [email protected]
Cc: Deucher, Alexander; Grodzovsky, Andrey; Pan, Xinhui; Zhang, Hawking
Subject: RE: [PATCH 1/2] drm/amdgpu: Fix null ptr when calling query_ras_error_count

Hi Andrey:

I'm also working on ras error address saving based on your eeprom patches, and the implementation is different from you. I'll send out my patches this week and we can discuss it.

Regards,
Tao

Quoted 60 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrey Grodzovsky
Sent: 2019年8月14日 1:51
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Grodzovsky, Andrey <[email protected]>; Pan, Xinhui <[email protected]>; Zhang, Hawking <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: Fix null ptr when calling query_ras_error_count

ras_err_data.err_addr was never allocated

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +15 -0
index 50c13b0..d9fb860 100644
@@ -1011,6 +1011,21 @@ static void amdgpu_ras_interrupt_handler(struct
 ras_manager *obj)
      int ret;
      struct ras_err_data err_data = {0, 0, 0, NULL};
 
+     /* Allocate enough to serve max  number of requests*/
+     int err_addr_size = data->ring_size / data->aligned_element_size *
+                        obj->adev->umc.umc_inst_num *
+                        obj->adev->umc.channel_inst_num;
+
+     err_data.err_addr = kcalloc(err_addr_size,
+                                 sizeof(*err_data.err_addr),
+                                 GFP_KERNEL);
+
+     if (!err_data.err_addr) {
+             DRM_ERROR("Not enough memory!");
+             return;
+     }
+
+
      while (data->rptr != data->wptr) {
              rmb();
              memcpy(&entry, &data->ring[data->rptr], @@ -1039,6
+1054,8 @@ static void amdgpu_ras_interrupt_handler(struct ras_manager
*obj)
                      }
              }
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+
+      kfree(err_data.err_addr);
 }
 
 static void amdgpu_ras_interrupt_process_handler(struct work_struct

*work)
--
2.7.4

Quoted 4 lines

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

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

A message that is not in the archive (sent off-list or not yet received): MWHPR12MB1453F67B997561E00180AE67EAAD0-Gy0DoCVfaSWZBIDmKHdw+wdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#9 lore raw

Referring to the series, patch #1 and #2.

Regards,
Tao

Quoted 74 lines

-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: 2019年8月14日 10:42
To: Zhou1, Tao <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Pan, Xinhui <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: Fix null ptr when calling query_ras_error_count

Are you referring to this patch which fixes a crash or to the second patch in the serries ?

Andrey

________________________________________
From: Zhou1, Tao <[email protected]>
Sent: 13 August 2019 22:24:00
To: Grodzovsky, Andrey; [email protected]
Cc: Deucher, Alexander; Grodzovsky, Andrey; Pan, Xinhui; Zhang, Hawking
Subject: RE: [PATCH 1/2] drm/amdgpu: Fix null ptr when calling query_ras_error_count

Hi Andrey:

I'm also working on ras error address saving based on your eeprom patches, and the implementation is different from you.
I'll send out my patches this week and we can discuss it.

Regards,
Tao

Quoted 6 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Andrey Grodzovsky
Sent: 2019年8月14日 1:51
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Grodzovsky,

Andrey

Quoted 1 line

<[email protected]>; Pan, Xinhui <[email protected]>;

Zhang,

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c static void

Quoted 17 lines

Hawking <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: Fix null ptr when calling query_ras_error_count

ras_err_data.err_addr was never allocated

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +0 -0
index 50c13b0..d9fb860 100644
@@ -1011,6 +1011,21 @@ static void

amdgpu_ras_interrupt_handler(struct

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +12 -0
 ras_manager *obj)
      int ret;
      struct ras_err_data err_data = {0, 0, 0, NULL};
 
+     /* Allocate enough to serve max  number of requests*/
+     int err_addr_size = data->ring_size / data->aligned_element_size *
+                        obj->adev->umc.umc_inst_num *
+                        obj->adev->umc.channel_inst_num;
+
+     err_data.err_addr = kcalloc(err_addr_size,
+                                 sizeof(*err_data.err_addr),
+                                 GFP_KERNEL);
+
+     if (!err_data.err_addr) {
+             DRM_ERROR("Not enough memory!");
+             return;
Quoted 25 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -0
+     }
+
+
      while (data->rptr != data->wptr) {
              rmb();
              memcpy(&entry, &data->ring[data->rptr], @@ -1039,6

+1054,8 @@ static void amdgpu_ras_interrupt_handler(struct

ras_manager

Quoted 17 lines

*obj)

                      }
              }
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
+
+      kfree(err_data.err_addr);
 }
 
 static void amdgpu_ras_interrupt_process_handler(struct work_struct

*work)
--
2.7.4

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

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