From patchwork Tue Apr 7 12:00:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 194311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6A6FC2BB1D for ; Tue, 7 Apr 2020 12:03:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEE9C2082F for ; Tue, 7 Apr 2020 12:03:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728624AbgDGMC6 (ORCPT ); Tue, 7 Apr 2020 08:02:58 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:53742 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728054AbgDGMC6 (ORCPT ); Tue, 7 Apr 2020 08:02:58 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B81D56EE67588597E0CB; Tue, 7 Apr 2020 20:02:23 +0800 (CST) Received: from DESKTOP-6T4S3DQ.china.huawei.com (10.47.82.134) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Tue, 7 Apr 2020 20:02:16 +0800 From: Shiju Jose To: , , , , , , , , , , , , CC: , , , , Shiju Jose Subject: [v7 PATCH 1/6] ACPI / APEI: Add support to queuing up the non-fatal HW errors and notify Date: Tue, 7 Apr 2020 13:00:40 +0100 Message-ID: <20200407120045.958-2-shiju.jose@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200407120045.958-1-shiju.jose@huawei.com> References: <20200407120045.958-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.82.134] X-CFilter-Loop: Reflected Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add queuing up the non-fatal HW errors to the work queue and interface to notify the registered kernel drivers for the error recovery. The interface enables drivers to register the callback functions to receive the error notification, including the vendor-specific HW errors and supports handling the non-fatal HW errors in the bottom half. Suggested-by: Borislav Petkov Signed-off-by: Shiju Jose --- drivers/acpi/apei/ghes.c | 127 +++++++++++++++++++++++++++++++++++++++ include/acpi/ghes.h | 28 +++++++++ 2 files changed, 155 insertions(+) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 24c9642e8fc7..5c0ab5422311 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,11 @@ #define GHES_ESTATUS_CACHES_SIZE 4 #define GHES_ESTATUS_IN_CACHE_MAX_NSEC 10000000000ULL + +#define GHES_EVENT_RING_SIZE 256 +#define GHES_GDATA_POOL_MIN_ALLOC_ORDER 3 +#define GHES_GDATA_POOL_MIN_SIZE 65536 + /* Prevent too many caches are allocated because of RCU */ #define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2) @@ -122,6 +128,19 @@ static DEFINE_MUTEX(ghes_list_mutex); */ static DEFINE_SPINLOCK(ghes_notify_lock_irq); +struct ghes_event_entry { + struct acpi_hest_generic_data *gdata; + int error_severity; +}; + +static DEFINE_KFIFO(ghes_event_ring, struct ghes_event_entry, + GHES_EVENT_RING_SIZE); + +static DEFINE_SPINLOCK(ghes_event_ring_lock); + +static struct gen_pool *ghes_gdata_pool; +static unsigned long ghes_gdata_pool_size_request; + static struct gen_pool *ghes_estatus_pool; static unsigned long ghes_estatus_pool_size_request; @@ -188,6 +207,40 @@ int ghes_estatus_pool_init(int num_ghes) return -ENOMEM; } +int ghes_gdata_pool_init(void) +{ + unsigned long addr, len; + int rc; + + ghes_gdata_pool = gen_pool_create(GHES_GDATA_POOL_MIN_ALLOC_ORDER, -1); + if (!ghes_gdata_pool) + return -ENOMEM; + + if (ghes_gdata_pool_size_request < GHES_GDATA_POOL_MIN_SIZE) + ghes_gdata_pool_size_request = GHES_GDATA_POOL_MIN_SIZE; + + len = ghes_gdata_pool_size_request; + addr = (unsigned long)vmalloc(PAGE_ALIGN(len)); + if (!addr) + goto err_pool_alloc; + + vmalloc_sync_mappings(); + + rc = gen_pool_add(ghes_gdata_pool, addr, PAGE_ALIGN(len), -1); + if (rc) + goto err_pool_add; + + return 0; + +err_pool_add: + vfree((void *)addr); + +err_pool_alloc: + gen_pool_destroy(ghes_gdata_pool); + + return -ENOMEM; +} + static int map_gen_v2(struct ghes *ghes) { return apei_map_generic_address(&ghes->generic_v2->read_ack_register); @@ -247,6 +300,10 @@ static struct ghes *ghes_new(struct acpi_hest_generic *generic) goto err_unmap_status_addr; } + ghes_gdata_pool_size_request += generic->records_to_preallocate * + generic->max_sections_per_record * + generic->max_raw_data_length; + return ghes; err_unmap_status_addr: @@ -490,6 +547,49 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) #endif } +static BLOCKING_NOTIFIER_HEAD(ghes_event_notify_list); + +/** + * ghes_register_event_notifier - register an event notifier + * for the non-fatal HW errors. + * @nb: pointer to the notifier_block structure of the event handler. + * + * return 0 : SUCCESS, non-zero : FAIL + */ +int ghes_register_event_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&ghes_event_notify_list, nb); +} +EXPORT_SYMBOL_GPL(ghes_register_event_notifier); + +/** + * ghes_unregister_event_notifier - unregister the previously + * registered event notifier. + * @nb: pointer to the notifier_block structure of the event handler. + */ +void ghes_unregister_event_notifier(struct notifier_block *nb) +{ + blocking_notifier_chain_unregister(&ghes_event_notify_list, nb); +} +EXPORT_SYMBOL_GPL(ghes_unregister_event_notifier); + +static void ghes_event_work_func(struct work_struct *work) +{ + struct ghes_event_entry entry; + u32 len; + + while (kfifo_get(&ghes_event_ring, &entry)) { + blocking_notifier_call_chain(&ghes_event_notify_list, + entry.error_severity, + entry.gdata); + len = acpi_hest_get_size(entry.gdata) + + acpi_hest_get_error_length(entry.gdata); + gen_pool_free(ghes_gdata_pool, (unsigned long)entry.gdata, len); + } +} + +static DECLARE_WORK(ghes_event_work, ghes_event_work_func); + static void ghes_do_proc(struct ghes *ghes, const struct acpi_hest_generic_status *estatus) { @@ -498,6 +598,8 @@ static void ghes_do_proc(struct ghes *ghes, guid_t *sec_type; const guid_t *fru_id = &guid_null; char *fru_text = ""; + struct ghes_event_entry event_entry; + u32 len; sev = ghes_severity(estatus->error_severity); apei_estatus_for_each_section(estatus, gdata) { @@ -509,6 +611,25 @@ static void ghes_do_proc(struct ghes *ghes, if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT) fru_text = gdata->fru_text; + len = acpi_hest_get_record_size(gdata); + event_entry.gdata = (void *)gen_pool_alloc(ghes_gdata_pool, + len); + if (!event_entry.gdata) { + pr_warn(GHES_PFX "ghes gdata pool alloc fail\n"); + break; + } + + memcpy(event_entry.gdata, gdata, len); + event_entry.error_severity = sev; + + if (kfifo_in_spinlocked(&ghes_event_ring, &event_entry, 1, + &ghes_event_ring_lock)) + schedule_work(&ghes_event_work); + else { + pr_warn(GHES_PFX "ghes event queue full\n"); + break; + } + if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) { struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata); @@ -1346,6 +1467,12 @@ static int __init ghes_init(void) else pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n"); + rc = ghes_gdata_pool_init(); + if (rc) { + pr_warn(GHES_PFX "ghes_gdata_pool_init failed\n"); + goto err; + } + return 0; err: return rc; diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index e3f1cddb4ac8..a3dd82069069 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -50,6 +50,34 @@ enum { GHES_SEV_PANIC = 0x3, }; + +#ifdef CONFIG_ACPI_APEI_GHES +/** + * ghes_register_event_notifier - register an event notifier + * for the non-fatal HW errors. + * @nb: pointer to the notifier_block structure of the event notifier. + * + * Return : 0 - SUCCESS, non-zero - FAIL. + */ +int ghes_register_event_notifier(struct notifier_block *nb); + +/** + * ghes_unregister_event_notifier - unregister the previously + * registered event notifier. + * @nb: pointer to the notifier_block structure of the event notifier. + */ +void ghes_unregister_event_notifier(struct notifier_block *nb); +#else +static inline int ghes_register_event_notifier(struct notifier_block *nb) +{ + return -ENODEV; +} + +static inline void ghes_unregister_event_notifier(struct notifier_block *nb) +{ +} +#endif + int ghes_estatus_pool_init(int num_ghes); /* From drivers/edac/ghes_edac.c */ From patchwork Tue Apr 7 12:00:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 194313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8CE4C2BB1D for ; Tue, 7 Apr 2020 12:02:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6FB720678 for ; Tue, 7 Apr 2020 12:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728533AbgDGMCg (ORCPT ); Tue, 7 Apr 2020 08:02:36 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:12691 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728514AbgDGMCg (ORCPT ); Tue, 7 Apr 2020 08:02:36 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D4FCD2F4798B7A04F03A; Tue, 7 Apr 2020 20:02:33 +0800 (CST) Received: from DESKTOP-6T4S3DQ.china.huawei.com (10.47.82.134) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Tue, 7 Apr 2020 20:02:26 +0800 From: Shiju Jose To: , , , , , , , , , , , , CC: , , , , Shiju Jose Subject: [v7 PATCH 3/6] ACPI / APEI: Add callback for AER to the GHES notifier Date: Tue, 7 Apr 2020 13:00:42 +0100 Message-ID: <20200407120045.958-4-shiju.jose@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200407120045.958-1-shiju.jose@huawei.com> References: <20200407120045.958-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.82.134] X-CFilter-Loop: Reflected Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add callback function for handling the AER to the GHES notifier. Signed-off-by: Shiju Jose --- drivers/acpi/apei/ghes.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 053c4a2ed96c..67ef1742fc93 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -527,11 +527,16 @@ static int ghes_handle_memory_failure(struct notifier_block *nb, * GHES_SEV_PANIC does not make it to this handling since the kernel must * panic. */ -static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) +static int ghes_handle_aer(struct notifier_block *nb, unsigned long event, + void *data) { #ifdef CONFIG_ACPI_APEI_PCIEAER + struct acpi_hest_generic_data *gdata = data; struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata); + if (!guid_equal((guid_t *)gdata->section_type, &CPER_SEC_PCIE)) + return NOTIFY_DONE; + if (pcie_err->validation_bits & CPER_PCIE_VALID_DEVICE_ID && pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) { unsigned int devfn; @@ -556,12 +561,17 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) pcie_err->aer_info); } #endif + return NOTIFY_STOP; } static struct notifier_block ghes_notifier_mem_error = { .notifier_call = ghes_handle_memory_failure, }; +static struct notifier_block ghes_notifier_aer = { + .notifier_call = ghes_handle_aer, +}; + struct ghes_error_handler_list { const char *name; struct notifier_block *nb; @@ -572,6 +582,10 @@ static const struct ghes_error_handler_list ghes_error_handler_list[] = { .name = "ghes_notifier_mem_error", .nb = &ghes_notifier_mem_error, }, + { + .name = "ghes_notifier_aer", + .nb = &ghes_notifier_aer, + }, }; static BLOCKING_NOTIFIER_HEAD(ghes_event_notify_list); @@ -657,10 +671,7 @@ static void ghes_do_proc(struct ghes *ghes, break; } - if (guid_equal(sec_type, &CPER_SEC_PCIE)) { - ghes_handle_aer(gdata); - } - else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) { + if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) { struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata); log_arm_hw_error(err); From patchwork Tue Apr 7 12:00:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 194312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96296C2BB1D for ; Tue, 7 Apr 2020 12:02:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 756D32074F for ; Tue, 7 Apr 2020 12:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728587AbgDGMCq (ORCPT ); Tue, 7 Apr 2020 08:02:46 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:12692 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726591AbgDGMCp (ORCPT ); Tue, 7 Apr 2020 08:02:45 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id F155AB66627BF4D13B8F; Tue, 7 Apr 2020 20:02:38 +0800 (CST) Received: from DESKTOP-6T4S3DQ.china.huawei.com (10.47.82.134) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Tue, 7 Apr 2020 20:02:31 +0800 From: Shiju Jose To: , , , , , , , , , , , , CC: , , , , Shiju Jose Subject: [v7 PATCH 4/6] ACPI / APEI: Add callback for ARM HW errors to the GHES notifier Date: Tue, 7 Apr 2020 13:00:43 +0100 Message-ID: <20200407120045.958-5-shiju.jose@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200407120045.958-1-shiju.jose@huawei.com> References: <20200407120045.958-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.47.82.134] X-CFilter-Loop: Reflected Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add callback function for handling the ARM HW errors to the GHES notifier. Signed-off-by: Shiju Jose --- drivers/acpi/apei/ghes.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 67ef1742fc93..3b89c7621a0d 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -564,6 +564,20 @@ static int ghes_handle_aer(struct notifier_block *nb, unsigned long event, return NOTIFY_STOP; } +static int ghes_handle_arm_hw_error(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct acpi_hest_generic_data *gdata = data; + struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata); + + if (!guid_equal((guid_t *)gdata->section_type, &CPER_SEC_PROC_ARM)) + return NOTIFY_DONE; + + log_arm_hw_error(err); + + return NOTIFY_STOP; +} + static struct notifier_block ghes_notifier_mem_error = { .notifier_call = ghes_handle_memory_failure, }; @@ -572,6 +586,10 @@ static struct notifier_block ghes_notifier_aer = { .notifier_call = ghes_handle_aer, }; +static struct notifier_block ghes_notifier_arm_hw_error = { + .notifier_call = ghes_handle_arm_hw_error, +}; + struct ghes_error_handler_list { const char *name; struct notifier_block *nb; @@ -586,6 +604,10 @@ static const struct ghes_error_handler_list ghes_error_handler_list[] = { .name = "ghes_notifier_aer", .nb = &ghes_notifier_aer, }, + { + .name = "ghes_notifier_arm_hw_error", + .nb = &ghes_notifier_arm_hw_error, + }, }; static BLOCKING_NOTIFIER_HEAD(ghes_event_notify_list); @@ -670,12 +692,7 @@ static void ghes_do_proc(struct ghes *ghes, pr_warn(GHES_PFX "ghes event queue full\n"); break; } - - if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) { - struct cper_sec_proc_arm *err = acpi_hest_get_payload(gdata); - - log_arm_hw_error(err); - } else { + { void *err = acpi_hest_get_payload(gdata); log_non_standard_event(sec_type, fru_id, fru_text,