Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4421726rwi; Mon, 17 Oct 2022 06:09:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78izpeKajb3U9RviFTYQhjffwWgBMXAeUd8frrFt5CvCVDoeK+vbCJSkkCPuRFGdHOCkzB X-Received: by 2002:a05:6a00:88f:b0:558:8186:3ec3 with SMTP id q15-20020a056a00088f00b0055881863ec3mr12392284pfj.83.1666012161075; Mon, 17 Oct 2022 06:09:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666012161; cv=none; d=google.com; s=arc-20160816; b=ZTQcmHRDxZT58E7sURvsYFVSWlisqEX+tT2MJNMo2pJVc6/Exgo13nMeZCdidsG9BR 2CEbinhL3XmQODGpY33UAG47MWSjwK7zvWQU/ZxJYTIOltkzkgTIQidi8tQA+faPFad+ 8ZX8oMZmU+u39AgA2cnW2DW/89JAl5aBQd5xEoAkrnygGxRMeFDq2/6nb1hL5Ub6wcey 4blEuPY7U7+WtPawhJf6fpQeq50MIc2+GoTiouF3K/iMPO5pQ53RXKwS1Gphd3bqF7oc LfSKiOp4DakpSDIOrDJaQmsaD42u9R6l7r2jSdfM52OMacrekkbcmLKJtHcEPd+uWB2z J1ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=klHIHfpDpIW2F9viLK//W9n0kM8KINNcQwuqAoMtON8=; b=L6zIXZwU/rp/mWUFQxBLyNZ+10Fw5v1BKfcGhdVyc52NBgHxXE8v3sIJHCJYvA2wiD 8b5HNTfMrCAnmPmiFDkCpUF3MtNNpXHpYt8pqkHlmtxQjmkPEggM+W4DxhwU/m4F3w+o /9lc0wAOxA20pLeByo55LX7ZX/6+CiX1hQua73G/6KBaYclAyVM0BUsju9dQ/228xgtd 6BbFk+LCsNe9ZGF5amu74uXtT6BsSmUsApkmfrdvslgdt7aC5Ka16cq2Zu++8iTwNicO GSovVNn1e6VI7U1hw7mOvUx+hDD4KVBmA7EPs4AFa3r6k1s3dbPuZjCfbK/7NpTYItur azXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a17090a5d8a00b0020243dc975bsi16380773pji.116.2022.10.17.06.09.08; Mon, 17 Oct 2022 06:09:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230028AbiJQNCT (ORCPT + 99 others); Mon, 17 Oct 2022 09:02:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230495AbiJQNCP (ORCPT ); Mon, 17 Oct 2022 09:02:15 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1E9C25F7D9; Mon, 17 Oct 2022 06:02:12 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8E4561FC7; Mon, 17 Oct 2022 06:02:18 -0700 (PDT) Received: from entos-ampere-02.shanghai.arm.com (entos-ampere-02.shanghai.arm.com [10.169.212.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A83F13F67D; Mon, 17 Oct 2022 06:02:05 -0700 (PDT) From: Jia He To: Ard Biesheuvel , Len Brown , Tony Luck , Borislav Petkov , Mauro Carvalho Chehab , Robert Richter , Robert Moore , Qiuxu Zhuo , Yazen Ghannam , Jan Luebbe , Khuong Dinh , Kani Toshi Cc: James Morse , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, devel@acpica.org, "Rafael J . Wysocki" , Shuai Xue , Jarkko Sakkinen , linux-efi@vger.kernel.org, nd@arm.com, Peter Zijlstra , Jia He Subject: [PATCH v9 2/7] EDAC/ghes: Add a notifier for reporting memory errors Date: Mon, 17 Oct 2022 13:01:35 +0000 Message-Id: <20221017130140.420986-3-justin.he@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221017130140.420986-1-justin.he@arm.com> References: <20221017130140.420986-1-justin.he@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To make a proper module, add a notifier for reporting memory errors. Use an atomic notifier because calls sites like ghes_proc_in_irq() run in interrupt context. Suggested-by: Borislav Petkov Signed-off-by: Jia He --- drivers/acpi/apei/ghes.c | 16 +++++++++++++++- drivers/edac/ghes_edac.c | 19 +++++++++++++++++-- include/acpi/ghes.h | 10 +++------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index d91ad378c00d..8cb65f757d06 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -94,6 +94,8 @@ #define FIX_APEI_GHES_SDEI_CRITICAL __end_of_fixed_addresses #endif +static ATOMIC_NOTIFIER_HEAD(ghes_report_chain); + static inline bool is_hest_type_generic_v2(struct ghes *ghes) { return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2; @@ -645,7 +647,7 @@ static bool ghes_do_proc(struct ghes *ghes, if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) { struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata); - ghes_edac_report_mem_error(sev, mem_err); + atomic_notifier_call_chain(&ghes_report_chain, sev, mem_err); arch_apei_report_mem_error(sev, mem_err); queued = ghes_handle_memory_failure(gdata, sev); @@ -1497,3 +1499,15 @@ void __init acpi_ghes_init(void) else pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n"); } + +void ghes_register_report_chain(struct notifier_block *nb) +{ + atomic_notifier_chain_register(&ghes_report_chain, nb); +} +EXPORT_SYMBOL_GPL(ghes_register_report_chain); + +void ghes_unregister_report_chain(struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&ghes_report_chain, nb); +} +EXPORT_SYMBOL_GPL(ghes_unregister_report_chain); diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c index c8fa7dcfdbd0..7b8d56a769f6 100644 --- a/drivers/edac/ghes_edac.c +++ b/drivers/edac/ghes_edac.c @@ -14,6 +14,7 @@ #include #include "edac_module.h" #include +#include #define OTHER_DETAIL_LEN 400 @@ -267,11 +268,14 @@ static int print_mem_error_other_detail(const struct cper_sec_mem_err *mem, char return n; } -void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err) +static int ghes_edac_report_mem_error(struct notifier_block *nb, + unsigned long val, void *data) { + struct cper_sec_mem_err *mem_err = (struct cper_sec_mem_err *)data; struct cper_mem_err_compact cmem; struct edac_raw_error_desc *e; struct mem_ctl_info *mci; + unsigned long sev = val; struct ghes_pvt *pvt; unsigned long flags; char *p; @@ -282,7 +286,7 @@ void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err) * know. */ if (WARN_ON_ONCE(in_nmi())) - return; + return NOTIFY_OK; spin_lock_irqsave(&ghes_lock, flags); @@ -374,8 +378,15 @@ void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err) unlock: spin_unlock_irqrestore(&ghes_lock, flags); + + return NOTIFY_OK; } +static struct notifier_block ghes_edac_mem_err_nb = { + .notifier_call = ghes_edac_report_mem_error, + .priority = 0, +}; + /* * Known systems that are safe to enable this module. */ @@ -503,6 +514,8 @@ int ghes_edac_register(struct ghes *ghes, struct device *dev) ghes_pvt = pvt; spin_unlock_irqrestore(&ghes_lock, flags); + ghes_register_report_chain(&ghes_edac_mem_err_nb); + /* only set on success */ refcount_set(&ghes_refcount, 1); @@ -548,6 +561,8 @@ void ghes_edac_unregister(struct ghes *ghes) if (mci) edac_mc_free(mci); + ghes_unregister_report_chain(&ghes_edac_mem_err_nb); + unlock: mutex_unlock(&ghes_reg_mutex); } diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 34fb3431a8f3..5cbd38b6e4e1 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -76,18 +76,11 @@ int ghes_estatus_pool_init(int num_ghes); /* From drivers/edac/ghes_edac.c */ #ifdef CONFIG_EDAC_GHES -void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err); - int ghes_edac_register(struct ghes *ghes, struct device *dev); void ghes_edac_unregister(struct ghes *ghes); #else -static inline void ghes_edac_report_mem_error(int sev, - struct cper_sec_mem_err *mem_err) -{ -} - static inline int ghes_edac_register(struct ghes *ghes, struct device *dev) { return -ENODEV; @@ -145,4 +138,7 @@ int ghes_notify_sea(void); static inline int ghes_notify_sea(void) { return -ENOENT; } #endif +struct notifier_block; +extern void ghes_register_report_chain(struct notifier_block *nb); +extern void ghes_unregister_report_chain(struct notifier_block *nb); #endif /* GHES_H */ -- 2.25.1