From: Hanjun Guo <guohanjun@huawei.com>
To: Shuai Xue <xueshuai@linux.alibaba.com>, <tony.luck@intel.com>,
<mchehab@kernel.org>, <yazen.ghannam@amd.com>
Cc: <dave.jiang@intel.com>, <Smita.KoralahalliChannabasappa@amd.com>,
<leitao@debian.org>, <pengdonglin@xiaomi.com>,
<baolin.wang@linux.alibaba.com>, <benjamin.cheatham@amd.com>,
<bp@alien8.de>, <dan.j.williams@intel.com>, <james.morse@arm.com>,
<lenb@kernel.org>, <linux-acpi@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <rafael@kernel.org>,
<zhuo.song@linux.alibaba.com>
Subject: Re: [PATCH 2/3] ACPI: APEI: GHES: Extract helper functions for error status handling
Date: Wed, 17 Dec 2025 09:25:46 +0800 [thread overview]
Message-ID: <4af676a8-26f1-0e1b-5e7f-1ca4824d56fb@huawei.com> (raw)
In-Reply-To: <20251203130253.73888-3-xueshuai@linux.alibaba.com>
On 2025/12/3 21:02, Shuai Xue wrote:
> Refactors the GHES driver by extracting common functionality into
> reusable helper functions:
>
> 1. ghes_has_active_errors() - Checks if any error sources in a given list
> have active errors
> 2. ghes_map_error_status() - Maps error status address to virtual address
> 3. ghes_unmap_error_status() - Unmaps error status virtual address
>
> These helpers eliminate code duplication in the NMI path and prepare for
> similar usage in the SEA path in a subsequent patch.
>
> No functional change intended.
>
> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>
> ---
> drivers/acpi/apei/ghes.c | 92 +++++++++++++++++++++++++++++++---------
> 1 file changed, 72 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
> index 62713b612865..2c7f3ca6ce50 100644
> --- a/drivers/acpi/apei/ghes.c
> +++ b/drivers/acpi/apei/ghes.c
> @@ -1375,6 +1375,74 @@ static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
> return ret;
> }
>
> +/**
> + * ghes_has_active_errors - Check if there are active errors in error sources
> + * @ghes_list: List of GHES entries to check for active errors
> + *
> + * This function iterates through all GHES entries in the given list and
> + * checks if any of them has active error status by reading the error
> + * status register.
> + *
> + * Return: true if at least one source has active error, false otherwise.
> + */
> +static bool __maybe_unused ghes_has_active_errors(struct list_head *ghes_list)
> +{
> + bool active_error = false;
> + struct ghes *ghes;
> +
> + rcu_read_lock();
> + list_for_each_entry_rcu(ghes, ghes_list, list) {
> + if (ghes->error_status_vaddr &&
> + readl(ghes->error_status_vaddr)) {
> + active_error = true;
> + break;
> + }
> + }
> + rcu_read_unlock();
> +
> + return active_error;
> +}
> +
> +/**
> + * ghes_map_error_status - Map error status address to virtual address
> + * @ghes: pointer to GHES structure
> + *
> + * Reads the error status address from ACPI HEST table and maps it to a virtual
> + * address that can be accessed by the kernel.
> + *
> + * Return: 0 on success, error code on failure.
> + */
> +static int __maybe_unused ghes_map_error_status(struct ghes *ghes)
> +{
> + struct acpi_hest_generic *g = ghes->generic;
> + u64 paddr;
> + int rc;
> +
> + rc = apei_read(&paddr, &g->error_status_address);
> + if (rc)
> + return rc;
> + ghes->error_status_vaddr =
> + acpi_os_ioremap(paddr, sizeof(ghes->estatus->block_status));
> + if (!ghes->error_status_vaddr)
> + return AE_BAD_ADDRESS;
Same update here.
> +
> + return 0;
> +}
> +
> +/**
> + * ghes_unmap_error_status - Unmap error status virtual address
> + * @ghes: pointer to GHES structure
> + *
> + * Unmaps the error status address if it was previously mapped.
> + */
> +static void __maybe_unused ghes_unmap_error_status(struct ghes *ghes)
> +{
> + if (ghes->error_status_vaddr) {
> + iounmap(ghes->error_status_vaddr);
> + ghes->error_status_vaddr = NULL;
> + }
> +}
> +
> #ifdef CONFIG_ACPI_APEI_SEA
> static LIST_HEAD(ghes_sea);
>
> @@ -1425,20 +1493,9 @@ static LIST_HEAD(ghes_nmi);
> static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
> {
> static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi);
> - bool active_error = false;
> int ret = NMI_DONE;
> - struct ghes *ghes;
>
> - rcu_read_lock();
> - list_for_each_entry_rcu(ghes, &ghes_nmi, list) {
> - if (ghes->error_status_vaddr && readl(ghes->error_status_vaddr)) {
> - active_error = true;
> - break;
> - }
> - }
> - rcu_read_unlock();
> -
> - if (!active_error)
> + if (!ghes_has_active_errors(&ghes_nmi))
> return ret;
>
> if (!atomic_add_unless(&ghes_in_nmi, 1, 1))
> @@ -1455,16 +1512,11 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
>
> static int ghes_nmi_add(struct ghes *ghes)
> {
> - struct acpi_hest_generic *g = ghes->generic;
> - u64 paddr;
> int rc;
>
> - rc = apei_read(&paddr, &g->error_status_address);
> + rc = ghes_map_error_status(ghes);
> if (rc)
> return rc;
> - ghes->error_status_vaddr = acpi_os_ioremap(paddr, sizeof(ghes->estatus->block_status));
> - if (!ghes->error_status_vaddr)
> - return AE_BAD_ADDRESS;
>
> mutex_lock(&ghes_list_mutex);
> if (list_empty(&ghes_nmi))
> @@ -1483,8 +1535,7 @@ static void ghes_nmi_remove(struct ghes *ghes)
> unregister_nmi_handler(NMI_LOCAL, "ghes");
> mutex_unlock(&ghes_list_mutex);
>
> - if (ghes->error_status_vaddr)
> - iounmap(ghes->error_status_vaddr);
> + ghes_unmap_error_status(ghes);
>
> /*
> * To synchronize with NMI handler, ghes can only be
> @@ -1492,6 +1543,7 @@ static void ghes_nmi_remove(struct ghes *ghes)
> */
> synchronize_rcu();
> }
> +
I think it's not belong to this patch.
Thanks
Hanjun
> #else /* CONFIG_HAVE_ACPI_APEI_NMI */
> static inline int ghes_nmi_add(struct ghes *ghes) { return -EINVAL; }
> static inline void ghes_nmi_remove(struct ghes *ghes) { }
>
next prev parent reply other threads:[~2025-12-17 1:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-03 13:02 [PATCH 0/3] ACPI: APEI: GHES: Performance improvements for error notification handlers Shuai Xue
2025-12-03 13:02 ` [PATCH 1/3] ACPI: APEI: GHES: Improve ghes_notify_nmi() status check Shuai Xue
2025-12-17 1:13 ` Hanjun Guo
2025-12-18 6:01 ` Shuai Xue
2025-12-03 13:02 ` [PATCH 2/3] ACPI: APEI: GHES: Extract helper functions for error status handling Shuai Xue
2025-12-17 1:25 ` Hanjun Guo [this message]
2025-12-18 6:03 ` Shuai Xue
2025-12-03 13:02 ` [PATCH 3/3] ACPI: APEI: GHES: Improve ghes_notify_sea() status check Shuai Xue
2025-12-11 18:44 ` [PATCH 0/3] ACPI: APEI: GHES: Performance improvements for error notification handlers Luck, Tony
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4af676a8-26f1-0e1b-5e7f-1ca4824d56fb@huawei.com \
--to=guohanjun@huawei.com \
--cc=Smita.KoralahalliChannabasappa@amd.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=benjamin.cheatham@amd.com \
--cc=bp@alien8.de \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=james.morse@arm.com \
--cc=leitao@debian.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=pengdonglin@xiaomi.com \
--cc=rafael@kernel.org \
--cc=tony.luck@intel.com \
--cc=xueshuai@linux.alibaba.com \
--cc=yazen.ghannam@amd.com \
--cc=zhuo.song@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®