Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2505807rwa; Mon, 22 Aug 2022 08:45:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR53xs92qoSZIR1AeorAW4mHvGAAftMxRgqk0KHx4TiT5ukj9lScHRazhswW/fintBJW4lqi X-Received: by 2002:a17:907:288a:b0:730:7ee5:e6a with SMTP id em10-20020a170907288a00b007307ee50e6amr13124818ejc.218.1661183109606; Mon, 22 Aug 2022 08:45:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661183109; cv=none; d=google.com; s=arc-20160816; b=cog729s7uTf06HgBkvBaOGnqOegoE01bhEN9wn4Paag24HXstyWYboZIwaaJcKKNMS pf7pEfw06sdNkeNRywZCcM2MmXG1RKBXOvQgtrQdedW1yEwtksy073FWo6owzK4m8S4i a+1Et+Kf+1KV1W68eAJEl3uQ3tnJ1GvkSdmfu8EW22lRp5LsKTdYYq9jFgn6vISNGSm5 HLxcnCf0gutNOa18Pnp++0g+Ueniss+RNd76P/UWijbyfxTSafKhQqBJfRNewvH3P3ZJ NoSz3nEn8j3MDacuLTKcHFZWiXrqXeOa9tScp/O4NYciN9YSTRkBNTt45pq2bRcWLJTo uo4A== 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=0z6lq/fqFAZvIpRUz0hf2xtfIJavjtfuSLK1npFYxVEZCuPa3NXGjkmZX8fBja43dN 3ns9+5XQFkPm5IHggERDvQ3IV+hYeOT+efYwmSkn0sTTXhDSMGYs1CIrzIgH3Qx5xIUH dFTahTeVgRK4/qq4LfT2gIrGWxbqICHb5ZY6BBQrOA1xuue9e55nOUlNHN30JCOn6vCn Eq+2FJXAnz7qm2/QHAphoB519whEZ3ylO7tBxHfc0lNMYwDYP8/IBWqh7Kx9PQh5CXdY osr0pjdjnqORysxUI2ZZYJyij6VojRrqtpv9IBNo18s96qC1ctXFL/vZfmHxb+/3oYf/ BRfg== 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 sh16-20020a1709076e9000b0073d8e9760ebsi871734ejc.449.2022.08.22.08.44.43; Mon, 22 Aug 2022 08:45:09 -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 S236726AbiHVPmB (ORCPT + 99 others); Mon, 22 Aug 2022 11:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236691AbiHVPlo (ORCPT ); Mon, 22 Aug 2022 11:41:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F2B181EAE4; Mon, 22 Aug 2022 08:41:26 -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 B966E12FC; Mon, 22 Aug 2022 08:41:29 -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 045523F70D; Mon, 22 Aug 2022 08:41:17 -0700 (PDT) From: Jia He To: Len Brown , James Morse , Tony Luck , Borislav Petkov , Mauro Carvalho Chehab , Robert Richter , Robert Moore , Qiuxu Zhuo , Yazen Ghannam , Jonathan Corbet , Jan Luebbe , Khuong Dinh , Kani Toshi Cc: Ard Biesheuvel , 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, "Paul E. McKenney" , Andrew Morton , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , linux-doc@vger.kernel.org, Jia He Subject: [RESEND PATCH v3 2/9] EDAC/ghes: Add a notifier for reporting memory errors Date: Mon, 22 Aug 2022 15:40:41 +0000 Message-Id: <20220822154048.188253-3-justin.he@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220822154048.188253-1-justin.he@arm.com> References: <20220822154048.188253-1-justin.he@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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