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 <songmuchun@bytedance.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://patch.msgid.link/20251028090408.76331-1-songmuchun@bytedance.com
pull/1354/merge
Muchun Song 2025-10-28 17:04:08 +08:00 committed by Thomas Gleixner
parent 68c4c159a0
commit 9ea2b810d5
1 changed files with 2 additions and 0 deletions

View File

@ -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: