* [PATCH] ACPI: APEI: GHES: sync ghes_proc_irq_work before freeing ghes
@ 2026-11-26 6:08 Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 15:36 ` Rafael J. Wysocki (Intel)
0 siblings, 1 reply; 2+ messages in thread
From: Bin Luo (University of Electronic Science and Technology of China) @ 2026-11-26 6:08 UTC (permalink / raw)
To: rafael
Cc: tony.luck, bp, guohanjun, mchehab, xueshuai, linux-acpi,
linux-kernel
NMI, SEA, and SDEI handlers enqueue estatus nodes holding a raw
estatus_node->ghes pointer onto ghes_estatus_llist and schedule
ghes_proc_irq_work to run ghes_proc_in_irq().
During ghes_remove(), ghes_nmi_remove(), ghes_sea_remove(), and
apei_sdei_unregister_ghes() stop further callbacks and synchronize RCU,
but do not synchronize ghes_proc_irq_work before ghes_fini() and
kfree(ghes). In addition, ghes_in_nmi_spool_from_list() calls
irq_work_queue(&ghes_proc_irq_work) after rcu_read_unlock(), leaving a
window where synchronize_rcu() can finish before the irq_work is queued.
Move irq_work_queue(&ghes_proc_irq_work) inside the RCU read-side
critical section in ghes_in_nmi_spool_from_list(), and call
irq_work_sync(&ghes_proc_irq_work) in the NMI, SEA, and SDEI removal
paths so all queued estatus nodes for the removed source are drained
before ghes is freed.
Fixes: 67eb2e990767 ("ACPI, APEI, GHES, printk support for recoverable error via NMI")
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
Found by code inspection. Compile-tested on x86_64 with W=1 and KASAN
(drivers/acpi/apei/ghes.o); not runtime-tested on APEI/NMI hardware.
drivers/acpi/apei/ghes.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index 5d888c8..75dd603 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -1483,10 +1483,10 @@ static int __maybe_unused ghes_in_nmi_spool_from_list(struct list_head *rcu_list
if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx))
ret = 0;
}
- rcu_read_unlock();
if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret)
irq_work_queue(&ghes_proc_irq_work);
+ rcu_read_unlock();
return ret;
}
@@ -1600,6 +1600,7 @@ static void ghes_sea_remove(struct ghes *ghes)
mutex_unlock(&ghes_list_mutex);
ghes_unmap_error_status(ghes);
synchronize_rcu();
+ irq_work_sync(&ghes_proc_irq_work);
}
#else /* CONFIG_ACPI_APEI_SEA */
static inline int ghes_sea_add(struct ghes *ghes) { return -EINVAL; }
@@ -1663,10 +1664,11 @@ static void ghes_nmi_remove(struct ghes *ghes)
ghes_unmap_error_status(ghes);
/*
- * To synchronize with NMI handler, ghes can only be
- * freed after NMI handler finishes.
+ * To synchronize with NMI handler and any queued estatus work,
+ * ghes can only be freed after both complete.
*/
synchronize_rcu();
+ irq_work_sync(&ghes_proc_irq_work);
}
#else /* CONFIG_HAVE_ACPI_APEI_NMI */
static inline int ghes_nmi_add(struct ghes *ghes) { return -EINVAL; }
@@ -1921,6 +1923,7 @@ static void ghes_remove(struct platform_device *ghes_dev)
ERR_PTR(rc));
return;
}
+ irq_work_sync(&ghes_proc_irq_work);
break;
default:
BUG();
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ACPI: APEI: GHES: sync ghes_proc_irq_work before freeing ghes
2026-11-26 6:08 [PATCH] ACPI: APEI: GHES: sync ghes_proc_irq_work before freeing ghes Bin Luo (University of Electronic Science and Technology of China)
@ 2026-11-27 15:36 ` Rafael J. Wysocki (Intel)
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-27 15:36 UTC (permalink / raw)
To: Bin Luo (University of Electronic Science and Technology of China)
Cc: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, linux-acpi,
linux-kernel
On Thu, Nov 26, 2026 at 7:08 AM Bin Luo (University of Electronic
Science and Technology of China) <luob87709@gmail.com> wrote:
>
> NMI, SEA, and SDEI handlers enqueue estatus nodes holding a raw
> estatus_node->ghes pointer onto ghes_estatus_llist and schedule
> ghes_proc_irq_work to run ghes_proc_in_irq().
>
> During ghes_remove(), ghes_nmi_remove(), ghes_sea_remove(), and
> apei_sdei_unregister_ghes() stop further callbacks and synchronize RCU,
> but do not synchronize ghes_proc_irq_work before ghes_fini() and
> kfree(ghes). In addition, ghes_in_nmi_spool_from_list() calls
> irq_work_queue(&ghes_proc_irq_work) after rcu_read_unlock(), leaving a
> window where synchronize_rcu() can finish before the irq_work is queued.
>
> Move irq_work_queue(&ghes_proc_irq_work) inside the RCU read-side
> critical section in ghes_in_nmi_spool_from_list(), and call
> irq_work_sync(&ghes_proc_irq_work) in the NMI, SEA, and SDEI removal
> paths so all queued estatus nodes for the removed source are drained
> before ghes is freed.
>
> Fixes: 67eb2e990767 ("ACPI, APEI, GHES, printk support for recoverable error via NMI")
> Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
Sashiko has feedback on this:
https://sashiko.dev/#/patchset/20261126060825.910-1-luob87709%40gmail.com
Please address it or if it doesn't need to be addressed, please let me know why.
> ---
> Found by code inspection. Compile-tested on x86_64 with W=1 and KASAN
> (drivers/acpi/apei/ghes.o); not runtime-tested on APEI/NMI hardware.
>
> drivers/acpi/apei/ghes.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
> index 5d888c8..75dd603 100644
> --- a/drivers/acpi/apei/ghes.c
> +++ b/drivers/acpi/apei/ghes.c
> @@ -1483,10 +1483,10 @@ static int __maybe_unused ghes_in_nmi_spool_from_list(struct list_head *rcu_list
> if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx))
> ret = 0;
> }
> - rcu_read_unlock();
>
> if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret)
> irq_work_queue(&ghes_proc_irq_work);
> + rcu_read_unlock();
>
> return ret;
> }
> @@ -1600,6 +1600,7 @@ static void ghes_sea_remove(struct ghes *ghes)
> mutex_unlock(&ghes_list_mutex);
> ghes_unmap_error_status(ghes);
> synchronize_rcu();
> + irq_work_sync(&ghes_proc_irq_work);
> }
> #else /* CONFIG_ACPI_APEI_SEA */
> static inline int ghes_sea_add(struct ghes *ghes) { return -EINVAL; }
> @@ -1663,10 +1664,11 @@ static void ghes_nmi_remove(struct ghes *ghes)
> ghes_unmap_error_status(ghes);
>
> /*
> - * To synchronize with NMI handler, ghes can only be
> - * freed after NMI handler finishes.
> + * To synchronize with NMI handler and any queued estatus work,
> + * ghes can only be freed after both complete.
> */
> synchronize_rcu();
> + irq_work_sync(&ghes_proc_irq_work);
> }
> #else /* CONFIG_HAVE_ACPI_APEI_NMI */
> static inline int ghes_nmi_add(struct ghes *ghes) { return -EINVAL; }
> @@ -1921,6 +1923,7 @@ static void ghes_remove(struct platform_device *ghes_dev)
> ERR_PTR(rc));
> return;
> }
> + irq_work_sync(&ghes_proc_irq_work);
> break;
> default:
> BUG();
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 15:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 6:08 [PATCH] ACPI: APEI: GHES: sync ghes_proc_irq_work before freeing ghes Bin Luo (University of Electronic Science and Technology of China)
2026-11-27 15:36 ` Rafael J. Wysocki (Intel)
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.