ACPI: APEI: fix missing erst record id
Subsystems (6)
PATCH v5 1/1 ACPI: APEI: fix missing erst record id
Read a record is cleared by others, but the deleted record cache entry is still created by erst_get_record_id_next. When next enumerate the records, get the cached deleted record, then erst_read return -ENOENT and try to get next record, loop back to first ID will return 0 in function __erst_record_id_cache_add_one and then set record_id as APEI_ERST_INVALID_RECORD_ID, finished this time read operation. It will result in read the records just in the cache hereafter.
This patch cleared the deleted record cache, fix the issue that "./erst-inject -p" shows record counts not equal to "./erst-inject -n".
A reproducer of the problem(retry many times):
[root@localhost erst-inject]# ./erst-inject -c 0xaaaaa00011 [root@localhost erst-inject]# ./erst-inject -p
rc: 273
rcd sig: CPER
rcd id: 0xaaaaa00012
rc: 273
rcd sig: CPER
rcd id: 0xaaaaa00013
rc: 273
rcd sig: CPER
rcd id: 0xaaaaa00014
[root@localhost erst-inject]# ./erst-inject -i 0xaaaaa000006 [root@localhost erst-inject]# ./erst-inject -i 0xaaaaa000007 [root@localhost erst-inject]# ./erst-inject -i 0xaaaaa000008 [root@localhost erst-inject]# ./erst-inject -p
rc: 273
rcd sig: CPER
rcd id: 0xaaaaa00012
rc: 273
rcd sig: CPER
rcd id: 0xaaaaa00013
rc: 273
rcd sig: CPER
rcd id: 0xaaaaa00014
[root@localhost erst-inject]# ./erst-inject -n total error record count: 6
Changelog:v1->v2 fix style problemsv2->v3 fix apei_read_mce called erst_get_record_id_next and modify the commit message.v3->v4 add erst_clear_cache in another retry.v4->v5 implement a new function for looking for a specific record
type, suggested by Luck Tony
--- arch/x86/kernel/cpu/mce/apei.c | 8 ++--- drivers/acpi/apei/erst-dbg.c | 3 +- drivers/acpi/apei/erst.c | 62 ++++++++++++++++++++++++++++++++-- include/acpi/apei.h | 2 ++ 4 files changed, 66 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/mce/apei.c +3 -5
@@ -177,16 +177,14 @@ ssize_t apei_read_mce(struct mce *m, u64 *record_id)/* no more record */ if (*record_id ==APEI_ERST_INVALID_RECORD_ID ) goto out; - rc =erst_read (*record_id, &rcd.hdr,sizeof (rcd)); + rc =erst_read_record (*record_id, &rcd.hdr,sizeof (rcd),sizeof (rcd), + &CPER_CREATOR_MCE );/* someone else has cleared the record, try next one */ if (rc == -ENOENT ) goto retry;else if (rc <0 ) goto out; -/* try to skip other type records in storage */ -else if (rc !=sizeof (rcd) || - !guid_equal (&rcd.hdr.creator_id, &CPER_CREATOR_MCE )) - goto retry; +memcpy (m, &rcd.mce,sizeof (*m)); rc =sizeof (*m); out:
drivers/acpi/apei/erst-dbg.c +2 -1
@@ -111,7 +111,8 @@ static ssize_t erst_dbg_read(struct file *filp, char __user *ubuf, goto out; } retry: - rc = len =erst_read (id, erst_dbg_buf, erst_dbg_buf_len); + rc = len =erst_read_record (id, erst_dbg_buf, erst_dbg_buf_len, + erst_dbg_buf_len,NULL );/* The record may be cleared by others, try read next record */ if (rc == -ENOENT ) goto retry_next;
drivers/acpi/apei/erst.c +59 -3
80 lines not on this page · raw message
include/acpi/apei.h +2 -0
@@ -46,6 +46,8 @@ int erst_get_record_id_next(int *pos, u64 *record_id);void erst_get_record_id_end (void );ssize_t erst_read (u64 record_id,struct cper_record_header *record,size_t buflen); +ssize_t erst_read_record (u64 record_id,struct cper_record_header *record, +size_t buflen,size_t recordlen,const guid_t *creatorid);int erst_clear (u64 record_id);int arch_apei_enable_cmcff (struct acpi_hest_header *hest_hdr,void *data);
Signature · 1 line
2.23.0
Quoted 2 lines
v4->v5implement a new function for looking for a specific record type, suggested by Luck Tony
Looks ok to me.