Skip to contentSkip to conversation

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

RFC PATCH Superseded Imran Khan 2 participants 2 messages Jan 2 – Jan 3 IRQ

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Imran Khan

author
#0 lore raw

RFC PATCH 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.

---

I have kept the patch as RFC because I am not sure, if there is some specific reason (and I have missed that) behind not getting affinity change notification for cpus being offlined.

 kernel/irq/cpuhotplug.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/irq/cpuhotplug.c +9 -1
index 755346ea98196..0ab0919f2cb57 100644
@@ -177,8 +177,16 @@ 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",

base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da

Signature · 1 line
2.34.1
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Imran,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da]

url:    https://github.com/intel-lab-lkp/linux/commits/Imran-Khan/genirq-cpuhotpug-notify-of-irq-affinity-change-for-offlined-cpu/20260102-232823
base:   f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da
patch link:    https://lore.kernel.org/r/20260102152637.25377-1-imran.f.khan%40oracle.com
patch subject: [RFC PATCH] genirq/cpuhotpug: notify of irq affinity change for offlined cpu.
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260103/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260103/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/jump_label.h:78,

                    from include/linux/dynamic_debug.h:6,
                    from include/linux/printk.h:621,
                    from include/asm-generic/bug.h:31,
                    from arch/x86/include/asm/bug.h:193,
                    from arch/x86/include/asm/alternative.h:9,
                    from arch/x86/include/asm/barrier.h:5,
                    from include/asm-generic/bitops/generic-non-atomic.h:7,
                    from include/linux/bitops.h:28,
                    from include/linux/kernel.h:23,
                    from include/linux/interrupt.h:6,
                    from kernel/irq/cpuhotplug.c:12:
   kernel/irq/cpuhotplug.c: In function 'irq_migrate_all_off_this_cpu':
>> include/linux/cleanup.h:439:19: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
     439 |                 } else
         |                   ^~~~
   include/linux/cleanup.h:442:9: note: in expansion of macro '__scoped_guard'
     442 |         __scoped_guard(_name, __UNIQUE_ID(label), args)
         |         ^~~~~~~~~~~~~~
   kernel/irq/cpuhotplug.c:180:17: note: in expansion of macro 'scoped_guard'
     180 |                 scoped_guard(raw_spinlock_irqsave, &desc->lock)
         |                 ^~~~~~~~~~~~
   kernel/irq/cpuhotplug.c:182:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
     182 |                         if (affinity_broken && desc->affinity_notify) {
         |                         ^~

vim +/else +439 include/linux/cleanup.h

857d18f23ab172 Peter Zijlstra  2025-07-11  422  
fcc22ac5baf06d Przemek Kitszel 2024-10-18  423  /*
fcc22ac5baf06d Przemek Kitszel 2024-10-18  424   * Helper macro for scoped_guard().
fcc22ac5baf06d Przemek Kitszel 2024-10-18  425   *
fcc22ac5baf06d Przemek Kitszel 2024-10-18  426   * Note that the "!__is_cond_ptr(_name)" part of the condition ensures that
fcc22ac5baf06d Przemek Kitszel 2024-10-18  427   * compiler would be sure that for the unconditional locks the body of the
fcc22ac5baf06d Przemek Kitszel 2024-10-18  428   * loop (caller-provided code glued to the else clause) could not be skipped.
fcc22ac5baf06d Przemek Kitszel 2024-10-18  429   * It is needed because the other part - "__guard_ptr(_name)(&scope)" - is too
fcc22ac5baf06d Przemek Kitszel 2024-10-18  430   * hard to deduce (even if could be proven true for unconditional locks).
fcc22ac5baf06d Przemek Kitszel 2024-10-18  431   */
fcc22ac5baf06d Przemek Kitszel 2024-10-18  432  #define __scoped_guard(_name, _label, args...)				\
fcc22ac5baf06d Przemek Kitszel 2024-10-18  433  	for (CLASS(_name, scope)(args);					\
fcc22ac5baf06d Przemek Kitszel 2024-10-18  434  	     __guard_ptr(_name)(&scope) || !__is_cond_ptr(_name);	\
fcc22ac5baf06d Przemek Kitszel 2024-10-18  435  	     ({ goto _label; }))					\
fcc22ac5baf06d Przemek Kitszel 2024-10-18  436  		if (0) {						\
fcc22ac5baf06d Przemek Kitszel 2024-10-18  437  _label:									\
fcc22ac5baf06d Przemek Kitszel 2024-10-18  438  			break;						\

fcc22ac5baf06d Przemek Kitszel 2024-10-18 @439 } else
e4ab322fbaaaf8 Peter Zijlstra 2023-09-17 440

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki