mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
To: rafael@kernel.org
Cc: tony.luck@intel.com, bp@alien8.de, guohanjun@huawei.com,
	mchehab@kernel.org, xueshuai@linux.alibaba.com,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ACPI: APEI: GHES: sync ghes_proc_irq_work before freeing ghes
Date: Thu, 26 Nov 2026 14:08:25 +0800	[thread overview]
Message-ID: <20261126060825.910-1-luob87709@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-26  6:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261126060825.910-1-luob87709@gmail.com \
    --to=luob87709@gmail.com \
    --cc=bp@alien8.de \
    --cc=guohanjun@huawei.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rafael@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=xueshuai@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®