Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1442477ybt; Thu, 18 Jun 2020 08:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzJEOAZHnVfAoeS5vme+mWcRC+BZBuqp6z2RzypFRwFjSRdFzjFtcx4iya3PFLIBjbJR1v X-Received: by 2002:aa7:dc57:: with SMTP id g23mr4459221edu.352.1592495193941; Thu, 18 Jun 2020 08:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592495193; cv=none; d=google.com; s=arc-20160816; b=jWVYJ63tboYSDcKYvtA0cyfVWWS1xVuZp8Ayo1rQhVPFV+h6Ll7+cZ2C7PUSSLamBG jckznZb6aox0jtVcDUtn6d9jv8twUHLYWNTkukGbEjr6VcNUZbFj2LxRLk1CYuRJPwuH QJfRBc7gMDSm8HuPrVmjHqwNWOk7SSduwaQnfxhuK7wfXxYUmRA0OfCLLksZ7oy6R/Eo 6J+hl+bjrWV4akBJgqa2QqVoP1xknP7GjZa3eJYfrpenthsG0gqG//BEMOH8hRQ8rKp7 bEzR8xOkZFnXxRgvnech9txlU7jYmeRcOV7HwbNdO8blPDl+90NfPgLeQPf5fp1gBeUn uM4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rbUKbPgEhFKwrFKSBBotuf+NK9aVkcxXvXXzTYyzCAY=; b=q6uUVqe7gviZ8FUB3QCN/9Z53WrVN23QLotu87jbl9cDzyVm5OSe/nyiKYGuRD77Qz q0MoxOwSdND+hT2FNUDCLjVqipApyUavE0W4i2pv7BOuk6n4enYD+luMrrHa7CiAl01p PbIQcKEh+YB6/qkmHONQekx9IpIzoFREK9GS5pBQbK2iWdc8OqXvLpv5DOR9kVMQ8bBP 3jMkkeqZpd2oPxyKjAkY0olAHhHnW1CBIIKEFXfhvNzxaeQLbd5Ff8f5XDiDD7HtN447 y8RAg+NU//0xLIy1Hb2XjGQasi7oSWOSs21QY7lndypTd18LiEtlMJsbeqrsSRZQvl8X VmDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si1981091ejj.410.2020.06.18.08.46.10; Thu, 18 Jun 2020 08:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731808AbgFRPl3 (ORCPT + 99 others); Thu, 18 Jun 2020 11:41:29 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2328 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731736AbgFRPkx (ORCPT ); Thu, 18 Jun 2020 11:40:53 -0400 Received: from lhreml715-chm.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id 69FA963F7BC3307C754F; Thu, 18 Jun 2020 16:40:51 +0100 (IST) Received: from DESKTOP-6T4S3DQ.china.huawei.com (10.47.90.32) by lhreml715-chm.china.huawei.com (10.201.108.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Thu, 18 Jun 2020 16:40:50 +0100 From: Shiju Jose To: , , , , , , , , , , , , , CC: , , , Subject: [PATCH v10 1/2] ACPI / APEI: Add support to notify the vendor specific HW errors Date: Thu, 18 Jun 2020 16:38:22 +0100 Message-ID: <20200618153823.588-2-shiju.jose@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200618153823.588-1-shiju.jose@huawei.com> References: <20200618153823.588-1-shiju.jose@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.47.90.32] X-ClientProxiedBy: lhreml714-chm.china.huawei.com (10.201.108.65) To lhreml715-chm.china.huawei.com (10.201.108.66) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to report the vendor specific non-fatal HW errors to the drivers for the error recovery. The interface functions ghes_register_event_notifier() and ghes_unregister_event_notifier() enables the drivers to register and unregister the vendor specific error handlers. The interface uses work queue for queuing each vendor-specific error record and uses blocking notifier chain, in the work function, to report the error to the registered drivers. The drivers should match the section type of the error record before processing the error data. Signed-off-by: Shiju Jose Reviewed-by: Bjorn Helgaas --- drivers/acpi/apei/ghes.c | 123 +++++++++++++++++++++++++++++++++++++++ include/acpi/ghes.h | 29 +++++++++ 2 files changed, 152 insertions(+) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 81bf71b10d44..b6dc4eaa6345 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ #define GHES_ESTATUS_CACHES_SIZE 4 #define GHES_ESTATUS_IN_CACHE_MAX_NSEC 10000000000ULL + /* Prevent too many caches are allocated because of RCU */ #define GHES_ESTATUS_CACHE_ALLOCED_MAX (GHES_ESTATUS_CACHES_SIZE * 3 / 2) @@ -88,6 +90,10 @@ #define FIX_APEI_GHES_SDEI_CRITICAL __end_of_fixed_addresses #endif +#define GHES_EVENT_RING_SIZE 256 +#define GHES_EVENT_GDATA_POOL_MIN_ALLOC_ORDER 3 +#define GHES_EVENT_GDATA_POOL_MIN_SIZE 65536 + static inline bool is_hest_type_generic_v2(struct ghes *ghes) { return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2; @@ -123,6 +129,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_event_gdata_pool; +static unsigned long ghes_event_gdata_pool_size_request; + static struct gen_pool *ghes_estatus_pool; static unsigned long ghes_estatus_pool_size_request; @@ -183,6 +202,38 @@ int ghes_estatus_pool_init(int num_ghes) return -ENOMEM; } +static int ghes_event_gdata_pool_init(void) +{ + unsigned long addr, len; + int rc; + + ghes_event_gdata_pool = gen_pool_create(GHES_EVENT_GDATA_POOL_MIN_ALLOC_ORDER, -1); + if (!ghes_event_gdata_pool) + return -ENOMEM; + + if (ghes_event_gdata_pool_size_request < GHES_EVENT_GDATA_POOL_MIN_SIZE) + ghes_event_gdata_pool_size_request = GHES_EVENT_GDATA_POOL_MIN_SIZE; + + len = ghes_event_gdata_pool_size_request; + addr = (unsigned long)vmalloc(PAGE_ALIGN(len)); + if (!addr) + goto err_pool_alloc; + + rc = gen_pool_add(ghes_event_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_event_gdata_pool); + + return -ENOMEM; +} + static int map_gen_v2(struct ghes *ghes) { return apei_map_generic_address(&ghes->generic_v2->read_ack_register); @@ -242,6 +293,10 @@ static struct ghes *ghes_new(struct acpi_hest_generic *generic) goto err_unmap_status_addr; } + ghes_event_gdata_pool_size_request += generic->records_to_preallocate * + generic->max_sections_per_record * + generic->max_raw_data_length; + return ghes; err_unmap_status_addr: @@ -511,6 +566,69 @@ 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.Presently supported to notify + * the vendor-specific HW errors only, though it can be used to + * notify the standard errors also. + * @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_record_size(entry.gdata); + gen_pool_free(ghes_event_gdata_pool, (unsigned long)entry.gdata, len); + } +} + +static DECLARE_WORK(ghes_event_work, ghes_event_work_func); + +static void ghes_handle_non_standard_event(struct acpi_hest_generic_data *gdata, + int sev) +{ + u32 len; + struct ghes_event_entry event_entry; + + len = acpi_hest_get_record_size(gdata); + event_entry.gdata = (void *)gen_pool_alloc(ghes_event_gdata_pool, len); + if (!event_entry.gdata) + return; + + 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 "event notify queue full\n"); +} + static bool ghes_do_proc(struct ghes *ghes, const struct acpi_hest_generic_status *estatus) { @@ -549,6 +667,7 @@ static bool ghes_do_proc(struct ghes *ghes, } else { void *err = acpi_hest_get_payload(gdata); + ghes_handle_non_standard_event(gdata, sev); log_non_standard_event(sec_type, fru_id, fru_text, sec_sev, err, gdata->error_data_length); @@ -1385,6 +1504,10 @@ static int __init ghes_init(void) else pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n"); + rc = ghes_event_gdata_pool_init(); + if (rc) + pr_warn(GHES_PFX "non-fatal vendor-specific errors not being notified\n"); + return 0; err: return rc; diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 517a5231cc1b..37a48ce13499 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -53,6 +53,35 @@ enum { GHES_SEV_PANIC = 0x3, }; +#ifdef CONFIG_ACPI_APEI_GHES +/** + * ghes_register_event_notifier - register an event notifier + * for the non-fatal HW errors.Presently supported to notify + * the vendor-specific HW errors only, though it can be used to notify + * the standard errors also. + * @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 */ -- 2.17.1