From a090931524d03a4975c84b89a32210420d852313 Mon Sep 17 00:00:00 2001 From: Liu Xinpeng Date: Tue, 12 Apr 2022 11:05:19 +0800 Subject: 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 Signed-off-by: Liu Xinpeng Reviewed-by: Tony Luck Signed-off-by: Rafael J. Wysocki --- arch/x86/kernel/cpu/mce/apei.c | 8 ++--- drivers/acpi/apei/erst-dbg.c | 3 +- drivers/acpi/apei/erst.c | 77 ++++++++++++++++++++++++++++++++++++++---- include/acpi/apei.h | 2 ++ 4 files changed, 78 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/apei.c b/arch/x86/kernel/cpu/mce/apei.c index 0e3ae64d3b76..717192915f28 100644 --- a/arch/x86/kernel/cpu/mce/apei.c +++ b/arch/x86/kernel/cpu/mce/apei.c @@ -177,16 +177,14 @@ retry: /* 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: diff --git a/drivers/acpi/apei/erst-dbg.c b/drivers/acpi/apei/erst-dbg.c index c740f0faad39..8bc71cdc2270 100644 --- a/drivers/acpi/apei/erst-dbg.c +++ b/drivers/acpi/apei/erst-dbg.c @@ -111,7 +111,8 @@ retry_next: 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; diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c index 698d67cee052..31b077eedb58 100644 --- a/drivers/acpi/apei/erst.c +++ b/drivers/acpi/apei/erst.c @@ -856,6 +856,74 @@ ssize_t erst_read(u64 record_id, struct cper_record_header *record, } EXPORT_SYMBOL_GPL(erst_read); +static void erst_clear_cache(u64 record_id) +{ + int i; + u64 *entries; + + mutex_lock(&erst_record_id_cache.lock); + + entries = erst_record_id_cache.entries; + for (i = 0; i < erst_record_id_cache.len; i++) { + if (entries[i] == record_id) + entries[i] = APEI_ERST_INVALID_RECORD_ID; + } + __erst_record_id_cache_compact(); + + mutex_unlock(&erst_record_id_cache.lock); +} + +ssize_t erst_read_record(u64 record_id, struct cper_record_header *record, + size_t buflen, size_t recordlen, const guid_t *creatorid) +{ + ssize_t len; + + /* + * if creatorid is NULL, read any record for erst-dbg module + */ + if (creatorid == NULL) { + len = erst_read(record_id, record, buflen); + if (len == -ENOENT) + erst_clear_cache(record_id); + + return len; + } + + len = erst_read(record_id, record, buflen); + /* + * if erst_read return value is -ENOENT skip to next record_id, + * and clear the record_id cache. + */ + if (len == -ENOENT) { + erst_clear_cache(record_id); + goto out; + } + + if (len < 0) + goto out; + + /* + * if erst_read return value is less than record head length, + * consider it as -EIO, and clear the record_id cache. + */ + if (len < recordlen) { + len = -EIO; + erst_clear_cache(record_id); + goto out; + } + + /* + * if creatorid is not wanted, consider it as not found, + * for skipping to next record_id. + */ + if (!guid_equal(&record->creator_id, creatorid)) + len = -ENOENT; + +out: + return len; +} +EXPORT_SYMBOL_GPL(erst_read_record); + int erst_clear(u64 record_id) { int rc, i; @@ -996,16 +1064,13 @@ skip: goto out; } - len = erst_read(record_id, &rcd->hdr, rcd_len); + len = erst_read_record(record_id, &rcd->hdr, rcd_len, sizeof(*rcd), + &CPER_CREATOR_PSTORE); /* The record may be cleared by others, try read next record */ if (len == -ENOENT) goto skip; - else if (len < 0 || len < sizeof(*rcd)) { - rc = -EIO; + else if (len < 0) goto out; - } - if (!guid_equal(&rcd->hdr.creator_id, &CPER_CREATOR_PSTORE)) - goto skip; record->buf = kmalloc(len, GFP_KERNEL); if (record->buf == NULL) { diff --git a/include/acpi/apei.h b/include/acpi/apei.h index afaca3a075e8..dc60f7db5524 100644 --- a/include/acpi/apei.h +++ b/include/acpi/apei.h @@ -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); -- cgit v1.2.3-59-g8ed1b From e802ca757b29ef98d9e155dec686a2ec8f832b65 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 13 Apr 2022 14:59:12 +0300 Subject: ACPI: docs: enumeration: Unify Package () for properties (part 2) Unify Package () representation for properties: - make them one line where it's possible - add spaces between parentheses and curly braces - drop the explicit size of package Signed-off-by: Andy Shevchenko Signed-off-by: Rafael J. Wysocki --- Documentation/firmware-guide/acpi/enumeration.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Documentation/firmware-guide/acpi/enumeration.rst b/Documentation/firmware-guide/acpi/enumeration.rst index 47fb4d6d4557..6b62425ef9cd 100644 --- a/Documentation/firmware-guide/acpi/enumeration.rst +++ b/Documentation/firmware-guide/acpi/enumeration.rst @@ -167,8 +167,7 @@ The table below shows an example of its usage:: Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { - Package () {"interrupt-names", - Package (2) {"default", "alert"}}, + Package () { "interrupt-names", Package () { "default", "alert" } }, } ... }) -- cgit v1.2.3-59-g8ed1b From ab59c89396c007c360b1a4d762732d1621ff5456 Mon Sep 17 00:00:00 2001 From: Tony Luck Date: Tue, 19 Apr 2022 14:19:21 -0700 Subject: ACPI, APEI, EINJ: Refuse to inject into the zero page Some validation tests dynamically inject errors into memory used by applications to check that the system can recover from a variety of poison consumption sceenarios. But sometimes the virtual address picked by these tests is mapped to the zero page. This causes additional unexpected machine checks as other processes that map the zero page also consume the poison. Disallow injection to the zero page. Signed-off-by: Tony Luck Signed-off-by: Rafael J. Wysocki --- drivers/acpi/apei/einj.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c index 95cc2a9f3e05..d4326ec12d29 100644 --- a/drivers/acpi/apei/einj.c +++ b/drivers/acpi/apei/einj.c @@ -549,6 +549,9 @@ static int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, !arch_is_platform_page(base_addr))) return -EINVAL; + if (is_zero_pfn(base_addr >> PAGE_SHIFT)) + return -EADDRINUSE; + inject: mutex_lock(&einj_mutex); rc = __einj_error_inject(type, flags, param1, param2, param3, param4); -- cgit v1.2.3-59-g8ed1b From 290a20782ac6d1bfbd70541cacddaf9acbe1f1f5 Mon Sep 17 00:00:00 2001 From: Sumeet Pawnikar Date: Thu, 21 Apr 2022 22:25:43 +0530 Subject: ACPI: DPTF: Correct description of INT3407 / INT3532 attributes Remove duplicate comments of PBSS for Battery steady state power and correct the typo for PMAX Maximum platform power. Signed-off-by: Sumeet Pawnikar Signed-off-by: Rafael J. Wysocki --- drivers/acpi/dptf/dptf_power.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/acpi/dptf/dptf_power.c b/drivers/acpi/dptf/dptf_power.c index dc1f52a5b3f4..1f2e6c29773b 100644 --- a/drivers/acpi/dptf/dptf_power.c +++ b/drivers/acpi/dptf/dptf_power.c @@ -12,14 +12,12 @@ /* * Presentation of attributes which are defined for INT3407 and INT3532. * They are: - * PMAX : Maximum platform powe + * PMAX : Maximum platform power * PSRC : Platform power source * ARTG : Adapter rating * CTYP : Charger type - * PBSS : Battery steady power * PROP : Rest of worst case platform Power * PBSS : Power Battery Steady State - * PBSS : Power Battery Steady State * RBHF : High Frequency Impedance * VBNL : Instantaneous No-Load Voltage * CMPP : Current Discharge Capability -- cgit v1.2.3-59-g8ed1b From 42e5ed0618030543e4f679afa5e42ec8ab9337bb Mon Sep 17 00:00:00 2001 From: Sumeet Pawnikar Date: Thu, 5 May 2022 22:30:19 +0530 Subject: ACPI: DPTF: Add support for high frequency impedance notification Add high frequency impedance notification support under DPTF. This returns high frequency impedance value that can be obtained from battery fuel gauge whenever there is change over a threshold. Also, corrected the typo from IMPEDANCED_CHNGED to IMPEDANCE_CHANGED. Signed-off-by: Sumeet Pawnikar Signed-off-by: Rafael J. Wysocki --- drivers/acpi/dptf/dptf_power.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/dptf/dptf_power.c b/drivers/acpi/dptf/dptf_power.c index 1f2e6c29773b..407b89d8a2ce 100644 --- a/drivers/acpi/dptf/dptf_power.c +++ b/drivers/acpi/dptf/dptf_power.c @@ -115,7 +115,7 @@ static const struct attribute_group dptf_battery_attribute_group = { #define POWER_STATE_CHANGED 0x81 #define STEADY_STATE_POWER_CHANGED 0x83 #define POWER_PROP_CHANGE_EVENT 0x84 -#define IMPEDANCED_CHNGED 0x85 +#define IMPEDANCE_CHANGED 0x85 #define VOLTAGE_CURRENT_CHANGED 0x86 static long long dptf_participant_type(acpi_handle handle) @@ -148,6 +148,9 @@ static void dptf_power_notify(acpi_handle handle, u32 event, void *data) case STEADY_STATE_POWER_CHANGED: attr = "max_steady_state_power_mw"; break; + case IMPEDANCE_CHANGED: + attr = "high_freq_impedance_mohm"; + break; case VOLTAGE_CURRENT_CHANGED: attr = "no_load_voltage_mv"; break; -- cgit v1.2.3-59-g8ed1b From 24773e6c7a27bfc724a8ed5523dc31bbfc9543d5 Mon Sep 17 00:00:00 2001 From: Li kunyu Date: Wed, 11 May 2022 13:16:05 +0800 Subject: x86: ACPI: Make mp_config_acpi_gsi() a void function Because the return value of mp_config_acpi_gsi() is not use, change it into a void function. Signed-off-by: Li kunyu [ rjw: Subject and changelog rewrite ] Signed-off-by: Rafael J. Wysocki --- arch/x86/kernel/acpi/boot.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c index 0d01e7f5078c..7e32e33d52fa 100644 --- a/arch/x86/kernel/acpi/boot.c +++ b/arch/x86/kernel/acpi/boot.c @@ -375,7 +375,7 @@ static void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, isa_irq_to_gsi[bus_irq] = gsi; } -static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger, +static void mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger, int polarity) { #ifdef CONFIG_X86_MPPARSE @@ -387,9 +387,9 @@ static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger, u8 pin; if (!acpi_ioapic) - return 0; + return; if (!dev || !dev_is_pci(dev)) - return 0; + return; pdev = to_pci_dev(dev); number = pdev->bus->number; @@ -408,7 +408,6 @@ static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger, mp_save_irq(&mp_irq); #endif - return 0; } static int __init mp_register_ioapic_irq(u8 bus_irq, u8 polarity, -- cgit v1.2.3-59-g8ed1b