MIPS: SB1250: Validate and update IRQ affinity
PATCH 1/1 MIPS: SB1250: Validate and update IRQ affinity
sb1250_set_affinity() selects the first online CPU in the requested affinity mask without checking whether such a CPU exists. If the intersection is empty, the resulting CPU index is invalid and must not be passed to cpu_logical_map().
Reject affinity masks containing no online CPU with -EINVAL before accessing the CPU mapping or interrupt mapper registers.
Also update the effective affinity mask to reflect the single logical CPU selected as the interrupt target.
--- arch/mips/sibyte/sb1250/irq.c | 3 +++ 1 file changed, 3 insertions(+)
arch/mips/sibyte/sb1250/irq.c +3 -0
@@ -76,6 +76,8 @@ static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask,unsigned long flags; i =cpumask_first_and (mask, cpu_online_mask); +if (i >= nr_cpu_ids) +return -EINVAL ;/* Convert logical CPU to physical CPU */ cpu =cpu_logical_map (i);
@@ -103,6 +105,7 @@ static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask,____raw_writeq (cur_ints,IOADDR (A_IMR_MAPPER (cpu) +R_IMR_INTERRUPT_MASK )); } +irq_data_update_effective_affinity (d,cpumask_of (i));raw_spin_unlock_irqrestore (&sb1250_imr_lock, flags);return 0 ;
Signature · 1 line
2.53.0
Quoted 40 lines · Florian Fainelli
sb1250_set_affinity()selects the first online CPU in the requested affinity mask without checking whether such a CPU exists. If the intersection is empty, the resulting CPU index is invalid and must not be passed tocpu_logical_map().Reject affinity masks containing no online CPU with
-EINVALbefore accessing the CPU mapping or interrupt mapper registers.Also update the effective affinity mask to reflect the single logical CPU selected as the interrupt target.
Fixes 421d1563c662 ("mips: Validate online cpus in irq_set_affinity() callbacks")Signed-off-by Florian Fainelli <[email protected]>--- arch/mips/sibyte/sb1250/irq.c | 3 +++ 1 file changed, 3 insertions(+)arch/mips/sibyte/sb1250/irq.c +3
-0@@ -76,6 +76,8 @@ static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask,unsigned long flags; i =cpumask_first_and (mask, cpu_online_mask); +if (i >= nr_cpu_ids) +return -EINVAL ;/* Convert logical CPU to physical CPU */ cpu =cpu_logical_map (i);@@ -103,6 +105,7 @@ static int sb1250_set_affinity(struct irq_data *d, const struct cpumask *mask,____raw_writeq (cur_ints,IOADDR (A_IMR_MAPPER (cpu) +R_IMR_INTERRUPT_MASK )); } +irq_data_update_effective_affinity (d,cpumask_of (i));raw_spin_unlock_irqrestore (&sb1250_imr_lock, flags);return 0 ;Signature · 1 line
2.53.0
applied to mips-fixes
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]
Quoted 7 lines · Florian Fainelli
sb1250_set_affinity()selects the first online CPU in the requested affinity mask without checking whether such a CPU exists. If the intersection is empty, the resulting CPU index is invalid and must not be passed tocpu_logical_map().Reject affinity masks containing no online CPU with
-EINVALbefore accessing the CPU mapping or interrupt mapper registers.
Why do you think this is needed? The only case where an unvalidated mask
is passed is AFAICT with:
/**
* irq_force_affinity - Force the irq affinity of a given irq
* @irq: Interrupt to set affinity
* @cpumask: cpumask
*
* Same as irq_set_affinity, but without checking the mask against
* online cpus.
*
* Solely for low level cpu hotplug code, where we need to make per
* cpu interrupts affine before the cpu becomes online. */
-- which does not apply here (nor for arch/mips/sibyte/bcm1480/irq.c, which uses analogous code and should otherwise be updated accordingly) since all the CPUs are onchip the SoC.
Have I missed anything?
Quoted 2 lines
Also update the effective affinity mask to reflect the single logical CPU selected as the interrupt target.
Likewise, why is it needed? This code returns IRQ_SET_MASK_OK (should
really use the enumeration constant), so the caller will do the copy.
Maciej
Quoted 27 lines · Maciej W. Rozycki
Quoted 7 lines
sb1250_set_affinity()selects the first online CPU in the requested affinity mask without checking whether such a CPU exists. If the intersection is empty, the resulting CPU index is invalid and must not be passed tocpu_logical_map().Reject affinity masks containing no online CPU with
-EINVALbefore accessing the CPU mapping or interrupt mapper registers.Why do you think this is needed? The only case where an unvalidated mask
is passed is AFAICT with:/**
*irq_force_affinity- Force the irq affinity of a given irq
* @irq: Interrupt to set affinity
* @cpumask: cpumask
*
* Same asirq_set_affinity, but without checking the mask against
* online cpus.
*
* Solely for low level cpu hotplug code, where we need to make per
* cpu interrupts affine before the cpu becomes online. */-- which does not apply here (nor for
arch/mips/sibyte/bcm1480/irq.c, which uses analogous code and should otherwise be updated accordingly) since all the CPUs are onchip the SoC.
Quoted 7 lines
Have I missed anything?
Quoted 2 lines
Also update the effective affinity mask to reflect the single logical CPU selected as the interrupt target.
Likewise, why is it needed? This code returns
IRQ_SET_MASK_OK(should
really use the enumeration constant), so the caller will do the copy.
I can see it went to Linus already. Can we please have it reverted?
Maciej
Hi Maciej,
Quoted 31 lines · Maciej W. Rozycki
Quoted 29 lines · Maciej W. Rozycki
Quoted 7 lines
sb1250_set_affinity()selects the first online CPU in the requested affinity mask without checking whether such a CPU exists. If the intersection is empty, the resulting CPU index is invalid and must not be passed tocpu_logical_map().Reject affinity masks containing no online CPU with
-EINVALbefore accessing the CPU mapping or interrupt mapper registers.Why do you think this is needed? The only case where an unvalidated mask
is passed is AFAICT with:/**
*irq_force_affinity- Force the irq affinity of a given irq
* @irq: Interrupt to set affinity
* @cpumask: cpumask
*
* Same asirq_set_affinity, but without checking the mask against
* online cpus.
*
* Solely for low level cpu hotplug code, where we need to make per
* cpu interrupts affine before the cpu becomes online. */-- which does not apply here (nor for
arch/mips/sibyte/bcm1480/irq.c, which uses analogous code and should otherwise be updated accordingly) since all the CPUs are onchip the SoC.Have I missed anything?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Also update the effective affinity mask to reflect the single logical CPU selected as the interrupt target.
Likewise, why is it needed? This code returns
IRQ_SET_MASK_OK(should
really use the enumeration constant), so the caller will do the copy.I can see it went to Linus already. Can we please have it reverted?
Apologies for the late response, I was hoping Thomas would allow us to discuss this before applying. The effective-affinity update addresses this warning observed during boot:
genirq: irq_chip SB1250-IMR did not update eff. affinity mask of irq 2
IRQ_SET_MASK_OK causes irq_do_set_affinity() to copy the requested mask into irq_common_data.affinity, but it does not populate the separate effective_affinity mask when CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK is enabled. irq_validate_effective_affinity() then finds that mask empty and emits the warning.
Since the mapper selects a single CPU, irq_data_update_effective_affinity(d, cpumask_of(i)) records the actual target and addresses that warning. I should have included this in the commit message.
You are right about the empty-mask check, I will remove that part, revise the commit message accordingly, and use IRQ_SET_MASK_OK explicitly. BCM1480 should receive the analogous effective-affinity update as well.
Signature · 1 line
Florian