Skip to contentSkip to conversation

genirq/cpuhotpug: notify of irq affinity change for offlined cpu.

RFC PATCH In review Imran Khan 2 participants 4 messages Jan 2 – Jan 13 IRQ

lore
Share & tools
lore

Imran Khan

author
#0 lore raw

RFC PATCH v2 1/1 genirq/cpuhotpug: notify of irq affinity change for offlined cpu.

During cpu offlining the irqs with broken_affinity are affined to other CPU but this affinity change is not accounted for by desc::affinity_notify (if available).
This can leave users of irq_set_affinity_notifier, with old affinity information.

---
v1 -> v2:
- Fix compilation error due to missed parenthesis around scoped_guard

 kernel/irq/cpuhotplug.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/irq/cpuhotplug.c +10 -2
index 755346ea98196..30153be1a4cca 100644
@@ -177,9 +177,17 @@ void irq_migrate_all_off_this_cpu(void)
 		bool affinity_broken;
 
 		desc = irq_to_desc(irq);
-		scoped_guard(raw_spinlock, &desc->lock)
+		scoped_guard(raw_spinlock_irqsave, &desc->lock) {
 			affinity_broken = migrate_one_irq(desc);
-
+			if (affinity_broken && desc->affinity_notify) {
+				kref_get(&desc->affinity_notify->kref);
+				if (!schedule_work(&desc->affinity_notify->work)) {
+					/* Work was already scheduled, drop our extra ref */
+					kref_put(&desc->affinity_notify->kref,
+					desc->affinity_notify->release);
+				}
+			}
+		}
 		if (affinity_broken) {
 			pr_debug_ratelimited("IRQ %u: no longer affine to CPU%u\n",
 					    irq, smp_processor_id());

base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da

Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 24 lines · Imran Khan

During cpu offlining the irqs with broken_affinity are affined to other CPU but this affinity change is not accounted for by desc::affinity_notify (if available).
This can leave users of irq_set_affinity_notifier, with old affinity information.

---
v1 -> v2:
- Fix compilation error due to missed parenthesis around scoped_guard

 kernel/irq/cpuhotplug.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/irq/cpuhotplug.c +1 -1
index 755346ea98196..30153be1a4cca 100644
@@ -177,9 +177,17 @@ void irq_migrate_all_off_this_cpu(void)
 		bool affinity_broken;
 
 		desc = irq_to_desc(irq);
-		scoped_guard(raw_spinlock, &desc->lock)
+		scoped_guard(raw_spinlock_irqsave, &desc->lock) {

kernel/irq/cpuhotplug.c void irq_migrate_all_off_this_cpu(void) · line 189

Quoted 10 lines
kernel/irq/cpuhotplug.c +8 -1
 			affinity_broken = migrate_one_irq(desc);
-
+			if (affinity_broken && desc->affinity_notify) {
+				kref_get(&desc->affinity_notify->kref);
+				if (!schedule_work(&desc->affinity_notify->work)) {
+					/* Work was already scheduled, drop our extra ref */
+					kref_put(&desc->affinity_notify->kref,
+					desc->affinity_notify->release);
+				}
+			}

No, we are not doing random copy&pasta.

Split out the functionality into a function and use it both here and in irq_set_affinity_locked().

Thanks,

tglx

maintainer
#2 lore raw
Quoted 12 lines · Thomas Gleixner

kernel/irq/cpuhotplug.c void irq_migrate_all_off_this_cpu(void) · line 189

Quoted 8 lines · Imran Khan
kernel/irq/cpuhotplug.c +8 -0
+			if (affinity_broken && desc->affinity_notify) {
+				kref_get(&desc->affinity_notify->kref);
+				if (!schedule_work(&desc->affinity_notify->work)) {
+					/* Work was already scheduled, drop our extra ref */
+					kref_put(&desc->affinity_notify->kref,
+					desc->affinity_notify->release);
+				}
+			}

No, we are not doing random copy&pasta.

Quoted 2 lines

Split out the functionality into a function and use it both here and in irq_set_affinity_locked().

And while at it you might fix the typos in subject and change log.

#3 lore raw

Hello Thomas,
Thanks a lot for reviewing this patch.

Quoted 13 lines · Thomas Gleixner
Quoted 12 lines · Thomas Gleixner

kernel/irq/cpuhotplug.c void irq_migrate_all_off_this_cpu(void) · line 189

Quoted 8 lines · Imran Khan
kernel/irq/cpuhotplug.c +8 -0
+			if (affinity_broken && desc->affinity_notify) {
+				kref_get(&desc->affinity_notify->kref);
+				if (!schedule_work(&desc->affinity_notify->work)) {
+					/* Work was already scheduled, drop our extra ref */
+					kref_put(&desc->affinity_notify->kref,
+					desc->affinity_notify->release);
+				}
+			}

No, we are not doing random copy&pasta.

Quoted 4 lines
Quoted 2 lines

Split out the functionality into a function and use it both here and in irq_set_affinity_locked().

And while at it you might fix the typos in subject and change log.

I have addressed your review comments and have sent a new (v3) version of this patch at [1].
Could you please have a look and let me know if it looks okay now.

Thanks,
Imran

[1]: https://lore.kernel.org/all/[email protected]/