Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

genirq: Add and use an irq_data_update_affinity helper

Some architectures and irqchip drivers modify the cpumask returned by
irq_data_get_affinity_mask, usually by copying in to it. This is
problematic for uniprocessor configurations, where the affinity mask
should be constant, as it is known at compile time.

Add and use a setter for the affinity mask, following the pattern of
irq_data_update_effective_affinity. This allows the getter function to
return a const cpumask pointer.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> # Xen bits
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220701200056.46555-7-samuel@sholland.org

authored by

Samuel Holland and committed by
Marc Zyngier
073352e9 961343d7

+21 -14
+1 -1
arch/alpha/kernel/irq.c
··· 60 60 cpu = (cpu < (NR_CPUS-1) ? cpu + 1 : 0); 61 61 last_cpu = cpu; 62 62 63 - cpumask_copy(irq_data_get_affinity_mask(data), cpumask_of(cpu)); 63 + irq_data_update_affinity(data, cpumask_of(cpu)); 64 64 chip->irq_set_affinity(data, cpumask_of(cpu), false); 65 65 return 0; 66 66 }
+1 -1
arch/ia64/kernel/iosapic.c
··· 834 834 if (iosapic_intr_info[irq].count == 0) { 835 835 #ifdef CONFIG_SMP 836 836 /* Clear affinity */ 837 - cpumask_setall(irq_get_affinity_mask(irq)); 837 + irq_data_update_affinity(irq_get_irq_data(irq), cpu_all_mask); 838 838 #endif 839 839 /* Clear the interrupt information */ 840 840 iosapic_intr_info[irq].dest = 0;
+2 -2
arch/ia64/kernel/irq.c
··· 57 57 void set_irq_affinity_info (unsigned int irq, int hwid, int redir) 58 58 { 59 59 if (irq < NR_IRQS) { 60 - cpumask_copy(irq_get_affinity_mask(irq), 61 - cpumask_of(cpu_logical_id(hwid))); 60 + irq_data_update_affinity(irq_get_irq_data(irq), 61 + cpumask_of(cpu_logical_id(hwid))); 62 62 irq_redir[irq] = (char) (redir & 0xff); 63 63 } 64 64 }
+2 -2
arch/ia64/kernel/msi_ia64.c
··· 37 37 msg.data = data; 38 38 39 39 pci_write_msi_msg(irq, &msg); 40 - cpumask_copy(irq_data_get_affinity_mask(idata), cpumask_of(cpu)); 40 + irq_data_update_affinity(idata, cpumask_of(cpu)); 41 41 42 42 return 0; 43 43 } ··· 132 132 msg.address_lo |= MSI_ADDR_DEST_ID_CPU(cpu_physical_id(cpu)); 133 133 134 134 dmar_msi_write(irq, &msg); 135 - cpumask_copy(irq_data_get_affinity_mask(data), mask); 135 + irq_data_update_affinity(data, mask); 136 136 137 137 return 0; 138 138 }
+1 -1
arch/parisc/kernel/irq.c
··· 315 315 { 316 316 #ifdef CONFIG_SMP 317 317 struct irq_data *d = irq_get_irq_data(irq); 318 - cpumask_copy(irq_data_get_affinity_mask(d), cpumask_of(cpu)); 318 + irq_data_update_affinity(d, cpumask_of(cpu)); 319 319 #endif 320 320 321 321 return per_cpu(cpu_data, cpu).txn_addr;
+2 -2
drivers/irqchip/irq-bcm6345-l1.c
··· 216 216 enabled = intc->cpus[old_cpu]->enable_cache[word] & mask; 217 217 if (enabled) 218 218 __bcm6345_l1_mask(d); 219 - cpumask_copy(irq_data_get_affinity_mask(d), dest); 219 + irq_data_update_affinity(d, dest); 220 220 if (enabled) 221 221 __bcm6345_l1_unmask(d); 222 222 } else { 223 - cpumask_copy(irq_data_get_affinity_mask(d), dest); 223 + irq_data_update_affinity(d, dest); 224 224 } 225 225 raw_spin_unlock_irqrestore(&intc->lock, flags); 226 226
+1 -1
drivers/parisc/iosapic.c
··· 677 677 if (dest_cpu < 0) 678 678 return -1; 679 679 680 - cpumask_copy(irq_data_get_affinity_mask(d), cpumask_of(dest_cpu)); 680 + irq_data_update_affinity(d, cpumask_of(dest_cpu)); 681 681 vi->txn_addr = txn_affinity_addr(d->irq, dest_cpu); 682 682 683 683 spin_lock_irqsave(&iosapic_lock, flags);
+1 -1
drivers/sh/intc/chip.c
··· 72 72 if (!cpumask_intersects(cpumask, cpu_online_mask)) 73 73 return -1; 74 74 75 - cpumask_copy(irq_data_get_affinity_mask(data), cpumask); 75 + irq_data_update_affinity(data, cpumask); 76 76 77 77 return IRQ_SET_MASK_OK_NOCOPY; 78 78 }
+4 -3
drivers/xen/events/events_base.c
··· 528 528 BUG_ON(irq == -1); 529 529 530 530 if (IS_ENABLED(CONFIG_SMP) && force_affinity) { 531 - cpumask_copy(irq_get_affinity_mask(irq), cpumask_of(cpu)); 532 - cpumask_copy(irq_get_effective_affinity_mask(irq), 533 - cpumask_of(cpu)); 531 + struct irq_data *data = irq_get_irq_data(irq); 532 + 533 + irq_data_update_affinity(data, cpumask_of(cpu)); 534 + irq_data_update_effective_affinity(data, cpumask_of(cpu)); 534 535 } 535 536 536 537 xen_evtchn_port_bind_to_cpu(evtchn, cpu, info->cpu);
+6
include/linux/irq.h
··· 884 884 return d->common->affinity; 885 885 } 886 886 887 + static inline void irq_data_update_affinity(struct irq_data *d, 888 + const struct cpumask *m) 889 + { 890 + cpumask_copy(d->common->affinity, m); 891 + } 892 + 887 893 static inline struct cpumask *irq_get_affinity_mask(int irq) 888 894 { 889 895 struct irq_data *d = irq_get_irq_data(irq);