Skip to content

Commit feb2d38

Browse files
axiqiarafaeljw
authored andcommitted
ACPI: APEI: GHES: Extract helper functions for error status handling
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 4. Use `guard(rcu)()` instead of explicit `rcu_read_lock()`/`rcu_read_unlock()`. 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. Tested-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com> Reviewed-by: Breno Leitao <leitao@debian.org> Reviewed-by: Hanjun Guo <guohanjun@huawei.com> Link: https://patch.msgid.link/20260112032239.30023-3-xueshuai@linux.alibaba.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent f2edc1f commit feb2d38

1 file changed

Lines changed: 68 additions & 21 deletions

File tree

drivers/acpi/apei/ghes.c

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,71 @@ static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
14341434
return ret;
14351435
}
14361436

1437+
/**
1438+
* ghes_has_active_errors - Check if there are active errors in error sources
1439+
* @ghes_list: List of GHES entries to check for active errors
1440+
*
1441+
* This function iterates through all GHES entries in the given list and
1442+
* checks if any of them has active error status by reading the error
1443+
* status register.
1444+
*
1445+
* Return: true if at least one source has active error, false otherwise.
1446+
*/
1447+
static bool __maybe_unused ghes_has_active_errors(struct list_head *ghes_list)
1448+
{
1449+
struct ghes *ghes;
1450+
1451+
guard(rcu)();
1452+
list_for_each_entry_rcu(ghes, ghes_list, list) {
1453+
if (ghes->error_status_vaddr &&
1454+
readl(ghes->error_status_vaddr))
1455+
return true;
1456+
}
1457+
1458+
return false;
1459+
}
1460+
1461+
/**
1462+
* ghes_map_error_status - Map error status address to virtual address
1463+
* @ghes: pointer to GHES structure
1464+
*
1465+
* Reads the error status address from ACPI HEST table and maps it to a virtual
1466+
* address that can be accessed by the kernel.
1467+
*
1468+
* Return: 0 on success, error code on failure.
1469+
*/
1470+
static int __maybe_unused ghes_map_error_status(struct ghes *ghes)
1471+
{
1472+
struct acpi_hest_generic *g = ghes->generic;
1473+
u64 paddr;
1474+
int rc;
1475+
1476+
rc = apei_read(&paddr, &g->error_status_address);
1477+
if (rc)
1478+
return rc;
1479+
1480+
ghes->error_status_vaddr =
1481+
acpi_os_ioremap(paddr, sizeof(ghes->estatus->block_status));
1482+
if (!ghes->error_status_vaddr)
1483+
return -EINVAL;
1484+
1485+
return 0;
1486+
}
1487+
1488+
/**
1489+
* ghes_unmap_error_status - Unmap error status virtual address
1490+
* @ghes: pointer to GHES structure
1491+
*
1492+
* Unmaps the error status address if it was previously mapped.
1493+
*/
1494+
static void __maybe_unused ghes_unmap_error_status(struct ghes *ghes)
1495+
{
1496+
if (ghes->error_status_vaddr) {
1497+
iounmap(ghes->error_status_vaddr);
1498+
ghes->error_status_vaddr = NULL;
1499+
}
1500+
}
1501+
14371502
#ifdef CONFIG_ACPI_APEI_SEA
14381503
static LIST_HEAD(ghes_sea);
14391504

@@ -1484,20 +1549,9 @@ static LIST_HEAD(ghes_nmi);
14841549
static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
14851550
{
14861551
static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi);
1487-
bool active_error = false;
14881552
int ret = NMI_DONE;
1489-
struct ghes *ghes;
14901553

1491-
rcu_read_lock();
1492-
list_for_each_entry_rcu(ghes, &ghes_nmi, list) {
1493-
if (ghes->error_status_vaddr && readl(ghes->error_status_vaddr)) {
1494-
active_error = true;
1495-
break;
1496-
}
1497-
}
1498-
rcu_read_unlock();
1499-
1500-
if (!active_error)
1554+
if (!ghes_has_active_errors(&ghes_nmi))
15011555
return ret;
15021556

15031557
if (!atomic_add_unless(&ghes_in_nmi, 1, 1))
@@ -1514,18 +1568,12 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
15141568

15151569
static int ghes_nmi_add(struct ghes *ghes)
15161570
{
1517-
struct acpi_hest_generic *g = ghes->generic;
1518-
u64 paddr;
15191571
int rc;
15201572

1521-
rc = apei_read(&paddr, &g->error_status_address);
1573+
rc = ghes_map_error_status(ghes);
15221574
if (rc)
15231575
return rc;
15241576

1525-
ghes->error_status_vaddr = acpi_os_ioremap(paddr, sizeof(ghes->estatus->block_status));
1526-
if (!ghes->error_status_vaddr)
1527-
return -EINVAL;
1528-
15291577
mutex_lock(&ghes_list_mutex);
15301578
if (list_empty(&ghes_nmi))
15311579
register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes");
@@ -1543,8 +1591,7 @@ static void ghes_nmi_remove(struct ghes *ghes)
15431591
unregister_nmi_handler(NMI_LOCAL, "ghes");
15441592
mutex_unlock(&ghes_list_mutex);
15451593

1546-
if (ghes->error_status_vaddr)
1547-
iounmap(ghes->error_status_vaddr);
1594+
ghes_unmap_error_status(ghes);
15481595

15491596
/*
15501597
* To synchronize with NMI handler, ghes can only be

0 commit comments

Comments
 (0)