drm/amdgpu: split ras_eeprom_init into init and check functions
Subsystems (2)
PATCH 1/2 drm/amdgpu: split ras_eeprom_init into init and check functions
Init function is for ras table header read and check function is responsible for the validation of the header. Call them in different stages.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 15 ++++++++++---- .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c | 20 +++++++++++++++++++ .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +11 -4
@@ -3006,9 +3006,20 @@ static int amdgpu_ras_load_bad_pages(struct amdgpu_device *adev) control->rec_type =AMDGPU_RAS_EEPROM_REC_MCA ; } + ret =amdgpu_ras_eeprom_check (control); +if (ret) + goto out; + +/* HW not usable */ +if (amdgpu_ras_is_rma (adev)) { + ret = -EHWPOISON ; + goto out; + } + ret =amdgpu_ras_add_bad_pages (adev, bps, control->ras_num_recs, true); } +out:kfree (bps);return ret; }
@@ -3407,10 +3418,6 @@ int amdgpu_ras_init_badpage_info(struct amdgpu_device *adev)if (ret)return ret; -/* HW not usable */ -if (amdgpu_ras_is_rma (adev)) -return -EHWPOISON ; -if (!adev->umc.ras || !adev->umc.ras->convert_ras_err_addr) control->rec_type =AMDGPU_RAS_EEPROM_REC_PA ;
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +20 -0
@@ -1382,6 +1382,26 @@ int amdgpu_ras_eeprom_init(struct amdgpu_ras_eeprom_control *control) } control->ras_fri =RAS_OFFSET_TO_INDEX (control, hdr->first_rec_offset); +return res <0 ? res :0 ; +} + +int amdgpu_ras_eeprom_check (struct amdgpu_ras_eeprom_control *control) +{ +struct amdgpu_device *adev =to_amdgpu_device (control); +struct amdgpu_ras_eeprom_table_header *hdr = &control->tbl_hdr; +struct amdgpu_ras *ras =amdgpu_ras_get_context (adev); +int res; + +if (!__is_ras_eeprom_supported (adev)) +return 0 ; + +/* Verify i2c adapter is initialized */ +if (!adev->pm.ras_eeprom_i2c_bus || !adev->pm.ras_eeprom_i2c_bus->algo) +return -ENOENT ; + +if (!__get_eeprom_i2c_addr (adev, control)) +return -EINVAL ; +if (hdr->header ==RAS_TABLE_HDR_VAL ) {DRM_DEBUG_DRIVER ("Found existing EEPROM table with %d records" , control->ras_num_recs);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h +2 -0
@@ -159,6 +159,8 @@ uint32_t amdgpu_ras_eeprom_max_record_count(struct amdgpu_ras_eeprom_control *covoid amdgpu_ras_debugfs_set_ret_size (struct amdgpu_ras_eeprom_control *control); +int amdgpu_ras_eeprom_check (struct amdgpu_ras_eeprom_control *control); +extern const struct file_operations amdgpu_ras_debugfs_eeprom_size_ops;extern const struct file_operations amdgpu_ras_debugfs_eeprom_table_ops;
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdgpu: correct the calculation of RAS bad page
After the introduction of NPS RAS, one bad page record on eeprom may be related to 1 or 16 bad pages, so the bad page record and bad page are two different concepts, define a new variable to store bad page number.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 10 +---- .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c | 40 +++++++++++++------ .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h | 5 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 2 +- 4 files changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -8
@@ -2934,13 +2934,7 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev,mutex_lock (&con->recovery_lock); control = &con->eeprom_control; data = con->eh_data; - bad_page_num = control->ras_num_recs; -/* one record on eeprom stands for all pages in one memory row -* in this mode -*/ -if (control->rec_type ==AMDGPU_RAS_EEPROM_REC_MCA ) - bad_page_num = control->ras_num_recs * adev->umc.retire_unit; - + bad_page_num = control->ras_num_bad_pages; save_count = data->count - bad_page_num;mutex_unlock (&con->recovery_lock);
@@ -3432,7 +3426,7 @@ int amdgpu_ras_init_badpage_info(struct amdgpu_device *adev)return ret;amdgpu_dpm_send_hbm_bad_pages_num ( - adev, control->ras_num_recs); + adev, control->ras_num_bad_pages);if (con->update_channel_flag == true) { amdgpu_dpm_send_hbm_bad_channel_flag(
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +27 -13
@@ -470,9 +470,10 @@ int amdgpu_ras_eeprom_reset_table(struct amdgpu_ras_eeprom_control *control) res =__write_table_ras_info (control); control->ras_num_recs =0 ; + control->ras_num_bad_pages =0 ; control->ras_fri =0 ; -amdgpu_dpm_send_hbm_bad_pages_num (adev, control->ras_num_recs); +amdgpu_dpm_send_hbm_bad_pages_num (adev, control->ras_num_bad_pages); control->bad_channel_bitmap =0 ;amdgpu_dpm_send_hbm_bad_channel_flag (adev, control->bad_channel_bitmap);
@@ -559,7 +560,7 @@ bool amdgpu_ras_eeprom_check_err_threshold(struct amdgpu_device *adev)if (con->eeprom_control.tbl_hdr.header ==RAS_TABLE_HDR_BAD ) {if (amdgpu_bad_page_threshold ==-1 ) {dev_warn (adev->dev,"RAS records:%d exceed threshold:%d" , - con->eeprom_control.ras_num_recs, con->bad_page_cnt_threshold); + con->eeprom_control.ras_num_bad_pages, con->bad_page_cnt_threshold);dev_warn (adev->dev,"But GPU can be operated due to bad_page_threshold = -1.\n" );return false;
@@ -621,6 +622,7 @@ amdgpu_ras_eeprom_append_table(struct amdgpu_ras_eeprom_control *control, const u32 num) {struct amdgpu_ras *con =amdgpu_ras_get_context (to_amdgpu_device (control)); +struct amdgpu_device *adev =to_amdgpu_device (control);u32 a, b, i;u8 *buf, *pp;int res;
@@ -723,6 +725,12 @@ amdgpu_ras_eeprom_append_table(struct amdgpu_ras_eeprom_control *control, control->ras_num_recs =1 + (control->ras_max_record_count + b - control->ras_fri) % control->ras_max_record_count; + +if (control->rec_type ==AMDGPU_RAS_EEPROM_REC_PA ) + control->ras_num_bad_pages = control->ras_num_recs; +else + control->ras_num_bad_pages = + control->ras_num_recs * adev->umc.retire_unit; Out:kfree (buf);return res;
@@ -740,10 +748,10 @@ amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)/* Modify the header if it exceeds. */ if (amdgpu_bad_page_threshold !=0 && - control->ras_num_recs >= ras->bad_page_cnt_threshold) { + control->ras_num_bad_pages >= ras->bad_page_cnt_threshold) {dev_warn (adev->dev,"Saved bad pages %d reaches threshold value %d\n" , - control->ras_num_recs, ras->bad_page_cnt_threshold); + control->ras_num_bad_pages, ras->bad_page_cnt_threshold); control->tbl_hdr.header =RAS_TABLE_HDR_BAD ;if (control->tbl_hdr.version ==RAS_TABLE_VER_V2_1 ) { control->tbl_rai.rma_status =GPU_RETIRED__ECC_REACH_THRESHOLD ;
@@ -798,9 +806,9 @@ amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)*/ if (amdgpu_bad_page_threshold !=0 && control->tbl_hdr.version ==RAS_TABLE_VER_V2_1 && - control->ras_num_recs < ras->bad_page_cnt_threshold) + control->ras_num_bad_pages < ras->bad_page_cnt_threshold) control->tbl_rai.health_percent = ((ras->bad_page_cnt_threshold - - control->ras_num_recs) *100 ) / + control->ras_num_bad_pages) *100 ) / ras->bad_page_cnt_threshold;/* Recalc the checksum.
@@ -1402,9 +1410,15 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)if (!__get_eeprom_i2c_addr (adev, control))return -EINVAL ; +if (control->rec_type ==AMDGPU_RAS_EEPROM_REC_PA ) + control->ras_num_bad_pages = control->ras_num_recs; +else + control->ras_num_bad_pages = + control->ras_num_recs * adev->umc.retire_unit; +if (hdr->header ==RAS_TABLE_HDR_VAL ) {DRM_DEBUG_DRIVER ("Found existing EEPROM table with %d records" , - control->ras_num_recs); + control->ras_num_bad_pages);if (hdr->version ==RAS_TABLE_VER_V2_1 ) { res =__read_table_ras_info (control);
@@ -1419,9 +1433,9 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)/* Warn if we are at 90% of the threshold or above */ -if (10 * control->ras_num_recs >=9 * ras->bad_page_cnt_threshold) +if (10 * control->ras_num_bad_pages >=9 * ras->bad_page_cnt_threshold)dev_warn (adev->dev,"RAS records:%u exceeds 90%% of threshold:%d" , - control->ras_num_recs, + control->ras_num_bad_pages, ras->bad_page_cnt_threshold); }else if (hdr->header ==RAS_TABLE_HDR_BAD && amdgpu_bad_page_threshold !=0 ) {
@@ -1435,7 +1449,7 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)if (res)DRM_ERROR ("RAS Table incorrect checksum or error:%d\n" , res); -if (ras->bad_page_cnt_threshold > control->ras_num_recs) { +if (ras->bad_page_cnt_threshold > control->ras_num_bad_pages) {/* This means that, the threshold was increased since * the last time the system was booted, and now, * ras->bad_page_cnt_threshold - control->num_recs > 0,
@@ -1445,13 +1459,13 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)dev_info (adev->dev,"records:%d threshold:%d, resetting " "RAS table header signature" , - control->ras_num_recs, + control->ras_num_bad_pages, ras->bad_page_cnt_threshold); res =amdgpu_ras_eeprom_correct_header_tag (control,RAS_TABLE_HDR_VAL ); }else {dev_err (adev->dev,"RAS records:%d exceed threshold:%d" , - control->ras_num_recs, ras->bad_page_cnt_threshold); + control->ras_num_bad_pages, ras->bad_page_cnt_threshold);if (amdgpu_bad_page_threshold ==-1 ) {dev_warn (adev->dev,"GPU will be initialized due to bad_page_threshold = -1." ); res =0 ;
@@ -1460,7 +1474,7 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)dev_err (adev->dev,"RAS records:%d exceed threshold:%d, " "GPU will not be initialized. Replace this GPU or increase the threshold" , - control->ras_num_recs, ras->bad_page_cnt_threshold); + control->ras_num_bad_pages, ras->bad_page_cnt_threshold); } } }else {
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h +5 -0
@@ -95,6 +95,11 @@ struct amdgpu_ras_eeprom_control {*/ u32 ras_num_recs; +/* the bad page number is ras_num_recs or +* ras_num_recs * umc.retire_unit +*/ +u32 ras_num_bad_pages; +/* First record index to read, 0-based. * Range is [0, num_recs-1]. This is * an absolute index, starting right after
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +1 -1
@@ -169,7 +169,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev, err_data->err_addr_cnt, false);amdgpu_ras_save_bad_pages (adev, &err_count); -amdgpu_dpm_send_hbm_bad_pages_num (adev, con->eeprom_control.ras_num_recs); +amdgpu_dpm_send_hbm_bad_pages_num (adev, con->eeprom_control.ras_num_bad_pages);if (con->update_channel_flag == true) {amdgpu_dpm_send_hbm_bad_channel_flag (adev, con->eeprom_control.bad_channel_bitmap);
Signature · 1 line
2.34.1
RE: [PATCH 2/2] drm/amdgpu: correct the calculation of RAS bad page
[AMD Official Use Only - AMD Internal Distribution Only]
Series is
Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Tao Zhou
Sent: Monday, December 2, 2024 18:25
To: [email protected]
Cc: Zhou1, Tao <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: correct the calculation of RAS bad page
After the introduction of NPS RAS, one bad page record on eeprom may be related to 1 or 16 bad pages, so the bad page record and bad page are two different concepts, define a new variable to store bad page number.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 10 +---- .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c | 40 +++++++++++++------ .../gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h | 5 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 2 +- 4 files changed, 35 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +2 -8
@@ -2934,13 +2934,7 @@ int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev,mutex_lock (&con->recovery_lock); control = &con->eeprom_control; data = con->eh_data; - bad_page_num = control->ras_num_recs; -/* one record on eeprom stands for all pages in one memory row -* in this mode -*/ -if (control->rec_type ==AMDGPU_RAS_EEPROM_REC_MCA ) - bad_page_num = control->ras_num_recs * adev->umc.retire_unit; - + bad_page_num = control->ras_num_bad_pages; save_count = data->count - bad_page_num;mutex_unlock (&con->recovery_lock);
@@ -3432,7 +3426,7 @@ int amdgpu_ras_init_badpage_info(struct amdgpu_device *adev)return ret;amdgpu_dpm_send_hbm_bad_pages_num ( - adev, control->ras_num_recs); + adev, control->ras_num_bad_pages);if (con->update_channel_flag == true) { amdgpu_dpm_send_hbm_bad_channel_flag(
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +2 -1
@@ -470,9 +470,10 @@ int amdgpu_ras_eeprom_reset_table(struct amdgpu_ras_eeprom_control *control) res =__write_table_ras_info (control); control->ras_num_recs =0 ; + control->ras_num_bad_pages =0 ; control->ras_fri =0 ; -amdgpu_dpm_send_hbm_bad_pages_num (adev, control->ras_num_recs); +amdgpu_dpm_send_hbm_bad_pages_num (adev, control->ras_num_bad_pages); control->bad_channel_bitmap =0 ; amdgpu_dpm_send_hbm_bad_channel_flag(adev, control->bad_channel_bitmap); @@ -559,7 +560,7 @@ bool amdgpu_ras_eeprom_check_err_threshold(struct amdgpu_device *adev)
if (con->eeprom_control.tbl_hdr.header == RAS_TABLE_HDR_BAD) {
if (amdgpu_bad_page_threshold == -1) {
dev_warn(adev->dev, "RAS records:%d exceed threshold:%d",
- con->eeprom_control.ras_num_recs, con->bad_page_cnt_threshold);
+ con->eeprom_control.ras_num_bad_pages,
+con->bad_page_cnt_threshold);
dev_warn(adev->dev,
"But GPU can be operated due to bad_page_threshold = -1.\n");
return false;
@@ -621,6 +622,7 @@ amdgpu_ras_eeprom_append_table(struct amdgpu_ras_eeprom_control *control,
const u32 num)
{
struct amdgpu_ras *con = amdgpu_ras_get_context(to_amdgpu_device(control));
+ struct amdgpu_device *adev = to_amdgpu_device(control);
u32 a, b, i;
u8 *buf, *pp;
int res;
@@ -723,6 +725,12 @@ amdgpu_ras_eeprom_append_table(struct amdgpu_ras_eeprom_control *control,
control->ras_num_recs = 1 + (control->ras_max_record_count + b
- control->ras_fri)
% control->ras_max_record_count;+
+ if (control->rec_type == AMDGPU_RAS_EEPROM_REC_PA)
+ control->ras_num_bad_pages = control->ras_num_recs;
+ else
+ control->ras_num_bad_pages =
+ control->ras_num_recs * adev->umc.retire_unit;
Out:
kfree(buf);
return res;
@@ -740,10 +748,10 @@ amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)
/* Modify the header if it exceeds.
*/
if (amdgpu_bad_page_threshold != 0 &&- control->ras_num_recs >= ras->bad_page_cnt_threshold) {
+ control->ras_num_bad_pages >= ras->bad_page_cnt_threshold) {
dev_warn(adev->dev,
"Saved bad pages %d reaches threshold value %d\n",
- control->ras_num_recs, ras->bad_page_cnt_threshold);
+ control->ras_num_bad_pages, ras->bad_page_cnt_threshold);
control->tbl_hdr.header = RAS_TABLE_HDR_BAD;
if (control->tbl_hdr.version == RAS_TABLE_VER_V2_1) {
control->tbl_rai.rma_status = GPU_RETIRED__ECC_REACH_THRESHOLD; @@ -798,9 +806,9 @@ amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)
*/
if (amdgpu_bad_page_threshold != 0 &&
control->tbl_hdr.version == RAS_TABLE_VER_V2_1 &&
- control->ras_num_recs < ras->bad_page_cnt_threshold)
+ control->ras_num_bad_pages < ras->bad_page_cnt_threshold)
control->tbl_rai.health_percent = ((ras->bad_page_cnt_threshold -
- control->ras_num_recs) * 100) /
+ control->ras_num_bad_pages) * 100) /
ras->bad_page_cnt_threshold;
/* Recalc the checksum.
@@ -1402,9 +1410,15 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
if (!__get_eeprom_i2c_addr(adev, control))
return -EINVAL;+ if (control->rec_type == AMDGPU_RAS_EEPROM_REC_PA)
+ control->ras_num_bad_pages = control->ras_num_recs;
+ else
+ control->ras_num_bad_pages =
+ control->ras_num_recs * adev->umc.retire_unit;
+
if (hdr->header == RAS_TABLE_HDR_VAL) {
DRM_DEBUG_DRIVER("Found existing EEPROM table with %d records",
- control->ras_num_recs);
+ control->ras_num_bad_pages);
if (hdr->version == RAS_TABLE_VER_V2_1) {
res = __read_table_ras_info(control); @@ -1419,9 +1433,9 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
/* Warn if we are at 90% of the threshold or above
*/
- if (10 * control->ras_num_recs >= 9 * ras->bad_page_cnt_threshold)
+ if (10 * control->ras_num_bad_pages >= 9 *
+ras->bad_page_cnt_threshold)
dev_warn(adev->dev, "RAS records:%u exceeds 90%% of threshold:%d",
- control->ras_num_recs,
+ control->ras_num_bad_pages,
ras->bad_page_cnt_threshold);
} else if (hdr->header == RAS_TABLE_HDR_BAD &&
amdgpu_bad_page_threshold != 0) {@@ -1435,7 +1449,7 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
if (res)
DRM_ERROR("RAS Table incorrect checksum or error:%d\n",
res);
- if (ras->bad_page_cnt_threshold > control->ras_num_recs) {
+ if (ras->bad_page_cnt_threshold > control->ras_num_bad_pages) {
/* This means that, the threshold was increased since
* the last time the system was booted, and now,
* ras->bad_page_cnt_threshold - control->num_recs > 0, @@ -1445,13 +1459,13 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
dev_info(adev->dev,
"records:%d threshold:%d, resetting "
"RAS table header signature",
- control->ras_num_recs,
+ control->ras_num_bad_pages,
ras->bad_page_cnt_threshold);
res = amdgpu_ras_eeprom_correct_header_tag(control,
RAS_TABLE_HDR_VAL);
} else {
dev_err(adev->dev, "RAS records:%d exceed threshold:%d",
- control->ras_num_recs, ras->bad_page_cnt_threshold);
+ control->ras_num_bad_pages, ras->bad_page_cnt_threshold);
if (amdgpu_bad_page_threshold == -1) {
dev_warn(adev->dev, "GPU will be initialized due to bad_page_threshold = -1.");
res = 0;@@ -1460,7 +1474,7 @@ int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
dev_err(adev->dev,
"RAS records:%d exceed threshold:%d, "
"GPU will not be initialized. Replace this GPU or increase the threshold",
- control->ras_num_recs, ras->bad_page_cnt_threshold);
+ control->ras_num_bad_pages, ras->bad_page_cnt_threshold);
}
}
} else {drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.h +5 -0
@@ -95,6 +95,11 @@ struct amdgpu_ras_eeprom_control {*/ u32 ras_num_recs; +/* the bad page number is ras_num_recs or +* ras_num_recs * umc.retire_unit +*/ +u32 ras_num_bad_pages; +/* First record index to read, 0-based. * Range is [0, num_recs-1]. This is * an absolute index, starting right after diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c
index 1881bcd040c7..cffe22b86118 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c +2 -1
@@ -169,7 +169,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev, err_data->err_addr_cnt, false);amdgpu_ras_save_bad_pages (adev, &err_count); -amdgpu_dpm_send_hbm_bad_pages_num (adev, con->eeprom_control.ras_num_recs); +amdgpu_dpm_send_hbm_bad_pages_num (adev, +con->eeprom_control.ras_num_bad_pages);if (con->update_channel_flag == true) {
amdgpu_dpm_send_hbm_bad_channel_flag(adev, con->eeprom_control.bad_channel_bitmap);
--
2.34.1