From: Muchun Song Date: Tue, 28 Oct 2025 09:04:08 +0000 (+0800) Subject: genirq/proc: Fix race in show_irq_affinity() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9ea2b810d51ae662cc5b5578f9395cb620a34a26;p=thirdparty%2Fkernel%2Flinux.git genirq/proc: Fix race in show_irq_affinity() Reading /proc/irq/N/smp_affinity* races with irq_set_affinity() and irq_move_masked_irq(), leading to old or torn output for users. After a user writes a new CPU mask to /proc/irq/N/affinity*, the syscall returns success, yet a subsequent read of the same file immediately returns a value different from what was just written. That's due to a race between show_irq_affinity() and irq_move_masked_irq() which lets the read observe a transient, inconsistent affinity mask. Cure it by guarding the read with irq_desc::lock. [ tglx: Massaged change log ] Signed-off-by: Muchun Song Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/20251028090408.76331-1-songmuchun@bytedance.com --- diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c index 29c2404e743be..77258eafbf632 100644 --- a/kernel/irq/proc.c +++ b/kernel/irq/proc.c @@ -48,6 +48,8 @@ static int show_irq_affinity(int type, struct seq_file *m) struct irq_desc *desc = irq_to_desc((long)m->private); const struct cpumask *mask; + guard(raw_spinlock_irq)(&desc->lock); + switch (type) { case AFFINITY: case AFFINITY_LIST: