* [PATCH v2] iommu/amd: RCU-protect iommu_ga_log_notifier
@ 2026-11-17 2:30 lirongqing
0 siblings, 0 replies; only message in thread
From: lirongqing @ 2026-11-17 2:30 UTC (permalink / raw)
To: Joerg Roedel, Vasant Hegde, Suravee Suthikulpanit, Will Deacon,
Robin Murphy, iommu, linux-kernel
Cc: Li RongQing
From: Li RongQing <lirongqing@baidu.com>
iommu_poll_ga_log() accesses iommu_ga_log_notifier without an RCU
read-side critical section, so synchronize_rcu() in the unregister
path does not wait for an in-flight notifier callback.
Use rcu_assign_pointer() when updating the notifier and
rcu_dereference() under rcu_read_lock() when invoking it. Load the
pointer once so the NULL check and the call observe the same value.
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
Diff with v1:
Changes since v1:
- Replace scoped_guard(rcu) with rcu_read_lock()/rcu_read_unlock().
There is a single call site and no early return, so the scoped guard
is unnecessary.
- Keep pr_debug() and pr_err() inside the RCU read-side section.
printk() does not sleep, so this is legal, and the notifier pointer
is checked only once.
drivers/iommu/amd/iommu.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 1df0807..bdf2ed0 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1035,11 +1035,11 @@ static void iommu_poll_events(struct amd_iommu *iommu)
}
#ifdef CONFIG_IRQ_REMAP
-static int (*iommu_ga_log_notifier)(u32);
+static int (__rcu *iommu_ga_log_notifier)(u32 ga_tag);
int amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
{
- iommu_ga_log_notifier = notifier;
+ rcu_assign_pointer(iommu_ga_log_notifier, notifier);
/*
* Ensure all in-flight IRQ handlers run to completion before returning
@@ -1075,17 +1075,21 @@ static void iommu_poll_ga_log(struct amd_iommu *iommu)
/* Handle GA entry */
switch (GA_REQ_TYPE(log_entry)) {
- case GA_GUEST_NR:
- if (!iommu_ga_log_notifier)
- break;
-
- pr_debug("%s: devid=%#x, ga_tag=%#x\n",
- __func__, GA_DEVID(log_entry),
- GA_TAG(log_entry));
-
- if (iommu_ga_log_notifier(GA_TAG(log_entry)) != 0)
- pr_err("GA log notifier failed.\n");
+ case GA_GUEST_NR: {
+ int (*notifier)(u32 ga_tag);
+
+ rcu_read_lock();
+ notifier = rcu_dereference(iommu_ga_log_notifier);
+ if (notifier) {
+ pr_debug("%s: devid=%#x, ga_tag=%#x\n",
+ __func__, GA_DEVID(log_entry),
+ GA_TAG(log_entry));
+ if (notifier(GA_TAG(log_entry)))
+ pr_err("GA log notifier failed.\n");
+ }
+ rcu_read_unlock();
break;
+ }
default:
break;
}
--
2.9.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-17 2:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 2:30 [PATCH v2] iommu/amd: RCU-protect iommu_ga_log_notifier lirongqing
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®