Skip to contentSkip to conversation

drm/amdgpu: Add recovery_lock to save bad pages function

PATCH In review Candice Li 2 participants 4 messages Nov 16, 2021 – Nov 17, 2021

Subsystems (2)
lore
Share & tools
lore

Candice Li

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Add recovery_lock to save bad pages function

Fix race condition failure during UMC UE injection.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +7 -2
index 08133de21fdd63..711b5fb26d47d4 100644
@@ -1931,10 +1931,12 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)
 	struct ras_err_handler_data *data;
 	struct amdgpu_ras_eeprom_control *control;
 	int save_count;
+	int ret = 0;
 
 	if (!con || !con->eh_data)
 		return 0;
 
+	mutex_lock(&con->recovery_lock);
 	control = &con->eeprom_control;
 	data = con->eh_data;
 	save_count = data->count - control->ras_num_recs;
@@ -1944,13 +1946,16 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)
 					     &data->bps[control->ras_num_recs],
 					     save_count)) {
 			dev_err(adev->dev, "Failed to save EEPROM table data!");
-			return -EIO;
+			ret = -EIO;
+			goto out;
 		}
 
 		dev_info(adev->dev, "Saved %d pages to EEPROM table.\n", save_count);
 	}
 
-	return 0;
+out:
+	mutex_unlock(&con->recovery_lock);
+	return ret;
 }
 
 /*
Signature · 1 line
2.17.1
#1 lore raw

[AMD Official Use Only]

Quoted 33 lines

-----Original Message-----
From: Li, Candice <[email protected]>
Sent: Tuesday, November 16, 2021 4:02 PM
To: [email protected]
Cc: Clements, John <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: Add recovery_lock to save bad pages function

Fix race condition failure during UMC UE injection.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 08133de21fdd63..711b5fb26d47d4 100644
@@ -1931,10 +1931,12 @@ int amdgpu_ras_save_bad_pages(struct
 amdgpu_device *adev)
      struct ras_err_handler_data *data;
      struct amdgpu_ras_eeprom_control *control;
      int save_count;
+     int ret = 0;
 
      if (!con || !con->eh_data)
              return 0;
 
+     mutex_lock(&con->recovery_lock);
      control = &con->eeprom_control;
      data = con->eh_data;
Quoted 1 line
      save_count = data->count - control->ras_num_recs; @@ -1944,13

[Tao] Since recovery_lock is dedicated to protecting eh_data, can we unlock it here?

Quoted 23 lines

+1946,16 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)

                                           &data->bps[control->ras_num_recs],
                                           save_count)) {
                      dev_err(adev->dev, "Failed to save EEPROM table

data!");

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -1
-                     return -EIO;
+                     ret = -EIO;
+                     goto out;
              }
 
              dev_info(adev->dev, "Saved %d pages to EEPROM table.\n",
save_count);
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -2
-     return 0;
+out:
+     mutex_unlock(&con->recovery_lock);
+     return ret;
 }
 
 /*
--

2.17.1

#2 lore raw

[Public]

Thanks for the review, Tao. Updated the position for unlocking.

Fix race condition failure during UMC UE injection.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 08133de21fdd63..53b957a5b9a65c 100644
@@ -1935,9 +1935,11 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)
        if (!con || !con->eh_data)
                return 0;
 
+       mutex_lock(&con->recovery_lock);
        control = &con->eeprom_control;
        data = con->eh_data;
        save_count = data->count - control->ras_num_recs;
+       mutex_unlock(&con->recovery_lock);
        /* only new entries are saved */
        if (save_count > 0) {
                if (amdgpu_ras_eeprom_append(control,

--
2.17.1

Thanks,
Candice

-----Original Message-----
From: Zhou1, Tao <[email protected]>
Sent: Tuesday, November 16, 2021 4:27 PM
To: Li, Candice <[email protected]>; [email protected]
Cc: Clements, John <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Add recovery_lock to save bad pages function

[AMD Official Use Only]

Quoted 33 lines

-----Original Message-----
From: Li, Candice <[email protected]>
Sent: Tuesday, November 16, 2021 4:02 PM
To: [email protected]
Cc: Clements, John <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: Add recovery_lock to save bad pages function

Fix race condition failure during UMC UE injection.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 08133de21fdd63..711b5fb26d47d4 100644
@@ -1931,10 +1931,12 @@ int amdgpu_ras_save_bad_pages(struct
 amdgpu_device *adev)
      struct ras_err_handler_data *data;
      struct amdgpu_ras_eeprom_control *control;
      int save_count;
+     int ret = 0;
 
      if (!con || !con->eh_data)
              return 0;
 
+     mutex_lock(&con->recovery_lock);
      control = &con->eeprom_control;
      data = con->eh_data;
Quoted 1 line
      save_count = data->count - control->ras_num_recs; @@ -1944,13

[Tao] Since recovery_lock is dedicated to protecting eh_data, can we unlock it here?

Quoted 23 lines

+1946,16 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)

                                           &data->bps[control->ras_num_recs],
                                           save_count)) {
                      dev_err(adev->dev, "Failed to save EEPROM table

data!");

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -1
-                     return -EIO;
+                     ret = -EIO;
+                     goto out;
              }
 
              dev_info(adev->dev, "Saved %d pages to EEPROM table.\n",
save_count);
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -2
-     return 0;
+out:
+     mutex_unlock(&con->recovery_lock);
+     return ret;
 }
 
 /*
--

2.17.1

Reviewed-by
#3 lore raw
Quoted 117 lines

-----Original Message-----
From: Li, Candice <[email protected]>
Sent: Wednesday, November 17, 2021 11:08 AM
To: Zhou1, Tao <[email protected]>; [email protected]
Cc: Clements, John <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Add recovery_lock to save bad pages function

[Public]

Thanks for the review, Tao. Updated the position for unlocking.

Fix race condition failure during UMC UE injection.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 08133de21fdd63..53b957a5b9a65c 100644
@@ -1935,9 +1935,11 @@ int amdgpu_ras_save_bad_pages(struct
 amdgpu_device *adev)
        if (!con || !con->eh_data)
                return 0;
 
+       mutex_lock(&con->recovery_lock);
        control = &con->eeprom_control;
        data = con->eh_data;
        save_count = data->count - control->ras_num_recs;
+       mutex_unlock(&con->recovery_lock);
        /* only new entries are saved */
        if (save_count > 0) {

if (amdgpu_ras_eeprom_append(control,
--
2.17.1

Thanks,
Candice

-----Original Message-----
From: Zhou1, Tao <[email protected]>
Sent: Tuesday, November 16, 2021 4:27 PM
To: Li, Candice <[email protected]>; [email protected]
Cc: Clements, John <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Add recovery_lock to save bad pages function

[AMD Official Use Only]

Quoted 34 lines

-----Original Message-----
From: Li, Candice <[email protected]>
Sent: Tuesday, November 16, 2021 4:02 PM
To: [email protected]
Cc: Clements, John <[email protected]>; Zhou1, Tao <[email protected]>; Li, Candice <[email protected]>
Subject: [PATCH] drm/amdgpu: Add recovery_lock to save bad pages function

Fix race condition failure during UMC UE injection.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -0
index 08133de21fdd63..711b5fb26d47d4 100644
@@ -1931,10 +1931,12 @@ int amdgpu_ras_save_bad_pages(struct
 amdgpu_device *adev)
      struct ras_err_handler_data *data;
      struct amdgpu_ras_eeprom_control *control;
      int save_count;
+     int ret = 0;
 
      if (!con || !con->eh_data)
              return 0;
 
+     mutex_lock(&con->recovery_lock);
      control = &con->eeprom_control;
      data = con->eh_data;
Quoted 1 line
      save_count = data->count - control->ras_num_recs; @@ -1944,13

[Tao] Since recovery_lock is dedicated to protecting eh_data, can we unlock it here?

Quoted 23 lines

+1946,16 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)

                                           &data->bps[control->ras_num_recs],
                                           save_count)) {
                      dev_err(adev->dev, "Failed to save EEPROM table

data!");

drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -1
-                     return -EIO;
+                     ret = -EIO;
+                     goto out;
              }
 
              dev_info(adev->dev, "Saved %d pages to EEPROM table.\n",
save_count);
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +3 -2
-     return 0;
+out:
+     mutex_unlock(&con->recovery_lock);
+     return ret;
 }
 
 /*
--

2.17.1