Skip to contentSkip to conversation

iommu/amd: Ensure GA log notifier callbacks finish running before module unload

PATCH Applied Sean Christopherson 3 participants 5 messages Mar 15, 2025 – Oct 27, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/amd: Ensure GA log notifier callbacks finish running before module unload

Synchronize RCU when unregistering KVM's GA log notifier to ensure all in-flight interrupt handlers complete before KVM-the module is unloaded.

---
 drivers/iommu/amd/iommu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iommu/amd/iommu.c +8 -0
index b48a72bd7b23..b314523d9194 100644
@@ -982,6 +982,14 @@ int amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
 {
 	iommu_ga_log_notifier = notifier;
 
+	/*
+	 * Ensure all in-flight IRQ handlers run to completion before returning
+	 * to the caller, e.g. to ensure module code isn't unloaded while it's
+	 * being executed in the IRQ handler.
+	 */
+	if (!notifier)
+		synchronize_rcu();
+
 	return 0;
 }
 EXPORT_SYMBOL(amd_iommu_register_ga_log_notifier);

base-commit: ea9bd29a9c0d757b3384ae3e633e6bbaddf00725

Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
maintainer Applied
#1 lore raw
Quoted 2 lines · Sean Christopherson
 drivers/iommu/amd/iommu.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Applied, thanks.

#2 lore raw
In reply to Sean Christopherson
Quoted 28 lines · Sean Christopherson

Synchronize RCU when unregistering KVM's GA log notifier to ensure all in-flight interrupt handlers complete before KVM-the module is unloaded.

---
 drivers/iommu/amd/iommu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iommu/amd/iommu.c +8 -0
index b48a72bd7b23..b314523d9194 100644
@@ -982,6 +982,14 @@ int amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
 {
 	iommu_ga_log_notifier = notifier;
 
+	/*
+	 * Ensure all in-flight IRQ handlers run to completion before returning
+	 * to the caller, e.g. to ensure module code isn't unloaded while it's
+	 * being executed in the IRQ handler.
+	 */
+	if (!notifier)
+		synchronize_rcu();
+
 	return 0;
 }
 EXPORT_SYMBOL(amd_iommu_register_ga_log_notifier);
Quoted 5 lines

base-commit: ea9bd29a9c0d757b3384ae3e633e6bbaddf00725

Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog

Hi Sean,

Sorry to bother you. I'm reworking the hardware_setup() path in our internal multi-KVM, but I didn't see any usage of 'amd_iommu_register_ga_log_notifier(NULL)' in the KVM code for now. Has it not been committed?

Thanks!

#3 lore raw
Quoted 36 lines · Hou Wenlong
Quoted 28 lines · Sean Christopherson

Synchronize RCU when unregistering KVM's GA log notifier to ensure all in-flight interrupt handlers complete before KVM-the module is unloaded.

---
 drivers/iommu/amd/iommu.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iommu/amd/iommu.c +8 -0
index b48a72bd7b23..b314523d9194 100644
@@ -982,6 +982,14 @@ int amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
 {
 	iommu_ga_log_notifier = notifier;
 
+	/*
+	 * Ensure all in-flight IRQ handlers run to completion before returning
+	 * to the caller, e.g. to ensure module code isn't unloaded while it's
+	 * being executed in the IRQ handler.
+	 */
+	if (!notifier)
+		synchronize_rcu();
+
 	return 0;
 }
 EXPORT_SYMBOL(amd_iommu_register_ga_log_notifier);
Quoted 5 lines

base-commit: ea9bd29a9c0d757b3384ae3e633e6bbaddf00725

Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog

Hi Sean,

Quoted 4 lines

Sorry to bother you. I'm reworking the hardware_setup() path in our internal multi-KVM, but I didn't see any usage of 'amd_iommu_register_ga_log_notifier(NULL)' in the KVM code for now. Has it not been committed?

Huh. I completely forgot to send (or even write?) the patch. I'll send one shortly.

Thanks much!

maintainer
#4 lore raw
Quoted 2 lines · Sean Christopherson

Huh. I completely forgot to send (or even write?) the patch. I'll send one shortly.

When you do, can you please add

Vasant Hegde <[email protected]> and Suravee Suthikulpanit <[email protected]>

on Cc as well? Their reviews are important in moving this forward.

Thanks,

Joerg