Skip to contentSkip to conversation

RAS support for GC 12.1 devices

PATCH In review Alex Deucher 2 participants 111 messages Aug 14 – Aug 15 Page 2 of 2

Subsystems (3)
lore
Share & tools
lore
author maintainer
#94 lore raw

PATCH 94/109 drm/amd/ras: populate cper aca register info for rma device

In reply to Alex Deucher

From: YiPeng Chai <[email protected]>

Populate cper aca register info for rma device.

---
 drivers/gpu/drm/amd/ras/core/aca.c          | 14 ++++++++++
 drivers/gpu/drm/amd/ras/core/aca.h          |  2 ++
 drivers/gpu/drm/amd/ras/core/aca_v1_0.c     | 26 ++++++++++++++++++
 drivers/gpu/drm/amd/ras/core/log_ring.c     | 30 ++++++++-------------
 drivers/gpu/drm/amd/ras/core/ras_aca_v5_0.c | 22 +++++++++++++++
 5 files changed, 75 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/ras/core/aca.c +14 -0
index 60a435ae92c9a..0f5e57965ac86 100644
@@ -691,3 +691,17 @@ u64 ras_aca_get_parser_caps(struct ras_core_context *ras_core)
 
 	return 0;
 }
+
+int ras_aca_fill_rma_bank(struct ras_core_context *ras_core,
+			struct aca_bank_reg *bank)
+{
+	struct ras_aca *ras_aca = &ras_core->ras_aca;
+
+	if (!bank)
+		return -EINVAL;
+
+	if (ras_aca->ip_func && ras_aca->ip_func->fill_rma_bank)
+		return ras_aca->ip_func->fill_rma_bank(ras_core, bank);
+
+	return -EOPNOTSUPP;
+}
drivers/gpu/drm/amd/ras/core/aca.h +2 -0
index 518351fe187aa..52acf19fac11a 100644
@@ -145,6 +145,7 @@ struct ras_aca_ip_func {
 	uint32_t block_num;
 	const struct aca_block_info **block_info;
 	u64 (*aca_parse_ras_caps)(struct ras_core_context *ras_core);
+	int (*fill_rma_bank)(struct ras_core_context *ras_core, struct aca_bank_reg *bank);
 };
 
 struct ras_aca {
@@ -170,4 +171,5 @@ int ras_aca_parse_bank(struct ras_core_context *ras_core,
 				struct aca_bank_reg *bank,
 				struct aca_bank_ecc *ecc);
 u64 ras_aca_get_parser_caps(struct ras_core_context *ras_core);
+int ras_aca_fill_rma_bank(struct ras_core_context *ras_core, struct aca_bank_reg *bank);
 #endif
drivers/gpu/drm/amd/ras/core/aca_v1_0.c +26 -0
index 1f0ad3e502da1..a4145f30f45f3 100644
@@ -384,8 +384,34 @@ static u64 aca_parse_ras_caps_v1_0(struct ras_core_context *ras_core)
 	return parser_supported_mask;
 }
 
+static int aca_fill_rma_bank_v1_0(struct ras_core_context *ras_core, struct aca_bank_reg *bank)
+{
+	struct device_system_info dev_info = {0};
+	u64 socket_id;
+	int ret;
+
+	if (!bank)
+		return -EINVAL;
+
+	ret = ras_core_get_device_system_info(ras_core, &dev_info);
+	if (ret)
+		return ret;
+
+	socket_id = dev_info.socket_id;
+
+	memset(bank->regs, 0, sizeof(bank->regs));
+	bank->regs[ACA_REG_IDX__CTL]    = 0x1ULL;
+	bank->regs[ACA_REG_IDX__STATUS] = 0xB000000000000137ULL;
+	bank->regs[ACA_REG_IDX__CONFG]  = 0x1ff00000002ULL;
+	bank->regs[ACA_REG_IDX__IPID]   = 0x9600000000ULL |
+		((socket_id / 4) & 0x01) | (((socket_id % 4) & 0x3) << 44);
+
+	return 0;
+}
+
 const struct ras_aca_ip_func ras_aca_func_v1_0 = {
 	.block_num = ARRAY_SIZE(aca_block_info_v1_0),
 	.block_info = aca_block_info_v1_0,
 	.aca_parse_ras_caps = aca_parse_ras_caps_v1_0,
+	.fill_rma_bank = aca_fill_rma_bank_v1_0,
 };
drivers/gpu/drm/amd/ras/core/log_ring.c +11 -19
index fb42449fbd6c4..e57f7ea3f3079 100644
@@ -32,16 +32,6 @@
 
 #define BATCH_IDX_TO_TREE_IDX(batch_idx, sn) (((batch_idx) << 8) | (sn))
 
-static const uint64_t ras_rma_aca_reg[ACA_REG_MAX_COUNT] = {
-	[ACA_REG_IDX__CTL]    = 0x1,
-	[ACA_REG_IDX__STATUS] = 0xB000000000000137,
-	[ACA_REG_IDX__ADDR]   = 0x0,
-	[ACA_REG_IDX__MISC0]  = 0x0,
-	[ACA_REG_IDX__CONFG] = 0x1ff00000002,
-	[ACA_REG_IDX__IPID]   = 0x9600000000,
-	[ACA_REG_IDX__SYND]   = 0x0,
-};
-
 static uint64_t ras_log_ring_get_logged_ecc_count(struct ras_core_context *ras_core)
 {
 	struct ras_log_ring *log_ring = &ras_core->ras_log_ring;
@@ -227,9 +217,8 @@ int ras_log_ring_add_log_event(struct ras_core_context *ras_core,
 		void *data, uint32_t size, struct ras_log_batch_tag *batch_tag)
 {
 	struct ras_log_ring *log_ring = &ras_core->ras_log_ring;
-	struct device_system_info dev_info = {0};
 	struct ras_log_info *log;
-	uint64_t socket_id;
+	struct aca_bank_reg *rma_bank;
 	void *obj;
 
 	if (size > sizeof(union ras_log_body)) {
@@ -263,13 +252,16 @@ int ras_log_ring_add_log_event(struct ras_core_context *ras_core,
 		log->size = size;
 	}
 
-	if (event == RAS_LOG_EVENT_RMA) {
-		memcpy(&log->body.aca_reg, ras_rma_aca_reg, sizeof(log->body.aca_reg));
-		ras_core_get_device_system_info(ras_core, &dev_info);
-		socket_id = dev_info.socket_id;
-		log->body.aca_reg.regs[ACA_REG_IDX__IPID] |= ((socket_id / 4) & 0x01);
-		log->body.aca_reg.regs[ACA_REG_IDX__IPID] |= (((socket_id % 4) & 0x3) << 44);
-		log->size = sizeof(log->body.aca_reg);
+	if ((event == RAS_LOG_EVENT_RMA) && !data && !size) {
+		rma_bank = kzalloc_obj(*rma_bank);
+		if (rma_bank && !ras_aca_fill_rma_bank(ras_core, rma_bank)) {
+			memcpy(log->body.aca_reg.regs,
+				rma_bank->regs, sizeof(log->body.aca_reg.regs));
+			log->size = sizeof(log->body.aca_reg);
+		} else {
+			RAS_DEV_WARN(ras_core->dev, "Failed to fill rma bank info!\n");
+		}
+		kfree(rma_bank);
 	}
 
 	return ras_log_ring_add_data(ras_core, log, batch_tag);
drivers/gpu/drm/amd/ras/core/ras_aca_v5_0.c +22 -0
index 52036ca7a39af..e35f96c3ac350 100644
@@ -348,8 +348,30 @@ static u64 aca_parse_ras_caps_v5_0(struct ras_core_context *ras_core)
 	return parser_supported_mask;
 }
 
+static int aca_fill_rma_bank_v5_0(struct ras_core_context *ras_core, struct aca_bank_reg *bank)
+{
+	struct device_system_info dev_info = {0};
+	int ret;
+
+	if (!bank)
+		return -EINVAL;
+
+	ret = ras_core_get_device_system_info(ras_core, &dev_info);
+	if (ret)
+		return ret;
+
+	memset(bank->regs, 0, sizeof(bank->regs));
+	bank->regs[ACA_REG_IDX__CTL]    = 0x1ULL;
+	bank->regs[ACA_REG_IDX__STATUS] = 0xB000000000000137ULL;
+	bank->regs[ACA_REG_IDX__CONFG]  = 0x1ff00000002ULL;
+	bank->regs[ACA_REG_IDX__IPID]   = 0x9600000000ULL | (dev_info.socket_id & 0xFF);
+
+	return 0;
+}
+
 const struct ras_aca_ip_func ras_aca_func_v5_0 = {
 	.block_num = ARRAY_SIZE(aca_block_info_v5_0),
 	.block_info = aca_block_info_v5_0,
 	.aca_parse_ras_caps = aca_parse_ras_caps_v5_0,
+	.fill_rma_bank = aca_fill_rma_bank_v5_0,
 };
Signature · 1 line
2.55.0
author maintainer
#95 lore raw

PATCH 95/109 drm/amd/ras: filter out invalid pages from extended page addresses

In reply to Alex Deucher

From: YiPeng Chai <[email protected]>

Filter out invalid pages from extended page addresses.

---
 drivers/gpu/drm/amd/ras/core/ras_umc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/ras/core/ras_umc.c +9 -4
index 299426d6d8318..4cce9f5c65932 100644
@@ -233,7 +233,8 @@ static int ras_umc_expand_row_pages(struct ras_core_context *ras_core,
 
 	row_pa = retired_addr & ~(flip_mask);
 
-	if (count < nr_page_pfns)
+	if ((count < nr_page_pfns) &&
+	    !ras_core_check_address_sanity(ras_core, row_pa))
 		page_pfns[count++] = RAS_ADDR_TO_PFN(row_pa);
 
 	subset = flip_mask;
@@ -243,7 +244,8 @@ static int ras_umc_expand_row_pages(struct ras_core_context *ras_core,
 		if (count >= nr_page_pfns)
 			break;
 
-		page_pfns[count++] = RAS_ADDR_TO_PFN(addr);
+		if (!ras_core_check_address_sanity(ras_core, addr))
+			page_pfns[count++] = RAS_ADDR_TO_PFN(addr);
 
 		subset = (subset - 1) & flip_mask;
 	};
@@ -271,7 +273,7 @@ int ras_umc_convert_record_to_row_pages(struct ras_core_context *ras_core,
 	}
 
 	count = ras_umc_expand_row_pages(ras_core, record, page_pfns, nr_page_pfns);
-	if (count > 0)
+	if (count >= 0)
 		record->cur_nps_valid_page_num = count;
 
 	return count;
@@ -656,10 +658,13 @@ static int ras_umc_update_eeprom_ram_data(struct ras_core_context *ras_core,
 	struct eeprom_store_record *data = &ras_umc->umc_err_data.ram_data;
 	int j;
 
-	if (!bps || !page_pfns || !nr_page_pfns ||
+	if (!bps || !page_pfns ||
 		(nr_page_pfns > ras_umc->max_pages_per_row))
 		return -EINVAL;
 
+	if (!nr_page_pfns)
+		return 0;
+
 	if (!data->space_left &&
 		ras_umc_realloc_err_data_space(ras_core, data, 256))
 		return -ENOMEM;
Signature · 1 line
2.55.0
author maintainer
#96 lore raw

PATCH 96/109 drm/amd/ras: fix and improve bad page count calculation

In reply to Alex Deucher

From: YiPeng Chai <[email protected]>

Fix an issue where the saved bad page count is always zero.

The cur_nps_valid_page_num field in the record already tracks the available bad page count, so use it directly to calculate the correct saved bad page number.

---
 drivers/gpu/drm/amd/ras/core/ras_umc.c | 32 +++++++++++++-------------
 drivers/gpu/drm/amd/ras/core/ras_umc.h |  6 -----
 2 files changed, 16 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/ras/core/ras_umc.c +16 -16
index 4cce9f5c65932..3e546e7fde59b 100644
@@ -683,14 +683,6 @@ static int ras_umc_update_eeprom_ram_data(struct ras_core_context *ras_core,
 	return 0;
 }
 
-static void ras_umc_update_bad_pages(struct ras_core_context *ras_core)
-{
-	struct ras_umc *ras_umc = &ras_core->ras_umc;
-	struct eeprom_store_record *data = &ras_umc->umc_err_data.ram_data;
-
-	data->bad_page_num_old = data->bad_page_num;
-}
-
 void ras_umc_report_badpage_info(struct ras_core_context *ras_core)
 {
 	struct ras_umc *ras_umc = &ras_core->ras_umc;
@@ -797,15 +789,24 @@ int ras_umc_load_bad_pages(struct ras_core_context *ras_core)
 	if (ret)
 		RAS_DEV_ERR(ras_core->dev,
 			"Failed to load EEPROM table records! ret:%d\n", ret);
-	else {
+	else
 		ret = ras_umc_add_bad_pages(ras_core, bps, ras_num_recs, &c);
-		ras_umc_update_bad_pages(ras_core);
-	}
 
 	kfree(bps);
 	return ret;
 }
 
+static int ras_umc_count_valid_pages(struct ras_core_context *ras_core,
+		struct eeprom_umc_record *records, const u32 nr_records)
+{
+	int count = 0, i;
+
+	for (i = 0; i < nr_records; i++)
+		count += records[i].cur_nps_valid_page_num;
+
+	return count;
+}
+
 /*
  * write error record array to eeprom, the function should be
  * protected by recovery_lock
@@ -815,8 +816,7 @@ static int ras_umc_save_bad_pages(struct ras_core_context *ras_core)
 {
 	struct ras_umc *ras_umc = &ras_core->ras_umc;
 	struct eeprom_store_record *data = &ras_umc->umc_err_data.rom_data;
-	struct eeprom_store_record *ram_data = &ras_umc->umc_err_data.ram_data;
-	int eeprom_record_num, logical_count = 0;
+	int eeprom_record_num;
 	int save_count;
 	int ret = -ENODATA;
 
@@ -833,7 +833,6 @@ static int ras_umc_save_bad_pages(struct ras_core_context *ras_core)
 
 	mutex_lock(&ras_umc->umc_lock);
 	save_count = data->count - eeprom_record_num;
-	logical_count = ram_data->bad_page_num - ram_data->bad_page_num_old;
 	/* only new entries are saved */
 	if (save_count > 0) {
 		ret = ras_eeprom_mgr_append_records(ras_core,
@@ -845,8 +844,9 @@ static int ras_umc_save_bad_pages(struct ras_core_context *ras_core)
 			goto exit;
 		}
 
-		ras_umc_update_bad_pages(ras_core);
-		RAS_DEV_INFO(ras_core->dev, "Saved %d records to EEPROM table.\n", logical_count);
+		RAS_DEV_INFO(ras_core->dev, "Saved %d pages to EEPROM table.\n",
+			ras_umc_count_valid_pages(ras_core,
+				&data->bps[eeprom_record_num], save_count));
 	}
 
 exit:
drivers/gpu/drm/amd/ras/core/ras_umc.h +0 -6
index 362c9ce6a404b..db480d15aad43 100644
@@ -151,12 +151,6 @@ struct eeprom_store_record {
 	int count;
 	/* the space can place new entries */
 	int space_left;
-	/* logical bad page number */
-	int bad_page_num;
-	/* the bad page number is ras_num_recs or
-	 * ras_num_recs * retire_unit
-	 */
-	int bad_page_num_old;
 	uint64_t umc_channel_bitmap;
 };
 
Signature · 1 line
2.55.0
author maintainer
#97 lore raw

PATCH 97/109 drm/amd/ras: increase page buffer size for A+A

In reply to Alex Deucher

From: YiPeng Chai <[email protected]>

Increase page buffer size for A+A.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 38 +++++++++++++++++--------
 1 file changed, 26 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +26 -12
index 263ac4b2ab582..c3bc71e1c9ff4 100644
@@ -219,8 +219,9 @@ static int amdgpu_check_address_validity(struct amdgpu_device *adev,
 {
 	struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
 	struct amdgpu_vram_block_info blk_info;
-	uint64_t page_pfns[32] = {0};
-	int i, ret, count;
+	uint64_t *page_pfns = NULL;
+	u32 nr_page_pfns = 256;
+	int i, ret = 0, count;
 	bool hit = false;
 
 	if (amdgpu_ip_version(adev, UMC_HWIP, 0) < IP_VERSION(12, 0, 0))
@@ -243,15 +244,21 @@ static int amdgpu_check_address_validity(struct amdgpu_device *adev,
 	    (address >= RAS_UMC_INJECT_ADDR_LIMIT))
 		return -EFAULT;
 
+	page_pfns = kcalloc(nr_page_pfns, sizeof(*page_pfns), GFP_KERNEL);
+	if (!page_pfns)
+		return -ENOMEM;
+
 	if (amdgpu_sriov_vf(adev))
 		count = amdgpu_virt_ras_convert_retired_address(adev, address,
-			page_pfns, ARRAY_SIZE(page_pfns));
+			page_pfns, nr_page_pfns);
 	else
 		count = amdgpu_ras_mgr_lookup_bad_pages_in_a_row(adev, address,
-			page_pfns, ARRAY_SIZE(page_pfns));
+			page_pfns, nr_page_pfns);
 
-	if (count <= 0)
-		return -EPERM;
+	if (count <= 0) {
+		ret = -EPERM;
+		goto out;
+	}
 
 	for (i = 0; i < count; i++) {
 		memset(&blk_info, 0, sizeof(blk_info));
@@ -264,16 +271,23 @@ static int amdgpu_check_address_validity(struct amdgpu_device *adev,
 			 */
 			if ((flags == BYPASS_ALLOCATED_ADDRESS) &&
 			    ((blk_info.task.pid != task_pid_nr(current)) ||
-				strncmp(blk_info.task.comm, current->comm, TASK_COMM_LEN)))
-				return -EACCES;
-			else if ((flags == BYPASS_INITIALIZATION_ADDRESS) &&
+				strncmp(blk_info.task.comm, current->comm, TASK_COMM_LEN))) {
+				ret = -EACCES;
+				goto out;
+			} else if ((flags == BYPASS_INITIALIZATION_ADDRESS) &&
 				(blk_info.task.pid == con->init_task_pid) &&
-				!strncmp(blk_info.task.comm, con->init_task_comm, TASK_COMM_LEN))
-				return -EACCES;
+				!strncmp(blk_info.task.comm, con->init_task_comm, TASK_COMM_LEN)) {
+				ret = -EACCES;
+				goto out;
+			}
 		}
 	}
 
-	return 0;
+	ret = 0;
+
+out:
+	kfree(page_pfns);
+	return ret;
 }
 
 static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
Signature · 1 line
2.55.0
author maintainer
#98 lore raw

PATCH 98/109 drm/amd/ras: move BERT boot errors to BERT sw init

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

Keep BERT boot-error handling owned by the BERT module instead of letting the MCE notifier lifecycle drive BERT processing and cleanup.

Group the cached boot-error state into a single structure so the related poll result, raw record data, per-socket write tracking, and lock are managed together.

Expose only the standard BERT sw_init/sw_fini entry points. The RAS manager calls them around the existing MCE sw lifecycle, while the MCE code no longer includes BERT headers or calls BERT helpers directly.

This lets BERT process cached boot records earlier in the RAS manager sw_init path and release its cached state independently during sw_fini.

---
 .../gpu/drm/amd/ras/ras_mgr/amdgpu_ras_bert.c | 95 ++++++++++++-------
 .../gpu/drm/amd/ras/ras_mgr/amdgpu_ras_bert.h |  6 +-
 .../gpu/drm/amd/ras/ras_mgr/amdgpu_ras_mce.c  |  7 --
 .../gpu/drm/amd/ras/ras_mgr/amdgpu_ras_mgr.c  |  5 +
 4 files changed, 68 insertions(+), 45 deletions(-)
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_bert.c +61 -34
index 29111b10b00a3..04490f5173c41 100644
@@ -31,15 +31,23 @@
 
 #include "amdgpu_ras_mgr.h"
 
-static DEFINE_MUTEX(boot_err_lock);
-static bool boot_err_polled, boot_err_written[MAX_GPU_INSTANCE];
-static int boot_err_poll_result;
-static u8 *boot_err_raw_data;
-static u32 boot_err_raw_data_len;
-
-int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
+struct amdgpu_ras_bert_boot_err_state {
+	struct mutex lock; /* protects cached boot error state */
+	bool polled;
+	bool written[MAX_GPU_INSTANCE];
+	int poll_result;
+	u8 *raw_data;
+	u32 raw_data_len;
+};
+
+static struct amdgpu_ras_bert_boot_err_state boot_err_state = {
+	.lock = __MUTEX_INITIALIZER(boot_err_state.lock),
+};
+
+static int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 {
 	struct amdgpu_ras_mgr *ras_mgr = amdgpu_ras_mgr_get_context(adev);
+	struct amdgpu_ras_bert_boot_err_state *state = &boot_err_state;
 	struct acpi_bert_region *boot_error_region;
 	struct acpi_table_header *table;
 	struct acpi_table_bert *bert_tab;
@@ -51,11 +59,11 @@ int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 	if (!ras_mgr || !ras_mgr->ras_core)
 		return -EPERM;
 
-	mutex_lock(&boot_err_lock);
+	mutex_lock(&state->lock);
 
-	if (!boot_err_polled) {
-		boot_err_polled = true;
-		boot_err_poll_result = 0;
+	if (!state->polled) {
+		state->polled = true;
+		state->poll_result = 0;
 		ret = 0;
 
 		if (acpi_disabled)
@@ -67,7 +75,7 @@ int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 
 		if (ACPI_FAILURE(status)) {
 			RAS_DEV_ERR(adev, "get table failed, %s.\n", acpi_format_exception(status));
-			boot_err_poll_result = -EINVAL;
+			state->poll_result = -EINVAL;
 			goto out_unlock;
 		}
 		bert_tab = (struct acpi_table_bert *)table;
@@ -75,36 +83,36 @@ int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 		if (bert_tab->header.length < sizeof(struct acpi_table_bert) ||
 		    bert_tab->region_length < sizeof(struct acpi_bert_region)) {
 			RAS_DEV_ERR(adev, "table invalid.\n");
-			boot_err_poll_result = -EINVAL;
+			state->poll_result = -EINVAL;
 			goto out_put_bert_tab;
 		}
 
 		region_len = bert_tab->region_length;
 		boot_error_region = acpi_os_map_memory(bert_tab->address, region_len);
 		if (boot_error_region) {
-			boot_err_raw_data = kmemdup(boot_error_region, region_len, GFP_KERNEL);
+			state->raw_data = kmemdup(boot_error_region, region_len, GFP_KERNEL);
 			acpi_os_unmap_memory(boot_error_region, region_len);
-			if (!boot_err_raw_data) {
+			if (!state->raw_data) {
 				RAS_DEV_ERR(adev, "failed to cache BERT raw data.\n");
-				boot_err_poll_result = -ENOMEM;
+				state->poll_result = -ENOMEM;
 			} else {
-				boot_err_raw_data_len = region_len;
+				state->raw_data_len = region_len;
 			}
 		} else {
 			RAS_DEV_ERR(adev, "failed to map BERT region.\n");
-			boot_err_poll_result = -ENOMEM;
+			state->poll_result = -ENOMEM;
 		}
 
 out_put_bert_tab:
 		acpi_put_table(table);
 	}
 
-	if (boot_err_poll_result) {
-		ret = boot_err_poll_result;
+	if (state->poll_result) {
+		ret = state->poll_result;
 		goto out_unlock;
 	}
 
-	if (!boot_err_raw_data || !boot_err_raw_data_len ||
+	if (!state->raw_data || !state->raw_data_len ||
 	    !(adev && (adev->gmc.xgmi.connected_to_cpu || adev->gmc.is_app_apu))) {
 		ret = 0;
 		goto out_unlock;
@@ -122,31 +130,50 @@ int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 		goto out_unlock;
 	}
 
-	if (boot_err_written[socket_id]) {
+	if (state->written[socket_id]) {
 		ret = 0;
 		goto out_unlock;
 	}
 
 	ret = ras_bert_process_records(ras_mgr->ras_core,
-				       boot_err_raw_data, boot_err_raw_data_len);
+				       state->raw_data, state->raw_data_len);
 	if (!ret)
-		boot_err_written[socket_id] = true;
+		state->written[socket_id] = true;
 
 out_unlock:
-	mutex_unlock(&boot_err_lock);
+	mutex_unlock(&state->lock);
 
 	return ret;
 }
 
-void amdgpu_ras_bert_reset_boot_errors(void)
+static void amdgpu_ras_bert_reset_boot_errors(void)
 {
-	mutex_lock(&boot_err_lock);
-	memset(boot_err_written, 0, sizeof(boot_err_written));
-	kfree(boot_err_raw_data);
-	boot_err_raw_data = NULL;
-	boot_err_raw_data_len = 0;
-	boot_err_poll_result = 0;
-	boot_err_polled = false;
-	mutex_unlock(&boot_err_lock);
+	struct amdgpu_ras_bert_boot_err_state *state = &boot_err_state;
+
+	mutex_lock(&state->lock);
+	memset(state->written, 0, sizeof(state->written));
+	kfree(state->raw_data);
+	state->raw_data = NULL;
+	state->raw_data_len = 0;
+	state->poll_result = 0;
+	state->polled = false;
+	mutex_unlock(&state->lock);
 }
 #endif
+
+int amdgpu_ras_bert_sw_init(struct amdgpu_device *adev)
+{
+#if defined(CONFIG_X86_MCE_AMD) && defined(CONFIG_ACPI_APEI)
+	return amdgpu_ras_bert_process_boot_errors(adev);
+#else
+	return 0;
+#endif
+}
+
+int amdgpu_ras_bert_sw_fini(struct amdgpu_device *adev)
+{
+#if defined(CONFIG_X86_MCE_AMD) && defined(CONFIG_ACPI_APEI)
+	amdgpu_ras_bert_reset_boot_errors();
+#endif
+	return 0;
+}
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_bert.h +2 -4
index 27e2378ea5f3a..e56aa143ad952 100644
@@ -24,9 +24,7 @@
 #ifndef __AMDGPU_RAS_BERT_H__
 #define __AMDGPU_RAS_BERT_H__
 
-#if defined(CONFIG_X86_MCE_AMD) && defined(CONFIG_ACPI_APEI)
-int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev);
-void amdgpu_ras_bert_reset_boot_errors(void);
-#endif
+int amdgpu_ras_bert_sw_init(struct amdgpu_device *adev);
+int amdgpu_ras_bert_sw_fini(struct amdgpu_device *adev);
 
 #endif
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_mce.c +0 -7
index 97ef50149fdf9..bc7a44618ac6c 100644
@@ -23,7 +23,6 @@
  */
 
 #include "amdgpu.h"
-#include "amdgpu_ras_bert.h"
 #include "amdgpu_ras_mgr.h"
 #include "amdgpu_ras_mce.h"
 #include <asm/mce.h>
@@ -123,9 +122,6 @@ static int amdgpu_ras_unregister_mce_notifier(struct amdgpu_device *adev)
 	if (atomic_read(&mce_mgr->ref_count) <= 0) {
 		atomic_set(&mce_mgr->dev_count, 0);
 		mce_unregister_decode_chain(&mce_mgr->nb);
-#ifdef CONFIG_ACPI_APEI
-		amdgpu_ras_bert_reset_boot_errors();
-#endif
 	}
 
 	return 0;
@@ -243,9 +239,6 @@ static int amdgpu_ras_mce_notifier(struct amdgpu_device *adev,
 
 int amdgpu_ras_mce_hw_init(struct amdgpu_device *adev)
 {
-#if defined(CONFIG_X86_MCE_AMD) && defined(CONFIG_ACPI_APEI)
-	amdgpu_ras_bert_process_boot_errors(adev);
-#endif
 	return 0;
 }
 
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_mgr.c +5 -0
index bda1f76d2dbf9..64622b593ab94 100644
@@ -33,6 +33,7 @@
 #include "amdgpu_ras_mp1_v13_0.h"
 #include "amdgpu_ras_mp1.h"
 #include "amdgpu_ras_nbio_v7_9.h"
+#include "amdgpu_ras_bert.h"
 #include "amdgpu_ras_mce.h"
 
 #define MAX_AID_NUM_PER_SOCKET_GFX9     4
@@ -356,6 +357,7 @@ int amdgpu_ras_mgr_sw_init(struct amdgpu_device *adev, struct ras_module_param *
 		goto err2;
 	}
 	amdgpu_ras_mgr_init_event_mgr(ras_mgr->ras_core);
+	amdgpu_ras_bert_sw_init(adev);
 	amdgpu_ras_mce_sw_init(adev);
 
 	if (amdgpu_sriov_vf(adev)) {
@@ -370,6 +372,8 @@ int amdgpu_ras_mgr_sw_init(struct amdgpu_device *adev, struct ras_module_param *
 	return 0;
 
 err3:
+	amdgpu_ras_mce_sw_fini(adev);
+	amdgpu_ras_bert_sw_fini(adev);
 	if (ras_mgr->ras_core)
 		ras_core_sw_fini(ras_mgr->ras_core);
 err2:
@@ -398,6 +402,7 @@ int amdgpu_ras_mgr_sw_fini(struct amdgpu_device *adev)
 		amdgpu_virt_ras_sw_fini(adev);
 
 	amdgpu_ras_mce_sw_fini(adev);
+	amdgpu_ras_bert_sw_fini(adev);
 	amdgpu_ras_process_fini(adev);
 	ras_core_sw_fini(ras_mgr->ras_core);
 	ras_core_destroy(ras_mgr->ras_core);
Signature · 1 line
2.55.0
author maintainer
#99 lore raw

PATCH 99/109 drm/amd/ras: allow waking RAS processing without an event

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

GPU MCE handling queues bank data directly in the MCE FIFO and only needs to wake the RAS processing thread. Requiring a separate event request prevents this path from scheduling processing when no event object is available.

Permit a NULL request to skip event queue insertion while still incrementing the interrupt request count and waking the processing thread.

---
 drivers/gpu/drm/amd/ras/core/ras_process.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/ras/core/ras_process.c +8 -5
index 395d10c94b195..f313f2021f243 100644
@@ -311,13 +311,16 @@ static int ras_process_add_non_umc_interrupt_req(struct ras_core_context *ras_co
 	struct ras_process *ras_proc = &ras_core->ras_proc;
 	int ret;
 
-	ret = ras_process_put_event(ras_core, req);
-	if (!ret) {
-		atomic_inc(&ras_proc->ras_interrupt_req);
-		wake_up(&ras_proc->ras_process_wq);
+	if (req) {
+		ret = ras_process_put_event(ras_core, req);
+		if (ret)
+			return ret;
 	}
 
-	return ret;
+	atomic_inc(&ras_proc->ras_interrupt_req);
+	wake_up(&ras_proc->ras_process_wq);
+
+	return 0;
 }
 
 int ras_process_add_interrupt_req(struct ras_core_context *ras_core,
Signature · 1 line
2.55.0
Reviewed-by on v1 99/109
#100 lore raw

RE: [PATCH 099/109] drm/amd/ras: allow waking RAS processing without an event

AMD General

Patch #99 ~ #109 are

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Saturday, August 15, 2026 5:03 AM
To: [email protected]
Cc: Liu, Xiang(Dean) <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH 099/109] drm/amd/ras: allow waking RAS processing without an event

From: Xiang Liu <[email protected]>

GPU MCE handling queues bank data directly in the MCE FIFO and only needs to wake the RAS processing thread. Requiring a separate event request prevents this path from scheduling processing when no event object is available.

Permit a NULL request to skip event queue insertion while still incrementing the interrupt request count and waking the processing thread.

---
 drivers/gpu/drm/amd/ras/core/ras_process.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/ras/core/ras_process.c +8 -5
index 395d10c94b195..f313f2021f243 100644
@@ -311,13 +311,16 @@ static int ras_process_add_non_umc_interrupt_req(struct ras_core_context *ras_co
        struct ras_process *ras_proc = &ras_core->ras_proc;
        int ret;
 
-       ret = ras_process_put_event(ras_core, req);
-       if (!ret) {
-               atomic_inc(&ras_proc->ras_interrupt_req);
-               wake_up(&ras_proc->ras_process_wq);
+       if (req) {
+               ret = ras_process_put_event(ras_core, req);
+               if (ret)
+                       return ret;
        }
 
-       return ret;
+       atomic_inc(&ras_proc->ras_interrupt_req);
+       wake_up(&ras_proc->ras_process_wq);
+
+       return 0;
 }
 
 int ras_process_add_interrupt_req(struct ras_core_context *ras_core,

--
2.55.0

author maintainer
#101 lore raw

PATCH 100/109 drm/amd/ras: classify ACA v5 MCE status

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

Machine-check records may not carry the hardware-maintained UMC error count expected by the normal polling path. As a result, valid deferred, uncorrected, and corrected MCE status values can remain unclassified.

For MCE-originated banks, classify the error directly from the MCA status bits when normal UMC decoding does not produce an error count.

---
 drivers/gpu/drm/amd/ras/core/ras_aca_v5_0.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/ras/core/ras_aca_v5_0.c +17 -0
index e35f96c3ac350..fe3942f54afc5 100644
@@ -174,6 +174,11 @@ static int aca_parse_umc_bank(struct ras_core_context *ras_core,
 
 	ext_error_code = ACA_V5_REG_STATUS_ERRORCODEEXT(status);
 	misc0_errcnt = ACA_V5_REG_MISC0_ERRCNT(bank->regs[ACA_REG_IDX__MISC0]);
+	if (bank->ecc_type == RAS_ERR_TYPE__MCE &&
+	    ACA_V5_REG_STATUS_DEFERRED(status)) {
+		err->de_count = 1;
+		return 0;
+	}
 
 	if (aca_check_umc_de(ras_core, status))
 		err->de_count = misc0_errcnt ? misc0_errcnt : 1;
@@ -182,6 +187,18 @@ static int aca_parse_umc_bank(struct ras_core_context *ras_core,
 	else if (aca_check_umc_ce(ras_core, status))
 		err->ce_count = ext_error_code ? 1 : misc0_errcnt;
 
+	if (bank->ecc_type != RAS_ERR_TYPE__MCE || err->de_count ||
+	    err->ue_count || err->ce_count)
+		return 0;
+
+	if (ACA_V5_REG_STATUS_DEFERRED(status))
+		err->de_count = 1;
+	else if (ACA_V5_REG_STATUS_UC(status) || ACA_V5_REG_STATUS_PCC(status) ||
+		 ACA_V5_REG_STATUS_TCC(status))
+		err->ue_count = 1;
+	else if (ACA_V5_REG_STATUS_CECC(status) || ACA_V5_REG_STATUS_UECC(status))
+		err->ce_count = 1;
+
 	return 0;
 }
 
Signature · 1 line
2.55.0
author maintainer
#102 lore raw

PATCH 101/109 drm/amd/ras: preserve CPU MCE context in the log ring

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

Processor CPER generation needs the APIC ID and machine-check bank number in addition to the ACA register values. Logging the full internal ACA bank also exceeds the stable fixed-size log body representation.

Carry the APIC ID and bank number with incoming ACA banks and store CPU MCE events in a compact 128-byte log context for later CPER encoding.

---
 drivers/gpu/drm/amd/ras/core/aca.h      |  2 ++
 drivers/gpu/drm/amd/ras/core/log_ring.h | 21 ++++++++++++++++++++-
 drivers/gpu/drm/amd/ras/core/ras_mce.c  |  9 +++++++--
 3 files changed, 29 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/ras/core/aca.h +2 -0
index 52acf19fac11a..759119bed870c 100644
@@ -54,6 +54,8 @@ struct aca_bank_reg {
 	uint64_t timestamp;
 	u32 bank_type;
 	u32 ecc_type;
+	u32 apic_id;
+	u32 bank;
 	u64 seq_no;
 	u64 regs[ACA_REG_MAX_COUNT];
 };
drivers/gpu/drm/amd/ras/core/log_ring.h +20 -1
index ed68664bf3c68..2d8e40c971062 100644
@@ -48,16 +48,35 @@ struct ras_aca_reg {
 	uint64_t regs[ACA_REG_MAX_COUNT];
 };
 
+struct ras_cpu_mce {
+	u64 regs[ACA_REG_MAX_COUNT - 1];
+	u32 apic_id;
+	u16 bank;
+	u16 reserved;
+};
+
+#define RAS_CPER_BOOT_RAW_DATA_SIZE	80
+#define RAS_BOOT_CTX_VALID_APIC_ID	BIT(0)
+
 struct ras_boot_err_ctx {
 	u8 section_type[16];
 	u32 error_severity;
 	u16 reg_ctx_type;
 	u16 reg_arr_size;
-	u64 regs[CPER_OAM_MAX_COUNT];
+	u32 msr_addr;
+	u16 raw_data_size;
+	u16 flags;
+	u64 apic_id;
+	u64 mm_reg_addr;
+	union {
+		u64 regs[CPER_OAM_MAX_COUNT];
+		u8 raw_data[RAS_CPER_BOOT_RAW_DATA_SIZE];
+	};
 };
 
 union ras_log_body {
 	struct ras_aca_reg aca_reg;
+	struct ras_cpu_mce cpu_mce;
 	struct ras_boot_err_ctx boot_err_ctx;
 };
 
drivers/gpu/drm/amd/ras/core/ras_mce.c +7 -2
index 018429e397979..71281917b132a 100644
@@ -70,7 +70,7 @@ static int ras_mce_add_gpu_bank(struct ras_core_context *ras_core,
 	ret = kfifo_in_spinlocked(&mce->mce_fifo,
 			aca_bank, sizeof(*aca_bank), &mce->mce_fifo_lock);
 	if (ret)
-		ras_process_add_interrupt_req(ras_core, NULL, true);
+		ras_process_add_interrupt_req(ras_core, NULL, false);
 
 	return ret ? 0 : -ENOSPC;
 }
@@ -78,9 +78,14 @@ static int ras_mce_add_gpu_bank(struct ras_core_context *ras_core,
 static int ras_mce_log_cpu_bank(struct ras_core_context *ras_core,
 			struct aca_bank_reg *aca_bank)
 {
+	struct ras_cpu_mce cpu_mce = {
+		.apic_id = aca_bank->apic_id,
+		.bank = aca_bank->bank,
+	};
 
+	memcpy(cpu_mce.regs, aca_bank->regs, sizeof(cpu_mce.regs));
 	ras_log_ring_add_log_event(ras_core,
-		RAS_LOG_EVENT_CPU_RAS, aca_bank, sizeof(*aca_bank), NULL);
+		RAS_LOG_EVENT_CPU_RAS, &cpu_mce, sizeof(cpu_mce), NULL);
 
 	return 0;
 }
Signature · 1 line
2.55.0
author maintainer
#103 lore raw

PATCH 102/109 drm/amd/ras: define processor and memory CPER formats

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

CPU machine-check and platform boot errors require standard processor and Platform Memory section definitions. The AMD crashdump format also uses a 64-byte common header followed by a common error information structure.

Add the required GUIDs, validity fields, processor structures, and AMD crashdump wire layout so rascore can generate each record type.

---
 drivers/gpu/drm/amd/ras/core/ras_cper.h | 99 +++++++++++++++++++++++--
 1 file changed, 93 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/ras/core/ras_cper.h +93 -6
index f69f4e4de9ec9..58d2955ec08dc 100644
@@ -38,8 +38,10 @@ struct ras_cper_guid {
 		(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}
 
 #define CPER_HDR__REV_1          (0x100)
+#define CPER_HDR__REV_AMD_CPU    (0x101)
 #define CPER_SEC__MINOR_REV_1    (0x01)
 #define CPER_SEC__MAJOR_REV_22   (0x22)
+#define CPER_SEC__REV_AMD_CPU    (0x0100)
 #define CPER_OAM_MAX_COUNT      (8)
 
 #define CPER_CTX_TYPE__CRASH     (1)
@@ -68,6 +70,43 @@ struct ras_cper_guid {
 #define PROC_ERR__SECTION_TYPE                                         \
 	CPER_GUID__INIT(0xDC3EA0B0, 0xA144, 0x4797, 0xB9, 0x5B, 0x53, 0xFA, \
 		  0x24, 0x2B, 0x6E, 0x1D)
+#define PROC_ERR__MS_CHECK_TYPE                                        \
+	CPER_GUID__INIT(0x48AB7F57, 0xDC34, 0x4F6C, 0xA7, 0xD3, 0xB0, 0xB5, \
+		  0xB0, 0xA7, 0x43, 0x14)
+#define PLATFORM_MEM__SECTION_TYPE                                     \
+	CPER_GUID__INIT(0xA5BC1114, 0x6F64, 0x4EDE, 0xB8, 0x63, 0x3E, 0x83, \
+		  0xED, 0x7C, 0x83, 0xB1)
+#define PCIE_ERR__SECTION_TYPE                                         \
+	CPER_GUID__INIT(0xD995E954, 0xBBC1, 0x430F, 0xAD, 0x91, 0xB4, 0x4D, \
+		  0xCB, 0x3C, 0x6F, 0x35)
+#define SMN_ERR__SECTION_TYPE                                          \
+	CPER_GUID__INIT(0xA2860CC1, 0x8987, 0x4B7C, 0xB8, 0x6A, 0xD5, 0x08, \
+		  0xB1, 0x76, 0xBA, 0x70)
+
+#define CPER_PROC_VALID_APIC_ID		BIT_ULL(0)
+#define CPER_PROC_ERR_INFO_COUNT(x)	(((u64)(x) & 0x3f) << 2)
+#define CPER_PROC_CONTEXT_COUNT(x)	(((u64)(x) & 0x3f) << 8)
+#define CPER_AMD_CONTEXT_COUNT(x)	(((u64)(x) & 0x3f) << 8)
+#define CPER_AMD_ERR_INFO_COUNT(x)	(((u64)(x) & 0x3f) << 2)
+
+#define CPER_PROC_INFO_VALID_CHECK_INFO	BIT_ULL(0)
+
+#define CPER_MS_CHECK_VALID_ERR_TYPE	BIT_ULL(0)
+#define CPER_MS_CHECK_VALID_PCC		BIT_ULL(1)
+#define CPER_MS_CHECK_VALID_UNCORRECTED	BIT_ULL(2)
+#define CPER_MS_CHECK_VALID_OVERFLOW	BIT_ULL(5)
+#define CPER_MS_CHECK_ERR_TYPE_INTERNAL	(5ULL << 16)
+#define CPER_MS_CHECK_PCC		BIT_ULL(19)
+#define CPER_MS_CHECK_UNCORRECTED	BIT_ULL(20)
+#define CPER_MS_CHECK_OVERFLOW		BIT_ULL(23)
+
+#define CPER_MCA_STATUS_OVERFLOW	BIT_ULL(62)
+#define CPER_MCA_STATUS_UNCORRECTED	BIT_ULL(61)
+#define CPER_MCA_STATUS_PCC		BIT_ULL(57)
+#define CPER_MCA_STATUS_DEFERRED	BIT_ULL(44)
+
+#define CPER_SMCA_MC0_STATUS_MSR	(0xc0002001U)
+#define CPER_SMCA_BANK_STRIDE		(0x10U)
 
 enum ras_cper_type {
 	RAS_CPER_TYPE_RUNTIME,
@@ -238,10 +277,10 @@ struct cper_section_runtime {
 };
 
 struct crashdump_hdr {
-	uint64_t reserved1;
-	uint64_t reserved2;
+	u64 valid_bits;
+	u32 pcie_device_id;
+	u32 pldm_bundle;
 	char     fw_id[48];
-	uint64_t reserved3[8];
 };
 
 struct fatal_reg_info {
@@ -267,16 +306,56 @@ struct crashdump_boot {
 	uint64_t msg[CPER_OAM_MAX_COUNT];
 };
 
+struct crashdump_error_info {
+	struct ras_cper_guid error_type;
+	u64 valid_bits;
+	u64 check_info;
+	u8 fru_part_number[16];
+	u8 redfish_event_id[16];
+};
+
 struct cper_section_fatal {
-	struct crashdump_hdr    hdr;
-	struct crashdump_fatal  data;
+	struct crashdump_hdr hdr;
+	struct crashdump_error_info error_info;
+	struct crashdump_fatal data;
 };
 
 struct cper_section_boot {
-	struct crashdump_hdr  hdr;
+	struct crashdump_hdr hdr;
+	struct crashdump_error_info error_info;
 	struct crashdump_boot data;
 };
 
+struct cper_processor_section {
+	u64 valid_bits;
+	u64 apic_id;
+	u8 cpuid[48];
+};
+
+struct cper_processor_error_info {
+	struct ras_cper_guid error_type;
+	u64 valid_bits;
+	u64 check_info;
+	u64 target_id;
+	u64 requester_id;
+	u64 responder_id;
+	u64 instruction_pointer;
+};
+
+struct cper_processor_context {
+	u16 reg_ctx_type;
+	u16 reg_arr_size;
+	u32 msr_addr;
+	u64 mm_reg_addr;
+	u64 reg_dump[RAS_CPER_ACA_REG_COUNT];
+};
+
+struct cper_section_processor {
+	struct cper_processor_section processor;
+	struct cper_processor_error_info error_info;
+	struct cper_processor_context context;
+};
+
 struct ras_cper_fatal_record {
 	struct cper_section_hdr hdr;
 	struct cper_section_desc descriptor;
@@ -288,6 +367,13 @@ struct ras_cper_boot_record {
 	struct cper_section_desc descriptor;
 	struct cper_section_boot boot;
 };
+
+struct ras_cper_processor_record {
+	struct cper_section_hdr hdr;
+	struct cper_section_desc descriptor;
+	struct cper_section_processor processor;
+};
+
 #pragma pack(pop)
 
 struct ras_core_context;
@@ -334,6 +420,7 @@ struct ras_cper {
 #define RAS_BOOT_SEC_LEN			(sizeof(struct cper_section_boot))
 #define RAS_FATAL_SEC_LEN			(sizeof(struct cper_section_fatal))
 #define RAS_NONSTD_SEC_LEN			(sizeof(struct cper_section_runtime))
+#define RAS_PROC_SEC_LEN			(sizeof(struct cper_section_processor))
 
 #define RAS_SEC_DESC_OFFSET(idx)		(RAS_HDR_LEN + (RAS_SEC_DESC_LEN * idx))
 
Signature · 1 line
2.55.0
author maintainer
#104 lore raw

PATCH 103/109 drm/amd/ras: generate AMD crashdump CPER records

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

Populate the AMD crashdump common header and error information before serializing fatal and boot records.

Validate that batched boot records share a section type, clamp the register context to the crashdump payload, and account for each record header when sizing the output.

Keep AMD record dispatch in a dedicated helper so processor and Platform Memory generation can be added independently.

---
 drivers/gpu/drm/amd/ras/core/ras_cper.c | 26 ++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/ras/core/ras_cper.c +23 -3
index 03240715b4aaf..eee4e0373c3bd 100644
@@ -113,6 +113,9 @@ static int fill_section_fatal(struct ras_core_context *ras_core, void *section,
 {
 	struct cper_section_fatal *fatal = section;
 
+	fatal->hdr.valid_bits = CPER_AMD_ERR_INFO_COUNT(1) |
+		CPER_AMD_CONTEXT_COUNT(1);
+	fatal->error_info.error_type = GPU__NONSTANDARD_ERROR;
 	fatal->data.reg_ctx_type = CPER_CTX_TYPE__CRASH;
 	fatal->data.reg_arr_size = sizeof(fatal->data.reg);
 
@@ -167,11 +170,15 @@ static int fill_section_boot(struct ras_core_context *ras_core, void *section,
 	struct cper_section_boot *boot = section;
 	struct ras_boot_err_ctx *ctx = &log->body.boot_err_ctx;
 	struct crashdump_boot *data = &boot->data;
+	u16 data_size;
 
+	boot->hdr.valid_bits = CPER_AMD_ERR_INFO_COUNT(1) |
+		CPER_AMD_CONTEXT_COUNT(1);
+	boot->error_info.error_type = GPU__NONSTANDARD_ERROR;
 	data->reg_ctx_type = ctx->reg_ctx_type;
-	data->reg_arr_size = ctx->reg_arr_size;
-	memcpy(data->msg, ctx->regs,
-		min(boot->data.reg_arr_size, sizeof(data->msg)));
+	data_size = min_t(u16, ctx->reg_arr_size, sizeof(data->msg));
+	data->reg_arr_size = data_size;
+	memcpy(data->msg, ctx->regs, data_size);
 
 	return 0;
 }
@@ -327,10 +334,23 @@ int ras_cper_generate_batch_cper(struct ras_core_context *ras_core,
 
 		/* MCE is encoded as 1 record each */
 		memcpy(&bank.regs, &batch_logs[0].body.aca_reg.regs, sizeof(bank.regs));
+		bank.ecc_type = RAS_ERR_TYPE__MCE;
 		event = cper_mce_parse_err_type(ras_core, &bank);
 		batch_logs[0].event = event;
 	}
 
+	if (event == RAS_LOG_EVENT_BOOT) {
+		uint32_t i;
+
+		for (i = 1; i < nr_batch_logs; i++) {
+			if (batch_logs[i].event != RAS_LOG_EVENT_BOOT ||
+			    memcmp(batch_logs[i].body.boot_err_ctx.section_type,
+				   batch_logs[0].body.boot_err_ctx.section_type,
+				   CPER_UUID_MAX_SIZE))
+				return -EINVAL;
+		}
+	}
+
 	mutex_lock(&cper->profile_mutex);
 	/* All the batch logs share the same event */
 	ret = ras_cper_get_profile(ras_core, event, &profile);
Signature · 1 line
2.55.0
author maintainer
#105 lore raw

PATCH 104/109 drm/amd/ras: generate processor CPER records

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

Encode runtime CPU machine checks with the standard IA Processor section, including APIC ID, machine-check status, bank MSR address, and SMCA register context.

Also preserve IA Processor sections recovered from BERT as boot-notified records with their original context metadata and variable payload size.

Route both forms through a processor-specific generator so they remain separate from AMD crashdump records.

---
 drivers/gpu/drm/amd/ras/core/ras_cper.c | 212 ++++++++++++++++++++++++
 1 file changed, 212 insertions(+)
drivers/gpu/drm/amd/ras/core/ras_cper.c +212 -0
index eee4e0373c3bd..1bbc2c3247c25 100644
@@ -27,6 +27,9 @@
 #include "ras_cper.h"
 #define ns_to_seconds(ns)   div_u64(ns, NSEC_PER_SEC)
 
+static const struct ras_cper_guid processor_section_type =
+	PROC_ERR__SECTION_TYPE;
+
 static int ras_cper_get_profile(struct ras_core_context *ras_core,
 		enum ras_log_event event, struct ras_cper_profile **profile);
 
@@ -183,6 +186,79 @@ static int fill_section_boot(struct ras_core_context *ras_core, void *section,
 	return 0;
 }
 
+static void fill_processor_error_info(struct cper_processor_error_info *error_info,
+		u64 status)
+{
+	u64 check_info = CPER_MS_CHECK_VALID_ERR_TYPE |
+		CPER_MS_CHECK_ERR_TYPE_INTERNAL;
+
+	error_info->error_type = PROC_ERR__MS_CHECK_TYPE;
+	error_info->valid_bits = CPER_PROC_INFO_VALID_CHECK_INFO;
+
+	if (status & CPER_MCA_STATUS_PCC)
+		check_info |= CPER_MS_CHECK_VALID_PCC | CPER_MS_CHECK_PCC;
+	if (status & CPER_MCA_STATUS_UNCORRECTED)
+		check_info |= CPER_MS_CHECK_VALID_UNCORRECTED |
+			CPER_MS_CHECK_UNCORRECTED;
+	if (status & CPER_MCA_STATUS_OVERFLOW)
+		check_info |= CPER_MS_CHECK_VALID_OVERFLOW |
+			CPER_MS_CHECK_OVERFLOW;
+
+	error_info->check_info = check_info;
+}
+
+static int fill_section_processor(struct cper_section_processor *processor,
+		struct ras_log_info *log)
+{
+	const struct ras_cpu_mce *mce = &log->body.cpu_mce;
+	u64 status = mce->regs[RAS_CPER_ACA_REG_STATUS];
+	u64 *reg_dump = processor->context.reg_dump;
+
+	processor->processor.valid_bits = CPER_PROC_VALID_APIC_ID |
+		CPER_PROC_ERR_INFO_COUNT(1) | CPER_PROC_CONTEXT_COUNT(1);
+	processor->processor.apic_id = mce->apic_id;
+	fill_processor_error_info(&processor->error_info, status);
+	processor->context.reg_ctx_type = CPER_CTX_TYPE__CRASH;
+	processor->context.reg_arr_size = sizeof(processor->context.reg_dump);
+	processor->context.msr_addr = CPER_SMCA_MC0_STATUS_MSR +
+		(mce->bank * CPER_SMCA_BANK_STRIDE);
+	/* The IA processor register array starts at MCA_STATUS. */
+	reg_dump[0] = mce->regs[ACA_REG_IDX__STATUS];
+	reg_dump[1] = mce->regs[ACA_REG_IDX__ADDR];
+	reg_dump[2] = mce->regs[ACA_REG_IDX__MISC0];
+	reg_dump[3] = mce->regs[ACA_REG_IDX__CONFG];
+	reg_dump[4] = mce->regs[ACA_REG_IDX__IPID];
+	reg_dump[5] = mce->regs[ACA_REG_IDX__SYND];
+	reg_dump[7] = mce->regs[ACA_REG_IDX__DESTAT];
+	reg_dump[8] = mce->regs[ACA_REG_IDX__DEADDR];
+	reg_dump[9] = mce->regs[ACA_REG_IDX__CTL_MASK];
+
+	return 0;
+}
+
+static int fill_section_boot_processor(struct cper_section_processor *processor,
+		struct ras_log_info *log)
+{
+	const struct ras_boot_err_ctx *ctx = &log->body.boot_err_ctx;
+	u64 status = ctx->regs[0];
+
+	processor->processor.valid_bits = CPER_PROC_ERR_INFO_COUNT(1) |
+		CPER_PROC_CONTEXT_COUNT(1);
+	if (ctx->flags & RAS_BOOT_CTX_VALID_APIC_ID)
+		processor->processor.valid_bits |= CPER_PROC_VALID_APIC_ID;
+	processor->processor.apic_id = ctx->apic_id;
+	fill_processor_error_info(&processor->error_info, status);
+	processor->context.reg_ctx_type = ctx->reg_ctx_type;
+	processor->context.reg_arr_size = ctx->reg_arr_size;
+	processor->context.msr_addr = ctx->msr_addr;
+	processor->context.mm_reg_addr = ctx->mm_reg_addr;
+	memcpy(processor->context.reg_dump, ctx->regs,
+		min_t(size_t, ctx->reg_arr_size,
+		      sizeof(processor->context.reg_dump)));
+
+	return 0;
+}
+
 static int cper_boot_get_severity(struct ras_log_info *log,
 			enum ras_cper_severity *sev)
 {
@@ -293,6 +369,139 @@ static int cper_build_multiple_records(struct ras_core_context *ras_core,
 	return 0;
 }
 
+static int cper_generate_boot_processor_records(struct ras_core_context *ras_core,
+		u8 *buffer, struct ras_log_info *batch_logs, u32 nr_batch_logs)
+{
+	u32 offset = 0;
+	u32 i;
+
+	for (i = 0; i < nr_batch_logs; i++) {
+		const struct ras_boot_err_ctx *ctx = &batch_logs[i].body.boot_err_ctx;
+		struct ras_cper_processor_record record = { 0 };
+		u16 data_size = min_t(u16, ctx->reg_arr_size,
+					 sizeof(record.processor.context.reg_dump));
+		u32 section_size = offsetof(struct cper_section_processor,
+					    context.reg_dump) + data_size;
+		u32 record_size = RAS_HDR_LEN + RAS_SEC_DESC_LEN + section_size;
+		enum ras_cper_severity sev = ctx->error_severity;
+
+		fill_section_hdr(ras_core, &record.hdr, BOOT__TYPE, sev,
+				 &batch_logs[i]);
+		record.hdr.record_length = record_size;
+		record.hdr.sec_cnt = 1;
+		fill_section_descriptor(ras_core, &record.descriptor, sev,
+				PROC_ERR__SECTION_TYPE,
+				offsetof(struct ras_cper_processor_record, processor),
+				section_size);
+		fill_section_boot_processor(&record.processor, &batch_logs[i]);
+		memcpy(buffer + offset, &record, record_size);
+		offset += record_size;
+	}
+
+	return offset;
+}
+
+static int cper_generate_runtime_processor_records(struct ras_core_context *ras_core,
+		u8 *buffer, struct ras_log_info *batch_logs, u32 nr_batch_logs)
+{
+	u32 i;
+
+	for (i = 0; i < nr_batch_logs; i++) {
+		struct ras_cper_processor_record record = { 0 };
+		u64 status = batch_logs[i].body.cpu_mce.regs[ACA_REG_IDX__STATUS];
+		enum ras_cper_severity sev;
+
+		if (!(status & CPER_MCA_STATUS_UNCORRECTED) &&
+		    !(status & CPER_MCA_STATUS_DEFERRED))
+			sev = RAS_CPER_SEV_NON_FATAL_CE;
+		else if ((status & CPER_MCA_STATUS_UNCORRECTED) &&
+			 (status & CPER_MCA_STATUS_PCC))
+			sev = RAS_CPER_SEV_FATAL_UE;
+		else
+			sev = RAS_CPER_SEV_NON_FATAL_UE;
+
+		fill_section_hdr(ras_core, &record.hdr, CPER_NOTIFY__MCE, sev,
+				 &batch_logs[i]);
+		record.hdr.revision = CPER_HDR__REV_AMD_CPU;
+		record.hdr.record_length = sizeof(record);
+		record.hdr.sec_cnt = 1;
+		fill_section_descriptor(ras_core, &record.descriptor, sev,
+				PROC_ERR__SECTION_TYPE,
+				offsetof(struct ras_cper_processor_record, processor),
+				RAS_PROC_SEC_LEN);
+		record.descriptor.flag_bits.latent_err =
+			!!(status & CPER_MCA_STATUS_DEFERRED);
+		record.descriptor.revision_minor = CPER_SEC__REV_AMD_CPU & 0xff;
+		record.descriptor.revision_major = CPER_SEC__REV_AMD_CPU >> 8;
+		fill_section_processor(&record.processor, &batch_logs[i]);
+		memcpy(buffer + (i * sizeof(record)), &record, sizeof(record));
+	}
+
+	return 0;
+}
+
+static bool cper_is_processor_record(struct ras_log_info *log)
+{
+	return log->event == RAS_LOG_EVENT_CPU_RAS ||
+		(log->event == RAS_LOG_EVENT_BOOT &&
+		 !memcmp(log->body.boot_err_ctx.section_type,
+			 processor_section_type.b, CPER_UUID_MAX_SIZE));
+}
+
+static int cper_generate_processor_records(struct ras_core_context *ras_core,
+		struct ras_log_info *batch_logs, u32 nr_batch_logs,
+		u8 *buffer, u32 buf_len, u32 *real_data_len)
+{
+	u32 record_size = 0;
+	u32 i;
+	int ret;
+
+	if (batch_logs[0].event == RAS_LOG_EVENT_CPU_RAS) {
+		if (nr_batch_logs > U32_MAX / sizeof(struct ras_cper_processor_record))
+			return -EOVERFLOW;
+		record_size = sizeof(struct ras_cper_processor_record) * nr_batch_logs;
+		if (record_size > buf_len)
+			return -ENOMEM;
+
+		ret = cper_generate_runtime_processor_records(ras_core, buffer,
+				batch_logs, nr_batch_logs);
+		if (ret)
+			return ret;
+		*real_data_len = record_size;
+		return 0;
+	}
+
+	for (i = 0; i < nr_batch_logs; i++) {
+		const struct ras_boot_err_ctx *ctx = &batch_logs[i].body.boot_err_ctx;
+		u16 data_size;
+		u32 size;
+
+		if (batch_logs[i].event != RAS_LOG_EVENT_BOOT ||
+		    !cper_is_processor_record(&batch_logs[i]))
+			return -EINVAL;
+
+		data_size = min_t(u16, ctx->reg_arr_size,
+				  sizeof(struct cper_processor_context) -
+				  offsetof(struct cper_processor_context, reg_dump));
+		size = RAS_HDR_LEN + RAS_SEC_DESC_LEN +
+			offsetof(struct cper_section_processor, context.reg_dump) +
+			data_size;
+		if (record_size > U32_MAX - size)
+			return -EOVERFLOW;
+		record_size += size;
+	}
+	if (record_size > buf_len)
+		return -ENOMEM;
+
+	ret = cper_generate_boot_processor_records(ras_core, buffer,
+			batch_logs, nr_batch_logs);
+	if (ret < 0)
+		return ret;
+	*real_data_len = ret;
+
+	return 0;
+}
+
 static enum ras_log_event cper_mce_parse_err_type(struct ras_core_context *ras_core,
 						  struct aca_bank_reg *bank)
 {
@@ -327,6 +536,9 @@ int ras_cper_generate_batch_cper(struct ras_core_context *ras_core,
 		return -EINVAL;
 
 	*real_data_len = 0;
+	if (cper_is_processor_record(&batch_logs[0]))
+		return cper_generate_processor_records(ras_core, batch_logs,
+			nr_batch_logs, buf, buf_len, real_data_len);
 
 	event = batch_logs[0].event;
 	if (event == RAS_LOG_EVENT_MCE) {
Signature · 1 line
2.55.0
author maintainer
#106 lore raw

PATCH 105/109 drm/amd/ras: generate Platform Memory CPER records

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

Preserve standard Platform Memory sections recovered from BERT instead of wrapping them in the AMD crashdump format.

Validate each boot section, copy its raw payload unchanged, align each complete record to a 32-bit boundary, and report the exact serialized size.

Route Platform Memory records through a dedicated generator, independently of crashdump and processor records.

---
 drivers/gpu/drm/amd/ras/core/ras_cper.c | 69 +++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
drivers/gpu/drm/amd/ras/core/ras_cper.c +69 -0
index 1bbc2c3247c25..c8506f695d607 100644
@@ -29,6 +29,8 @@
 
 static const struct ras_cper_guid processor_section_type =
 	PROC_ERR__SECTION_TYPE;
+static const struct ras_cper_guid platform_memory_section_type =
+	PLATFORM_MEM__SECTION_TYPE;
 
 static int ras_cper_get_profile(struct ras_core_context *ras_core,
 		enum ras_log_event event, struct ras_cper_profile **profile);
@@ -502,6 +504,70 @@ static int cper_generate_processor_records(struct ras_core_context *ras_core,
 	return 0;
 }
 
+static bool cper_is_platform_memory_record(struct ras_log_info *log)
+{
+	return log->event == RAS_LOG_EVENT_BOOT &&
+		!memcmp(log->body.boot_err_ctx.section_type,
+			platform_memory_section_type.b, CPER_UUID_MAX_SIZE);
+}
+
+static int cper_generate_platform_memory_records(struct ras_core_context *ras_core,
+		struct ras_log_info *batch_logs, u32 nr_batch_logs,
+		u8 *buffer, u32 buf_len, u32 *real_data_len)
+{
+	u32 record_size = 0;
+	u32 offset = 0;
+	u32 i;
+
+	for (i = 0; i < nr_batch_logs; i++) {
+		const struct ras_boot_err_ctx *ctx = &batch_logs[i].body.boot_err_ctx;
+		u32 size;
+
+		if (!cper_is_platform_memory_record(&batch_logs[i]) ||
+		    !ctx->raw_data_size ||
+		    ctx->raw_data_size > sizeof(ctx->raw_data))
+			return -EINVAL;
+
+		size = ALIGN(RAS_HDR_LEN + RAS_SEC_DESC_LEN +
+			     ctx->raw_data_size, sizeof(u32));
+		if (record_size > U32_MAX - size)
+			return -EOVERFLOW;
+		record_size += size;
+	}
+	if (record_size > buf_len)
+		return -ENOMEM;
+
+	for (i = 0; i < nr_batch_logs; i++) {
+		const struct ras_boot_err_ctx *ctx = &batch_logs[i].body.boot_err_ctx;
+		struct cper_section_desc *descriptor;
+		struct cper_section_hdr *hdr;
+		u32 size = ALIGN(RAS_HDR_LEN + RAS_SEC_DESC_LEN +
+				 ctx->raw_data_size, sizeof(u32));
+
+		hdr = (struct cper_section_hdr *)(buffer + offset);
+		descriptor = (struct cper_section_desc *)(buffer + offset +
+						  RAS_HDR_LEN);
+		fill_section_hdr(ras_core, hdr, BOOT__TYPE,
+				 ctx->error_severity, &batch_logs[i]);
+		hdr->record_length = size;
+		hdr->sec_cnt = 1;
+		fill_section_descriptor(ras_core, descriptor, ctx->error_severity,
+				PLATFORM_MEM__SECTION_TYPE,
+				RAS_HDR_LEN + RAS_SEC_DESC_LEN,
+				ctx->raw_data_size);
+		memcpy(buffer + offset + RAS_HDR_LEN + RAS_SEC_DESC_LEN,
+		       ctx->raw_data, ctx->raw_data_size);
+		memset(buffer + offset + RAS_HDR_LEN + RAS_SEC_DESC_LEN +
+		       ctx->raw_data_size, 0,
+		       size - RAS_HDR_LEN - RAS_SEC_DESC_LEN -
+		       ctx->raw_data_size);
+		offset += size;
+	}
+
+	*real_data_len = offset;
+	return 0;
+}
+
 static enum ras_log_event cper_mce_parse_err_type(struct ras_core_context *ras_core,
 						  struct aca_bank_reg *bank)
 {
@@ -539,6 +605,9 @@ int ras_cper_generate_batch_cper(struct ras_core_context *ras_core,
 	if (cper_is_processor_record(&batch_logs[0]))
 		return cper_generate_processor_records(ras_core, batch_logs,
 			nr_batch_logs, buf, buf_len, real_data_len);
+	if (cper_is_platform_memory_record(&batch_logs[0]))
+		return cper_generate_platform_memory_records(ras_core, batch_logs,
+			nr_batch_logs, buf, buf_len, real_data_len);
 
 	event = batch_logs[0].event;
 	if (event == RAS_LOG_EVENT_MCE) {
Signature · 1 line
2.55.0
author maintainer
#107 lore raw

PATCH 106/109 drm/amd/ras: collect CPU MCE metadata

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

Processor CPER generation needs the APIC ID and bank number from the x86 machine-check record. CPU banks must also be logged by only one GPU to avoid duplicate processor records.

Copy the APIC ID and bank number into the rascore ACA bank and route CPU banks through the first registered GPU. Keep GPU banks routed by their decoded socket ID.

---
 drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_mce.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_mce.c +7 -3
index bc7a44618ac6c..ad978ed458437 100644
@@ -133,6 +133,8 @@ static void __fill_mce_to_aca_bank(struct amdgpu_device *adev,
 	aca_bank->timestamp = m->time;
 	aca_bank->bank_type = bank_type;
 	aca_bank->ecc_type = RAS_ERR_TYPE__MCE;
+	aca_bank->apic_id = m->apicid;
+	aca_bank->bank = m->bank;
 	aca_bank->regs[ACA_REG_IDX__STATUS] = m->status;
 	aca_bank->regs[ACA_REG_IDX__ADDR] = m->addr;
 	aca_bank->regs[ACA_REG_IDX__MISC0] = m->misc;
@@ -186,9 +188,11 @@ static int amdgpu_ras_mce_notifier_v5(struct amdgpu_device *adev, unsigned int i
 
 	if (ras_mce_check_bank(ras_mgr->ras_core, MCE_BANK_TYPE_GPU, m->bank)) {
 		bank_type = MCE_BANK_TYPE_GPU;
-	/* For CPU bank, only the first registered gpu device needs to record bank */
-	} else if (ras_mce_check_bank(ras_mgr->ras_core, MCE_BANK_TYPE_CPU, m->bank) &&
-			!id) {
+	} else if (ras_mce_check_bank(ras_mgr->ras_core, MCE_BANK_TYPE_CPU, m->bank)) {
+		/* For CPU bank, only the first registered gpu device needs to record bank */
+		if (id)
+			return 0;
+
 		bank_type = MCE_BANK_TYPE_CPU;
 	} else {
 		RAS_DEV_WARN(adev, "Unsupported mce bank: %u\n",  m->bank);
Signature · 1 line
2.55.0
author maintainer
#108 lore raw

PATCH 107/109 drm/amd/ras: parse and route BERT sections

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

BERT may contain structured AMD crashdump, IA processor, Platform Memory, PCIe, and SMN sections. Replaying all sections for every GPU either duplicates GPU records or drops CPU and platform records when their topology IDs are compared with GPU OAM IDs.

Parse the supported section formats in rascore. Route GPU records using the OAM identity and gate CPU and platform sections through an explicit owner selected by the operating-system integration layer.

---
 drivers/gpu/drm/amd/ras/core/ras.h      |   1 +
 drivers/gpu/drm/amd/ras/core/ras_bert.c | 337 +++++++++++++++++++++++-
 2 files changed, 331 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/ras/core/ras.h +1 -0
index 6509bd798e48e..49f9dd1b212d3 100644
@@ -384,6 +384,7 @@ struct ras_core_config {
 struct ras_core_context {
 	void *dev;
 	struct ras_core_config *config;
+	bool bert_platform_owner;
 	u32 socket_num_per_node;
 	u32 aid_num_per_socket;
 	u32 xcd_num_per_aid;
drivers/gpu/drm/amd/ras/core/ras_bert.c +330 -7

371 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#109 lore raw

PATCH 108/109 drm/amd/ras: assign BERT platform record ownership

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

IA processor and Platform Memory BERT sections are system-wide records and must not be copied into every GPU RAS ring. Per-socket GPU records still need to be offered to each matching GPU.

Assign platform sections to the first eligible RAS instance and claim each GPU socket before parsing its cached BERT data. Serialize ownership with the shared mutex and retain the state until the final RAS device exits.

---
 .../gpu/drm/amd/ras/ras_mgr/amdgpu_ras_bert.c | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_ras_bert.c +16 -4
index 04490f5173c41..71e9c8d3c8476 100644
@@ -34,7 +34,9 @@
 struct amdgpu_ras_bert_boot_err_state {
 	struct mutex lock; /* protects cached boot error state */
 	bool polled;
+	bool platform_written;
 	bool written[MAX_GPU_INSTANCE];
+	u32 users;
 	int poll_result;
 	u8 *raw_data;
 	u32 raw_data_len;
@@ -60,6 +62,7 @@ static int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 		return -EPERM;
 
 	mutex_lock(&state->lock);
+	state->users++;
 
 	if (!state->polled) {
 		state->polled = true;
@@ -135,10 +138,13 @@ static int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 		goto out_unlock;
 	}
 
+	ras_mgr->ras_core->bert_platform_owner = !state->platform_written;
+	if (ras_mgr->ras_core->bert_platform_owner)
+		state->platform_written = true;
+	state->written[socket_id] = true;
 	ret = ras_bert_process_records(ras_mgr->ras_core,
 				       state->raw_data, state->raw_data_len);
-	if (!ret)
-		state->written[socket_id] = true;
+	ras_mgr->ras_core->bert_platform_owner = false;
 
 out_unlock:
 	mutex_unlock(&state->lock);
@@ -146,17 +152,23 @@ static int amdgpu_ras_bert_process_boot_errors(struct amdgpu_device *adev)
 	return ret;
 }
 
-static void amdgpu_ras_bert_reset_boot_errors(void)
+static void amdgpu_ras_bert_release_boot_errors(void)
 {
 	struct amdgpu_ras_bert_boot_err_state *state = &boot_err_state;
 
 	mutex_lock(&state->lock);
+	if (!state->users || --state->users)
+		goto out_unlock;
+
 	memset(state->written, 0, sizeof(state->written));
+	state->platform_written = false;
 	kfree(state->raw_data);
 	state->raw_data = NULL;
 	state->raw_data_len = 0;
 	state->poll_result = 0;
 	state->polled = false;
+
+out_unlock:
 	mutex_unlock(&state->lock);
 }
 #endif
@@ -173,7 +185,7 @@ int amdgpu_ras_bert_sw_init(struct amdgpu_device *adev)
 int amdgpu_ras_bert_sw_fini(struct amdgpu_device *adev)
 {
 #if defined(CONFIG_X86_MCE_AMD) && defined(CONFIG_ACPI_APEI)
-	amdgpu_ras_bert_reset_boot_errors();
+	amdgpu_ras_bert_release_boot_errors();
 #endif
 	return 0;
 }
Signature · 1 line
2.55.0
author maintainer
#110 lore raw

PATCH 109/109 drm/amd/ras: fix CPER command record retrieval

In reply to Alex Deucher

From: Xiang Liu <[email protected]>

The CPER command reports the next batch ID as the latest valid record and does not handle a request starting at the write pointer. Batch trace responses also copy only the ACA interpretation of the log union.

Report the latest valid CPER ID, select the preceding record for a write pointer request, expose a bounded command transfer size, and copy the complete log body for batch trace records.

---
 drivers/gpu/drm/amd/ras/core/cmd.c | 23 +++++++++++++++++------
 drivers/gpu/drm/amd/ras/core/cmd.h |  2 ++
 2 files changed, 19 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/ras/core/cmd.c +17 -6
index 2eb67ccc562d5..66bd62a819b2e 100644
@@ -174,16 +174,18 @@ static int ras_cmd_get_cper_snapshot(struct ras_core_context *ras_core,
 	struct ras_cmd_cper_snapshot_rsp *output_data =
 			(struct ras_cmd_cper_snapshot_rsp *)cmd->output_buff_raw;
 	struct ras_log_batch_overview overview;
+	u64 latest_cper_id;
 
 	if ((cmd->input_size != sizeof(struct ras_cmd_cper_snapshot_req)) ||
 		(cmd->output_buf_size < sizeof(*output_data)))
 		return RAS_CMD__ERROR_INVALID_INPUT_SIZE;
 
 	ras_log_ring_get_batch_overview(ras_core, &overview);
+	latest_cper_id = overview.logged_batch_count ? overview.last_batch_id - 1 : 0;
 
 	output_data->total_cper_num = overview.logged_batch_count;
 	output_data->start_cper_id = overview.first_batch_id;
-	output_data->latest_cper_id = overview.last_batch_id;
+	output_data->latest_cper_id = latest_cper_id;
 
 	output_data->version = 0;
 
@@ -202,7 +204,7 @@ static int ras_cmd_get_cper_records(struct ras_core_context *ras_core,
 	uint32_t nr_batch_logs = MAX_RECORD_PER_BATCH;
 	struct ras_log_batch_overview overview;
 	uint32_t offset = 0, real_data_len = 0;
-	uint64_t batch_id;
+	u64 batch_id, start_batch_id;
 	uint8_t *buf_ptr = (uint8_t *)(uintptr_t)req->buf_ptr;
 	int ret = 0, i, count, valid_batch_count = 0;
 
@@ -221,14 +223,24 @@ static int ras_cmd_get_cper_records(struct ras_core_context *ras_core,
 	}
 
 	ras_log_ring_get_batch_overview(ras_core, &overview);
+
+	start_batch_id = req->cper_start_id;
+	if (overview.logged_batch_count && start_batch_id == overview.last_batch_id)
+		start_batch_id = overview.last_batch_id - 1;
+
 	for (i = 0; i < req->cper_num; i++) {
-		batch_id = req->cper_start_id + i;
+		batch_id = start_batch_id + i;
 		if (batch_id >= overview.last_batch_id)
 			break;
 
 		count = ras_log_ring_get_batch_records(ras_core, batch_id, batch_logs,
 					nr_batch_logs);
 		if (count > 0) {
+			if (offset >= req->buf_size) {
+				ret = -ENOMEM;
+				break;
+			}
+
 			ret = ras_cper_generate_batch_cper(ras_core, batch_logs, count,
 					&buf_ptr[offset], req->buf_size - offset, &real_data_len);
 			if (ret)
@@ -328,9 +340,8 @@ static int ras_cmd_get_batch_trace_records(struct ras_core_context *ras_core,
 				record->seqno = trace_arry[j].seqno;
 				record->timestamp = trace_arry[j].timestamp;
 				record->event = trace_arry[j].event;
-				memcpy(&record->body.aca_reg,
-					&trace_arry[j].body.aca_reg,
-					sizeof(trace_arry[j].body.aca_reg));
+				memcpy(&record->body, &trace_arry[j].body,
+				       sizeof(record->body));
 			}
 		} else {
 			count = 0;
drivers/gpu/drm/amd/ras/core/cmd.h +2 -0
index a37b050e913ab..d3f5ec3c8e5c6 100644
@@ -359,6 +359,8 @@ struct ras_cmd_cper_snapshot_rsp {
 	uint64_t latest_cper_id;
 };
 
+#define RAS_CMD_MAX_CPER_BUF_SZ	(2 * 1024U * 1024U) /* 2 MiB */
+
 struct ras_cmd_cper_record_req {
 	struct ras_cmd_dev_handle dev;
 	uint64_t cper_start_id;
Signature · 1 line
2.55.0