Re: [PATCH 4.4 15/97] genirq: Use irqd_get_trigger_type to compare the trigger type for shared IRQs

From: Ben Hutchings
Date: Tue Apr 03 2018 - 10:17:28 EST


On Fri, 2018-03-23 at 10:54 +0100, Greg Kroah-Hartman wrote:
> 4.4-stable review patch.ÂÂIf anyone has any objections, please let me know.
>
> ------------------
>
> From: Hans de Goede <hdegoede@xxxxxxxxxx>
>
>
> [ Upstream commit 382bd4de61827dbaaf5fb4fb7b1f4be4a86505e7 ]
>
> When requesting a shared irq with IRQF_TRIGGER_NONE then the irqaction
> flags get filled with the trigger type from the irq_data:
>
> ÂÂÂÂÂÂÂÂif (!(new->flags & IRQF_TRIGGER_MASK))
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂnew->flags |= irqd_get_trigger_type(&desc->irq_data);

The code above was added to __setup_irq() in 4.8, so I don't think this
fix is needed in 3.18 or 4.4; and I suspect it might cause a regression
there.

Ben.

> On the first setup_irq() the trigger type in irq_data is NONE when the
> above code executes, then the irq is started up for the first time and
> then the actual trigger type gets established, but that's too late to fix
> up new->flags.
>
> When then a second user of the irq requests the irq with IRQF_TRIGGER_NONE
> its irqaction's triggertype gets set to the actual trigger type and the
> following check fails:
>
> ÂÂÂÂÂÂÂÂif (!((old->flags ^ new->flags) & IRQF_TRIGGER_MASK))
>
> Resulting in the request_irq failing with -EBUSY even though both
> users requested the irq with IRQF_SHARED | IRQF_TRIGGER_NONE
>
> Fix this by comparing the new irqaction's trigger type to the trigger type
> stored in the irq_data which correctly reflects the actual trigger type
> being used for the irq.
>
> Suggested-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx>
> Acked-by: Marc Zyngier <marc.zyngier@xxxxxxx>
> Link: http://lkml.kernel.org/r/20170415100831.17073-1-hdegoede@xxxxxxxxxx
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Signed-off-by: Sasha Levin <alexander.levin@xxxxxxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> ---
> Âkernel/irq/manage.c |ÂÂÂÂ4 +++-
> Â1 file changed, 3 insertions(+), 1 deletion(-)
>
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -1189,8 +1189,10 @@ __setup_irq(unsigned int irq, struct irq
> Â Â* set the trigger type must match. Also all must
> Â Â* agree on ONESHOT.
> Â Â*/
> + unsigned int oldtype = irqd_get_trigger_type(&desc->irq_data);
> +
> Â if (!((old->flags & new->flags) & IRQF_SHARED) ||
> - ÂÂÂÂ((old->flags ^ new->flags) & IRQF_TRIGGER_MASK) ||
> + ÂÂÂÂ(oldtype != (new->flags & IRQF_TRIGGER_MASK)) ||
> Â ÂÂÂÂ((old->flags ^ new->flags) & IRQF_ONESHOT))
> Â goto mismatch;
> Â

--
Ben Hutchings
Software Developer, Codethink Ltd.