ACPI: APEI: GHES: sync ghes_proc_irq_work before freeing ghes
PATCH 1/1 ACPI: APEI: GHES: sync ghes_proc_irq_work before freeing ghes
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.
---
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(-)
drivers/acpi/apei/ghes.c +6 -3
@@ -1483,10 +1483,10 @@ static int __maybe_unused ghes_in_nmi_spool_from_list(struct list_head *rcu_listif (!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 ();
Signature · 1 line
2.43.0